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, |
39 filtersByDomain, selectorGroupSize} = sandboxedRequire("../lib/elemHide"), | 39 filterTextByDomain, 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 { | 273 { |
274 ElemHide.add(Filter.fromText("##test")); | 274 ElemHide.add(Filter.fromText("##test")); |
275 ElemHideExceptions.add(Filter.fromText("foo.com#@#test")); | 275 ElemHideExceptions.add(Filter.fromText("foo.com#@#test")); |
276 testResult(test, "foo.com", [], {expectedExceptions: ["foo.com#@#test"]}); | 276 testResult(test, "foo.com", [], {expectedExceptions: ["foo.com#@#test"]}); |
277 testResult(test, "bar.com", ["test"]); | 277 testResult(test, "bar.com", ["test"]); |
278 test.done(); | 278 test.done(); |
279 }; | 279 }; |
280 | 280 |
281 exports.testFiltersByDomain = function(test) | 281 exports.testFiltersByDomain = function(test) |
282 { | 282 { |
283 test.equal(filtersByDomain.size, 0); | 283 test.equal(filterTextByDomain.size, 0); |
284 | 284 |
285 ElemHide.add(Filter.fromText("##test")); | 285 ElemHide.add(Filter.fromText("##test")); |
286 test.equal(filtersByDomain.size, 0); | 286 test.equal(filterTextByDomain.size, 0); |
287 | 287 |
288 ElemHide.add(Filter.fromText("example.com##test")); | 288 ElemHide.add(Filter.fromText("example.com##test")); |
289 test.equal(filtersByDomain.size, 1); | 289 test.equal(filterTextByDomain.size, 1); |
290 | 290 |
291 ElemHide.add(Filter.fromText("example.com,~www.example.com##test")); | 291 ElemHide.add(Filter.fromText("example.com,~www.example.com##test")); |
292 test.equal(filtersByDomain.size, 2); | 292 test.equal(filterTextByDomain.size, 2); |
293 | 293 |
294 ElemHide.remove(Filter.fromText("example.com##test")); | 294 ElemHide.remove(Filter.fromText("example.com##test")); |
295 test.equal(filtersByDomain.size, 2); | 295 test.equal(filterTextByDomain.size, 2); |
296 | 296 |
297 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test")); | 297 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test")); |
298 test.equal(filtersByDomain.size, 0); | 298 test.equal(filterTextByDomain.size, 0); |
299 | 299 |
300 test.done(); | 300 test.done(); |
301 }; | 301 }; |
302 | 302 |
303 exports.testCreateStyleSheet = function(test) | 303 exports.testCreateStyleSheet = function(test) |
304 { | 304 { |
305 test.equal( | 305 test.equal( |
306 createStyleSheet([ | 306 createStyleSheet([ |
307 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar", | 307 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar", |
308 "#foo[data-bar='bar']" | 308 "#foo[data-bar='bar']" |
(...skipping 30 matching lines...) Expand all Loading... |
339 // not the case, the function goes into an infinite loop. It should only be | 339 // not the case, the function goes into an infinite loop. It should only be |
340 // used with the return value of the createStyleSheet function. | 340 // used with the return value of the createStyleSheet function. |
341 | 341 |
342 test.deepEqual([...rulesFromStyleSheet("")], []); | 342 test.deepEqual([...rulesFromStyleSheet("")], []); |
343 test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]); | 343 test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]); |
344 test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")], | 344 test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")], |
345 ["#foo {}", "#bar {}"]); | 345 ["#foo {}", "#bar {}"]); |
346 | 346 |
347 test.done(); | 347 test.done(); |
348 }; | 348 }; |
OLD | NEW |