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 ElemHideExceptions = null; | 24 let ElemHideExceptions = null; |
24 let Filter = null; | 25 let Filter = null; |
25 let filtersByDomain = null; | 26 let filtersByDomain = null; |
| 27 let selectorGroupSize = null; |
26 | 28 |
27 exports.setUp = function(callback) | 29 exports.setUp = function(callback) |
28 { | 30 { |
29 let sandboxedRequire = createSandbox({ | 31 let sandboxedRequire = createSandbox({ |
30 extraExports: { | 32 extraExports: { |
31 elemHide: ["filtersByDomain"] | 33 elemHide: ["filtersByDomain", "selectorGroupSize"] |
32 } | 34 } |
33 }); | 35 }); |
34 ( | 36 ( |
35 {ElemHide, filtersByDomain} = sandboxedRequire("../lib/elemHide"), | 37 {ElemHide, createStyleSheet, filtersByDomain, selectorGroupSize} = |
| 38 sandboxedRequire("../lib/elemHide"), |
36 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), | 39 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), |
37 {Filter} = sandboxedRequire("../lib/filterClasses") | 40 {Filter} = sandboxedRequire("../lib/filterClasses") |
38 ); | 41 ); |
39 | 42 |
40 callback(); | 43 callback(); |
41 }; | 44 }; |
42 | 45 |
43 function normalizeSelectors(selectors) | 46 function normalizeSelectors(selectors) |
44 { | 47 { |
45 // getSelectorsForDomain is currently allowed to return duplicate selectors | 48 // getSelectorsForDomain is currently allowed to return duplicate selectors |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 test.equal(filtersByDomain.size, 2); | 269 test.equal(filtersByDomain.size, 2); |
267 | 270 |
268 ElemHide.remove(Filter.fromText("example.com##test")); | 271 ElemHide.remove(Filter.fromText("example.com##test")); |
269 test.equal(filtersByDomain.size, 2); | 272 test.equal(filtersByDomain.size, 2); |
270 | 273 |
271 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test")); | 274 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test")); |
272 test.equal(filtersByDomain.size, 0); | 275 test.equal(filtersByDomain.size, 0); |
273 | 276 |
274 test.done(); | 277 test.done(); |
275 }; | 278 }; |
| 279 |
| 280 exports.testCreateStyleSheet = function(test) |
| 281 { |
| 282 test.equal( |
| 283 createStyleSheet([ |
| 284 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar", |
| 285 "#foo[data-bar='bar']" |
| 286 ]), |
| 287 "html, #foo, .bar, #foo .bar, #foo > .bar, #foo[data-bar='bar'] " + |
| 288 "{display: none !important;}", |
| 289 "Style sheet creation should work" |
| 290 ); |
| 291 |
| 292 let selectors = new Array(50000).map((element, index) => ".s" + index); |
| 293 |
| 294 test.equal(createStyleSheet(selectors).split("\n").length, |
| 295 Math.ceil(50000 / selectorGroupSize), |
| 296 "Style sheet should be split up into rules with at most " + |
| 297 selectorGroupSize + " selectors each"); |
| 298 |
| 299 test.done(); |
| 300 }; |
OLD | NEW |