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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 } | 100 } |
101 else if (filter instanceof ElemHideBase) | 101 else if (filter instanceof ElemHideBase) |
102 { | 102 { |
103 if (filter instanceof ElemHideFilter) | 103 if (filter instanceof ElemHideFilter) |
104 result.push("type=elemhide"); | 104 result.push("type=elemhide"); |
105 else if (filter instanceof ElemHideException) | 105 else if (filter instanceof ElemHideException) |
106 result.push("type=elemhideexception"); | 106 result.push("type=elemhideexception"); |
107 else if (filter instanceof ElemHideEmulationFilter) | 107 else if (filter instanceof ElemHideEmulationFilter) |
108 result.push("type=elemhideemulation"); | 108 result.push("type=elemhideemulation"); |
109 | 109 |
110 result.push("selectorDomain=" + (filter.selectorDomain || "")); | 110 result.push("injectionDomain=" + (filter.injectionDomain || "")); |
111 result.push("selector=" + filter.selector); | 111 result.push("code=" + filter.code); |
112 } | 112 } |
113 } | 113 } |
114 return result; | 114 return result; |
115 } | 115 } |
116 | 116 |
117 function addDefaults(expected) | 117 function addDefaults(expected) |
118 { | 118 { |
119 let type = null; | 119 let type = null; |
120 let hasProperty = {}; | 120 let hasProperty = {}; |
121 for (let entry of expected) | 121 for (let entry of expected) |
(...skipping 28 matching lines...) Expand all Loading... |
150 addProperty("sitekeys", ""); | 150 addProperty("sitekeys", ""); |
151 } | 151 } |
152 if (type == "filterlist") | 152 if (type == "filterlist") |
153 { | 153 { |
154 addProperty("collapse", "null"); | 154 addProperty("collapse", "null"); |
155 addProperty("csp", "null"); | 155 addProperty("csp", "null"); |
156 } | 156 } |
157 if (type == "elemhide" || type == "elemhideexception" || | 157 if (type == "elemhide" || type == "elemhideexception" || |
158 type == "elemhideemulation") | 158 type == "elemhideemulation") |
159 { | 159 { |
160 addProperty("selectorDomain", ""); | 160 addProperty("injectionDomain", ""); |
161 addProperty("domains", ""); | 161 addProperty("domains", ""); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 function compareFilter(test, text, expected, postInit) | 165 function compareFilter(test, text, expected, postInit) |
166 { | 166 { |
167 addDefaults(expected); | 167 addDefaults(expected); |
168 | 168 |
169 let filter = Filter.fromText(text); | 169 let filter = Filter.fromText(text); |
170 if (postInit) | 170 if (postInit) |
(...skipping 148 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"]); | 319 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"]); | 320 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
"]); | 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
"]); |
322 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp
=foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); | 322 compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp
=foo,csp=ReFeRReR", "reason=filter_invalid_csp"]); |
323 | 323 |
324 test.done(); | 324 test.done(); |
325 }; | 325 }; |
326 | 326 |
327 exports.testElementHidingRules = function(test) | 327 exports.testElementHidingRules = function(test) |
328 { | 328 { |
329 compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]); | 329 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"]); | 330 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"]); | 331 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"]); | 332 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"]); | 333 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"]); | 334 compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar#
#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO|~BAZ"]); |
335 | 335 |
336 test.done(); | 336 test.done(); |
337 }; | 337 }; |
338 | 338 |
339 exports.testElementHidingExceptions = function(test) | 339 exports.testElementHidingExceptions = function(test) |
340 { | 340 { |
341 compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selec
tor=ddd"]); | 341 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"]); | 342 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"]); | 343 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"]); | 344 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"]); | 345 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"]); | 346 compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo
,~baz,bar#@#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO|~BAZ"]
); |
347 | 347 |
348 test.done(); | 348 test.done(); |
349 }; | 349 }; |
350 | 350 |
351 exports.testElemHideEmulationFilters = function(test) | 351 exports.testElemHideEmulationFilters = function(test) |
352 { | 352 { |
353 // Check valid domain combinations | 353 // 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"]); | 354 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"]); | 355 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"]); | 356 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"]); | 357 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 | 358 |
359 // Check some special cases | 359 // Check some special cases |
360 compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-ab
p-properties(abc)", "reason=filter_elemhideemulation_nodomain"]); | 360 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"]); | 361 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"]); | 362 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"]); | 363 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"]); | 364 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 | 365 |
366 // Check conversion of legacy filters | 366 // 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"]); | 367 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)")); | 368 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"]); | 369 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"]); | 370 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"]); | 371 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 | 372 |
373 // test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037)
. | 373 // 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"]); | 374 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 | 375 |
376 test.done(); | 376 test.done(); |
377 }; | 377 }; |
378 | 378 |
379 exports.testEmptyElemHideDomains = function(test) | 379 exports.testEmptyElemHideDomains = function(test) |
380 { | 380 { |
381 let emptyDomainFilters = [ | 381 let emptyDomainFilters = [ |
382 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", | 382 ",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", |
383 ",foo.com##selector", "foo.com,~##selector", | 383 ",foo.com##selector", "foo.com,~##selector", |
384 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" | 384 "foo.com,,bar.com##selector", "foo.com,~,bar.com##selector" |
385 ]; | 385 ]; |
386 | 386 |
387 for (let filterText of emptyDomainFilters) | 387 for (let filterText of emptyDomainFilters) |
388 { | 388 { |
389 let filter = Filter.fromText(filterText); | 389 let filter = Filter.fromText(filterText); |
390 test.ok(filter instanceof InvalidFilter); | 390 test.ok(filter instanceof InvalidFilter); |
391 test.equal(filter.reason, "filter_invalid_domain"); | 391 test.equal(filter.reason, "filter_invalid_domain"); |
392 } | 392 } |
393 | 393 |
394 test.done(); | 394 test.done(); |
395 }; | 395 }; |
396 | 396 |
397 exports.testElemHideRulesWithBraces = function(test) | 397 exports.testElemHideRulesWithBraces = function(test) |
398 { | 398 { |
399 compareFilter( | 399 compareFilter( |
400 test, "###foo{color: red}", [ | 400 test, "###foo{color: red}", [ |
401 "type=elemhide", | 401 "type=elemhide", |
402 "text=###foo{color: red}", | 402 "text=###foo{color: red}", |
403 "selectorDomain=", | 403 "injectionDomain=", |
404 "selector=#foo\\7B color: red\\7D ", | 404 "code=#foo\\7B color: red\\7D ", |
405 "domains=" | 405 "domains=" |
406 ] | 406 ] |
407 ); | 407 ); |
408 compareFilter( | 408 compareFilter( |
409 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ | 409 test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [ |
410 "type=elemhideemulation", | 410 "type=elemhideemulation", |
411 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", | 411 "text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", |
412 "selectorDomain=foo.com", | 412 "injectionDomain=foo.com", |
413 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", | 413 "code=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", |
414 "domains=FOO.COM" | 414 "domains=FOO.COM" |
415 ] | 415 ] |
416 ); | 416 ); |
417 test.done(); | 417 test.done(); |
418 }; | 418 }; |
419 | 419 |
420 exports.testFilterNormalization = function(test) | 420 exports.testFilterNormalization = function(test) |
421 { | 421 { |
422 // Line breaks etc | 422 // Line breaks etc |
423 test.equal(Filter.normalize("\n\t\nad\ns"), | 423 test.equal(Filter.normalize("\n\t\nad\ns"), |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 "foo$csp=bar,$csp=c s p"); | 493 "foo$csp=bar,$csp=c s p"); |
494 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), | 494 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), |
495 "foo$bar$csp=ba r"); | 495 "foo$bar$csp=ba r"); |
496 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), | 496 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), |
497 "f$o$o$csp=f o o"); | 497 "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"), | 498 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"); | 499 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); |
500 | 500 |
501 test.done(); | 501 test.done(); |
502 }; | 502 }; |
OLD | NEW |