| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 ElemHide.remove(filter3); | 111 ElemHide.remove(filter3); |
| 112 filter3.delete(); | 112 filter3.delete(); |
| 113 selectors = ElemHide.getSelectorsForDomain("example.com", 0); | 113 selectors = ElemHide.getSelectorsForDomain("example.com", 0); |
| 114 test.equal(selectors.selectorCount, 2); | 114 test.equal(selectors.selectorCount, 2); |
| 115 selectors.delete(); | 115 selectors.delete(); |
| 116 | 116 |
| 117 test.done(); | 117 test.done(); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 exports.testSyntaxConversion = function(test) |
| 121 { |
| 122 function checkConvertedFilter(old, converted) |
| 123 { |
| 124 let filter = Filter.fromText(old); |
| 125 |
| 126 test.equal(filter.text, converted); |
| 127 } |
| 128 |
| 129 checkConvertedFilter("example.com#?#foo[-abp-properties='something']bar", "exa
mple.com#?#foo:-abp-properties(something)bar"); |
| 130 checkConvertedFilter("example.com#@#foo[-abp-properties='something']bar", "exa
mple.com#@#foo:-abp-properties(something)bar"); |
| 131 checkConvertedFilter("example.com#?#[-abp-properties=\"something\"]", "example
.com#?#:-abp-properties(something)"); |
| 132 checkConvertedFilter("example.com#?#[-abp-properties=(something)]", "example.c
om#?#:-abp-properties((something))"); |
| 133 |
| 134 test.done(); |
| 135 }; |
| 136 |
| 120 exports.testDomainRestrictions = function(test) | 137 exports.testDomainRestrictions = function(test) |
| 121 { | 138 { |
| 122 function testSelectorMatches(description, filters, domain, expectedMatches) | 139 function testSelectorMatches(description, filters, domain, expectedMatches) |
| 123 { | 140 { |
| 124 for (let text of filters) | 141 for (let text of filters) |
| 125 { | 142 { |
| 126 let filter = Filter.fromText(text); | 143 let filter = Filter.fromText(text); |
| 127 if (filter instanceof ElemHideEmulationFilter) | 144 if (filter instanceof ElemHideEmulationFilter) |
| 128 ElemHideEmulation.add(filter); | 145 ElemHideEmulation.add(filter); |
| 129 else | 146 else |
| (...skipping 12 matching lines...) Expand all Loading... |
| 142 test.deepEqual(matches.sort(), expectedMatches.sort(), description); | 159 test.deepEqual(matches.sort(), expectedMatches.sort(), description); |
| 143 rules.delete(); | 160 rules.delete(); |
| 144 | 161 |
| 145 ElemHideEmulation.clear(); | 162 ElemHideEmulation.clear(); |
| 146 ElemHide.clear(); | 163 ElemHide.clear(); |
| 147 } | 164 } |
| 148 | 165 |
| 149 testSelectorMatches( | 166 testSelectorMatches( |
| 150 "Ignore generic filters", | 167 "Ignore generic filters", |
| 151 [ | 168 [ |
| 152 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", | 169 "#?#:-abp-properties(foo)", "example.com#?#:-abp-properties(foo)", |
| 153 "~example.com##[-abp-properties='foo']" | 170 "~example.com##:-abp-properties(foo)" |
| 154 ], | 171 ], |
| 155 "example.com", | 172 "example.com", |
| 156 ["example.com##[-abp-properties='foo']"] | 173 ["example.com#?#:-abp-properties(foo)"] |
| 157 ); | 174 ); |
| 158 testSelectorMatches( | 175 testSelectorMatches( |
| 159 "Ignore selectors with exceptions", | 176 "Ignore selectors with exceptions", |
| 160 [ | 177 [ |
| 161 "example.com##[-abp-properties='foo']", | 178 "example.com#?#:-abp-properties(foo)", |
| 162 "example.com##[-abp-properties='bar']", | 179 "example.com#?#:-abp-properties(bar)", |
| 163 "example.com#@#[-abp-properties='foo']" | 180 "example.com#@#:-abp-properties(foo)" |
| 164 ], | 181 ], |
| 165 "example.com", | 182 "example.com", |
| 166 ["example.com##[-abp-properties='bar']"] | 183 ["example.com#?#:-abp-properties(bar)"] |
| 167 ); | 184 ); |
| 168 testSelectorMatches( | 185 testSelectorMatches( |
| 169 "Ignore filters that include parent domain but exclude subdomain", | 186 "Ignore filters that include parent domain but exclude subdomain", |
| 170 [ | 187 [ |
| 171 "~www.example.com,example.com##[-abp-properties='foo']" | 188 "~www.example.com,example.com#?#:-abp-properties(foo)" |
| 172 ], | 189 ], |
| 173 "www.example.com", | 190 "www.example.com", |
| 174 [] | 191 [] |
| 175 ); | 192 ); |
| 176 testSelectorMatches( | 193 testSelectorMatches( |
| 177 "Ignore filters with parent domain if exception matches subdomain", | 194 "Ignore filters with parent domain if exception matches subdomain", |
| 178 [ | 195 [ |
| 179 "www.example.com#@#[-abp-properties='foo']", | 196 "www.example.com#@#:-abp-properties(foo)", |
| 180 "example.com##[-abp-properties='foo']" | 197 "example.com#?#:-abp-properties(foo)" |
| 181 ], | 198 ], |
| 182 "www.example.com", | 199 "www.example.com", |
| 183 [] | 200 [] |
| 184 ); | 201 ); |
| 185 testSelectorMatches( | 202 testSelectorMatches( |
| 186 "Ignore filters for other subdomain", | 203 "Ignore filters for other subdomain", |
| 187 [ | 204 [ |
| 188 "www.example.com##[-abp-properties='foo']", | 205 "www.example.com#?#:-abp-properties(foo)", |
| 189 "other.example.com##[-abp-properties='foo']" | 206 "other.example.com#?#:-abp-properties(foo)" |
| 190 ], | 207 ], |
| 191 "other.example.com", | 208 "other.example.com", |
| 192 ["other.example.com##[-abp-properties='foo']"] | 209 ["other.example.com#?#:-abp-properties(foo)"] |
| 193 ); | 210 ); |
| 194 | 211 |
| 195 test.done(); | 212 test.done(); |
| 196 }; | 213 }; |
| 197 | 214 |
| 198 exports.testElemHideEmulationFiltersContainer = function(test) | 215 exports.testElemHideEmulationFiltersContainer = function(test) |
| 199 { | 216 { |
| 200 function compareRules(description, domain, expectedMatches) | 217 function compareRules(description, domain, expectedMatches) |
| 201 { | 218 { |
| 202 let rules = ElemHideEmulation.getRulesForDomain(domain); | 219 let rules = ElemHideEmulation.getRulesForDomain(domain); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 252 |
| 236 ElemHideEmulation.clear(); | 253 ElemHideEmulation.clear(); |
| 237 compareRules( | 254 compareRules( |
| 238 "Return no filters after clearing", | 255 "Return no filters after clearing", |
| 239 "www.example.com", | 256 "www.example.com", |
| 240 [] | 257 [] |
| 241 ); | 258 ); |
| 242 | 259 |
| 243 test.done(); | 260 test.done(); |
| 244 }; | 261 }; |
| OLD | NEW |