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: Addressed Felix's feedback Created Sept. 29, 2015, 11:05 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
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 if (prevWnd == wnd && prevItem.location == item.location && prevItem.type == item.type && prevItem.docDomain == item.docDomain) 290 if (prevWnd == wnd && prevItem.location == item.location && prevItem.type == item.type && prevItem.docDomain == item.docDomain)
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 == 7)
301 defaultMatcher.add(Filter.fromText(expectedURL + "$domain=127.0.0.1"));
302 else if (stage > 1)
301 defaultMatcher.add(Filter.fromText(expectedURL)); 303 defaultMatcher.add(Filter.fromText(expectedURL));
304
302 if (stage == 3) 305 if (stage == 3)
303 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document")); 306 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document"));
304 if (stage == 4) 307 if (stage == 4)
305 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$~document")); 308 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$~document"));
306 if (stage == 5) 309 if (stage == 5)
307 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document,site key=" + publickey)); 310 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$document,site key=" + publickey));
311 if (stage == 6 || stage == 7)
312 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$genericblock" ));
313 if (stage == 8)
314 defaultMatcher.add(Filter.fromText("@@||127.0.0.1:1234/test|$genericblock, sitekey=" + publickey));
308 315
309 if (!explicitEvent) 316 if (!explicitEvent)
310 { 317 {
311 if (body.indexOf("2000/svg") >= 0) 318 if (body.indexOf("2000/svg") >= 0)
312 { 319 {
313 // SVG image: add an onload attribute to the document element and keep 320 // SVG image: add an onload attribute to the document element and keep
314 // polling until the document is really loaded. 321 // 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 + '"'); 322 body = body.replace(/(<svg\b)/, '$1 onload="if (document.readyState != \ 'complete\') setTimeout(arguments.callee.bind(this), 0); else ' + dispatchReadyE vent + '"');
316 } 323 }
317 else 324 else
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 }); 367 });
361 368
362 policyHits = []; 369 policyHits = [];
363 var callback = function() 370 var callback = function()
364 { 371 {
365 let expectedStatus = "allowed"; 372 let expectedStatus = "allowed";
366 if (stage == 3) 373 if (stage == 3)
367 equal(policyHits.length, 0, "Number of policy hits"); 374 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 375 // 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 376 // filter hits being counted even if the resource doesn't end up getting b locked
370 else if (stage != 5) 377 else if (stage != 5 && stage != 6 && stage != 8)
371 { 378 {
372 equal(policyHits.length, 1, "Number of policy hits"); 379 equal(policyHits.length, 1, "Number of policy hits");
373 if (policyHits.length == 1) 380 if (policyHits.length == 1)
374 { 381 {
375 let [wnd, node, item] = policyHits[0]; 382 let [wnd, node, item] = policyHits[0];
376 383
377 equal(item.location, expectedURL, "Request URL"); 384 equal(item.location, expectedURL, "Request URL");
378 385
379 expectedStatus = (stage == 1 ? "allowed" : "blocked"); 386 expectedStatus = (stage == 1 ? "allowed" : "blocked");
380 let actualStatus = (item.filter ? "blocked" : "allowed"); 387 let actualStatus = (item.filter ? "blocked" : "allowed");
(...skipping 13 matching lines...) Expand all
394 }; 401 };
395 frame.addEventListener("abp:frameready", callback, false, true); 402 frame.addEventListener("abp:frameready", callback, false, true);
396 frame.setAttribute("src", "http://127.0.0.1:1234/test"); 403 frame.setAttribute("src", "http://127.0.0.1:1234/test");
397 } 404 }
398 405
399 let stageDescriptions = { 406 let stageDescriptions = {
400 1: "running without filters", 407 1: "running without filters",
401 2: "running with filter %S", 408 2: "running with filter %S",
402 3: "running with filter %S and site exception", 409 3: "running with filter %S and site exception",
403 4: "running with filter %S and exception not applicable to sites", 410 4: "running with filter %S and exception not applicable to sites",
404 5: "running with filter %S and sitekey exception" 411 5: "running with filter %S and sitekey exception",
412 6: "running with filter %S and $genericblock exception",
413 7: "running with filter %S$domain=127.0.0.1 and $genericblock exception",
414 8: "running with filter %S and $genericblock,sitekey exception"
405 }; 415 };
406 416
407 for (let test = 0; test < tests.length; test++) 417 for (let test = 0; test < tests.length; test++)
408 { 418 {
409 let [name, body, expectedURL, expectedType, expectedDomain, expectedThirdPar ty] = tests[test]; 419 let [name, body, expectedURL, expectedType, expectedDomain, expectedThirdPar ty] = tests[test];
410 for (let stage = 1; stage in stageDescriptions; stage++) 420 for (let stage = 1; stage in stageDescriptions; stage++)
411 { 421 {
412 let stageDescription = stageDescriptions[stage]; 422 let stageDescription = stageDescriptions[stage];
413 if (stageDescription.indexOf("%S") >= 0) 423 if (stageDescription.indexOf("%S") >= 0)
414 stageDescription = stageDescription.replace("%S", expectedURL); 424 stageDescription = stageDescription.replace("%S", expectedURL);
415 425
416 asyncTest(name + " (" + stageDescription + ")", runTest.bind(null, tests[t est], stage)); 426 asyncTest(name + " (" + stageDescription + ")", runTest.bind(null, tests[t est], stage));
417 } 427 }
418 } 428 }
419 })(); 429 })();
OLDNEW
« chrome/content/tests/elemhide.js ('K') | « chrome/content/tests/matcher.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld