Index: test/filterClasses.js |
=================================================================== |
--- a/test/filterClasses.js |
+++ b/test/filterClasses.js |
@@ -24,28 +24,28 @@ |
let CommentFilter = null; |
let ActiveFilter = null; |
let RegExpFilter = null; |
let BlockingFilter = null; |
let WhitelistFilter = null; |
let ElemHideBase = null; |
let ElemHideFilter = null; |
let ElemHideException = null; |
-let CSSPropertyFilter = null; |
+let ElemHideEmulationFilter = null; |
let t = null; |
let defaultTypes = null; |
exports.setUp = function(callback) |
{ |
let sandboxedRequire = createSandbox(); |
( |
{Filter, InvalidFilter, CommentFilter, ActiveFilter, RegExpFilter, |
BlockingFilter, WhitelistFilter, ElemHideBase, ElemHideFilter, |
- ElemHideException, CSSPropertyFilter} = sandboxedRequire("../lib/filterClasses") |
+ ElemHideException, ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses") |
kzar
2016/11/21 16:24:55
Nit: This and some of the other lines you've modif
Felix Dahlke
2016/11/21 17:26:12
I'd actually prefer to leave those alone as part o
kzar
2016/11/21 19:18:22
On 2016/11/21 17:26:12, Felix Dahlke wrote:
Felix Dahlke
2016/11/21 20:11:48
Fair enough, I fixed all lines I'm touching know,
|
); |
t = RegExpFilter.typeMap; |
defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP | |
t.GENERICHIDE | t.GENERICBLOCK); |
callback(); |
}; |
@@ -99,23 +99,18 @@ |
} |
} |
else if (filter instanceof ElemHideBase) |
{ |
if (filter instanceof ElemHideFilter) |
result.push("type=elemhide"); |
else if (filter instanceof ElemHideException) |
result.push("type=elemhideexception"); |
- else if (filter instanceof CSSPropertyFilter) |
- { |
- result.push("type=cssrule"); |
- result.push("prefix=" + (filter.selectorPrefix || "")); |
- result.push("regexp=" + filter.regexpString); |
- result.push("suffix=" + (filter.selectorSuffix || "")); |
- } |
+ else if (filter instanceof ElemHideEmulationFilter) |
+ result.push("type=elemhideemulation"); |
result.push("selectorDomain=" + (filter.selectorDomain || "")); |
result.push("selector=" + filter.selector); |
} |
} |
return result; |
} |
@@ -132,17 +127,17 @@ |
} |
function addProperty(prop, value) |
{ |
if (!(prop in hasProperty)) |
expected.push(prop + "=" + value); |
} |
- if (type == "whitelist" || type == "filterlist" || type == "elemhide" || type == "elemhideexception" || type == "cssrule") |
+ if (type == "whitelist" || type == "filterlist" || type == "elemhide" || type == "elemhideexception" || type == "elemhideemulation") |
{ |
addProperty("disabled", "false"); |
addProperty("lastHit", "0"); |
addProperty("hitCount", "0"); |
} |
if (type == "whitelist" || type == "filterlist") |
{ |
addProperty("contentType", 0x7FFFFFFF & ~( |
@@ -154,27 +149,21 @@ |
addProperty("thirdParty", "null"); |
addProperty("domains", ""); |
addProperty("sitekeys", ""); |
} |
if (type == "filterlist") |
{ |
addProperty("collapse", "null"); |
} |
- if (type == "elemhide" || type == "elemhideexception" || type == "cssrule") |
+ if (type == "elemhide" || type == "elemhideexception" || type == "elemhideemulation") |
{ |
addProperty("selectorDomain", ""); |
addProperty("domains", ""); |
} |
- if (type == "cssrule") |
- { |
- addProperty("regexp", ""); |
- addProperty("prefix", ""); |
- addProperty("suffix", ""); |
- } |
} |
function compareFilter(test, text, expected, postInit) |
{ |
addDefaults(expected); |
let filter = Filter.fromText(text); |
if (postInit) |
@@ -211,17 +200,17 @@ |
test.equal(typeof CommentFilter, "function", "typeof CommentFilter"); |
test.equal(typeof ActiveFilter, "function", "typeof ActiveFilter"); |
test.equal(typeof RegExpFilter, "function", "typeof RegExpFilter"); |
test.equal(typeof BlockingFilter, "function", "typeof BlockingFilter"); |
test.equal(typeof WhitelistFilter, "function", "typeof WhitelistFilter"); |
test.equal(typeof ElemHideBase, "function", "typeof ElemHideBase"); |
test.equal(typeof ElemHideFilter, "function", "typeof ElemHideFilter"); |
test.equal(typeof ElemHideException, "function", "typeof ElemHideException"); |
- test.equal(typeof CSSPropertyFilter, "function", "typeof CSSPropertyFilter"); |
+ test.equal(typeof ElemHideEmulationFilter, "function", "typeof ElemHideEmulationFilter"); |
test.done(); |
}; |
exports.testComments = function(test) |
{ |
compareFilter(test, "!asdf", ["type=comment", "text=!asdf"]); |
compareFilter(test, "!foo#bar", ["type=comment", "text=!foo#bar"]); |
@@ -232,26 +221,26 @@ |
exports.testInvalidFilters = function(test) |
{ |
compareFilter(test, "/??/", ["type=invalid", "text=/??/", "reason=filter_invalid_regexp"]); |
compareFilter(test, "asd$foobar", ["type=invalid", "text=asd$foobar", "reason=filter_unknown_option"]); |
compareFilter(test, "#dd(asd)(ddd)", ["type=invalid", "text=#dd(asd)(ddd)", "reason=filter_elemhide_duplicate_id"]); |
compareFilter(test, "#*", ["type=invalid", "text=#*", "reason=filter_elemhide_nocriteria"]); |
- function compareCSSRule(domains) |
+ function checkElemHideEmulationFilterInvalid(domains) |
{ |
let filterText = domains + "##[-abp-properties='abc']"; |
- compareFilter(test, filterText, ["type=invalid", "text=" + filterText, "reason=filter_cssproperty_nodomain"]); |
+ compareFilter(test, filterText, ["type=invalid", "text=" + filterText, "reason=filter_elemhideemulation_nodomain"]); |
} |
- compareCSSRule(""); |
- compareCSSRule("~foo.com"); |
- compareCSSRule("~foo.com,~bar.com"); |
- compareCSSRule("foo"); |
- compareCSSRule("~foo.com,bar"); |
+ checkElemHideEmulationFilterInvalid(""); |
+ checkElemHideEmulationFilterInvalid("~foo.com"); |
+ checkElemHideEmulationFilterInvalid("~foo.com,~bar.com"); |
+ checkElemHideEmulationFilterInvalid("foo"); |
+ checkElemHideEmulationFilterInvalid("~foo.com,bar"); |
test.done(); |
}; |
exports.testFiltersWithState = function(test) |
{ |
compareFilter(test, "blabla", ["type=filterlist", "text=blabla", "regexp=blabla"]); |
compareFilter(test, "blabla_default", ["type=filterlist", "text=blabla_default", "regexp=blabla_default"], function(filter) |
@@ -346,33 +335,28 @@ |
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"]); |
test.done(); |
}; |
-exports.testCSSPropertyFilters = function(test) |
+exports.testElemHideEmulationFilters = function(test) |
{ |
// Check valid domain combinations |
- compareFilter(test, "foo.com##[-abp-properties='abc']", ["type=cssrule", "text=foo.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM", "regexp=abc"]); |
- compareFilter(test, "foo.com,~bar.com##[-abp-properties='abc']", ["type=cssrule", "text=foo.com,~bar.com##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR.COM", "regexp=abc"]); |
- compareFilter(test, "foo.com,~bar##[-abp-properties='abc']", ["type=cssrule", "text=foo.com,~bar##[-abp-properties='abc']", "selectorDomain=foo.com", "selector=[-abp-properties='abc']", "domains=FOO.COM|~BAR", "regexp=abc"]); |
- compareFilter(test, "~foo.com,bar.com##[-abp-properties='abc']", ["type=cssrule", "text=~foo.com,bar.com##[-abp-properties='abc']", "selectorDomain=bar.com", "selector=[-abp-properties='abc']", "domains=BAR.COM|~FOO.COM", "regexp=abc"]); |
+ 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, "##[-abp-properties='']", ["type=elemhide", "text=##[-abp-properties='']", "selector=[-abp-properties='']"]); |
+ compareFilter(test, "##[-abp-properties='']", ["type=invalid", "text=##[-abp-properties='']", "reason=filter_elemhideemulation_nodomain"]); |
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##aaa [-abp-properties='abc'] bbb", ["type=cssrule", "text=foo.com##aaa [-abp-properties='abc'] bbb", "selectorDomain=foo.com", "selector=aaa [-abp-properties='abc'] bbb", "domains=FOO.COM", "prefix=aaa ", "regexp=abc", "suffix= bbb"]); |
- compareFilter(test, "foo.com##[-abp-properties='|background-image: url(data:*)']", ["type=cssrule", "text=foo.com##[-abp-properties='|background-image: url(data:*)']", "selectorDomain=foo.com", "selector=[-abp-properties='|background-image: url(data:*)']", "domains=FOO.COM", "regexp=^background\\-image\\:\\ url\\(data\\:.*\\)"]); |
- |
- // Test regexp property matching |
- compareFilter(test, "foo.com##[-abp-properties='/abc']", ["type=cssrule", "text=foo.com##[-abp-properties='/abc']", "selectorDomain=foo.com", "selector=[-abp-properties='/abc']", "domains=FOO.COM", "regexp=\\/abc"]); |
- compareFilter(test, "foo.com##[-abp-properties='abc/']", ["type=cssrule", "text=foo.com##[-abp-properties='abc/']", "selectorDomain=foo.com", "selector=[-abp-properties='abc/']", "domains=FOO.COM", "regexp=abc\\/"]); |
- compareFilter(test, "foo.com##[-abp-properties='/abc/']", ["type=cssrule", "text=foo.com##[-abp-properties='/abc/']", "selectorDomain=foo.com", "selector=[-abp-properties='/abc/']", "domains=FOO.COM", "regexp=abc"]); |
+ 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"]); |
test.done(); |
}; |
exports.testEmptyElemHideDomains = function(test) |
{ |
let emptyDomainFilters = [ |
",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", |