Index: test/elemHide.js |
diff --git a/test/elemHide.js b/test/elemHide.js |
index b93baa4e4400ec3a923fb6ad515e874206128154..655b6ce62ae7102d8248ab39fd88b4c1ceb36d41 100644 |
--- a/test/elemHide.js |
+++ b/test/elemHide.js |
@@ -41,125 +41,179 @@ 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("", []); |
+ 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"], ElemHide.SPECIFIC_ONLY); |
+ testResult("example.com", ["foo", "bar"], ElemHide.SPECIFIC_ONLY); |
+ testResult("com", ["bar"], ElemHide.SPECIFIC_ONLY); |
+ testResult("", [], ElemHide.SPECIFIC_ONLY); |
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"], ElemHide.SPECIFIC_ONLY); |
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"], ElemHide.SPECIFIC_ONLY); |
+ testResult("foo.com", ["specific", "world"], ElemHide.NO_UNCONDITIONAL); |
+ testResult("foo.com", ["hello", "specific", "world"], ElemHide.ALL_MATCHING); |
+ 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"); |
Wladimir Palant
2016/09/26 14:56:54
How about:
testResult("foo.com", []);
This is
kzar
2016/09/27 12:40:22
Done.
|
+ |
+ addFilter("##hello"); |
+ addFilter("foo.com##hello"); |
+ testResult("foo.com", ["hello"]); |
+ removeFilter("##hello"); |
+ testResult("foo.com", ["hello"]); |
+ removeFilter("foo.com##hello"); |
Wladimir Palant
2016/09/26 14:56:54
Same here, how about testing the final state?
kzar
2016/09/27 12:40:22
Done.
|
+ |
Wladimir Palant
2016/09/26 14:56:54
How about testing the combination of ##hello and f
kzar
2016/09/27 12:40:22
Done.
|
+ // 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(); |
}; |