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

Delta Between Two Patch Sets: test/elemHide.js

Issue 29882562: Issue 6956 - Move extension's style sheet generation into core (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created Sept. 16, 2018, 5:19 p.m.
Right Patch Set: Avoid temporary array and join Created Sept. 18, 2018, 3:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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;
26 let selectorGroupSize = null; 27 let selectorGroupSize = null;
27 28
28 exports.setUp = function(callback) 29 exports.setUp = function(callback)
29 { 30 {
30 let sandboxedRequire = createSandbox({ 31 let sandboxedRequire = createSandbox({
31 extraExports: { 32 extraExports: {
32 elemHide: ["filtersByDomain", "selectorGroupSize"] 33 elemHide: ["filtersByDomain", "selectorGroupSize"]
33 } 34 }
34 }); 35 });
35 ( 36 (
36 {ElemHide, filtersByDomain, selectorGroupSize} = 37 {ElemHide, createStyleSheet, filtersByDomain, selectorGroupSize} =
37 sandboxedRequire("../lib/elemHide"), 38 sandboxedRequire("../lib/elemHide"),
38 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), 39 {ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"),
39 {Filter} = sandboxedRequire("../lib/filterClasses") 40 {Filter} = sandboxedRequire("../lib/filterClasses")
40 ); 41 );
41 42
42 callback(); 43 callback();
43 }; 44 };
44 45
45 function normalizeSelectors(selectors) 46 function normalizeSelectors(selectors)
46 { 47 {
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 273
273 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test")); 274 ElemHide.remove(Filter.fromText("example.com,~www.example.com##test"));
274 test.equal(filtersByDomain.size, 0); 275 test.equal(filtersByDomain.size, 0);
275 276
276 test.done(); 277 test.done();
277 }; 278 };
278 279
279 exports.testCreateStyleSheet = function(test) 280 exports.testCreateStyleSheet = function(test)
280 { 281 {
281 test.equal( 282 test.equal(
282 ElemHide.createStyleSheet([ 283 createStyleSheet([
283 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar", 284 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar",
284 "#foo[data-bar='bar']" 285 "#foo[data-bar='bar']"
285 ]), 286 ]),
286 "html, #foo, .bar, #foo .bar, #foo > .bar, #foo[data-bar='bar'] " + 287 "html, #foo, .bar, #foo .bar, #foo > .bar, #foo[data-bar='bar'] " +
287 "{display: none !important;}", 288 "{display: none !important;}\n",
288 "Style sheet creation should work" 289 "Style sheet creation should work"
289 ); 290 );
290 291
291 let selectors = new Array(50000).map((element, index) => ".s" + index); 292 let selectors = new Array(50000).map((element, index) => ".s" + index);
292 293
293 test.equal(ElemHide.createStyleSheet(selectors).split("\n").length, 294 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length,
294 Math.ceil(50000 / selectorGroupSize), 295 Math.ceil(50000 / selectorGroupSize),
295 "Style sheet should be split up into rules with at most " + 296 "Style sheet should be split up into rules with at most " +
296 selectorGroupSize + " selectors each"); 297 selectorGroupSize + " selectors each");
297 298
298 test.done(); 299 test.done();
299 }; 300 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld