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: Add proper delete for filters in tests. Created Nov. 8, 2017, 12:02 a.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 | « meson.build ('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,29 +32,98 @@
ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses"),
{ElemHideEmulation} = sandboxedRequire("../lib/elemHideEmulation"),
{ElemHide} = sandboxedRequire("../lib/elemHide")
);
callback();
};
+
+exports.testElemHideAPI = function(test)
+{
+ {
+ 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();
+ }
+
+ {
+ 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);
+
+ 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 = 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");
+
+ let filter3 = Filter.fromText("example.com##.message");
+ ElemHide.add(filter3);
+ selectors = ElemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+ selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+
+ let filter4 = Filter.fromText("mail.example.com#@#.message");
+ ElemHide.add(filter4);
+ selectors = ElemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+ selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
+ test.equal(selectors.selectorCount, 2);
+
+ unconditionals = ElemHide.getUnconditionalSelectors();
+ test.equal(unconditionals.selectorCount, 1);
+
+ ElemHide.remove(filter4);
+ filter4.delete();
+ selectors = ElemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+ selectors = ElemHide.getSelectorsForDomain("mail.example.com", 0);
+ test.equal(selectors.selectorCount, 3);
+
+ ElemHide.remove(filter3);
+ filter3.delete();
+ selectors = ElemHide.getSelectorsForDomain("example.com", 0);
+ test.equal(selectors.selectorCount, 2);
+
+ test.done();
+};
+
exports.testDomainRestrictions = function(test)
{
function testSelectorMatches(description, filters, domain, expectedMatches)
{
- for (let filter of filters)
+ 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);
+ filter.delete();
}
-
let matches = ElemHideEmulation.getRulesForDomain(domain)
.map(filter => filter.text);
test.deepEqual(matches.sort(), expectedMatches.sort(), description);
ElemHideEmulation.clear();
ElemHide.clear();
}
« no previous file with comments | « meson.build ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld