OLD | NEW |
(Empty) | |
| 1 var SAME_ORIGIN = true; |
| 2 var CROSS_ORIGIN = false; |
| 3 |
| 4 var EXPECT_BLOCK = true; |
| 5 var EXPECT_LOAD = false; |
| 6 |
| 7 var CROSSORIGIN_ORIGIN = "http://localhost:8080"; |
| 8 |
| 9 window.jsTestIsAsync = true; |
| 10 window.wasPostTestScriptParsed = true; |
| 11 |
| 12 if (window.testRunner) |
| 13 testRunner.dumpChildFramesAsText(); |
| 14 |
| 15 window.addEventListener("message", function (e) { |
| 16 debug("Message received: " + e.data); |
| 17 }); |
| 18 |
| 19 function injectIFrame(policy, sameOrigin, expectBlock) { |
| 20 var iframe = document.createElement("iframe"); |
| 21 iframe.addEventListener("load", iframeLoaded(expectBlock)); |
| 22 iframe.addEventListener("error", iframeLoaded(expectBlock)); |
| 23 |
| 24 var url = "/security/contentSecurityPolicy/resources/frame-ancestors.pl?poli
cy=" + policy; |
| 25 if (!sameOrigin) |
| 26 url = CROSSORIGIN_ORIGIN + url; |
| 27 |
| 28 iframe.src = url; |
| 29 document.body.appendChild(iframe); |
| 30 } |
| 31 |
| 32 function iframeLoaded(expectBlock) { |
| 33 return function(ev) { |
| 34 try { |
| 35 console.log("IFrame load event fired: the IFrame's location is '" +
ev.target.contentWindow.location.href + "'."); |
| 36 if (expectBlock) |
| 37 testFailed("The IFrame should have been blocked. It wasn't."); |
| 38 else |
| 39 testPassed("The IFrame should not have been blocked. It wasn't."
); |
| 40 } catch (ex) { |
| 41 debug("IFrame load event fired: the IFrame is cross-origin (or was b
locked)."); |
| 42 if (expectBlock) |
| 43 testPassed("The IFrame should have been blocked. It was."); |
| 44 else |
| 45 testFailed("The IFrame should not have been blocked. It was."); |
| 46 } |
| 47 finishJSTest(); |
| 48 }; |
| 49 } |
| 50 |
| 51 function crossOriginFrameShouldBeBlocked(policy) { |
| 52 window.onload = function () { |
| 53 injectIFrame(policy, CROSS_ORIGIN, EXPECT_BLOCK); |
| 54 }; |
| 55 } |
| 56 |
| 57 function crossOriginFrameShouldBeAllowed(policy) { |
| 58 window.onload = function () { |
| 59 injectIFrame(policy, CROSS_ORIGIN, EXPECT_LOAD); |
| 60 }; |
| 61 } |
| 62 |
| 63 function sameOriginFrameShouldBeBlocked(policy) { |
| 64 window.onload = function () { |
| 65 injectIFrame(policy, SAME_ORIGIN, EXPECT_BLOCK); |
| 66 }; |
| 67 } |
| 68 |
| 69 function sameOriginFrameShouldBeAllowed(policy) { |
| 70 window.onload = function () { |
| 71 injectIFrame(policy, SAME_ORIGIN, EXPECT_LOAD); |
| 72 }; |
| 73 } |
OLD | NEW |