Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: test/elemHide.js

Issue 29897558: Issue 6957 - Add rulesFromStyleSheet function to ElemHide module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Oct. 1, 2018, 2:56 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 ElemHideExceptions = null; 25 let ElemHideExceptions = null;
25 let Filter = null; 26 let Filter = null;
26 let filtersByDomain = null; 27 let filtersByDomain = null;
27 let selectorGroupSize = null; 28 let selectorGroupSize = null;
28 29
29 exports.setUp = function(callback) 30 exports.setUp = function(callback)
30 { 31 {
31 let sandboxedRequire = createSandbox({ 32 let sandboxedRequire = createSandbox({
32 extraExports: { 33 extraExports: {
33 elemHide: ["filtersByDomain", "selectorGroupSize"] 34 elemHide: ["filtersByDomain", "selectorGroupSize"]
34 } 35 }
35 }); 36 });
36 ( 37 (
37 {ElemHide, createStyleSheet, filtersByDomain, selectorGroupSize} = 38 {ElemHide, createStyleSheet, rulesFromStyleSheet,
38 sandboxedRequire("../lib/elemHide"), 39 filtersByDomain, selectorGroupSize} = sandboxedRequire("../lib/elemHide"),
39 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), 40 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"),
40 {Filter} = sandboxedRequire("../lib/filterClasses") 41 {Filter} = sandboxedRequire("../lib/filterClasses")
41 ); 42 );
42 43
43 callback(); 44 callback();
44 }; 45 };
45 46
46 function normalizeSelectors(selectors) 47 function normalizeSelectors(selectors)
47 { 48 {
48 // generateStyleSheetForDomain is currently allowed to return duplicate 49 // generateStyleSheetForDomain is currently allowed to return duplicate
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 299
299 let selectors = new Array(50000).map((element, index) => ".s" + index); 300 let selectors = new Array(50000).map((element, index) => ".s" + index);
300 301
301 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length, 302 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length,
302 Math.ceil(50000 / selectorGroupSize), 303 Math.ceil(50000 / selectorGroupSize),
303 "Style sheet should be split up into rules with at most " + 304 "Style sheet should be split up into rules with at most " +
304 selectorGroupSize + " selectors each"); 305 selectorGroupSize + " selectors each");
305 306
306 test.done(); 307 test.done();
307 }; 308 };
309
310 exports.testRulesFromStyleSheet = function(test)
311 {
312 // Note: The rulesFromStyleSheet function assumes that each rule will be
313 // terminated with a newline character, including the last rule. If this is
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.
316
317 test.deepEqual([...rulesFromStyleSheet("")], []);
318 test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]);
319 test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")],
320 ["#foo {}", "#bar {}"]);
321
322 test.done();
323 };
OLDNEW
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld