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") |
); |
t = RegExpFilter.typeMap; |
defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP | |
t.GENERICHIDE | t.GENERICBLOCK); |
callback(); |
}; |
@@ -99,22 +99,20 @@ |
} |
} |
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) |
+ else if (filter instanceof ElemHideEmulationFilter) |
{ |
- result.push("type=cssrule"); |
- result.push("prefix=" + (filter.selectorPrefix || "")); |
- result.push("regexp=" + filter.regexpString); |
- result.push("suffix=" + (filter.selectorSuffix || "")); |
+ result.push("type=elemhideemulation"); |
+ result.push("features=" + filter.features); |
} |
result.push("selectorDomain=" + (filter.selectorDomain || "")); |
result.push("selector=" + filter.selector); |
} |
} |
return result; |
} |
@@ -132,17 +130,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,26 +152,24 @@ |
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") |
+ if (type == "elemhideemulation") |
{ |
- addProperty("regexp", ""); |
- addProperty("prefix", ""); |
- addProperty("suffix", ""); |
+ addProperty("features", "0"); |
} |
} |
function compareFilter(test, text, expected, postInit) |
{ |
addDefaults(expected); |
let filter = Filter.fromText(text); |
@@ -211,17 +207,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 +228,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,28 +342,41 @@ |
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) |
{ |
+ let featuresIsPropertySelector = "features=" + |
+ ElemHideEmulationFilter.featureMap.PROPERTY_SELECTOR; |
+ let featuresIsHasPseudoClass = "features=" + |
+ ElemHideEmulationFilter.featureMap.HAS_PSEUDO_CLASS; |
+ let featuresArePropertySelectorAndHasPseudoClass = "features=" + |
+ (ElemHideEmulationFilter.featureMap.PROPERTY_SELECTOR | |
+ ElemHideEmulationFilter.featureMap.HAS_PSEUDO_CLASS); |
+ |
// 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", featuresIsPropertySelector]); |
+ 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", featuresIsPropertySelector]); |
+ 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", featuresIsPropertySelector]); |
+ 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", featuresIsPropertySelector]); |
- 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\\:.*\\)"]); |
+ 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", featuresIsPropertySelector]); |
+ 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", featuresIsPropertySelector]); |
+ |
+ // Test feature detection |
+ 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", featuresIsPropertySelector]); |
+ compareFilter(test, "foo.com##:has(#ddd)", ["type=elemhideemulation", "text=foo.com##:has(#ddd)", "selectorDomain=foo.com", "selector=:has(#ddd)", "domains=FOO.COM", featuresIsHasPseudoClass]); |
+ compareFilter(test, "foo.com##:has([-abp-properties='abc'])", ["type=elemhideemulation", "text=foo.com##:has([-abp-properties='abc'])", "selectorDomain=foo.com", "selector=:has([-abp-properties='abc'])", "domains=FOO.COM", featuresArePropertySelectorAndHasPseudoClass]); |
test.done(); |
}; |
exports.testEmptyElemHideDomains = function(test) |
{ |
let emptyDomainFilters = [ |
",##selector", ",,,##selector", "~,foo.com##selector", "foo.com,##selector", |