| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0); | 91 selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0); |
| 92 test.equal(selectors.selectorCount, 3); | 92 test.equal(selectors.selectorCount, 3); |
| 93 | 93 |
| 94 ElemHide.remove(filter3); | 94 ElemHide.remove(filter3); |
| 95 selectors = ElemHide.getSelectorsForDomain("example.com", 0); | 95 selectors = ElemHide.getSelectorsForDomain("example.com", 0); |
| 96 test.equal(selectors.selectorCount, 2); | 96 test.equal(selectors.selectorCount, 2); |
| 97 | 97 |
| 98 test.done(); | 98 test.done(); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 exports.testSyntaxConversion = function(test) |
| 102 { |
| 103 function checkConvertedFilter(old, converted) |
| 104 { |
| 105 let filter = Filter.fromText(old); |
| 106 |
| 107 test.equal(filter.text, converted); |
| 108 } |
| 109 |
| 110 checkConvertedFilter("example.com#?#foo[-abp-properties='something']bar", "exa
mple.com#?#foo:-abp-properties(something)bar"); |
| 111 checkConvertedFilter("example.com#?#[-abp-properties=\"something\"]", "example
.com#?#:-abp-properties(something)"); |
| 112 checkConvertedFilter("example.com#?#[-abp-properties=(something)]", "example.c
om#?#:-abp-properties((something))"); |
| 113 |
| 114 test.done(); |
| 115 }; |
| 116 |
| 101 exports.testDomainRestrictions = function(test) | 117 exports.testDomainRestrictions = function(test) |
| 102 { | 118 { |
| 103 function testSelectorMatches(description, filters, domain, expectedMatches) | 119 function testSelectorMatches(description, filters, domain, expectedMatches) |
| 104 { | 120 { |
| 105 for (let text of filters) | 121 for (let text of filters) |
| 106 { | 122 { |
| 107 let filter = Filter.fromText(text); | 123 let filter = Filter.fromText(text); |
| 108 if (filter instanceof ElemHideEmulationFilter) | 124 if (filter instanceof ElemHideEmulationFilter) |
| 109 ElemHideEmulation.add(filter); | 125 ElemHideEmulation.add(filter); |
| 110 else | 126 else |
| 111 ElemHide.add(filter); | 127 ElemHide.add(filter); |
| 112 } | 128 } |
| 113 | 129 |
| 114 let rules = ElemHideEmulation.getRulesForDomain(domain); | 130 let rules = ElemHideEmulation.getRulesForDomain(domain); |
| 115 let matches = []; | 131 let matches = []; |
| 116 for (let i = 0; i < rules.filterCount; i++) | 132 for (let i = 0; i < rules.filterCount; i++) |
| 117 matches.push(rules.filterAt(i).text); | 133 matches.push(rules.filterAt(i).text); |
| 118 test.deepEqual(matches.sort(), expectedMatches.sort(), description); | 134 test.deepEqual(matches.sort(), expectedMatches.sort(), description); |
| 119 | 135 |
| 120 ElemHideEmulation.clear(); | 136 ElemHideEmulation.clear(); |
| 121 ElemHide.clear(); | 137 ElemHide.clear(); |
| 122 } | 138 } |
| 123 | 139 |
| 124 testSelectorMatches( | 140 testSelectorMatches( |
| 125 "Ignore generic filters", | 141 "Ignore generic filters", |
| 126 [ | 142 [ |
| 127 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", | 143 "#?#:-abp-properties(foo)", "example.com#?#:-abp-properties(foo)", |
| 128 "~example.com##[-abp-properties='foo']" | 144 "~example.com##:-abp-properties(foo)" |
| 129 ], | 145 ], |
| 130 "example.com", | 146 "example.com", |
| 131 ["example.com##[-abp-properties='foo']"] | 147 ["example.com#?#:-abp-properties(foo)"] |
| 132 ); | 148 ); |
| 133 testSelectorMatches( | 149 testSelectorMatches( |
| 134 "Ignore selectors with exceptions", | 150 "Ignore selectors with exceptions", |
| 135 [ | 151 [ |
| 136 "example.com##[-abp-properties='foo']", | 152 "example.com#?#:-abp-properties(foo)", |
| 137 "example.com##[-abp-properties='bar']", | 153 "example.com#?#:-abp-properties(bar)", |
| 138 "example.com#@#[-abp-properties='foo']" | 154 "example.com#@#:-abp-properties(foo)" |
| 139 ], | 155 ], |
| 140 "example.com", | 156 "example.com", |
| 141 ["example.com##[-abp-properties='bar']"] | 157 ["example.com#?#:-abp-properties(bar)"] |
| 142 ); | 158 ); |
| 143 testSelectorMatches( | 159 testSelectorMatches( |
| 144 "Ignore filters that include parent domain but exclude subdomain", | 160 "Ignore filters that include parent domain but exclude subdomain", |
| 145 [ | 161 [ |
| 146 "~www.example.com,example.com##[-abp-properties='foo']" | 162 "~www.example.com,example.com#?#:-abp-properties(foo)" |
| 147 ], | 163 ], |
| 148 "www.example.com", | 164 "www.example.com", |
| 149 [] | 165 [] |
| 150 ); | 166 ); |
| 151 testSelectorMatches( | 167 testSelectorMatches( |
| 152 "Ignore filters with parent domain if exception matches subdomain", | 168 "Ignore filters with parent domain if exception matches subdomain", |
| 153 [ | 169 [ |
| 154 "www.example.com#@#[-abp-properties='foo']", | 170 "www.example.com#@#:-abp-properties(foo)", |
| 155 "example.com##[-abp-properties='foo']" | 171 "example.com#?#:-abp-properties(foo)" |
| 156 ], | 172 ], |
| 157 "www.example.com", | 173 "www.example.com", |
| 158 [] | 174 [] |
| 159 ); | 175 ); |
| 160 testSelectorMatches( | 176 testSelectorMatches( |
| 161 "Ignore filters for other subdomain", | 177 "Ignore filters for other subdomain", |
| 162 [ | 178 [ |
| 163 "www.example.com##[-abp-properties='foo']", | 179 "www.example.com#?#:-abp-properties(foo)", |
| 164 "other.example.com##[-abp-properties='foo']" | 180 "other.example.com#?#:-abp-properties(foo)" |
| 165 ], | 181 ], |
| 166 "other.example.com", | 182 "other.example.com", |
| 167 ["other.example.com##[-abp-properties='foo']"] | 183 ["other.example.com#?#:-abp-properties(foo)"] |
| 168 ); | 184 ); |
| 169 | 185 |
| 170 test.done(); | 186 test.done(); |
| 171 }; | 187 }; |
| 172 | 188 |
| 173 exports.testElemHideEmulationFiltersContainer = function(test) | 189 exports.testElemHideEmulationFiltersContainer = function(test) |
| 174 { | 190 { |
| 175 function compareRules(description, domain, expectedMatches) | 191 function compareRules(description, domain, expectedMatches) |
| 176 { | 192 { |
| 177 let rules = ElemHideEmulation.getRulesForDomain(domain); | 193 let rules = ElemHideEmulation.getRulesForDomain(domain); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 204 | 220 |
| 205 ElemHideEmulation.clear(); | 221 ElemHideEmulation.clear(); |
| 206 compareRules( | 222 compareRules( |
| 207 "Return no filters after clearing", | 223 "Return no filters after clearing", |
| 208 "www.example.com", | 224 "www.example.com", |
| 209 [] | 225 [] |
| 210 ); | 226 ); |
| 211 | 227 |
| 212 test.done(); | 228 test.done(); |
| 213 }; | 229 }; |
| OLD | NEW |