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

Side by Side Diff: test/filterClasses.js

Issue 29760704: Issue 6592 - Implement $rewrite filter option (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Some comment adjustments. Created May 7, 2018, 8:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/_common.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 let sitekeys = filter.sitekeys || []; 88 let sitekeys = filter.sitekeys || [];
89 result.push("sitekeys=" + sitekeys.slice().sort().join("|")); 89 result.push("sitekeys=" + sitekeys.slice().sort().join("|"));
90 90
91 result.push("thirdParty=" + filter.thirdParty); 91 result.push("thirdParty=" + filter.thirdParty);
92 if (filter instanceof BlockingFilter) 92 if (filter instanceof BlockingFilter)
93 { 93 {
94 result.push("type=filterlist"); 94 result.push("type=filterlist");
95 result.push("collapse=" + filter.collapse); 95 result.push("collapse=" + filter.collapse);
96 result.push("csp=" + filter.csp); 96 result.push("csp=" + filter.csp);
97 result.push("rewrite=" + filter.rewrite);
97 } 98 }
98 else if (filter instanceof WhitelistFilter) 99 else if (filter instanceof WhitelistFilter)
99 result.push("type=whitelist"); 100 result.push("type=whitelist");
100 } 101 }
101 else if (filter instanceof ElemHideBase) 102 else if (filter instanceof ElemHideBase)
102 { 103 {
103 if (filter instanceof ElemHideFilter) 104 if (filter instanceof ElemHideFilter)
104 result.push("type=elemhide"); 105 result.push("type=elemhide");
105 else if (filter instanceof ElemHideException) 106 else if (filter instanceof ElemHideException)
106 result.push("type=elemhideexception"); 107 result.push("type=elemhideexception");
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 )); 147 ));
147 addProperty("matchCase", "false"); 148 addProperty("matchCase", "false");
148 addProperty("thirdParty", "null"); 149 addProperty("thirdParty", "null");
149 addProperty("domains", ""); 150 addProperty("domains", "");
150 addProperty("sitekeys", ""); 151 addProperty("sitekeys", "");
151 } 152 }
152 if (type == "filterlist") 153 if (type == "filterlist")
153 { 154 {
154 addProperty("collapse", "null"); 155 addProperty("collapse", "null");
155 addProperty("csp", "null"); 156 addProperty("csp", "null");
157 addProperty("rewrite", "null");
156 } 158 }
157 if (type == "elemhide" || type == "elemhideexception" || 159 if (type == "elemhide" || type == "elemhideexception" ||
158 type == "elemhideemulation") 160 type == "elemhideemulation")
159 { 161 {
160 addProperty("selectorDomains", ""); 162 addProperty("selectorDomains", "");
161 addProperty("domains", ""); 163 addProperty("domains", "");
162 } 164 }
163 } 165 }
164 166
165 function compareFilter(test, text, expected, postInit) 167 function compareFilter(test, text, expected, postInit)
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 285
284 test.done(); 286 test.done();
285 }; 287 };
286 288
287 exports.testFilterOptions = function(test) 289 exports.testFilterOptions = function(test)
288 { 290 {
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"]); 291 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"]);
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"]); 292 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"]);
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"]); 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.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 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"]);
295 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"]);
293 296
294 // background and image should be the same for backwards compatibility 297 // background and image should be the same for backwards compatibility
295 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]); 298 compareFilter(test, "bla$image", ["type=filterlist", "text=bla$image", "regexp =bla", "contentType=" + (t.IMAGE)]);
296 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]); 299 compareFilter(test, "bla$background", ["type=filterlist", "text=bla$background ", "regexp=bla", "contentType=" + (t.IMAGE)]);
297 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 300 compareFilter(test, "bla$~image", ["type=filterlist", "text=bla$~image", "rege xp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
298 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]); 301 compareFilter(test, "bla$~background", ["type=filterlist", "text=bla$~backgrou nd", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE)]);
299 302
300 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]); 303 compareFilter(test, "@@bla$~script,~other", ["type=whitelist", "text=@@bla$~sc ript,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHE R))]);
301 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]); 304 compareFilter(test, "@@http://bla$~script,~other", ["type=whitelist", "text=@@ http://bla$~script,~other", "regexp=http\\:\\/\\/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))]); 305 compareFilter(test, "@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@ |ftp://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (default Types & ~(t.SCRIPT | t.OTHER))]);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 test.equal(Filter.normalize("foo$csp=c s p csp= ba z,cs p = script-src 'self '"), 493 test.equal(Filter.normalize("foo$csp=c s p csp= ba z,cs p = script-src 'self '"),
491 "foo$csp=c s p csp= ba z,csp=script-src 'self'"); 494 "foo$csp=c s p csp= ba z,csp=script-src 'self'");
492 test.equal(Filter.normalize("foo$csp=bar,$c sp=c s p"), 495 test.equal(Filter.normalize("foo$csp=bar,$c sp=c s p"),
493 "foo$csp=bar,$csp=c s p"); 496 "foo$csp=bar,$csp=c s p");
494 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), 497 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"),
495 "foo$bar$csp=ba r"); 498 "foo$bar$csp=ba r");
496 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), 499 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "),
497 "f$o$o$csp=f o o"); 500 "f$o$o$csp=f o o");
498 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1= 1&$2=2&$3=3"), 501 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1= 1&$2=2&$3=3"),
499 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); 502 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3");
503 test.equal(Filter.normalize("||content.server.com/files/*.php$rewrite= $1"),
504 "||content.server.com/files/*.php$rewrite=$1");
505 test.done();
506 };
507
508
509 exports.testFilterRewriteOption = function(test)
510 {
511 let text = "/(content\\.server\\/file\\/.*\\.txt)\\?.*$/$rewrite=$1";
512
513 let filter = Filter.fromText(text);
514
515 test.equal(filter.rewrite, "$1");
516 // no rewrite occured: didn't match.
517 test.equal(filter.rewriteUrl("foo"), "foo");
518 // rewrite occured: matched.
519 test.equal(filter.rewriteUrl("http://content.server/file/foo.txt?bar"),
520 "http://content.server/file/foo.txt");
521
522 // checking for same origin.
523 let rewriteDiffOrigin = "/content\\.server(\\/file\\/.*\\.txt)\\?.*$/$rewrite= foo.com$1";
524 let filterDiffOrigin = Filter.fromText(rewriteDiffOrigin);
525
526 // no rewrite occured because of a different origin.
527 test.equal(
528 filterDiffOrigin.rewriteUrl("http://content.server/file/foo.txt?bar"),
529 "http://content.server/file/foo.txt?bar");
500 530
501 test.done(); 531 test.done();
502 }; 532 };
OLDNEW
« no previous file with comments | « test/_common.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld