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

Delta Between Two Patch Sets: test/abp2blocklist.js

Issue 29467595: Issue 5325 - Add support for separator characters (Closed) Base URL: https://hg.adblockplus.org/abp2blocklist
Left Patch Set: Created June 16, 2017, 5:25 p.m.
Right Patch Set: Rebase Created July 12, 2017, 12:45 p.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 | « lib/abp2blocklist.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([^.%A-Za-z0-9_].*)?$", "ignore-previous- rules"], 64 ["^https?://([^/:]*\\.)?test\\.com[/:]", ["*special.test.com"]]
66 ["^https?://([^/:]*\\.)?test\\.com[/:]", "css-display-none"],
67 ["^https?://([^/]+\\.)?special\\.test\\.com([^.%A-Za-z0-9_].*)?$", "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": "^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 "unless-top-url": ["^https?://.*/foo"]}, 88 trigger: {
92 action: {type: "block"}}, 89 "url-filter": "^https?://.*/foo",
93 {trigger: {"url-filter": "^https?://([^/]+\\.)?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": ["^https?://([^/]+\\.)?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": "^https?://([^/]+\\.)?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": [
102 "^https?://([^/]+\\.)?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":
120 "^https?://(.*[^-_.%A-Za-z0-9])?foo([^-_.%A-Za-z0-9].*)?$",
121 "resource-type": ["image", "style-sheet", "script", "font",
122 "media", "raw"]
123 },
124 action: {type: "block"}
125 }
105 ]); 126 ]);
106 127
107 testRules(test, ["||example.com"], [ 128 testRules(test, ["||example.com"], [
108 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com", 129 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com",
109 "url-filter-is-case-sensitive": true, 130 "url-filter-is-case-sensitive": true,
110 "resource-type": ["image", "style-sheet", "script", "font", 131 "resource-type": ["image", "style-sheet", "script", "font",
111 "media", "raw", "document"], 132 "media", "raw", "document"],
112 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"], 133 "unless-top-url": ["^https?://([^/]+\\.)?example\\.com"],
113 "top-url-filter-is-case-sensitive": true}, 134 "top-url-filter-is-case-sensitive": true},
114 135
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 ["###example", "test.com###EXAMPLE"], 168 ["###example", "test.com###EXAMPLE"],
148 ["[id=example]", "[id=EXAMPLE]"], 169 ["[id=example]", "[id=EXAMPLE]"],
149 rules => rules.map(rule => rule.action.selector)); 170 rules => rules.map(rule => rule.action.selector));
150 171
151 test.done(); 172 test.done();
152 }, 173 },
153 174
154 testDomainWhitelisting: function(test) 175 testDomainWhitelisting: function(test)
155 { 176 {
156 testRules(test, ["@@||example.com^$document"], [ 177 testRules(test, ["@@||example.com^$document"], [
157 {trigger: {"url-filter": ".*", 178 {
158 "if-domain": ["*example.com"]}, 179 trigger: {
159 action: {type: "ignore-previous-rules"}} 180 "url-filter": ".*",
181 "if-domain": ["*example.com"]
182 },
183 action: {type: "ignore-previous-rules"}
184 }
160 ]); 185 ]);
161 testRules(test, ["@@||example.com^$document,image"], [ 186 testRules(test, ["@@||example.com^$document,image"], [
162 {trigger: {"url-filter": ".*", 187 {
163 "if-domain": ["*example.com"]}, 188 trigger: {
164 action: {type: "ignore-previous-rules"}}, 189 "url-filter": ".*",
165 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com([^.%A-Za-z0-9 _].*)?$", 190 "if-domain": ["*example.com"]
166 "resource-type": ["image"]}, 191 },
167 action: {type: "ignore-previous-rules"}} 192 action: {type: "ignore-previous-rules"}
193 },
194 {
195 trigger: {
196 "url-filter": "^https?://([^/]+\\.)?example\\.com([^-_.%a-z0-9].*)?$",
197 "url-filter-is-case-sensitive": true,
198 "resource-type": ["image"]
199 },
200 action: {type: "ignore-previous-rules"}
201 }
168 ]); 202 ]);
169 testRules(test, ["@@||example.com/path^$font,document"], [ 203 testRules(test, ["@@||example.com/path^$font,document"], [
170 {trigger: {"url-filter": "^https?://([^/]+\\.)?example\\.com/path([^.%A-Za -z0-9_].*)?$", 204 {
171 "resource-type": ["font"]}, 205 trigger: {
172 action: {type: "ignore-previous-rules"}} 206 "url-filter":
207 "^https?://([^/]+\\.)?example\\.com/path([^-_.%A-Za-z0-9].*)?$",
208 "resource-type": ["font"]
209 },
210 action: {type: "ignore-previous-rules"}
211 }
173 ]); 212 ]);
174 213
175 test.done(); 214 test.done();
176 }, 215 },
177 216
178 testGenericblockExceptions: function(test) 217 testGenericblockExceptions: function(test)
179 { 218 {
180 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"], 219 testRules(test, ["^ad.jpg|", "@@||example.com^$genericblock"],
181 [[undefined, ["*example.com"]]], 220 [[undefined, ["*example.com"]]],
182 rules => rules.map(rule => [rule.trigger["if-domain"], 221 rules => rules.map(rule => [rule.trigger["if-domain"],
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 }, 253 },
215 254
216 testRequestTypeMapping: function(test) 255 testRequestTypeMapping: function(test)
217 { 256 {
218 testRules( 257 testRules(
219 test, 258 test,
220 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media", 259 ["1", "2$image", "3$stylesheet", "4$script", "5$font", "6$media",
221 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest", 260 "7$popup", "8$object", "9$object_subrequest", "10$xmlhttprequest",
222 "11$ping", "12$subdocument", "13$other", "14$IMAGE", 261 "11$ping", "12$subdocument", "13$other", "14$IMAGE",
223 "15$script,PING,Popup", "16$~image"], 262 "15$script,PING,Popup", "16$~image"],
224 [["image", "style-sheet", "script", "font", "media", "raw", "document" ], 263 [["image", "style-sheet", "script", "font", "media", "raw"],
225 ["image"], 264 ["image"],
226 ["style-sheet"], 265 ["style-sheet"],
227 ["script"], 266 ["script"],
228 ["font"], 267 ["font"],
229 ["media"], 268 ["media"],
230 ["popup"], 269 ["popup"],
231 ["media"], 270 ["media"],
232 ["raw"], 271 ["raw"],
233 ["raw"], 272 ["raw"],
234 ["raw"], 273 ["raw"],
235 ["document"],
236 ["raw"], 274 ["raw"],
237 ["image"], 275 ["image"],
238 ["script", "popup", "raw" ], 276 ["script", "popup", "raw" ],
239 ["style-sheet", "script", "font", "media", "raw", "document"]], 277 ["style-sheet", "script", "font", "media", "raw"]],
240 rules => rules.map(rule => rule.trigger["resource-type"]) 278 rules => rules.map(rule => rule.trigger["resource-type"])
241 ); 279 );
242 280
243 test.done(); 281 test.done();
244 }, 282 },
245 283
246 testUnsupportedfilters: function(test) 284 testUnsupportedfilters: function(test)
247 { 285 {
248 // These types of filters are currently completely unsupported. 286 // These types of filters are currently completely unsupported.
249 testRules(test, ["foo$sitekey=bar"], []); 287 testRules(test, ["foo$sitekey=bar"], []);
(...skipping 18 matching lines...) Expand all
268 ["foo.com"], 306 ["foo.com"],
269 rules => rules[0]["trigger"]["if-domain"]); 307 rules => rules[0]["trigger"]["if-domain"]);
270 308
271 test.done(); 309 test.done();
272 }, 310 },
273 311
274 testUnicode: function(test) 312 testUnicode: function(test)
275 { 313 {
276 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"], 314 testRules(test, ["$domain=🐈.cat"], ["*xn--zn8h.cat"],
277 rules => rules[0]["trigger"]["if-domain"]); 315 rules => rules[0]["trigger"]["if-domain"]);
278 testRules(test, ["🐈$domain=🐈.cat"], []); 316 testRules(test, ["||🐈"], "^https?://([^/]+\\.)?xn--zn8h",
279 testRules(test, ["###🐈"], []); 317 rules => rules[0]["trigger"]["url-filter"]);
318 testRules(test, ["🐈$domain=🐈.cat"], "^https?://.*%F0%9F%90%88",
319 rules => rules[0]["trigger"]["url-filter"]);
320 testRules(test, ["🐈%F0%9F%90%88$domain=🐈.cat"],
321 "^https?://.*%F0%9F%90%88%F0%9F%90%88",
322 rules => rules[0]["trigger"]["url-filter"]);
323 testRules(test, ["###🐈"], "[id=🐈]",
324 rules => rules[0]["action"]["selector"]);
280 325
281 test.done(); 326 test.done();
282 } 327 }
283 }; 328 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld