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

Unified Diff: test/elemHide.js

Issue 29886555: Issue 6957 - Add generateStyleSheetForDomain function to ElemHide module (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Sept. 20, 2018, 12:22 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
@@ -42,30 +42,42 @@
callback();
};
function normalizeSelectors(selectors)
{
// getSelectorsForDomain is currently allowed to return duplicate selectors
// for performance reasons, so we need to remove duplicates here.
- return selectors.sort().filter((selector, index, sortedSelectors) =>
+ return selectors.slice().sort().filter((selector, index, sortedSelectors) =>
Manish Jethani 2018/09/20 12:27:24 Somewhat unrelated, but we should make a copy and
Jon Sonesen 2018/09/20 20:10:20 Acknowledged. Just curious, since slice returns a
Manish Jethani 2018/09/21 10:53:05 The selectors themselves are immutable string obje
Jon Sonesen 2018/09/23 18:01:59 Yeah I figured since it is test code the importanc
{
return index == 0 || selector != sortedSelectors[index - 1];
});
}
function testResult(test, domain, expectedSelectors, specificOnly)
{
let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors);
test.deepEqual(
normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)),
normalizedExpectedSelectors
);
+
+ let {code, selectors} =
+ ElemHide.generateStyleSheetForDomain(domain, specificOnly);
+
+ test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors);
+
+ // Make sure each expected selector is in the actual CSS code.
+ for (let selector of normalizedExpectedSelectors)
+ {
+ test.ok(code.includes(selector + ", ") ||
+ code.includes(selector + " {display: none !important;}\n"));
+ }
Jon Sonesen 2018/09/20 20:10:20 I am sort of confused by the set literal `{code, s
Manish Jethani 2018/09/21 10:53:05 This is called a destructuring assignment [1] [1]
Jon Sonesen 2018/09/23 18:01:59 I do think the convention is helpful tbh so I was
}
exports.testGetSelectorsForDomain = function(test)
{
let addFilter = filterText => ElemHide.add(Filter.fromText(filterText));
let removeFilter = filterText => ElemHide.remove(Filter.fromText(filterText));
let addException =
filterText => ElemHideExceptions.add(Filter.fromText(filterText));
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld