| Index: third_party/WebKit/LayoutTests/external/wpt/content-security-policy/frame-ancestors/support/frame-ancestors-test.sub.js
|
| diff --git a/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/resources/frame-ancestors-test.js b/third_party/WebKit/LayoutTests/external/wpt/content-security-policy/frame-ancestors/support/frame-ancestors-test.sub.js
|
| similarity index 56%
|
| rename from third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/resources/frame-ancestors-test.js
|
| rename to third_party/WebKit/LayoutTests/external/wpt/content-security-policy/frame-ancestors/support/frame-ancestors-test.sub.js
|
| index 7eb1be60e43bef89aa3b624b94f3df70413fb5b7..795842707616f02443445c29e3957ccb58b49d5e 100644
|
| --- a/third_party/WebKit/LayoutTests/http/tests/security/contentSecurityPolicy/resources/frame-ancestors-test.js
|
| +++ b/third_party/WebKit/LayoutTests/external/wpt/content-security-policy/frame-ancestors/support/frame-ancestors-test.sub.js
|
| @@ -4,33 +4,36 @@ var CROSS_ORIGIN = false;
|
| var EXPECT_BLOCK = true;
|
| var EXPECT_LOAD = false;
|
|
|
| -var SAMEORIGIN_ORIGIN = "http://127.0.0.1:8000";
|
| -var CROSSORIGIN_ORIGIN = "http://localhost:8080";
|
| +var SAMEORIGIN_ORIGIN = "{{location[scheme]}}://{{location[host]}}";
|
| +var CROSSORIGIN_ORIGIN = "http://{{domains[www1]}}:{{ports[http][1]}}";
|
|
|
| -window.jsTestIsAsync = true;
|
| -window.wasPostTestScriptParsed = true;
|
| +var test;
|
|
|
| -if (window.testRunner)
|
| - testRunner.dumpChildFramesAsText();
|
| +function endTest(failed, message) {
|
| + if (typeof test === 'undefined') return;
|
| +
|
| + if (failed) {
|
| + test.step(function() {
|
| + assert_unreached(message);
|
| + test.done();
|
| + });
|
| + }
|
| + else test.done({message: message});
|
| +}
|
|
|
| window.addEventListener("message", function (e) {
|
| - if (window.parent != window) {
|
| + if (window.parent != window)
|
| window.parent.postMessage(e.data, "*");
|
| - } else {
|
| - if (e.data)
|
| - testFailed("The inner IFrame failed.");
|
| - else
|
| - testPassed("The inner IFrame passed.");
|
| -
|
| - finishJSTest();
|
| - }
|
| + else
|
| + if (e.data.type === 'test_result')
|
| + endTest(e.data.failed, "Inner IFrame msg: " + e.data.msg);
|
| });
|
|
|
| function injectNestedIframe(policy, parent, child, expectation, isSandboxed) {
|
| var iframe = document.createElement("iframe");
|
|
|
| - var url = "/security/contentSecurityPolicy/resources/frame-in-frame.pl?"
|
| - + "policy=" + policy
|
| + var url = "/content-security-policy/frame-ancestors/support/frame-in-frame.sub.html"
|
| + + "?policy=" + policy
|
| + "&parent=" + parent
|
| + "&child=" + child
|
| + "&expectation=" + expectation;
|
| @@ -49,8 +52,10 @@ function injectIFrame(policy, sameOrigin, expectBlock) {
|
| iframe.addEventListener("load", iframeLoaded(expectBlock));
|
| iframe.addEventListener("error", iframeLoaded(expectBlock));
|
|
|
| - var url = "/security/contentSecurityPolicy/resources/frame-ancestors.pl?policy=" + policy;
|
| - if (!sameOrigin)
|
| + var url = "/content-security-policy/frame-ancestors/support/frame-ancestors.sub.html?policy=" + policy;
|
| + if (sameOrigin)
|
| + url = SAMEORIGIN_ORIGIN + url;
|
| + else
|
| url = CROSSORIGIN_ORIGIN + url;
|
|
|
| iframe.src = url;
|
| @@ -60,32 +65,40 @@ function injectIFrame(policy, sameOrigin, expectBlock) {
|
| function iframeLoaded(expectBlock) {
|
| return function(ev) {
|
| var failed = true;
|
| + var message = "";
|
| 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 (or cross-origin). It wasn't.");
|
| + message = "The IFrame should have been blocked (or cross-origin). It wasn't.";
|
| failed = true;
|
| } else {
|
| - testPassed("The IFrame should not have been blocked. It wasn't.");
|
| + message = "The IFrame should not have been blocked. It wasn't.";
|
| failed = false;
|
| }
|
| } catch (ex) {
|
| - debug("IFrame load event fired: the IFrame is cross-origin (or was blocked).");
|
| + console.log("IFrame load event fired: the IFrame is cross-origin (or was blocked).");
|
| if (expectBlock) {
|
| - testPassed("The IFrame should have been blocked (or cross-origin). It was.");
|
| + message = "The IFrame should have been blocked (or cross-origin). It was.";
|
| failed = false;
|
| } else {
|
| - testFailed("The IFrame should not have been blocked. It was.");
|
| + message = "The IFrame should not have been blocked. It was.";
|
| failed = true;
|
| }
|
| }
|
| if (window.parent != window)
|
| - window.parent.postMessage(failed, '*');
|
| + window.parent.postMessage({type: 'test_result', failed: failed, message: message}, '*');
|
| else
|
| - finishJSTest();
|
| + endTest(failed, message);
|
| };
|
| }
|
|
|
| +function originFrameShouldBe(child, expectation, policy) {
|
| + if (child == "cross" && expectation == "blocked") crossOriginFrameShouldBeBlocked(policy);
|
| + if (child == "same" && expectation == "blocked") sameOriginFrameShouldBeBlocked(policy);
|
| + if (child == "cross" && expectation == "allowed") crossOriginFrameShouldBeAllowed(policy);
|
| + if (child == "same" && expectation == "allowed") sameOriginFrameShouldBeAllowed(policy);
|
| +}
|
| +
|
| function crossOriginFrameShouldBeBlocked(policy) {
|
| window.onload = function () {
|
| injectIFrame(policy, CROSS_ORIGIN, EXPECT_BLOCK);
|
| @@ -112,12 +125,12 @@ function sameOriginFrameShouldBeAllowed(policy) {
|
|
|
| function testNestedIFrame(policy, parent, child, expectation) {
|
| window.onload = function () {
|
| - injectNestedIframe(policy, parent == SAME_ORIGIN ? "same" : "cross", child == SAME_ORIGIN ? "same" : "cross", expectation == EXPECT_LOAD ? "Allowed" : "Blocked", false /* isSandboxed */);
|
| + injectNestedIframe(policy, parent == SAME_ORIGIN ? "same" : "cross", child == SAME_ORIGIN ? "same" : "cross", expectation == EXPECT_LOAD ? "allowed" : "blocked", false /* isSandboxed */);
|
| };
|
| }
|
|
|
| function testNestedSandboxedIFrame(policy, parent, child, expectation) {
|
| window.onload = function () {
|
| - injectNestedIframe(policy, parent == SAME_ORIGIN ? "same" : "cross", child == SAME_ORIGIN ? "same" : "cross", expectation == EXPECT_LOAD ? "Allowed" : "Blocked", true /* isSandboxed */);
|
| + injectNestedIframe(policy, parent == SAME_ORIGIN ? "same" : "cross", child == SAME_ORIGIN ? "same" : "cross", expectation == EXPECT_LOAD ? "allowed" : "blocked", true /* isSandboxed */);
|
| };
|
| }
|
|
|