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