LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 30 matching lines...) Expand all Loading... |
41 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, | 41 BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, |
42 ElemHideException, ElemHideEmulationFilter | 42 ElemHideException, ElemHideEmulationFilter |
43 } = sandboxedRequire("../lib/filterClasses") | 43 } = sandboxedRequire("../lib/filterClasses") |
44 ); | 44 ); |
45 ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier")); | 45 ({FilterNotifier} = sandboxedRequire("../lib/filterNotifier")); |
46 callback(); | 46 callback(); |
47 }; | 47 }; |
48 | 48 |
49 exports.testFromText = function(test) | 49 exports.testFromText = function(test) |
50 { | 50 { |
| 51 // fields are: |
| 52 // text, type, typeName, collapse (optional, BlockingFilter only) |
51 let tests = [ | 53 let tests = [ |
52 ["!asdf", CommentFilter, "comment"], | 54 ["!asdf", CommentFilter, "comment"], |
53 ["asdf", BlockingFilter, "blocking"], | 55 ["asdf", BlockingFilter, "blocking", 1], |
54 ["asdf$image,~collapse", BlockingFilter, "blocking"], | 56 ["asdf$image,~collapse", BlockingFilter, "blocking", 0], |
55 ["/asdf/", BlockingFilter, "blocking"], | 57 ["/asdf/", BlockingFilter, "blocking", 1], |
56 ["/asdf??+/", InvalidFilter, "invalid"], | 58 ["/asdf??+/", InvalidFilter, "invalid"], |
57 ["@@asdf", WhitelistFilter, "whitelist"], | 59 ["@@asdf", WhitelistFilter, "whitelist"], |
58 ["@@asdf$image,~collapse", WhitelistFilter, "whitelist"], | 60 ["@@asdf$image,~collapse", WhitelistFilter, "whitelist"], |
59 ["@@/asdf/", WhitelistFilter, "whitelist"], | 61 ["@@/asdf/", WhitelistFilter, "whitelist"], |
60 ["@@/asdf??+/", InvalidFilter, "invalid"], | 62 ["@@/asdf??+/", InvalidFilter, "invalid"], |
61 ["##asdf", ElemHideFilter, "elemhide"], | 63 ["##asdf", ElemHideFilter, "elemhide"], |
62 ["#@#asdf", ElemHideException, "elemhideexception"], | 64 ["#@#asdf", ElemHideException, "elemhideexception"], |
63 ["foobar##asdf", ElemHideFilter, "elemhide"], | 65 ["foobar##asdf", ElemHideFilter, "elemhide"], |
64 ["foobar#@#asdf", ElemHideException, "elemhideexception"], | 66 ["foobar#@#asdf", ElemHideException, "elemhideexception"], |
65 ["foobar##a", ElemHideFilter, "elemhide"], | 67 ["foobar##a", ElemHideFilter, "elemhide"], |
66 ["foobar#@#a", ElemHideException, "elemhideexception"], | 68 ["foobar#@#a", ElemHideException, "elemhideexception"], |
67 | 69 |
68 ["foobar#asdf", BlockingFilter, "blocking"], | 70 ["foobar#asdf", BlockingFilter, "blocking", 1], |
69 ["foobar|foobas##asdf", BlockingFilter, "blocking"], | 71 ["foobar|foobas##asdf", BlockingFilter, "blocking", 1], |
70 ["foobar##asdf{asdf}", BlockingFilter, "blocking"], | 72 ["foobar##asdf{asdf}", ElemHideFilter, "elemhide"], |
71 ["foobar##", BlockingFilter, "blocking"], | 73 ["foobar##", BlockingFilter, "blocking", 1], |
72 ["foobar#@#", BlockingFilter, "blocking"], | 74 ["foobar#@#", BlockingFilter, "blocking", 1], |
73 ["asdf$foobar", InvalidFilter, "invalid"], | 75 ["asdf$foobar", InvalidFilter, "invalid"], |
74 ["asdf$image,foobar", InvalidFilter, "invalid"], | 76 ["asdf$image,foobar", InvalidFilter, "invalid"], |
75 ["asdf$image=foobar", BlockingFilter, "blocking"], | 77 ["asdf$image=foobar", BlockingFilter, "blocking", 1], |
76 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking"], | 78 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking", 0], |
77 | 79 |
78 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"], | 80 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"], |
79 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep
tion"], | 81 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep
tion"], |
80 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter
, "elemhideemulation"], | 82 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter
, "elemhideemulation"], |
81 ["example.com#@#foo[-abp-properties='something']bar", ElemHideException, "el
emhideexception"], | 83 ["example.com#@#foo[-abp-properties='something']bar", ElemHideException, "el
emhideexception"], |
82 ["~example.com##foo[-abp-properties='something']bar", InvalidFilter, "invali
d"], | 84 ["~example.com##foo[-abp-properties='something']bar", InvalidFilter, "invali
d"], |
83 ["~example.com#@#foo[-abp-properties='something']bar", ElemHideException, "e
lemhideexception"], | 85 ["~example.com#@#foo[-abp-properties='something']bar", ElemHideException, "e
lemhideexception"], |
84 ["~example.com,~example.info##foo[-abp-properties='something']bar", InvalidF
ilter, "invalid"], | 86 ["~example.com,~example.info##foo[-abp-properties='something']bar", InvalidF
ilter, "invalid"], |
85 ["~example.com,~example.info#@#foo[-abp-properties='something']bar", ElemHid
eException, "elemhideexception"], | 87 ["~example.com,~example.info#@#foo[-abp-properties='something']bar", ElemHid
eException, "elemhideexception"], |
86 ["~sub.example.com,example.com##foo[-abp-properties='something']bar", ElemHi
deEmulationFilter, "elemhideemulation"], | 88 ["~sub.example.com,example.com##foo[-abp-properties='something']bar", ElemHi
deEmulationFilter, "elemhideemulation"], |
87 ["~sub.example.com,example.com#@#foo[-abp-properties='something']bar", ElemH
ideException, "elemhideexception"], | 89 ["~sub.example.com,example.com#@#foo[-abp-properties='something']bar", ElemH
ideException, "elemhideexception"], |
88 ["example.com,~sub.example.com##foo[-abp-properties='something']bar", ElemHi
deEmulationFilter, "elemhideemulation"], | 90 ["example.com,~sub.example.com##foo[-abp-properties='something']bar", ElemHi
deEmulationFilter, "elemhideemulation"], |
89 ["example.com,~sub.example.com#@#foo[-abp-properties='something']bar", ElemH
ideException, "elemhideexception"], | 91 ["example.com,~sub.example.com#@#foo[-abp-properties='something']bar", ElemH
ideException, "elemhideexception"], |
90 ["example.com##[-abp-properties='something']", ElemHideEmulationFilter, "ele
mhideemulation"], | 92 ["example.com##[-abp-properties='something']", ElemHideEmulationFilter, "ele
mhideemulation"], |
91 ["example.com#@#[-abp-properties='something']", ElemHideException, "elemhide
exception"], | 93 ["example.com#@#[-abp-properties='something']", ElemHideException, "elemhide
exception"], |
92 ["example.com##[-abp-properties=\"something\"]", ElemHideEmulationFilter, "e
lemhideemulation"], | 94 ["example.com##[-abp-properties=\"something\"]", ElemHideEmulationFilter, "e
lemhideemulation"], |
93 ["example.com#@#[-abp-properties=\"something\"]", ElemHideException, "elemhi
deexception"], | 95 ["example.com#@#[-abp-properties=\"something\"]", ElemHideException, "elemhi
deexception"], |
94 ["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "ele
mhideemulation"], | 96 ["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "ele
mhideemulation"], |
95 ["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhide
exception"] | 97 ["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhide
exception"] |
96 ]; | 98 ]; |
97 for (let [text, type, typeName] of tests) | 99 for (let [text, type, typeName, collapse] of tests) |
98 { | 100 { |
99 let filter = Filter.fromText(text); | 101 let filter = Filter.fromText(text); |
100 test.ok(filter instanceof Filter, "Got filter for " + text); | 102 test.ok(filter instanceof Filter, "Got filter for " + text); |
101 test.equal(filter.text, text, "Correct filter text for " + text); | 103 test.equal(filter.text, text, "Correct filter text for " + text); |
102 test.ok(filter instanceof type, "Correct filter type for " + text); | 104 test.ok(filter instanceof type, "Correct filter type for " + text); |
103 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam
e); | 105 test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam
e); |
| 106 if (filter instanceof BlockingFilter) |
| 107 test.equal(filter.collapse, collapse); |
| 108 else |
| 109 test.equal(filter.collapse, undefined); |
104 if (type == InvalidFilter) | 110 if (type == InvalidFilter) |
105 test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); | 111 test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); |
106 filter.delete(); | 112 filter.delete(); |
107 } | 113 } |
108 test.done(); | 114 test.done(); |
109 }; | 115 }; |
110 | 116 |
111 exports.testClassHierarchy = function(test) | 117 exports.testClassHierarchy = function(test) |
112 { | 118 { |
113 let allClasses = [ | 119 let allClasses = [ |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 380 |
375 for (let [text, selector, selectorDomain] of tests) | 381 for (let [text, selector, selectorDomain] of tests) |
376 { | 382 { |
377 doTest(text, selector, selectorDomain); | 383 doTest(text, selector, selectorDomain); |
378 doTest(text.replace("##", "#@#"), selector, selectorDomain); | 384 doTest(text.replace("##", "#@#"), selector, selectorDomain); |
379 } | 385 } |
380 | 386 |
381 test.done(); | 387 test.done(); |
382 }; | 388 }; |
383 | 389 |
| 390 exports.testElemHideRulesWithBraces = function(test) |
| 391 { |
| 392 let filter = Filter.fromText("###foo{color: red}"); |
| 393 test.equal(filter.type, "elemhide"); |
| 394 test.equal(filter.selector, "#foo\\7B color: red\\7D "); |
| 395 filter.delete(); |
| 396 |
| 397 filter = Filter.fromText("foo.com##[-abp-properties='/margin: [3-4]{2}/']"); |
| 398 test.equal(filter.type, "elemhideemulation"); |
| 399 test.equal(filter.selector, "[-abp-properties='/margin: [3-4]\\7B 2\\7D /']"); |
| 400 filter.delete(); |
| 401 |
| 402 test.done(); |
| 403 }; |
| 404 |
384 exports.testNotifications = function(test) | 405 exports.testNotifications = function(test) |
385 { | 406 { |
386 function checkNotifications(action, expected, message) | 407 function checkNotifications(action, expected, message) |
387 { | 408 { |
388 let result = null; | 409 let result = null; |
389 let listener = (topic, filter) => | 410 let listener = (topic, filter) => |
390 { | 411 { |
391 if (result) | 412 if (result) |
392 test.ok(false, "Got more that one notification - " + message); | 413 test.ok(false, "Got more that one notification - " + message); |
393 else | 414 else |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 filter.hitCount++; | 452 filter.hitCount++; |
432 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); | 453 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); |
433 checkNotifications(() => | 454 checkNotifications(() => |
434 { | 455 { |
435 filter.hitCount = 0; | 456 filter.hitCount = 0; |
436 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); | 457 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); |
437 | 458 |
438 filter.delete(); | 459 filter.delete(); |
439 test.done(); | 460 test.done(); |
440 }; | 461 }; |
LEFT | RIGHT |