| Left: | ||
| Right: | 
| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 { | 50 { | 
| 51 // fields are: | 51 // fields are: | 
| 52 // text, type, typeName, collapse (optional, BlockingFilter only) | 52 // text, type, typeName, collapse (optional, BlockingFilter only) | 
| 53 let tests = [ | 53 let tests = [ | 
| 54 ["!asdf", CommentFilter, "comment"], | 54 ["!asdf", CommentFilter, "comment"], | 
| 55 ["asdf", BlockingFilter, "blocking", 1], | 55 ["asdf", BlockingFilter, "blocking", 1], | 
| 56 ["asdf$image,~collapse", BlockingFilter, "blocking", 0], | 56 ["asdf$image,~collapse", BlockingFilter, "blocking", 0], | 
| 57 ["/asdf/", BlockingFilter, "blocking", 1], | 57 ["/asdf/", BlockingFilter, "blocking", 1], | 
| 58 ["/asdf??+/", InvalidFilter, "invalid"], | 58 ["/asdf??+/", InvalidFilter, "invalid"], | 
| 59 ["@@asdf", WhitelistFilter, "whitelist"], | 59 ["@@asdf", WhitelistFilter, "whitelist"], | 
| 60 ["@@asdf$image,~collapse", WhitelistFilter, "whitelist", 0], | 60 ["@@asdf$image,~collapse", WhitelistFilter, "whitelist"], | 
| 61 ["@@/asdf/", WhitelistFilter, "whitelist"], | 61 ["@@/asdf/", WhitelistFilter, "whitelist"], | 
| 62 ["@@/asdf??+/", InvalidFilter, "invalid"], | 62 ["@@/asdf??+/", InvalidFilter, "invalid"], | 
| 63 ["##asdf", ElemHideFilter, "elemhide"], | 63 ["##asdf", ElemHideFilter, "elemhide"], | 
| 64 ["#@#asdf", ElemHideException, "elemhideexception"], | 64 ["#@#asdf", ElemHideException, "elemhideexception"], | 
| 65 ["foobar##asdf", ElemHideFilter, "elemhide"], | 65 ["foobar##asdf", ElemHideFilter, "elemhide"], | 
| 66 ["foobar#@#asdf", ElemHideException, "elemhideexception"], | 66 ["foobar#@#asdf", ElemHideException, "elemhideexception"], | 
| 67 ["foobar##a", ElemHideFilter, "elemhide"], | 67 ["foobar##a", ElemHideFilter, "elemhide"], | 
| 68 ["foobar#@#a", ElemHideException, "elemhideexception"], | 68 ["foobar#@#a", ElemHideException, "elemhideexception"], | 
| 69 | 69 | 
| 70 ["foobar#asdf", BlockingFilter, "blocking", 1], | 70 ["foobar#asdf", BlockingFilter, "blocking", 1], | 
| 71 ["foobar|foobas##asdf", BlockingFilter, "blocking", 1], | 71 ["foobar|foobas##asdf", BlockingFilter, "blocking", 1], | 
| 72 ["foobar##asdf{asdf}", BlockingFilter, "blocking", 1], | 72 ["foobar##asdf{asdf}", ElemHideFilter, "elemhide"], | 
| 73 ["foobar##", BlockingFilter, "blocking", 1], | 73 ["foobar##", BlockingFilter, "blocking", 1], | 
| 74 ["foobar#@#", BlockingFilter, "blocking", 1], | 74 ["foobar#@#", BlockingFilter, "blocking", 1], | 
| 75 ["asdf$foobar", InvalidFilter, "invalid"], | 75 ["asdf$foobar", InvalidFilter, "invalid"], | 
| 76 ["asdf$image,foobar", InvalidFilter, "invalid"], | 76 ["asdf$image,foobar", InvalidFilter, "invalid"], | 
| 77 ["asdf$image=foobar", BlockingFilter, "blocking", 1], | 77 ["asdf$image=foobar", BlockingFilter, "blocking", 1], | 
| 78 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking", 0], | 78 ["asdf$image=foobar=xyz,~collapse", BlockingFilter, "blocking", 0], | 
| 79 | 79 | 
| 80 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"], | 80 ["##foo[-abp-properties='something']bar", InvalidFilter, "invalid"], | 
| 81 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep tion"], | 81 ["#@#foo[-abp-properties='something']bar", ElemHideException, "elemhideexcep tion"], | 
| 82 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter , "elemhideemulation"], | 82 ["example.com##foo[-abp-properties='something']bar", ElemHideEmulationFilter , "elemhideemulation"], | 
| (...skipping 13 matching lines...) Expand all Loading... | |
| 96 ["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "ele mhideemulation"], | 96 ["example.com##[-abp-properties=(something)]", ElemHideEmulationFilter, "ele mhideemulation"], | 
| 97 ["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhide exception"] | 97 ["example.com#@#[-abp-properties=(something)]", ElemHideException, "elemhide exception"] | 
| 98 ]; | 98 ]; | 
| 99 for (let [text, type, typeName, collapse] of tests) | 99 for (let [text, type, typeName, collapse] of tests) | 
| 100 { | 100 { | 
| 101 let filter = Filter.fromText(text); | 101 let filter = Filter.fromText(text); | 
| 102 test.ok(filter instanceof Filter, "Got filter for " + text); | 102 test.ok(filter instanceof Filter, "Got filter for " + text); | 
| 103 test.equal(filter.text, text, "Correct filter text for " + text); | 103 test.equal(filter.text, text, "Correct filter text for " + text); | 
| 104 test.ok(filter instanceof type, "Correct filter type for " + text); | 104 test.ok(filter instanceof type, "Correct filter type for " + text); | 
| 105 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) | 106 if (filter instanceof BlockingFilter) | 
| 
 
sergei
2017/11/21 16:17:01
What about checking that `filter.collapse` and `co
 
hub
2017/11/21 17:42:47
done.
 
 | |
| 107 test.equal(filter.collapse, collapse); | 107 test.equal(filter.collapse, collapse); | 
| 108 else | |
| 109 test.equal(filter.collapse, undefined); | |
| 108 if (type == InvalidFilter) | 110 if (type == InvalidFilter) | 
| 109 test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); | 111 test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); | 
| 110 filter.delete(); | 112 filter.delete(); | 
| 111 } | 113 } | 
| 112 test.done(); | 114 test.done(); | 
| 113 }; | 115 }; | 
| 114 | 116 | 
| 115 exports.testClassHierarchy = function(test) | 117 exports.testClassHierarchy = function(test) | 
| 116 { | 118 { | 
| 117 let allClasses = [ | 119 let allClasses = [ | 
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 | 380 | 
| 379 for (let [text, selector, selectorDomain] of tests) | 381 for (let [text, selector, selectorDomain] of tests) | 
| 380 { | 382 { | 
| 381 doTest(text, selector, selectorDomain); | 383 doTest(text, selector, selectorDomain); | 
| 382 doTest(text.replace("##", "#@#"), selector, selectorDomain); | 384 doTest(text.replace("##", "#@#"), selector, selectorDomain); | 
| 383 } | 385 } | 
| 384 | 386 | 
| 385 test.done(); | 387 test.done(); | 
| 386 }; | 388 }; | 
| 387 | 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 | |
| 388 exports.testNotifications = function(test) | 405 exports.testNotifications = function(test) | 
| 389 { | 406 { | 
| 390 function checkNotifications(action, expected, message) | 407 function checkNotifications(action, expected, message) | 
| 391 { | 408 { | 
| 392 let result = null; | 409 let result = null; | 
| 393 let listener = (topic, filter) => | 410 let listener = (topic, filter) => | 
| 394 { | 411 { | 
| 395 if (result) | 412 if (result) | 
| 396 test.ok(false, "Got more that one notification - " + message); | 413 test.ok(false, "Got more that one notification - " + message); | 
| 397 else | 414 else | 
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 435 filter.hitCount++; | 452 filter.hitCount++; | 
| 436 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); | 453 }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); | 
| 437 checkNotifications(() => | 454 checkNotifications(() => | 
| 438 { | 455 { | 
| 439 filter.hitCount = 0; | 456 filter.hitCount = 0; | 
| 440 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); | 457 }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); | 
| 441 | 458 | 
| 442 filter.delete(); | 459 filter.delete(); | 
| 443 test.done(); | 460 test.done(); | 
| 444 }; | 461 }; | 
| LEFT | RIGHT |