Index: test/elemHideEmulation.js |
=================================================================== |
--- a/test/elemHideEmulation.js |
+++ b/test/elemHideEmulation.js |
@@ -82,54 +82,84 @@ |
})(elemHide.getSelectorsForDomain("example.com", 0)); |
withNAD(0, filter3 => |
{ |
elemHide.add(filter3); |
withNAD( |
0, selectors => |
- test.equal(selectors.selectorCount, 3))( |
+ { |
sergei
2018/01/30 16:00:48
It seems some changes like these are not related t
hub
2018/01/30 17:37:58
In a preview comment on this review you wanted to
sergei
2018/01/30 17:40:56
Ah, OK.
|
+ test.equal(selectors.selectorCount, 3); |
+ test.equal(selectors.selectorAt(0), "#ads"); |
+ test.equal(selectors.selectorAt(1), ".message"); |
+ test.equal(selectors.selectorAt(2), ".foo"); |
+ })( |
elemHide.getSelectorsForDomain("example.com", 0)); |
withNAD( |
0, selectors => |
- test.equal(selectors.selectorCount, 3))( |
+ { |
+ test.equal(selectors.selectorCount, 3); |
+ test.equal(selectors.selectorAt(0), "#ads"); |
+ test.equal(selectors.selectorAt(1), ".message"); |
+ test.equal(selectors.selectorAt(2), ".foo"); |
+ })( |
elemHide.getSelectorsForDomain("mail.example.com", 0)); |
withNAD(0, filter4 => |
{ |
elemHide.add(filter4); |
withNAD( |
0, selectors => |
- test.equal(selectors.selectorCount, 3))( |
+ { |
+ test.equal(selectors.selectorCount, 3); |
+ test.equal(selectors.selectorAt(0), "#ads"); |
+ test.equal(selectors.selectorAt(1), ".message"); |
+ test.equal(selectors.selectorAt(2), ".foo"); |
+ })( |
elemHide.getSelectorsForDomain("example.com", 0)); |
withNAD( |
0, selectors => |
- test.equal(selectors.selectorCount, 2))( |
+ { |
+ test.equal(selectors.selectorCount, 2); |
+ test.equal(selectors.selectorAt(0), "#ads"); |
+ test.equal(selectors.selectorAt(1), ".foo"); |
+ })( |
elemHide.getSelectorsForDomain("mail.example.com", 0)); |
withNAD( |
0, |
unconditionals => |
- test.equal(unconditionals.selectorCount, 1))(elemHide.getUnconditionalSelectors()); |
+ { |
+ test.equal(unconditionals.selectorCount, 1); |
+ test.equal(unconditionals.selectorAt(0), "#ads"); |
+ })(elemHide.getUnconditionalSelectors()); |
elemHide.remove(filter4); |
})(Filter.fromText("mail.example.com#@#.message")); |
withNAD( |
0, selectors => |
- test.equal(selectors.selectorCount, 3))( |
- elemHide.getSelectorsForDomain("example.com", 0)); |
+ { |
+ test.equal(selectors.selectorCount, 3); |
+ test.equal(selectors.selectorAt(0), "#ads"); |
+ test.equal(selectors.selectorAt(1), ".message"); |
+ test.equal(selectors.selectorAt(2), ".foo"); |
+ })(elemHide.getSelectorsForDomain("example.com", 0)); |
withNAD( |
0, selectors => |
- test.equal(selectors.selectorCount, 3))( |
- elemHide.getSelectorsForDomain("mail.example.com", 0)); |
+ { |
+ test.equal(selectors.selectorCount, 3); |
+ test.equal(selectors.selectorAt(0), "#ads"); |
+ test.equal(selectors.selectorAt(1), ".message"); |
+ test.equal(selectors.selectorAt(2), ".foo"); |
+ })(elemHide.getSelectorsForDomain("mail.example.com", 0)); |
elemHide.remove(filter3); |
})(Filter.fromText("example.com##.message")); |
withNAD( |
0, selectors => |
test.equal(selectors.selectorCount, 2))( |
elemHide.getSelectorsForDomain("example.com", 0)); |
@@ -137,35 +167,42 @@ |
test.done(); |
}; |
exports.testDomainRestrictions = function(test) |
{ |
function testSelectorMatches(description, filters, domain, expectedMatches) |
{ |
- withNAD(0, elemHide => |
+ withNAD([0, 1], (elemHide, elemHideEmulation) => |
{ |
let addFilter = withNAD(0, filter => |
{ |
if (filter instanceof ElemHideEmulationFilter) |
- ElemHideEmulation.add(filter); |
+ elemHideEmulation.add(filter); |
else |
elemHide.add(filter); |
}); |
for (let text of filters) |
addFilter(Filter.fromText(text)); |
- let matches = ElemHideEmulation.getRulesForDomain(domain, elemHide) |
- .map(filter => filter.text); |
- test.deepEqual(matches.sort(), expectedMatches.sort(), description); |
+ withNAD(0, rules => |
+ { |
+ let matches = []; |
+ let push = withNAD(0, filter => matches.push(filter.text)); |
- ElemHideEmulation.clear(); |
- })(ElemHide.create()); |
+ for (let i = 0; i < rules.filterCount; i++) |
+ push(rules.filterAt(i)); |
+ |
+ test.deepEqual(matches.sort(), expectedMatches.sort(), description); |
+ })(elemHideEmulation.getRulesForDomain(elemHide, domain)); |
+ |
+ elemHideEmulation.clear(); |
+ })(ElemHide.create(), ElemHideEmulation.create()); |
} |
testSelectorMatches( |
"Ignore generic filters", |
[ |
"##[-abp-properties='foo']", "example.com##[-abp-properties='foo']", |
"~example.com##[-abp-properties='foo']" |
], |
@@ -209,49 +246,57 @@ |
["other.example.com##[-abp-properties='foo']"] |
); |
test.done(); |
}; |
exports.testElemHideEmulationFiltersContainer = function(test) |
{ |
- withNAD(0, elemHide => |
+ withNAD([0, 1], (elemHide, elemHideEmulation) => |
{ |
function compareRules(description, domain, expectedMatches) |
{ |
- let result = ElemHideEmulation.getRulesForDomain(domain, elemHide) |
- .map(filter => filter.text); |
+ let rules = elemHideEmulation.getRulesForDomain(elemHide, domain); |
+ let result = []; |
+ for (let i = 0; i < rules.filterCount; i++) |
+ { |
+ let filter = rules.filterAt(i); |
+ result.push(filter.text); |
+ filter.delete(); |
+ } |
expectedMatches = expectedMatches.map(filter => filter.text); |
test.deepEqual(result.sort(), expectedMatches.sort(), description); |
+ |
+ rules.delete(); |
} |
withNAD([0, 1, 2], (domainFilter, subdomainFilter, otherDomainFilter) => |
{ |
- ElemHideEmulation.add(domainFilter); |
- ElemHideEmulation.add(subdomainFilter); |
- ElemHideEmulation.add(otherDomainFilter); |
+ elemHideEmulation.add(domainFilter); |
+ elemHideEmulation.add(subdomainFilter); |
+ elemHideEmulation.add(otherDomainFilter); |
compareRules( |
"Return all matching filters", |
"www.example.com", |
[domainFilter, subdomainFilter] |
); |
- ElemHideEmulation.remove(domainFilter); |
+ elemHideEmulation.remove(domainFilter); |
compareRules( |
"Return all matching filters after removing one", |
"www.example.com", |
[subdomainFilter] |
); |
- ElemHideEmulation.clear(); |
+ elemHideEmulation.clear(); |
compareRules( |
"Return no filters after clearing", |
"www.example.com", |
[] |
); |
})(Filter.fromText("example.com##filter1"), |
Filter.fromText("www.example.com##filter2"), |
Filter.fromText("other.example.com##filter3")); |
- })(ElemHide.create()); |
+ })(ElemHide.create(), ElemHideEmulation.create()); |
test.done(); |
}; |