OLD | NEW |
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 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 let dummyFilter = Filter.fromText("^" + keyword + "^"); | 51 let dummyFilter = Filter.fromText("^" + keyword + "^"); |
52 dummyFilter.filterCount = Infinity; | 52 dummyFilter.filterCount = Infinity; |
53 matcher.add(dummyFilter); | 53 matcher.add(dummyFilter); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 test.equal(result.join(", "), expected.join(", "), "Keyword candidates for "
+ filter.text); | 57 test.equal(result.join(", "), expected.join(", "), "Keyword candidates for "
+ filter.text); |
58 } | 58 } |
59 } | 59 } |
60 | 60 |
61 function checkMatch(test, filters, location, contentType, docDomain, thirdParty,
sitekey, specificOnly, expected, expectedFirstMatch = expected) | 61 function checkMatch(test, filters, location, contentType, docDomain, sitekey, sp
ecificOnly, expected, expectedFirstMatch = expected) |
62 { | 62 { |
63 let matcher = new Matcher(); | 63 let matcher = new Matcher(); |
64 for (let filter of filters) | 64 for (let filter of filters) |
65 matcher.add(Filter.fromText(filter)); | 65 matcher.add(Filter.fromText(filter)); |
66 | 66 |
67 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], d
ocDomain, thirdParty, sitekey, specificOnly); | 67 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], d
ocDomain, sitekey, specificOnly); |
68 if (result) | 68 if (result) |
69 result = result.text; | 69 result = result.text; |
70 | 70 |
71 test.equal(result, expectedFirstMatch, "match(" + location + ", " + contentTyp
e + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ",
" + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-spe
cificOnly") + ") with:\n" + filters.join("\n")); | 71 test.equal(result, expectedFirstMatch, "match(" + location + ", " + contentTyp
e + ", " + docDomain + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ?
"specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n")); |
72 | 72 |
73 let combinedMatcher = new CombinedMatcher(); | 73 let combinedMatcher = new CombinedMatcher(); |
74 for (let i = 0; i < 2; i++) | 74 for (let i = 0; i < 2; i++) |
75 { | 75 { |
76 for (let filter of filters) | 76 for (let filter of filters) |
77 combinedMatcher.add(Filter.fromText(filter)); | 77 combinedMatcher.add(Filter.fromText(filter)); |
78 | 78 |
79 result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[contentTy
pe], docDomain, thirdParty, sitekey, specificOnly); | 79 result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[contentTy
pe], docDomain, sitekey, specificOnly); |
80 if (result) | 80 if (result) |
81 result = result.text; | 81 result = result.text; |
82 | 82 |
83 test.equal(result, expected, "combinedMatch(" + location + ", " + contentTyp
e + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ",
" + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-spe
cificOnly") + ") with:\n" + filters.join("\n")); | 83 test.equal(result, expected, "combinedMatch(" + location + ", " + contentTyp
e + ", " + docDomain + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ?
"specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n")); |
84 | 84 |
85 // Generic whitelisting rules can match for specificOnly searches, so we | 85 // Generic whitelisting rules can match for specificOnly searches, so we |
86 // can't easily know which rule will match for these whitelisting tests | 86 // can't easily know which rule will match for these whitelisting tests |
87 if (specificOnly) | 87 if (specificOnly) |
88 continue; | 88 continue; |
89 | 89 |
90 // For next run: add whitelisting filters for filters that aren't already | 90 // For next run: add whitelisting filters for filters that aren't already |
91 filters = filters.map(text => text.substr(0, 2) == "@@" ? text : "@@" + text
); | 91 filters = filters.map(text => text.substr(0, 2) == "@@" ? text : "@@" + text
); |
92 if (expected && expected.substr(0, 2) != "@@") | 92 if (expected && expected.substr(0, 2) != "@@") |
93 expected = "@@" + expected; | 93 expected = "@@" + expected; |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 function checkSearch(test, filters, location, contentType, docDomain, | 97 function checkSearch(test, filters, location, contentType, docDomain, |
98 thirdParty, sitekey, specificOnly, filterType, | 98 sitekey, specificOnly, filterType, expected) |
99 expected) | |
100 { | 99 { |
101 let matcher = new CombinedMatcher(); | 100 let matcher = new CombinedMatcher(); |
102 for (let filter of filters) | 101 for (let filter of filters) |
103 matcher.add(Filter.fromText(filter)); | 102 matcher.add(Filter.fromText(filter)); |
104 | 103 |
105 let result = matcher.search(location, RegExpFilter.typeMap[contentType], | 104 let result = matcher.search(location, RegExpFilter.typeMap[contentType], |
106 docDomain, thirdParty, sitekey, specificOnly, | 105 docDomain, sitekey, specificOnly, filterType); |
107 filterType); | |
108 for (let key in result) | 106 for (let key in result) |
109 result[key] = result[key].map(filter => filter.text); | 107 result[key] = result[key].map(filter => filter.text); |
110 | 108 |
111 test.deepEqual(result, expected, "search(" + location + ", " + | 109 test.deepEqual(result, expected, "search(" + location + ", " + |
112 contentType + ", " + docDomain + ", " + | 110 contentType + ", " + docDomain + ", " + |
113 (thirdParty ? "third-party" : "first-party") + ", " + | |
114 (sitekey || "no-sitekey") + ", " + | 111 (sitekey || "no-sitekey") + ", " + |
115 (specificOnly ? "specificOnly" : "not-specificOnly") + ", " + | 112 (specificOnly ? "specificOnly" : "not-specificOnly") + ", " + |
116 filterType + ") with:\n" + filters.join("\n")); | 113 filterType + ") with:\n" + filters.join("\n")); |
117 } | 114 } |
118 | 115 |
119 function cacheCheck(test, matcher, location, contentType, docDomain, thirdParty,
expected) | 116 function cacheCheck(test, matcher, location, contentType, docDomain, expected) |
120 { | 117 { |
121 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], d
ocDomain, thirdParty); | 118 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], d
ocDomain); |
122 if (result) | 119 if (result) |
123 result = result.text; | 120 result = result.text; |
124 | 121 |
125 test.equal(result, expected, "match(" + location + ", " + contentType + ", " +
docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with stati
c filters"); | 122 test.equal(result, expected, "match(" + location + ", " + contentType + ", " +
docDomain + ") with static filters"); |
126 } | 123 } |
127 | 124 |
128 exports.testMatcherClassDefinitions = function(test) | 125 exports.testMatcherClassDefinitions = function(test) |
129 { | 126 { |
130 test.equal(typeof Matcher, "function", "typeof Matcher"); | 127 test.equal(typeof Matcher, "function", "typeof Matcher"); |
131 test.equal(typeof CombinedMatcher, "function", "typeof CombinedMatcher"); | 128 test.equal(typeof CombinedMatcher, "function", "typeof CombinedMatcher"); |
132 test.equal(typeof defaultMatcher, "object", "typeof defaultMatcher"); | 129 test.equal(typeof defaultMatcher, "object", "typeof defaultMatcher"); |
133 test.ok(defaultMatcher instanceof CombinedMatcher, "defaultMatcher is a Combin
edMatcher instance"); | 130 test.ok(defaultMatcher instanceof CombinedMatcher, "defaultMatcher is a Combin
edMatcher instance"); |
134 | 131 |
135 test.done(); | 132 test.done(); |
(...skipping 18 matching lines...) Expand all Loading... |
154 compareKeywords(test, "_asdf_1234_", ["asdf", "1234"]); | 151 compareKeywords(test, "_asdf_1234_", ["asdf", "1234"]); |
155 compareKeywords(test, "+asdf-1234=", ["asdf", "1234"]); | 152 compareKeywords(test, "+asdf-1234=", ["asdf", "1234"]); |
156 compareKeywords(test, "/123^ad2&ad&", ["123", "ad2"]); | 153 compareKeywords(test, "/123^ad2&ad&", ["123", "ad2"]); |
157 compareKeywords(test, "/123^ad2&ad$script,domain=example.com", ["123", "ad2"])
; | 154 compareKeywords(test, "/123^ad2&ad$script,domain=example.com", ["123", "ad2"])
; |
158 | 155 |
159 test.done(); | 156 test.done(); |
160 }; | 157 }; |
161 | 158 |
162 exports.testFilterMatching = function(test) | 159 exports.testFilterMatching = function(test) |
163 { | 160 { |
164 checkMatch(test, [], "http://abc/def", "IMAGE", null, false, null, false, null
); | 161 checkMatch(test, [], "http://abc/def", "IMAGE", "abc", null, false, null); |
165 checkMatch(test, ["abc"], "http://abc/def", "IMAGE", null, false, null, false,
"abc"); | 162 checkMatch(test, ["abc"], "http://abc/def", "IMAGE", "abc", null, false, "abc"
); |
166 checkMatch(test, ["abc", "ddd"], "http://abc/def", "IMAGE", null, false, null,
false, "abc"); | 163 checkMatch(test, ["abc", "ddd"], "http://abc/def", "IMAGE", "abc", null, false
, "abc"); |
167 checkMatch(test, ["ddd", "abc"], "http://abc/def", "IMAGE", null, false, null,
false, "abc"); | 164 checkMatch(test, ["ddd", "abc"], "http://abc/def", "IMAGE", "abc", null, false
, "abc"); |
168 checkMatch(test, ["ddd", "abd"], "http://abc/def", "IMAGE", null, false, null,
false, null); | 165 checkMatch(test, ["ddd", "abd"], "http://abc/def", "IMAGE", "abc", null, false
, null); |
169 checkMatch(test, ["abc", "://abc/d"], "http://abc/def", "IMAGE", null, false,
null, false, "://abc/d"); | 166 checkMatch(test, ["abc", "://abc/d"], "http://abc/def", "IMAGE", "abc", null,
false, "://abc/d"); |
170 checkMatch(test, ["://abc/d", "abc"], "http://abc/def", "IMAGE", null, false,
null, false, "://abc/d"); | 167 checkMatch(test, ["://abc/d", "abc"], "http://abc/def", "IMAGE", "abc", null,
false, "://abc/d"); |
171 checkMatch(test, ["|http://"], "http://abc/def", "IMAGE", null, false, null, f
alse, "|http://"); | 168 checkMatch(test, ["|http://"], "http://abc/def", "IMAGE", "abc", null, false,
"|http://"); |
172 checkMatch(test, ["|http://abc"], "http://abc/def", "IMAGE", null, false, null
, false, "|http://abc"); | 169 checkMatch(test, ["|http://abc"], "http://abc/def", "IMAGE", "abc", null, fals
e, "|http://abc"); |
173 checkMatch(test, ["|abc"], "http://abc/def", "IMAGE", null, false, null, false
, null); | 170 checkMatch(test, ["|abc"], "http://abc/def", "IMAGE", "abc", null, false, null
); |
174 checkMatch(test, ["|/abc/def"], "http://abc/def", "IMAGE", null, false, null,
false, null); | 171 checkMatch(test, ["|/abc/def"], "http://abc/def", "IMAGE", "abc", null, false,
null); |
175 checkMatch(test, ["/def|"], "http://abc/def", "IMAGE", null, false, null, fals
e, "/def|"); | 172 checkMatch(test, ["/def|"], "http://abc/def", "IMAGE", "abc", null, false, "/d
ef|"); |
176 checkMatch(test, ["/abc/def|"], "http://abc/def", "IMAGE", null, false, null,
false, "/abc/def|"); | 173 checkMatch(test, ["/abc/def|"], "http://abc/def", "IMAGE", "abc", null, false,
"/abc/def|"); |
177 checkMatch(test, ["/abc/|"], "http://abc/def", "IMAGE", null, false, null, fal
se, null); | 174 checkMatch(test, ["/abc/|"], "http://abc/def", "IMAGE", "abc", null, false, nu
ll); |
178 checkMatch(test, ["http://abc/|"], "http://abc/def", "IMAGE", null, false, nul
l, false, null); | 175 checkMatch(test, ["http://abc/|"], "http://abc/def", "IMAGE", "abc", null, fal
se, null); |
179 checkMatch(test, ["|http://abc/def|"], "http://abc/def", "IMAGE", null, false,
null, false, "|http://abc/def|"); | 176 checkMatch(test, ["|http://abc/def|"], "http://abc/def", "IMAGE", "abc", null,
false, "|http://abc/def|"); |
180 checkMatch(test, ["|/abc/def|"], "http://abc/def", "IMAGE", null, false, null,
false, null); | 177 checkMatch(test, ["|/abc/def|"], "http://abc/def", "IMAGE", "abc", null, false
, null); |
181 checkMatch(test, ["|http://abc/|"], "http://abc/def", "IMAGE", null, false, nu
ll, false, null); | 178 checkMatch(test, ["|http://abc/|"], "http://abc/def", "IMAGE", "abc", null, fa
lse, null); |
182 checkMatch(test, ["|/abc/|"], "http://abc/def", "IMAGE", null, false, null, fa
lse, null); | 179 checkMatch(test, ["|/abc/|"], "http://abc/def", "IMAGE", "abc", null, false, n
ull); |
183 checkMatch(test, ["||example.com/abc"], "http://example.com/abc/def", "IMAGE",
null, false, null, false, "||example.com/abc"); | 180 checkMatch(test, ["||example.com/abc"], "http://example.com/abc/def", "IMAGE",
"example.com", null, false, "||example.com/abc"); |
184 checkMatch(test, ["||com/abc/def"], "http://example.com/abc/def", "IMAGE", nul
l, false, null, false, "||com/abc/def"); | 181 checkMatch(test, ["||com/abc/def"], "http://example.com/abc/def", "IMAGE", "ex
ample.com", null, false, "||com/abc/def"); |
185 checkMatch(test, ["||com/abc"], "http://example.com/abc/def", "IMAGE", null, f
alse, null, false, "||com/abc"); | 182 checkMatch(test, ["||com/abc"], "http://example.com/abc/def", "IMAGE", "exampl
e.com", null, false, "||com/abc"); |
186 checkMatch(test, ["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", nu
ll, false, null, false, null); | 183 checkMatch(test, ["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", "e
xample.com", null, false, null); |
187 checkMatch(test, ["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", nu
ll, false, null, false, null); | 184 checkMatch(test, ["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", "e
xample.com", null, false, null); |
188 checkMatch(test, ["||http://example.com/"], "http://example.com/abc/def", "IMA
GE", null, false, null, false, null); | 185 checkMatch(test, ["||http://example.com/"], "http://example.com/abc/def", "IMA
GE", "example.com", null, false, null); |
189 checkMatch(test, ["||example.com/abc/def|"], "http://example.com/abc/def", "IM
AGE", null, false, null, false, "||example.com/abc/def|"); | 186 checkMatch(test, ["||example.com/abc/def|"], "http://example.com/abc/def", "IM
AGE", "example.com", null, false, "||example.com/abc/def|"); |
190 checkMatch(test, ["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", nu
ll, false, null, false, "||com/abc/def|"); | 187 checkMatch(test, ["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", "e
xample.com", null, false, "||com/abc/def|"); |
191 checkMatch(test, ["||example.com/abc|"], "http://example.com/abc/def", "IMAGE"
, null, false, null, false, null); | 188 checkMatch(test, ["||example.com/abc|"], "http://example.com/abc/def", "IMAGE"
, "example.com", null, false, null); |
192 checkMatch(test, ["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", n
ull, false, null, false, "://abc/d"); | 189 checkMatch(test, ["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", "
abc", null, false, "://abc/d"); |
193 checkMatch(test, ["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "h
ttp://abc/def", "IMAGE", null, false, null, false, "://abc/de"); | 190 checkMatch(test, ["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "h
ttp://abc/def", "IMAGE", "abc", null, false, "://abc/de"); |
194 checkMatch(test, ["abc$third-party", "abc$~third-party", "ddd"], "http://abc/d
ef", "IMAGE", null, false, null, false, "abc$~third-party"); | 191 checkMatch(test, ["abc$third-party", "abc$~third-party", "ddd"], "http://abc/d
ef", "IMAGE", "abc", null, false, "abc$~third-party"); |
195 checkMatch(test, ["abc$third-party", "abc$~third-party", "ddd"], "http://abc/d
ef", "IMAGE", null, true, null, false, "abc$third-party"); | 192 checkMatch(test, ["abc$third-party", "abc$~third-party", "ddd"], "http://abc/d
ef", "IMAGE", "third-party-domain", null, false, "abc$third-party"); |
196 checkMatch(test, ["//abc/def$third-party", "//abc/def$~third-party", "//abc_de
f"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def$~third-part
y"); | 193 checkMatch(test, ["//abc/def$third-party", "//abc/def$~third-party", "//abc_de
f"], "http://abc/def", "IMAGE", "abc", null, false, "//abc/def$~third-party"); |
197 checkMatch(test, ["//abc/def$third-party", "//abc/def$~third-party", "//abc_de
f"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def$third-party"
); | 194 checkMatch(test, ["//abc/def$third-party", "//abc/def$~third-party", "//abc_de
f"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "//abc/def$th
ird-party"); |
198 checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def"], "http:/
/abc/def", "IMAGE", null, true, null, false, "//abc/def"); | 195 checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def"], "http:/
/abc/def", "IMAGE", "third-party-domain", null, false, "//abc/def"); |
199 checkMatch(test, ["//abc/def", "abc$third-party", "abc$~third-party"], "http:/
/abc/def", "IMAGE", null, true, null, false, "//abc/def"); | 196 checkMatch(test, ["//abc/def", "abc$third-party", "abc$~third-party"], "http:/
/abc/def", "IMAGE", "third-party-domain", null, false, "//abc/def"); |
200 checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$third-part
y"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def$third-party"
); | 197 checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$third-part
y"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "//abc/def$th
ird-party"); |
201 checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$third-part
y"], "http://abc/def", "IMAGE", null, false, null, false, "abc$~third-party"); | 198 checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$third-part
y"], "http://abc/def", "IMAGE", "abc", null, false, "abc$~third-party"); |
202 checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$~third-par
ty"], "http://abc/def", "IMAGE", null, true, null, false, "abc$third-party"); | 199 checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$~third-par
ty"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "abc$third-p
arty"); |
203 checkMatch(test, ["abc$image", "abc$script", "abc$~image"], "http://abc/def",
"IMAGE", null, false, null, false, "abc$image"); | 200 checkMatch(test, ["abc$image", "abc$script", "abc$~image"], "http://abc/def",
"IMAGE", "abc", null, false, "abc$image"); |
204 checkMatch(test, ["abc$image", "abc$script", "abc$~script"], "http://abc/def",
"SCRIPT", null, false, null, false, "abc$script"); | 201 checkMatch(test, ["abc$image", "abc$script", "abc$~script"], "http://abc/def",
"SCRIPT", "abc", null, false, "abc$script"); |
205 checkMatch(test, ["abc$image", "abc$script", "abc$~image"], "http://abc/def",
"OTHER", null, false, null, false, "abc$~image"); | 202 checkMatch(test, ["abc$image", "abc$script", "abc$~image"], "http://abc/def",
"OTHER", "abc", null, false, "abc$~image"); |
206 checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~image"],
"http://abc/def", "IMAGE", null, false, null, false, "//abc/def$image"); | 203 checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~image"],
"http://abc/def", "IMAGE", "abc", null, false, "//abc/def$image"); |
207 checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~script"],
"http://abc/def", "SCRIPT", null, false, null, false, "//abc/def$script"); | 204 checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~script"],
"http://abc/def", "SCRIPT", "abc", null, false, "//abc/def$script"); |
208 checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~image"],
"http://abc/def", "OTHER", null, false, null, false, "//abc/def$~image"); | 205 checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~image"],
"http://abc/def", "OTHER", "abc", null, false, "//abc/def$~image"); |
209 checkMatch(test, ["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "
IMAGE", null, false, null, false, "//abc/def"); | 206 checkMatch(test, ["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "
IMAGE", "abc", null, false, "//abc/def"); |
210 checkMatch(test, ["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "
IMAGE", null, false, null, false, "//abc/def"); | 207 checkMatch(test, ["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "
IMAGE", "abc", null, false, "//abc/def"); |
211 checkMatch(test, ["abc$image", "abc$~image", "//abc/def$image"], "http://abc/d
ef", "IMAGE", null, false, null, false, "//abc/def$image"); | 208 checkMatch(test, ["abc$image", "abc$~image", "//abc/def$image"], "http://abc/d
ef", "IMAGE", "abc", null, false, "//abc/def$image"); |
212 checkMatch(test, ["abc$image", "abc$~image", "//abc/def$script"], "http://abc/
def", "IMAGE", null, false, null, false, "abc$image"); | 209 checkMatch(test, ["abc$image", "abc$~image", "//abc/def$script"], "http://abc/
def", "IMAGE", "abc", null, false, "abc$image"); |
213 checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo
.com|~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, null, false, "abc$
domain=foo.com"); | 210 checkMatch(test, ["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"); |
214 checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo
.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, false, "abc$
domain=bar.com"); | 211 checkMatch(test, ["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"); |
215 checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo
.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, false, "abc$
domain=~foo.com|~bar.com"); | 212 checkMatch(test, ["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"); |
216 checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo
.com|~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, null, false, "abc$
domain=foo.com"); | 213 checkMatch(test, ["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"); |
217 checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo
.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, false, null)
; | 214 checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo
.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", null, false, null); |
218 checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo
.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, false, null)
; | 215 checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo
.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", null, false, null); |
219 checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo
.com|~bar.com"], "http://ccc/def", "IMAGE", "baz.com", false, null, false, "ccc$
domain=~foo.com|~bar.com"); | 216 checkMatch(test, ["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"); |
220 checkMatch(test, ["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "
http://abc/def", "IMAGE", "foo.com", false, "foo-publickey", false, "abc$sitekey
=foo-publickey"); | 217 checkMatch(test, ["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "
http://abc/def", "IMAGE", "foo.com", "foo-publickey", false, "abc$sitekey=foo-pu
blickey"); |
221 checkMatch(test, ["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "
http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, "abc$sitekey
=bar-publickey"); | 218 checkMatch(test, ["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "
http://abc/def", "IMAGE", "bar.com", "bar-publickey", false, "abc$sitekey=bar-pu
blickey"); |
222 checkMatch(test, ["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "
http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, null); | 219 checkMatch(test, ["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "
http://abc/def", "IMAGE", "bar.com", "bar-publickey", false, null); |
223 checkMatch(test, ["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "
http://abc/def", "IMAGE", "baz.com", false, null, false, null); | 220 checkMatch(test, ["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "
http://abc/def", "IMAGE", "baz.com", null, false, null); |
224 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar
-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "foo-p
ublickey", false, "abc$sitekey=foo-publickey,domain=foo.com"); | 221 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar
-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", "foo-publicke
y", false, "abc$sitekey=foo-publickey,domain=foo.com"); |
225 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar
-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "bar-p
ublickey", false, null); | 222 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar
-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", "bar-publicke
y", false, null); |
226 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar
-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "foo-p
ublickey", false, null); | 223 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar
-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", "foo-publicke
y", false, null); |
227 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar
-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "bar-p
ublickey", false, "abc$sitekey=bar-publickey,domain=bar.com"); | 224 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar
-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", "bar-publicke
y", false, "abc$sitekey=bar-publickey,domain=bar.com"); |
228 checkMatch(test, ["@@foo.com$document"], "http://foo.com/bar", "DOCUMENT", "fo
o.com", false, null, false, "@@foo.com$document"); | 225 checkMatch(test, ["@@foo.com$document"], "http://foo.com/bar", "DOCUMENT", "fo
o.com", null, false, "@@foo.com$document"); |
229 checkMatch(test, ["@@foo.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "fo
o.com", false, null, false, "@@foo.com$elemhide"); | 226 checkMatch(test, ["@@foo.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "fo
o.com", null, false, "@@foo.com$elemhide"); |
230 checkMatch(test, ["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE
", "foo.com", false, null, false, "@@foo.com$generichide"); | 227 checkMatch(test, ["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE
", "foo.com", null, false, "@@foo.com$generichide"); |
231 checkMatch(test, ["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLO
CK", "foo.com", false, null, false, "@@foo.com$genericblock"); | 228 checkMatch(test, ["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLO
CK", "foo.com", null, false, "@@foo.com$genericblock"); |
232 checkMatch(test, ["@@bar.com$document"], "http://foo.com/bar", "DOCUMENT", "fo
o.com", false, null, false, null); | 229 checkMatch(test, ["@@bar.com$document"], "http://foo.com/bar", "DOCUMENT", "fo
o.com", null, false, null); |
233 checkMatch(test, ["@@bar.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "fo
o.com", false, null, false, null); | 230 checkMatch(test, ["@@bar.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "fo
o.com", null, false, null); |
234 checkMatch(test, ["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE
", "foo.com", false, null, false, null); | 231 checkMatch(test, ["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE
", "foo.com", null, false, null); |
235 checkMatch(test, ["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLO
CK", "foo.com", false, null, false, null); | 232 checkMatch(test, ["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLO
CK", "foo.com", null, false, null); |
236 checkMatch(test, ["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", false, nu
ll, true, null); | 233 checkMatch(test, ["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", null, tru
e, null); |
237 checkMatch(test, ["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo.
com", false, null, true, "/bar$domain=foo.com"); | 234 checkMatch(test, ["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo.
com", null, true, "/bar$domain=foo.com"); |
238 checkMatch(test, ["@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", f
alse, null, false, null, "@@||foo.com^"); | 235 checkMatch(test, ["@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", n
ull, false, null, "@@||foo.com^"); |
239 checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo
.com", false, null, false, "@@||foo.com^"); | 236 checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo
.com", null, false, "@@||foo.com^"); |
240 checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/foo", "IMAGE", "foo
.com", false, null, false, null, "@@||foo.com^"); | 237 checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/foo", "IMAGE", "foo
.com", null, false, null, "@@||foo.com^"); |
241 checkMatch(test, ["||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com
", false, null, false, "||foo.com^$popup"); | 238 checkMatch(test, ["||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com
", null, false, "||foo.com^$popup"); |
242 checkMatch(test, ["@@||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.c
om", false, null, false, null, "@@||foo.com^$popup"); | 239 checkMatch(test, ["@@||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.c
om", null, false, null, "@@||foo.com^$popup"); |
243 checkMatch(test, ["||foo.com^$popup", "@@||foo.com^$popup"], "http://foo.com/b
ar", "POPUP", "foo.com", false, null, false, "@@||foo.com^$popup", "||foo.com^$p
opup"); | 240 checkMatch(test, ["||foo.com^$popup", "@@||foo.com^$popup"], "http://foo.com/b
ar", "POPUP", "foo.com", null, false, "@@||foo.com^$popup", "||foo.com^$popup"); |
244 checkMatch(test, ["||foo.com^$csp=script-src 'none'"], "http://foo.com/bar", "
CSP", "foo.com", false, null, false, "||foo.com^$csp=script-src 'none'"); | 241 checkMatch(test, ["||foo.com^$csp=script-src 'none'"], "http://foo.com/bar", "
CSP", "foo.com", null, false, "||foo.com^$csp=script-src 'none'"); |
245 checkMatch(test, ["@@||foo.com^$csp"], "http://foo.com/bar", "CSP", "foo.com",
false, null, false, null, "@@||foo.com^$csp"); | 242 checkMatch(test, ["@@||foo.com^$csp"], "http://foo.com/bar", "CSP", "foo.com",
null, false, null, "@@||foo.com^$csp"); |
246 checkMatch(test, ["||foo.com^$csp=script-src 'none'", "@@||foo.com^$csp"], "ht
tp://foo.com/bar", "CSP", "foo.com", false, null, false, "@@||foo.com^$csp", "||
foo.com^$csp=script-src 'none'"); | 243 checkMatch(test, ["||foo.com^$csp=script-src 'none'", "@@||foo.com^$csp"], "ht
tp://foo.com/bar", "CSP", "foo.com", null, false, "@@||foo.com^$csp", "||foo.com
^$csp=script-src 'none'"); |
247 | 244 |
248 test.done(); | 245 test.done(); |
249 }; | 246 }; |
250 | 247 |
251 exports.testFilterSearch = function(test) | 248 exports.testFilterSearch = function(test) |
252 { | 249 { |
253 // Start with three filters: foo, bar, and @@foo | 250 // Start with three filters: foo, bar, and @@foo |
254 let filters = ["foo", "bar", "@@foo"]; | 251 let filters = ["foo", "bar", "@@foo"]; |
255 | 252 |
256 checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com", | 253 checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com", |
257 false, null, false, "all", | 254 null, false, "all", |
258 {blocking: ["foo"], whitelist: ["@@foo"]}); | 255 {blocking: ["foo"], whitelist: ["@@foo"]}); |
259 | 256 |
260 // Blocking only. | 257 // Blocking only. |
261 checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com", | 258 checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com", |
262 false, null, false, "blocking", {blocking: ["foo"]}); | 259 null, false, "blocking", {blocking: ["foo"]}); |
263 | 260 |
264 // Whitelist only. | 261 // Whitelist only. |
265 checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com", | 262 checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com", |
266 false, null, false, "whitelist", {whitelist: ["@@foo"]}); | 263 null, false, "whitelist", {whitelist: ["@@foo"]}); |
267 | 264 |
268 // Different URLs. | 265 // Different URLs. |
269 checkSearch(test, filters, "http://example.com/bar", "IMAGE", "example.com", | 266 checkSearch(test, filters, "http://example.com/bar", "IMAGE", "example.com", |
270 false, null, false, "all", {blocking: ["bar"], whitelist: []}); | 267 null, false, "all", {blocking: ["bar"], whitelist: []}); |
271 checkSearch(test, filters, "http://example.com/foo/bar", "IMAGE", | 268 checkSearch(test, filters, "http://example.com/foo/bar", "IMAGE", |
272 "example.com", false, null, false, "all", | 269 "example.com", null, false, "all", |
273 {blocking: ["foo", "bar"], whitelist: ["@@foo"]}); | 270 {blocking: ["foo", "bar"], whitelist: ["@@foo"]}); |
274 | 271 |
275 // Non-matching content type. | 272 // Non-matching content type. |
276 checkSearch(test, filters, "http://example.com/foo", "CSP", "example.com", | 273 checkSearch(test, filters, "http://example.com/foo", "CSP", "example.com", |
277 false, null, false, "all", {blocking: [], whitelist: []}); | 274 null, false, "all", {blocking: [], whitelist: []}); |
278 | 275 |
279 // Non-matching specificity. | 276 // Non-matching specificity. |
280 checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com", | 277 checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com", |
281 false, null, true, "all", {blocking: [], whitelist: ["@@foo"]}); | 278 null, true, "all", {blocking: [], whitelist: ["@@foo"]}); |
282 | 279 |
283 test.done(); | 280 test.done(); |
284 }; | 281 }; |
285 | 282 |
286 exports.testResultCacheChecks = function(test) | 283 exports.testResultCacheChecks = function(test) |
287 { | 284 { |
288 let matcher = new CombinedMatcher(); | 285 let matcher = new CombinedMatcher(); |
289 matcher.add(Filter.fromText("abc$image")); | 286 matcher.add(Filter.fromText("abc$image")); |
290 matcher.add(Filter.fromText("abc$script")); | 287 matcher.add(Filter.fromText("abc$script")); |
291 matcher.add(Filter.fromText("abc$~image,~script,~media,~ping")); | 288 matcher.add(Filter.fromText("abc$~image,~script,~media,~ping")); |
292 matcher.add(Filter.fromText("cba$third-party")); | 289 matcher.add(Filter.fromText("cba$third-party")); |
293 matcher.add(Filter.fromText("cba$~third-party,~script")); | 290 matcher.add(Filter.fromText("cba$~third-party,~script")); |
294 matcher.add(Filter.fromText("http://def$image")); | 291 matcher.add(Filter.fromText("http://def$image")); |
295 matcher.add(Filter.fromText("http://def$script")); | 292 matcher.add(Filter.fromText("http://def$script")); |
296 matcher.add(Filter.fromText("http://def$~image,~script,~media,~ping")); | 293 matcher.add(Filter.fromText("http://def$~image,~script,~media,~ping")); |
297 matcher.add(Filter.fromText("http://fed$third-party")); | 294 matcher.add(Filter.fromText("http://fed$third-party")); |
298 matcher.add(Filter.fromText("http://fed$~third-party,~script")); | 295 matcher.add(Filter.fromText("http://fed$~third-party,~script")); |
299 | 296 |
300 cacheCheck(test, matcher, "http://abc", "IMAGE", null, false, "abc$image"); | 297 cacheCheck(test, matcher, "http://abc", "IMAGE", "abc", "abc$image"); |
301 cacheCheck(test, matcher, "http://abc", "SCRIPT", null, false, "abc$script"); | 298 cacheCheck(test, matcher, "http://abc", "SCRIPT", "abc", "abc$script"); |
302 cacheCheck(test, matcher, "http://abc", "OTHER", null, false, "abc$~image,~scr
ipt,~media,~ping"); | 299 cacheCheck(test, matcher, "http://abc", "OTHER", "abc", "abc$~image,~script,~m
edia,~ping"); |
303 cacheCheck(test, matcher, "http://cba", "IMAGE", null, false, "cba$~third-part
y,~script"); | 300 cacheCheck(test, matcher, "http://cba", "IMAGE", "cba", "cba$~third-party,~scr
ipt"); |
304 cacheCheck(test, matcher, "http://cba", "IMAGE", null, true, "cba$third-party"
); | 301 cacheCheck(test, matcher, "http://cba", "IMAGE", "third-party-domain", "cba$th
ird-party"); |
305 cacheCheck(test, matcher, "http://def", "IMAGE", null, false, "http://def$imag
e"); | 302 cacheCheck(test, matcher, "http://def", "IMAGE", "def", "http://def$image"); |
306 cacheCheck(test, matcher, "http://def", "SCRIPT", null, false, "http://def$scr
ipt"); | 303 cacheCheck(test, matcher, "http://def", "SCRIPT", "def", "http://def$script"); |
307 cacheCheck(test, matcher, "http://def", "OTHER", null, false, "http://def$~ima
ge,~script,~media,~ping"); | 304 cacheCheck(test, matcher, "http://def", "OTHER", "def", "http://def$~image,~sc
ript,~media,~ping"); |
308 cacheCheck(test, matcher, "http://fed", "IMAGE", null, false, "http://fed$~thi
rd-party,~script"); | 305 cacheCheck(test, matcher, "http://fed", "IMAGE", "fed", "http://fed$~third-par
ty,~script"); |
309 cacheCheck(test, matcher, "http://fed", "IMAGE", null, true, "http://fed$third
-party"); | 306 cacheCheck(test, matcher, "http://fed", "IMAGE", "third-party-domain", "http:/
/fed$third-party"); |
310 cacheCheck(test, matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third-
party,~script"); | 307 cacheCheck(test, matcher, "http://abc_cba", "MEDIA", "abc_cba", "cba$~third-pa
rty,~script"); |
311 cacheCheck(test, matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-pa
rty"); | 308 cacheCheck(test, matcher, "http://abc_cba", "MEDIA", "third-party-domain", "cb
a$third-party"); |
312 cacheCheck(test, matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script
"); | 309 cacheCheck(test, matcher, "http://abc_cba", "SCRIPT", "abc_cba", "abc$script")
; |
313 cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", null, false, "http
://fed$~third-party,~script"); | 310 cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", "def", "http://fed
$~third-party,~script"); |
314 cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", null, true, "http:
//fed$third-party"); | 311 cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", "third-party-domai
n", "http://fed$third-party"); |
315 cacheCheck(test, matcher, "http://def?http://fed", "SCRIPT", null, false, "htt
p://def$script"); | 312 cacheCheck(test, matcher, "http://def?http://fed", "SCRIPT", "def", "http://de
f$script"); |
316 | 313 |
317 test.done(); | 314 test.done(); |
318 }; | 315 }; |
319 | 316 |
320 exports.testWhitelisted = function(test) | 317 exports.testWhitelisted = function(test) |
321 { | 318 { |
322 let matcher = new CombinedMatcher(); | 319 let matcher = new CombinedMatcher(); |
323 | 320 |
324 test.ok(!matcher.isWhitelisted("https://example.com/foo", | 321 test.ok(!matcher.isWhitelisted("https://example.com/foo", |
325 RegExpFilter.typeMap.IMAGE)); | 322 RegExpFilter.typeMap.IMAGE)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 RegExpFilter.typeMap.IMAGE)); | 360 RegExpFilter.typeMap.IMAGE)); |
364 | 361 |
365 matcher.remove(Filter.fromText("||example.com/foo/bar/image.jpg")); | 362 matcher.remove(Filter.fromText("||example.com/foo/bar/image.jpg")); |
366 | 363 |
367 // Make sure the filter got removed so there is no match. | 364 // Make sure the filter got removed so there is no match. |
368 test.ok(!matcher.matchesAny("https://example.com/foo/bar/image.jpg", | 365 test.ok(!matcher.matchesAny("https://example.com/foo/bar/image.jpg", |
369 RegExpFilter.typeMap.IMAGE)); | 366 RegExpFilter.typeMap.IMAGE)); |
370 | 367 |
371 test.done(); | 368 test.done(); |
372 }; | 369 }; |
OLD | NEW |