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

Unified Diff: test/matcher.js

Issue 29998564: Issue 7260 - Internalize third-party request check in matcher (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Feb. 5, 2019, 4:04 a.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
« lib/matcher.js ('K') | « lib/matcher.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/matcher.js
===================================================================
--- a/test/matcher.js
+++ b/test/matcher.js
@@ -53,81 +53,78 @@
matcher.add(dummyFilter);
}
}
test.equal(result.join(", "), expected.join(", "), "Keyword candidates for " + filter.text);
}
}
-function checkMatch(test, filters, location, contentType, docDomain, thirdParty, sitekey, specificOnly, expected, expectedFirstMatch = expected)
+function checkMatch(test, filters, location, contentType, docDomain, sitekey, specificOnly, expected, expectedFirstMatch = expected)
{
let matcher = new Matcher();
for (let filter of filters)
matcher.add(Filter.fromText(filter));
- let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, thirdParty, sitekey, specificOnly);
+ let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, sitekey, specificOnly);
if (result)
result = result.text;
- test.equal(result, expectedFirstMatch, "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n"));
+ test.equal(result, expectedFirstMatch, "match(" + location + ", " + contentType + ", " + docDomain + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n"));
let combinedMatcher = new CombinedMatcher();
for (let i = 0; i < 2; i++)
{
for (let filter of filters)
combinedMatcher.add(Filter.fromText(filter));
- result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, thirdParty, sitekey, specificOnly);
+ result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, sitekey, specificOnly);
if (result)
result = result.text;
- test.equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n"));
+ test.equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n"));
// Generic whitelisting rules can match for specificOnly searches, so we
// can't easily know which rule will match for these whitelisting tests
if (specificOnly)
continue;
// For next run: add whitelisting filters for filters that aren't already
filters = filters.map(text => text.substr(0, 2) == "@@" ? text : "@@" + text);
if (expected && expected.substr(0, 2) != "@@")
expected = "@@" + expected;
}
}
function checkSearch(test, filters, location, contentType, docDomain,
- thirdParty, sitekey, specificOnly, filterType,
- expected)
+ sitekey, specificOnly, filterType, expected)
{
let matcher = new CombinedMatcher();
for (let filter of filters)
matcher.add(Filter.fromText(filter));
let result = matcher.search(location, RegExpFilter.typeMap[contentType],
- docDomain, thirdParty, sitekey, specificOnly,
- filterType);
+ docDomain, sitekey, specificOnly, filterType);
for (let key in result)
result[key] = result[key].map(filter => filter.text);
test.deepEqual(result, expected, "search(" + location + ", " +
contentType + ", " + docDomain + ", " +
- (thirdParty ? "third-party" : "first-party") + ", " +
(sitekey || "no-sitekey") + ", " +
(specificOnly ? "specificOnly" : "not-specificOnly") + ", " +
filterType + ") with:\n" + filters.join("\n"));
}
-function cacheCheck(test, matcher, location, contentType, docDomain, thirdParty, expected)
+function cacheCheck(test, matcher, location, contentType, docDomain, expected)
{
- let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, thirdParty);
+ let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain);
if (result)
result = result.text;
- test.equal(result, expected, "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with static filters");
+ test.equal(result, expected, "match(" + location + ", " + contentType + ", " + docDomain + ") with static filters");
}
exports.testMatcherClassDefinitions = function(test)
{
test.equal(typeof Matcher, "function", "typeof Matcher");
test.equal(typeof CombinedMatcher, "function", "typeof CombinedMatcher");
test.equal(typeof defaultMatcher, "object", "typeof defaultMatcher");
test.ok(defaultMatcher instanceof CombinedMatcher, "defaultMatcher is a CombinedMatcher instance");
@@ -156,134 +153,134 @@
compareKeywords(test, "/123^ad2&ad&", ["123", "ad2"]);
compareKeywords(test, "/123^ad2&ad$script,domain=example.com", ["123", "ad2"]);
test.done();
};
exports.testFilterMatching = function(test)
{
- checkMatch(test, [], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["abc"], "http://abc/def", "IMAGE", null, false, null, false, "abc");
- checkMatch(test, ["abc", "ddd"], "http://abc/def", "IMAGE", null, false, null, false, "abc");
- checkMatch(test, ["ddd", "abc"], "http://abc/def", "IMAGE", null, false, null, false, "abc");
- checkMatch(test, ["ddd", "abd"], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["abc", "://abc/d"], "http://abc/def", "IMAGE", null, false, null, false, "://abc/d");
- checkMatch(test, ["://abc/d", "abc"], "http://abc/def", "IMAGE", null, false, null, false, "://abc/d");
- checkMatch(test, ["|http://"], "http://abc/def", "IMAGE", null, false, null, false, "|http://");
- checkMatch(test, ["|http://abc"], "http://abc/def", "IMAGE", null, false, null, false, "|http://abc");
- checkMatch(test, ["|abc"], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["|/abc/def"], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["/def|"], "http://abc/def", "IMAGE", null, false, null, false, "/def|");
- checkMatch(test, ["/abc/def|"], "http://abc/def", "IMAGE", null, false, null, false, "/abc/def|");
- checkMatch(test, ["/abc/|"], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["http://abc/|"], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["|http://abc/def|"], "http://abc/def", "IMAGE", null, false, null, false, "|http://abc/def|");
- checkMatch(test, ["|/abc/def|"], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["|http://abc/|"], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["|/abc/|"], "http://abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["||example.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||example.com/abc");
- checkMatch(test, ["||com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||com/abc/def");
- checkMatch(test, ["||com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||com/abc");
- checkMatch(test, ["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["||http://example.com/"], "http://example.com/abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["||example.com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||example.com/abc/def|");
- checkMatch(test, ["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||com/abc/def|");
- checkMatch(test, ["||example.com/abc|"], "http://example.com/abc/def", "IMAGE", null, false, null, false, null);
- checkMatch(test, ["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", null, false, null, false, "://abc/d");
- checkMatch(test, ["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "http://abc/def", "IMAGE", null, false, null, false, "://abc/de");
- checkMatch(test, ["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, false, null, false, "abc$~third-party");
- checkMatch(test, ["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, true, null, false, "abc$third-party");
- checkMatch(test, ["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def$~third-party");
- checkMatch(test, ["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def$third-party");
- checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def");
- checkMatch(test, ["//abc/def", "abc$third-party", "abc$~third-party"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def");
- checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def$third-party");
- checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, false, null, false, "abc$~third-party");
- checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$~third-party"], "http://abc/def", "IMAGE", null, true, null, false, "abc$third-party");
- checkMatch(test, ["abc$image", "abc$script", "abc$~image"], "http://abc/def", "IMAGE", null, false, null, false, "abc$image");
- checkMatch(test, ["abc$image", "abc$script", "abc$~script"], "http://abc/def", "SCRIPT", null, false, null, false, "abc$script");
- checkMatch(test, ["abc$image", "abc$script", "abc$~image"], "http://abc/def", "OTHER", null, false, null, false, "abc$~image");
- checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def$image");
- checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~script"], "http://abc/def", "SCRIPT", null, false, null, false, "//abc/def$script");
- checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "OTHER", null, false, null, false, "//abc/def$~image");
- checkMatch(test, ["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def");
- checkMatch(test, ["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def");
- checkMatch(test, ["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def$image");
- checkMatch(test, ["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def", "IMAGE", null, false, null, false, "abc$image");
- checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, null, false, "abc$domain=foo.com");
- checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, false, "abc$domain=bar.com");
- checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, false, "abc$domain=~foo.com|~bar.com");
- checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, null, false, "abc$domain=foo.com");
- checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, false, null);
- checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, false, null);
- checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://ccc/def", "IMAGE", "baz.com", false, null, false, "ccc$domain=~foo.com|~bar.com");
- checkMatch(test, ["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "foo.com", false, "foo-publickey", false, "abc$sitekey=foo-publickey");
- checkMatch(test, ["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, "abc$sitekey=bar-publickey");
- checkMatch(test, ["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, null);
- checkMatch(test, ["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "baz.com", false, null, false, null);
- checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "foo-publickey", false, "abc$sitekey=foo-publickey,domain=foo.com");
- checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "bar-publickey", false, null);
- checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "foo-publickey", false, null);
- checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, "abc$sitekey=bar-publickey,domain=bar.com");
- checkMatch(test, ["@@foo.com$document"], "http://foo.com/bar", "DOCUMENT", "foo.com", false, null, false, "@@foo.com$document");
- checkMatch(test, ["@@foo.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "foo.com", false, null, false, "@@foo.com$elemhide");
- checkMatch(test, ["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "foo.com", false, null, false, "@@foo.com$generichide");
- checkMatch(test, ["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK", "foo.com", false, null, false, "@@foo.com$genericblock");
- checkMatch(test, ["@@bar.com$document"], "http://foo.com/bar", "DOCUMENT", "foo.com", false, null, false, null);
- checkMatch(test, ["@@bar.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "foo.com", false, null, false, null);
- checkMatch(test, ["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "foo.com", false, null, false, null);
- checkMatch(test, ["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK", "foo.com", false, null, false, null);
- checkMatch(test, ["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", false, null, true, null);
- checkMatch(test, ["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo.com", false, null, true, "/bar$domain=foo.com");
- checkMatch(test, ["@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", false, null, false, null, "@@||foo.com^");
- checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", false, null, false, "@@||foo.com^");
- checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/foo", "IMAGE", "foo.com", false, null, false, null, "@@||foo.com^");
- checkMatch(test, ["||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com", false, null, false, "||foo.com^$popup");
- checkMatch(test, ["@@||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com", false, null, false, null, "@@||foo.com^$popup");
- checkMatch(test, ["||foo.com^$popup", "@@||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com", false, null, false, "@@||foo.com^$popup", "||foo.com^$popup");
- checkMatch(test, ["||foo.com^$csp=script-src 'none'"], "http://foo.com/bar", "CSP", "foo.com", false, null, false, "||foo.com^$csp=script-src 'none'");
- checkMatch(test, ["@@||foo.com^$csp"], "http://foo.com/bar", "CSP", "foo.com", false, null, false, null, "@@||foo.com^$csp");
- checkMatch(test, ["||foo.com^$csp=script-src 'none'", "@@||foo.com^$csp"], "http://foo.com/bar", "CSP", "foo.com", false, null, false, "@@||foo.com^$csp", "||foo.com^$csp=script-src 'none'");
+ checkMatch(test, [], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["abc"], "http://abc/def", "IMAGE", "abc", null, false, "abc");
+ checkMatch(test, ["abc", "ddd"], "http://abc/def", "IMAGE", "abc", null, false, "abc");
+ checkMatch(test, ["ddd", "abc"], "http://abc/def", "IMAGE", "abc", null, false, "abc");
+ checkMatch(test, ["ddd", "abd"], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["abc", "://abc/d"], "http://abc/def", "IMAGE", "abc", null, false, "://abc/d");
+ checkMatch(test, ["://abc/d", "abc"], "http://abc/def", "IMAGE", "abc", null, false, "://abc/d");
+ checkMatch(test, ["|http://"], "http://abc/def", "IMAGE", "abc", null, false, "|http://");
+ checkMatch(test, ["|http://abc"], "http://abc/def", "IMAGE", "abc", null, false, "|http://abc");
+ checkMatch(test, ["|abc"], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["|/abc/def"], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["/def|"], "http://abc/def", "IMAGE", "abc", null, false, "/def|");
+ checkMatch(test, ["/abc/def|"], "http://abc/def", "IMAGE", "abc", null, false, "/abc/def|");
+ checkMatch(test, ["/abc/|"], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["http://abc/|"], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["|http://abc/def|"], "http://abc/def", "IMAGE", "abc", null, false, "|http://abc/def|");
+ checkMatch(test, ["|/abc/def|"], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["|http://abc/|"], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["|/abc/|"], "http://abc/def", "IMAGE", "abc", null, false, null);
+ checkMatch(test, ["||example.com/abc"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, "||example.com/abc");
+ checkMatch(test, ["||com/abc/def"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, "||com/abc/def");
+ checkMatch(test, ["||com/abc"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, "||com/abc");
+ checkMatch(test, ["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, null);
+ checkMatch(test, ["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, null);
+ checkMatch(test, ["||http://example.com/"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, null);
+ checkMatch(test, ["||example.com/abc/def|"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, "||example.com/abc/def|");
+ checkMatch(test, ["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, "||com/abc/def|");
+ checkMatch(test, ["||example.com/abc|"], "http://example.com/abc/def", "IMAGE", "example.com", null, false, null);
+ checkMatch(test, ["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", "abc", null, false, "://abc/d");
+ checkMatch(test, ["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "http://abc/def", "IMAGE", "abc", null, false, "://abc/de");
+ checkMatch(test, ["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", "abc", null, false, "abc$~third-party");
+ checkMatch(test, ["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "abc$third-party");
+ checkMatch(test, ["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", "abc", null, false, "//abc/def$~third-party");
+ checkMatch(test, ["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "//abc/def$third-party");
+ checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "//abc/def");
+ checkMatch(test, ["//abc/def", "abc$third-party", "abc$~third-party"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "//abc/def");
+ checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "//abc/def$third-party");
+ checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", "abc", null, false, "abc$~third-party");
+ checkMatch(test, ["abc$third-party", "abc$~third-party", "//abc/def$~third-party"], "http://abc/def", "IMAGE", "third-party-domain", null, false, "abc$third-party");
+ checkMatch(test, ["abc$image", "abc$script", "abc$~image"], "http://abc/def", "IMAGE", "abc", null, false, "abc$image");
+ checkMatch(test, ["abc$image", "abc$script", "abc$~script"], "http://abc/def", "SCRIPT", "abc", null, false, "abc$script");
+ checkMatch(test, ["abc$image", "abc$script", "abc$~image"], "http://abc/def", "OTHER", "abc", null, false, "abc$~image");
+ checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "IMAGE", "abc", null, false, "//abc/def$image");
+ checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~script"], "http://abc/def", "SCRIPT", "abc", null, false, "//abc/def$script");
+ checkMatch(test, ["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "OTHER", "abc", null, false, "//abc/def$~image");
+ checkMatch(test, ["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "IMAGE", "abc", null, false, "//abc/def");
+ checkMatch(test, ["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAGE", "abc", null, false, "//abc/def");
+ checkMatch(test, ["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def", "IMAGE", "abc", null, false, "//abc/def$image");
+ checkMatch(test, ["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def", "IMAGE", "abc", null, false, "abc$image");
+ checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "foo.com", null, false, "abc$domain=foo.com");
+ checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", null, false, "abc$domain=bar.com");
+ checkMatch(test, ["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", null, false, "abc$domain=~foo.com|~bar.com");
+ checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "foo.com", null, false, "abc$domain=foo.com");
+ checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", null, false, null);
+ checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", null, false, null);
+ checkMatch(test, ["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://ccc/def", "IMAGE", "baz.com", null, false, "ccc$domain=~foo.com|~bar.com");
+ checkMatch(test, ["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "foo.com", "foo-publickey", false, "abc$sitekey=foo-publickey");
+ checkMatch(test, ["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "bar.com", "bar-publickey", false, "abc$sitekey=bar-publickey");
+ checkMatch(test, ["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "bar.com", "bar-publickey", false, null);
+ checkMatch(test, ["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "baz.com", null, false, null);
+ checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", "foo-publickey", false, "abc$sitekey=foo-publickey,domain=foo.com");
+ checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", "bar-publickey", false, null);
+ checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", "foo-publickey", false, null);
+ checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", "bar-publickey", false, "abc$sitekey=bar-publickey,domain=bar.com");
+ checkMatch(test, ["@@foo.com$document"], "http://foo.com/bar", "DOCUMENT", "foo.com", null, false, "@@foo.com$document");
+ checkMatch(test, ["@@foo.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "foo.com", null, false, "@@foo.com$elemhide");
+ checkMatch(test, ["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "foo.com", null, false, "@@foo.com$generichide");
+ checkMatch(test, ["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK", "foo.com", null, false, "@@foo.com$genericblock");
+ checkMatch(test, ["@@bar.com$document"], "http://foo.com/bar", "DOCUMENT", "foo.com", null, false, null);
+ checkMatch(test, ["@@bar.com$elemhide"], "http://foo.com/bar", "ELEMHIDE", "foo.com", null, false, null);
+ checkMatch(test, ["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE", "foo.com", null, false, null);
+ checkMatch(test, ["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLOCK", "foo.com", null, false, null);
+ checkMatch(test, ["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", null, true, null);
+ checkMatch(test, ["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo.com", null, true, "/bar$domain=foo.com");
+ checkMatch(test, ["@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", null, false, null, "@@||foo.com^");
+ checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", null, false, "@@||foo.com^");
+ checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/foo", "IMAGE", "foo.com", null, false, null, "@@||foo.com^");
+ checkMatch(test, ["||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com", null, false, "||foo.com^$popup");
+ checkMatch(test, ["@@||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com", null, false, null, "@@||foo.com^$popup");
+ checkMatch(test, ["||foo.com^$popup", "@@||foo.com^$popup"], "http://foo.com/bar", "POPUP", "foo.com", null, false, "@@||foo.com^$popup", "||foo.com^$popup");
+ checkMatch(test, ["||foo.com^$csp=script-src 'none'"], "http://foo.com/bar", "CSP", "foo.com", null, false, "||foo.com^$csp=script-src 'none'");
+ checkMatch(test, ["@@||foo.com^$csp"], "http://foo.com/bar", "CSP", "foo.com", null, false, null, "@@||foo.com^$csp");
+ checkMatch(test, ["||foo.com^$csp=script-src 'none'", "@@||foo.com^$csp"], "http://foo.com/bar", "CSP", "foo.com", null, false, "@@||foo.com^$csp", "||foo.com^$csp=script-src 'none'");
test.done();
};
exports.testFilterSearch = function(test)
{
// Start with three filters: foo, bar, and @@foo
let filters = ["foo", "bar", "@@foo"];
checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com",
- false, null, false, "all",
+ null, false, "all",
{blocking: ["foo"], whitelist: ["@@foo"]});
// Blocking only.
checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com",
- false, null, false, "blocking", {blocking: ["foo"]});
+ null, false, "blocking", {blocking: ["foo"]});
// Whitelist only.
checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com",
- false, null, false, "whitelist", {whitelist: ["@@foo"]});
+ null, false, "whitelist", {whitelist: ["@@foo"]});
// Different URLs.
checkSearch(test, filters, "http://example.com/bar", "IMAGE", "example.com",
- false, null, false, "all", {blocking: ["bar"], whitelist: []});
+ null, false, "all", {blocking: ["bar"], whitelist: []});
checkSearch(test, filters, "http://example.com/foo/bar", "IMAGE",
- "example.com", false, null, false, "all",
+ "example.com", null, false, "all",
{blocking: ["foo", "bar"], whitelist: ["@@foo"]});
// Non-matching content type.
checkSearch(test, filters, "http://example.com/foo", "CSP", "example.com",
- false, null, false, "all", {blocking: [], whitelist: []});
+ null, false, "all", {blocking: [], whitelist: []});
// Non-matching specificity.
checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com",
- false, null, true, "all", {blocking: [], whitelist: ["@@foo"]});
+ null, true, "all", {blocking: [], whitelist: ["@@foo"]});
test.done();
};
exports.testResultCacheChecks = function(test)
{
let matcher = new CombinedMatcher();
matcher.add(Filter.fromText("abc$image"));
@@ -292,32 +289,32 @@
matcher.add(Filter.fromText("cba$third-party"));
matcher.add(Filter.fromText("cba$~third-party,~script"));
matcher.add(Filter.fromText("http://def$image"));
matcher.add(Filter.fromText("http://def$script"));
matcher.add(Filter.fromText("http://def$~image,~script,~media,~ping"));
matcher.add(Filter.fromText("http://fed$third-party"));
matcher.add(Filter.fromText("http://fed$~third-party,~script"));
- cacheCheck(test, matcher, "http://abc", "IMAGE", null, false, "abc$image");
- cacheCheck(test, matcher, "http://abc", "SCRIPT", null, false, "abc$script");
- cacheCheck(test, matcher, "http://abc", "OTHER", null, false, "abc$~image,~script,~media,~ping");
- cacheCheck(test, matcher, "http://cba", "IMAGE", null, false, "cba$~third-party,~script");
- cacheCheck(test, matcher, "http://cba", "IMAGE", null, true, "cba$third-party");
- cacheCheck(test, matcher, "http://def", "IMAGE", null, false, "http://def$image");
- cacheCheck(test, matcher, "http://def", "SCRIPT", null, false, "http://def$script");
- cacheCheck(test, matcher, "http://def", "OTHER", null, false, "http://def$~image,~script,~media,~ping");
- cacheCheck(test, matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-party,~script");
- cacheCheck(test, matcher, "http://fed", "IMAGE", null, true, "http://fed$third-party");
- cacheCheck(test, matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third-party,~script");
- cacheCheck(test, matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-party");
- cacheCheck(test, matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script");
- cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", null, false, "http://fed$~third-party,~script");
- cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", null, true, "http://fed$third-party");
- cacheCheck(test, matcher, "http://def?http://fed", "SCRIPT", null, false, "http://def$script");
+ cacheCheck(test, matcher, "http://abc", "IMAGE", "abc", "abc$image");
+ cacheCheck(test, matcher, "http://abc", "SCRIPT", "abc", "abc$script");
+ cacheCheck(test, matcher, "http://abc", "OTHER", "abc", "abc$~image,~script,~media,~ping");
+ cacheCheck(test, matcher, "http://cba", "IMAGE", "cba", "cba$~third-party,~script");
+ cacheCheck(test, matcher, "http://cba", "IMAGE", "third-party-domain", "cba$third-party");
+ cacheCheck(test, matcher, "http://def", "IMAGE", "def", "http://def$image");
+ cacheCheck(test, matcher, "http://def", "SCRIPT", "def", "http://def$script");
+ cacheCheck(test, matcher, "http://def", "OTHER", "def", "http://def$~image,~script,~media,~ping");
+ cacheCheck(test, matcher, "http://fed", "IMAGE", "fed", "http://fed$~third-party,~script");
+ cacheCheck(test, matcher, "http://fed", "IMAGE", "third-party-domain", "http://fed$third-party");
+ cacheCheck(test, matcher, "http://abc_cba", "MEDIA", "abc_cba", "cba$~third-party,~script");
+ cacheCheck(test, matcher, "http://abc_cba", "MEDIA", "third-party-domain", "cba$third-party");
+ cacheCheck(test, matcher, "http://abc_cba", "SCRIPT", "abc_cba", "abc$script");
+ cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", "def", "http://fed$~third-party,~script");
+ cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", "third-party-domain", "http://fed$third-party");
+ cacheCheck(test, matcher, "http://def?http://fed", "SCRIPT", "def", "http://def$script");
test.done();
};
exports.testWhitelisted = function(test)
{
let matcher = new CombinedMatcher();
« lib/matcher.js ('K') | « lib/matcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld