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("selectorDomains=" + (filter.selectorDomains || "")); |
111 result.push("selector=" + filter.selector); | 111 result.push("selector=" + filter.selector); |
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 = {}; |
(...skipping 29 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("selectorDomains", ""); |
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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", "selector=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", "selector=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", "selectorDo
mains=foo", "selector=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", "se
lectorDomains=foo,bar", "selector=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", "
selectorDomains=foo", "selector=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", "selectorDomains=foo,bar", "selector=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", "selec
tor=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", "selector=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",
"selectorDomains=foo", "selector=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", "selectorDomains=foo,bar", "selector=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", "selectorDomains=foo", "selector=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", "selectorDomains=foo,bar", "selector=ddd", "domains=BAR|FOO|~B
AZ"]); |
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)", "selectorDomains=foo.com", "selector
=:-abp-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)", "selectorDomains=f
oo.com", "selector=:-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)", "selectorDomains=foo.com",
"selector=:-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)", "selectorDomains=b
ar.com", "selector=:-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", "selectorDomains=foo.com", "selector=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)", "selectorDomains=foo.com", "selector=:-abp-f
oobar(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", "selectorDomains=foo
.com", "selector=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:*))", "selectorDomains=foo.com", "selector=:-abp-properties(|backgro
und-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)", "selectorDomains=foo.com", "selecto
r=:-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']", "selectorDomains=foo.com", "sele
ctor=[-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']", "selectorDomains=foo.com", "sele
ctor=[-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", "selectorDomains=fo
o.com", "selector=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']", "selectorDomains=foo.com", "sel
ector=[-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 "selectorDomains=", |
404 "selector=#foo\\7B color: red\\7D ", | 404 "selector=#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 "selectorDomains=foo.com", |
413 "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)", | 413 "selector=:-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 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 "foo$csp=bar,$csp=c s p"); | 468 "foo$csp=bar,$csp=c s p"); |
469 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), | 469 test.equal(Filter.normalize(" f o o $ bar $csp=ba r"), |
470 "foo$bar$csp=ba r"); | 470 "foo$bar$csp=ba r"); |
471 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), | 471 test.equal(Filter.normalize("f $ o $ o $ csp=f o o "), |
472 "f$o$o$csp=f o o"); | 472 "f$o$o$csp=f o o"); |
473 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1=
1&$2=2&$3=3"), | 473 test.equal(Filter.normalize("/foo$/$ csp = script-src http://example.com/?$1=
1&$2=2&$3=3"), |
474 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); | 474 "/foo$/$csp=script-src http://example.com/?$1=1&$2=2&$3=3"); |
475 | 475 |
476 test.done(); | 476 test.done(); |
477 }; | 477 }; |
OLD | NEW |