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: Created Sept. 16, 2018, 5:19 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
@@ -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();
+};
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld