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

Unified Diff: test/elemHide.js

Issue 29349187: Issue 4167 - getSelectorsForDomain criteria + keys (Closed)
Patch Set: Further improve tests Created Sept. 20, 2016, 2:42 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
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/elemHide.js
diff --git a/test/elemHide.js b/test/elemHide.js
index b93baa4e4400ec3a923fb6ad515e874206128154..acd2f406aa17e1f82a2044f8aeb750887f82e87e 100644
--- a/test/elemHide.js
+++ b/test/elemHide.js
@@ -41,125 +41,183 @@ exports.testGetSelectorsForDomain = function(test)
return index == 0 || selector != selectors[index - 1];
});
}
- function selectorsEqual(domain, expectedSelectors, specificOnly)
+ function testResult(domain, expectedSelectors, criteria)
{
+ let normalizedExpectedSelectors = normalizeSelectors(expectedSelectors);
+
+ // Test without filter keys
test.deepEqual(
- normalizeSelectors(ElemHide.getSelectorsForDomain(domain, specificOnly)),
- normalizeSelectors(expectedSelectors)
+ normalizeSelectors(ElemHide.getSelectorsForDomain(domain, criteria)),
+ normalizedExpectedSelectors
);
+
+ // With filter keys
+ let [selectors, filterKeys] = ElemHide.getSelectorsForDomain(domain, criteria,
+ true);
+ test.deepEqual(filterKeys.map(k => ElemHide.getFilterByKey(k).selector),
+ selectors);
+ test.deepEqual(normalizeSelectors(selectors), normalizedExpectedSelectors);
}
- selectorsEqual("", []);
+ let allSelectors = 0;
+ let noUnconditional = 1;
+ let specificOnly = 2;
+
+ testResult("", []);
addFilter("~foo.example.com,example.com##foo");
- selectorsEqual("barfoo.example.com", ["foo"]);
- selectorsEqual("bar.foo.example.com", []);
- selectorsEqual("foo.example.com", []);
- selectorsEqual("example.com", ["foo"]);
- selectorsEqual("com", []);
- selectorsEqual("", []);
+ testResult("barfoo.example.com", ["foo"]);
+ testResult("bar.foo.example.com", []);
+ testResult("foo.example.com", []);
+ testResult("example.com", ["foo"]);
+ testResult("com", []);
+ testResult("", []);
addFilter("foo.example.com##turnip");
- selectorsEqual("foo.example.com", ["turnip"]);
- selectorsEqual("example.com", ["foo"]);
- selectorsEqual("com", []);
- selectorsEqual("", []);
+ testResult("foo.example.com", ["turnip"]);
+ testResult("example.com", ["foo"]);
+ testResult("com", []);
+ testResult("", []);
addFilter("example.com#@#foo");
- selectorsEqual("foo.example.com", ["turnip"]);
- selectorsEqual("example.com", []);
- selectorsEqual("com", []);
- selectorsEqual("", []);
+ testResult("foo.example.com", ["turnip"]);
+ testResult("example.com", []);
+ testResult("com", []);
+ testResult("", []);
addFilter("com##bar");
- selectorsEqual("foo.example.com", ["turnip", "bar"]);
- selectorsEqual("example.com", ["bar"]);
- selectorsEqual("com", ["bar"]);
- selectorsEqual("", []);
+ testResult("foo.example.com", ["turnip", "bar"]);
+ testResult("example.com", ["bar"]);
+ testResult("com", ["bar"]);
+ testResult("", []);
addFilter("example.com#@#bar");
- selectorsEqual("foo.example.com", ["turnip"]);
- selectorsEqual("example.com", []);
- selectorsEqual("com", ["bar"]);
- selectorsEqual("", []);
+ testResult("foo.example.com", ["turnip"]);
+ testResult("example.com", []);
+ testResult("com", ["bar"]);
+ testResult("", []);
removeFilter("example.com#@#foo");
- selectorsEqual("foo.example.com", ["turnip"]);
- selectorsEqual("example.com", ["foo"]);
- selectorsEqual("com", ["bar"]);
- selectorsEqual("", []);
+ testResult("foo.example.com", ["turnip"]);
+ testResult("example.com", ["foo"]);
+ testResult("com", ["bar"]);
+ testResult("", []);
removeFilter("example.com#@#bar");
- selectorsEqual("foo.example.com", ["turnip", "bar"]);
- selectorsEqual("example.com", ["foo", "bar"]);
- selectorsEqual("com", ["bar"]);
- selectorsEqual("", []);
+ testResult("foo.example.com", ["turnip", "bar"]);
+ testResult("example.com", ["foo", "bar"]);
+ testResult("com", ["bar"]);
+ testResult("", []);
addFilter("##generic");
- selectorsEqual("foo.example.com", ["turnip", "bar", "generic"]);
- selectorsEqual("example.com", ["foo", "bar", "generic"]);
- selectorsEqual("com", ["bar", "generic"]);
- selectorsEqual("", ["generic"]);
- selectorsEqual("foo.example.com", ["turnip", "bar"], true);
- selectorsEqual("example.com", ["foo", "bar"], true);
- selectorsEqual("com", ["bar"], true);
- selectorsEqual("", [], true);
+ testResult("foo.example.com", ["turnip", "bar", "generic"]);
+ testResult("example.com", ["foo", "bar", "generic"]);
+ testResult("com", ["bar", "generic"]);
+ testResult("", ["generic"]);
+ testResult("foo.example.com", ["turnip", "bar"], specificOnly);
+ testResult("example.com", ["foo", "bar"], specificOnly);
+ testResult("com", ["bar"], specificOnly);
+ testResult("", [], specificOnly);
removeFilter("##generic");
addFilter("~adblockplus.org##example");
- selectorsEqual("adblockplus.org", []);
- selectorsEqual("", ["example"]);
- selectorsEqual("foo.example.com", ["turnip", "bar", "example"]);
- selectorsEqual("foo.example.com", ["turnip", "bar"], true);
+ testResult("adblockplus.org", []);
+ testResult("", ["example"]);
+ testResult("foo.example.com", ["turnip", "bar", "example"]);
+ testResult("foo.example.com", ["turnip", "bar"], specificOnly);
removeFilter("~adblockplus.org##example");
removeFilter("~foo.example.com,example.com##foo");
- selectorsEqual("foo.example.com", ["turnip", "bar"]);
- selectorsEqual("example.com", ["bar"]);
- selectorsEqual("com", ["bar"]);
- selectorsEqual("", []);
+ testResult("foo.example.com", ["turnip", "bar"]);
+ testResult("example.com", ["bar"]);
+ testResult("com", ["bar"]);
+ testResult("", []);
removeFilter("com##bar");
- selectorsEqual("foo.example.com", ["turnip"]);
- selectorsEqual("example.com", []);
- selectorsEqual("com", []);
- selectorsEqual("", []);
+ testResult("foo.example.com", ["turnip"]);
+ testResult("example.com", []);
+ testResult("com", []);
+ testResult("", []);
removeFilter("foo.example.com##turnip");
- selectorsEqual("foo.example.com", []);
- selectorsEqual("example.com", []);
- selectorsEqual("com", []);
- selectorsEqual("", []);
+ testResult("foo.example.com", []);
+ testResult("example.com", []);
+ testResult("com", []);
+ testResult("", []);
addFilter("example.com##dupe");
addFilter("example.com##dupe");
- selectorsEqual("example.com", ["dupe"]);
+ testResult("example.com", ["dupe"]);
removeFilter("example.com##dupe");
- selectorsEqual("example.com", []);
+ testResult("example.com", []);
removeFilter("example.com##dupe");
addFilter("~foo.example.com,example.com##foo");
addFilter("##foo");
- selectorsEqual("foo.example.com", ["foo"]);
- selectorsEqual("example.com", ["foo"]);
- selectorsEqual("com", ["foo"]);
- selectorsEqual("", ["foo"]);
+ testResult("foo.example.com", ["foo"]);
+ testResult("example.com", ["foo"]);
+ testResult("com", ["foo"]);
+ testResult("", ["foo"]);
removeFilter("##foo");
addFilter("example.org##foo");
- selectorsEqual("foo.example.com", []);
- selectorsEqual("example.com", ["foo"]);
- selectorsEqual("com", []);
- selectorsEqual("", []);
+ testResult("foo.example.com", []);
+ testResult("example.com", ["foo"]);
+ testResult("com", []);
+ testResult("", []);
removeFilter("example.org##foo");
addFilter("~example.com##foo");
- selectorsEqual("foo.example.com", []);
- selectorsEqual("example.com", ["foo"]);
- selectorsEqual("com", ["foo"]);
- selectorsEqual("", ["foo"]);
- removeFilter("example.org##foo");
+ testResult("foo.example.com", []);
+ testResult("example.com", ["foo"]);
+ testResult("com", ["foo"]);
+ testResult("", ["foo"]);
+ removeFilter("~example.com##foo");
+
+ removeFilter("~foo.example.com,example.com##foo");
+
+ // Test criteria
+ addFilter("##hello");
+ addFilter("~example.com##world");
+ addFilter("foo.com##specific");
+ testResult("foo.com", ["specific"], specificOnly);
+ testResult("foo.com", ["specific", "world"], noUnconditional);
+ testResult("foo.com", ["hello", "specific", "world"], allSelectors);
+ testResult("foo.com", ["hello", "specific", "world"]);
+ removeFilter("foo.com##specific");
+ removeFilter("~example.com##world");
+ removeFilter("##hello");
+
+ addFilter("##hello");
+ addFilter("foo.com##hello");
+ testResult("foo.com", ["hello"]);
+ removeFilter("foo.com##hello");
+ testResult("foo.com", ["hello"]);
+ removeFilter("##hello");
+
+ addFilter("##hello");
+ addFilter("foo.com##hello");
+ testResult("foo.com", ["hello"]);
+ removeFilter("##hello");
+ testResult("foo.com", ["hello"]);
+ removeFilter("foo.com##hello");
+
+ // Advanced filter keys test
+ testResult("", []);
+ addFilter("##dupe");
+ addFilter(",,##dupe");
+ addFilter(",,,##dupe");
+ addFilter("foo.com##dupe");
+ testResult("", ["dupe"]);
+ removeFilter(",,,##dupe");
+ testResult("", ["dupe"]);
+ removeFilter("foo.com##dupe");
+ testResult("", ["dupe"]);
+ removeFilter(",,##dupe");
+ testResult("", ["dupe"]);
+ removeFilter("##dupe");
+ testResult("", []);
test.done();
};
« lib/elemHide.js ('K') | « lib/elemHide.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld