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

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

Issue 29329739: Issue 3226 - Adjust content policy unit tests for e10s-related content policy changes (Closed)
Patch Set: Created Nov. 4, 2015, 11:09 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 (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 {
11 prepareFilterComponents.call(this); 11 prepareFilterComponents.call(this);
12 preparePrefs.call(this); 12 preparePrefs.call(this);
13 13
14 server = new nsHttpServer(); 14 server = new nsHttpServer();
15 server.start(1234); 15 server.start(1234);
16 16
17 frame = document.createElementNS("http://www.mozilla.org/keymaster/gatekee per/there.is.only.xul", "iframe"); 17 frame = document.createElementNS("http://www.mozilla.org/keymaster/gatekee per/there.is.only.xul", "browser");
18 frame.setAttribute("type", "content"); 18 frame.setAttribute("type", "content");
19 frame.setAttribute("disablehistory", "true");
19 frame.style.visibility = "collapse"; 20 frame.style.visibility = "collapse";
20 document.body.appendChild(frame); 21 document.body.appendChild(frame);
21 22
22 requestNotifier = new RequestNotifier(frame.contentWindow, onPolicyHit); 23 requestNotifier = new RequestNotifier(frame.outerWindowID, onPolicyHit);
23 24
24 httpProtocol = Utils.httpProtocol; 25 httpProtocol = Utils.httpProtocol;
25 Utils.httpProtocol = {userAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"}; 26 Utils.httpProtocol = {userAgent: "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0"};
26 }, 27 },
27 teardown: function() 28 teardown: function()
28 { 29 {
29 restoreFilterComponents.call(this); 30 restoreFilterComponents.call(this);
30 restorePrefs.call(this); 31 restorePrefs.call(this);
31 32
32 stop(); 33 stop();
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 "http://127.0.0.1:1234/test.class", "object", false, false 264 "http://127.0.0.1:1234/test.class", "object", false, false
264 ], 265 ],
265 [ 266 [
266 "HTML object (Java)", 267 "HTML object (Java)",
267 '<object type="application/x-java-applet" data="test.class"></object>', 268 '<object type="application/x-java-applet" data="test.class"></object>',
268 "http://127.0.0.1:1234/test.class", "object", false, false 269 "http://127.0.0.1:1234/test.class", "object", false, false
269 ]); 270 ]);
270 } 271 }
271 272
272 let policyHits = []; 273 let policyHits = [];
273 function onPolicyHit(wnd, node, item, scanComplete) 274 function onPolicyHit(item, scanComplete)
274 { 275 {
275 if (!item) 276 if (!item)
276 return; 277 return;
277 if (item.location == "http://127.0.0.1:1234/test" || 278 if (item.location == "http://127.0.0.1:1234/test" ||
278 item.location == "http://127.0.0.1:1234/redirect.gif" || 279 item.location == "http://127.0.0.1:1234/redirect.gif" ||
279 item.location == "http://127.0.0.1:1234/redirect2.gif") 280 item.location == "http://127.0.0.1:1234/redirect2.gif")
280 { 281 {
281 return; 282 return;
282 } 283 }
283 if (item.filter instanceof WhitelistFilter) 284 if (item.filter && item.filter.substr(0, 2) == "@@")
284 return; 285 return;
285 286
286 if (policyHits.length > 0) 287 if (policyHits.length > 0)
287 { 288 {
288 // Ignore duplicate policy calls (possible due to prefetching) 289 // Ignore duplicate policy calls (possible due to prefetching)
289 let [prevWnd, prevNode, prevItem] = policyHits[policyHits.length - 1]; 290 let prevItem = policyHits[policyHits.length - 1];
290 if (prevWnd == wnd && prevItem.location == item.location && prevItem.type == item.type && prevItem.docDomain == item.docDomain) 291 if (prevItem.location == item.location && prevItem.type == item.type && pr evItem.docDomain == item.docDomain)
291 policyHits.pop(); 292 policyHits.pop();
292 } 293 }
293 policyHits.push([wnd, node, item]); 294 policyHits.push(item);
294 } 295 }
295 296
296 function runTest([name, body, expectedURL, expectedType, expectedThirdParty, e xplicitEvent], stage) 297 function runTest([name, body, expectedURL, expectedType, expectedThirdParty, e xplicitEvent], stage)
297 { 298 {
298 defaultMatcher.clear(); 299 defaultMatcher.clear();
299 300
300 if (stage == 7) 301 if (stage == 7)
301 defaultMatcher.add(Filter.fromText(expectedURL + "$domain=127.0.0.1")); 302 defaultMatcher.add(Filter.fromText(expectedURL + "$domain=127.0.0.1"));
302 else if (stage > 1) 303 else if (stage > 1)
303 defaultMatcher.add(Filter.fromText(expectedURL)); 304 defaultMatcher.add(Filter.fromText(expectedURL));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 serverHit = true; 361 serverHit = true;
361 response.setStatusLine("1.1", "404", "Not Found"); 362 response.setStatusLine("1.1", "404", "Not Found");
362 response.setHeader("Content-Type", "text/html"); 363 response.setHeader("Content-Type", "text/html");
363 364
364 // Work around weird Firefox behavior, where worker scripts succesfully lo ad with empty 404 pages. 365 // Work around weird Firefox behavior, where worker scripts succesfully lo ad with empty 404 pages.
365 var error = "<b>Not found...<b>"; 366 var error = "<b>Not found...<b>";
366 response.bodyOutputStream.write(error, error.length); 367 response.bodyOutputStream.write(error, error.length);
367 }); 368 });
368 369
369 policyHits = []; 370 policyHits = [];
370 var callback = function() 371 let callback = function()
371 { 372 {
373 frame.messageManager.removeMessageListener("ready", callback);
374
372 let expectedStatus = "allowed"; 375 let expectedStatus = "allowed";
373 if (stage == 3) 376 if (stage == 3)
374 equal(policyHits.length, 0, "Number of policy hits"); 377 equal(policyHits.length, 0, "Number of policy hits");
375 // We cannot rely on the correctness of policy hits for sitekey filters du e to blocking 378 // We cannot rely on the correctness of policy hits for sitekey filters du e to blocking
376 // filter hits being counted even if the resource doesn't end up getting b locked 379 // filter hits being counted even if the resource doesn't end up getting b locked
377 else if (stage != 5 && stage != 6 && stage != 8) 380 else if (stage != 5 && stage != 6 && stage != 8)
378 { 381 {
379 equal(policyHits.length, 1, "Number of policy hits"); 382 equal(policyHits.length, 1, "Number of policy hits");
380 if (policyHits.length == 1) 383 if (policyHits.length == 1)
381 { 384 {
382 let [wnd, node, item] = policyHits[0]; 385 let item = policyHits[0];
383 386
384 equal(item.location, expectedURL, "Request URL"); 387 equal(item.location, expectedURL, "Request URL");
385 388
386 expectedStatus = (stage == 1 ? "allowed" : "blocked"); 389 expectedStatus = (stage == 1 ? "allowed" : "blocked");
387 let actualStatus = (item.filter ? "blocked" : "allowed"); 390 let actualStatus = (item.filter ? "blocked" : "allowed");
388 391
389 equal(actualStatus, expectedStatus, "Request blocked"); 392 equal(actualStatus, expectedStatus, "Request blocked");
390 equal(item.type.toLowerCase(), expectedType, "Request type"); 393 equal(item.type.toLowerCase(), expectedType, "Request type");
391 equal(item.thirdParty, expectedThirdParty, "Third-party flag"); 394 equal(item.thirdParty, expectedThirdParty, "Third-party flag");
392 equal(item.docDomain, "127.0.0.1", "Document domain"); 395 equal(item.docDomain, "127.0.0.1", "Document domain");
393 } 396 }
394 } 397 }
395 server.registerPathHandler(expectedURL.replace(/http:\/\/[^\/]+/, ""), nul l); 398 server.registerPathHandler(expectedURL.replace(/http:\/\/[^\/]+/, ""), nul l);
396 equal(serverHit, expectedStatus == "allowed", "Request received by server" ); 399 equal(serverHit, expectedStatus == "allowed", "Request received by server" );
397 400
398 frame.removeEventListener("abp:frameready", callback, false);
399
400 start(); 401 start();
401 }; 402 };
402 frame.addEventListener("abp:frameready", callback, false, true); 403 let callback2 = function()
404 {
405 // The frame will report hits asynchronously so make the frame send us a
406 // message and only process the results after it is received.
407 frame.removeEventListener("abp:frameready", callback2, false);
408 frame.messageManager.addMessageListener("ready", callback);
409 frame.messageManager.loadFrameScript("data:text/javascript,sendAsyncMessag e('ready')", false);
410 };
411 frame.addEventListener("abp:frameready", callback2, false, true);
403 frame.setAttribute("src", "http://127.0.0.1:1234/test"); 412 frame.setAttribute("src", "http://127.0.0.1:1234/test");
404 } 413 }
405 414
406 let stageDescriptions = { 415 let stageDescriptions = {
407 1: "running without filters", 416 1: "running without filters",
408 2: "running with filter %S", 417 2: "running with filter %S",
409 3: "running with filter %S and site exception", 418 3: "running with filter %S and site exception",
410 4: "running with filter %S and exception not applicable to sites", 419 4: "running with filter %S and exception not applicable to sites",
411 5: "running with filter %S and sitekey exception", 420 5: "running with filter %S and sitekey exception",
412 6: "running with filter %S and $genericblock exception", 421 6: "running with filter %S and $genericblock exception",
413 7: "running with filter %S$domain=127.0.0.1 and $genericblock exception", 422 7: "running with filter %S$domain=127.0.0.1 and $genericblock exception",
414 8: "running with filter %S and $genericblock,sitekey exception" 423 8: "running with filter %S and $genericblock,sitekey exception"
415 }; 424 };
416 425
417 for (let test = 0; test < tests.length; test++) 426 for (let test = 0; test < tests.length; test++)
418 { 427 {
419 let [name, body, expectedURL, expectedType, expectedDomain, expectedThirdPar ty] = tests[test]; 428 let [name, body, expectedURL, expectedType, expectedDomain, expectedThirdPar ty] = tests[test];
420 for (let stage = 1; stage in stageDescriptions; stage++) 429 for (let stage = 1; stage in stageDescriptions; stage++)
421 { 430 {
422 let stageDescription = stageDescriptions[stage]; 431 let stageDescription = stageDescriptions[stage];
423 if (stageDescription.indexOf("%S") >= 0) 432 if (stageDescription.indexOf("%S") >= 0)
424 stageDescription = stageDescription.replace("%S", expectedURL); 433 stageDescription = stageDescription.replace("%S", expectedURL);
425 434
426 asyncTest(name + " (" + stageDescription + ")", runTest.bind(null, tests[t est], stage)); 435 asyncTest(name + " (" + stageDescription + ")", runTest.bind(null, tests[t est], stage));
427 } 436 }
428 } 437 }
429 })(); 438 })();
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