| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 "use strict"; | 18 "use strict"; |
| 19 | 19 |
| 20 const assert = require("assert"); | 20 const assert = require("assert"); |
| 21 const {createSandbox} = require("./_common"); | 21 const {createSandbox} = require("./_common"); |
| 22 | 22 |
| 23 let Filter = null; | 23 let Filter = null; |
| 24 let RegExpFilter = null; | 24 let RegExpFilter = null; |
| 25 let CombinedMatcher = null; | 25 let CombinedMatcher = null; |
| 26 let defaultMatcher = null; | 26 let defaultMatcher = null; |
| 27 let Matcher = null; | 27 let Matcher = null; |
| 28 let parseURL = null; |
| 28 | 29 |
| 29 describe("Matcher", () => | 30 describe("Matcher", () => |
| 30 { | 31 { |
| 31 beforeEach(() => | 32 beforeEach(() => |
| 32 { | 33 { |
| 33 let sandboxedRequire = createSandbox(); | 34 let sandboxedRequire = createSandbox(); |
| 34 ( | 35 ( |
| 35 {Filter, RegExpFilter} = sandboxedRequire("../lib/filterClasses"), | 36 {Filter, RegExpFilter} = sandboxedRequire("../lib/filterClasses"), |
| 36 {CombinedMatcher, defaultMatcher, Matcher} = sandboxedRequire("../lib/matc
her") | 37 {CombinedMatcher, defaultMatcher, Matcher} = sandboxedRequire("../lib/matc
her"), |
| 38 {parseURL} = sandboxedRequire("../lib/url") |
| 37 ); | 39 ); |
| 38 }); | 40 }); |
| 39 | 41 |
| 40 function compareKeywords(text, expected) | 42 function compareKeywords(text, expected) |
| 41 { | 43 { |
| 42 for (let filter of [Filter.fromText(text), Filter.fromText("@@" + text)]) | 44 for (let filter of [Filter.fromText(text), Filter.fromText("@@" + text)]) |
| 43 { | 45 { |
| 44 let matcher = new Matcher(); | 46 let matcher = new Matcher(); |
| 45 let result = []; | 47 let result = []; |
| 46 for (let i = 0; i < expected.length; i++) | 48 for (let i = 0; i < expected.length; i++) |
| 47 { | 49 { |
| 48 let keyword = matcher.findKeyword(filter); | 50 let keyword = matcher.findKeyword(filter); |
| 49 result.push(keyword); | 51 result.push(keyword); |
| 50 if (keyword) | 52 if (keyword) |
| 51 { | 53 { |
| 52 let dummyFilter = Filter.fromText("^" + keyword + "^"); | 54 let dummyFilter = Filter.fromText("^" + keyword + "^"); |
| 53 dummyFilter.filterCount = Infinity; | 55 dummyFilter.filterCount = Infinity; |
| 54 matcher.add(dummyFilter); | 56 matcher.add(dummyFilter); |
| 55 } | 57 } |
| 56 } | 58 } |
| 57 | 59 |
| 58 assert.equal(result.join(", "), expected.join(", "), "Keyword candidates f
or " + filter.text); | 60 assert.equal(result.join(", "), expected.join(", "), "Keyword candidates f
or " + filter.text); |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 | 63 |
| 62 function checkMatch(filters, location, contentType, docDomain, thirdParty, sit
ekey, specificOnly, expected, expectedFirstMatch = expected) | 64 function checkMatch(filters, location, contentType, docDomain, sitekey, specif
icOnly, expected, expectedFirstMatch = expected) |
| 63 { | 65 { |
| 66 let url = parseURL(location); |
| 67 |
| 64 let matcher = new Matcher(); | 68 let matcher = new Matcher(); |
| 65 for (let filter of filters) | 69 for (let filter of filters) |
| 66 matcher.add(Filter.fromText(filter)); | 70 matcher.add(Filter.fromText(filter)); |
| 67 | 71 |
| 68 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty, sitekey, specificOnly); | 72 let result = matcher.matchesAny(url, RegExpFilter.typeMap[contentType], docD
omain, sitekey, specificOnly); |
| 69 if (result) | 73 if (result) |
| 70 result = result.text; | 74 result = result.text; |
| 71 | 75 |
| 72 assert.equal(result, expectedFirstMatch, "match(" + location + ", " + conten
tType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") +
", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not
-specificOnly") + ") with:\n" + filters.join("\n")); | 76 assert.equal(result, expectedFirstMatch, "match(" + location + ", " + conten
tType + ", " + docDomain + ", " + (sitekey || "no-sitekey") + ", " + (specificOn
ly ? "specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n")); |
| 73 | 77 |
| 74 let combinedMatcher = new CombinedMatcher(); | 78 let combinedMatcher = new CombinedMatcher(); |
| 75 for (let i = 0; i < 2; i++) | 79 for (let i = 0; i < 2; i++) |
| 76 { | 80 { |
| 77 for (let filter of filters) | 81 for (let filter of filters) |
| 78 combinedMatcher.add(Filter.fromText(filter)); | 82 combinedMatcher.add(Filter.fromText(filter)); |
| 79 | 83 |
| 80 result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[content
Type], docDomain, thirdParty, sitekey, specificOnly); | 84 result = combinedMatcher.matchesAny(url, RegExpFilter.typeMap[contentType]
, docDomain, sitekey, specificOnly); |
| 81 if (result) | 85 if (result) |
| 82 result = result.text; | 86 result = result.text; |
| 83 | 87 |
| 84 assert.equal(result, expected, "combinedMatch(" + location + ", " + conten
tType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") +
", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not
-specificOnly") + ") with:\n" + filters.join("\n")); | 88 assert.equal(result, expected, "combinedMatch(" + location + ", " + conten
tType + ", " + docDomain + ", " + (sitekey || "no-sitekey") + ", " + (specificOn
ly ? "specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n")); |
| 85 | 89 |
| 86 // Generic whitelisting rules can match for specificOnly searches, so we | 90 // Generic whitelisting rules can match for specificOnly searches, so we |
| 87 // can't easily know which rule will match for these whitelisting tests | 91 // can't easily know which rule will match for these whitelisting tests |
| 88 if (specificOnly) | 92 if (specificOnly) |
| 89 continue; | 93 continue; |
| 90 | 94 |
| 91 // For next run: add whitelisting filters for filters that aren't already | 95 // For next run: add whitelisting filters for filters that aren't already |
| 92 filters = filters.map(text => text.substring(0, 2) == "@@" ? text : "@@" +
text); | 96 filters = filters.map(text => text.substring(0, 2) == "@@" ? text : "@@" +
text); |
| 93 if (expected && expected.substring(0, 2) != "@@") | 97 if (expected && expected.substring(0, 2) != "@@") |
| 94 expected = "@@" + expected; | 98 expected = "@@" + expected; |
| 95 } | 99 } |
| 96 } | 100 } |
| 97 | 101 |
| 98 function checkSearch(filters, location, contentType, docDomain, | 102 function checkSearch(filters, location, contentType, docDomain, |
| 99 thirdParty, sitekey, specificOnly, filterType, | 103 sitekey, specificOnly, filterType, |
| 100 expected) | 104 expected) |
| 101 { | 105 { |
| 106 let url = parseURL(location); |
| 107 |
| 102 let matcher = new CombinedMatcher(); | 108 let matcher = new CombinedMatcher(); |
| 103 for (let filter of filters) | 109 for (let filter of filters) |
| 104 matcher.add(Filter.fromText(filter)); | 110 matcher.add(Filter.fromText(filter)); |
| 105 | 111 |
| 106 let result = matcher.search(location, RegExpFilter.typeMap[contentType], | 112 let result = matcher.search(url, RegExpFilter.typeMap[contentType], |
| 107 docDomain, thirdParty, sitekey, specificOnly, | 113 docDomain, sitekey, specificOnly, |
| 108 filterType); | 114 filterType); |
| 109 for (let key in result) | 115 for (let key in result) |
| 110 result[key] = result[key].map(filter => filter.text); | 116 result[key] = result[key].map(filter => filter.text); |
| 111 | 117 |
| 112 assert.deepEqual(result, expected, "search(" + location + ", " + | 118 assert.deepEqual(result, expected, "search(" + location + ", " + |
| 113 contentType + ", " + docDomain + ", " + | 119 contentType + ", " + docDomain + ", " + |
| 114 (thirdParty ? "third-party" : "first-party") + ", " + | |
| 115 (sitekey || "no-sitekey") + ", " + | 120 (sitekey || "no-sitekey") + ", " + |
| 116 (specificOnly ? "specificOnly" : "not-specificOnly") + ", " + | 121 (specificOnly ? "specificOnly" : "not-specificOnly") + ", " + |
| 117 filterType + ") with:\n" + filters.join("\n")); | 122 filterType + ") with:\n" + filters.join("\n")); |
| 118 } | 123 } |
| 119 | 124 |
| 120 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp
ected) | 125 function cacheCheck(matcher, location, contentType, docDomain, expected) |
| 121 { | 126 { |
| 122 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType],
docDomain, thirdParty); | 127 let url = parseURL(location); |
| 128 |
| 129 let result = matcher.matchesAny(url, RegExpFilter.typeMap[contentType], docD
omain); |
| 123 if (result) | 130 if (result) |
| 124 result = result.text; | 131 result = result.text; |
| 125 | 132 |
| 126 assert.equal(result, expected, "match(" + location + ", " + contentType + ",
" + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with s
tatic filters"); | 133 assert.equal(result, expected, "match(" + location + ", " + contentType + ",
" + docDomain + ") with static filters"); |
| 127 } | 134 } |
| 128 | 135 |
| 129 it("Class Definitions", () => | 136 it("Class Definitions", () => |
| 130 { | 137 { |
| 131 assert.equal(typeof Matcher, "function", "typeof Matcher"); | 138 assert.equal(typeof Matcher, "function", "typeof Matcher"); |
| 132 assert.equal(typeof CombinedMatcher, "function", "typeof CombinedMatcher"); | 139 assert.equal(typeof CombinedMatcher, "function", "typeof CombinedMatcher"); |
| 133 assert.equal(typeof defaultMatcher, "object", "typeof defaultMatcher"); | 140 assert.equal(typeof defaultMatcher, "object", "typeof defaultMatcher"); |
| 134 assert.ok(defaultMatcher instanceof CombinedMatcher, "defaultMatcher is a Co
mbinedMatcher instance"); | 141 assert.ok(defaultMatcher instanceof CombinedMatcher, "defaultMatcher is a Co
mbinedMatcher instance"); |
| 135 }); | 142 }); |
| 136 | 143 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 151 compareKeywords("^foo%2Ebar^", ["foo%2ebar"]); | 158 compareKeywords("^foo%2Ebar^", ["foo%2ebar"]); |
| 152 compareKeywords("^aSdF^1234", ["asdf"]); | 159 compareKeywords("^aSdF^1234", ["asdf"]); |
| 153 compareKeywords("_asdf_1234_", ["asdf", "1234"]); | 160 compareKeywords("_asdf_1234_", ["asdf", "1234"]); |
| 154 compareKeywords("+asdf-1234=", ["asdf", "1234"]); | 161 compareKeywords("+asdf-1234=", ["asdf", "1234"]); |
| 155 compareKeywords("/123^ad2&ad&", ["123", "ad2"]); | 162 compareKeywords("/123^ad2&ad&", ["123", "ad2"]); |
| 156 compareKeywords("/123^ad2&ad$script,domain=example.com", ["123", "ad2"]); | 163 compareKeywords("/123^ad2&ad$script,domain=example.com", ["123", "ad2"]); |
| 157 }); | 164 }); |
| 158 | 165 |
| 159 it("Filter Matching", () => | 166 it("Filter Matching", () => |
| 160 { | 167 { |
| 161 checkMatch([], "http://abc/def", "IMAGE", null, false, null, false, null); | 168 checkMatch([], "http://abc/def", "IMAGE", null, null, false, null); |
| 162 checkMatch(["abc"], "http://abc/def", "IMAGE", null, false, null, false, "ab
c"); | 169 checkMatch(["abc"], "http://abc/def", "IMAGE", null, null, false, "abc"); |
| 163 checkMatch(["abc", "ddd"], "http://abc/def", "IMAGE", null, false, null, fal
se, "abc"); | 170 checkMatch(["abc", "ddd"], "http://abc/def", "IMAGE", null, null, false, "ab
c"); |
| 164 checkMatch(["ddd", "abc"], "http://abc/def", "IMAGE", null, false, null, fal
se, "abc"); | 171 checkMatch(["ddd", "abc"], "http://abc/def", "IMAGE", null, null, false, "ab
c"); |
| 165 checkMatch(["ddd", "abd"], "http://abc/def", "IMAGE", null, false, null, fal
se, null); | 172 checkMatch(["ddd", "abd"], "http://abc/def", "IMAGE", null, null, false, nul
l); |
| 166 checkMatch(["abc", "://abc/d"], "http://abc/def", "IMAGE", null, false, null
, false, "://abc/d"); | 173 checkMatch(["abc", "://abc/d"], "http://abc/def", "IMAGE", null, null, false
, "://abc/d"); |
| 167 checkMatch(["://abc/d", "abc"], "http://abc/def", "IMAGE", null, false, null
, false, "://abc/d"); | 174 checkMatch(["://abc/d", "abc"], "http://abc/def", "IMAGE", null, null, false
, "://abc/d"); |
| 168 checkMatch(["|http://"], "http://abc/def", "IMAGE", null, false, null, false
, "|http://"); | 175 checkMatch(["|http://"], "http://abc/def", "IMAGE", null, null, false, "|htt
p://"); |
| 169 checkMatch(["|http://abc"], "http://abc/def", "IMAGE", null, false, null, fa
lse, "|http://abc"); | 176 checkMatch(["|http://abc"], "http://abc/def", "IMAGE", null, null, false, "|
http://abc"); |
| 170 checkMatch(["|abc"], "http://abc/def", "IMAGE", null, false, null, false, nu
ll); | 177 checkMatch(["|abc"], "http://abc/def", "IMAGE", null, null, false, null); |
| 171 checkMatch(["|/abc/def"], "http://abc/def", "IMAGE", null, false, null, fals
e, null); | 178 checkMatch(["|/abc/def"], "http://abc/def", "IMAGE", null, null, false, null
); |
| 172 checkMatch(["/def|"], "http://abc/def", "IMAGE", null, false, null, false, "
/def|"); | 179 checkMatch(["/def|"], "http://abc/def", "IMAGE", null, null, false, "/def|")
; |
| 173 checkMatch(["/abc/def|"], "http://abc/def", "IMAGE", null, false, null, fals
e, "/abc/def|"); | 180 checkMatch(["/abc/def|"], "http://abc/def", "IMAGE", null, null, false, "/ab
c/def|"); |
| 174 checkMatch(["/abc/|"], "http://abc/def", "IMAGE", null, false, null, false,
null); | 181 checkMatch(["/abc/|"], "http://abc/def", "IMAGE", null, null, false, null); |
| 175 checkMatch(["http://abc/|"], "http://abc/def", "IMAGE", null, false, null, f
alse, null); | 182 checkMatch(["http://abc/|"], "http://abc/def", "IMAGE", null, null, false, n
ull); |
| 176 checkMatch(["|http://abc/def|"], "http://abc/def", "IMAGE", null, false, nul
l, false, "|http://abc/def|"); | 183 checkMatch(["|http://abc/def|"], "http://abc/def", "IMAGE", null, null, fals
e, "|http://abc/def|"); |
| 177 checkMatch(["|/abc/def|"], "http://abc/def", "IMAGE", null, false, null, fal
se, null); | 184 checkMatch(["|/abc/def|"], "http://abc/def", "IMAGE", null, null, false, nul
l); |
| 178 checkMatch(["|http://abc/|"], "http://abc/def", "IMAGE", null, false, null,
false, null); | 185 checkMatch(["|http://abc/|"], "http://abc/def", "IMAGE", null, null, false,
null); |
| 179 checkMatch(["|/abc/|"], "http://abc/def", "IMAGE", null, false, null, false,
null); | 186 checkMatch(["|/abc/|"], "http://abc/def", "IMAGE", null, null, false, null); |
| 180 checkMatch(["||example.com/abc"], "http://example.com/abc/def", "IMAGE", nul
l, false, null, false, "||example.com/abc"); | 187 checkMatch(["||example.com/abc"], "http://example.com/abc/def", "IMAGE", nul
l, null, false, "||example.com/abc"); |
| 181 checkMatch(["||com/abc/def"], "http://example.com/abc/def", "IMAGE", null, f
alse, null, false, "||com/abc/def"); | 188 checkMatch(["||com/abc/def"], "http://example.com/abc/def", "IMAGE", null, n
ull, false, "||com/abc/def"); |
| 182 checkMatch(["||com/abc"], "http://example.com/abc/def", "IMAGE", null, false
, null, false, "||com/abc"); | 189 checkMatch(["||com/abc"], "http://example.com/abc/def", "IMAGE", null, null,
false, "||com/abc"); |
| 183 checkMatch(["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", null,
false, null, false, null); | 190 checkMatch(["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", null,
null, false, null); |
| 184 checkMatch(["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", null,
false, null, false, null); | 191 checkMatch(["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", null,
null, false, null); |
| 185 checkMatch(["||http://example.com/"], "http://example.com/abc/def", "IMAGE",
null, false, null, false, null); | 192 checkMatch(["||http://example.com/"], "http://example.com/abc/def", "IMAGE",
null, null, false, null); |
| 186 checkMatch(["||example.com/abc/def|"], "http://example.com/abc/def", "IMAGE"
, null, false, null, false, "||example.com/abc/def|"); | 193 checkMatch(["||example.com/abc/def|"], "http://example.com/abc/def", "IMAGE"
, null, null, false, "||example.com/abc/def|"); |
| 187 checkMatch(["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", null,
false, null, false, "||com/abc/def|"); | 194 checkMatch(["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", null,
null, false, "||com/abc/def|"); |
| 188 checkMatch(["||example.com/abc|"], "http://example.com/abc/def", "IMAGE", nu
ll, false, null, false, null); | 195 checkMatch(["||example.com/abc|"], "http://example.com/abc/def", "IMAGE", nu
ll, null, false, null); |
| 189 checkMatch(["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", null,
false, null, false, "://abc/d"); | 196 checkMatch(["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", null,
null, false, "://abc/d"); |
| 190 checkMatch(["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "http:
//abc/def", "IMAGE", null, false, null, false, "://abc/de"); | 197 checkMatch(["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "http:
//abc/def", "IMAGE", null, null, false, "://abc/de"); |
| 191 checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def",
"IMAGE", null, false, null, false, "abc$~third-party"); | 198 checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def",
"IMAGE", null, null, false, "abc$~third-party"); |
| 192 checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def",
"IMAGE", null, true, null, false, "abc$third-party"); | 199 checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def",
"IMAGE", "other-domain", null, false, "abc$third-party"); |
| 193 checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"],
"http://abc/def", "IMAGE", null, false, null, false, "//abc/def$~third-party"); | 200 checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"],
"http://abc/def", "IMAGE", null, null, false, "//abc/def$~third-party"); |
| 194 checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"],
"http://abc/def", "IMAGE", null, true, null, false, "//abc/def$third-party"); | 201 checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"],
"http://abc/def", "IMAGE", "other-domain", null, false, "//abc/def$third-party"
); |
| 195 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def"], "http://abc
/def", "IMAGE", null, true, null, false, "//abc/def"); | 202 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def"], "http://abc
/def", "IMAGE", null, null, false, "//abc/def"); |
| 196 checkMatch(["//abc/def", "abc$third-party", "abc$~third-party"], "http://abc
/def", "IMAGE", null, true, null, false, "//abc/def"); | 203 checkMatch(["//abc/def", "abc$third-party", "abc$~third-party"], "http://abc
/def", "IMAGE", null, null, false, "//abc/def"); |
| 197 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"],
"http://abc/def", "IMAGE", null, true, null, false, "//abc/def$third-party"); | 204 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"],
"http://abc/def", "IMAGE", "other-domain", null, false, "//abc/def$third-party"
); |
| 198 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"],
"http://abc/def", "IMAGE", null, false, null, false, "abc$~third-party"); | 205 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"],
"http://abc/def", "IMAGE", null, null, false, "abc$~third-party"); |
| 199 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$~third-party"]
, "http://abc/def", "IMAGE", null, true, null, false, "abc$third-party"); | 206 checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$~third-party"]
, "http://abc/def", "IMAGE", "other-domain", null, false, "abc$third-party"); |
| 200 checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "IMA
GE", null, false, null, false, "abc$image"); | 207 checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "IMA
GE", null, null, false, "abc$image"); |
| 201 checkMatch(["abc$image", "abc$script", "abc$~script"], "http://abc/def", "SC
RIPT", null, false, null, false, "abc$script"); | 208 checkMatch(["abc$image", "abc$script", "abc$~script"], "http://abc/def", "SC
RIPT", null, null, false, "abc$script"); |
| 202 checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "OTH
ER", null, false, null, false, "abc$~image"); | 209 checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "OTH
ER", null, null, false, "abc$~image"); |
| 203 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "htt
p://abc/def", "IMAGE", null, false, null, false, "//abc/def$image"); | 210 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "htt
p://abc/def", "IMAGE", null, null, false, "//abc/def$image"); |
| 204 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~script"], "ht
tp://abc/def", "SCRIPT", null, false, null, false, "//abc/def$script"); | 211 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~script"], "ht
tp://abc/def", "SCRIPT", null, null, false, "//abc/def$script"); |
| 205 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "htt
p://abc/def", "OTHER", null, false, null, false, "//abc/def$~image"); | 212 checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "htt
p://abc/def", "OTHER", null, null, false, "//abc/def$~image"); |
| 206 checkMatch(["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "IMAG
E", null, false, null, false, "//abc/def"); | 213 checkMatch(["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "IMAG
E", null, null, false, "//abc/def"); |
| 207 checkMatch(["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAG
E", null, false, null, false, "//abc/def"); | 214 checkMatch(["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAG
E", null, null, false, "//abc/def"); |
| 208 checkMatch(["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def",
"IMAGE", null, false, null, false, "//abc/def$image"); | 215 checkMatch(["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def",
"IMAGE", null, null, false, "//abc/def$image"); |
| 209 checkMatch(["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def"
, "IMAGE", null, false, null, false, "abc$image"); | 216 checkMatch(["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def"
, "IMAGE", null, null, false, "abc$image"); |
| 210 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, null, false, "abc$doma
in=foo.com"); | 217 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "foo.com", null, false, "abc$domain=foo.
com"); |
| 211 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, false, "abc$doma
in=bar.com"); | 218 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "bar.com", null, false, "abc$domain=bar.
com"); |
| 212 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, false, "abc$doma
in=~foo.com|~bar.com"); | 219 checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "baz.com", null, false, "abc$domain=~foo
.com|~bar.com"); |
| 213 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, null, false, "abc$doma
in=foo.com"); | 220 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "foo.com", null, false, "abc$domain=foo.
com"); |
| 214 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, false, null); | 221 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "bar.com", null, false, null); |
| 215 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); | 222 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://abc/def", "IMAGE", "baz.com", null, false, null); |
| 216 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"); | 223 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com
|~bar.com"], "http://ccc/def", "IMAGE", "baz.com", null, false, "ccc$domain=~foo
.com|~bar.com"); |
| 217 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "foo.com", false, "foo-publickey", false, "abc$sitekey=foo
-publickey"); | 224 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "foo.com", "foo-publickey", false, "abc$sitekey=foo-public
key"); |
| 218 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, "abc$sitekey=bar
-publickey"); | 225 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "bar.com", "bar-publickey", false, "abc$sitekey=bar-public
key"); |
| 219 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, null); | 226 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "bar.com", "bar-publickey", false, null); |
| 220 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "baz.com", false, null, false, null); | 227 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http
://abc/def", "IMAGE", "baz.com", null, false, null); |
| 221 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"); | 228 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", "foo-publickey",
false, "abc$sitekey=foo-publickey,domain=foo.com"); |
| 222 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); | 229 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", "bar-publickey",
false, null); |
| 223 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); | 230 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", "foo-publickey",
false, null); |
| 224 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"); | 231 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub
lickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", "bar-publickey",
false, "abc$sitekey=bar-publickey,domain=bar.com"); |
| 225 checkMatch(["@@foo.com$document"], "http://foo.com/bar", "DOCUMENT", "foo.co
m", false, null, false, "@@foo.com$document"); | 232 checkMatch(["@@foo.com$document"], "http://foo.com/bar", "DOCUMENT", "foo.co
m", null, false, "@@foo.com$document"); |
| 226 checkMatch(["@@foo.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "foo.co
m", false, null, false, "@@foo.com$elemhide"); | 233 checkMatch(["@@foo.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "foo.co
m", null, false, "@@foo.com$elemhide"); |
| 227 checkMatch(["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "
foo.com", false, null, false, "@@foo.com$generichide"); | 234 checkMatch(["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "
foo.com", null, false, "@@foo.com$generichide"); |
| 228 checkMatch(["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK",
"foo.com", false, null, false, "@@foo.com$genericblock"); | 235 checkMatch(["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK",
"foo.com", null, false, "@@foo.com$genericblock"); |
| 229 checkMatch(["@@bar.com$document"], "http://foo.com/bar", "DOCUMENT", "foo.co
m", false, null, false, null); | 236 checkMatch(["@@bar.com$document"], "http://foo.com/bar", "DOCUMENT", "foo.co
m", null, false, null); |
| 230 checkMatch(["@@bar.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "foo.co
m", false, null, false, null); | 237 checkMatch(["@@bar.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "foo.co
m", null, false, null); |
| 231 checkMatch(["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "
foo.com", false, null, false, null); | 238 checkMatch(["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "
foo.com", null, false, null); |
| 232 checkMatch(["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK",
"foo.com", false, null, false, null); | 239 checkMatch(["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK",
"foo.com", null, false, null); |
| 233 checkMatch(["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", false, null,
true, null); | 240 checkMatch(["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", null, true, n
ull); |
| 234 checkMatch(["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo.com"
, false, null, true, "/bar$domain=foo.com"); | 241 checkMatch(["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo.com"
, null, true, "/bar$domain=foo.com"); |
| 235 checkMatch(["@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", false
, null, false, null, "@@||foo.com^"); | 242 checkMatch(["@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", null,
false, null, "@@||foo.com^"); |
| 236 checkMatch(["/bar", "@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com
", false, null, false, "@@||foo.com^"); | 243 checkMatch(["/bar", "@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com
", null, false, "@@||foo.com^"); |
| 237 checkMatch(["/bar", "@@||foo.com^"], "http://foo.com/foo", "IMAGE", "foo.com
", false, null, false, null, "@@||foo.com^"); | 244 checkMatch(["/bar", "@@||foo.com^"], "http://foo.com/foo", "IMAGE", "foo.com
", null, false, null, "@@||foo.com^"); |
| 238 checkMatch(["||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com", f
alse, null, false, "||foo.com^$popup"); | 245 checkMatch(["||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com", n
ull, false, "||foo.com^$popup"); |
| 239 checkMatch(["@@||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com",
false, null, false, null, "@@||foo.com^$popup"); | 246 checkMatch(["@@||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com",
null, false, null, "@@||foo.com^$popup"); |
| 240 checkMatch(["||foo.com^$popup", "@@||foo.com^$popup"], "http://foo.com/bar",
"POPUP", "foo.com", false, null, false, "@@||foo.com^$popup", "||foo.com^$popup
"); | 247 checkMatch(["||foo.com^$popup", "@@||foo.com^$popup"], "http://foo.com/bar",
"POPUP", "foo.com", null, false, "@@||foo.com^$popup", "||foo.com^$popup"); |
| 241 checkMatch(["||foo.com^$csp=script-src 'none'"], "http://foo.com/bar", "CSP"
, "foo.com", false, null, false, "||foo.com^$csp=script-src 'none'"); | 248 checkMatch(["||foo.com^$csp=script-src 'none'"], "http://foo.com/bar", "CSP"
, "foo.com", null, false, "||foo.com^$csp=script-src 'none'"); |
| 242 checkMatch(["@@||foo.com^$csp"], "http://foo.com/bar", "CSP", "foo.com", fal
se, null, false, null, "@@||foo.com^$csp"); | 249 checkMatch(["@@||foo.com^$csp"], "http://foo.com/bar", "CSP", "foo.com", nul
l, false, null, "@@||foo.com^$csp"); |
| 243 checkMatch(["||foo.com^$csp=script-src 'none'", "@@||foo.com^$csp"], "http:/
/foo.com/bar", "CSP", "foo.com", false, null, false, "@@||foo.com^$csp", "||foo.
com^$csp=script-src 'none'"); | 250 checkMatch(["||foo.com^$csp=script-src 'none'", "@@||foo.com^$csp"], "http:/
/foo.com/bar", "CSP", "foo.com", null, false, "@@||foo.com^$csp", "||foo.com^$cs
p=script-src 'none'"); |
| 244 | 251 |
| 245 // See #7312. | 252 // See #7312. |
| 246 checkMatch(["^foo/bar/$script"], "http://foo/bar/", "SCRIPT", "example.com",
true, null, true, null); | 253 checkMatch(["^foo/bar/$script"], "http://foo/bar/", "SCRIPT", "example.com",
null, true, null); |
| 247 checkMatch(["^foo/bar/$script"], "http://foo/bar/", "SCRIPT", "example.com",
true, null, false, "^foo/bar/$script"); | 254 checkMatch(["^foo/bar/$script"], "http://foo/bar/", "SCRIPT", "example.com",
null, false, "^foo/bar/$script"); |
| 248 checkMatch(["^foo/bar/$script,domain=example.com", "@@^foo/bar/$script"], "h
ttp://foo/bar/", "SCRIPT", "example.com", true, null, true, "@@^foo/bar/$script"
, "^foo/bar/$script,domain=example.com"); | 255 checkMatch(["^foo/bar/$script,domain=example.com", "@@^foo/bar/$script"], "h
ttp://foo/bar/", "SCRIPT", "example.com", null, true, "@@^foo/bar/$script", "^fo
o/bar/$script,domain=example.com"); |
| 249 checkMatch(["@@^foo/bar/$script", "^foo/bar/$script,domain=example.com"], "h
ttp://foo/bar/", "SCRIPT", "example.com", true, null, true, "@@^foo/bar/$script"
, "^foo/bar/$script,domain=example.com"); | 256 checkMatch(["@@^foo/bar/$script", "^foo/bar/$script,domain=example.com"], "h
ttp://foo/bar/", "SCRIPT", "example.com", null, true, "@@^foo/bar/$script", "^fo
o/bar/$script,domain=example.com"); |
| 250 checkMatch(["@@^foo/bar/$script", "^foo/bar/$script,domain=example.com"], "h
ttp://foo/bar/", "SCRIPT", "example.com", true, null, false, "@@^foo/bar/$script
"); | 257 checkMatch(["@@^foo/bar/$script", "^foo/bar/$script,domain=example.com"], "h
ttp://foo/bar/", "SCRIPT", "example.com", null, false, "@@^foo/bar/$script"); |
| 251 }); | 258 }); |
| 252 | 259 |
| 253 it("Filter Search", () => | 260 it("Filter Search", () => |
| 254 { | 261 { |
| 255 // Start with three filters: foo, bar, and @@foo | 262 // Start with three filters: foo, bar, and @@foo |
| 256 let filters = ["foo", "bar", "@@foo"]; | 263 let filters = ["foo", "bar", "@@foo"]; |
| 257 | 264 |
| 258 checkSearch(filters, "http://example.com/foo", "IMAGE", "example.com", | 265 checkSearch(filters, "http://example.com/foo", "IMAGE", "example.com", |
| 259 false, null, false, "all", | 266 null, false, "all", |
| 260 {blocking: ["foo"], whitelist: ["@@foo"]}); | 267 {blocking: ["foo"], whitelist: ["@@foo"]}); |
| 261 | 268 |
| 262 // Blocking only. | 269 // Blocking only. |
| 263 checkSearch(filters, "http://example.com/foo", "IMAGE", "example.com", | 270 checkSearch(filters, "http://example.com/foo", "IMAGE", "example.com", |
| 264 false, null, false, "blocking", {blocking: ["foo"]}); | 271 null, false, "blocking", {blocking: ["foo"]}); |
| 265 | 272 |
| 266 // Whitelist only. | 273 // Whitelist only. |
| 267 checkSearch(filters, "http://example.com/foo", "IMAGE", "example.com", | 274 checkSearch(filters, "http://example.com/foo", "IMAGE", "example.com", |
| 268 false, null, false, "whitelist", {whitelist: ["@@foo"]}); | 275 null, false, "whitelist", {whitelist: ["@@foo"]}); |
| 269 | 276 |
| 270 // Different URLs. | 277 // Different URLs. |
| 271 checkSearch(filters, "http://example.com/bar", "IMAGE", "example.com", | 278 checkSearch(filters, "http://example.com/bar", "IMAGE", "example.com", |
| 272 false, null, false, "all", {blocking: ["bar"], whitelist: []}); | 279 null, false, "all", {blocking: ["bar"], whitelist: []}); |
| 273 checkSearch(filters, "http://example.com/foo/bar", "IMAGE", | 280 checkSearch(filters, "http://example.com/foo/bar", "IMAGE", |
| 274 "example.com", false, null, false, "all", | 281 "example.com", null, false, "all", |
| 275 {blocking: ["foo", "bar"], whitelist: ["@@foo"]}); | 282 {blocking: ["foo", "bar"], whitelist: ["@@foo"]}); |
| 276 | 283 |
| 277 // Non-matching content type. | 284 // Non-matching content type. |
| 278 checkSearch(filters, "http://example.com/foo", "CSP", "example.com", | 285 checkSearch(filters, "http://example.com/foo", "CSP", "example.com", |
| 279 false, null, false, "all", {blocking: [], whitelist: []}); | 286 null, false, "all", {blocking: [], whitelist: []}); |
| 280 | 287 |
| 281 // Non-matching specificity. | 288 // Non-matching specificity. |
| 282 checkSearch(filters, "http://example.com/foo", "IMAGE", "example.com", | 289 checkSearch(filters, "http://example.com/foo", "IMAGE", "example.com", |
| 283 false, null, true, "all", {blocking: [], whitelist: ["@@foo"]}); | 290 null, true, "all", {blocking: [], whitelist: ["@@foo"]}); |
| 284 }); | 291 }); |
| 285 | 292 |
| 286 it("Result cache checks", () => | 293 it("Result cache checks", () => |
| 287 { | 294 { |
| 288 let matcher = new CombinedMatcher(); | 295 let matcher = new CombinedMatcher(); |
| 289 matcher.add(Filter.fromText("abc$image")); | 296 matcher.add(Filter.fromText("abc$image")); |
| 290 matcher.add(Filter.fromText("abc$script")); | 297 matcher.add(Filter.fromText("abc$script")); |
| 291 matcher.add(Filter.fromText("abc$~image,~script,~media,~ping")); | 298 matcher.add(Filter.fromText("abc$~image,~script,~media,~ping")); |
| 292 matcher.add(Filter.fromText("cba$third-party")); | 299 matcher.add(Filter.fromText("cba$third-party")); |
| 293 matcher.add(Filter.fromText("cba$~third-party,~script")); | 300 matcher.add(Filter.fromText("cba$~third-party,~script")); |
| 294 matcher.add(Filter.fromText("http://def$image")); | 301 matcher.add(Filter.fromText("http://def$image")); |
| 295 matcher.add(Filter.fromText("http://def$script")); | 302 matcher.add(Filter.fromText("http://def$script")); |
| 296 matcher.add(Filter.fromText("http://def$~image,~script,~media,~ping")); | 303 matcher.add(Filter.fromText("http://def$~image,~script,~media,~ping")); |
| 297 matcher.add(Filter.fromText("http://fed$third-party")); | 304 matcher.add(Filter.fromText("http://fed$third-party")); |
| 298 matcher.add(Filter.fromText("http://fed$~third-party,~script")); | 305 matcher.add(Filter.fromText("http://fed$~third-party,~script")); |
| 299 | 306 |
| 300 cacheCheck(matcher, "http://abc", "IMAGE", null, false, "abc$image"); | 307 cacheCheck(matcher, "http://abc", "IMAGE", null, "abc$image"); |
| 301 cacheCheck(matcher, "http://abc", "SCRIPT", null, false, "abc$script"); | 308 cacheCheck(matcher, "http://abc", "SCRIPT", null, "abc$script"); |
| 302 cacheCheck(matcher, "http://abc", "OTHER", null, false, "abc$~image,~script,
~media,~ping"); | 309 cacheCheck(matcher, "http://abc", "OTHER", null, "abc$~image,~script,~media,
~ping"); |
| 303 cacheCheck(matcher, "http://cba", "IMAGE", null, false, "cba$~third-party,~s
cript"); | 310 cacheCheck(matcher, "http://cba", "IMAGE", null, "cba$~third-party,~script")
; |
| 304 cacheCheck(matcher, "http://cba", "IMAGE", null, true, "cba$third-party"); | 311 cacheCheck(matcher, "http://cba", "IMAGE", "other-domain", "cba$third-party"
); |
| 305 cacheCheck(matcher, "http://def", "IMAGE", null, false, "http://def$image"); | 312 cacheCheck(matcher, "http://def", "IMAGE", null, "http://def$image"); |
| 306 cacheCheck(matcher, "http://def", "SCRIPT", null, false, "http://def$script"
); | 313 cacheCheck(matcher, "http://def", "SCRIPT", null, "http://def$script"); |
| 307 cacheCheck(matcher, "http://def", "OTHER", null, false, "http://def$~image,~
script,~media,~ping"); | 314 cacheCheck(matcher, "http://def", "OTHER", null, "http://def$~image,~script,
~media,~ping"); |
| 308 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p
arty,~script"); | 315 cacheCheck(matcher, "http://fed", "IMAGE", null, "http://fed$~third-party,~s
cript"); |
| 309 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par
ty"); | 316 cacheCheck(matcher, "http://fed", "IMAGE", "other-domain", "http://fed$third
-party"); |
| 310 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third-part
y,~script"); | 317 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, "cba$~third-party,~scri
pt"); |
| 311 cacheCheck(matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-party"
); | 318 cacheCheck(matcher, "http://abc_cba", "MEDIA", "other-domain", "cba$third-pa
rty"); |
| 312 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script"); | 319 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, "abc$script"); |
| 313 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, false, "http://f
ed$~third-party,~script"); | 320 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, "http://fed$~thi
rd-party,~script"); |
| 314 cacheCheck(matcher, "http://def?http://fed", "MEDIA", null, true, "http://fe
d$third-party"); | 321 cacheCheck(matcher, "http://def?http://fed", "MEDIA", "other-domain", "http:
//fed$third-party"); |
| 315 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http://
def$script"); | 322 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, "http://def$scr
ipt"); |
| 316 }); | 323 }); |
| 317 | 324 |
| 318 it("Whitelisted", () => | 325 it("Whitelisted", () => |
| 319 { | 326 { |
| 320 let matcher = new CombinedMatcher(); | 327 let matcher = new CombinedMatcher(); |
| 321 | 328 |
| 322 assert.ok(!matcher.isWhitelisted("https://example.com/foo", | 329 assert.ok(!matcher.isWhitelisted(parseURL("https://example.com/foo"), |
| 323 RegExpFilter.typeMap.IMAGE)); | 330 RegExpFilter.typeMap.IMAGE)); |
| 324 assert.ok(!matcher.isWhitelisted("https://example.com/bar", | 331 assert.ok(!matcher.isWhitelisted(parseURL("https://example.com/bar"), |
| 325 RegExpFilter.typeMap.IMAGE)); | 332 RegExpFilter.typeMap.IMAGE)); |
| 326 assert.ok(!matcher.isWhitelisted("https://example.com/foo", | 333 assert.ok(!matcher.isWhitelisted(parseURL("https://example.com/foo"), |
| 327 RegExpFilter.typeMap.SUBDOCUMENT)); | 334 RegExpFilter.typeMap.SUBDOCUMENT)); |
| 328 | 335 |
| 329 matcher.add(Filter.fromText("@@/foo^$image")); | 336 matcher.add(Filter.fromText("@@/foo^$image")); |
| 330 | 337 |
| 331 assert.ok(matcher.isWhitelisted("https://example.com/foo", | 338 assert.ok(matcher.isWhitelisted(parseURL("https://example.com/foo"), |
| 332 RegExpFilter.typeMap.IMAGE)); | 339 RegExpFilter.typeMap.IMAGE)); |
| 333 assert.ok(!matcher.isWhitelisted("https://example.com/bar", | 340 assert.ok(!matcher.isWhitelisted(parseURL("https://example.com/bar"), |
| 334 RegExpFilter.typeMap.IMAGE)); | 341 RegExpFilter.typeMap.IMAGE)); |
| 335 assert.ok(!matcher.isWhitelisted("https://example.com/foo", | 342 assert.ok(!matcher.isWhitelisted(parseURL("https://example.com/foo"), |
| 336 RegExpFilter.typeMap.SUBDOCUMENT)); | 343 RegExpFilter.typeMap.SUBDOCUMENT)); |
| 337 | 344 |
| 338 matcher.remove(Filter.fromText("@@/foo^$image")); | 345 matcher.remove(Filter.fromText("@@/foo^$image")); |
| 339 | 346 |
| 340 assert.ok(!matcher.isWhitelisted("https://example.com/foo", | 347 assert.ok(!matcher.isWhitelisted(parseURL("https://example.com/foo"), |
| 341 RegExpFilter.typeMap.IMAGE)); | 348 RegExpFilter.typeMap.IMAGE)); |
| 342 assert.ok(!matcher.isWhitelisted("https://example.com/bar", | 349 assert.ok(!matcher.isWhitelisted(parseURL("https://example.com/bar"), |
| 343 RegExpFilter.typeMap.IMAGE)); | 350 RegExpFilter.typeMap.IMAGE)); |
| 344 assert.ok(!matcher.isWhitelisted("https://example.com/foo", | 351 assert.ok(!matcher.isWhitelisted(parseURL("https://example.com/foo"), |
| 345 RegExpFilter.typeMap.SUBDOCUMENT)); | 352 RegExpFilter.typeMap.SUBDOCUMENT)); |
| 346 }); | 353 }); |
| 347 | 354 |
| 348 it("Add remove by keyword", () => | 355 it("Add remove by keyword", () => |
| 349 { | 356 { |
| 350 let matcher = new CombinedMatcher(); | 357 let matcher = new CombinedMatcher(); |
| 351 | 358 |
| 352 matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg^")); | 359 matcher.add(Filter.fromText("||example.com/foo/bar/ad.jpg^")); |
| 353 | 360 |
| 354 // Add the same filter a second time to make sure it doesn't get added again | 361 // Add the same filter a second time to make sure it doesn't get added again |
| 355 // by a different keyword. | 362 // by a different keyword. |
| 356 matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg^")); | 363 matcher.add(Filter.fromText("||example.com/foo/bar/ad.jpg^")); |
| 357 | 364 |
| 358 assert.ok(!!matcher.matchesAny("https://example.com/foo/bar/image.jpg", | 365 assert.ok(!!matcher.matchesAny(parseURL("https://example.com/foo/bar/ad.jpg"
), |
| 359 RegExpFilter.typeMap.IMAGE)); | 366 RegExpFilter.typeMap.IMAGE)); |
| 360 | 367 |
| 361 matcher.remove(Filter.fromText("||example.com/foo/bar/image.jpg^")); | 368 matcher.remove(Filter.fromText("||example.com/foo/bar/ad.jpg^")); |
| 362 | 369 |
| 363 // Make sure the filter got removed so there is no match. | 370 // Make sure the filter got removed so there is no match. |
| 364 assert.ok(!matcher.matchesAny("https://example.com/foo/bar/image.jpg", | 371 assert.ok(!matcher.matchesAny(parseURL("https://example.com/foo/bar/ad.jpg")
, |
| 365 RegExpFilter.typeMap.IMAGE)); | 372 RegExpFilter.typeMap.IMAGE)); |
| 366 | 373 |
| 367 | 374 |
| 368 // Map { "example" => { text: "||example.com^$~third-party" } } | 375 // Map { "example" => { text: "||example.com^$~third-party" } } |
| 369 matcher.add(Filter.fromText("||example.com^$~third-party")); | 376 matcher.add(Filter.fromText("||example.com^$~third-party")); |
| 370 | 377 |
| 371 assert.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1); | 378 assert.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1); |
| 372 | 379 |
| 373 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword) | 380 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword) |
| 374 { | 381 { |
| 375 assert.equal(key, "example"); | 382 assert.equal(key, "example"); |
| 376 assert.deepEqual(value, Filter.fromText("||example.com^$~third-party")); | 383 assert.deepEqual(value, Filter.fromText("||example.com^$~third-party")); |
| 377 break; | 384 break; |
| 378 } | 385 } |
| 379 | 386 |
| 380 assert.ok(!!matcher.matchesAny("https://example.com/example/image.jpg", | 387 assert.ok(!!matcher.matchesAny(parseURL("https://example.com/example/ad.jpg"
), |
| 381 RegExpFilter.typeMap.IMAGE, "example.com", | 388 RegExpFilter.typeMap.IMAGE, "example.com")); |
| 382 false)); | |
| 383 | 389 |
| 384 // Map { | 390 // Map { |
| 385 // "example" => Map { | 391 // "example" => Map { |
| 386 // "" => Map { | 392 // "" => Map { |
| 387 // { text: "||example.com^$~third-party" } => true, | 393 // { text: "||example.com^$~third-party" } => true, |
| 388 // { text: "/example/*$~third-party" } => true | 394 // { text: "/example/*$~third-party" } => true |
| 389 // } | 395 // } |
| 390 // } | 396 // } |
| 391 // } | 397 // } |
| 392 matcher.add(Filter.fromText("/example/*$~third-party")); | 398 matcher.add(Filter.fromText("/example/*$~third-party")); |
| 393 | 399 |
| 394 assert.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1); | 400 assert.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1); |
| 395 | 401 |
| 396 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword) | 402 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword) |
| 397 { | 403 { |
| 398 assert.equal(key, "example"); | 404 assert.equal(key, "example"); |
| 399 assert.equal(value.size, 1); | 405 assert.equal(value.size, 1); |
| 400 | 406 |
| 401 let map = value.get(""); | 407 let map = value.get(""); |
| 402 assert.equal(map.size, 2); | 408 assert.equal(map.size, 2); |
| 403 assert.equal(map.get(Filter.fromText("||example.com^$~third-party")), true
); | 409 assert.equal(map.get(Filter.fromText("||example.com^$~third-party")), true
); |
| 404 assert.equal(map.get(Filter.fromText("/example/*$~third-party")), true); | 410 assert.equal(map.get(Filter.fromText("/example/*$~third-party")), true); |
| 405 | 411 |
| 406 break; | 412 break; |
| 407 } | 413 } |
| 408 | 414 |
| 409 assert.ok(!!matcher.matchesAny("https://example.com/example/image.jpg", | 415 assert.ok(!!matcher.matchesAny(parseURL("https://example.com/example/ad.jpg"
), |
| 410 RegExpFilter.typeMap.IMAGE, "example.com", | 416 RegExpFilter.typeMap.IMAGE, "example.com")); |
| 411 false)); | |
| 412 | 417 |
| 413 // Map { "example" => { text: "/example/*$~third-party" } } | 418 // Map { "example" => { text: "/example/*$~third-party" } } |
| 414 matcher.remove(Filter.fromText("||example.com^$~third-party")); | 419 matcher.remove(Filter.fromText("||example.com^$~third-party")); |
| 415 | 420 |
| 416 assert.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1); | 421 assert.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1); |
| 417 | 422 |
| 418 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword) | 423 for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword) |
| 419 { | 424 { |
| 420 assert.equal(key, "example"); | 425 assert.equal(key, "example"); |
| 421 assert.deepEqual(value, Filter.fromText("/example/*$~third-party")); | 426 assert.deepEqual(value, Filter.fromText("/example/*$~third-party")); |
| 422 break; | 427 break; |
| 423 } | 428 } |
| 424 | 429 |
| 425 assert.ok(!!matcher.matchesAny("https://example.com/example/image.jpg", | 430 assert.ok(!!matcher.matchesAny(parseURL("https://example.com/example/ad.jpg"
), |
| 426 RegExpFilter.typeMap.IMAGE, "example.com", | 431 RegExpFilter.typeMap.IMAGE, "example.com")); |
| 427 false)); | |
| 428 | 432 |
| 429 // Map {} | 433 // Map {} |
| 430 matcher.remove(Filter.fromText("/example/*$~third-party")); | 434 matcher.remove(Filter.fromText("/example/*$~third-party")); |
| 431 | 435 |
| 432 assert.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 0); | 436 assert.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 0); |
| 433 | 437 |
| 434 assert.ok(!matcher.matchesAny("https://example.com/example/image.jpg", | 438 assert.ok(!matcher.matchesAny(parseURL("https://example.com/example/ad.jpg")
, |
| 435 RegExpFilter.typeMap.IMAGE, "example.com", | 439 RegExpFilter.typeMap.IMAGE, "example.com")); |
| 436 false)); | |
| 437 }); | 440 }); |
| 438 }); | 441 }); |
| LEFT | RIGHT |