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(); |
} |