OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 equal(result.join(", "), expected.join(", "), "Keyword candidates for " +
filter.text); | 23 equal(result.join(", "), expected.join(", "), "Keyword candidates for " +
filter.text); |
24 } | 24 } |
25 } | 25 } |
26 | 26 |
27 function checkMatch(filters, location, contentType, docDomain, thirdParty, sit
ekey, expected) | 27 function checkMatch(filters, location, contentType, docDomain, thirdParty, sit
ekey, expected) |
28 { | 28 { |
29 let matcher = new Matcher(); | 29 let matcher = new Matcher(); |
30 for (let filter of filters) | 30 for (let filter of filters) |
31 matcher.add(Filter.fromText(filter)); | 31 matcher.add(Filter.fromText(filter)); |
32 | 32 |
33 let result = matcher.matchesAny(location, contentType, docDomain, thirdParty
, sitekey); | 33 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty, sitekey); |
34 if (result) | 34 if (result) |
35 result = result.text; | 35 result = result.text; |
36 | 36 |
37 equal(result, expected, "match(" + location + ", " + contentType + ", " + do
cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey
|| "no-sitekey") + ") with:\n" + filters.join("\n")); | 37 equal(result, expected, "match(" + location + ", " + contentType + ", " + do
cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey
|| "no-sitekey") + ") with:\n" + filters.join("\n")); |
38 | 38 |
39 let combinedMatcher = new CombinedMatcher(); | 39 let combinedMatcher = new CombinedMatcher(); |
40 for (let i = 0; i < 2; i++) | 40 for (let i = 0; i < 2; i++) |
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, contentType, docDomain,
thirdParty, sitekey); | 45 let result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[con
tentType], docDomain, thirdParty, sitekey); |
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") + ") with:\n" + filters.join("\n")); | 49 equal(result, expected, "combinedMatch(" + location + ", " + contentType +
", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " +
(sitekey || "no-sitekey") + ") with:\n" + filters.join("\n")); |
50 | 50 |
51 // For next run: add whitelisting filters | 51 // For next run: add whitelisting filters |
52 filters = filters.map((text) => "@@" + text); | 52 filters = filters.map((text) => "@@" + text); |
53 if (expected) | 53 if (expected) |
54 expected = "@@" + expected; | 54 expected = "@@" + expected; |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp
ected) | 58 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp
ected) |
59 { | 59 { |
60 let result = matcher.matchesAny(location, contentType, docDomain, thirdParty
); | 60 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty); |
61 if (result) | 61 if (result) |
62 result = result.text; | 62 result = result.text; |
63 | 63 |
64 equal(result, expected, "match(" + location + ", " + contentType + ", " + do
cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with static f
ilters"); | 64 equal(result, expected, "match(" + location + ", " + contentType + ", " + do
cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with static f
ilters"); |
65 } | 65 } |
66 | 66 |
67 test("Matcher class definitions", function() | 67 test("Matcher class definitions", function() |
68 { | 68 { |
69 equal(typeof Matcher, "function", "typeof Matcher"); | 69 equal(typeof Matcher, "function", "typeof Matcher"); |
70 equal(typeof CombinedMatcher, "function", "typeof CombinedMatcher"); | 70 equal(typeof CombinedMatcher, "function", "typeof CombinedMatcher"); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p
arty,~script"); | 187 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p
arty,~script"); |
188 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par
ty"); | 188 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par
ty"); |
189 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third-part
y,~script"); | 189 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third-part
y,~script"); |
190 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-party"
); | 190 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-party"
); |
191 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script"); | 191 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script"); |
192 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, false, "http://f
ed$~third-party,~script"); | 192 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, false, "http://f
ed$~third-party,~script"); |
193 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, true, "http://fe
d$third-party"); | 193 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, true, "http://fe
d$third-party"); |
194 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http://
def$script"); | 194 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http://
def$script"); |
195 }); | 195 }); |
196 })(); | 196 })(); |
OLD | NEW |