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

Delta Between Two Patch Sets: test/filterClasses.js

Issue 29900557: Issue 7016 - Convert serialization functions into generators (Closed)
Left Patch Set: Address PS2 Comments Created Oct. 12, 2018, 3:46 a.m.
Right Patch Set: Actually address nits Created Oct. 23, 2018, 3:21 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 | « lib/subscriptionClasses.js ('k') | test/subscriptionClasses.js » ('j') | 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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 for (let [domain, isIncluded] of filter.domains) 76 for (let [domain, isIncluded] of filter.domains)
77 { 77 {
78 if (domain != "") 78 if (domain != "")
79 domains.push(isIncluded ? domain : "~" + domain); 79 domains.push(isIncluded ? domain : "~" + domain);
80 } 80 }
81 } 81 }
82 result.push("domains=" + domains.sort().join("|")); 82 result.push("domains=" + domains.sort().join("|"));
83 83
84 if (filter instanceof RegExpFilter) 84 if (filter instanceof RegExpFilter)
85 { 85 {
86 result.push("regexp=" + filter.regexp.source); 86 result.push("regexp=" + (filter.regexp ? filter.regexp.source : null));
87 result.push("contentType=" + filter.contentType); 87 result.push("contentType=" + filter.contentType);
88 result.push("matchCase=" + filter.matchCase); 88 result.push("matchCase=" + filter.matchCase);
89 89
90 let sitekeys = filter.sitekeys || []; 90 let sitekeys = filter.sitekeys || [];
91 result.push("sitekeys=" + sitekeys.slice().sort().join("|")); 91 result.push("sitekeys=" + sitekeys.slice().sort().join("|"));
92 92
93 result.push("thirdParty=" + filter.thirdParty); 93 result.push("thirdParty=" + filter.thirdParty);
94 if (filter instanceof BlockingFilter) 94 if (filter instanceof BlockingFilter)
95 { 95 {
96 result.push("type=filterlist"); 96 result.push("type=filterlist");
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 { 153 {
154 addProperty("disabled", "false"); 154 addProperty("disabled", "false");
155 addProperty("lastHit", "0"); 155 addProperty("lastHit", "0");
156 addProperty("hitCount", "0"); 156 addProperty("hitCount", "0");
157 } 157 }
158 if (type == "whitelist" || type == "filterlist") 158 if (type == "whitelist" || type == "filterlist")
159 { 159 {
160 addProperty("contentType", 0x7FFFFFFF & ~( 160 addProperty("contentType", 0x7FFFFFFF & ~(
161 t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK 161 t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK
162 )); 162 ));
163 addProperty("regexp", "null");
163 addProperty("matchCase", "false"); 164 addProperty("matchCase", "false");
164 addProperty("thirdParty", "null"); 165 addProperty("thirdParty", "null");
165 addProperty("domains", ""); 166 addProperty("domains", "");
166 addProperty("sitekeys", ""); 167 addProperty("sitekeys", "");
167 } 168 }
168 if (type == "filterlist") 169 if (type == "filterlist")
169 { 170 {
170 addProperty("collapse", "null"); 171 addProperty("collapse", "null");
171 addProperty("csp", "null"); 172 addProperty("csp", "null");
172 addProperty("rewrite", "null"); 173 addProperty("rewrite", "null");
(...skipping 16 matching lines...) Expand all
189 addDefaults(expected); 190 addDefaults(expected);
190 191
191 let filter = Filter.fromText(text); 192 let filter = Filter.fromText(text);
192 if (postInit) 193 if (postInit)
193 postInit(filter); 194 postInit(filter);
194 let result = serializeFilter(filter); 195 let result = serializeFilter(filter);
195 test.equal(result.sort().join("\n"), expected.sort().join("\n"), text); 196 test.equal(result.sort().join("\n"), expected.sort().join("\n"), text);
196 197
197 // Test round-trip 198 // Test round-trip
198 let filter2; 199 let filter2;
199 filter2 = Filter.fromText(filter.text); 200 let buffer = [...filter.serialize()];
201 if (buffer.length)
202 {
203 let map = Object.create(null);
204 for (let line of buffer.slice(1))
205 {
206 if (/(.*?)=(.*)/.test(line))
207 map[RegExp.$1] = RegExp.$2;
208 }
209 filter2 = Filter.fromObject(map);
210 }
211 else
212 filter2 = Filter.fromText(filter.text);
200 213
201 test.equal(serializeFilter(filter).join("\n"), serializeFilter(filter2).join(" \n"), text + " deserialization"); 214 test.equal(serializeFilter(filter).join("\n"), serializeFilter(filter2).join(" \n"), text + " deserialization");
202 } 215 }
203 216
204 exports.testFilterClassDefinitions = function(test) 217 exports.testFilterClassDefinitions = function(test)
205 { 218 {
206 test.equal(typeof Filter, "function", "typeof Filter"); 219 test.equal(typeof Filter, "function", "typeof Filter");
207 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); 220 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter");
208 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); 221 test.equal(typeof CommentFilter, "function", "typeof CommentFilter");
209 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); 222 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 checkElemHideEmulationFilterInvalid("~foo.com"); 262 checkElemHideEmulationFilterInvalid("~foo.com");
250 checkElemHideEmulationFilterInvalid("~foo.com,~bar.com"); 263 checkElemHideEmulationFilterInvalid("~foo.com,~bar.com");
251 checkElemHideEmulationFilterInvalid("foo"); 264 checkElemHideEmulationFilterInvalid("foo");
252 checkElemHideEmulationFilterInvalid("~foo.com,bar"); 265 checkElemHideEmulationFilterInvalid("~foo.com,bar");
253 266
254 test.done(); 267 test.done();
255 }; 268 };
256 269
257 exports.testFiltersWithState = function(test) 270 exports.testFiltersWithState = function(test)
258 { 271 {
259 compareFilter(test, "blabla", ["type=filterlist", "text=blabla", "regexp=blabl a"]); 272 compareFilter(test, "blabla", ["type=filterlist", "text=blabla"]);
260 compareFilter( 273 compareFilter(
261 test, "blabla_default", ["type=filterlist", "text=blabla_default", "regexp=b labla_default"], 274 test, "blabla_default", ["type=filterlist", "text=blabla_default"],
262 filter => 275 filter =>
263 { 276 {
264 filter.disabled = false; 277 filter.disabled = false;
265 filter.hitCount = 0; 278 filter.hitCount = 0;
266 filter.lastHit = 0; 279 filter.lastHit = 0;
267 } 280 }
268 ); 281 );
269 compareFilter( 282 compareFilter(
270 test, "blabla_non_default", 283 test, "blabla_non_default",
271 ["type=filterlist", "text=blabla_non_default", "regexp=blabla_non_default", "disabled=true", "hitCount=12", "lastHit=20"], 284 ["type=filterlist", "text=blabla_non_default", "disabled=true", "hitCount=12 ", "lastHit=20"],
272 filter => 285 filter =>
273 { 286 {
274 filter.disabled = true; 287 filter.disabled = true;
275 filter.hitCount = 12; 288 filter.hitCount = 12;
276 filter.lastHit = 20; 289 filter.lastHit = 20;
277 } 290 }
278 ); 291 );
279 292
280 test.done(); 293 test.done();
281 }; 294 };
282 295
283 exports.testSpecialCharacters = function(test) 296 exports.testSpecialCharacters = function(test)
284 { 297 {
285 compareFilter(test, "/ddd|f?a[s]d/", ["type=filterlist", "text=/ddd|f?a[s]d/", "regexp=ddd|f?a[s]d"]); 298 compareFilter(test, "/ddd|f?a[s]d/", ["type=filterlist", "text=/ddd|f?a[s]d/", "regexp=ddd|f?a[s]d"]);
286 compareFilter(test, "*asdf*d**dd*", ["type=filterlist", "text=*asdf*d**dd*", " regexp=asdf.*d.*dd"]); 299 compareFilter(test, "*asdf*d**dd*", ["type=filterlist", "text=*asdf*d**dd*", " regexp=asdf.*d.*dd"]);
287 compareFilter(test, "|*asd|f*d**dd*|", ["type=filterlist", "text=|*asd|f*d**dd *|", "regexp=^.*asd\\|f.*d.*dd.*$"]); 300 compareFilter(test, "|*asd|f*d**dd*|", ["type=filterlist", "text=|*asd|f*d**dd *|", "regexp=^.*asd\\|f.*d.*dd.*$"]);
288 compareFilter(test, "dd[]{}$%<>&()d", ["type=filterlist", "text=dd[]{}$%<>&()d ", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d"]); 301 compareFilter(test, "dd[]{}$%<>&()*d", ["type=filterlist", "text=dd[]{}$%<>&() *d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\).*d"]);
289 302
290 // Leading and trailing wildcards should be left in for rewrite filters (#6868 ). 303 // Leading and trailing wildcards should be left in for rewrite filters (#6868 ).
291 compareFilter(test, "*asdf*d**dd*$rewrite=", ["type=filterlist", "text=*asdf*d **dd*$rewrite=", "regexp=.*asdf.*d.*dd.*", "rewrite=", "contentType=" + (default Types & ~(t.SCRIPT | t.SUBDOCUMENT | t.OBJECT | t.OBJECT_SUBREQUEST))]); 304 compareFilter(test, "*asdf*d**dd*$rewrite=", ["type=filterlist", "text=*asdf*d **dd*$rewrite=", "regexp=.*asdf.*d.*dd.*", "rewrite=", "contentType=" + (default Types & ~(t.SCRIPT | t.SUBDOCUMENT | t.OBJECT | t.OBJECT_SUBREQUEST))]);
292 305
293 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); 306 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]);
294 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); 307 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]);
295 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); 308 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]);
296 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]); 309 compareFilter(test, "@@dd[]{}$%<>&()*d", ["type=whitelist", "text=@@dd[]{}$%<> &()*d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\).*d", "contentType=" + defaul tTypes]);
297 310
298 test.done(); 311 test.done();
299 }; 312 };
300 313
301 exports.testFilterOptions = function(test) 314 exports.testFilterOptions = function(test)
302 { 315 {
303 compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,dom ain=FOO.cOm,sitekey=foo", ["type=filterlist", "text=bla$match-case,csp=first csp ,script,other,third-party,domain=FOO.cOm,sitekey=foo", "regexp=bla", "matchCase= true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domain s=foo.com", "sitekeys=FOO", "csp=first csp"]); 316 compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,dom ain=FOO.cOm,sitekey=foo", ["type=filterlist", "text=bla$match-case,csp=first csp ,script,other,third-party,domain=FOO.cOm,sitekey=foo", "matchCase=true", "conten tType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=foo.com", "s itekeys=FOO", "csp=first csp"]);
304 compareFilter(test, "bla$~match-case,~csp=csp,~script,~other,~third-party,doma in=~bAr.coM", ["type=filterlist", "text=bla$~match-case,~csp=csp,~script,~other, ~third-party,domain=~bAr.coM", "regexp=bla", "contentType=" + (defaultTypes & ~( t.SCRIPT | t.OTHER)), "thirdParty=false", "domains=~bar.com"]); 317 compareFilter(test, "bla$~match-case,~csp=csp,~script,~other,~third-party,doma in=~bAr.coM", ["type=filterlist", "text=bla$~match-case,~csp=csp,~script,~other, ~third-party,domain=~bAr.coM", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.O THER)), "thirdParty=false", "domains=~bar.com"]);
305 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bAR.foO.Com|~Foo.Bar.com,csp=c s p,sitekey=foo|bar", ["type=whitelist", "text=@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bAR.foO .Com|~Foo.Bar.com,csp=c s p,sitekey=foo|bar", "regexp=bla", "matchCase=true", "c ontentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=bar.com |foo.com|~bar.foo.com|~foo.bar.com", "sitekeys=BAR|FOO"]); 318 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bAR.foO.Com|~Foo.Bar.com,csp=c s p,sitekey=foo|bar", ["type=whitelist", "text=@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bAR.foO .Com|~Foo.Bar.com,csp=c s p,sitekey=foo|bar", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=bar.com|foo.com|~bar. foo.com|~foo.bar.com", "sitekeys=BAR|FOO"]);
306 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,sitekey=foo|bar", ["type=whitelist", "text=@@b la$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo. bar.com,sitekey=foo|bar", "regexp=bla", "matchCase=true", "contentType=" + (t.SC RIPT | t.OTHER), "thirdParty=true", "domains=bar.com|foo.com|~bar.foo.com|~foo.b ar.com", "sitekeys=BAR|FOO"]); 319 compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com| bar.com|~bar.foo.com|~foo.bar.com,sitekey=foo|bar", ["type=whitelist", "text=@@b la$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo. bar.com,sitekey=foo|bar", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER ), "thirdParty=true", "domains=bar.com|foo.com|~bar.foo.com|~foo.bar.com", "site keys=BAR|FOO"]);
307 compareFilter(test, "||content.server.com/files/*.php$rewrite=$1", ["type=filt erlist", "text=||content.server.com/files/*.php$rewrite=$1", "regexp=^[\\w\\-]+: \\/+(?!\\/)(?:[^\\/]+\\.)?content\\.server\\.com\\/files\\/.*\\.php", "matchCase =false", "rewrite=$1", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.SUBDOCUME NT | t.OBJECT | t.OBJECT_SUBREQUEST))]); 320 compareFilter(test, "||content.server.com/files/*.php$rewrite=$1", ["type=filt erlist", "text=||content.server.com/files/*.php$rewrite=$1", "regexp=^[\\w\\-]+: \\/+(?!\\/)(?:[^\\/]+\\.)?content\\.server\\.com\\/files\\/.*\\.php", "matchCase =false", "rewrite=$1", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.SUBDOCUME NT | t.OBJECT | t.OBJECT_SUBREQUEST))]);
308 321
309 // background and image should be the same for backwards compatibility 322 // background and image should be the same for backwards compatibility
310 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]); 323 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "conten tType=" + (t.IMAGE)]);
311 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]); 324 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "contentType=" + (t.IMAGE)]);
312 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 325 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "cont entType=" + (defaultTypes & ~t.IMAGE)]);
313 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 326 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "contentType=" + (defaultTypes & ~t.IMAGE)]);
314 327
315 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]); 328 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
316 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 329 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]);
317 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 330 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
318 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text= @@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.DOCUMENT)]); 331 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text= @@bla$~script,~other,document", "contentType=" + (defaultTypes & ~(t.SCRIPT | t. OTHER) | t.DOCUMENT)]);
319 compareFilter(test, "@@bla$~script,~other,~document", ["type=whitelist", "text =@@bla$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); 332 compareFilter(test, "@@bla$~script,~other,~document", ["type=whitelist", "text =@@bla$~script,~other,~document", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
320 compareFilter(test, "@@bla$document", ["type=whitelist", "text=@@bla$document" , "regexp=bla", "contentType=" + t.DOCUMENT]); 333 compareFilter(test, "@@bla$document", ["type=whitelist", "text=@@bla$document" , "contentType=" + t.DOCUMENT]);
321 compareFilter(test, "@@bla$~script,~other,elemhide", ["type=whitelist", "text= @@bla$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.ELEMHIDE)]); 334 compareFilter(test, "@@bla$~script,~other,elemhide", ["type=whitelist", "text= @@bla$~script,~other,elemhide", "contentType=" + (defaultTypes & ~(t.SCRIPT | t. OTHER) | t.ELEMHIDE)]);
322 compareFilter(test, "@@bla$~script,~other,~elemhide", ["type=whitelist", "text =@@bla$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); 335 compareFilter(test, "@@bla$~script,~other,~elemhide", ["type=whitelist", "text =@@bla$~script,~other,~elemhide", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
323 compareFilter(test, "@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide" , "regexp=bla", "contentType=" + t.ELEMHIDE]); 336 compareFilter(test, "@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide" , "contentType=" + t.ELEMHIDE]);
324 337
325 compareFilter(test, "@@bla$~script,~other,donottrack", ["type=invalid", "text= @@bla$~script,~other,donottrack", "reason=filter_unknown_option"]); 338 compareFilter(test, "@@bla$~script,~other,donottrack", ["type=invalid", "text= @@bla$~script,~other,donottrack", "reason=filter_unknown_option"]);
326 compareFilter(test, "@@bla$~script,~other,~donottrack", ["type=invalid", "text =@@bla$~script,~other,~donottrack", "reason=filter_unknown_option"]); 339 compareFilter(test, "@@bla$~script,~other,~donottrack", ["type=invalid", "text =@@bla$~script,~other,~donottrack", "reason=filter_unknown_option"]);
327 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac k", "reason=filter_unknown_option"]); 340 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac k", "reason=filter_unknown_option"]);
328 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea son=filter_unknown_option"]); 341 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea son=filter_unknown_option"]);
329 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f oobar", "reason=filter_unknown_option"]); 342 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f oobar", "reason=filter_unknown_option"]);
330 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar, image", "reason=filter_unknown_option"]); 343 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar, image", "reason=filter_unknown_option"]);
331 344
332 compareFilter(test, "bla$csp", ["type=invalid", "text=bla$csp", "reason=filter _invalid_csp"]); 345 compareFilter(test, "bla$csp", ["type=invalid", "text=bla$csp", "reason=filter _invalid_csp"]);
333 compareFilter(test, "bla$csp=", ["type=invalid", "text=bla$csp=", "reason=filt er_invalid_csp"]); 346 compareFilter(test, "bla$csp=", ["type=invalid", "text=bla$csp=", "reason=filt er_invalid_csp"]);
347
348 // Blank CSP values are allowed for whitelist filters.
349 compareFilter(test, "@@bla$csp", ["type=whitelist", "text=@@bla$csp", "content Type=" + t.CSP]);
350 compareFilter(test, "@@bla$csp=", ["type=whitelist", "text=@@bla$csp=", "conte ntType=" + t.CSP]);
351
334 compareFilter(test, "bla$csp=report-uri", ["type=invalid", "text=bla$csp=repor t-uri", "reason=filter_invalid_csp"]); 352 compareFilter(test, "bla$csp=report-uri", ["type=invalid", "text=bla$csp=repor t-uri", "reason=filter_invalid_csp"]);
335 compareFilter(test, "bla$csp=foo,csp=report-to", ["type=invalid", "text=bla$cs p=foo,csp=report-to", "reason=filter_invalid_csp"]); 353 compareFilter(test, "bla$csp=foo,csp=report-to", ["type=invalid", "text=bla$cs p=foo,csp=report-to", "reason=filter_invalid_csp"]);
336 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla $csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]); 354 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla $csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]);
337 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp =foo,csp=base-uri", "reason=filter_invalid_csp"]); 355 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp =foo,csp=base-uri", "reason=filter_invalid_csp"]);
338 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp "]); 356 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp "]);
339 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); 357 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]);
340 358
341 test.done(); 359 test.done();
342 }; 360 };
343 361
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 normalized, 508 normalized,
491 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p" 509 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p"
492 ); 510 );
493 compareFilter( 511 compareFilter(
494 test, normalized, [ 512 test, normalized, [
495 "type=filterlist", 513 "type=filterlist",
496 "text=" + normalized, 514 "text=" + normalized,
497 "csp=c s p", 515 "csp=c s p",
498 "domains=domain.com|foo.com", 516 "domains=domain.com|foo.com",
499 "sitekeys=FOO", 517 "sitekeys=FOO",
500 "regexp=b\\$la",
501 "contentType=" + t.CSP 518 "contentType=" + t.CSP
502 ] 519 ]
503 ); 520 );
504 521
505 // Some $csp edge cases 522 // Some $csp edge cases
506 test.equal(Filter.normalize("$csp= "), 523 test.equal(Filter.normalize("$csp= "),
507 "$csp="); 524 "$csp=");
508 test.equal(Filter.normalize("$csp= c s p"), 525 test.equal(Filter.normalize("$csp= c s p"),
509 "$csp=c s p"); 526 "$csp=c s p");
510 test.equal(Filter.normalize("$$csp= c s p"), 527 test.equal(Filter.normalize("$$csp= c s p"),
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 test.equal( 602 test.equal(
586 filterStrip.rewriteUrl("http://example.com/?tag"), 603 filterStrip.rewriteUrl("http://example.com/?tag"),
587 "http://example.com/?" 604 "http://example.com/?"
588 ); 605 );
589 606
590 test.done(); 607 test.done();
591 }; 608 };
592 609
593 exports.testDomainMapDeduplication = function(test) 610 exports.testDomainMapDeduplication = function(test)
594 { 611 {
595 let filter1 = Filter.fromText("example.com##.foo"); 612 let filter1 = Filter.fromText("foo$domain=blocking.example.com");
596 let filter2 = Filter.fromText("example.com##.bar"); 613 let filter2 = Filter.fromText("bar$domain=blocking.example.com");
614 let filter3 = Filter.fromText("elemhide.example.com##.foo");
615 let filter4 = Filter.fromText("elemhide.example.com##.bar");
597 616
598 // This compares the references to make sure that both refer to the same 617 // This compares the references to make sure that both refer to the same
599 // object (#6815). 618 // object (#6815).
600 test.equal(filter1.domains, filter2.domains); 619 test.equal(filter1.domains, filter2.domains);
601 620
602 let filter3 = Filter.fromText("www.example.com##.bar"); 621 // For element hiding filters, the value of the property is cached internally
603 622 // only on second access.
604 test.notEqual(filter2.domains, filter3.domains); 623 test.notEqual(filter3.domains, filter4.domains);
605 624 test.equal(filter3.domains, filter4.domains);
606 test.done(); 625
607 }; 626 let filter5 = Filter.fromText("bar$domain=www.example.com");
627 let filter6 = Filter.fromText("www.example.com##.bar");
628
629 test.notEqual(filter2.domains, filter5.domains);
630
631 // Check twice for element hiding filters to make sure the internal cached
632 // values are also not equal.
633 test.notEqual(filter4.domains, filter6.domains);
634 test.notEqual(filter4.domains, filter6.domains);
635
636 test.done();
637 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld