| Left: | ||
| Right: |
| 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 | 131 |
| 132 withNAD( | 132 withNAD( |
| 133 0, selectors => | 133 0, selectors => |
| 134 test.equal(selectors.selectorCount, 2))( | 134 test.equal(selectors.selectorCount, 2))( |
| 135 elemHide.getSelectorsForDomain("example.com", 0)); | 135 elemHide.getSelectorsForDomain("example.com", 0)); |
| 136 })(ElemHide.create()); | 136 })(ElemHide.create()); |
| 137 | 137 |
| 138 test.done(); | 138 test.done(); |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 exports.testSyntaxConversion = function(test) | |
| 142 { | |
| 143 function checkConvertedFilter(old, converted) | |
| 144 { | |
| 145 let filter = Filter.fromText(old); | |
|
sergei
2018/01/30 19:02:40
`filter` should be released.
hub
2018/01/30 22:53:13
Done.
| |
| 146 | |
| 147 test.equal(filter.text, converted); | |
| 148 } | |
| 149 | |
| 150 checkConvertedFilter("example.com#?#foo[-abp-properties='something']bar", "exa mple.com#?#foo:-abp-properties(something)bar"); | |
| 151 checkConvertedFilter("example.com#@#foo[-abp-properties='something']bar", "exa mple.com#@#foo:-abp-properties(something)bar"); | |
| 152 checkConvertedFilter("example.com#?#[-abp-properties=\"something\"]", "example .com#?#:-abp-properties(something)"); | |
| 153 checkConvertedFilter("example.com#?#[-abp-properties=(something)]", "example.c om#?#:-abp-properties((something))"); | |
| 154 | |
| 155 test.done(); | |
| 156 }; | |
| 157 | |
| 141 exports.testDomainRestrictions = function(test) | 158 exports.testDomainRestrictions = function(test) |
| 142 { | 159 { |
| 143 function testSelectorMatches(description, filters, domain, expectedMatches) | 160 function testSelectorMatches(description, filters, domain, expectedMatches) |
| 144 { | 161 { |
| 145 withNAD([0, 1], (elemHide, elemHideEmulation) => | 162 withNAD([0, 1], (elemHide, elemHideEmulation) => |
| 146 { | 163 { |
| 147 let addFilter = withNAD(0, filter => | 164 let addFilter = withNAD(0, filter => |
| 148 { | 165 { |
| 149 if (filter instanceof ElemHideEmulationFilter) | 166 if (filter instanceof ElemHideEmulationFilter) |
| 150 elemHideEmulation.add(filter); | 167 elemHideEmulation.add(filter); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 166 test.deepEqual(matches.sort(), expectedMatches.sort(), description); | 183 test.deepEqual(matches.sort(), expectedMatches.sort(), description); |
| 167 })(elemHideEmulation.getRulesForDomain(elemHide, domain)); | 184 })(elemHideEmulation.getRulesForDomain(elemHide, domain)); |
| 168 | 185 |
| 169 elemHideEmulation.clear(); | 186 elemHideEmulation.clear(); |
| 170 })(ElemHide.create(), ElemHideEmulation.create()); | 187 })(ElemHide.create(), ElemHideEmulation.create()); |
| 171 } | 188 } |
| 172 | 189 |
| 173 testSelectorMatches( | 190 testSelectorMatches( |
| 174 "Ignore generic filters", | 191 "Ignore generic filters", |
| 175 [ | 192 [ |
| 176 "##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", | 193 "#?#:-abp-properties(foo)", "example.com#?#:-abp-properties(foo)", |
| 177 "~example.com##[-abp-properties='foo']" | 194 "~example.com##:-abp-properties(foo)" |
| 178 ], | 195 ], |
| 179 "example.com", | 196 "example.com", |
| 180 ["example.com##[-abp-properties='foo']"] | 197 ["example.com#?#:-abp-properties(foo)"] |
| 181 ); | 198 ); |
| 182 testSelectorMatches( | 199 testSelectorMatches( |
| 183 "Ignore selectors with exceptions", | 200 "Ignore selectors with exceptions", |
| 184 [ | 201 [ |
| 185 "example.com##[-abp-properties='foo']", | 202 "example.com#?#:-abp-properties(foo)", |
| 186 "example.com##[-abp-properties='bar']", | 203 "example.com#?#:-abp-properties(bar)", |
| 187 "example.com#@#[-abp-properties='foo']" | 204 "example.com#@#:-abp-properties(foo)" |
| 188 ], | 205 ], |
| 189 "example.com", | 206 "example.com", |
| 190 ["example.com##[-abp-properties='bar']"] | 207 ["example.com#?#:-abp-properties(bar)"] |
| 191 ); | 208 ); |
| 192 testSelectorMatches( | 209 testSelectorMatches( |
| 193 "Ignore filters that include parent domain but exclude subdomain", | 210 "Ignore filters that include parent domain but exclude subdomain", |
| 194 [ | 211 [ |
| 195 "~www.example.com,example.com##[-abp-properties='foo']" | 212 "~www.example.com,example.com#?#:-abp-properties(foo)" |
| 196 ], | 213 ], |
| 197 "www.example.com", | 214 "www.example.com", |
| 198 [] | 215 [] |
| 199 ); | 216 ); |
| 200 testSelectorMatches( | 217 testSelectorMatches( |
| 201 "Ignore filters with parent domain if exception matches subdomain", | 218 "Ignore filters with parent domain if exception matches subdomain", |
| 202 [ | 219 [ |
| 203 "www.example.com#@#[-abp-properties='foo']", | 220 "www.example.com#@#:-abp-properties(foo)", |
| 204 "example.com##[-abp-properties='foo']" | 221 "example.com#?#:-abp-properties(foo)" |
| 205 ], | 222 ], |
| 206 "www.example.com", | 223 "www.example.com", |
| 207 [] | 224 [] |
| 208 ); | 225 ); |
| 209 testSelectorMatches( | 226 testSelectorMatches( |
| 210 "Ignore filters for other subdomain", | 227 "Ignore filters for other subdomain", |
| 211 [ | 228 [ |
| 212 "www.example.com##[-abp-properties='foo']", | 229 "www.example.com#?#:-abp-properties(foo)", |
| 213 "other.example.com##[-abp-properties='foo']" | 230 "other.example.com#?#:-abp-properties(foo)" |
| 214 ], | 231 ], |
| 215 "other.example.com", | 232 "other.example.com", |
| 216 ["other.example.com##[-abp-properties='foo']"] | 233 ["other.example.com#?#:-abp-properties(foo)"] |
| 217 ); | 234 ); |
| 218 | 235 |
| 219 test.done(); | 236 test.done(); |
| 220 }; | 237 }; |
| 221 | 238 |
| 222 exports.testElemHideEmulationFiltersContainer = function(test) | 239 exports.testElemHideEmulationFiltersContainer = function(test) |
| 223 { | 240 { |
| 224 withNAD([0, 1], (elemHide, elemHideEmulation) => | 241 withNAD([0, 1], (elemHide, elemHideEmulation) => |
| 225 { | 242 { |
| 226 function compareRules(description, domain, expectedMatches) | 243 function compareRules(description, domain, expectedMatches) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 "www.example.com", | 277 "www.example.com", |
| 261 [] | 278 [] |
| 262 ); | 279 ); |
| 263 })(Filter.fromText("example.com##filter1"), | 280 })(Filter.fromText("example.com##filter1"), |
| 264 Filter.fromText("www.example.com##filter2"), | 281 Filter.fromText("www.example.com##filter2"), |
| 265 Filter.fromText("other.example.com##filter3")); | 282 Filter.fromText("other.example.com##filter3")); |
| 266 })(ElemHide.create(), ElemHideEmulation.create()); | 283 })(ElemHide.create(), ElemHideEmulation.create()); |
| 267 | 284 |
| 268 test.done(); | 285 test.done(); |
| 269 }; | 286 }; |
| OLD | NEW |