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

Unified Diff: test/elemHideEmulation.js

Issue 29587914: Issue 5142 - Convert Element Hiding to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: remove an unused #include Created Jan. 22, 2018, 4:52 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 | « test/elemHide.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/elemHideEmulation.js
===================================================================
--- a/test/elemHideEmulation.js
+++ b/test/elemHideEmulation.js
@@ -32,35 +32,121 @@
ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"),
{ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"),
{ElemHide} = sandboxedRequire("../lib/elemHide")
);
callback();
};
+exports.testElemHideAPI = function(test)
+{
+ let elemHide = ElemHide.create();
+
+ {
+ let filter = Filter.fromText("###ads");
+ elemHide.add(filter);
+
+ test.equal(filter.selectorDomain, "");
+ let unconditionals = elemHide.getUnconditionalSelectors();
+ test.equal(unconditionals.selectorCount, 1);
+ test.equal(unconditionals.selectorAt(0), "#ads");
+ test.equal(unconditionals.filterKeyAt(0), "###ads");
+ filter.delete();
+ unconditionals.delete();
+ }
+
+ {
+ let filter2 = Filter.fromText("example.com##.foo");
+ elemHide.add(filter2);
+ test.equal(filter2.selectorDomain, "example.com");
+ filter2.delete();
+ }
+
+ let unconditionals = elemHide.getUnconditionalSelectors();
+ test.equal(unconditionals.selectorCount, 1);
+ unconditionals.delete();
+
+ let selectors = elemHide.getSelectorsForDomain("example.com", 1);
+ test.equal(selectors.selectorCount, 1);
+ test.equal(selectors.selectorAt(0), ".foo");
+ test.equal(selectors.filterKeyAt(0), "example.com##.foo");
+ selectors.delete();
+
+ selectors = elemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 2);
+ test.equal(selectors.selectorAt(0), "#ads");
+ test.equal(selectors.filterKeyAt(0), "###ads");
+ test.equal(selectors.selectorAt(1), ".foo");
+ test.equal(selectors.filterKeyAt(1), "example.com##.foo");
+ selectors.delete();
+
+ let filter3 = Filter.fromText("example.com##.message");
+ elemHide.add(filter3);
+ selectors = elemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+ selectors.delete();
+ selectors = elemHide.getSelectorsForDomain("mail.example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+ selectors.delete();
+
+ let filter4 = Filter.fromText("mail.example.com#@#.message");
+ elemHide.add(filter4);
+ selectors = elemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+ selectors.delete();
+ selectors = elemHide.getSelectorsForDomain("mail.example.com", 0);
+ test.equal(selectors.selectorCount, 2);
+ selectors.delete();
+
+ unconditionals = elemHide.getUnconditionalSelectors();
+ test.equal(unconditionals.selectorCount, 1);
+ unconditionals.delete();
+
+ elemHide.remove(filter4);
+ filter4.delete();
+ selectors = elemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+ selectors.delete();
+ selectors = elemHide.getSelectorsForDomain("mail.example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+ selectors.delete();
+
+ elemHide.remove(filter3);
+ filter3.delete();
+ selectors = elemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 2);
+ selectors.delete();
+
+ elemHide.delete();
+ test.done();
+};
+
exports.testDomainRestrictions = function(test)
{
function testSelectorMatches(description, filters, domain, expectedMatches)
{
- for (let filter of filters)
+ let elemHide = ElemHide.create();
+
+ for (let text of filters)
{
- filter = Filter.fromText(filter);
+ let filter = Filter.fromText(text);
if (filter instanceof ElemHideEmulationFilter)
ElemHideEmulation.add(filter);
else
- ElemHide.add(filter);
+ elemHide.add(filter);
+ filter.delete();
}
-
- let matches = ElemHideEmulation.getRulesForDomain(domain)
+ let matches = ElemHideEmulation.getRulesForDomain(domain, elemHide)
.map(filter => filter.text);
test.deepEqual(matches.sort(), expectedMatches.sort(), description);
ElemHideEmulation.clear();
- ElemHide.clear();
+
+ elemHide.delete();
}
testSelectorMatches(
"Ignore generic filters",
[
"##[-abp-properties='foo']", "example.com##[-abp-properties='foo']",
"~example.com##[-abp-properties='foo']"
],
@@ -104,19 +190,21 @@
["other.example.com##[-abp-properties='foo']"]
);
test.done();
};
exports.testElemHideEmulationFiltersContainer = function(test)
{
+ let elemHide = ElemHide.create();
+
function compareRules(description, domain, expectedMatches)
{
- let result = ElemHideEmulation.getRulesForDomain(domain)
+ let result = ElemHideEmulation.getRulesForDomain(domain, elemHide)
.map(filter => filter.text);
expectedMatches = expectedMatches.map(filter => filter.text);
test.deepEqual(result.sort(), expectedMatches.sort(), description);
}
let domainFilter = Filter.fromText("example.com##filter1");
let subdomainFilter = Filter.fromText("www.example.com##filter2");
let otherDomainFilter = Filter.fromText("other.example.com##filter3");
@@ -139,10 +227,12 @@
ElemHideEmulation.clear();
compareRules(
"Return no filters after clearing",
"www.example.com",
[]
);
+ elemHide.delete();
+
test.done();
};
« no previous file with comments | « test/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld