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

Side by Side Diff: chrome/content/tests/policy.js

Issue 6439460933730304: Issue 616 - Add tests for $generichide and $genericblock (Closed)
Patch Set: Fixed contentpolicy tests with recent changes to underlying logic Created Sept. 5, 2015, 2:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 let server = null; 3 let server = null;
4 let frame = null; 4 let frame = null;
5 let requestNotifier = null; 5 let requestNotifier = null;
6 let httpProtocol = null; 6 let httpProtocol = null;
7 7
8 module("Content policy", { 8 module("Content policy", {
9 setup: function() 9 setup: function()
10 { 10 {
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 policyHits.pop(); 291 policyHits.pop();
292 } 292 }
293 policyHits.push([wnd, node, item]); 293 policyHits.push([wnd, node, item]);
294 } 294 }
295 295
296 function runTest([name, body, expectedURL, expectedType, expectedThirdParty, e xplicitEvent], stage) 296 function runTest([name, body, expectedURL, expectedType, expectedThirdParty, e xplicitEvent], stage)
297 { 297 {
298 defaultMatcher.clear(); 298 defaultMatcher.clear();
299 299
300 if (stage > 1) 300 if (stage > 1)
301 defaultMatcher.add(Filter.fromText(expectedURL)); 301 if (stage == 7)
Felix Dahlke 2015/09/28 18:24:07 I think this block can be simplified: if (stage =
kzar 2015/09/29 11:07:02 Done.
302 defaultMatcher.add(Filter.fromText(expectedURL + "$domain=127.0.0.1"));
303 else
304 defaultMatcher.add(Filter.fromText(expectedURL));
305
302 if (stage == 3) 306 if (stage == 3)
303 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document")); 307 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document"));
304 if (stage == 4) 308 if (stage == 4)
305 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$~document")); 309 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$~document"));
306 if (stage == 5) 310 if (stage == 5)
307 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document,site key=" + publickey)); 311 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document,site key=" + publickey));
312 if (stage == 6 || stage == 7)
313 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$genericblock" ));
314 if (stage == 8)
315 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$genericblock, sitekey=" + publickey));
308 316
309 if (!explicitEvent) 317 if (!explicitEvent)
310 { 318 {
311 if (body.indexOf("2000/svg") >= 0) 319 if (body.indexOf("2000/svg") >= 0)
312 { 320 {
313 // SVG image: add an onload attribute to the document element and keep 321 // SVG image: add an onload attribute to the document element and keep
314 // polling until the document is really loaded. 322 // polling until the document is really loaded.
315 body = body.replace(/(<svg\b)/, '$1 onload="if (document.readyState != \ 'complete\') setTimeout(arguments.callee.bind(this), 0); else ' + dispatchReadyE vent + '"'); 323 body = body.replace(/(<svg\b)/, '$1 onload="if (document.readyState != \ 'complete\') setTimeout(arguments.callee.bind(this), 0); else ' + dispatchReadyE vent + '"');
316 } 324 }
317 else 325 else
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 }); 368 });
361 369
362 policyHits = []; 370 policyHits = [];
363 var callback = function() 371 var callback = function()
364 { 372 {
365 let expectedStatus = "allowed"; 373 let expectedStatus = "allowed";
366 if (stage == 3) 374 if (stage == 3)
367 equal(policyHits.length, 0, "Number of policy hits"); 375 equal(policyHits.length, 0, "Number of policy hits");
368 // We cannot rely on the correctness of policy hits for sitekey filters du e to blocking 376 // We cannot rely on the correctness of policy hits for sitekey filters du e to blocking
369 // filter hits being counted even if the resource doesn't end up getting b locked 377 // filter hits being counted even if the resource doesn't end up getting b locked
370 else if (stage != 5) 378 else if (stage != 5 && stage != 6 && stage != 8)
371 { 379 {
372 equal(policyHits.length, 1, "Number of policy hits"); 380 equal(policyHits.length, 1, "Number of policy hits");
373 if (policyHits.length == 1) 381 if (policyHits.length == 1)
374 { 382 {
375 let [wnd, node, item] = policyHits[0]; 383 let [wnd, node, item] = policyHits[0];
376 384
377 equal(item.location, expectedURL, "Request URL"); 385 equal(item.location, expectedURL, "Request URL");
378 386
379 expectedStatus = (stage == 1 ? "allowed" : "blocked"); 387 expectedStatus = (stage == 1 ? "allowed" : "blocked");
380 let actualStatus = (item.filter ? "blocked" : "allowed"); 388 let actualStatus = (item.filter ? "blocked" : "allowed");
(...skipping 13 matching lines...) Expand all
394 }; 402 };
395 frame.addEventListener("abp:frameready", callback, false, true); 403 frame.addEventListener("abp:frameready", callback, false, true);
396 frame.setAttribute("src", "http://127.0.0.1:1234/test"); 404 frame.setAttribute("src", "http://127.0.0.1:1234/test");
397 } 405 }
398 406
399 let stageDescriptions = { 407 let stageDescriptions = {
400 1: "running without filters", 408 1: "running without filters",
401 2: "running with filter %S", 409 2: "running with filter %S",
402 3: "running with filter %S and site exception", 410 3: "running with filter %S and site exception",
403 4: "running with filter %S and exception not applicable to sites", 411 4: "running with filter %S and exception not applicable to sites",
404 5: "running with filter %S and sitekey exception" 412 5: "running with filter %S and sitekey exception",
413 6: "running with filter %S and $genericblock exception",
414 7: "running with filter %S$domain=127.0.0.1 and $genericblock exception",
415 8: "running with filter %S and $genericblock,sitekey exception"
405 }; 416 };
406 417
407 for (let test = 0; test < tests.length; test++) 418 for (let test = 0; test < tests.length; test++)
408 { 419 {
409 let [name, body, expectedURL, expectedType, expectedDomain, expectedThirdPar ty] = tests[test]; 420 let [name, body, expectedURL, expectedType, expectedDomain, expectedThirdPar ty] = tests[test];
410 for (let stage = 1; stage in stageDescriptions; stage++) 421 for (let stage = 1; stage in stageDescriptions; stage++)
411 { 422 {
412 let stageDescription = stageDescriptions[stage]; 423 let stageDescription = stageDescriptions[stage];
413 if (stageDescription.indexOf("%S") >= 0) 424 if (stageDescription.indexOf("%S") >= 0)
414 stageDescription = stageDescription.replace("%S", expectedURL); 425 stageDescription = stageDescription.replace("%S", expectedURL);
415 426
416 asyncTest(name + " (" + stageDescription + ")", runTest.bind(null, tests[t est], stage)); 427 asyncTest(name + " (" + stageDescription + ")", runTest.bind(null, tests[t est], stage));
417 } 428 }
418 } 429 }
419 })(); 430 })();
OLDNEW
« chrome/content/tests/matcher.js ('K') | « chrome/content/tests/matcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld