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

Delta Between Two Patch Sets: test/filterClasses.js

Issue 29680689: [$csp2 adblockpluscore] Issue 6329 - Add the CSP filter type (Closed)
Left Patch Set: Created Jan. 26, 2018, 5:41 p.m.
Right Patch Set: Addressed Sebastian's feedback Created March 21, 2018, 4:51 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/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-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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || 135 if (type == "whitelist" || type == "filterlist" || type == "elemhide" ||
136 type == "elemhideexception" || type == "elemhideemulation") 136 type == "elemhideexception" || type == "elemhideemulation")
137 { 137 {
138 addProperty("disabled", "false"); 138 addProperty("disabled", "false");
139 addProperty("lastHit", "0"); 139 addProperty("lastHit", "0");
140 addProperty("hitCount", "0"); 140 addProperty("hitCount", "0");
141 } 141 }
142 if (type == "whitelist" || type == "filterlist") 142 if (type == "whitelist" || type == "filterlist")
143 { 143 {
144 addProperty("contentType", 0x7FFFFFFF & ~( 144 addProperty("contentType", 0x7FFFFFFF & ~(
145 RegExpFilter.typeMap.CSP | RegExpFilter.typeMap.DOCUMENT | 145 t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK
146 RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP |
147 RegExpFilter.typeMap.GENERICHIDE | RegExpFilter.typeMap.GENERICBLOCK
148 )); 146 ));
149 addProperty("matchCase", "false"); 147 addProperty("matchCase", "false");
150 addProperty("thirdParty", "null"); 148 addProperty("thirdParty", "null");
151 addProperty("domains", ""); 149 addProperty("domains", "");
152 addProperty("sitekeys", ""); 150 addProperty("sitekeys", "");
153 } 151 }
154 if (type == "filterlist") 152 if (type == "filterlist")
155 { 153 {
156 addProperty("collapse", "null"); 154 addProperty("collapse", "null");
157 addProperty("csp", "null"); 155 addProperty("csp", "null");
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); 279 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]);
282 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); 280 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]);
283 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); 281 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]);
284 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]); 282 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]);
285 283
286 test.done(); 284 test.done();
287 }; 285 };
288 286
289 exports.testFilterOptions = function(test) 287 exports.testFilterOptions = function(test)
290 { 288 {
291 compareFilter(test, "bla$match-case,script,other,third-party,domain=foo.com,si tekey=foo,csp= c s p ", ["type=filterlist", "text=bla$match-case,script,other,th ird-party,domain=foo.com,sitekey=foo,csp=c s p", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=FOO. COM", "sitekeys=FOO", "csp=c s p"]); 289 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"]);
292 compareFilter(test, "bla$~match-case,~script,~other,~third-party,domain=~bar.c om", ["type=filterlist", "text=bla$~match-case,~script,~other,~third-party,domai n=~bar.com", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER )), "thirdParty=false", "domains=~BAR.COM"]); 290 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"]);
293 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.f oo.com|~foo.bar.com,csp=c s p,sitekey=foo|bar", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=BAR.C OM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM", "sitekeys=BAR|FOO"]); 291 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"]);
292 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"]);
294 293
295 // background and image should be the same for backwards compatibility 294 // background and image should be the same for backwards compatibility
296 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]); 295 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]);
297 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]); 296 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]);
298 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 297 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
299 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 298 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
300 299
301 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]); 300 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]);
302 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 301 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
303 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 302 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
304 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text= @@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.DOCUMENT)]); 303 compareFilter(test, "@@bla$~script,~other,document", ["type=whitelist", "text= @@bla$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.DOCUMENT)]);
305 compareFilter(test, "@@bla$~script,~other,~document", ["type=whitelist", "text =@@bla$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); 304 compareFilter(test, "@@bla$~script,~other,~document", ["type=whitelist", "text =@@bla$~script,~other,~document", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
306 compareFilter(test, "@@bla$document", ["type=whitelist", "text=@@bla$document" , "regexp=bla", "contentType=" + t.DOCUMENT]); 305 compareFilter(test, "@@bla$document", ["type=whitelist", "text=@@bla$document" , "regexp=bla", "contentType=" + t.DOCUMENT]);
307 compareFilter(test, "@@bla$~script,~other,elemhide", ["type=whitelist", "text= @@bla$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.ELEMHIDE)]); 306 compareFilter(test, "@@bla$~script,~other,elemhide", ["type=whitelist", "text= @@bla$~script,~other,elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~ (t.SCRIPT | t.OTHER) | t.ELEMHIDE)]);
308 compareFilter(test, "@@bla$~script,~other,~elemhide", ["type=whitelist", "text =@@bla$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]); 307 compareFilter(test, "@@bla$~script,~other,~elemhide", ["type=whitelist", "text =@@bla$~script,~other,~elemhide", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))]);
309 compareFilter(test, "@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide" , "regexp=bla", "contentType=" + t.ELEMHIDE]); 308 compareFilter(test, "@@bla$elemhide", ["type=whitelist", "text=@@bla$elemhide" , "regexp=bla", "contentType=" + t.ELEMHIDE]);
310 309
311 compareFilter(test, "@@bla$~script,~other,donottrack", ["type=invalid", "text= @@bla$~script,~other,donottrack", "reason=filter_unknown_option"]); 310 compareFilter(test, "@@bla$~script,~other,donottrack", ["type=invalid", "text= @@bla$~script,~other,donottrack", "reason=filter_unknown_option"]);
312 compareFilter(test, "@@bla$~script,~other,~donottrack", ["type=invalid", "text =@@bla$~script,~other,~donottrack", "reason=filter_unknown_option"]); 311 compareFilter(test, "@@bla$~script,~other,~donottrack", ["type=invalid", "text =@@bla$~script,~other,~donottrack", "reason=filter_unknown_option"]);
313 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac k", "reason=filter_unknown_option"]); 312 compareFilter(test, "@@bla$donottrack", ["type=invalid", "text=@@bla$donottrac k", "reason=filter_unknown_option"]);
314 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea son=filter_unknown_option"]); 313 compareFilter(test, "@@bla$foobar", ["type=invalid", "text=@@bla$foobar", "rea son=filter_unknown_option"]);
315 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f oobar", "reason=filter_unknown_option"]); 314 compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,f oobar", "reason=filter_unknown_option"]);
316 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar, image", "reason=filter_unknown_option"]); 315 compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar, image", "reason=filter_unknown_option"]);
317 316
318 compareFilter(test, "bla$csp=report-uri", ["type=invalid", "text=bla$csp=repor t-uri", "reason=filter_invalid_csp"]); 317 compareFilter(test, "bla$csp=report-uri", ["type=invalid", "text=bla$csp=repor t-uri", "reason=filter_invalid_csp"]);
318 compareFilter(test, "bla$csp=foo,csp=report-to", ["type=invalid", "text=bla$cs p=foo,csp=report-to", "reason=filter_invalid_csp"]);
319 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla $csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]);
320 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp =foo,csp=base-uri", "reason=filter_invalid_csp"]);
321 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp "]);
322 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]);
319 323
320 test.done(); 324 test.done();
321 }; 325 };
322 326
323 exports.testElementHidingRules = function(test) 327 exports.testElementHidingRules = function(test)
324 { 328 {
325 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); 329 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]);
326 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]); 330 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]);
327 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo main=foo", "selector=ddd", "domains=FOO"]); 331 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo main=foo", "selector=ddd", "domains=FOO"]);
328 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se lectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 332 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se lectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 "type=elemhideemulation", 410 "type=elemhideemulation",
407 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", 411 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)",
408 "selectorDomain=foo.com", 412 "selectorDomain=foo.com",
409 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", 413 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)",
410 "domains=FOO.COM" 414 "domains=FOO.COM"
411 ] 415 ]
412 ); 416 );
413 test.done(); 417 test.done();
414 }; 418 };
415 419
416 exports.testFilterNormalisation = function(test) 420 exports.testFilterNormalization = function(test)
417 { 421 {
418 compareFilter(test, Filter.stripJunk(" domain.c» om## #sele ctor "), [ 422 // Line breaks etc
419 "type=elemhide", 423 test.equal(Filter.normalize("\n\t\nad\ns"),
420 "text=domain.com###sele ctor", 424 "ads");
421 "selectorDomain=domain.com", 425
422 "selector=#sele ctor", 426 // Comment filters
423 "domains=DOMAIN.COM" 427 test.equal(Filter.normalize(" ! fo o## bar "),
424 ]); 428 "! fo o## bar");
425 compareFilter(test, Filter.stripJunk(" ! fo o## » bar "), [ 429
426 "type=comment", "text=! fo o## bar" 430 // Element hiding filters
427 ]); 431 test.equal(Filter.normalize(" domain.c om## # sele ctor "),
428 compareFilter(test, Filter.stripJunk(" bl » a$sitekey= foo ,domain= do ma in.com |foo .com "), [ 432 "domain.com### sele ctor");
429 "type=filterlist", 433
430 "text=bla$sitekey=foo,domain=domain.com|foo.com", 434 // Regular filters
431 "regexp=bla", 435 let normalized = Filter.normalize(
432 "sitekeys=FOO", 436 " b$l » a$sitekey= foo ,domain= do main.com |foo .com,c sp= c s p "
433 "domains=DOMAIN.COM|FOO.COM" 437 );
434 ]); 438 test.equal(
435 compareFilter(test, Filter.stripJunk(" @@bl » a$foo= bar ,domain = ab cd ,foo"), [ 439 normalized,
436 "type=invalid", 440 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p"
437 "text=@@bla$foo=bar,domain=abcd,foo", 441 );
438 "reason=filter_unknown_option" 442 compareFilter(
439 ]); 443 test, normalized, [
440 444 "type=filterlist",
441 compareFilter(test, "bla$domain= a b ,csp= the c s p ", [ 445 "text=" + normalized,
442 "type=filterlist", 446 "csp=c s p",
443 "contentType=" + t.CSP, 447 "domains=DOMAIN.COM|FOO.COM",
444 "regexp=bla", 448 "sitekeys=FOO",
445 "text=bla$domain=ab,csp=the c s p", 449 "regexp=b\\$la",
446 "csp=the c s p", 450 "contentType=" + t.CSP
447 "domains=AB" 451 ]
448 ]); 452 );
449 compareFilter(test, Filter.stripJunk("bla$csp= the c s p ,invalid= f o o " ), [ 453
450 "type=invalid", 454 // Some $csp edge cases
451 "text=bla$csp=the c s p,invalid=foo", 455 test.equal(Filter.normalize("$csp= c s p"),
452 "reason=filter_unknown_option" 456 "$csp=c s p");
453 ]); 457 test.equal(Filter.normalize("$$csp= c s p"),
454 458 "$$csp=c s p");
455 test.done(); 459 test.equal(Filter.normalize("$$$csp= c s p"),
456 }; 460 "$$$csp=c s p");
461 test.equal(Filter.normalize("foo?csp=b a r$csp=script-src 'self'"),
462 "foo?csp=bar$csp=script-src 'self'");
463 test.equal(Filter.normalize("foo$bar=c s p = ba z,cs p = script-src 'self'"),
464 "foo$bar=csp=baz,csp=script-src 'self'");
465 test.equal(Filter.normalize("foo$csp=c s p csp= ba z,cs p = script-src 'self '"),
466 "foo$csp=c s p csp= ba z,csp=script-src 'self'");
467 test.equal(Filter.normalize("foo$csp=bar,$c sp=c s p"),
468 "foo$csp=bar,$csp=c s p");
469 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"),
470 "foo$bar$csp=ba r");
471 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "),
472 "f$o$o$csp=f o o");
473 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1= 1&$2=2&$3=3"),
474 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3");
475
476 test.done();
477 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld