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: Add top-level exception after copying rule Created July 9, 2017, 9:27 a.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 "unless-top-url": ["^[^:]+:(//)?.*/foo"]}, 88 trigger: {
92 action: {type: "block"}}, 89 "url-filter": "^[^:]+:(//)?.*/foo",
93 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?test\\.com", 90 "resource-type": ["image", "style-sheet", "script", "font",
94 "url-filter-is-case-sensitive": true, 91 "media", "raw"]
95 "resource-type": ["image", "style-sheet", "script", "font", 92 },
96 "media", "raw", "document"], 93 action: {type: "block"}
97 "unless-top-url": ["^[^:]+:(//)?([^/]+\\.)?test\\.com"], 94 },
98 "top-url-filter-is-case-sensitive": true}, 95 {
99 action: {type: "block"}}, 96 trigger: {
100 {trigger: {"url-filter": "^http://example\\.com/foo", 97 "url-filter": "^[^:]+:(//)?([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$",
101 "resource-type": ["image", "style-sheet", "script", "font", 98 "url-filter-is-case-sensitive": true,
102 "media", "raw", "document"], 99 "resource-type": ["image", "style-sheet", "script", "font",
103 "unless-top-url": ["^http://example\\.com/foo"]}, 100 "media", "raw", "document"],
104 action: {type: "block"}}, 101 "unless-top-url": [
105 {trigger: {"url-filter": "^[^:]+:(//)?.*http://example\\.com/foo", 102 "^[^:]+:(//)?([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$"
106 "resource-type": ["image", "style-sheet", "script", "font", 103 ],
107 "media", "raw", "document"], 104 "top-url-filter-is-case-sensitive": true
108 "unless-top-url": ["^[^:]+:(//)?.*http://example\\.com/foo"]}, 105 },
109 action: {type: "block"}} 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 }
110 ]); 135 ]);
111 136
112 testRules(test, ["||example.com"], [ 137 testRules(test, ["||example.com"], [
113 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?example\\.com", 138 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?example\\.com",
114 "url-filter-is-case-sensitive": true, 139 "url-filter-is-case-sensitive": true,
115 "resource-type": ["image", "style-sheet", "script", "font", 140 "resource-type": ["image", "style-sheet", "script", "font",
116 "media", "raw", "document"], 141 "media", "raw", "document"],
117 "unless-top-url": ["^[^:]+:(//)?([^/]+\\.)?example\\.com"], 142 "unless-top-url": ["^[^:]+:(//)?([^/]+\\.)?example\\.com"],
118 "top-url-filter-is-case-sensitive": true}, 143 "top-url-filter-is-case-sensitive": true},
119 144
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 ["###example", "test.com###EXAMPLE"], 177 ["###example", "test.com###EXAMPLE"],
153 ["[id=example]", "[id=EXAMPLE]"], 178 ["[id=example]", "[id=EXAMPLE]"],
154 rules => rules.map(rule => rule.action.selector)); 179 rules => rules.map(rule => rule.action.selector));
155 180
156 test.done(); 181 test.done();
157 }, 182 },
158 183
159 testDomainWhitelisting: function(test) 184 testDomainWhitelisting: function(test)
160 { 185 {
161 testRules(test, ["@@||example.com^$document"], [ 186 testRules(test, ["@@||example.com^$document"], [
162 {trigger: {"url-filter": ".*", 187 {
163 "if-domain": ["*example.com"]}, 188 trigger: {
164 action: {type: "ignore-previous-rules"}} 189 "url-filter": ".*",
190 "if-domain": ["*example.com"]
191 },
192 action: {type: "ignore-previous-rules"}
193 }
165 ]); 194 ]);
166 testRules(test, ["@@||example.com^$document,image"], [ 195 testRules(test, ["@@||example.com^$document,image"], [
167 {trigger: {"url-filter": ".*", 196 {
168 "if-domain": ["*example.com"]}, 197 trigger: {
169 action: {type: "ignore-previous-rules"}}, 198 "url-filter": ".*",
170 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 199 "if-domain": ["*example.com"]
171 "url-filter-is-case-sensitive": true, 200 },
172 "resource-type": ["image"]}, 201 action: {type: "ignore-previous-rules"}
173 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 }
174 ]); 211 ]);
175 testRules(test, ["@@||example.com/path^$font,document"], [ 212 testRules(test, ["@@||example.com/path^$font,document"], [
176 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com/path", 213 {
177 "resource-type": ["font"]}, 214 trigger: {
178 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 }
179 ]); 221 ]);
180 222
181 test.done(); 223 test.done();
182 }, 224 },
183 225
184 testGenericblockExceptions: function(test) 226 testGenericblockExceptions: function(test)
185 { 227 {
186 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"], 228 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"],
187 [[undefined, ["*example.com"]]], 229 [[undefined, ["*example.com"]]],
188 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
221 263
222 testRequestTypeMapping: function(test) 264 testRequestTypeMapping: function(test)
223 { 265 {
224 testRules( 266 testRules(
225 test, 267 test,
226 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media", 268 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media",
227 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest", 269 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest",
228 "11$websocket", "12$webrtc", 270 "11$websocket", "12$webrtc",
229 "13$ping", "14$subdocument", "15$other", "16$IMAGE", 271 "13$ping", "14$subdocument", "15$other", "16$IMAGE",
230 "17$script,PING,Popup", "18$~image"], 272 "17$script,PING,Popup", "18$~image"],
231 [["image", "style-sheet", "script", "font", "media", "raw", "document" ], 273 [["image", "style-sheet", "script", "font", "media", "raw"],
232 ["image"], 274 ["image"],
233 ["style-sheet"], 275 ["style-sheet"],
234 ["script"], 276 ["script"],
235 ["font"], 277 ["font"],
236 ["media"], 278 ["media"],
237 ["popup"], 279 ["popup"],
238 ["media"], 280 ["media"],
239 ["raw"], 281 ["raw"],
240 ["raw"], 282 ["raw"],
241 ["raw"], // WebSocket 283 ["raw"], // WebSocket
242 ["raw"], // WebRTC: STUN 284 ["raw"], // WebRTC: STUN
243 ["raw"], // WebRTC: TURN 285 ["raw"], // WebRTC: TURN
244 ["raw"], 286 ["raw"],
245 ["document"],
246 ["raw"], 287 ["raw"],
247 ["image"], 288 ["image"],
248 ["script", "popup", "raw" ], 289 ["script", "popup", "raw" ],
249 ["style-sheet", "script", "font", "media", "raw", "document"]], 290 ["style-sheet", "script", "font", "media", "raw"]],
250 rules => rules.map(rule => rule.trigger["resource-type"]) 291 rules => rules.map(rule => rule.trigger["resource-type"])
251 ); 292 );
252 293
253 test.done(); 294 test.done();
254 }, 295 },
255 296
256 testUnsupportedfilters: function(test) 297 testUnsupportedfilters: function(test)
257 { 298 {
258 // These types of filters are currently completely unsupported. 299 // These types of filters are currently completely unsupported.
259 testRules(test, ["foo$sitekey=bar"], []); 300 testRules(test, ["foo$sitekey=bar"], []);
(...skipping 18 matching lines...) Expand all
278 ["foo.com"], 319 ["foo.com"],
279 rules => rules[0]["trigger"]["if-domain"]); 320 rules => rules[0]["trigger"]["if-domain"]);
280 321
281 test.done(); 322 test.done();
282 }, 323 },
283 324
284 testUnicode: function(test) 325 testUnicode: function(test)
285 { 326 {
286 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], 327 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"],
287 rules => rules[0]["trigger"]["if-domain"]); 328 rules => rules[0]["trigger"]["if-domain"]);
288 testRules(test, ["🐈$domain=🐈.cat"], []); 329 testRules(test, ["||🐈"], "^[^:]+:(//)?([^/]+\\.)?xn--zn8h",
289 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"]);
290 338
291 test.done(); 339 test.done();
292 }, 340 },
293 341
294 testWebSocket: function(test) 342 testWebSocket: function(test)
295 { 343 {
296 testRules(test, ["foo$websocket"], [ 344 testRules(test, ["foo$websocket"], [
297 {trigger: {"url-filter": "^wss?://.*foo", "resource-type": ["raw"]}, 345 {trigger: {"url-filter": "^wss?://.*foo", "resource-type": ["raw"]},
298 action: {type: "block"}} 346 action: {type: "block"}}
299 ]); 347 ]);
300 348
301 test.done(); 349 test.done();
302 }, 350 },
303 351
304 testWebRTC: function(test) 352 testWebRTC: function(test)
305 { 353 {
306 testRules(test, ["foo$webrtc"], [ 354 testRules(test, ["foo$webrtc"], [
307 {trigger: {"url-filter": "^stuns?:.*foo", "resource-type": ["raw"]}, 355 {trigger: {"url-filter": "^stuns?:.*foo", "resource-type": ["raw"]},
308 action: {type: "block"}}, 356 action: {type: "block"}},
309 {trigger: {"url-filter": "^turns?:.*foo", "resource-type": ["raw"]}, 357 {trigger: {"url-filter": "^turns?:.*foo", "resource-type": ["raw"]},
310 action: {type: "block"}} 358 action: {type: "block"}}
311 ]); 359 ]);
312 360
313 test.done(); 361 test.done();
314 } 362 }
315 }; 363 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld