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

Unified Diff: test/matcher.js

Issue 30001564: Issue 7267 - Optimize memory layout of filter domain maps in matcher (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Add tests Created Feb. 8, 2019, 5:20 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
« 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
@@ -348,25 +348,96 @@
test.done();
};
exports.testAddRemoveByKeyword = function(test)
{
let matcher = new CombinedMatcher();
- matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg"));
+ matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg^"));
// Add the same filter a second time to make sure it doesn't get added again
// by a different keyword.
- matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg"));
+ matcher.add(Filter.fromText("||example.com/foo/bar/image.jpg^"));
test.ok(!!matcher.matchesAny("https://example.com/foo/bar/image.jpg",
RegExpFilter.typeMap.IMAGE));
- matcher.remove(Filter.fromText("||example.com/foo/bar/image.jpg"));
+ matcher.remove(Filter.fromText("||example.com/foo/bar/image.jpg^"));
// Make sure the filter got removed so there is no match.
test.ok(!matcher.matchesAny("https://example.com/foo/bar/image.jpg",
RegExpFilter.typeMap.IMAGE));
+
+ // Map { "example" => { text: "||example.com^$~third-party" } }
+ matcher.add(Filter.fromText("||example.com^$~third-party"));
+
+ test.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1);
+
+ for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword)
+ {
+ test.equal(key, "example");
+ test.deepEqual(value, Filter.fromText("||example.com^$~third-party"));
+ break;
+ }
+
+ test.ok(!!matcher.matchesAny("https://example.com/example/image.jpg",
+ RegExpFilter.typeMap.IMAGE, "example.com",
+ false));
+
+ // Map {
+ // "example" => Map {
+ // "" => Map {
+ // { text: "||example.com^$~third-party" } => true,
+ // { text: "/example/*$~third-party" } => true
+ // }
+ // }
+ // }
+ matcher.add(Filter.fromText("/example/*$~third-party"));
+
+ test.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1);
+
+ for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword)
+ {
+ test.equal(key, "example");
+ test.equal(value.size, 1);
+
+ let map = value.get("");
+ test.equal(map.size, 2);
+ test.equal(map.get(Filter.fromText("||example.com^$~third-party")), true);
+ test.equal(map.get(Filter.fromText("/example/*$~third-party")), true);
+
+ break;
+ }
+
+ test.ok(!!matcher.matchesAny("https://example.com/example/image.jpg",
+ RegExpFilter.typeMap.IMAGE, "example.com",
+ false));
+
+ // Map { "example" => { text: "/example/*$~third-party" } }
+ matcher.remove(Filter.fromText("||example.com^$~third-party"));
+
+ test.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 1);
+
+ for (let [key, value] of matcher._blacklist._filterDomainMapsByKeyword)
+ {
+ test.equal(key, "example");
+ test.deepEqual(value, Filter.fromText("/example/*$~third-party"));
+ break;
+ }
+
+ test.ok(!!matcher.matchesAny("https://example.com/example/image.jpg",
+ RegExpFilter.typeMap.IMAGE, "example.com",
+ false));
+
+ // Map {}
+ matcher.remove(Filter.fromText("/example/*$~third-party"));
+
+ test.equal(matcher._blacklist._filterDomainMapsByKeyword.size, 0);
+
+ test.ok(!matcher.matchesAny("https://example.com/example/image.jpg",
+ RegExpFilter.typeMap.IMAGE, "example.com",
+ false));
+
test.done();
};
« 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