| 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 |
| 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 const {createSandbox} = require("./_common"); | 20 const {createSandbox} = require("./_common"); |
| 21 | 21 |
| 22 let ElemHide = null; | 22 let ElemHide = null; |
| 23 let createStyleSheet = null; | 23 let createStyleSheet = null; |
| 24 let rulesFromStyleSheet = null; | 24 let rulesFromStyleSheet = null; |
| 25 let ElemHideExceptions = null; | 25 let ElemHideExceptions = null; |
| 26 let Filter = null; | 26 let Filter = null; |
| 27 let filtersByDomain = null; | 27 let filterTextByDomain = null; |
| 28 let selectorGroupSize = null; | 28 let selectorGroupSize = null; |
| 29 | 29 |
| 30 exports.setUp = function(callback) | 30 exports.setUp = function(callback) |
| 31 { | 31 { |
| 32 let sandboxedRequire = createSandbox({ | 32 let sandboxedRequire = createSandbox({ |
| 33 extraExports: { | 33 extraExports: { |
| 34 elemHide: ["filtersByDomain", "selectorGroupSize"] | 34 elemHide: ["filterTextByDomain", "selectorGroupSize"] |
| 35 } | 35 } |
| 36 }); | 36 }); |
| 37 ( | 37 ( |
| 38 {ElemHide, createStyleSheet, rulesFromStyleSheet, | 38 {ElemHide, createStyleSheet, rulesFromStyleSheet, filterTextByDomain, |
| 39 filtersByDomain, selectorGroupSize} = sandboxedRequire("../lib/elemHide"), | 39 selectorGroupSize} = sandboxedRequire("../lib/elemHide"), |
| 40 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), | 40 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), |
| 41 {Filter} = sandboxedRequire("../lib/filterClasses") | 41 {Filter} = sandboxedRequire("../lib/filterClasses") |
| 42 ); | 42 ); |
| 43 | 43 |
| 44 callback(); | 44 callback(); |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 function normalizeSelectors(selectors) | 47 function normalizeSelectors(selectors) |
| 48 { | 48 { |
| 49 // generateStyleSheetForDomain is currently allowed to return duplicate | 49 // generateStyleSheetForDomain is currently allowed to return duplicate |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 { | 258 { |
| 259 ElemHide.add(Filter.fromText("##test")); | 259 ElemHide.add(Filter.fromText("##test")); |
| 260 ElemHideExceptions.add(Filter.fromText("foo.com#@#test")); | 260 ElemHideExceptions.add(Filter.fromText("foo.com#@#test")); |
| 261 testResult(test, "foo.com", []); | 261 testResult(test, "foo.com", []); |
| 262 testResult(test, "bar.com", ["test"]); | 262 testResult(test, "bar.com", ["test"]); |
| 263 test.done(); | 263 test.done(); |
| 264 }; | 264 }; |
| 265 | 265 |
| 266 exports.testFiltersByDomain = function(test) | 266 exports.testFiltersByDomain = function(test) |
| 267 { | 267 { |
| 268 test.equal(filtersByDomain.size, 0); | 268 test.equal(filterTextByDomain.size, 0); |
| 269 | 269 |
| 270 ElemHide.add(Filter.fromText("##test")); | 270 ElemHide.add(Filter.fromText("##test")); |
| 271 test.equal(filtersByDomain.size, 0); | 271 test.equal(filterTextByDomain.size, 0); |
| 272 | 272 |
| 273 ElemHide.add(Filter.fromText("example.com##test")); | 273 ElemHide.add(Filter.fromText("example.com##test")); |
| 274 test.equal(filtersByDomain.size, 1); | 274 test.equal(filterTextByDomain.size, 1); |
| 275 | 275 |
| 276 ElemHide.add(Filter.fromText("example.com,~www.example.com##test")); | 276 ElemHide.add(Filter.fromText("example.com,~www.example.com##test")); |
| 277 test.equal(filtersByDomain.size, 2); | 277 test.equal(filterTextByDomain.size, 2); |
| 278 | 278 |
| 279 ElemHide.remove(Filter.fromText("example.com##test")); | 279 ElemHide.remove(Filter.fromText("example.com##test")); |
| 280 test.equal(filtersByDomain.size, 2); | 280 test.equal(filterTextByDomain.size, 2); |
| 281 | 281 |
| 282 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test")); | 282 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test")); |
| 283 test.equal(filtersByDomain.size, 0); | 283 test.equal(filterTextByDomain.size, 0); |
| 284 | 284 |
| 285 test.done(); | 285 test.done(); |
| 286 }; | 286 }; |
| 287 | 287 |
| 288 exports.testCreateStyleSheet = function(test) | 288 exports.testCreateStyleSheet = function(test) |
| 289 { | 289 { |
| 290 test.equal( | 290 test.equal( |
| 291 createStyleSheet([ | 291 createStyleSheet([ |
| 292 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar", | 292 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar", |
| 293 "#foo[data-bar='bar']" | 293 "#foo[data-bar='bar']" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 314 // not the case, the function goes into an infinite loop. It should only be | 314 // not the case, the function goes into an infinite loop. It should only be |
| 315 // used with the return value of the createStyleSheet function. | 315 // used with the return value of the createStyleSheet function. |
| 316 | 316 |
| 317 test.deepEqual([...rulesFromStyleSheet("")], []); | 317 test.deepEqual([...rulesFromStyleSheet("")], []); |
| 318 test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]); | 318 test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]); |
| 319 test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")], | 319 test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")], |
| 320 ["#foo {}", "#bar {}"]); | 320 ["#foo {}", "#bar {}"]); |
| 321 | 321 |
| 322 test.done(); | 322 test.done(); |
| 323 }; | 323 }; |
| OLD | NEW |