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

Delta Between Two Patch Sets: test/filterClasses.js

Issue 29737558: Issue 6538, 6781 - Implement support for snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Rebase Created June 11, 2018, 10 a.m.
Right Patch Set: Improve comment formatting Created July 11, 2018, 1:02 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
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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 const {createSandbox} = require("./_common"); 20 const {createSandbox} = require("./_common");
21 21
22 let Filter = null; 22 let Filter = null;
23 let InvalidFilter = null; 23 let InvalidFilter = null;
24 let CommentFilter = null; 24 let CommentFilter = null;
25 let ActiveFilter = null; 25 let ActiveFilter = null;
26 let RegExpFilter = null; 26 let RegExpFilter = null;
27 let BlockingFilter = null; 27 let BlockingFilter = null;
28 let ScriptFilter = null; 28 let ContentFilter = null;
29 let WhitelistFilter = null; 29 let WhitelistFilter = null;
30 let ElemHideBase = null; 30 let ElemHideBase = null;
31 let ElemHideFilter = null; 31 let ElemHideFilter = null;
32 let ElemHideException = null; 32 let ElemHideException = null;
33 let ElemHideEmulationFilter = null; 33 let ElemHideEmulationFilter = null;
34 let SnippetFilter = null; 34 let SnippetFilter = null;
35 35
36 let t = null; 36 let t = null;
37 let defaultTypes = null; 37 let defaultTypes = null;
38 38
39 exports.setUp = function(callback) 39 exports.setUp = function(callback)
40 { 40 {
41 let sandboxedRequire = createSandbox(); 41 let sandboxedRequire = createSandbox();
42 ( 42 (
43 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, 43 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter,
44 BlockingFilter, WhitelistFilter, ScriptFilter, ElemHideBase, 44 BlockingFilter, WhitelistFilter, ContentFilter, ElemHideBase,
45 ElemHideFilter, ElemHideException, ElemHideEmulationFilter, 45 ElemHideFilter, ElemHideException, ElemHideEmulationFilter,
46 SnippetFilter} = sandboxedRequire("../lib/filterClasses") 46 SnippetFilter} = sandboxedRequire("../lib/filterClasses")
47 ); 47 );
48 t = RegExpFilter.typeMap; 48 t = RegExpFilter.typeMap;
49 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP | 49 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP |
50 t.GENERICHIDE | t.GENERICBLOCK); 50 t.GENERICHIDE | t.GENERICBLOCK);
51 51
52 callback(); 52 callback();
53 }; 53 };
54 54
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } 215 }
216 216
217 exports.testFilterClassDefinitions = function(test) 217 exports.testFilterClassDefinitions = function(test)
218 { 218 {
219 test.equal(typeof Filter, "function", "typeof Filter"); 219 test.equal(typeof Filter, "function", "typeof Filter");
220 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); 220 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter");
221 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); 221 test.equal(typeof CommentFilter, "function", "typeof CommentFilter");
222 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); 222 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter");
223 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); 223 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter");
224 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); 224 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter");
225 test.equal(typeof ScriptFilter, "function", "typeof ScriptFilter"); 225 test.equal(typeof ContentFilter, "function", "typeof ContentFilter");
226 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); 226 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter");
227 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); 227 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase");
228 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); 228 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter");
229 test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); 229 test.equal(typeof ElemHideException, "function", "typeof ElemHideException");
230 test.equal(typeof ElemHideEmulationFilter, "function", 230 test.equal(typeof ElemHideEmulationFilter, "function",
231 "typeof ElemHideEmulationFilter"); 231 "typeof ElemHideEmulationFilter");
232 test.equal(typeof SnippetFilter, "function", "typeof SnippetFilter"); 232 test.equal(typeof SnippetFilter, "function", "typeof SnippetFilter");
233 233
234 test.done(); 234 test.done();
235 }; 235 };
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); 303 compareFilter(test, "@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d /", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]);
304 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]); 304 compareFilter(test, "@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*" , "regexp=asdf.*d.*dd", "contentType=" + defaultTypes]);
305 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); 305 compareFilter(test, "@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d* *dd*|", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]);
306 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]); 306 compareFilter(test, "@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>& ()d", "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTyp es]);
307 307
308 test.done(); 308 test.done();
309 }; 309 };
310 310
311 exports.testFilterOptions = function(test) 311 exports.testFilterOptions = function(test)
312 { 312 {
313 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"]); 313 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"]);
314 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"]); 314 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"]);
315 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"]); 315 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"]);
316 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"]); 316 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"]);
317 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))]); 317 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))]);
318 318
319 // background and image should be the same for backwards compatibility 319 // background and image should be the same for backwards compatibility
320 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]); 320 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]);
321 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]); 321 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]);
322 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 322 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
323 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 323 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
324 324
325 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]); 325 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]);
326 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 326 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
(...skipping 19 matching lines...) Expand all
346 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp "]); 346 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp "]);
347 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); 347 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp =foo,csp=ReFeRReR", "reason=filter_invalid_csp"]);
348 348
349 test.done(); 349 test.done();
350 }; 350 };
351 351
352 exports.testElementHidingRules = function(test) 352 exports.testElementHidingRules = function(test)
353 { 353 {
354 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); 354 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]);
355 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]); 355 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]);
356 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo mains=foo", "selector=ddd", "domains=FOO"]); 356 compareFilter(test, "fOO##ddd", ["type=elemhide", "text=fOO##ddd", "selectorDo mains=foo", "selector=ddd", "domains=foo"]);
357 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se lectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 357 compareFilter(test, "Foo,bAr##ddd", ["type=elemhide", "text=Foo,bAr##ddd", "se lectorDomains=foo,bar", "selector=ddd", "domains=bar|foo"]);
358 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", " selectorDomains=foo", "selector=ddd", "domains=FOO|~BAR"]); 358 compareFilter(test, "foo,~baR##ddd", ["type=elemhide", "text=foo,~baR##ddd", " selectorDomains=foo", "selector=ddd", "domains=foo|~bar"]);
359 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar# #ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]); 359 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar# #ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo|~baz"]);
360 360
361 test.done(); 361 test.done();
362 }; 362 };
363 363
364 exports.testElementHidingExceptions = function(test) 364 exports.testElementHidingExceptions = function(test)
365 { 365 {
366 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec tor=ddd"]); 366 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec tor=ddd"]);
367 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t ext=#@#body > div:first-child", "selector=body > div:first-child"]); 367 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t ext=#@#body > div:first-child", "selector=body > div:first-child"]);
368 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=FOO"]); 368 compareFilter(test, "fOO#@#ddd", ["type=elemhideexception", "text=fOO#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=foo"]);
369 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar# @#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 369 compareFilter(test, "Foo,bAr#@#ddd", ["type=elemhideexception", "text=Foo,bAr# @#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo"]);
370 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba r#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=FOO|~BAR"]); 370 compareFilter(test, "foo,~baR#@#ddd", ["type=elemhideexception", "text=foo,~ba R#@#ddd", "selectorDomains=foo", "selector=ddd", "domains=foo|~bar"]);
371 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo ,~baz,bar#@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO|~B AZ"]); 371 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo ,~baz,bar#@#ddd", "selectorDomains=foo,bar", "selector=ddd", "domains=bar|foo|~b az"]);
372 372
373 test.done(); 373 test.done();
374 }; 374 };
375 375
376 exports.testElemHideEmulationFilters = function(test) 376 exports.testElemHideEmulationFilters = function(test)
377 { 377 {
378 // Check valid domain combinations 378 // Check valid domain combinations
379 compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulatio n", "text=foo.com#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selector =:-abp-properties(abc)", "domains=FOO.COM"]); 379 compareFilter(test, "fOO.cOm#?#:-abp-properties(abc)", ["type=elemhideemulatio n", "text=fOO.cOm#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selector =:-abp-properties(abc)", "domains=foo.com"]);
380 compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "selectorDomains=f oo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]); 380 compareFilter(test, "Foo.com,~bAr.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=Foo.com,~bAr.com#?#:-abp-properties(abc)", "selectorDomains=f oo.com", "selector=:-abp-properties(abc)", "domains=foo.com|~bar.com"]);
381 compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemu lation", "text=foo.com,~bar#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]); 381 compareFilter(test, "foo.com,~baR#?#:-abp-properties(abc)", ["type=elemhideemu lation", "text=foo.com,~baR#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selector=:-abp-properties(abc)", "domains=foo.com|~bar"]);
382 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "selectorDomains=b ar.com", "selector=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]); 382 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "selectorDomains=b ar.com", "selector=:-abp-properties(abc)", "domains=bar.com|~foo.com"]);
383 383
384 // Check some special cases 384 // Check some special cases
385 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]); 385 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]);
386 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com# ?#abc", "selectorDomains=foo.com", "selector=abc", "domains=FOO.COM"]); 386 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com# ?#abc", "selectorDomains=foo.com", "selector=abc", "domains=foo.com"]);
387 compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-foobar(abc)", "selectorDomains=foo.com", "selector=:-abp-f oobar(abc)", "domains=FOO.COM"]); 387 compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-foobar(abc)", "selectorDomains=foo.com", "selector=:-abp-f oobar(abc)", "domains=foo.com"]);
388 compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhide emulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomains=foo .com", "selector=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]); 388 compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhide emulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomains=foo .com", "selector=aaa :-abp-properties(abc) bbb", "domains=foo.com"]);
389 compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*) )", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-imag e: url(data:*))", "selectorDomains=foo.com", "selector=:-abp-properties(|backgro und-image: url(data:*))", "domains=FOO.COM"]); 389 compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*) )", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-imag e: url(data:*))", "selectorDomains=foo.com", "selector=:-abp-properties(|backgro und-image: url(data:*))", "domains=foo.com"]);
390 390
391 // Check conversion of legacy filters 391 // Check conversion of legacy filters
392 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulati on", "text=foo.com#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selecto r=:-abp-properties(abc)", "domains=FOO.COM"]); 392 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulati on", "text=foo.com#?#:-abp-properties(abc)", "selectorDomains=foo.com", "selecto r=:-abp-properties(abc)", "domains=foo.com"]);
393 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex t("foo.com#?#:-abp-properties(abc)")); 393 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex t("foo.com#?#:-abp-properties(abc)"));
394 compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexcept ion", "text=foo.com#@#[-abp-properties='abc']", "selectorDomains=foo.com", "sele ctor=[-abp-properties='abc']", "domains=FOO.COM"]); 394 compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexcept ion", "text=foo.com#@#[-abp-properties='abc']", "selectorDomains=foo.com", "sele ctor=[-abp-properties='abc']", "domains=foo.com"]);
395 compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=elemhideemulat ion", "text=foo.com#?#[-abp-properties='abc']", "selectorDomains=foo.com", "sele ctor=[-abp-properties='abc']", "domains=FOO.COM"]); 395 compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=elemhideemulat ion", "text=foo.com#?#[-abp-properties='abc']", "selectorDomains=foo.com", "sele ctor=[-abp-properties='abc']", "domains=foo.com"]);
396 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhid eemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomains=fo o.com", "selector=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]); 396 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhid eemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomains=fo o.com", "selector=aaa :-abp-properties(abc) bbb", "domains=foo.com"]);
397 397
398 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037) . 398 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037) .
399 compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide" , "text=foo.com##[-abp-properties-bogus='abc']", "selectorDomains=foo.com", "sel ector=[-abp-properties-bogus='abc']", "domains=FOO.COM"]); 399 compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide" , "text=foo.com##[-abp-properties-bogus='abc']", "selectorDomains=foo.com", "sel ector=[-abp-properties-bogus='abc']", "domains=foo.com"]);
400 400
401 test.done(); 401 test.done();
402 }; 402 };
403 403
404 exports.testEmptyElemHideDomains = function(test) 404 exports.testEmptyElemHideDomains = function(test)
405 { 405 {
406 let emptyDomainFilters = [ 406 let emptyDomainFilters = [
407 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", 407 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector",
408 ",foo.com##selector", "foo.com,~##selector", 408 ",foo.com##selector", "foo.com,~##selector",
409 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" 409 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector"
(...skipping 19 matching lines...) Expand all
429 "selector=#foo\\7B color: red\\7D ", 429 "selector=#foo\\7B color: red\\7D ",
430 "domains=" 430 "domains="
431 ] 431 ]
432 ); 432 );
433 compareFilter( 433 compareFilter(
434 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ 434 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [
435 "type=elemhideemulation", 435 "type=elemhideemulation",
436 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", 436 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)",
437 "selectorDomains=foo.com", 437 "selectorDomains=foo.com",
438 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", 438 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)",
439 "domains=FOO.COM" 439 "domains=foo.com"
440 ] 440 ]
441 ); 441 );
442 test.done(); 442 test.done();
443 }; 443 };
444 444
445 exports.testSnippetFilters = function(test) 445 exports.testSnippetFilters = function(test)
446 { 446 {
447 compareFilter(test, "foo.com#$#abc", ["type=snippet", "text=foo.com#$#abc", "s criptDomains=foo.com", "script=abc", "domains=FOO.COM"]); 447 compareFilter(test, "foo.com#$#abc", ["type=snippet", "text=foo.com#$#abc", "s criptDomains=foo.com", "script=abc", "domains=foo.com"]);
448 compareFilter(test, "foo.com,~bar.com#$#abc", ["type=snippet", "text=foo.com,~ bar.com#$#abc", "scriptDomains=foo.com", "script=abc", "domains=FOO.COM|~BAR.COM "]); 448 compareFilter(test, "foo.com,~bar.com#$#abc", ["type=snippet", "text=foo.com,~ bar.com#$#abc", "scriptDomains=foo.com", "script=abc", "domains=foo.com|~bar.com "]);
449 compareFilter(test, "foo.com,~bar#$#abc", ["type=snippet", "text=foo.com,~bar# $#abc", "scriptDomains=foo.com", "script=abc", "domains=FOO.COM|~BAR"]); 449 compareFilter(test, "foo.com,~bar#$#abc", ["type=snippet", "text=foo.com,~bar# $#abc", "scriptDomains=foo.com", "script=abc", "domains=foo.com|~bar"]);
450 compareFilter(test, "~foo.com,bar.com#$#abc", ["type=snippet", "text=~foo.com, bar.com#$#abc", "scriptDomains=bar.com", "script=abc", "domains=BAR.COM|~FOO.COM "]); 450 compareFilter(test, "~foo.com,bar.com#$#abc", ["type=snippet", "text=~foo.com, bar.com#$#abc", "scriptDomains=bar.com", "script=abc", "domains=bar.com|~foo.com "]);
451 451
452 test.done(); 452 test.done();
453 }; 453 };
454 454
455 exports.testFilterNormalization = function(test) 455 exports.testFilterNormalization = function(test)
456 { 456 {
457 // Line breaks etc 457 // Line breaks etc
458 test.equal(Filter.normalize("\n\t\nad\ns"), 458 test.equal(Filter.normalize("\n\t\nad\ns"),
459 "ads"); 459 "ads");
460 460
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 ); 501 );
502 test.equal( 502 test.equal(
503 normalized, 503 normalized,
504 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p" 504 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p"
505 ); 505 );
506 compareFilter( 506 compareFilter(
507 test, normalized, [ 507 test, normalized, [
508 "type=filterlist", 508 "type=filterlist",
509 "text=" + normalized, 509 "text=" + normalized,
510 "csp=c s p", 510 "csp=c s p",
511 "domains=DOMAIN.COM|FOO.COM", 511 "domains=domain.com|foo.com",
512 "sitekeys=FOO", 512 "sitekeys=FOO",
513 "regexp=b\\$la", 513 "regexp=b\\$la",
514 "contentType=" + t.CSP 514 "contentType=" + t.CSP
515 ] 515 ]
516 ); 516 );
517 517
518 // Some $csp edge cases 518 // Some $csp edge cases
519 test.equal(Filter.normalize("$csp= c s p"), 519 test.equal(Filter.normalize("$csp= c s p"),
520 "$csp=c s p"); 520 "$csp=c s p");
521 test.equal(Filter.normalize("$$csp= c s p"), 521 test.equal(Filter.normalize("$$csp= c s p"),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 572
573 test.equal( 573 test.equal(
574 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"), 574 filterRelative.rewriteUrl("http://content.server/file/foo.txt?bar"),
575 "http://content.server/file/foo.txt/disable" 575 "http://content.server/file/foo.txt/disable"
576 ); 576 );
577 test.equal( 577 test.equal(
578 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"), 578 filterRelative.rewriteUrl("http://example.com/file/foo.txt?bar"),
579 "http://example.com/file/foo.txt/disable" 579 "http://example.com/file/foo.txt/disable"
580 ); 580 );
581 581
582 test.done(); 582 // Example from https://github.com/uBlockOrigin/uBlock-issues/issues/46#issuec omment-391190533
583 }; 583 // The rewrite shouldn't happen.
584 let rewriteEvil = "/(^https?:\\/\\/[^/])/$script,rewrite=$1.evil.com";
585 let filterEvil = Filter.fromText(rewriteEvil);
586
587 test.equal(
588 filterEvil.rewriteUrl("https://www.adblockplus.org/script.js"),
589 "https://www.adblockplus.org/script.js"
590 );
591
592 test.done();
593 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld