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

Unified Diff: test/matcher.js

Issue 29990555: Issue 7179 - Add function to return all matching filters (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add JSDoc for collection parameter Created Jan. 28, 2019, 5:34 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 | « 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
@@ -89,16 +89,38 @@
// 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)
+{
+ 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);
+ 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)
{
let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], docDomain, thirdParty);
if (result)
result = result.text;
test.equal(result, expected, "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ") with static filters");
}
@@ -221,16 +243,51 @@
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'");
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",
+ {blocking: ["foo"], whitelist: ["@@foo"]});
+
+ // Blocking only.
+ checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com",
+ false, null, false, "blocking", {blocking: ["foo"]});
+
+ // Whitelist only.
+ checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com",
+ false, null, false, "whitelist", {whitelist: ["@@foo"]});
+
+ // Different URLs.
+ checkSearch(test, filters, "http://example.com/bar", "IMAGE", "example.com",
+ false, null, false, "all", {blocking: ["bar"], whitelist: []});
+ checkSearch(test, filters, "http://example.com/foo/bar", "IMAGE",
+ "example.com", false, 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: []});
+
+ // Non-matching specificity.
+ checkSearch(test, filters, "http://example.com/foo", "IMAGE", "example.com",
+ false, null, true, "all", {blocking: [], whitelist: ["@@foo"]});
+
+ test.done();
+};
+
exports.testResultCacheChecks = function(test)
{
let matcher = new CombinedMatcher();
matcher.add(Filter.fromText("abc$image"));
matcher.add(Filter.fromText("abc$script"));
matcher.add(Filter.fromText("abc$~image,~script,~media,~ping"));
matcher.add(Filter.fromText("cba$third-party"));
matcher.add(Filter.fromText("cba$~third-party,~script"));
« no previous file with comments | « lib/matcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld