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

Unified Diff: test/filterClasses.js

Issue 29737558: Issue 6538, 6781 - Implement support for snippet filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Make snippet filters similar to element hiding filters Created April 25, 2018, 5:15 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
Index: test/filterClasses.js
===================================================================
--- a/test/filterClasses.js
+++ b/test/filterClasses.js
@@ -39,18 +39,18 @@
let sandboxedRequire = createSandbox();
(
{Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter,
BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter,
ElemHideException,
ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses")
);
t = RegExpFilter.typeMap;
- defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP |
- t.GENERICHIDE | t.GENERICBLOCK);
+ defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.SNIPPET | t.DOCUMENT |
+ t.POPUP | t.GENERICHIDE | t.GENERICBLOCK);
callback();
};
function serializeFilter(filter)
{
// Filter serialization only writes out essential properties, need to do a full serialization here
let result = [];
@@ -102,18 +102,18 @@
{
if (filter instanceof ElemHideFilter)
result.push("type=elemhide");
else if (filter instanceof ElemHideException)
result.push("type=elemhideexception");
else if (filter instanceof ElemHideEmulationFilter)
result.push("type=elemhideemulation");
- result.push("selectorDomain=" + (filter.selectorDomain || ""));
- result.push("selector=" + filter.selector);
+ result.push("injectionDomain=" + (filter.injectionDomain || ""));
+ result.push("code=" + filter.code);
}
}
return result;
}
function addDefaults(expected)
{
let type = null;
@@ -137,32 +137,33 @@
{
addProperty("disabled", "false");
addProperty("lastHit", "0");
addProperty("hitCount", "0");
}
if (type == "whitelist" || type == "filterlist")
{
addProperty("contentType", 0x7FFFFFFF & ~(
- t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK
+ t.CSP | t.DOCUMENT | t.ELEMHIDE | t.SNIPPET | t.POPUP | t.GENERICHIDE |
+ t.GENERICBLOCK
));
addProperty("matchCase", "false");
addProperty("thirdParty", "null");
addProperty("domains", "");
addProperty("sitekeys", "");
}
if (type == "filterlist")
{
addProperty("collapse", "null");
addProperty("csp", "null");
}
if (type == "elemhide" || type == "elemhideexception" ||
type == "elemhideemulation")
{
- addProperty("selectorDomain", "");
+ addProperty("injectionDomain", "");
addProperty("domains", "");
}
}
function compareFilter(test, text, expected, postInit)
{
addDefaults(expected);
@@ -321,62 +322,62 @@
compareFilter(test, "bla$csp=foo,csp=upgrade-insecure-requests", ["type=invalid", "text=bla$csp=foo,csp=upgrade-insecure-requests", "reason=filter_invalid_csp"]);
compareFilter(test, "bla$csp=foo,csp=ReFeRReR", ["type=invalid", "text=bla$csp=foo,csp=ReFeRReR", "reason=filter_invalid_csp"]);
test.done();
};
exports.testElementHidingRules = function(test)
{
- compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "selector=ddd"]);
- compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "selector=body > div:first-child"]);
- compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO"]);
- compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
- compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
- compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar##ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
+ compareFilter(test, "##ddd", ["type=elemhide", "text=##ddd", "code=ddd"]);
+ compareFilter(test, "##body > div:first-child", ["type=elemhide", "text=##body > div:first-child", "code=body > div:first-child"]);
+ compareFilter(test, "foo##ddd", ["type=elemhide", "text=foo##ddd", "injectionDomain=foo", "code=ddd", "domains=FOO"]);
+ compareFilter(test, "foo,bar##ddd", ["type=elemhide", "text=foo,bar##ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO"]);
+ compareFilter(test, "foo,~bar##ddd", ["type=elemhide", "text=foo,~bar##ddd", "injectionDomain=foo", "code=ddd", "domains=FOO|~BAR"]);
+ compareFilter(test, "foo,~baz,bar##ddd", ["type=elemhide", "text=foo,~baz,bar##ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO|~BAZ"]);
test.done();
};
exports.testElementHidingExceptions = function(test)
{
- compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "selector=ddd"]);
- compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "text=#@#body > div:first-child", "selector=body > div:first-child"]);
- compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO"]);
- compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar#@#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO"]);
- compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~bar#@#ddd", "selectorDomain=foo", "selector=ddd", "domains=FOO|~BAR"]);
- compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo,~baz,bar#@#ddd", "selectorDomain=foo,bar", "selector=ddd", "domains=BAR|FOO|~BAZ"]);
+ compareFilter(test, "#@#ddd", ["type=elemhideexception", "text=#@#ddd", "code=ddd"]);
+ compareFilter(test, "#@#body > div:first-child", ["type=elemhideexception", "text=#@#body > div:first-child", "code=body > div:first-child"]);
+ compareFilter(test, "foo#@#ddd", ["type=elemhideexception", "text=foo#@#ddd", "injectionDomain=foo", "code=ddd", "domains=FOO"]);
+ compareFilter(test, "foo,bar#@#ddd", ["type=elemhideexception", "text=foo,bar#@#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO"]);
+ compareFilter(test, "foo,~bar#@#ddd", ["type=elemhideexception", "text=foo,~bar#@#ddd", "injectionDomain=foo", "code=ddd", "domains=FOO|~BAR"]);
+ compareFilter(test, "foo,~baz,bar#@#ddd", ["type=elemhideexception", "text=foo,~baz,bar#@#ddd", "injectionDomain=foo,bar", "code=ddd", "domains=BAR|FOO|~BAZ"]);
test.done();
};
exports.testElemHideEmulationFilters = function(test)
{
// Check valid domain combinations
- compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM"]);
- compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhideemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]);
- compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemulation", "text=foo.com,~bar#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]);
- compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhideemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "selectorDomain=bar.com", "selector=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]);
+ compareFilter(test, "foo.com#?#:-abp-properties(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:-abp-properties(abc)", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com,~bar.com#?#:-abp-properties(abc)", ["type=elemhideemulation", "text=foo.com,~bar.com#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:-abp-properties(abc)", "domains=FOO.COM|~BAR.COM"]);
+ compareFilter(test, "foo.com,~bar#?#:-abp-properties(abc)", ["type=elemhideemulation", "text=foo.com,~bar#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:-abp-properties(abc)", "domains=FOO.COM|~BAR"]);
+ compareFilter(test, "~foo.com,bar.com#?#:-abp-properties(abc)", ["type=elemhideemulation", "text=~foo.com,bar.com#?#:-abp-properties(abc)", "injectionDomain=bar.com", "code=:-abp-properties(abc)", "domains=BAR.COM|~FOO.COM"]);
// Check some special cases
compareFilter(test, "#?#:-abp-properties(abc)", ["type=invalid", "text=#?#:-abp-properties(abc)", "reason=filter_elemhideemulation_nodomain"]);
- compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com#?#abc", "selectorDomain=foo.com", "selector=abc", "domains=FOO.COM"]);
- compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-foobar(abc)", "selectorDomain=foo.com", "selector=:-abp-foobar(abc)", "domains=FOO.COM"]);
- compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhideemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomain=foo.com", "selector=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]);
- compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*))", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-image: url(data:*))", "selectorDomain=foo.com", "selector=:-abp-properties(|background-image: url(data:*))", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com#?#abc", ["type=elemhideemulation", "text=foo.com#?#abc", "injectionDomain=foo.com", "code=abc", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com#?#:-abp-foobar(abc)", ["type=elemhideemulation", "text=foo.com#?#:-abp-foobar(abc)", "injectionDomain=foo.com", "code=:-abp-foobar(abc)", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com#?#aaa :-abp-properties(abc) bbb", ["type=elemhideemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "injectionDomain=foo.com", "code=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com#?#:-abp-properties(|background-image: url(data:*))", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(|background-image: url(data:*))", "injectionDomain=foo.com", "code=:-abp-properties(|background-image: url(data:*))", "domains=FOO.COM"]);
// Check conversion of legacy filters
- compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(abc)", "selectorDomain=foo.com", "selector=:-abp-properties(abc)", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=elemhideemulation", "text=foo.com#?#:-abp-properties(abc)", "injectionDomain=foo.com", "code=:-abp-properties(abc)", "domains=FOO.COM"]);
test.equal(Filter.fromText("foo.com##[-abp-properties='abc']"), Filter.fromText("foo.com#?#:-abp-properties(abc)"));
- compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexception", "text=foo.com#@#[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM"]);
- compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=elemhideemulation", "text=foo.com#?#[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM"]);
- compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhideemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "selectorDomain=foo.com", "selector=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com#@#[-abp-properties='abc']", ["type=elemhideexception", "text=foo.com#@#[-abp-properties='abc']", "injectionDomain=foo.com", "code=[-abp-properties='abc']", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com#?#[-abp-properties='abc']", ["type=elemhideemulation", "text=foo.com#?#[-abp-properties='abc']", "injectionDomain=foo.com", "code=[-abp-properties='abc']", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com##aaa [-abp-properties='abc'] bbb", ["type=elemhideemulation", "text=foo.com#?#aaa :-abp-properties(abc) bbb", "injectionDomain=foo.com", "code=aaa :-abp-properties(abc) bbb", "domains=FOO.COM"]);
// test matching -abp-properties= (https://issues.adblockplus.org/ticket/5037).
- compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide", "text=foo.com##[-abp-properties-bogus='abc']", "selectorDomain=foo.com", "selector=[-abp-properties-bogus='abc']", "domains=FOO.COM"]);
+ compareFilter(test, "foo.com##[-abp-properties-bogus='abc']", ["type=elemhide", "text=foo.com##[-abp-properties-bogus='abc']", "injectionDomain=foo.com", "code=[-abp-properties-bogus='abc']", "domains=FOO.COM"]);
test.done();
};
exports.testEmptyElemHideDomains = function(test)
{
let emptyDomainFilters = [
",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector",
@@ -395,27 +396,27 @@
};
exports.testElemHideRulesWithBraces = function(test)
{
compareFilter(
test, "###foo{color: red}", [
"type=elemhide",
"text=###foo{color: red}",
- "selectorDomain=",
- "selector=#foo\\7B color: red\\7D ",
+ "injectionDomain=",
+ "code=#foo\\7B color: red\\7D ",
"domains="
]
);
compareFilter(
test, "foo.com#?#:-abp-properties(/margin: [3-4]{2}/)", [
"type=elemhideemulation",
"text=foo.com#?#:-abp-properties(/margin: [3-4]{2}/)",
- "selectorDomain=foo.com",
- "selector=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)",
+ "injectionDomain=foo.com",
+ "code=:-abp-properties(/margin: [3-4]\\7B 2\\7D /)",
"domains=FOO.COM"
]
);
test.done();
};
exports.testFilterNormalization = function(test)
{

Powered by Google App Engine
This is Rietveld