| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 51 // Generic whitelisting rules can match for specificOnly searches, so we |
| 52 // can't easily know which rule will match for these whitelisting tests | 52 // can't easily know which rule will match for these whitelisting tests |
| 53 if (specificOnly) | 53 if (specificOnly) |
| 54 continue; | 54 continue; |
| 55 | 55 |
| 56 // 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); | 57 filters = filters.map((text) => text.substr(0, 2) == "@@" ? text : "@@" +
text); |
| 58 if (expected && expected.substr(0, 2) != "@@") | 58 if (expected && expected.substr(0, 2) != "@@") |
| 59 expected = "@@" + expected; | 59 expected = "@@" + expected; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp
ected) | 63 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp
ected) |
| 64 { | 64 { |
| 65 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty); | 65 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty); |
| 66 if (result) | 66 if (result) |
| 67 result = result.text; | 67 result = result.text; |
| 68 | 68 |
| 69 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |