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

Side by Side Diff: test/elemHide.js

Issue 30002601: Issue 7284 - Move CSS escaping to createStyleSheet (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Added test Created Feb. 15, 2019, 2:36 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 | « test/browser/elemHideEmulation.js ('k') | test/filterClasses.js » ('j') | 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
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 test.equal( 290 test.equal(
291 createStyleSheet([ 291 createStyleSheet([
292 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar", 292 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar",
293 "#foo[data-bar='bar']" 293 "#foo[data-bar='bar']"
294 ]), 294 ]),
295 "html, #foo, .bar, #foo .bar, #foo > .bar, #foo[data-bar='bar'] " + 295 "html, #foo, .bar, #foo .bar, #foo > .bar, #foo[data-bar='bar'] " +
296 "{display: none !important;}\n", 296 "{display: none !important;}\n",
297 "Style sheet creation should work" 297 "Style sheet creation should work"
298 ); 298 );
299 299
300 let selectors = new Array(50000).map((element, index) => ".s" + index); 300 let selectors = new Array(50000).fill().map((element, index) => ".s" + index);
301 301
302 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length, 302 test.equal((createStyleSheet(selectors).match(/\n/g) || []).length,
303 Math.ceil(50000 / selectorGroupSize), 303 Math.ceil(50000 / selectorGroupSize),
304 "Style sheet should be split up into rules with at most " + 304 "Style sheet should be split up into rules with at most " +
305 selectorGroupSize + " selectors each"); 305 selectorGroupSize + " selectors each");
306 306
307 test.equal(
308 createStyleSheet([
309 "html", "#foo", ".bar", "#foo .bar", "#foo > .bar",
310 "#foo[data-bar='{foo: 1}']"
311 ]),
312 "html, #foo, .bar, #foo .bar, #foo > .bar, #foo[data-bar='\\7B foo: 1\\7D '] " +
Manish Jethani 2019/02/16 04:34:04 Nit: This is the only line in the file that exceed
hub 2019/02/18 12:56:20 Done.
Manish Jethani 2019/02/18 13:07:21 Nit: When wrapping an expression `a + b` the break
hub 2019/02/18 13:51:08 Done.
313 "{display: none !important;}\n",
314 "Style sheet creation should work"
Manish Jethani 2019/02/16 04:34:04 "Braces should be escaped"
hub 2019/02/18 12:56:20 Done.
315 );
307 test.done(); 316 test.done();
Manish Jethani 2019/02/16 04:34:04 Nit: Can we leave a blank line above test.done?
hub 2019/02/18 12:56:21 Done.
308 }; 317 };
309 318
310 exports.testRulesFromStyleSheet = function(test) 319 exports.testRulesFromStyleSheet = function(test)
311 { 320 {
312 // Note: The rulesFromStyleSheet function assumes that each rule will be 321 // Note: The rulesFromStyleSheet function assumes that each rule will be
313 // terminated with a newline character, including the last rule. If this is 322 // 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 323 // not the case, the function goes into an infinite loop. It should only be
315 // used with the return value of the createStyleSheet function. 324 // used with the return value of the createStyleSheet function.
316 325
317 test.deepEqual([...rulesFromStyleSheet("")], []); 326 test.deepEqual([...rulesFromStyleSheet("")], []);
318 test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]); 327 test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]);
319 test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")], 328 test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")],
320 ["#foo {}", "#bar {}"]); 329 ["#foo {}", "#bar {}"]);
321 330
322 test.done(); 331 test.done();
323 }; 332 };
OLDNEW
« no previous file with comments | « test/browser/elemHideEmulation.js ('k') | test/filterClasses.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld