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

Side by Side Diff: chrome/content/tests/filterClasses.js

Issue 6612283790721024: Issue 698 - Added tests for $sitekey option (Closed)
Patch Set: Created Sept. 2, 2014, 2:03 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 | « no previous file | chrome/content/tests/matcher.js » ('j') | chrome/content/tests/matcher.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 module("Filter classes", {setup: prepareFilterComponents, teardown: restoreFil terComponents}); 3 module("Filter classes", {setup: prepareFilterComponents, teardown: restoreFil terComponents});
4 4
5 function serializeFilter(filter) 5 function serializeFilter(filter)
6 { 6 {
7 // Filter serialization only writes out essential properties, need to do a f ull serialization here 7 // Filter serialization only writes out essential properties, need to do a f ull serialization here
8 let result = []; 8 let result = [];
9 result.push("text=" + filter.text); 9 result.push("text=" + filter.text);
10 if (filter instanceof InvalidFilter) 10 if (filter instanceof InvalidFilter)
(...skipping 20 matching lines...) Expand all
31 domains.push(filter.domains[domain] ? domain : "~" + domain); 31 domains.push(filter.domains[domain] ? domain : "~" + domain);
32 } 32 }
33 result.push("domains=" + domains.sort().join("|")); 33 result.push("domains=" + domains.sort().join("|"));
34 34
35 if (filter instanceof RegExpFilter) 35 if (filter instanceof RegExpFilter)
36 { 36 {
37 result.push("regexp=" + filter.regexp.source); 37 result.push("regexp=" + filter.regexp.source);
38 result.push("contentType=" + filter.contentType); 38 result.push("contentType=" + filter.contentType);
39 result.push("matchCase=" + filter.matchCase); 39 result.push("matchCase=" + filter.matchCase);
40 40
41 let sitekeys = filter.sitekeys || [];
42 result.push("sitekeys=" + sitekeys.sort().join("|"));
Wladimir Palant 2014/09/10 21:55:06 sitekeys.sort() will have side-effects - it will a
Thomas Greiner 2014/12/11 14:33:55 Done.
43
41 result.push("thirdParty=" + filter.thirdParty); 44 result.push("thirdParty=" + filter.thirdParty);
42 if (filter instanceof BlockingFilter) 45 if (filter instanceof BlockingFilter)
43 { 46 {
44 result.push("type=filterlist"); 47 result.push("type=filterlist");
45 result.push("collapse=" + filter.collapse); 48 result.push("collapse=" + filter.collapse);
46 } 49 }
47 else if (filter instanceof WhitelistFilter) 50 else if (filter instanceof WhitelistFilter)
48 { 51 {
49 result.push("type=whitelist"); 52 result.push("type=whitelist");
50 } 53 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 addProperty("disabled", "false"); 89 addProperty("disabled", "false");
87 addProperty("lastHit", "0"); 90 addProperty("lastHit", "0");
88 addProperty("hitCount", "0"); 91 addProperty("hitCount", "0");
89 } 92 }
90 if (type == "whitelist" || type == "filterlist") 93 if (type == "whitelist" || type == "filterlist")
91 { 94 {
92 addProperty("contentType", 0x7FFFFFFF & ~(RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP)); 95 addProperty("contentType", 0x7FFFFFFF & ~(RegExpFilter.typeMap.ELEMHIDE | RegExpFilter.typeMap.POPUP));
93 addProperty("matchCase", "false"); 96 addProperty("matchCase", "false");
94 addProperty("thirdParty", "null"); 97 addProperty("thirdParty", "null");
95 addProperty("domains", ""); 98 addProperty("domains", "");
99 addProperty("sitekeys", "");
96 } 100 }
97 if (type == "filterlist") 101 if (type == "filterlist")
98 { 102 {
99 addProperty("collapse", "null"); 103 addProperty("collapse", "null");
100 } 104 }
101 if (type == "elemhide" || type == "elemhideexception") 105 if (type == "elemhide" || type == "elemhideexception")
102 { 106 {
103 addProperty("selectorDomain", ""); 107 addProperty("selectorDomain", "");
104 addProperty("domains", ""); 108 addProperty("domains", "");
105 } 109 }
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 compareFilter("@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d**dd* |", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]); 211 compareFilter("@@|*asd|f*d**dd*|", ["type=whitelist", "text=@@|*asd|f*d**dd* |", "regexp=^.*asd\\|f.*d.*dd.*$", "contentType=" + defaultTypes]);
208 compareFilter("@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>&()d" , "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTypes]) ; 212 compareFilter("@@dd[]{}$%<>&()d", ["type=whitelist", "text=@@dd[]{}$%<>&()d" , "regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d", "contentType=" + defaultTypes]) ;
209 }); 213 });
210 214
211 test("Filter options", function() 215 test("Filter options", function()
212 { 216 {
213 compareFilter("bla$match-case,script,other,third-party,domain=foo.com", ["ty pe=filterlist", "text=bla$match-case,script,other,third-party,domain=foo.com", " regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdPart y=true", "domains=FOO.COM"]); 217 compareFilter("bla$match-case,script,other,third-party,domain=foo.com", ["ty pe=filterlist", "text=bla$match-case,script,other,third-party,domain=foo.com", " regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdPart y=true", "domains=FOO.COM"]);
214 compareFilter("bla$~match-case,~script,~other,~third-party,domain=~bar.com", ["type=filterlist", "text=bla$~match-case,~script,~other,~third-party,domain=~b ar.com", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER) | t.DOCUMENT), "thirdParty=false", "domains=~BAR.COM"]); 218 compareFilter("bla$~match-case,~script,~other,~third-party,domain=~bar.com", ["type=filterlist", "text=bla$~match-case,~script,~other,~third-party,domain=~b ar.com", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER) | t.DOCUMENT), "thirdParty=false", "domains=~BAR.COM"]);
215 compareFilter("@@bla$match-case,script,other,third-party,domain=foo.com|bar. com|~bar.foo.com|~foo.bar.com", ["type=whitelist", "text=@@bla$match-case,script ,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo.bar.com", "regexp=bl a", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM"]); 219 compareFilter("@@bla$match-case,script,other,third-party,domain=foo.com|bar. com|~bar.foo.com|~foo.bar.com", ["type=whitelist", "text=@@bla$match-case,script ,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo.bar.com", "regexp=bl a", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM"]);
216 220
221 compareFilter("bla$match-case,script,other,third-party,sitekey=foo", ["type= filterlist", "text=bla$match-case,script,other,third-party,sitekey=foo", "regexp =bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdParty=true ", "sitekeys=FOO"]);
222 compareFilter("@@bla$match-case,script,other,third-party,sitekey=foo|bar", [ "type=whitelist", "text=@@bla$match-case,script,other,third-party,sitekey=foo|ba r", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thir dParty=true", "sitekeys=BAR|FOO"]);
Wladimir Palant 2014/09/10 21:55:06 It's ok to add the sitekey option to the tests abo
Thomas Greiner 2014/12/11 14:33:55 Done.
223
217 // background and image should be the same for backwards compatibility 224 // background and image should be the same for backwards compatibility
218 compareFilter("bla$image", ["type=filterlist", "text=bla$image", "regexp=bla ", "contentType=" + (t.IMAGE)]); 225 compareFilter("bla$image", ["type=filterlist", "text=bla$image", "regexp=bla ", "contentType=" + (t.IMAGE)]);
219 compareFilter("bla$background", ["type=filterlist", "text=bla$background", " regexp=bla", "contentType=" + (t.IMAGE)]); 226 compareFilter("bla$background", ["type=filterlist", "text=bla$background", " regexp=bla", "contentType=" + (t.IMAGE)]);
220 compareFilter("bla$~image", ["type=filterlist", "text=bla$~image", "regexp=b la", "contentType=" + (defaultTypes & ~t.IMAGE | t.DOCUMENT)]); 227 compareFilter("bla$~image", ["type=filterlist", "text=bla$~image", "regexp=b la", "contentType=" + (defaultTypes & ~t.IMAGE | t.DOCUMENT)]);
221 compareFilter("bla$~background", ["type=filterlist", "text=bla$~background", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE | t.DOCUMENT)]); 228 compareFilter("bla$~background", ["type=filterlist", "text=bla$~background", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE | t.DOCUMENT)]);
222 229
223 compareFilter("@@bla$~script,~other", ["type=whitelist", "text=@@bla$~script ,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))] ); 230 compareFilter("@@bla$~script,~other", ["type=whitelist", "text=@@bla$~script ,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))] );
224 compareFilter("@@http://bla$~script,~other", ["type=whitelist", "text=@@http ://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER) | t.DOCUMENT)]); 231 compareFilter("@@http://bla$~script,~other", ["type=whitelist", "text=@@http ://bla$~script,~other", "regexp=http\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER) | t.DOCUMENT)]);
225 compareFilter("@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@|ftp ://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER) | t.DOCUMENT)]); 232 compareFilter("@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@|ftp ://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER) | t.DOCUMENT)]);
226 compareFilter("@@bla$~script,~other,document", ["type=whitelist", "text=@@bl a$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~(t. SCRIPT | t.OTHER) | t.DOCUMENT)]); 233 compareFilter("@@bla$~script,~other,document", ["type=whitelist", "text=@@bl a$~script,~other,document", "regexp=bla", "contentType=" + (defaultTypes & ~(t. SCRIPT | t.OTHER) | t.DOCUMENT)]);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 compareFilter("#@ddd(fff)(foo=bar)", ["type=elemhideexception", "text=#@ddd( fff)(foo=bar)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']); 268 compareFilter("#@ddd(fff)(foo=bar)", ["type=elemhideexception", "text=#@ddd( fff)(foo=bar)", 'selector=ddd.fff[foo="bar"],ddd#fff[foo="bar"]']);
262 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]); 269 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]);
263 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']); 270 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']);
264 compareFilter("#@#body > div:first-child", ["type=elemhideexception", "text= #@#body > div:first-child", "selector=body > div:first-child"]); 271 compareFilter("#@#body > div:first-child", ["type=elemhideexception", "text= #@#body > div:first-child", "selector=body > div:first-child"]);
265 compareFilter("foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "selec torDomain=foo", "selector=ddd", "domains=FOO"]); 272 compareFilter("foo#@ddd", ["type=elemhideexception", "text=foo#@ddd", "selec torDomain=foo", "selector=ddd", "domains=FOO"]);
266 compareFilter("foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ddd" , "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); 273 compareFilter("foo,bar#@ddd", ["type=elemhideexception", "text=foo,bar#@ddd" , "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
267 compareFilter("foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar#@dd d", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); 274 compareFilter("foo,~bar#@ddd", ["type=elemhideexception", "text=foo,~bar#@dd d", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
268 compareFilter("foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz ,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]); 275 compareFilter("foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz ,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
269 }); 276 });
270 })(); 277 })();
OLDNEW
« no previous file with comments | « no previous file | chrome/content/tests/matcher.js » ('j') | chrome/content/tests/matcher.js » ('J')

Powered by Google App Engine
This is Rietveld