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

Unified Diff: test/elemHide.js

Issue 29897558: Issue 6957 - Add rulesFromStyleSheet function to ElemHide module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Oct. 1, 2018, 2:56 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
« no previous file with comments | « 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
@@ -16,31 +16,32 @@
*/
"use strict";
const {createSandbox} = require("./_common");
let ElemHide = null;
let createStyleSheet = null;
+let rulesFromStyleSheet = null;
let ElemHideExceptions = null;
let Filter = null;
let filtersByDomain = null;
let selectorGroupSize = null;
exports.setUp = function(callback)
{
let sandboxedRequire = createSandbox({
extraExports: {
elemHide: ["filtersByDomain", "selectorGroupSize"]
}
});
(
- {ElemHide, createStyleSheet, filtersByDomain, selectorGroupSize} =
- sandboxedRequire("../lib/elemHide"),
+ {ElemHide, createStyleSheet, rulesFromStyleSheet,
+ filtersByDomain, selectorGroupSize} = sandboxedRequire("../lib/elemHide"),
{ElemHideExceptions} = sandboxedRequire("../lib/elemHideExceptions"),
{Filter} = sandboxedRequire("../lib/filterClasses")
);
callback();
};
function normalizeSelectors(selectors)
@@ -300,8 +301,23 @@
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();
};
+
+exports.testRulesFromStyleSheet = function(test)
+{
+ // Note: The rulesFromStyleSheet function assumes that each rule will be
+ // terminated with a newline character, including the last rule. If this is
+ // not the case, the function goes into an infinite loop. It should only be
+ // used with the return value of the createStyleSheet function.
+
+ test.deepEqual([...rulesFromStyleSheet("")], []);
+ test.deepEqual([...rulesFromStyleSheet("#foo {}\n")], ["#foo {}"]);
+ test.deepEqual([...rulesFromStyleSheet("#foo {}\n#bar {}\n")],
+ ["#foo {}", "#bar {}"]);
+
+ test.done();
+};
« no previous file with comments | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld