LEFT | RIGHT |
1 (function() | 1 (function() |
2 { | 2 { |
3 module("Filter matcher", {setup: prepareFilterComponents, teardown: restoreFil
terComponents}); | 3 module("Filter matcher", {setup: prepareFilterComponents, teardown: restoreFil
terComponents}); |
4 | 4 |
5 function compareKeywords(text, expected) | 5 function compareKeywords(text, expected) |
6 { | 6 { |
7 for (let filter of [Filter.fromText(text), Filter.fromText("@@" + text)]) | 7 for (let filter of [Filter.fromText(text), Filter.fromText("@@" + text)]) |
8 { | 8 { |
9 let matcher = new Matcher(); | 9 let matcher = new Matcher(); |
10 let result = []; | 10 let result = []; |
(...skipping 30 matching lines...) Expand all Loading... |
41 { | 41 { |
42 for (let filter of filters) | 42 for (let filter of filters) |
43 combinedMatcher.add(Filter.fromText(filter)); | 43 combinedMatcher.add(Filter.fromText(filter)); |
44 | 44 |
45 let result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[con
tentType], docDomain, thirdParty, sitekey, specificOnly); | 45 let result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[con
tentType], docDomain, thirdParty, sitekey, specificOnly); |
46 if (result) | 46 if (result) |
47 result = result.text; | 47 result = result.text; |
48 | 48 |
49 equal(result, expected, "combinedMatch(" + location + ", " + contentType +
", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " +
(sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specif
icOnly") + ") with:\n" + filters.join("\n")); | 49 equal(result, expected, "combinedMatch(" + location + ", " + contentType +
", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " +
(sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specif
icOnly") + ") with:\n" + filters.join("\n")); |
50 | 50 |
| 51 // Generic whitelisting rules can match for specificOnly searches, so we |
| 52 // can't easily know which rule will match for these whitelisting tests |
| 53 if (specificOnly) |
| 54 continue; |
| 55 |
51 // For next run: add whitelisting filters for filters that aren't already | 56 // For next run: add whitelisting filters for filters that aren't already |
| 57 filters = filters.map((text) => text.substr(0, 2) == "@@" ? text : "@@" +
text); |
52 if (expected && expected.substr(0, 2) != "@@") | 58 if (expected && expected.substr(0, 2) != "@@") |
53 { | 59 expected = "@@" + expected; |
54 filters = filters.filter((text) => text.substr(0, 2) != "@@").map((text)
=> "@@" + text); | |
55 if (expected) | |
56 expected = "@@" + expected; | |
57 } | |
58 } | 60 } |
59 } | 61 } |
60 | 62 |
61 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp
ected) | 63 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp
ected) |
62 { | 64 { |
63 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty); | 65 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty); |
64 if (result) | 66 if (result) |
65 result = result.text; | 67 result = result.text; |
66 | 68 |
67 equal(result, expected, "match(" + location + ", " + contentType + ", " + do
cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with static f
ilters"); | 69 equal(result, expected, "match(" + location + ", " + contentType + ", " + do
cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with static f
ilters"); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, false, null); | 158 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, false, null); |
157 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://ccc/def", "IMAGE", "baz.com", false, null, false, "ccc$doma
in=~foo.com|~bar.com"); | 159 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://ccc/def", "IMAGE", "baz.com", false, null, false, "ccc$doma
in=~foo.com|~bar.com"); |
158 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "foo.com", false, "foo-publickey", false, "abc$sitekey=foo
-publickey"); | 160 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "foo.com", false, "foo-publickey", false, "abc$sitekey=foo
-publickey"); |
159 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, "abc$sitekey=bar
-publickey"); | 161 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, "abc$sitekey=bar
-publickey"); |
160 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, null); | 162 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, null); |
161 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "baz.com", false, null, false, null); | 163 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "baz.com", false, null, false, null); |
162 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "foo-publi
ckey", false, "abc$sitekey=foo-publickey,domain=foo.com"); | 164 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "foo-publi
ckey", false, "abc$sitekey=foo-publickey,domain=foo.com"); |
163 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "bar-publi
ckey", false, null); | 165 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "bar-publi
ckey", false, null); |
164 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "foo-publi
ckey", false, null); | 166 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "foo-publi
ckey", false, null); |
165 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publi
ckey", false, "abc$sitekey=bar-publickey,domain=bar.com"); | 167 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publi
ckey", false, "abc$sitekey=bar-publickey,domain=bar.com"); |
166 checkMatch(["@@kzar.co.uk$generichide"], "http://kzar.co.uk/dave", "GENERICH
IDE", "kzar.co.uk", false, null, false, "@@kzar.co.uk$generichide"); | 168 checkMatch(["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "
foo.com", false, null, false, "@@foo.com$generichide"); |
167 checkMatch(["@@kzar.co.uk$genericblock"], "http://kzar.co.uk/dave", "GENERIC
BLOCK", "kzar.co.uk", false, null, false, "@@kzar.co.uk$genericblock"); | 169 checkMatch(["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK",
"foo.com", false, null, false, "@@foo.com$genericblock"); |
168 checkMatch(["@@foo.com$generichide"], "http://kzar.co.uk/dave", "GENERICHIDE
", "kzar.co.uk", false, null, false, null); | 170 checkMatch(["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "
foo.com", false, null, false, null); |
169 checkMatch(["@@foo.com$genericblock"], "http://kzar.co.uk/dave", "GENERICBLO
CK", "kzar.co.uk", false, null, false, null); | 171 checkMatch(["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK",
"foo.com", false, null, false, null); |
170 checkMatch(["###dave"], "http://kzar.co.uk/dave", "IMAGE", "kzar.co.uk", fal
se, null, true, null); | 172 checkMatch(["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", false, null,
true, null); |
171 checkMatch(["kzar.co.uk###dave"], "http://kzar.co.uk/dave", "IMAGE", "kzar.c
o.uk", false, null, true, null); | 173 checkMatch(["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo.com"
, false, null, true, "/bar$domain=foo.com"); |
172 checkMatch(["/dave$domain=kzar.co.uk"], "http://kzar.co.uk/dave", "IMAGE", "
kzar.co.uk", false, null, true, "/dave$domain=kzar.co.uk"); | |
173 checkMatch(["/dave"], "http://kzar.co.uk/dave", "IMAGE", "kzar.co.uk", false
, null, true, null); | |
174 }); | 174 }); |
175 | 175 |
176 test("Result cache checks", function() | 176 test("Result cache checks", function() |
177 { | 177 { |
178 let matcher = new CombinedMatcher(); | 178 let matcher = new CombinedMatcher(); |
179 matcher.add(Filter.fromText("abc$image")); | 179 matcher.add(Filter.fromText("abc$image")); |
180 matcher.add(Filter.fromText("abc$script")); | 180 matcher.add(Filter.fromText("abc$script")); |
181 matcher.add(Filter.fromText("abc$~image,~script,~media")); | 181 matcher.add(Filter.fromText("abc$~image,~script,~media")); |
182 matcher.add(Filter.fromText("cba$third-party")); | 182 matcher.add(Filter.fromText("cba$third-party")); |
183 matcher.add(Filter.fromText("cba$~third-party,~script")); | 183 matcher.add(Filter.fromText("cba$~third-party,~script")); |
(...skipping 14 matching lines...) Expand all Loading... |
198 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p
arty,~script"); | 198 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p
arty,~script"); |
199 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par
ty"); | 199 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par
ty"); |
200 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third-part
y,~script"); | 200 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third-part
y,~script"); |
201 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-party"
); | 201 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-party"
); |
202 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script"); | 202 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script"); |
203 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, false, "http://f
ed$~third-party,~script"); | 203 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, false, "http://f
ed$~third-party,~script"); |
204 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, true, "http://fe
d$third-party"); | 204 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, true, "http://fe
d$third-party"); |
205 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http://
def$script"); | 205 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http://
def$script"); |
206 }); | 206 }); |
207 })(); | 207 })(); |
LEFT | RIGHT |