Left: | ||
Right: |
LEFT | RIGHT |
---|---|
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 21 matching lines...) Expand all Loading... | |
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 || []; | 41 let sitekeys = filter.sitekeys || []; |
42 result.push("sitekeys=" + sitekeys.sort().join("|")); | 42 result.push("sitekeys=" + sitekeys.slice().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 | 43 |
44 result.push("thirdParty=" + filter.thirdParty); | 44 result.push("thirdParty=" + filter.thirdParty); |
45 if (filter instanceof BlockingFilter) | 45 if (filter instanceof BlockingFilter) |
46 { | 46 { |
47 result.push("type=filterlist"); | 47 result.push("type=filterlist"); |
48 result.push("collapse=" + filter.collapse); | 48 result.push("collapse=" + filter.collapse); |
49 } | 49 } |
50 else if (filter instanceof WhitelistFilter) | 50 else if (filter instanceof WhitelistFilter) |
51 { | 51 { |
52 result.push("type=whitelist"); | 52 result.push("type=whitelist"); |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 compareFilter("dd[]{}$%<>&()d", ["type=filterlist", "text=dd[]{}$%<>&()d", " regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d"]); | 207 compareFilter("dd[]{}$%<>&()d", ["type=filterlist", "text=dd[]{}$%<>&()d", " regexp=dd\\[\\]\\{\\}\\$\\%\\<\\>\\&\\(\\)d"]); |
208 | 208 |
209 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]); |
210 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]); |
211 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]); |
212 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]) ; |
213 }); | 213 }); |
214 | 214 |
215 test("Filter options", function() | 215 test("Filter options", function() |
216 { | 216 { |
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"]); | 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"]); |
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"]); | 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"]); |
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"]); | 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"]); |
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 | 220 |
224 // background and image should be the same for backwards compatibility | 221 // background and image should be the same for backwards compatibility |
225 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)]); |
226 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)]); |
227 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)]); |
228 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)]); |
229 | 226 |
230 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))] ); |
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)]); | 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)]); |
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)]); | 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 Loading... | |
268 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"]']); |
269 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]); | 266 compareFilter("#@*(fff)", ["type=elemhideexception", "text=#@*(fff)", "selec tor=.fff,#fff"]); |
270 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']); | 267 compareFilter("#@*(foo=bar)", ["type=elemhideexception", "text=#@*(foo=bar)" , 'selector=[foo="bar"]']); |
271 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"]); |
272 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"]); |
273 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"]); |
274 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"]); |
275 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"]); |
276 }); | 273 }); |
277 })(); | 274 })(); |
LEFT | RIGHT |