Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/abp2blocklist.js

Issue 29452289: Issue 5283 - Add support for $websocket and $webrtc (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Left Patch Set: Generate single rule for filter covering all raw types Created July 3, 2017, 6:28 p.m.
Right Patch Set: Rebase Created July 13, 2017, 11:41 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « node_modules/filterClasses.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 {trigger: {"url-filter": "^https?://([^/:]*\\.)?test\\.com[/:]", 45 {trigger: {"url-filter": "^https?://([^/:]*\\.)?test\\.com[/:]",
46 "url-filter-is-case-sensitive": true}, 46 "url-filter-is-case-sensitive": true},
47 action: {type: "css-display-none", selector: ".whatever"}} 47 action: {type: "css-display-none", selector: ".whatever"}}
48 ]); 48 ]);
49 49
50 test.done(); 50 test.done();
51 }, 51 },
52 52
53 testElementHidingExceptions: function(test) 53 testElementHidingExceptions: function(test)
54 { 54 {
55 // Element hiding rules should be in the following order: (1) generic
56 // rules, (2) exceptions for generic rules, (3) domain-specific rules,
57 // (4) exceptions for all rules.
58 testRules(test, [ 55 testRules(test, [
59 "##.whatever", 56 "##.whatever",
60 "test.com###something", 57 "test.com###something",
61 "@@||special.test.com^$elemhide", 58 "@@||special.test.com^$elemhide",
62 "@@||test.com^$generichide" 59 "@@||test.com^$generichide",
60 "@@^something^$elemhide",
61 "@@^anything^$generichide"
63 ], [ 62 ], [
64 ["^https?://", "css-display-none"], 63 ["^https?://", ["*test.com", "*special.test.com"]],
65 ["^https?://([^/]+\\.)?test\\.com", "ignore-previous-rules"], 64 ["^https?://([^/:]*\\.)?test\\.com[/:]", ["*special.test.com"]]
66 ["^https?://([^/:]*\\.)?test\\.com[/:]", "css-display-none"],
67 ["^https?://([^/]+\\.)?special\\.test\\.com", "ignore-previous-rules"]
68 ], rules => rules.map(rule => [rule.trigger["url-filter"], 65 ], rules => rules.map(rule => [rule.trigger["url-filter"],
69 rule.action.type])); 66 rule.trigger["unless-domain"]]));
70 67
71 testRules(test, ["#@#whatever"], []); 68 testRules(test, ["#@#whatever"], []);
72 testRules(test, ["test.com#@#whatever"], []); 69 testRules(test, ["test.com#@#whatever"], []);
73 testRules(test, ["~test.com#@#whatever"], []); 70 testRules(test, ["~test.com#@#whatever"], []);
74 71
75 // We currently completely ignore any element hiding filters that have the 72 // We currently completely ignore any element hiding filters that have the
76 // same selector as an element hiding exception. In these examples #whatever 73 // same selector as an element hiding exception. In these examples #whatever
77 // should be hidden for all domains not ending in test.com instead of 74 // should be hidden for all domains not ending in test.com instead of
78 // nowhere! 75 // nowhere!
79 testRules(test, ["test.com#@#whatever", "##whatever"], []); 76 testRules(test, ["test.com#@#whatever", "##whatever"], []);
80 testRules(test, ["~test.com##whatever"], []); 77 testRules(test, ["~test.com##whatever"], []);
81 78
82 test.done(); 79 test.done();
83 }, 80 },
84 81
85 testRequestFilters: function(test) 82 testRequestFilters: function(test)
86 { 83 {
87 testRules(test, ["/foo", "||test.com", "http://example.com/foo"], [ 84 testRules(test, [
88 {trigger: {"url-filter": "^[^:]+:(//)?.*/foo", 85 "/foo", "||test.com^", "http://example.com/foo", "^foo^"
89 "resource-type": ["image", "style-sheet", "script", "font", 86 ], [
90 "media", "raw", "document"]}, 87 {
91 action: {type: "block"}}, 88 trigger: {
92 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?test\\.com", 89 "url-filter": "^[^:]+:(//)?.*/foo",
93 "url-filter-is-case-sensitive": true, 90 "resource-type": ["image", "style-sheet", "script", "font",
94 "resource-type": ["image", "style-sheet", "script", "font", 91 "media", "raw"]
95 "media", "raw", "document"]}, 92 },
96 action: {type: "block"}}, 93 action: {type: "block"}
97 {trigger: {"url-filter": "^http://example\\.com/foo", 94 },
98 "resource-type": ["image", "style-sheet", "script", "font", 95 {
99 "media", "raw", "document"]}, 96 trigger: {
100 action: {type: "block"}}, 97 "url-filter": "^[^:]+:(//)?([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$",
101 {trigger: {"url-filter": "^[^:]+:(//)?.*http://example\\.com/foo", 98 "url-filter-is-case-sensitive": true,
102 "resource-type": ["image", "style-sheet", "script", "font", 99 "resource-type": ["image", "style-sheet", "script", "font",
103 "media", "raw", "document"]}, 100 "media", "raw", "document"],
104 action: {type: "block"}} 101 "unless-top-url": [
102 "^[^:]+:(//)?([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$"
103 ],
104 "top-url-filter-is-case-sensitive": true
105 },
106 action: {type: "block"}
107 },
108 {
109 trigger: {
110 "url-filter": "^http://example\\.com/foo",
111 "resource-type": ["image", "style-sheet", "script", "font",
112 "media", "raw", "document"],
113 "unless-top-url": ["^http://example\\.com/foo"]
114 },
115 action: {type: "block"}
116 },
117 {
118 trigger: {
119 "url-filter": "^[^:]+:(//)?.*http://example\\.com/foo",
120 "resource-type": ["image", "style-sheet", "script", "font",
121 "media", "raw", "document"],
122 "unless-top-url": ["^[^:]+:(//)?.*http://example\\.com/foo"]
123 },
124 action: {type: "block"}
125 },
126 {
127 trigger: {
128 "url-filter":
129 "^[^:]+:(//)?(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0-9].*)?$",
130 "resource-type": ["image", "style-sheet", "script", "font",
131 "media", "raw"]
132 },
133 action: {type: "block"}
134 }
105 ]); 135 ]);
106 136
107 testRules(test, ["||example.com"], [ 137 testRules(test, ["||example.com"], [
108 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?example\\.com", 138 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?example\\.com",
109 "url-filter-is-case-sensitive": true, 139 "url-filter-is-case-sensitive": true,
110 "resource-type": ["image", "style-sheet", "script", "font", 140 "resource-type": ["image", "style-sheet", "script", "font",
111 "media", "raw", "document"]}, 141 "media", "raw", "document"],
142 "unless-top-url": ["^[^:]+:(//)?([^/]+\\.)?example\\.com"],
143 "top-url-filter-is-case-sensitive": true},
112 144
113 action: {type: "block"}} 145 action: {type: "block"}}
114 ]); 146 ]);
115 147
116 // Rules which would match no resource-types shouldn't be generated. 148 // Rules which would match no resource-types shouldn't be generated.
117 testRules(test, ["foo$document", "||foo.com$document"], []); 149 testRules(test, ["foo$document", "||foo.com$document"], []);
118 150
119 test.done(); 151 test.done();
120 }, 152 },
121 153
(...skipping 23 matching lines...) Expand all
145 ["###example", "test.com###EXAMPLE"], 177 ["###example", "test.com###EXAMPLE"],
146 ["[id=example]", "[id=EXAMPLE]"], 178 ["[id=example]", "[id=EXAMPLE]"],
147 rules => rules.map(rule => rule.action.selector)); 179 rules => rules.map(rule => rule.action.selector));
148 180
149 test.done(); 181 test.done();
150 }, 182 },
151 183
152 testDomainWhitelisting: function(test) 184 testDomainWhitelisting: function(test)
153 { 185 {
154 testRules(test, ["@@||example.com^$document"], [ 186 testRules(test, ["@@||example.com^$document"], [
155 {trigger: {"url-filter": ".*", 187 {
156 "if-domain": ["*example.com"]}, 188 trigger: {
157 action: {type: "ignore-previous-rules"}} 189 "url-filter": ".*",
190 "if-domain": ["*example.com"]
191 },
192 action: {type: "ignore-previous-rules"}
193 }
158 ]); 194 ]);
159 testRules(test, ["@@||example.com^$document,image"], [ 195 testRules(test, ["@@||example.com^$document,image"], [
160 {trigger: {"url-filter": ".*", 196 {
161 "if-domain": ["*example.com"]}, 197 trigger: {
162 action: {type: "ignore-previous-rules"}}, 198 "url-filter": ".*",
163 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 199 "if-domain": ["*example.com"]
164 "url-filter-is-case-sensitive": true, 200 },
165 "resource-type": ["image"]}, 201 action: {type: "ignore-previous-rules"}
166 action: {type: "ignore-previous-rules"}} 202 },
203 {
204 trigger: {
205 "url-filter": "^https?://([^/]+\\.)?example\\.com([^-_.%a-z0-9].*)?$",
206 "url-filter-is-case-sensitive": true,
207 "resource-type": ["image"]
208 },
209 action: {type: "ignore-previous-rules"}
210 }
167 ]); 211 ]);
168 testRules(test, ["@@||example.com/path^$font,document"], [ 212 testRules(test, ["@@||example.com/path^$font,document"], [
169 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com/path", 213 {
170 "resource-type": ["font"]}, 214 trigger: {
171 action: {type: "ignore-previous-rules"}} 215 "url-filter":
216 "^https?://([^/]+\\.)?example\\.com/path([^-_.%A-Za-z0-9].*)?$",
217 "resource-type": ["font"]
218 },
219 action: {type: "ignore-previous-rules"}
220 }
172 ]); 221 ]);
173 222
174 test.done(); 223 test.done();
175 }, 224 },
176 225
177 testGenericblockExceptions: function(test) 226 testGenericblockExceptions: function(test)
178 { 227 {
179 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"], 228 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"],
180 [[undefined, ["*example.com"]]], 229 [[undefined, ["*example.com"]]],
181 rules => rules.map(rule => [rule.trigger["if-domain"], 230 rules => rules.map(rule => [rule.trigger["if-domain"],
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 263
215 testRequestTypeMapping: function(test) 264 testRequestTypeMapping: function(test)
216 { 265 {
217 testRules( 266 testRules(
218 test, 267 test,
219 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media", 268 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media",
220 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest", 269 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest",
221 "11$websocket", "12$webrtc", 270 "11$websocket", "12$webrtc",
222 "13$ping", "14$subdocument", "15$other", "16$IMAGE", 271 "13$ping", "14$subdocument", "15$other", "16$IMAGE",
223 "17$script,PING,Popup", "18$~image"], 272 "17$script,PING,Popup", "18$~image"],
224 [["image", "style-sheet", "script", "font", "media", "raw", "document" ], 273 [["image", "style-sheet", "script", "font", "media", "raw"],
225 ["image"], 274 ["image"],
226 ["style-sheet"], 275 ["style-sheet"],
227 ["script"], 276 ["script"],
228 ["font"], 277 ["font"],
229 ["media"], 278 ["media"],
230 ["popup"], 279 ["popup"],
231 ["media"], 280 ["media"],
232 ["raw"], 281 ["raw"],
233 ["raw"], 282 ["raw"],
234 ["raw"], // WebSocket 283 ["raw"], // WebSocket
235 ["raw"], // WebRTC: STUN 284 ["raw"], // WebRTC: STUN
236 ["raw"], // WebRTC: TURN 285 ["raw"], // WebRTC: TURN
237 ["raw"], 286 ["raw"],
238 ["document"],
239 ["raw"], 287 ["raw"],
240 ["image"], 288 ["image"],
241 ["script", "popup", "raw" ], 289 ["script", "popup", "raw" ],
242 ["style-sheet", "script", "font", "media", "raw", "document"]], 290 ["style-sheet", "script", "font", "media", "raw"]],
243 rules => rules.map(rule => rule.trigger["resource-type"]) 291 rules => rules.map(rule => rule.trigger["resource-type"])
244 ); 292 );
245 293
246 test.done(); 294 test.done();
247 }, 295 },
248 296
249 testUnsupportedfilters: function(test) 297 testUnsupportedfilters: function(test)
250 { 298 {
251 // These types of filters are currently completely unsupported. 299 // These types of filters are currently completely unsupported.
252 testRules(test, ["foo$sitekey=bar"], []); 300 testRules(test, ["foo$sitekey=bar"], []);
(...skipping 18 matching lines...) Expand all
271 ["foo.com"], 319 ["foo.com"],
272 rules => rules[0]["trigger"]["if-domain"]); 320 rules => rules[0]["trigger"]["if-domain"]);
273 321
274 test.done(); 322 test.done();
275 }, 323 },
276 324
277 testUnicode: function(test) 325 testUnicode: function(test)
278 { 326 {
279 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], 327 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"],
280 rules => rules[0]["trigger"]["if-domain"]); 328 rules => rules[0]["trigger"]["if-domain"]);
281 testRules(test, ["🐈$domain=🐈.cat"], []); 329 testRules(test, ["||🐈"], "^[^:]+:(//)?([^/]+\\.)?xn--zn8h",
282 testRules(test, ["###🐈"], []); 330 rules => rules[0]["trigger"]["url-filter"]);
331 testRules(test, ["🐈$domain=🐈.cat"], "^[^:]+:(//)?.*%F0%9F%90%88",
332 rules => rules[0]["trigger"]["url-filter"]);
333 testRules(test, ["🐈%F0%9F%90%88$domain=🐈.cat"],
334 "^[^:]+:(//)?.*%F0%9F%90%88%F0%9F%90%88",
335 rules => rules[0]["trigger"]["url-filter"]);
336 testRules(test, ["###🐈"], "[id=🐈]",
337 rules => rules[0]["action"]["selector"]);
283 338
284 test.done(); 339 test.done();
285 }, 340 },
286 341
287 testWebSocket: function(test) 342 testWebSocket: function(test)
288 { 343 {
289 testRules(test, ["foo$websocket"], [ 344 testRules(test, ["foo$websocket"], [
290 {trigger: {"url-filter": "^wss?://.*foo", "resource-type": ["raw"]}, 345 {trigger: {"url-filter": "^wss?://.*foo", "resource-type": ["raw"]},
291 action: {type: "block"}} 346 action: {type: "block"}}
292 ]); 347 ]);
293 348
294 test.done(); 349 test.done();
295 }, 350 },
296 351
297 testWebRTC: function(test) 352 testWebRTC: function(test)
298 { 353 {
299 testRules(test, ["foo$webrtc"], [ 354 testRules(test, ["foo$webrtc"], [
300 {trigger: {"url-filter": "^stuns?:.*foo", "resource-type": ["raw"]}, 355 {trigger: {"url-filter": "^stuns?:.*foo", "resource-type": ["raw"]},
301 action: {type: "block"}}, 356 action: {type: "block"}},
302 {trigger: {"url-filter": "^turns?:.*foo", "resource-type": ["raw"]}, 357 {trigger: {"url-filter": "^turns?:.*foo", "resource-type": ["raw"]},
303 action: {type: "block"}} 358 action: {type: "block"}}
304 ]); 359 ]);
305 360
306 test.done(); 361 test.done();
307 } 362 }
308 }; 363 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld