Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COOP and COEP tests #17606

Merged
merged 26 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions html/cross-origin-embedder-policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
See `../cross-origin-opener-policy/README.md`.
44 changes: 44 additions & 0 deletions html/cross-origin-embedder-policy/blob.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<div id=log></div>
<script>
const origins = get_host_info();
annevk marked this conversation as resolved.
Show resolved Hide resolved
[
{
"origin": origins.HTTPS_ORIGIN,
"crossOrigin": origins.HTTPS_REMOTE_ORIGIN
},
{
"origin": origins.HTTPS_REMOTE_ORIGIN,
"crossOrigin": origins.HTTPS_NOTSAMESITE_ORIGIN
},
{
"origin": origins.HTTPS_NOTSAMESITE_ORIGIN,
"crossOrigin": origins.HTTPS_ORIGIN
}
].forEach(({ origin, crossOrigin }) => {
["subframe", "navigate"].forEach(variant => {
async_test(t => {
const id = token();
const frame = document.createElement("iframe");
t.add_cleanup(() => { frame.remove(); });
const path = new URL("resources/blob-url-factory.html", window.location).pathname;
frame.src = `${origin}${path}?id=${id}&variant=${variant}&crossOrigin=${crossOrigin}`;
window.addEventListener("message", t.step_func(({ data }) => {
if (data.id !== id) {
return;
}
assert_equals(data.origin, origin);
assert_true(data.sameOriginNoCORPSuccess, "Same-origin without CORP did not succeed");
assert_true(data.crossOriginNoCORPFailure, "Cross-origin without CORP did not fail");
t.done();
}));
document.body.append(frame);
}, `Cross-Origin-Embedder-Policy and blob: URL from ${origin} in subframe via ${variant}`);
});
});
</script>
1 change: 1 addition & 0 deletions html/cross-origin-embedder-policy/blob.https.html.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: require-corp
20 changes: 20 additions & 0 deletions html/cross-origin-embedder-policy/data.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/script-factory.js"></script>
<div id=log></div>
<script>
async_test(t => {
window.addEventListener("message", t.step_func_done(({ data }) => {
assert_equals(data.id, "");
assert_equals(data.origin, "null");
assert_false(data.sameOriginNoCORPSuccess); // This is effectively a no-op for this test
assert_true(data.crossOriginNoCORPFailure, "Cross-origin without CORP did not fail");
}));
const frame = document.createElement("iframe");
t.add_cleanup(() => frame.remove());
frame.src = `data:text/html,${createScript("null", window.origin)}`;
document.body.append(frame);
}, "Cross-Origin-Embedder-Policy and data: URLs");
</script>
1 change: 1 addition & 0 deletions html/cross-origin-embedder-policy/data.https.html.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: require-corp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
async_test(t => {
const frame = document.createElement("iframe");
t.add_cleanup(() => frame.remove());
let i = 0;
frame.onload = t.step_func(() => {
i++;
assert_equals(frame.contentDocument.URL, "about:blank");
frame.src = "about:blank";
if (i == 2) {
t.done();
}
});
document.body.append(frame);
annevk marked this conversation as resolved.
Show resolved Hide resolved
}, "Cross-Origin-Embedder-Policy and about:blank");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: require-corp
79 changes: 79 additions & 0 deletions html/cross-origin-embedder-policy/none.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<!doctype html>
<meta name="timeout" content="long">
<title>Cross-Origin-Embedder-Policy header and nested navigable resource without such header</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/common/utils.js></script> <!-- Use token() to allow running tests in parallel -->
<div id=log></div>
<script>
async_test(t => {
const frame = document.createElement("iframe");
t.add_cleanup(() => frame.remove());
frame.onload = t.step_func_done(() => {
assert_not_equals(frame.contentDocument, null);
});
frame.src = "/common/blank.html";
document.body.append(frame);
annevk marked this conversation as resolved.
Show resolved Hide resolved
assert_equals(frame.contentDocument.body.localName, "body");
}, `"none" top-level: navigating a frame to "none" should succeed`);

