Index: LayoutTests/http/tests/security/contentSecurityPolicy/resources/frame-ancestors-test.js |
diff --git a/LayoutTests/http/tests/security/contentSecurityPolicy/resources/frame-ancestors-test.js b/LayoutTests/http/tests/security/contentSecurityPolicy/resources/frame-ancestors-test.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..74a231e0c8bbfd8b2e8b9f0d191464586be4c0ce |
--- /dev/null |
+++ b/LayoutTests/http/tests/security/contentSecurityPolicy/resources/frame-ancestors-test.js |
@@ -0,0 +1,73 @@ |
+var SAME_ORIGIN = true; |
+var CROSS_ORIGIN = false; |
+ |
+var EXPECT_BLOCK = true; |
+var EXPECT_LOAD = false; |
+ |
+var CROSSORIGIN_ORIGIN = "http://localhost:8080"; |
+ |
+window.jsTestIsAsync = true; |
+window.wasPostTestScriptParsed = true; |
+ |
+if (window.testRunner) |
+ testRunner.dumpChildFramesAsText(); |
+ |
+window.addEventListener("message", function (e) { |
+ debug("Message received: " + e.data); |
+}); |
+ |
+function injectIFrame(policy, sameOrigin, expectBlock) { |
+ var iframe = document.createElement("iframe"); |
+ iframe.addEventListener("load", iframeLoaded(expectBlock)); |
+ iframe.addEventListener("error", iframeLoaded(expectBlock)); |
+ |
+ var url = "/security/contentSecurityPolicy/resources/frame-ancestors.pl?policy=" + policy; |
+ if (!sameOrigin) |
+ url = CROSSORIGIN_ORIGIN + url; |
+ |
+ iframe.src = url; |
+ document.body.appendChild(iframe); |
+} |
+ |
+function iframeLoaded(expectBlock) { |
+ return function(ev) { |
+ try { |
+ console.log("IFrame load event fired: the IFrame's location is '" + ev.target.contentWindow.location.href + "'."); |
+ if (expectBlock) |
+ testFailed("The IFrame should have been blocked. It wasn't."); |
+ else |
+ testPassed("The IFrame should not have been blocked. It wasn't."); |
+ } catch (ex) { |
+ debug("IFrame load event fired: the IFrame is cross-origin (or was blocked)."); |
+ if (expectBlock) |
+ testPassed("The IFrame should have been blocked. It was."); |
+ else |
+ testFailed("The IFrame should not have been blocked. It was."); |
+ } |
+ finishJSTest(); |
+ }; |
+} |
+ |
+function crossOriginFrameShouldBeBlocked(policy) { |
+ window.onload = function () { |
+ injectIFrame(policy, CROSS_ORIGIN, EXPECT_BLOCK); |
+ }; |
+} |
+ |
+function crossOriginFrameShouldBeAllowed(policy) { |
+ window.onload = function () { |
+ injectIFrame(policy, CROSS_ORIGIN, EXPECT_LOAD); |
+ }; |
+} |
+ |
+function sameOriginFrameShouldBeBlocked(policy) { |
+ window.onload = function () { |
+ injectIFrame(policy, SAME_ORIGIN, EXPECT_BLOCK); |
+ }; |
+} |
+ |
+function sameOriginFrameShouldBeAllowed(policy) { |
+ window.onload = function () { |
+ injectIFrame(policy, SAME_ORIGIN, EXPECT_LOAD); |
+ }; |
+} |