Index: test/filterClasses.js |
diff --git a/test/filterClasses.js b/test/filterClasses.js |
index a3726337fc282b3f6abdc87ddcd23d025a4fc988..4c76d4631724ea74c6869daddf1e76063f7c7f14 100644 |
--- a/test/filterClasses.js |
+++ b/test/filterClasses.js |
@@ -44,7 +44,7 @@ exports.setUp = function(callback) |
ElemHideEmulationFilter} = sandboxedRequire("../lib/filterClasses") |
); |
t = RegExpFilter.typeMap; |
- defaultTypes = 0x7FFFFFFF & ~(t.ELEMHIDE | t.DOCUMENT | t.POPUP | |
+ defaultTypes = 0x7FFFFFFF & ~(t.CSP | t.ELEMHIDE | t.DOCUMENT | t.POPUP | |
t.GENERICHIDE | t.GENERICBLOCK); |
callback(); |
@@ -93,6 +93,7 @@ function serializeFilter(filter) |
{ |
result.push("type=filterlist"); |
result.push("collapse=" + filter.collapse); |
+ result.push("csp=" + filter.csp); |
} |
else if (filter instanceof WhitelistFilter) |
result.push("type=whitelist"); |
@@ -141,9 +142,7 @@ function addDefaults(expected) |
if (type == "whitelist" || type == "filterlist") |
{ |
addProperty("contentType", 0x7FFFFFFF & ~( |
- RegExpFilter.typeMap.DOCUMENT | RegExpFilter.typeMap.ELEMHIDE | |
- RegExpFilter.typeMap.POPUP | RegExpFilter.typeMap.GENERICHIDE | |
- RegExpFilter.typeMap.GENERICBLOCK |
+ t.CSP | t.DOCUMENT | t.ELEMHIDE | t.POPUP | t.GENERICHIDE | t.GENERICBLOCK |
)); |
addProperty("matchCase", "false"); |
addProperty("thirdParty", "null"); |
@@ -151,7 +150,10 @@ function addDefaults(expected) |
addProperty("sitekeys", ""); |
} |
if (type == "filterlist") |
+ { |
addProperty("collapse", "null"); |
+ addProperty("csp", "null"); |
+ } |
if (type == "elemhide" || type == "elemhideexception" || |
type == "elemhideemulation") |
{ |
@@ -284,8 +286,9 @@ exports.testSpecialCharacters = function(test) |
exports.testFilterOptions = function(test) |
{ |
- compareFilter(test, "bla$match-case,script,other,third-party,domain=foo.com,sitekey=foo", ["type=filterlist", "text=bla$match-case,script,other,third-party,domain=foo.com,sitekey=foo", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdParty=true", "domains=FOO.COM", "sitekeys=FOO"]); |
- compareFilter(test, "bla$~match-case,~script,~other,~third-party,domain=~bar.com", ["type=filterlist", "text=bla$~match-case,~script,~other,~third-party,domain=~bar.com", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER)), "thirdParty=false", "domains=~BAR.COM"]); |
+ compareFilter(test, "bla$match-case,csp=first csp,script,other,third-party,domain=foo.com,sitekey=foo,csp=second csp", ["type=filterlist", "text=bla$match-case,csp=first csp,script,other,third-party,domain=foo.com,sitekey=foo,csp=second csp", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=FOO.COM", "sitekeys=FOO", "csp=first csp; second csp"]); |
+ compareFilter(test, "bla$~match-case,~csp=csp,~script,~other,~third-party,domain=~bar.com", ["type=filterlist", "text=bla$~match-case,~csp=csp,~script,~other,~third-party,domain=~bar.com", "regexp=bla", "contentType=" + (defaultTypes & ~(t.SCRIPT | t.OTHER)), "thirdParty=false", "domains=~BAR.COM"]); |
+ compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo.bar.com,csp=c s p,sitekey=foo|bar", ["type=whitelist", "text=@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo.bar.com,csp=c s p,sitekey=foo|bar", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER | t.CSP), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM", "sitekeys=BAR|FOO"]); |
compareFilter(test, "@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo.bar.com,sitekey=foo|bar", ["type=whitelist", "text=@@bla$match-case,script,other,third-party,domain=foo.com|bar.com|~bar.foo.com|~foo.bar.com,sitekey=foo|bar", "regexp=bla", "matchCase=true", "contentType=" + (t.SCRIPT | t.OTHER), "thirdParty=true", "domains=BAR.COM|FOO.COM|~BAR.FOO.COM|~FOO.BAR.COM", "sitekeys=BAR|FOO"]); |
// background and image should be the same for backwards compatibility |
@@ -311,6 +314,9 @@ exports.testFilterOptions = function(test) |
compareFilter(test, "@@bla$image,foobar", ["type=invalid", "text=@@bla$image,foobar", "reason=filter_unknown_option"]); |
compareFilter(test, "@@bla$foobar,image", ["type=invalid", "text=@@bla$foobar,image", "reason=filter_unknown_option"]); |
+ compareFilter(test, "bla$csp=report-uri", ["type=invalid", "text=bla$csp=report-uri", "reason=filter_invalid_csp"]); |
+ compareFilter(test, "bla$csp=foo,csp=report-uri", ["type=invalid", "text=bla$csp=foo,csp=report-uri", "reason=filter_invalid_csp"]); |
+ |
test.done(); |
}; |
@@ -406,3 +412,40 @@ exports.testElemHideRulesWithBraces = function(test) |
); |
test.done(); |
}; |
+ |
+exports.testFilterNormalization = function(test) |
+{ |
+ // Line breaks etc |
+ test.equal(Filter.normalize("\n\t\nad\ns"), |
+ "ads"); |
+ |
+ // Comment filters |
+ test.equal(Filter.normalize(" ! fo o## bar "), |
+ "! fo o## bar"); |
+ |
+ // Element hiding filters |
+ test.equal(Filter.normalize(" domain.c om## # sele ctor "), |
+ "domain.com### sele ctor"); |
+ |
+ // Regular filters |
+ let normalized = Filter.normalize( |
+ " bl a$sitekey= foo ,domain= do main.com |foo .com,csp= c s p " |
+ ); |
+ test.equal( |
+ normalized, |
+ "bl a$sitekey= foo ,domain= do main.com |foo .com,csp= c s p" |
+ ); |
+ compareFilter( |
+ test, normalized, [ |
+ "type=filterlist", |
+ "text=" + normalized, |
+ "csp=c s p", |
+ "domains=DOMAIN.COM|FOO.COM", |
+ "sitekeys=FOO", |
+ "regexp=bla", |
+ "contentType=" + t.CSP |
+ ] |
+ ); |
+ |
+ test.done(); |
+}; |