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

Unified Diff: chrome/content/tests/matcher.js

Issue 6439460933730304: Issue 616 - Add tests for $generichide and $genericblock (Closed)
Patch Set: Rebased onto typeMask changes Created July 14, 2015, 4:45 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
« no previous file with comments | « chrome/content/tests/filterClasses.js ('k') | chrome/content/tests/policy.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/tests/matcher.js
diff --git a/chrome/content/tests/matcher.js b/chrome/content/tests/matcher.js
index 8a1d6c536a79d98d370ea2821212dd2641f60154..4c3cdb6b1b14de12546a1cd6ec394bc1f319c933 100644
--- a/chrome/content/tests/matcher.js
+++ b/chrome/content/tests/matcher.js
@@ -24,17 +24,17 @@
}
}
- function checkMatch(filters, location, contentType, docDomain, thirdParty, sitekey, expected)
+ function checkMatch(filters, location, contentType, docDomain, thirdParty, sitekey, specificOnly, 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);
+ let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, thirdParty, sitekey, specificOnly);
if (result)
result = result.text;
- equal(result, expected, "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ") with:\n" + filters.join("\n"));
+ equal(result, expected, "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n"));
let combinedMatcher = new CombinedMatcher();
for (let i = 0; i < 2; i++)
@@ -42,16 +42,19 @@
for (let filter of filters)
combinedMatcher.add(Filter.fromText(filter));
- let result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, thirdParty, sitekey);
+ let result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, thirdParty, sitekey, specificOnly);
if (result)
result = result.text;
- equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ") with:\n" + filters.join("\n"));
+ equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specificOnly") + ") with:\n" + filters.join("\n"));
- // For next run: add whitelisting filters
- filters = filters.map((text) => "@@" + text);
- if (expected)
- expected = "@@" + expected;
+ // For next run: add whitelisting filters for filters that aren't already
+ if (expected && expected.substr(0, 2) != "@@")
+ {
+ filters = filters.filter((text) => text.substr(0, 2) != "@@").map((text) => "@@" + text);
+ if (expected)
+ expected = "@@" + expected;
+ }
}
}
@@ -96,70 +99,78 @@
test("Filter matching", function()
{
- checkMatch([], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["abc"], "http://abc/def", "IMAGE", null, false, null, "abc");
- checkMatch(["abc", "ddd"], "http://abc/def", "IMAGE", null, false, null, "abc");
- checkMatch(["ddd", "abc"], "http://abc/def", "IMAGE", null, false, null, "abc");
- checkMatch(["ddd", "abd"], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["abc", "://abc/d"], "http://abc/def", "IMAGE", null, false, null, "://abc/d");
- checkMatch(["://abc/d", "abc"], "http://abc/def", "IMAGE", null, false, null, "://abc/d");
- checkMatch(["|http://"], "http://abc/def", "IMAGE", null, false, null, "|http://");
- checkMatch(["|http://abc"], "http://abc/def", "IMAGE", null, false, null, "|http://abc");
- checkMatch(["|abc"], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["|/abc/def"], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["/def|"], "http://abc/def", "IMAGE", null, false, null, "/def|");
- checkMatch(["/abc/def|"], "http://abc/def", "IMAGE", null, false, null, "/abc/def|");
- checkMatch(["/abc/|"], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["http://abc/|"], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["|http://abc/def|"], "http://abc/def", "IMAGE", null, false, null, "|http://abc/def|");
- checkMatch(["|/abc/def|"], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["|http://abc/|"], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["|/abc/|"], "http://abc/def", "IMAGE", null, false, null, null);
- checkMatch(["||example.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, "||example.com/abc");
- checkMatch(["||com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, null, "||com/abc/def");
- checkMatch(["||com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, "||com/abc");
- checkMatch(["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, null);
- checkMatch(["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, null, null);
- checkMatch(["||http://example.com/"], "http://example.com/abc/def", "IMAGE", null, false, null, null);
- checkMatch(["||example.com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, null, "||example.com/abc/def|");
- checkMatch(["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, null, "||com/abc/def|");
- checkMatch(["||example.com/abc|"], "http://example.com/abc/def", "IMAGE", null, false, null, null);
- checkMatch(["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", null, false, null, "://abc/d");
- checkMatch(["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "http://abc/def", "IMAGE", null, false, null, "://abc/de");
- checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, false, null, "abc$~third-party");
- checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, true, null, "abc$third-party");
- checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, false, null, "//abc/def$~third-party");
- checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, true, null, "//abc/def$third-party");
- checkMatch(["abc$third-party", "abc$~third-party", "//abc/def"], "http://abc/def", "IMAGE", null, true, null, "//abc/def");
- checkMatch(["//abc/def", "abc$third-party", "abc$~third-party"], "http://abc/def", "IMAGE", null, true, null, "//abc/def");
- checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, true, null, "//abc/def$third-party");
- checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, false, null, "abc$~third-party");
- checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$~third-party"], "http://abc/def", "IMAGE", null, true, null, "abc$third-party");
- checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "IMAGE", null, false, null, "abc$image");
- checkMatch(["abc$image", "abc$script", "abc$~script"], "http://abc/def", "SCRIPT", null, false, null, "abc$script");
- checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "OTHER", null, false, null, "abc$~image");
- checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "IMAGE", null, false, null, "//abc/def$image");
- checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~script"], "http://abc/def", "SCRIPT", null, false, null, "//abc/def$script");
- checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "OTHER", null, false, null, "//abc/def$~image");
- checkMatch(["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "IMAGE", null, false, null, "//abc/def");
- checkMatch(["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAGE", null, false, null, "//abc/def");
- checkMatch(["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def", "IMAGE", null, false, null, "//abc/def$image");
- checkMatch(["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def", "IMAGE", null, false, null, "abc$image");
- checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, null, "abc$domain=foo.com");
- checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, "abc$domain=bar.com");
- checkMatch(["abc$domain=foo.com", "abc$domain=bar.com", "abc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, "abc$domain=~foo.com|~bar.com");
- checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "foo.com", false, null, "abc$domain=foo.com");
- checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, null);
- checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, null);
- checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://ccc/def", "IMAGE", "baz.com", false, null, "ccc$domain=~foo.com|~bar.com");
- checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "foo.com", false, "foo-publickey", "abc$sitekey=foo-publickey");
- checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", "abc$sitekey=bar-publickey");
- checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", null);
- checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "baz.com", false, null, null);
- checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "foo-publickey", "abc$sitekey=foo-publickey,domain=foo.com");
- checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "bar-publickey", null);
- checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "foo-publickey", null);
- checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", "abc$sitekey=bar-publickey,domain=bar.com");
+ checkMatch([], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["abc"], "http://abc/def", "IMAGE", null, false, null, false, "abc");
+ checkMatch(["abc", "ddd"], "http://abc/def", "IMAGE", null, false, null, false, "abc");
+ checkMatch(["ddd", "abc"], "http://abc/def", "IMAGE", null, false, null, false, "abc");
+ checkMatch(["ddd", "abd"], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["abc", "://abc/d"], "http://abc/def", "IMAGE", null, false, null, false, "://abc/d");
+ checkMatch(["://abc/d", "abc"], "http://abc/def", "IMAGE", null, false, null, false, "://abc/d");
+ checkMatch(["|http://"], "http://abc/def", "IMAGE", null, false, null, false, "|http://");
+ checkMatch(["|http://abc"], "http://abc/def", "IMAGE", null, false, null, false, "|http://abc");
+ checkMatch(["|abc"], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["|/abc/def"], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["/def|"], "http://abc/def", "IMAGE", null, false, null, false, "/def|");
+ checkMatch(["/abc/def|"], "http://abc/def", "IMAGE", null, false, null, false, "/abc/def|");
+ checkMatch(["/abc/|"], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["http://abc/|"], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["|http://abc/def|"], "http://abc/def", "IMAGE", null, false, null, false, "|http://abc/def|");
+ checkMatch(["|/abc/def|"], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["|http://abc/|"], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["|/abc/|"], "http://abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["||example.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||example.com/abc");
+ checkMatch(["||com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||com/abc/def");
+ checkMatch(["||com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||com/abc");
+ checkMatch(["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["||http://example.com/"], "http://example.com/abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["||example.com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||example.com/abc/def|");
+ checkMatch(["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, null, false, "||com/abc/def|");
+ checkMatch(["||example.com/abc|"], "http://example.com/abc/def", "IMAGE", null, false, null, false, null);
+ checkMatch(["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", null, false, null, false, "://abc/d");
+ checkMatch(["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "http://abc/def", "IMAGE", null, false, null, false, "://abc/de");
+ checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, false, null, false, "abc$~third-party");
+ checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, true, null, false, "abc$third-party");
+ checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def$~third-party");
+ checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def$third-party");
+ checkMatch(["abc$third-party", "abc$~third-party", "//abc/def"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def");
+ checkMatch(["//abc/def", "abc$third-party", "abc$~third-party"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def");
+ checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, true, null, false, "//abc/def$third-party");
+ checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, false, null, false, "abc$~third-party");
+ checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$~third-party"], "http://abc/def", "IMAGE", null, true, null, false, "abc$third-party");
+ checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "IMAGE", null, false, null, false, "abc$image");
+ checkMatch(["abc$image", "abc$script", "abc$~script"], "http://abc/def", "SCRIPT", null, false, null, false, "abc$script");
+ checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "OTHER", null, false, null, false, "abc$~image");
+ checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def$image");
+ checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~script"], "http://abc/def", "SCRIPT", null, false, null, false, "//abc/def$script");
+ checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "OTHER", null, false, null, false, "//abc/def$~image");
+ checkMatch(["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def");
+ checkMatch(["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def");
+ checkMatch(["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def", "IMAGE", null, false, null, false, "//abc/def$image");
+ checkMatch(["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def", "IMAGE", null, false, null, false, "abc$image");
+ checkMatch(["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(["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(["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(["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(["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(["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(["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(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "foo.com", false, "foo-publickey", false, "abc$sitekey=foo-publickey");
+ checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, "abc$sitekey=bar-publickey");
+ checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publickey", false, null);
+ checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http://abc/def", "IMAGE", "baz.com", false, null, false, null);
+ checkMatch(["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(["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(["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(["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(["@@kzar.co.uk$generichide"], "http://kzar.co.uk/dave", "GENERICHIDE", "kzar.co.uk", false, null, false, "@@kzar.co.uk$generichide");
+ checkMatch(["@@kzar.co.uk$genericblock"], "http://kzar.co.uk/dave", "GENERICBLOCK", "kzar.co.uk", false, null, false, "@@kzar.co.uk$genericblock");
+ checkMatch(["@@foo.com$generichide"], "http://kzar.co.uk/dave", "GENERICHIDE", "kzar.co.uk", false, null, false, null);
+ checkMatch(["@@foo.com$genericblock"], "http://kzar.co.uk/dave", "GENERICBLOCK", "kzar.co.uk", false, null, false, null);
+ checkMatch(["###dave"], "http://kzar.co.uk/dave", "IMAGE", "kzar.co.uk", false, null, true, null);
+ checkMatch(["kzar.co.uk###dave"], "http://kzar.co.uk/dave", "IMAGE", "kzar.co.uk", false, null, true, null);
+ checkMatch(["/dave$domain=kzar.co.uk"], "http://kzar.co.uk/dave", "IMAGE", "kzar.co.uk", false, null, true, "/dave$domain=kzar.co.uk");
+ checkMatch(["/dave"], "http://kzar.co.uk/dave", "IMAGE", "kzar.co.uk", false, null, true, null);
});
test("Result cache checks", function()
« no previous file with comments | « chrome/content/tests/filterClasses.js ('k') | chrome/content/tests/policy.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld