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 |
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 {createSandbox} = require("./_common"); | 20 const {createSandbox} = require("./_common"); |
21 | 21 |
22 let Filter = null; | 22 let Filter = null; |
23 let InvalidFilter = null; | 23 let InvalidFilter = null; |
24 let CommentFilter = null; | 24 let CommentFilter = null; |
25 let ActiveFilter = null; | 25 let ActiveFilter = null; |
26 let RegExpFilter = null; | 26 let RegExpFilter = null; |
27 let BlockingFilter = null; | 27 let BlockingFilter = null; |
28 let WhitelistFilter = null; | 28 let WhitelistFilter = null; |
| 29 let CodeInjectionFilter = null; |
29 let ElemHideBase = null; | 30 let ElemHideBase = null; |
30 let ElemHideFilter = null; | 31 let ElemHideFilter = null; |
31 let ElemHideException = null; | 32 let ElemHideException = null; |
32 let ElemHideEmulationFilter = null; | 33 let ElemHideEmulationFilter = null; |
| 34 let SnippetFilter = null; |
33 | 35 |
34 let t = null; | 36 let t = null; |
35 let defaultTypes = null; | 37 let defaultTypes = null; |
36 | 38 |
37 exports.setUp = function(callback) | 39 exports.setUp = function(callback) |
38 { | 40 { |
39 let sandboxedRequire = createSandbox(); | 41 let sandboxedRequire = createSandbox(); |
40 ( | 42 ( |
41 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, | 43 {Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, |
42 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, | 44 BlockingFilter, WhitelistFilter, CodeInjectionFilter, ElemHideBase, |
| 45 ElemHideFilter, |
43 ElemHideException, | 46 ElemHideException, |
44 ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses") | 47 ElemHideEmulationFilter, |
| 48 SnippetFilter} = sandboxedRequire("../lib/filterClasses") |
45 ); | 49 ); |
46 t = RegExpFilter.typeMap; | 50 t = RegExpFilter.typeMap; |
47 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP | | 51 defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP | |
48 t.GENERICHIDE | t.GENERICBLOCK); | 52 t.GENERICHIDE | t.GENERICBLOCK); |
49 | 53 |
50 callback(); | 54 callback(); |
51 }; | 55 }; |
52 | 56 |
53 function serializeFilter(filter) | 57 function serializeFilter(filter) |
54 { | 58 { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 result.push("thirdParty=" + filter.thirdParty); | 95 result.push("thirdParty=" + filter.thirdParty); |
92 if (filter instanceof BlockingFilter) | 96 if (filter instanceof BlockingFilter) |
93 { | 97 { |
94 result.push("type=filterlist"); | 98 result.push("type=filterlist"); |
95 result.push("collapse=" + filter.collapse); | 99 result.push("collapse=" + filter.collapse); |
96 result.push("csp=" + filter.csp); | 100 result.push("csp=" + filter.csp); |
97 } | 101 } |
98 else if (filter instanceof WhitelistFilter) | 102 else if (filter instanceof WhitelistFilter) |
99 result.push("type=whitelist"); | 103 result.push("type=whitelist"); |
100 } | 104 } |
101 else if (filter instanceof ElemHideBase) | 105 else if (filter instanceof CodeInjectionFilter) |
102 { | 106 { |
103 if (filter instanceof ElemHideFilter) | 107 if (filter instanceof ElemHideFilter) |
104 result.push("type=elemhide"); | 108 result.push("type=elemhide"); |
105 else if (filter instanceof ElemHideException) | 109 else if (filter instanceof ElemHideException) |
106 result.push("type=elemhideexception"); | 110 result.push("type=elemhideexception"); |
107 else if (filter instanceof ElemHideEmulationFilter) | 111 else if (filter instanceof ElemHideEmulationFilter) |
108 result.push("type=elemhideemulation"); | 112 result.push("type=elemhideemulation"); |
| 113 else if (filter instanceof SnippetFilter) |
| 114 result.push("type=snippet"); |
109 | 115 |
110 result.push("selectorDomain=" + (filter.selectorDomain || "")); | 116 result.push("injectionDomain=" + (filter.injectionDomain || "")); |
111 result.push("selector=" + filter.selector); | 117 result.push("code=" + filter.code); |
112 } | 118 } |
113 } | 119 } |
114 return result; | 120 return result; |
115 } | 121 } |
116 | 122 |
117 function addDefaults(expected) | 123 function addDefaults(expected) |
118 { | 124 { |
119 let type = null; | 125 let type = null; |
120 let hasProperty = {}; | 126 let hasProperty = {}; |
121 for (let entry of expected) | 127 for (let entry of expected) |
122 { | 128 { |
123 if (/^type=(.*)/.test(entry)) | 129 if (/^type=(.*)/.test(entry)) |
124 type = RegExp.$1; | 130 type = RegExp.$1; |
125 else if (/^(\w+)/.test(entry)) | 131 else if (/^(\w+)/.test(entry)) |
126 hasProperty[RegExp.$1] = true; | 132 hasProperty[RegExp.$1] = true; |
127 } | 133 } |
128 | 134 |
129 function addProperty(prop, value) | 135 function addProperty(prop, value) |
130 { | 136 { |
131 if (!(prop in hasProperty)) | 137 if (!(prop in hasProperty)) |
132 expected.push(prop + "=" + value); | 138 expected.push(prop + "=" + value); |
133 } | 139 } |
134 | 140 |
135 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || | 141 if (type == "whitelist" || type == "filterlist" || type == "elemhide" || |
136 type == "elemhideexception" || type == "elemhideemulation") | 142 type == "elemhideexception" || type == "elemhideemulation" || |
| 143 type == "snippet") |
137 { | 144 { |
138 addProperty("disabled", "false"); | 145 addProperty("disabled", "false"); |
139 addProperty("lastHit", "0"); | 146 addProperty("lastHit", "0"); |
140 addProperty("hitCount", "0"); | 147 addProperty("hitCount", "0"); |
141 } | 148 } |
142 if (type == "whitelist" || type == "filterlist") | 149 if (type == "whitelist" || type == "filterlist") |
143 { | 150 { |
144 addProperty("contentType", 0x7FFFFFFF & ~( | 151 addProperty("contentType", 0x7FFFFFFF & ~( |
145 t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK | 152 t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK |
146 )); | 153 )); |
147 addProperty("matchCase", "false"); | 154 addProperty("matchCase", "false"); |
148 addProperty("thirdParty", "null"); | 155 addProperty("thirdParty", "null"); |
149 addProperty("domains", ""); | 156 addProperty("domains", ""); |
150 addProperty("sitekeys", ""); | 157 addProperty("sitekeys", ""); |
151 } | 158 } |
152 if (type == "filterlist") | 159 if (type == "filterlist") |
153 { | 160 { |
154 addProperty("collapse", "null"); | 161 addProperty("collapse", "null"); |
155 addProperty("csp", "null"); | 162 addProperty("csp", "null"); |
156 } | 163 } |
157 if (type == "elemhide" || type == "elemhideexception" || | 164 if (type == "elemhide" || type == "elemhideexception" || |
158 type == "elemhideemulation") | 165 type == "elemhideemulation" || type == "snippet") |
159 { | 166 { |
160 addProperty("selectorDomain", ""); | 167 addProperty("injectionDomain", ""); |
161 addProperty("domains", ""); | 168 addProperty("domains", ""); |
162 } | 169 } |
163 } | 170 } |
164 | 171 |
165 function compareFilter(test, text, expected, postInit) | 172 function compareFilter(test, text, expected, postInit) |
166 { | 173 { |
167 addDefaults(expected); | 174 addDefaults(expected); |
168 | 175 |
169 let filter = Filter.fromText(text); | 176 let filter = Filter.fromText(text); |
170 if (postInit) | 177 if (postInit) |
(...skipping 23 matching lines...) Expand all Loading... |
194 | 201 |
195 exports.testFilterClassDefinitions = function(test) | 202 exports.testFilterClassDefinitions = function(test) |
196 { | 203 { |
197 test.equal(typeof Filter, "function", "typeof Filter"); | 204 test.equal(typeof Filter, "function", "typeof Filter"); |
198 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); | 205 test.equal(typeof InvalidFilter, "function", "typeof InvalidFilter"); |
199 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); | 206 test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); |
200 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); | 207 test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); |
201 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); | 208 test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); |
202 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); | 209 test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); |
203 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); | 210 test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); |
| 211 test.equal(typeof CodeInjectionFilter, "function", |
| 212 "typeof CodeInjectionFilter"); |
204 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); | 213 test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); |
205 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); | 214 test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); |
206 test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); | 215 test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); |
207 test.equal(typeof ElemHideEmulationFilter, "function", | 216 test.equal(typeof ElemHideEmulationFilter, "function", |
208 "typeof ElemHideEmulationFilter"); | 217 "typeof ElemHideEmulationFilter"); |
| 218 test.equal(typeof SnippetFilter, "function", "typeof SnippetFilter"); |
209 | 219 |
210 test.done(); | 220 test.done(); |
211 }; | 221 }; |
212 | 222 |
213 exports.testComments = function(test) | 223 exports.testComments = function(test) |
214 { | 224 { |
215 compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]); | 225 compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]); |
216 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]); | 226 compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]); |
217 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]); | 227 compareFilter(test, "!foo##bar", ["type=comment", "text=!foo##bar"]); |
218 | 228 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla
$csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]); | 329 compareFilter(test, "bla$csp=foo,csp=referrer foo", ["type=invalid", "text=bla
$csp=foo,csp=referrer foo", "reason=filter_invalid_csp"]); |
320 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp
=foo,csp=base-uri", "reason=filter_invalid_csp"]); | 330 compareFilter(test, "bla$csp=foo,csp=base-uri", ["type=invalid", "text=bla$csp
=foo,csp=base-uri", "reason=filter_invalid_csp"]); |
321 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali
d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp
"]); | 331 compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invali
d", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp
"]); |
322 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp
=foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); | 332 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp
=foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); |
323 | 333 |
324 test.done(); | 334 test.done(); |
325 }; | 335 }; |
326 | 336 |
327 exports.testElementHidingRules = function(test) | 337 exports.testElementHidingRules = function(test) |
328 { | 338 { |
329 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); | 339 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "code=ddd"]); |
330 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body
> div:first-child", "selector=body > div:first-child"]); | 340 compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body
> div:first-child", "code=body > div:first-child"]); |
331 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDo
main=foo", "selector=ddd", "domains=FOO"]); | 341 compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "injectionD
omain=foo", "code=ddd", "domains=FOO"]); |
332 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "se
lectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); | 342 compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "in
jectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO"]); |
333 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", "
selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); | 343 compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", "
injectionDomain=foo", "code=ddd", "domains=FOO|~BAR"]); |
334 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar#
#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]); | 344 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar#
#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO|~BAZ"]); |
335 | 345 |
336 test.done(); | 346 test.done(); |
337 }; | 347 }; |
338 | 348 |
339 exports.testElementHidingExceptions = function(test) | 349 exports.testElementHidingExceptions = function(test) |
340 { | 350 { |
341 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec
tor=ddd"]); | 351 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "code=
ddd"]); |
342 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t
ext=#@#body > div:first-child", "selector=body > div:first-child"]); | 352 compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "t
ext=#@#body > div:first-child", "code=body > div:first-child"]); |
343 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd",
"selectorDomain=foo", "selector=ddd", "domains=FOO"]); | 353 compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd",
"injectionDomain=foo", "code=ddd", "domains=FOO"]); |
344 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar#
@#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]); | 354 compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar#
@#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO"]); |
345 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba
r#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]); | 355 compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~ba
r#@#ddd", "injectionDomain=foo", "code=ddd", "domains=FOO|~BAR"]); |
346 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo
,~baz,bar#@#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BA
Z"]); | 356 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo
,~baz,bar#@#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO|~BAZ"]
); |
347 | 357 |
348 test.done(); | 358 test.done(); |
349 }; | 359 }; |
350 | 360 |
351 exports.testElemHideEmulationFilters = function(test) | 361 exports.testElemHideEmulationFilters = function(test) |
352 { | 362 { |
353 // Check valid domain combinations | 363 // Check valid domain combinations |
354 compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulatio
n", "text=foo.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector=
:-abp-properties(abc)", "domains=FOO.COM"]); | 364 compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulatio
n", "text=foo.com#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:-a
bp-properties(abc)", "domains=FOO.COM"]); |
355 compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhid
eemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "selectorDomain=fo
o.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]); | 365 compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhid
eemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "injectionDomain=f
oo.com", "code=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]); |
356 compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemu
lation", "text=foo.com,~bar#?#:-abp-properties(abc)", "selectorDomain=foo.com",
"selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]); | 366 compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemu
lation", "text=foo.com,~bar#?#:-abp-properties(abc)", "injectionDomain=foo.com",
"code=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]); |
357 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid
eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "selectorDomain=ba
r.com", "selector=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]); | 367 compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhid
eemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "injectionDomain=b
ar.com", "code=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]); |
358 | 368 |
359 // Check some special cases | 369 // Check some special cases |
360 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab
p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]); | 370 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab
p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]); |
361 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com#
?#abc", "selectorDomain=foo.com", "selector=abc", "domains=FOO.COM"]); | 371 compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com#
?#abc", "injectionDomain=foo.com", "code=abc", "domains=FOO.COM"]); |
362 compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation",
"text=foo.com#?#:-abp-foobar(abc)", "selectorDomain=foo.com", "selector=:-abp-fo
obar(abc)", "domains=FOO.COM"]); | 372 compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation",
"text=foo.com#?#:-abp-foobar(abc)", "injectionDomain=foo.com", "code=:-abp-fooba
r(abc)", "domains=FOO.COM"]); |
363 compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhide
emulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomain=foo.
com", "selector=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]); | 373 compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhide
emulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "injectionDomain=foo
.com", "code=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]); |
364 compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*)
)", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-imag
e: url(data:*))", "selectorDomain=foo.com", "selector=:-abp-properties(|backgrou
nd-image: url(data:*))", "domains=FOO.COM"]); | 374 compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*)
)", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-imag
e: url(data:*))", "injectionDomain=foo.com", "code=:-abp-properties(|background-
image: url(data:*))", "domains=FOO.COM"]); |
365 | 375 |
366 // Check conversion of legacy filters | 376 // Check conversion of legacy filters |
367 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulati
on", "text=foo.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector
=:-abp-properties(abc)", "domains=FOO.COM"]); | 377 compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulati
on", "text=foo.com#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:-
abp-properties(abc)", "domains=FOO.COM"]); |
368 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex
t("foo.com#?#:-abp-properties(abc)")); | 378 test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromTex
t("foo.com#?#:-abp-properties(abc)")); |
369 compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexcept
ion", "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selec
tor=[-abp-properties='abc']", "domains=FOO.COM"]); | 379 compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexcept
ion", "text=foo.com#@#[-abp-properties='abc']", "injectionDomain=foo.com", "code
=[-abp-properties='abc']", "domains=FOO.COM"]); |
370 compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=elemhideemulat
ion", "text=foo.com#?#[-abp-properties='abc']", "selectorDomain=foo.com", "selec
tor=[-abp-properties='abc']", "domains=FOO.COM"]); | 380 compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=elemhideemulat
ion", "text=foo.com#?#[-abp-properties='abc']", "injectionDomain=foo.com", "code
=[-abp-properties='abc']", "domains=FOO.COM"]); |
371 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhid
eemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomain=foo
.com", "selector=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]); | 381 compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhid
eemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "injectionDomain=fo
o.com", "code=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]); |
372 | 382 |
373 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037)
. | 383 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037)
. |
374 compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide"
, "text=foo.com##[-abp-properties-bogus='abc']", "selectorDomain=foo.com", "sele
ctor=[-abp-properties-bogus='abc']", "domains=FOO.COM"]); | 384 compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide"
, "text=foo.com##[-abp-properties-bogus='abc']", "injectionDomain=foo.com", "cod
e=[-abp-properties-bogus='abc']", "domains=FOO.COM"]); |
375 | 385 |
376 test.done(); | 386 test.done(); |
377 }; | 387 }; |
378 | 388 |
379 exports.testEmptyElemHideDomains = function(test) | 389 exports.testEmptyElemHideDomains = function(test) |
380 { | 390 { |
381 let emptyDomainFilters = [ | 391 let emptyDomainFilters = [ |
382 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", | 392 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", |
383 ",foo.com##selector", "foo.com,~##selector", | 393 ",foo.com##selector", "foo.com,~##selector", |
384 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" | 394 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" |
385 ]; | 395 ]; |
386 | 396 |
387 for (let filterText of emptyDomainFilters) | 397 for (let filterText of emptyDomainFilters) |
388 { | 398 { |
389 let filter = Filter.fromText(filterText); | 399 let filter = Filter.fromText(filterText); |
390 test.ok(filter instanceof InvalidFilter); | 400 test.ok(filter instanceof InvalidFilter); |
391 test.equal(filter.reason, "filter_invalid_domain"); | 401 test.equal(filter.reason, "filter_invalid_domain"); |
392 } | 402 } |
393 | 403 |
394 test.done(); | 404 test.done(); |
395 }; | 405 }; |
396 | 406 |
397 exports.testElemHideRulesWithBraces = function(test) | 407 exports.testElemHideRulesWithBraces = function(test) |
398 { | 408 { |
399 compareFilter( | 409 compareFilter( |
400 test, "###foo{color: red}", [ | 410 test, "###foo{color: red}", [ |
401 "type=elemhide", | 411 "type=elemhide", |
402 "text=###foo{color: red}", | 412 "text=###foo{color: red}", |
403 "selectorDomain=", | 413 "injectionDomain=", |
404 "selector=#foo\\7B color: red\\7D ", | 414 "code=#foo\\7B color: red\\7D ", |
405 "domains=" | 415 "domains=" |
406 ] | 416 ] |
407 ); | 417 ); |
408 compareFilter( | 418 compareFilter( |
409 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ | 419 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ |
410 "type=elemhideemulation", | 420 "type=elemhideemulation", |
411 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", | 421 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", |
412 "selectorDomain=foo.com", | 422 "injectionDomain=foo.com", |
413 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", | 423 "code=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", |
414 "domains=FOO.COM" | 424 "domains=FOO.COM" |
415 ] | 425 ] |
416 ); | 426 ); |
417 test.done(); | 427 test.done(); |
418 }; | 428 }; |
419 | 429 |
| 430 exports.testSnippetFilters = function(test) |
| 431 { |
| 432 compareFilter(test, "foo.com#$#abc", ["type=snippet", "text=foo.com#$#abc", "i
njectionDomain=foo.com", "code=abc", "domains=FOO.COM"]); |
| 433 compareFilter(test, "foo.com,~bar.com#$#abc", ["type=snippet", "text=foo.com,~
bar.com#$#abc", "injectionDomain=foo.com", "code=abc", "domains=FOO.COM|~BAR.COM
"]); |
| 434 compareFilter(test, "foo.com,~bar#$#abc", ["type=snippet", "text=foo.com,~bar#
$#abc", "injectionDomain=foo.com", "code=abc", "domains=FOO.COM|~BAR"]); |
| 435 compareFilter(test, "~foo.com,bar.com#$#abc", ["type=snippet", "text=~foo.com,
bar.com#$#abc", "injectionDomain=bar.com", "code=abc", "domains=BAR.COM|~FOO.COM
"]); |
| 436 |
| 437 test.done(); |
| 438 }; |
| 439 |
420 exports.testFilterNormalization = function(test) | 440 exports.testFilterNormalization = function(test) |
421 { | 441 { |
422 // Line breaks etc | 442 // Line breaks etc |
423 test.equal(Filter.normalize("\n\t\nad\ns"), | 443 test.equal(Filter.normalize("\n\t\nad\ns"), |
424 "ads"); | 444 "ads"); |
425 | 445 |
426 // Comment filters | 446 // Comment filters |
427 test.equal(Filter.normalize(" ! fo o## bar "), | 447 test.equal(Filter.normalize(" ! fo o## bar "), |
428 "! fo o## bar"); | 448 "! fo o## bar"); |
429 | 449 |
(...skipping 19 matching lines...) Expand all Loading... |
449 test.equal(Filter.normalize(" domain.c om#@# # sele ctor "), | 469 test.equal(Filter.normalize(" domain.c om#@# # sele ctor "), |
450 "domain.com#@## sele ctor"); | 470 "domain.com#@## sele ctor"); |
451 | 471 |
452 // Incorrect syntax: the separator "#@#" cannot contain spaces; treated as a | 472 // Incorrect syntax: the separator "#@#" cannot contain spaces; treated as a |
453 // regular filter instead (not an element hiding filter either!), because | 473 // regular filter instead (not an element hiding filter either!), because |
454 // unlike the case with "# ?##" the "##" following the "@" is not considered | 474 // unlike the case with "# ?##" the "##" following the "@" is not considered |
455 // to be a separator | 475 // to be a separator |
456 test.equal(Filter.normalize(" domain.c om# @## sele ctor "), | 476 test.equal(Filter.normalize(" domain.c om# @## sele ctor "), |
457 "domain.com#@##selector"); | 477 "domain.com#@##selector"); |
458 | 478 |
| 479 // Snippet filters |
| 480 test.equal(Filter.normalize(" domain.c om#$# sni pp et "), |
| 481 "domain.com#$#sni pp et"); |
| 482 |
459 // Regular filters | 483 // Regular filters |
460 let normalized = Filter.normalize( | 484 let normalized = Filter.normalize( |
461 " b$l a$sitekey= foo ,domain= do main.com |foo .com,c sp= c s p
" | 485 " b$l a$sitekey= foo ,domain= do main.com |foo .com,c sp= c s p
" |
462 ); | 486 ); |
463 test.equal( | 487 test.equal( |
464 normalized, | 488 normalized, |
465 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p" | 489 "b$la$sitekey=foo,domain=domain.com|foo.com,csp=c s p" |
466 ); | 490 ); |
467 compareFilter( | 491 compareFilter( |
468 test, normalized, [ | 492 test, normalized, [ |
(...skipping 24 matching lines...) Expand all Loading... |
493 "foo$csp=bar,$csp=c s p"); | 517 "foo$csp=bar,$csp=c s p"); |
494 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), | 518 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), |
495 "foo$bar$csp=ba r"); | 519 "foo$bar$csp=ba r"); |
496 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), | 520 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), |
497 "f$o$o$csp=f o o"); | 521 "f$o$o$csp=f o o"); |
498 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1=
1&$2=2&$3=3"), | 522 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1=
1&$2=2&$3=3"), |
499 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); | 523 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); |
500 | 524 |
501 test.done(); | 525 test.done(); |
502 }; | 526 }; |
OLD | NEW |