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: Created May 31, 2017, 2:42 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, [
Manish Jethani 2017/05/31 02:51:43 We can talk about this. As I said earlier, I don't
Sebastian Noack 2017/05/31 07:09:26 A pattern of "http://example.com" should match any
Manish Jethani 2017/05/31 07:22:46 I see what you mean. In that case we should check
Sebastian Noack 2017/05/31 08:05:46 How about this: * If the filter neither starts wi
Manish Jethani 2017/06/02 08:02:36 These rules are both complicated and wrong. For ex
Sebastian Noack 2017/06/02 10:58:50 Note that "raw" is for all requests initiated by c
Manish Jethani 2017/07/03 18:34:52 Makes sense, done.
88 {trigger: {"url-filter": "^https?://.*/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": "^https?://([^/]+\\.)?test\\.com", 89 "url-filter": "^[^:]+:(//)?.*/foo",
90 "resource-type": ["image", "style-sheet", "script", "font",
91 "media", "raw"]
92 },
93 action: {type: "block"}
94 },
95 {
96 trigger: {
97 "url-filter": "^[^:]+:(//)?([^/]+\\.)?test\\.com([^-_.%a-z0-9].*)?$",
98 "url-filter-is-case-sensitive": true,
99 "resource-type": ["image", "style-sheet", "script", "font",
100 "media", "raw", "document"],
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 }
135 ]);
136
137 testRules(test, ["||example.com"], [
138 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?example\\.com",
93 "url-filter-is-case-sensitive": true, 139 "url-filter-is-case-sensitive": true,
94 "resource-type": ["image", "style-sheet", "script", "font", 140 "resource-type": ["image", "style-sheet", "script", "font",
95 "media", "raw", "document"]}, 141 "media", "raw", "document"],
96 action: {type: "block"}}, 142 "unless-top-url": ["^[^:]+:(//)?([^/]+\\.)?example\\.com"],
97 {trigger: {"url-filter": "^http://example\\.com/foo", 143 "top-url-filter-is-case-sensitive": true},
98 "resource-type": ["image", "style-sheet", "script", "font",
99 "media", "raw", "document"]},
100 action: {type: "block"}}
101 ]);
102
103 testRules(test, ["||example.com"], [
104 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com",
105 "url-filter-is-case-sensitive": true,
106 "resource-type": ["image", "style-sheet", "script", "font",
107 "media", "raw", "document"]},
108 144
109 action: {type: "block"}} 145 action: {type: "block"}}
110 ]); 146 ]);
111 147
112 // Rules which would match no resource-types shouldn't be generated. 148 // Rules which would match no resource-types shouldn't be generated.
113 testRules(test, ["foo$document", "||foo.com$document"], []); 149 testRules(test, ["foo$document", "||foo.com$document"], []);
114 150
115 test.done(); 151 test.done();
116 }, 152 },
117 153
118 testRequestFilterExceptions: function(test) 154 testRequestFilterExceptions: function(test)
119 { 155 {
120 testRules(test, ["@@example.com"], [ 156 testRules(test, ["@@example.com"], [
121 {trigger: {"url-filter": "^https?://.*example\\.com", 157 {trigger: {"url-filter": "^[^:]+:(//)?.*example\\.com",
122 "resource-type": ["image", "style-sheet", "script", "font", 158 "resource-type": ["image", "style-sheet", "script", "font",
123 "media", "raw", "document"]}, 159 "media", "raw", "document"]},
124 action: {type: "ignore-previous-rules"}} 160 action: {type: "ignore-previous-rules"}}
125 ]); 161 ]);
126 162
127 testRules(test, ["@@||example.com"], [ 163 testRules(test, ["@@||example.com"], [
128 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 164 {trigger: {"url-filter": "^[^:]+:(//)?([^/]+\\.)?example\\.com",
129 "url-filter-is-case-sensitive": true, 165 "url-filter-is-case-sensitive": true,
130 "resource-type": ["image", "style-sheet", "script", "font", 166 "resource-type": ["image", "style-sheet", "script", "font",
131 "media", "raw", "document"]}, 167 "media", "raw", "document"]},
132 action: {type: "ignore-previous-rules"}} 168 action: {type: "ignore-previous-rules"}}
133 ]); 169 ]);
134 170
135 test.done(); 171 test.done();
136 }, 172 },
137 173
138 testElementIDattributeFormat: function(test) 174 testElementIDattributeFormat: function(test)
139 { 175 {
140 testRules(test, 176 testRules(test,
141 ["###example", "test.com###EXAMPLE"], 177 ["###example", "test.com###EXAMPLE"],
142 ["[id=example]", "[id=EXAMPLE]"], 178 ["[id=example]", "[id=EXAMPLE]"],
143 rules => rules.map(rule => rule.action.selector)); 179 rules => rules.map(rule => rule.action.selector));
144 180
145 test.done(); 181 test.done();
146 }, 182 },
147 183
148 testDomainWhitelisting: function(test) 184 testDomainWhitelisting: function(test)
149 { 185 {
150 testRules(test, ["@@||example.com^$document"], [ 186 testRules(test, ["@@||example.com^$document"], [
151 {trigger: {"url-filter": ".*", 187 {
152 "if-domain": ["*example.com"]}, 188 trigger: {
153 action: {type: "ignore-previous-rules"}} 189 "url-filter": ".*",
190 "if-domain": ["*example.com"]
191 },
192 action: {type: "ignore-previous-rules"}
193 }
154 ]); 194 ]);
155 testRules(test, ["@@||example.com^$document,image"], [ 195 testRules(test, ["@@||example.com^$document,image"], [
156 {trigger: {"url-filter": ".*", 196 {
157 "if-domain": ["*example.com"]}, 197 trigger: {
158 action: {type: "ignore-previous-rules"}}, 198 "url-filter": ".*",
159 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 199 "if-domain": ["*example.com"]
160 "url-filter-is-case-sensitive": true, 200 },
161 "resource-type": ["image"]}, 201 action: {type: "ignore-previous-rules"}
162 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 }
163 ]); 211 ]);
164 testRules(test, ["@@||example.com/path^$font,document"], [ 212 testRules(test, ["@@||example.com/path^$font,document"], [
165 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com/path", 213 {
166 "resource-type": ["font"]}, 214 trigger: {
167 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 }
168 ]); 221 ]);
169 222
170 test.done(); 223 test.done();
171 }, 224 },
172 225
173 testGenericblockExceptions: function(test) 226 testGenericblockExceptions: function(test)
174 { 227 {
175 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"], 228 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"],
176 [[undefined, ["*example.com"]]], 229 [[undefined, ["*example.com"]]],
177 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
210 263
211 testRequestTypeMapping: function(test) 264 testRequestTypeMapping: function(test)
212 { 265 {
213 testRules( 266 testRules(
214 test, 267 test,
215 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media", 268 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media",
216 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest", 269 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest",
217 "11$websocket", "12$webrtc", 270 "11$websocket", "12$webrtc",
218 "13$ping", "14$subdocument", "15$other", "16$IMAGE", 271 "13$ping", "14$subdocument", "15$other", "16$IMAGE",
219 "17$script,PING,Popup", "18$~image"], 272 "17$script,PING,Popup", "18$~image"],
220 [["image", "style-sheet", "script", "font", "media", "raw", "document" ], 273 [["image", "style-sheet", "script", "font", "media", "raw"],
221 ["image"], 274 ["image"],
222 ["style-sheet"], 275 ["style-sheet"],
223 ["script"], 276 ["script"],
224 ["font"], 277 ["font"],
225 ["media"], 278 ["media"],
226 ["popup"], 279 ["popup"],
227 ["media"], 280 ["media"],
228 ["raw"], 281 ["raw"],
229 ["raw"], 282 ["raw"],
230 ["raw"], // WebSocket 283 ["raw"], // WebSocket
231 ["raw"], // WebRTC: STUN 284 ["raw"], // WebRTC: STUN
232 ["raw"], // WebRTC: TURN 285 ["raw"], // WebRTC: TURN
233 ["raw"], 286 ["raw"],
234 ["document"],
235 ["raw"], 287 ["raw"],
236 ["image"], 288 ["image"],
237 ["script", "popup", "raw" ], 289 ["script", "popup", "raw" ],
238 ["style-sheet", "script", "font", "media", "raw", "document"]], 290 ["style-sheet", "script", "font", "media", "raw"]],
239 rules => rules.map(rule => rule.trigger["resource-type"]) 291 rules => rules.map(rule => rule.trigger["resource-type"])
240 ); 292 );
241 293
242 test.done(); 294 test.done();
243 }, 295 },
244 296
245 testUnsupportedfilters: function(test) 297 testUnsupportedfilters: function(test)
246 { 298 {
247 // These types of filters are currently completely unsupported. 299 // These types of filters are currently completely unsupported.
248 testRules(test, ["foo$sitekey=bar"], []); 300 testRules(test, ["foo$sitekey=bar"], []);
(...skipping 18 matching lines...) Expand all
267 ["foo.com"], 319 ["foo.com"],
268 rules => rules[0]["trigger"]["if-domain"]); 320 rules => rules[0]["trigger"]["if-domain"]);
269 321
270 test.done(); 322 test.done();
271 }, 323 },
272 324
273 testUnicode: function(test) 325 testUnicode: function(test)
274 { 326 {
275 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], 327 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"],
276 rules => rules[0]["trigger"]["if-domain"]); 328 rules => rules[0]["trigger"]["if-domain"]);
277 testRules(test, ["🐈$domain=🐈.cat"], []); 329 testRules(test, ["||🐈"], "^[^:]+:(//)?([^/]+\\.)?xn--zn8h",
278 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"]);
279 338
280 test.done(); 339 test.done();
281 }, 340 },
282 341
283 testWebSocket: function(test) 342 testWebSocket: function(test)
284 { 343 {
285 testRules(test, ["foo$websocket"], [ 344 testRules(test, ["foo$websocket"], [
286 {trigger: {"url-filter": "^wss?://.*foo", "resource-type": ["raw"]}, 345 {trigger: {"url-filter": "^wss?://.*foo", "resource-type": ["raw"]},
287 action: {type: "block"}} 346 action: {type: "block"}}
288 ]); 347 ]);
289 348
290 test.done(); 349 test.done();
291 }, 350 },
292 351
293 testWebRTC: function(test) 352 testWebRTC: function(test)
294 { 353 {
295 testRules(test, ["foo$webrtc"], [ 354 testRules(test, ["foo$webrtc"], [
296 {trigger: {"url-filter": "^stuns?:.*foo", "resource-type": ["raw"]}, 355 {trigger: {"url-filter": "^stuns?:.*foo", "resource-type": ["raw"]},
297 action: {type: "block"}}, 356 action: {type: "block"}},
298 {trigger: {"url-filter": "^turns?:.*foo", "resource-type": ["raw"]}, 357 {trigger: {"url-filter": "^turns?:.*foo", "resource-type": ["raw"]},
299 action: {type: "block"}} 358 action: {type: "block"}}
300 ]); 359 ]);
301 360
302 test.done(); 361 test.done();
303 } 362 }
304 }; 363 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld