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

Delta Between Two Patch Sets: chrome/content/tests/matcher.js

Issue 6612283790721024: Issue 698 - Added tests for $sitekey option (Closed)
Left Patch Set: Created Sept. 2, 2014, 2:03 p.m.
Right Patch Set: Created Dec. 11, 2014, 2:18 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 (function() 1 (function()
2 { 2 {
3 module("Filter matcher", {setup: prepareFilterComponents, teardown: restoreFil terComponents}); 3 module("Filter matcher", {setup: prepareFilterComponents, teardown: restoreFil terComponents});
4
5 let publickeys = {
6 /*
7 -----BEGIN RSA PRIVATE KEY-----
8 MIIBOgIBAAJBANLNgMGCl6kc3QE/73/ESBsuhzCNQWApqWS1nKVWf+RjDTiF80LD
9 2TiTdQhlW9mlWsDDbttsDlEcCmPVz6H3OUMCAwEAAQJBALo/ZSYTqsl4ve7vvTwG
10 gKq7ZihIdV1wEcDwELGoBiESo87zl//7q2q9/7VE3dB3Qp6uZMLtxVvXzF8bh074
11 OuECIQDzzenwgPVMtg6OjMtZBAB95oKaTzd+x/8JienKW4edEQIhAN1Y+vlB/waB
12 miRjGMrsOQDHhUbxyL6NXaPfxYlosYETAiBg0M9qgztl+BH1x7FkqvMrC+OnNXf7
13 L552gj7F7ez/kQIgOBNhyaHxlNlijpNYZZhAvLTPS/DXFYdE0M5RAgW26mcCIDrR
14 fi2xaM2NqJQCmyshtNmDxW2FCrtrQn1n0211WCEe
15 -----END RSA PRIVATE KEY-----
16 */
17 foo: "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANLNgMGCl6kc3QE/73/ESBsuhzCNQWApqWS1nK VWf+RjDTiF80LD2TiTdQhlW9mlWsDDbttsDlEcCmPVz6H3OUMCAwEAAQ",
18 /*
19 -----BEGIN RSA PRIVATE KEY-----
20 MIIBOgIBAAJBALlKJGIBHYU3rIWyGmiwUgK1BUUomSBgLzSngoE7gBc7mqgCsEbj
21 f9EJ5AvQIM1x7MhVsD5djpqHLcjiQlZFXfECAwEAAQJABEK7MXG7HwwXsH9W8h9T
22 03IcK+nyE3eCvmA3tQcMO/x93imcBdNiz7ev09wGIPDN3Kmauf70/QnjebuDSV9A
23 XQIhAN57+YUwDdGccxqZyj+wRuU5pA1rltIDBQByBLRGd6YjAiEA1TPE2PdWrSsp
24 S6VZoRPWIEebfH/ufWZEFfYKDwP9qtsCIEk3JSr2YGXNhXeIiq0g1oPSzzD3af+c
25 rMWzv+aPlgpfAiAvtSLiTg6GN3dJJxn0UmUC2iMv68ypIN4xb9n2XDVCKwIhAJkd
26 evN4qUcg1kCeQ4LZ5F4WUus+4kd2+Y1nnYQbOrE9
27 -----END RSA PRIVATE KEY-----
28 */
29 bar: "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALlKJGIBHYU3rIWyGmiwUgK1BUUomSBgLzSngo E7gBc7mqgCsEbjf9EJ5AvQIM1x7MhVsD5djpqHLcjiQlZFXfECAwEAAQ"
30 };
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
31
32 function beautifyKeys(str)
33 {
34 if (typeof str != "string")
35 return str;
36
37 return str.replace(publickeys.foo, "foo-publickey", "g")
38 .replace(publickeys.bar, "bar-publickey", "g");
39 }
40 4
41 function compareKeywords(text, expected) 5 function compareKeywords(text, expected)
42 { 6 {
43 for (let filter of [Filter.fromText(text), Filter.fromText("@@" + text)]) 7 for (let filter of [Filter.fromText(text), Filter.fromText("@@" + text)])
44 { 8 {
45 let matcher = new Matcher(); 9 let matcher = new Matcher();
46 let result = []; 10 let result = [];
47 for (let dummy of expected) 11 for (let dummy of expected)
48 { 12 {
49 keyword = matcher.findKeyword(filter); 13 keyword = matcher.findKeyword(filter);
(...skipping 13 matching lines...) Expand all
63 function checkMatch(filters, location, contentType, docDomain, thirdParty, sit ekey, expected) 27 function checkMatch(filters, location, contentType, docDomain, thirdParty, sit ekey, expected)
64 { 28 {
65 let matcher = new Matcher(); 29 let matcher = new Matcher();
66 for (let filter of filters) 30 for (let filter of filters)
67 matcher.add(Filter.fromText(filter)); 31 matcher.add(Filter.fromText(filter));
68 32
69 let result = matcher.matchesAny(location, contentType, docDomain, thirdParty , sitekey); 33 let result = matcher.matchesAny(location, contentType, docDomain, thirdParty , sitekey);
70 if (result) 34 if (result)
71 result = result.text; 35 result = result.text;
72 36
73 equal(beautifyKeys(result), beautifyKeys(expected), "match(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "firs t-party") + ", " + (sitekey ? beautifyKeys(sitekey) : "no-sitekey") + ") with:\n " + beautifyKeys(filters.join("\n"))); 37 equal(result, expected, "match(" + location + ", " + contentType + ", " + do cDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ") with:\n" + filters.join("\n"));
74 38
75 let combinedMatcher = new CombinedMatcher(); 39 let combinedMatcher = new CombinedMatcher();
76 for (let i = 0; i < 2; i++) 40 for (let i = 0; i < 2; i++)
77 { 41 {
78 for (let filter of filters) 42 for (let filter of filters)
79 combinedMatcher.add(Filter.fromText(filter)); 43 combinedMatcher.add(Filter.fromText(filter));
80 44
81 let result = combinedMatcher.matchesAny(location, contentType, docDomain, thirdParty, sitekey); 45 let result = combinedMatcher.matchesAny(location, contentType, docDomain, thirdParty, sitekey);
82 if (result) 46 if (result)
83 result = result.text; 47 result = result.text;
84 48
85 equal(beautifyKeys(result), beautifyKeys(expected), "combinedMatch(" + loc ation + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-part y" : "first-party") + ", " + (sitekey ? beautifyKeys(sitekey) : "no-sitekey") + ") with:\n" + beautifyKeys(filters.join("\n"))); 49 equal(result, expected, "combinedMatch(" + location + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey || "no-sitekey") + ") with:\n" + filters.join("\n"));
86 50
87 // For next run: add whitelisting filters 51 // For next run: add whitelisting filters
88 filters = filters.map((text) => "@@" + text); 52 filters = filters.map((text) => "@@" + text);
89 if (expected) 53 if (expected)
90 expected = "@@" + expected; 54 expected = "@@" + expected;
91 } 55 }
92 } 56 }
93 57
94 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp ected) 58 function cacheCheck(matcher, location, contentType, docDomain, thirdParty, exp ected)
95 { 59 {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 checkMatch(["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAG E", null, false, null, "//abc/def"); 145 checkMatch(["//abc/def", "abc$image", "abc$~image"], "http://abc/def", "IMAG E", null, false, null, "//abc/def");
182 checkMatch(["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def", "IMAGE", null, false, null, "//abc/def$image"); 146 checkMatch(["abc$image", "abc$~image", "//abc/def$image"], "http://abc/def", "IMAGE", null, false, null, "//abc/def$image");
183 checkMatch(["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def" , "IMAGE", null, false, null, "abc$image"); 147 checkMatch(["abc$image", "abc$~image", "//abc/def$script"], "http://abc/def" , "IMAGE", null, false, null, "abc$image");
184 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"); 148 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");
185 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"); 149 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");
186 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"); 150 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");
187 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"); 151 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");
188 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, null); 152 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "bar.com", false, null, null);
189 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, null); 153 checkMatch(["abc$domain=foo.com", "cba$domain=bar.com", "ccc$domain=~foo.com |~bar.com"], "http://abc/def", "IMAGE", "baz.com", false, null, null);
190 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"); 154 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");
191 checkMatch(["abc$sitekey=" + publickeys.foo, "abc$sitekey=" + publickeys.bar ], "http://abc/def", "IMAGE", "foo.com", false, publickeys.foo, "abc$sitekey=" + publickeys.foo); 155 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http ://abc/def", "IMAGE", "foo.com", false, "foo-publickey", "abc$sitekey=foo-public key");
192 checkMatch(["abc$sitekey=" + publickeys.foo, "abc$sitekey=" + publickeys.bar ], "http://abc/def", "IMAGE", "bar.com", false, publickeys.bar, "abc$sitekey=" + publickeys.bar); 156 checkMatch(["abc$sitekey=foo-publickey", "abc$sitekey=bar-publickey"], "http ://abc/def", "IMAGE", "bar.com", false, "bar-publickey", "abc$sitekey=bar-public key");
193 checkMatch(["abc$sitekey=" + publickeys.foo, "cba$sitekey=" + publickeys.bar ], "http://abc/def", "IMAGE", "bar.com", false, publickeys.bar, null); 157 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "http ://abc/def", "IMAGE", "bar.com", false, "bar-publickey", null);
194 checkMatch(["abc$sitekey=" + publickeys.foo, "cba$sitekey=" + publickeys.bar ], "http://abc/def", "IMAGE", "baz.com", false, null, null); 158 checkMatch(["abc$sitekey=foo-publickey", "cba$sitekey=bar-publickey"], "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.
159 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub lickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "foo-publi ckey", "abc$sitekey=foo-publickey,domain=foo.com");
160 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub lickey,domain=bar.com"], "http://abc/def", "IMAGE", "foo.com", false, "bar-publi ckey", null);
161 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub lickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "foo-publi ckey", null);
162 checkMatch(["abc$sitekey=foo-publickey,domain=foo.com", "abc$sitekey=bar-pub lickey,domain=bar.com"], "http://abc/def", "IMAGE", "bar.com", false, "bar-publi ckey", "abc$sitekey=bar-publickey,domain=bar.com");
195 }); 163 });
196 164
197 test("Result cache checks", function() 165 test("Result cache checks", function()
198 { 166 {
199 let matcher = new CombinedMatcher(); 167 let matcher = new CombinedMatcher();
200 matcher.add(Filter.fromText("abc$image")); 168 matcher.add(Filter.fromText("abc$image"));
201 matcher.add(Filter.fromText("abc$script")); 169 matcher.add(Filter.fromText("abc$script"));
202 matcher.add(Filter.fromText("abc$~image,~script,~document")); 170 matcher.add(Filter.fromText("abc$~image,~script,~document"));
203 matcher.add(Filter.fromText("cba$third-party")); 171 matcher.add(Filter.fromText("cba$third-party"));
204 matcher.add(Filter.fromText("cba$~third-party,~script")); 172 matcher.add(Filter.fromText("cba$~third-party,~script"));
(...skipping 14 matching lines...) Expand all
219 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p arty,~script"); 187 cacheCheck(matcher, "http://fed", "IMAGE", null, false, "http://fed$~third-p arty,~script");
220 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par ty"); 188 cacheCheck(matcher, "http://fed", "IMAGE", null, true, "http://fed$third-par ty");
221 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, false, "cba$~third-p arty,~script"); 189 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, false, "cba$~third-p arty,~script");
222 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, true, "cba$third-par ty"); 190 cacheCheck(matcher, "http://abc_cba", "DOCUMENT", null, true, "cba$third-par ty");
223 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script"); 191 cacheCheck(matcher, "http://abc_cba", "SCRIPT", null, false, "abc$script");
224 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, false, "http: //fed$~third-party,~script"); 192 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, false, "http: //fed$~third-party,~script");
225 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, true, "http:/ /fed$third-party"); 193 cacheCheck(matcher, "http://def?http://fed", "DOCUMENT", null, true, "http:/ /fed$third-party");
226 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http:// def$script"); 194 cacheCheck(matcher, "http://def?http://fed", "SCRIPT", null, false, "http:// def$script");
227 }); 195 });
228 })(); 196 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld