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

Unified Diff: test/elemHideEmulation.js

Issue 29594607: Issue 5143 - Convert ElemHideEmulation to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebase. Review comments addressed. Created Jan. 25, 2018, 7:04 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
« compiled/ElemHideEmulation.cpp ('K') | « 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
@@ -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();
};
« compiled/ElemHideEmulation.cpp ('K') | « meson.build ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld