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

Unified Diff: test/elemHide.js

Issue 29882562: Issue 6956 - Move extension's style sheet generation into core (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Avoid temporary array and join Created Sept. 18, 2018, 3:11 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/elemHide.js
===================================================================
--- a/test/elemHide.js
+++ b/test/elemHide.js
@@ -15,29 +15,32 @@
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
const {createSandbox} = require("./_common");
let ElemHide = null;
+let createStyleSheet = null;
let ElemHideExceptions = null;
let Filter = null;
let filtersByDomain = null;
+let selectorGroupSize = null;
exports.setUp = function(callback)
{
let sandboxedRequire = createSandbox({
extraExports: {
- elemHide: ["filtersByDomain"]
+ elemHide: ["filtersByDomain", "selectorGroupSize"]
}
});
(
- {ElemHide, filtersByDomain} = sandboxedRequire("../lib/elemHide"),
+ {ElemHide, createStyleSheet, filtersByDomain, selectorGroupSize} =
+ sandboxedRequire("../lib/elemHide"),
{ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"),
{Filter} = sandboxedRequire("../lib/filterClasses")
);
callback();
};
function normalizeSelectors(selectors)
@@ -268,8 +271,30 @@
ElemHide.remove(Filter.fromText("example.com##test"));
test.equal(filtersByDomain.size, 2);
ElemHide.remove(Filter.fromText("example.com,~www.example.com##test"));
test.equal(filtersByDomain.size, 0);
test.done();
};
+
+exports.testCreateStyleSheet = function(test)
+{
+ test.equal(
+ createStyleSheet([
+ "html", "#foo", ".bar", "#foo .bar", "#foo > .bar",
+ "#foo[data-bar='bar']"
+ ]),
+ "html, #foo, .bar, #foo .bar, #foo > .bar, #foo[data-bar='bar'] " +
+ "{display: none !important;}\n",
+ "Style sheet creation should work"
+ );
+
+ let selectors = new Array(50000).map((element, index) => ".s" + index);
+
+ test.equal((createStyleSheet(selectors).match(/\n/g) || []).length,
+ Math.ceil(50000 / selectorGroupSize),
+ "Style sheet should be split up into rules with at most " +
+ selectorGroupSize + " selectors each");
+
+ test.done();
+};
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld