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

Side by Side Diff: test/matcher.js

Issue 29932584: Issue 7003 - Add tests for new filter matching behavior (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Created Nov. 1, 2018, 12:58 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH 3 * Copyright (C) 2006-present eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 let dummyFilter = Filter.fromText("^" + keyword + "^"); 51 let dummyFilter = Filter.fromText("^" + keyword + "^");
52 dummyFilter.filterCount = Infinity; 52 dummyFilter.filterCount = Infinity;
53 matcher.add(dummyFilter); 53 matcher.add(dummyFilter);
54 } 54 }
55 } 55 }
56 56
57 test.equal(result.join(", "), expected.join(", "), "Keyword candidates for " + filter.text); 57 test.equal(result.join(", "), expected.join(", "), "Keyword candidates for " + filter.text);
58 } 58 }
59 } 59 }
60 60
61 function checkMatch(test, filters, location, contentType, docDomain, thirdParty, sitekey, specificOnly, expected) 61 function checkMatch(test, filters, location, contentType, docDomain, thirdParty, sitekey, specificOnly, expected, expectedFirstMatch = expected)
Manish Jethani 2018/11/01 01:00:34 A standalone matcher will always return the first
62 { 62 {
63 let matcher = new Matcher(); 63 let matcher = new Matcher();
64 for (let filter of filters) 64 for (let filter of filters)
65 matcher.add(Filter.fromText(filter)); 65 matcher.add(Filter.fromText(filter));
66 66
67 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], d ocDomain, thirdParty, sitekey, specificOnly); 67 let result = matcher.matchesAny(location, RegExpFilter.typeMap[contentType], d ocDomain, thirdParty, sitekey, specificOnly);
68 if (result) 68 if (result)
69 result = result.text; 69 result = result.text;
70 70
71 test.equal(result, expected, "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitek ey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-specificOnly" ) + ") with:\n" + filters.join("\n")); 71 test.equal(result, expectedFirstMatch, "match(" + location + ", " + contentTyp e + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ", " + (specificOnly ? "specificOnly" : "not-spe cificOnly") + ") with:\n" + filters.join("\n"));
72 72
73 let combinedMatcher = new CombinedMatcher(); 73 let combinedMatcher = new CombinedMatcher();
74 for (let i = 0; i < 2; i++) 74 for (let i = 0; i < 2; i++)
75 { 75 {
76 for (let filter of filters) 76 for (let filter of filters)
77 combinedMatcher.add(Filter.fromText(filter)); 77 combinedMatcher.add(Filter.fromText(filter));
78 78
79 result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[contentTy pe], docDomain, thirdParty, sitekey, specificOnly); 79 result = combinedMatcher.matchesAny(location, RegExpFilter.typeMap[contentTy pe], docDomain, thirdParty, sitekey, specificOnly);
80 if (result) 80 if (result)
81 result = result.text; 81 result = result.text;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar -publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "foo-p ublickey", false, "abc$sitekey=foo-publickey,domain=foo.com"); 202 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar -publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "foo-p ublickey", false, "abc$sitekey=foo-publickey,domain=foo.com");
203 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar -publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "bar-p ublickey", false, null); 203 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar -publickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "bar-p ublickey", false, null);
204 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar -publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "foo-p ublickey", false, null); 204 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar -publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "foo-p ublickey", false, null);
205 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar -publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "bar-p ublickey", false, "abc$sitekey=bar-publickey,domain=bar.com"); 205 checkMatch(test, ["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar -publickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "bar-p ublickey", false, "abc$sitekey=bar-publickey,domain=bar.com");
206 checkMatch(test, ["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE ", "foo.com", false, null, false, "@@foo.com$generichide"); 206 checkMatch(test, ["@@foo.com$generichide"], "http://foo.com/bar", "GENERICHIDE ", "foo.com", false, null, false, "@@foo.com$generichide");
207 checkMatch(test, ["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLO CK", "foo.com", false, null, false, "@@foo.com$genericblock"); 207 checkMatch(test, ["@@foo.com$genericblock"], "http://foo.com/bar", "GENERICBLO CK", "foo.com", false, null, false, "@@foo.com$genericblock");
208 checkMatch(test, ["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE ", "foo.com", false, null, false, null); 208 checkMatch(test, ["@@bar.com$generichide"], "http://foo.com/bar", "GENERICHIDE ", "foo.com", false, null, false, null);
209 checkMatch(test, ["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLO CK", "foo.com", false, null, false, null); 209 checkMatch(test, ["@@bar.com$genericblock"], "http://foo.com/bar", "GENERICBLO CK", "foo.com", false, null, false, null);
210 checkMatch(test, ["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", false, nu ll, true, null); 210 checkMatch(test, ["/bar"], "http://foo.com/bar", "IMAGE", "foo.com", false, nu ll, true, null);
211 checkMatch(test, ["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo. com", false, null, true, "/bar$domain=foo.com"); 211 checkMatch(test, ["/bar$domain=foo.com"], "http://foo.com/bar", "IMAGE", "foo. com", false, null, true, "/bar$domain=foo.com");
212 checkMatch(test, ["@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo.com", f alse, null, false, null, "@@||foo.com^");
Manish Jethani 2018/11/01 01:00:34 Here "expectedFirstMatch" is the whitelist filter
213 checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/bar", "IMAGE", "foo .com", false, null, false, "@@||foo.com^");
214 checkMatch(test, ["/bar", "@@||foo.com^"], "http://foo.com/foo", "IMAGE", "foo .com", false, null, false, null, "@@||foo.com^");
212 215
213 test.done(); 216 test.done();
214 }; 217 };
215 218
216 exports.testResultCacheChecks = function(test) 219 exports.testResultCacheChecks = function(test)
217 { 220 {
218 let matcher = new CombinedMatcher(); 221 let matcher = new CombinedMatcher();
219 matcher.add(Filter.fromText("abc$image")); 222 matcher.add(Filter.fromText("abc$image"));
220 matcher.add(Filter.fromText("abc$script")); 223 matcher.add(Filter.fromText("abc$script"));
221 matcher.add(Filter.fromText("abc$~image,~script,~media,~ping")); 224 matcher.add(Filter.fromText("abc$~image,~script,~media,~ping"));
(...skipping 17 matching lines...) Expand all
239 cacheCheck(test, matcher, "http://fed", "IMAGE", null, true, "http://fed$third -party"); 242 cacheCheck(test, matcher, "http://fed", "IMAGE", null, true, "http://fed$third -party");
240 cacheCheck(test, matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third- party,~script"); 243 cacheCheck(test, matcher, "http://abc_cba", "MEDIA", null, false, "cba$~third- party,~script");
241 cacheCheck(test, matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-pa rty"); 244 cacheCheck(test, matcher, "http://abc_cba", "MEDIA", null, true, "cba$third-pa rty");
242 cacheCheck(test, matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script "); 245 cacheCheck(test, matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script ");
243 cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", null, false, "http ://fed$~third-party,~script"); 246 cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", null, false, "http ://fed$~third-party,~script");
244 cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", null, true, "http: //fed$third-party"); 247 cacheCheck(test, matcher, "http://def?http://fed", "MEDIA", null, true, "http: //fed$third-party");
245 cacheCheck(test, matcher, "http://def?http://fed", "SCRIPT", null, false, "htt p://def$script"); 248 cacheCheck(test, matcher, "http://def?http://fed", "SCRIPT", null, false, "htt p://def$script");
246 249
247 test.done(); 250 test.done();
248 }; 251 };
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld