| 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 | 
|   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 let {createSandbox} = require("./_common"); |   20 let {createSandbox} = require("./_common"); | 
 |   21 const {withNAD} = require("./_test-utils"); | 
|   21  |   22  | 
|   22 let Filter = null; |   23 let Filter = null; | 
|   23 let InvalidFilter = null; |   24 let InvalidFilter = null; | 
|   24 let CommentFilter = null; |   25 let CommentFilter = null; | 
|   25 let ActiveFilter = null; |   26 let ActiveFilter = null; | 
|   26 let RegExpFilter = null; |   27 let RegExpFilter = null; | 
|   27 let BlockingFilter = null; |   28 let BlockingFilter = null; | 
|   28 let WhitelistFilter = null; |   29 let WhitelistFilter = null; | 
|   29 let ElemHideBase = null; |   30 let ElemHideBase = null; | 
|   30 let ElemHideFilter = null; |   31 let ElemHideFilter = null; | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   89     ["~sub.example.com,example.com#@#foo:-abp-properties(something)bar", ElemHid
     eException, "elemhideexception"], |   90     ["~sub.example.com,example.com#@#foo:-abp-properties(something)bar", ElemHid
     eException, "elemhideexception"], | 
|   90     ["example.com,~sub.example.com#?#foo:-abp-properties(something)bar", ElemHid
     eEmulationFilter, "elemhideemulation"], |   91     ["example.com,~sub.example.com#?#foo:-abp-properties(something)bar", ElemHid
     eEmulationFilter, "elemhideemulation"], | 
|   91     ["example.com,~sub.example.com#@#foo:-abp-properties(something)bar", ElemHid
     eException, "elemhideexception"], |   92     ["example.com,~sub.example.com#@#foo:-abp-properties(something)bar", ElemHid
     eException, "elemhideexception"], | 
|   92     ["example.com#?#:-abp-properties(something)", ElemHideEmulationFilter, "elem
     hideemulation"], |   93     ["example.com#?#:-abp-properties(something)", ElemHideEmulationFilter, "elem
     hideemulation"], | 
|   93     ["example.com#@#:-abp-properties(something)", ElemHideException, "elemhideex
     ception"], |   94     ["example.com#@#:-abp-properties(something)", ElemHideException, "elemhideex
     ception"], | 
|   94     ["example.com#?#:-abp-properties((something))", ElemHideEmulationFilter, "el
     emhideemulation"], |   95     ["example.com#?#:-abp-properties((something))", ElemHideEmulationFilter, "el
     emhideemulation"], | 
|   95     ["example.com#@#:-abp-properties((something))", ElemHideException, "elemhide
     exception"] |   96     ["example.com#@#:-abp-properties((something))", ElemHideException, "elemhide
     exception"] | 
|   96   ]; |   97   ]; | 
|   97   for (let [text, type, typeName, collapse] of tests) |   98   for (let [text, type, typeName, collapse] of tests) | 
|   98   { |   99   { | 
|   99     let filter = Filter.fromText(text); |  100     withNAD(0, filter => | 
|  100     test.ok(filter instanceof Filter, "Got filter for " + text); |  101     { | 
|  101     test.equal(filter.text, text, "Correct filter text for " + text); |  102       test.ok(filter instanceof Filter, "Got filter for " + text); | 
|  102     test.ok(filter instanceof type, "Correct filter type for " + text); |  103       test.equal(filter.text, text, "Correct filter text for " + text); | 
|  103     test.equal(filter.type, typeName, "Type name for " + text + " is " + typeNam
     e); |  104       test.ok(filter instanceof type, "Correct filter type for " + text); | 
|  104     if (filter instanceof BlockingFilter) |  105       test.equal(filter.type, typeName, "Type name for " + text + " is " + typeN
     ame); | 
|  105       test.equal(filter.collapse, collapse); |  106       if (filter instanceof BlockingFilter) | 
|  106     else |  107         test.equal(filter.collapse, collapse); | 
|  107       test.equal(filter.collapse, undefined); |  108       else | 
|  108     if (type == InvalidFilter) |  109         test.equal(filter.collapse, undefined); | 
|  109       test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); |  110       if (type == InvalidFilter) | 
|  110     filter.delete(); |  111         test.ok(filter.reason, "Invalid filter " + text + " has a reason set"); | 
|  111   } |  112     })(Filter.fromText(text)); | 
 |  113   } | 
 |  114  | 
 |  115   // conversion from old syntax. | 
 |  116   withNAD(0, filter => | 
 |  117   { | 
 |  118     test.equal(filter.text, "example.com#?#:-abp-properties(something)"); | 
 |  119     test.ok(filter instanceof ElemHideEmulationFilter); | 
 |  120     test.equal(filter.type, "elemhideemulation"); | 
 |  121   })(Filter.fromText("example.com##[-abp-properties='something']")); | 
 |  122  | 
|  112   test.done(); |  123   test.done(); | 
|  113 }; |  124 }; | 
|  114  |  125  | 
|  115 exports.testClassHierarchy = function(test) |  126 exports.testClassHierarchy = function(test) | 
|  116 { |  127 { | 
|  117   let allClasses = [ |  128   let allClasses = [ | 
|  118     Filter, InvalidFilter, CommentFilter, ActiveFilter, |  129     Filter, InvalidFilter, CommentFilter, ActiveFilter, | 
|  119     RegExpFilter, BlockingFilter, WhitelistFilter, ElemHideBase, |  130     RegExpFilter, BlockingFilter, WhitelistFilter, ElemHideBase, | 
|  120     ElemHideFilter, ElemHideException, ElemHideEmulationFilter |  131     ElemHideFilter, ElemHideException, ElemHideEmulationFilter | 
|  121   ]; |  132   ]; | 
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  380   { |  391   { | 
|  381     doTest(text, selector, selectorDomain); |  392     doTest(text, selector, selectorDomain); | 
|  382     doTest(text.replace("##", "#@#"), selector, selectorDomain); |  393     doTest(text.replace("##", "#@#"), selector, selectorDomain); | 
|  383   } |  394   } | 
|  384  |  395  | 
|  385   test.done(); |  396   test.done(); | 
|  386 }; |  397 }; | 
|  387  |  398  | 
|  388 exports.testElemHideRulesWithBraces = function(test) |  399 exports.testElemHideRulesWithBraces = function(test) | 
|  389 { |  400 { | 
|  390   let filter = Filter.fromText("###foo{color: red}"); |  401   withNAD(0, filter => | 
|  391   test.equal(filter.type, "elemhide"); |  402   { | 
|  392   test.equal(filter.selector, "#foo\\7B color: red\\7D "); |  403     test.equal(filter.type, "elemhide"); | 
|  393   filter.delete(); |  404     test.equal(filter.selector, "#foo\\7B color: red\\7D "); | 
|  394  |  405   })(Filter.fromText("###foo{color: red}")); | 
|  395   filter = Filter.fromText("foo.com#?#[-abp-properties='/margin: [3-4]{2}/']"); |  406  | 
|  396   test.equal(filter.type, "elemhideemulation"); |  407   // Filter conversion to the new syntax dealing with braces too. | 
|  397   test.equal(filter.selector, ":-abp-properties(/margin: [3-4]\\7B 2\\7D /)"); |  408   withNAD(0, filter => | 
|  398   filter.delete(); |  409   { | 
 |  410     test.equal(filter.type, "elemhideemulation"); | 
 |  411     test.equal(filter.selector, ":-abp-properties(/margin: [3-4]\\7B 2\\7D /)"); | 
 |  412   })(Filter.fromText("foo.com##[-abp-properties='/margin: [3-4]{2}/']")); | 
|  399  |  413  | 
|  400   test.done(); |  414   test.done(); | 
|  401 }; |  415 }; | 
|  402  |  416  | 
|  403 exports.testNotifications = function(test) |  417 exports.testNotifications = function(test) | 
|  404 { |  418 { | 
|  405   function checkNotifications(action, expected, message) |  419   function checkNotifications(action, expected, message) | 
|  406   { |  420   { | 
|  407     let result = null; |  421     let result = null; | 
|  408     let listener = (topic, filter) => |  422     let listener = (topic, filter) => | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  450     filter.hitCount++; |  464     filter.hitCount++; | 
|  451   }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); |  465   }, ["filter.hitCount", "foobar"], "Increasing filter hit counts"); | 
|  452   checkNotifications(() => |  466   checkNotifications(() => | 
|  453   { |  467   { | 
|  454     filter.hitCount = 0; |  468     filter.hitCount = 0; | 
|  455   }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); |  469   }, ["filter.hitCount", "foobar"], "Resetting filter hit counts"); | 
|  456  |  470  | 
|  457   filter.delete(); |  471   filter.delete(); | 
|  458   test.done(); |  472   test.done(); | 
|  459 }; |  473 }; | 
| LEFT | RIGHT |