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 Dec. 11, 2014, 2:18 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
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.slice().sort().join("|"));
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 compareFilter("dd[]{}$%<>&()d", ["type=filterlist", "text=dd[]{}$%<>&()d", " regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d"]); 207 compareFilter("dd[]{}$%<>&()d", ["type=filterlist", "text=dd[]{}$%<>&()d", " regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d"]);
204 208
205 compareFilter("@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]); 209 compareFilter("@@/ddd|f?a[s]d/", ["type=whitelist", "text=@@/ddd|f?a[s]d/", "regexp=ddd|f?a[s]d", "contentType=" + defaultTypes]);
206 compareFilter("@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*", "r egexp=asdf.*d.*dd", "contentType=" + defaultTypes]); 210 compareFilter("@@*asdf*d**dd*", ["type=whitelist", "text=@@*asdf*d**dd*", "r egexp=asdf.*d.*dd", "contentType=" + defaultTypes]);
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,siteke y=foo", ["type=filterlist", "text=bla$match-case,script,other,third-party,domain =foo.com,sitekey=foo", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIP T | t.OTHER), "thirdParty=true", "domains=FOO.COM", "sitekeys=FOO"]);
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,sitekey=foo|bar", ["type=whitelist", "text=@@bla$m atch-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.SCRIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.C OM", "sitekeys=BAR|FOO"]);
216 220
217 // background and image should be the same for backwards compatibility 221 // background and image should be the same for backwards compatibility
218 compareFilter("bla$image", ["type=filterlist", "text=bla$image", "regexp=bla ", "contentType=" + (t.IMAGE)]); 222 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)]); 223 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)]); 224 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)]); 225 compareFilter("bla$~background", ["type=filterlist", "text=bla$~background", "regexp=bla", "contentType=" + (defaultTypes & ~t.IMAGE | t.DOCUMENT)]);
222 226
223 compareFilter("@@bla$~script,~other", ["type=whitelist", "text=@@bla$~script ,~other", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER))] ); 227 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)]); 228 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)]); 229 compareFilter("@@|ftp://bla$~script,~other", ["type=whitelist", "text=@@|ftp ://bla$~script,~other", "regexp=^ftp\\:\\/\\/bla", "contentType=" + (defaultType s & ~(t.SCRIPT | t.OTHER) | t.DOCUMENT)]);
(...skipping 35 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"]']); 265 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"]); 266 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]);
263 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']); 267 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"]); 268 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"]); 269 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"]); 270 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"]); 271 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"]); 272 compareFilter("foo,~baz,bar#@ddd", ["type=elemhideexception", "text=foo,~baz ,bar#@ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
269 }); 273 });
270 })(); 274 })();
OLDNEW
« no previous file with comments | « no previous file | chrome/content/tests/matcher.js » ('j') | chrome/content/tests/regexpFilters_matching.js » ('J')

Powered by Google App Engine
This is Rietveld