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

Delta Between Two Patch Sets: chrome/content/tests/regexpFilters_matching.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
« no previous file with change/comment | « chrome/content/tests/policy.js ('k') | chrome/content/tests/signatures.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 (function() 1 (function()
2 { 2 {
3 module("Matching of blocking filters", {setup: prepareFilterComponents, teardo wn: restoreFilterComponents}); 3 module("Matching of blocking filters", {setup: prepareFilterComponents, teardo wn: restoreFilterComponents});
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"
Wladimir Palant 2014/09/10 21:55:06 Here as well: given that the keys aren't actually
Thomas Greiner 2014/12/11 14:33:55 Done.
30 };
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 testMatch(text, location, contentType, docDomain, thirdParty, sitekey , expected) 5 function testMatch(text, location, contentType, docDomain, thirdParty, sitekey , expected)
42 { 6 {
43 function testMatch_internal(text, location, contentType, docDomain, thirdPar ty, sitekey, expected) 7 function testMatch_internal(text, location, contentType, docDomain, thirdPar ty, sitekey, expected)
44 { 8 {
45 let filter = Filter.fromText(text); 9 let filter = Filter.fromText(text);
46 let result = filter.matches(location, contentType, docDomain, thirdParty, sitekey); 10 let result = filter.matches(location, contentType, docDomain, thirdParty, sitekey);
47 equal(!!result, expected, '"' + beautifyKeys(text) + '".matches(' + locati on + ", " + contentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party") + ", " + (sitekey ? beautifyKeys(sitekey) : "no-sitekey") + ")" ); 11 equal(!!result, expected, '"' + text + '".matches(' + location + ", " + co ntentType + ", " + docDomain + ", " + (thirdParty ? "third-party" : "first-party ") + ", " + (sitekey || "no-sitekey") + ")");
48 } 12 }
49 testMatch_internal(text, location, contentType, docDomain, thirdParty, sitek ey, expected); 13 testMatch_internal(text, location, contentType, docDomain, thirdParty, sitek ey, expected);
50 if (!/^@@/.test(text)) 14 if (!/^@@/.test(text))
51 testMatch_internal("@@" + text, location, contentType, docDomain, thirdPar ty, sitekey, expected); 15 testMatch_internal("@@" + text, location, contentType, docDomain, thirdPar ty, sitekey, expected);
52 } 16 }
53 17
54 test("Basic filters", function() 18 test("Basic filters", function()
55 { 19 {
56 testMatch("abc", "http://abc/adf", "IMAGE", null, false, null, true); 20 testMatch("abc", "http://abc/adf", "IMAGE", null, false, null, true);
57 testMatch("abc", "http://ABC/adf", "IMAGE", null, false, null, true); 21 testMatch("abc", "http://ABC/adf", "IMAGE", null, false, null, true);
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 testMatch("abc$domain=foo.com,image", "http://abc/def", "OBJECT", "foo.com", true, null, false); 270 testMatch("abc$domain=foo.com,image", "http://abc/def", "OBJECT", "foo.com", true, null, false);
307 testMatch("abc$domain=foo.com,image", "http://abc/def", "OBJECT", "bar.com", true, null, false); 271 testMatch("abc$domain=foo.com,image", "http://abc/def", "OBJECT", "bar.com", true, null, false);
308 testMatch("abc$domain=foo.com,~image", "http://abc/def", "IMAGE", "foo.com", true, null, false); 272 testMatch("abc$domain=foo.com,~image", "http://abc/def", "IMAGE", "foo.com", true, null, false);
309 testMatch("abc$domain=foo.com,~image", "http://abc/def", "IMAGE", "bar.com", true, null, false); 273 testMatch("abc$domain=foo.com,~image", "http://abc/def", "IMAGE", "bar.com", true, null, false);
310 testMatch("abc$domain=foo.com,~image", "http://abc/def", "OBJECT", "foo.com" , true, null, true); 274 testMatch("abc$domain=foo.com,~image", "http://abc/def", "OBJECT", "foo.com" , true, null, true);
311 testMatch("abc$domain=foo.com,~image", "http://abc/def", "OBJECT", "bar.com" , true, null, false); 275 testMatch("abc$domain=foo.com,~image", "http://abc/def", "OBJECT", "bar.com" , true, null, false);
312 }); 276 });
313 277
314 test("Sitekey restrictions", function() 278 test("Sitekey restrictions", function()
315 { 279 {
316 testMatch("abc$sitekey=" + publickeys.foo, "http://abc/def", "IMAGE", "foo.c om", true, publickeys.foo, true); 280 testMatch("abc$sitekey=foo-publickey", "http://abc/def", "IMAGE", "foo.com", true, "foo-publickey", true);
317 testMatch("abc$sitekey=" + publickeys.foo, "http://abc/def", "IMAGE", "foo.c om", true, null, false); 281 testMatch("abc$sitekey=foo-publickey", "http://abc/def", "IMAGE", "foo.com", true, null, false);
Wladimir Palant 2014/09/10 21:55:06 What about the scenario where the sitekey is prese
Thomas Greiner 2014/12/11 14:33:55 Done.
318 testMatch("abc$sitekey=" + publickeys.foo + "|" + publickeys.bar, "http://ab c/def", "IMAGE", "foo.com", true, publickeys.foo, true); 282 testMatch("abc$sitekey=foo-publickey", "http://abc/def", "IMAGE", "foo.com", true, "bar-publickey", false);
319 testMatch("abc$sitekey=" + publickeys.foo + "|" + publickeys.bar, "http://ab c/def", "IMAGE", "foo.com", true, null, false); 283 testMatch("abc$sitekey=foo-publickey|bar-publickey", "http://abc/def", "IMAG E", "foo.com", true, "foo-publickey", true);
320 testMatch("abc$sitekey=" + publickeys.bar + "|" + publickeys.foo, "http://ab c/def", "IMAGE", "foo.com", true, publickeys.foo, true); 284 testMatch("abc$sitekey=foo-publickey|bar-publickey", "http://abc/def", "IMAG E", "foo.com", true, null, false);
321 testMatch("abc$sitekey=" + publickeys.foo, "http://ccc/def", "IMAGE", "foo.c om", true, publickeys.foo, false); 285 testMatch("abc$sitekey=bar-publickey|foo-publickey", "http://abc/def", "IMAG E", "foo.com", true, "foo-publickey", true);
322 testMatch("abc$image,sitekey=" + publickeys.foo, "http://abc/def", "IMAGE", "foo.com", true, publickeys.foo, true); 286 testMatch("abc$sitekey=foo-publickey", "http://ccc/def", "IMAGE", "foo.com", true, "foo-publickey", false);
323 testMatch("abc$image,sitekey=" + publickeys.foo, "http://abc/def", "OBJECT", "foo.com", true, publickeys.foo, false); 287 testMatch("abc$domain=foo.com,sitekey=foo-publickey", "http://abc/def", "IMA GE", "foo.com", true, "foo-publickey", true);
324 testMatch("abc$~image,sitekey=" + publickeys.foo, "http://abc/def", "IMAGE", "foo.com", true, publickeys.foo, false); 288 testMatch("abc$domain=foo.com,sitekey=foo-publickey", "http://abc/def", "IMA GE", "bar.com", true, "foo-publickey", false);
325 testMatch("abc$~image,sitekey=" + publickeys.foo, "http://abc/def", "OBJECT" , "foo.com", true, publickeys.foo, true); 289 testMatch("abc$domain=~foo.com,sitekey=foo-publickey", "http://abc/def", "IM AGE", "foo.com", true, "foo-publickey", false);
326 testMatch("abc$sitekey=" + publickeys.foo + ",image", "http://abc/def", "IMA GE", "foo.com", true, publickeys.foo, true); 290 testMatch("abc$domain=~foo.com,sitekey=foo-publickey", "http://abc/def", "IM AGE", "bar.com", true, "foo-publickey", true);
327 testMatch("abc$sitekey=" + publickeys.foo + ",image", "http://abc/def", "OBJ ECT", "foo.com", true, publickeys.foo, false); 291 testMatch("abc$domain=bar.com,sitekey=foo-publickey", "http://abc/def", "IMA GE", "foo.com", true, "foo-publickey", false);
328 testMatch("abc$sitekey=" + publickeys.foo + ",~image", "http://abc/def", "IM AGE", "foo.com", true, publickeys.foo, false); 292 testMatch("abc$domain=bar.com,sitekey=foo-publickey", "http://abc/def", "IMA GE", "bar.com", true, "foo-publickey", true);
Wladimir Palant 2014/12/11 15:57:47 Nit: the last two tests are redundant, they test t
329 testMatch("abc$sitekey=" + publickeys.foo + ",~image", "http://abc/def", "OB JECT", "foo.com", true, publickeys.foo, true);
Wladimir Palant 2014/09/10 21:55:06 This should test how the sitekeys get along with d
Thomas Greiner 2014/12/11 14:33:55 Done. Let me know if it makes sense to also includ
330 }); 293 });
331 294
332 test("Exception rules", function() 295 test("Exception rules", function()
333 { 296 {
334 testMatch("@@test", "http://test/", "DOCUMENT", null, false, null, false); 297 testMatch("@@test", "http://test/", "DOCUMENT", null, false, null, false);
335 testMatch("@@http://test*", "http://test/", "DOCUMENT", null, false, null, t rue); 298 testMatch("@@http://test*", "http://test/", "DOCUMENT", null, false, null, t rue);
336 testMatch("@@ftp://test*", "ftp://test/", "DOCUMENT", null, false, null, tru e); 299 testMatch("@@ftp://test*", "ftp://test/", "DOCUMENT", null, false, null, tru e);
337 testMatch("@@test$document", "http://test/", "DOCUMENT", null, false, null, true); 300 testMatch("@@test$document", "http://test/", "DOCUMENT", null, false, null, true);
338 testMatch("@@test$document,image", "http://test/", "DOCUMENT", null, false, null, true); 301 testMatch("@@test$document,image", "http://test/", "DOCUMENT", null, false, null, true);
339 testMatch("@@test$~image", "http://test/", "DOCUMENT", null, false, null, fa lse); 302 testMatch("@@test$~image", "http://test/", "DOCUMENT", null, false, null, fa lse);
340 testMatch("@@test$~image,document", "http://test/", "DOCUMENT", null, false, null, true); 303 testMatch("@@test$~image,document", "http://test/", "DOCUMENT", null, false, null, true);
341 testMatch("@@test$document,~image", "http://test/", "DOCUMENT", null, false, null, true); 304 testMatch("@@test$document,~image", "http://test/", "DOCUMENT", null, false, null, true);
342 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "foo .com", false, null, true); 305 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "foo .com", false, null, true);
343 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "bar .com", false, null, false); 306 testMatch("@@test$document,domain=foo.com", "http://test/", "DOCUMENT", "bar .com", false, null, false);
344 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "fo o.com", false, null, false); 307 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "fo o.com", false, null, false);
345 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "ba r.com", false, null, true); 308 testMatch("@@test$document,domain=~foo.com", "http://test/", "DOCUMENT", "ba r.com", false, null, true);
346 testMatch("@@test$document,sitekey=" + publickeys.foo, "http://test/", "DOCU MENT", "foo.com", false, publickeys.foo, true); 309 testMatch("@@test$document,sitekey=foo-publickey", "http://test/", "DOCUMENT ", "foo.com", false, "foo-publickey", true);
347 testMatch("@@test$document,sitekey=" + publickeys.foo, "http://test/", "DOCU MENT", "foo.com", false, null, false); 310 testMatch("@@test$document,sitekey=foo-publickey", "http://test/", "DOCUMENT ", "foo.com", false, null, false);
348 }); 311 });
349 })(); 312 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld