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

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

Issue 6612283790721024: Issue 698 - Added tests for $sitekey option (Closed)
Patch Set: Created Sept. 2, 2014, 2:03 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
Index: chrome/content/tests/matcher.js
===================================================================
--- a/chrome/content/tests/matcher.js
+++ b/chrome/content/tests/matcher.js
@@ -2,6 +2,42 @@
{
module("Filter matcher", {setup: prepareFilterComponents, teardown: restoreFilterComponents});
+ let publickeys = {
+ /*
+ -----BEGIN RSA PRIVATE KEY-----
+ MIIBOgIBAAJBANLNgMGCl6kc3QE/73/ESBsuhzCNQWApqWS1nKVWf+RjDTiF80LD
+ 2TiTdQhlW9mlWsDDbttsDlEcCmPVz6H3OUMCAwEAAQJBALo/ZSYTqsl4ve7vvTwG
+ gKq7ZihIdV1wEcDwELGoBiESo87zl//7q2q9/7VE3dB3Qp6uZMLtxVvXzF8bh074
+ OuECIQDzzenwgPVMtg6OjMtZBAB95oKaTzd+x/8JienKW4edEQIhAN1Y+vlB/waB
+ miRjGMrsOQDHhUbxyL6NXaPfxYlosYETAiBg0M9qgztl+BH1x7FkqvMrC+OnNXf7
+ L552gj7F7ez/kQIgOBNhyaHxlNlijpNYZZhAvLTPS/DXFYdE0M5RAgW26mcCIDrR
+ fi2xaM2NqJQCmyshtNmDxW2FCrtrQn1n0211WCEe
+ -----END RSA PRIVATE KEY-----
+ */
+ foo: "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLNgMGCl6kc3QE/73/ESBsuhzCNQWApqWS1nKVWf+RjDTiF80LD2TiTdQhlW9mlWsDDbttsDlEcCmPVz6H3OUMCAwEAAQ",
+ /*
+ -----BEGIN RSA PRIVATE KEY-----
+ MIIBOgIBAAJBALlKJGIBHYU3rIWyGmiwUgK1BUUomSBgLzSngoE7gBc7mqgCsEbj
+ f9EJ5AvQIM1x7MhVsD5djpqHLcjiQlZFXfECAwEAAQJABEK7MXG7HwwXsH9W8h9T
+ 03IcK+nyE3eCvmA3tQcMO/x93imcBdNiz7ev09wGIPDN3Kmauf70/QnjebuDSV9A
+ XQIhAN57+YUwDdGccxqZyj+wRuU5pA1rltIDBQByBLRGd6YjAiEA1TPE2PdWrSsp
+ S6VZoRPWIEebfH/ufWZEFfYKDwP9qtsCIEk3JSr2YGXNhXeIiq0g1oPSzzD3af+c
+ rMWzv+aPlgpfAiAvtSLiTg6GN3dJJxn0UmUC2iMv68ypIN4xb9n2XDVCKwIhAJkd
+ evN4qUcg1kCeQ4LZ5F4WUus+4kd2+Y1nnYQbOrE9
+ -----END RSA PRIVATE KEY-----
+ */
+ bar: "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlKJGIBHYU3rIWyGmiwUgK1BUUomSBgLzSngoE7gBc7mqgCsEbjf9EJ5AvQIM1x7MhVsD5djpqHLcjiQlZFXfECAwEAAQ"
+ };
Wladimir Palant 2014/09/10 21:55:06 Given that no signatures are being verified here a
Thomas Greiner 2014/12/11 14:33:55 Done. That was a leftover from my previous approac
+
+ function beautifyKeys(str)
+ {
+ if (typeof str != "string")
+ return str;
+
+ return str.replace(publickeys.foo, "foo-publickey", "g")
+ .replace(publickeys.bar, "bar-publickey", "g");
+ }
+
function compareKeywords(text, expected)
{
for (let filter of [Filter.fromText(text), Filter.fromText("@@" + text)])
@@ -24,17 +60,17 @@
}
}
- function checkMatch(filters, location, contentType, docDomain, thirdParty, expected)
+ function checkMatch(filters, location, contentType, docDomain, thirdParty, sitekey, expected)
{
let matcher = new Matcher();
for (let filter of filters)
matcher.add(Filter.fromText(filter));
- let result = matcher.matchesAny(location, contentType, docDomain, thirdParty);
+ let result = matcher.matchesAny(location, contentType, docDomain, thirdParty, sitekey);
if (result)
result = result.text;
- equal(result, expected, "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with:\n" + filters.join("\n"));
+ equal(beautifyKeys(result), beautifyKeys(expected), "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey ? beautifyKeys(sitekey) : "no-sitekey") + ") with:\n" + beautifyKeys(filters.join("\n")));
let combinedMatcher = new CombinedMatcher();
for (let i = 0; i < 2; i++)
@@ -42,11 +78,11 @@
for (let filter of filters)
combinedMatcher.add(Filter.fromText(filter));
- let result = combinedMatcher.matchesAny(location, contentType, docDomain, thirdParty);
+ let result = combinedMatcher.matchesAny(location, contentType, docDomain, thirdParty, sitekey);
if (result)
result = result.text;
- equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with:\n" + filters.join("\n"));
+ equal(beautifyKeys(result), beautifyKeys(expected), "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey ? beautifyKeys(sitekey) : "no-sitekey") + ") with:\n" + beautifyKeys(filters.join("\n")));
// For next run: add whitelisting filters
filters = filters.map((text) => "@@" + text);
@@ -96,62 +132,66 @@
test("Filter matching", function()
{
- checkMatch([], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["abc"], "http://abc/def", "IMAGE", null, false, "abc");
- checkMatch(["abc", "ddd"], "http://abc/def", "IMAGE", null, false, "abc");
- checkMatch(["ddd", "abc"], "http://abc/def", "IMAGE", null, false, "abc");
- checkMatch(["ddd", "abd"], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["abc", "://abc/d"], "http://abc/def", "IMAGE", null, false, "://abc/d");
- checkMatch(["://abc/d", "abc"], "http://abc/def", "IMAGE", null, false, "://abc/d");
- checkMatch(["|http://"], "http://abc/def", "IMAGE", null, false, "|http://");
- checkMatch(["|http://abc"], "http://abc/def", "IMAGE", null, false, "|http://abc");
- checkMatch(["|abc"], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["|/abc/def"], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["/def|"], "http://abc/def", "IMAGE", null, false, "/def|");
- checkMatch(["/abc/def|"], "http://abc/def", "IMAGE", null, false, "/abc/def|");
- checkMatch(["/abc/|"], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["http://abc/|"], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["|http://abc/def|"], "http://abc/def", "IMAGE", null, false, "|http://abc/def|");
- checkMatch(["|/abc/def|"], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["|http://abc/|"], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["|/abc/|"], "http://abc/def", "IMAGE", null, false, null);
- checkMatch(["||example.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, "||example.com/abc");
- checkMatch(["||com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, "||com/abc/def");
- checkMatch(["||com/abc"], "http://example.com/abc/def", "IMAGE", null, false, "||com/abc");
- checkMatch(["||mple.com/abc"], "http://example.com/abc/def", "IMAGE", null, false, null);
- checkMatch(["||.com/abc/def"], "http://example.com/abc/def", "IMAGE", null, false, null);
- checkMatch(["||http://example.com/"], "http://example.com/abc/def", "IMAGE", null, false, null);
- checkMatch(["||example.com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, "||example.com/abc/def|");
- checkMatch(["||com/abc/def|"], "http://example.com/abc/def", "IMAGE", null, false, "||com/abc/def|");
- checkMatch(["||example.com/abc|"], "http://example.com/abc/def", "IMAGE", null, false, null);
- checkMatch(["abc", "://abc/d", "asdf1234"], "http://abc/def", "IMAGE", null, false, "://abc/d");
- checkMatch(["foo*://abc/d", "foo*//abc/de", "://abc/de", "asdf1234"], "http://abc/def", "IMAGE", null, false, "://abc/de");
- checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, false, "abc$~third-party");
- checkMatch(["abc$third-party", "abc$~third-party", "ddd"], "http://abc/def", "IMAGE", null, true, "abc$third-party");
- checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, false, "//abc/def$~third-party");
- checkMatch(["//abc/def$third-party", "//abc/def$~third-party", "//abc_def"], "http://abc/def", "IMAGE", null, true, "//abc/def$third-party");
- checkMatch(["abc$third-party", "abc$~third-party", "//abc/def"], "http://abc/def", "IMAGE", null, true, "//abc/def");
- checkMatch(["//abc/def", "abc$third-party", "abc$~third-party"], "http://abc/def", "IMAGE", null, true, "//abc/def");
- checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, true, "//abc/def$third-party");
- checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$third-party"], "http://abc/def", "IMAGE", null, false, "abc$~third-party");
- checkMatch(["abc$third-party", "abc$~third-party", "//abc/def$~third-party"], "http://abc/def", "IMAGE", null, true, "abc$third-party");
- checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "IMAGE", null, false, "abc$image");
- checkMatch(["abc$image", "abc$script", "abc$~script"], "http://abc/def", "SCRIPT", null, false, "abc$script");
- checkMatch(["abc$image", "abc$script", "abc$~image"], "http://abc/def", "OTHER", null, false, "abc$~image");
- checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "IMAGE", null, false, "//abc/def$image");
- checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~script"], "http://abc/def", "SCRIPT", null, false, "//abc/def$script");
- checkMatch(["//abc/def$image", "//abc/def$script", "//abc/def$~image"], "http://abc/def", "OTHER", null, false, "//abc/def$~image");
- checkMatch(["abc$image", "abc$~image", "//abc/def"], "http://abc/def", "IMAGE", null, false, "//abc/def");
- checkMatch(["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAGE", null, false, "//abc/def");
- checkMatch(["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def", "IMAGE", null, false, "//abc/def$image");
- checkMatch(["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def", "IMAGE", 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, "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, "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, "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, "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);
- checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null);
- checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com|~bar.com"], "http://ccc/def", "IMAGE", "baz.com", false, "ccc$domain=~foo.com|~bar.com");
+ 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=" + publickeys.foo, "abc$sitekey=" + publickeys.bar], "http://abc/def", "IMAGE", "foo.com", false, publickeys.foo, "abc$sitekey=" + publickeys.foo);
+ checkMatch(["abc$sitekey=" + publickeys.foo, "abc$sitekey=" + publickeys.bar], "http://abc/def", "IMAGE", "bar.com", false, publickeys.bar, "abc$sitekey=" + publickeys.bar);
+ checkMatch(["abc$sitekey=" + publickeys.foo, "cba$sitekey=" + publickeys.bar], "http://abc/def", "IMAGE", "bar.com", false, publickeys.bar, null);
+ checkMatch(["abc$sitekey=" + publickeys.foo, "cba$sitekey=" + publickeys.bar], "http://abc/def", "IMAGE", "baz.com", false, null, null);
Wladimir Palant 2014/09/10 21:55:06 Please test the scenarios where the filter combine
Thomas Greiner 2014/12/11 14:33:55 Done.
});
test("Result cache checks", function()

Powered by Google App Engine
This is Rietveld