async_test(t => {
const frame = document.createElement("iframe");
t.add_cleanup(() => frame.remove());
const blank = "/common/blank.html";
let firstNavOk = false;
frame.onload = t.step_func(() => {
assert_not_equals(frame.contentDocument, null);
firstNavOk = true;
});
t.step_timeout(() => {
assert_true(firstNavOk);
assert_not_equals(frame.contentDocument, null);
annevk marked this conversation as resolved.
Show resolved Hide resolved
assert_equals(frame.contentWindow.location.pathname, blank);
t.done();
}, 500);
annevk marked this conversation as resolved.
Show resolved Hide resolved
frame.src = `resources/navigate-require-corp.sub.html?to=${blank}`;
document.body.append(frame);
assert_equals(frame.contentDocument.body.localName, "body");
}, `"none" top-level: navigating a frame from "require-corp" to "none" should succeed`);

async_test(t => {
const w = window.open(`resources/navigate-none.sub.html?to=navigate-require-corp.sub.html`, "window_name");
t.add_cleanup(() => w.close());

t.step_timeout(() => {
w.history.back();
t.step_timeout(() => {
assert_not_equals(w.document, null);
t.done();
}, 500);
}, 500);
}, `"none" top-level: navigating a frame back from "require-corp" should succeed`);

async_test(t => {
let pageLoaded = false;
const bc = new BroadcastChannel(token());
let finished = false;
bc.onmessage = t.step_func((event) => {
pageLoaded = true;
let payload = event.data;
assert_equals(payload, "loaded");
});

const bc2 = new BroadcastChannel(token());
bc2.onmessage = t.step_func((event) => {
finished = true;
let payload = event.data;
assert_equals(payload, "loaded");
});

const win = window.open(`resources/navigate-require-corp.sub.html?channelName=${bc.name}&to=navigate-none.sub.html?channelName=${bc2.name}`, "_blank", "noopener");
assert_equals(win, null);

annevk marked this conversation as resolved.
Show resolved Hide resolved
t.step_timeout(() => {
assert_true(pageLoaded);
assert_true(finished);
t.done();
}, 500);
}, `"require-corp" top-level noopener popup: navigating to "none" should succeed`);
</script>
1 change: 1 addition & 0 deletions html/cross-origin-embedder-policy/none.https.html.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: unknown-should-be-parsed-as-null
130 changes: 130 additions & 0 deletions html/cross-origin-embedder-policy/require-corp.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<!doctype html>
<meta name="timeout" content="long">
<title>Cross-Origin-Embedder-Policy header and nested navigable resource without such header</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script> <!-- Use token() to allow running tests in parallel -->
<div id=log></div>
<script>
async_test(t => {
const frame = document.createElement("iframe");
t.step_timeout(() => {
annevk marked this conversation as resolved.
Show resolved Hide resolved
// Make sure the iframe didn't load.
assert_equals(frame.contentDocument, null);
t.done();
}, 500);
frame.src = "/common/blank.html";
annevk marked this conversation as resolved.
Show resolved Hide resolved
document.body.append(frame);
assert_equals(frame.contentDocument.body.localName, "body");
}, `"require-corp" top-level: navigating a frame to "none" should fail`);
JuniorHsu marked this conversation as resolved.
Show resolved Hide resolved

async_test(t => {
const frame = document.createElement("iframe");
const bc = new BroadcastChannel(token());
annevk marked this conversation as resolved.
Show resolved Hide resolved
bc.onmessage = t.step_func((event) => {
assert_not_equals(frame.contentDocument, null);
let payload = event.data;
assert_equals(payload, "loaded");
t.step_timeout(() => {
assert_equals(frame.contentDocument, null);
t.done();
}, 500);
});

frame.src = `resources/navigate-require-corp.sub.html?channelName=${bc.name}&to=/common/blank.html`;
document.body.append(frame);
assert_equals(frame.contentDocument.body.localName, "body");
}, `"require-corp" top-level: navigating a frame from "require-corp" to "none" should fail`);
JuniorHsu marked this conversation as resolved.
Show resolved Hide resolved

async_test(t => {
let pageLoaded = false;
const bc = new BroadcastChannel(token());
let finished = false;
bc.onmessage = t.step_func((event) => {
let payload = event.data;
assert_equals(payload, "loaded");
pageLoaded = true;
});

const bc2 = new BroadcastChannel(token());
bc2.onmessage = t.step_func_done((event) => {
let payload = event.data;
assert_equals(payload, "loaded");
assert_equals(pageLoaded, true);
});

const win = window.open(`resources/navigate-none.sub.html?channelName=${bc.name}&to=navigate-none.sub.html?channelName=${bc2.name}`, "_blank", "noopener");
assert_equals(win, null);
}, `"require-corp" top-level: creating a noopener "none" popup should succeed`);

async_test(t => {
let pageLoaded = false;
const bc = new BroadcastChannel(token());
bc.onmessage = t.step_func_done((event) => {
pageLoaded = true;
let payload = event.data;
assert_equals(payload, "loaded");
});

const win = window.open(`resources/navigate-none.sub.html?channelName=${bc.name}&to=/common/blank.html`, "_blank");
t.add_cleanup(() => win.close());
t.step_timeout(() => {
assert_equals(pageLoaded, true);
t.done();
}, 500);
}, `"require-corp" top-level: creating a "none" popup should succeed.`);

[
{
"name": "",
"title": "as popup"
},
{
"name": "noopener",
"title": "as noopener popup"
},
{
"name": "clear opener",
"title": "as popup with opener set to null"
}
].forEach(({name, title}) => {
async_test(t => {
let pageLoaded = false;
const bc = new BroadcastChannel(token());
bc.onmessage = t.step_func(event => {
pageLoaded = true;
const payload = event.data;
assert_equals(payload, "loaded");
});

const bc2 = new BroadcastChannel(token());
bc2.onmessage = t.step_func_done(event => {
const payload = event.data;
assert_equals(payload, "loaded");
assert_equals(pageLoaded, true);
});

let clearOpener = "";
if (name === "clear opener") {
clearOpener = "&clearOpener=true"
}

let noopener = undefined;
if (name === "noopener") {
noopener = "noopener"
}

const win = window.open(`resources/navigate-require-corp.sub.html?channelName=${bc.name}${clearOpener}&to=navigate-none.sub.html?channelName=${bc2.name}`, "_blank", noopener);
annevk marked this conversation as resolved.
Show resolved Hide resolved
}, `"require-corp" top-level (${title}): navigating to "none" should succeed`);
});

promise_test(async t => {
const response = await fetch(get_host_info().HTTPS_REMOTE_ORIGIN+"/html/cross-origin-embedder-policy/resources/nothing.txt", {mode: "no-cors"});
annevk marked this conversation as resolved.
Show resolved Hide resolved
assert_equals(response.type, "opaque");
}, `"require-corp" top-level: fetch() to CORP: cross-origin response should succeed`);

promise_test(t => {
promise_rejects(t, new TypeError(), fetch(get_host_info().HTTPS_REMOTE_ORIGIN+"/common/blank.html", {mode: "no-cors"}));
annevk marked this conversation as resolved.
Show resolved Hide resolved
}, `"require-corp" top-level: fetch() to response without CORP should fail`);
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: require-corp
17 changes: 17 additions & 0 deletions html/cross-origin-embedder-policy/resources/blob-url-factory.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<body>
<script src="script-factory.js"></script>
<script>
const query = new URLSearchParams(window.location.search);
const id = query.get("id");
const variant = query.get("variant");
const parent = (variant === "subframe") ? "parent.parent" : "parent";
const blob = new Blob([createScript(window.origin, query.get("crossOrigin"), parent, id)], { type: "text/html" });
const blobURL = URL.createObjectURL(blob);
if (variant === "subframe") {
const frame = document.createElement("iframe");
frame.src = blobURL;
document.body.append(frame);
} else {
window.location = blobURL;
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Resource-Policy: cross-origin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: require-corp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nothing with same-origin CORP
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Resource-Policy: same-origin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Resource-Policy: cross-origin
annevk marked this conversation as resolved.
Show resolved Hide resolved
annevk marked this conversation as resolved.
Show resolved Hide resolved
22 changes: 22 additions & 0 deletions html/cross-origin-embedder-policy/resources/script-factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// This creates a serialized <script> element that is useful for blob/data/srcdoc-style tests.

function createScript(sameOrigin, crossOrigin, parent="parent", id="") {
return `<script>
let i = 0;
const data = { id: "${id}",
origin: window.origin,
sameOriginNoCORPSuccess: false,
crossOriginNoCORPFailure: false };
function report(field, success) {
i++;
data[field] = success;
if (i === 2 || "${sameOrigin}" === "null") {
window.${parent}.postMessage(data, "*");
}
}
if ("${sameOrigin}" !== "null") {
fetch("${sameOrigin}/common/blank.html", { mode: "no-cors" }).then(() => report("sameOriginNoCORPSuccess", true), () => report("sameOriginNoCORPSuccess", false));
}
fetch("${crossOrigin}/common/blank.html", { mode: "no-cors" }).then(() => report("crossOriginNoCORPFailure", false), () => report("crossOriginNoCORPFailure", true));
<\/script>`;
}
Loading