Index: test/elemHide.js |
=================================================================== |
--- a/test/elemHide.js |
+++ b/test/elemHide.js |
@@ -18,26 +18,28 @@ |
"use strict"; |
const {createSandbox} = require("./_common"); |
let ElemHide = 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, filtersByDomain, selectorGroupSize} = |
+ sandboxedRequire("../lib/elemHide"), |
{ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"), |
{Filter} = sandboxedRequire("../lib/filterClasses") |
); |
callback(); |
}; |
function normalizeSelectors(selectors) |
@@ -268,8 +270,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( |
+ ElemHide.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;}", |
+ "Style sheet creation should work" |
+ ); |
+ |
+ let selectors = new Array(50000).map((element, index) => ".s" + index); |
+ |
+ test.equal(ElemHide.createStyleSheet(selectors).split("\n").length, |
+ Math.ceil(50000 / selectorGroupSize), |
+ "Style sheet should be split up into rules with at most " + |
+ selectorGroupSize + " selectors each"); |
+ |
+ test.done(); |
+}; |