Skip to content

Commit

Permalink
Verify that COOP severed the relationship on the Opener's side, with …
Browse files Browse the repository at this point in the history
…the popup's initial Browsing context closed. (web-platform-tests#21161)

* Add an assertion on the Opener's WindowProxy, verifying that COOP severed the relationship bothways

* Remove defunct comment

* Trigger the popup closure during the test cleanup using the broadcast channel

* Close the popup from the top level opened document in COOP tests, also test opener's window proxy on some more tests

* Fix typos and style

* Fix failing cleanup in blob-popup.https.html
  • Loading branch information
ParisMeuleman authored Jan 21, 2020
1 parent 16bc186 commit 3624a87
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 14 deletions.
12 changes: 7 additions & 5 deletions html/cross-origin-opener-policy/blob-popup.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@
const blobContents = `<script>
const w = window.open("${get_host_info().HTTPS_REMOTE_ORIGIN}/html/cross-origin-opener-policy/resources/coop-coep.py?coop=x&coep=x&channel=${bc.name}", "${bc.name}");
window.opener.furtherPopup = w;
// w will be closed by its postback iframe. When out of process,
// window.close() does not work.
window.opener.test.add_cleanup(() => w.close());
<\/script>`;
const blob = new Blob([blobContents], { type: "text/html" });
const blobURL = URL.createObjectURL(blob);
const popup = window.open(blobURL);
t.add_cleanup(() => popup.close());
t.add_cleanup(() => {
// Close the popups once the test is complete.
// The browsing context of the second popup is closed hence use the
// broadcast channel to trigger the closure.
bc.postMessage("close");
popup.close();
});
popup.onload = t.step_func(() => {
assert_equals(popup.opener, window);
assert_equals(popup.location.href, blobURL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
const noCOOP = "/common/blank.html";
const popupName = token();
const popup = window.open(noCOOP, popupName);
t.add_cleanup(() => popup.close());
// Close the popup once the test is complete.
// The browsing context is closed after the navigation hence use the broadcast channel
// to trigger the closure.
t.add_cleanup(() => {
bc.postMessage("close");
});
popup.onload = t.step_func(() => {
assert_equals(popup.name, popupName);
assert_equals(new URL(popup.document.URL).pathname, noCOOP);
Expand All @@ -23,6 +28,7 @@
// string comparison to "" to keep the random token out of error messages.
assert_equals(payload.name.length, 0);
assert_false(payload.opener);
assert_true(popup.closed);
});
const coop = `resources/coop-coep.py?coop=same-origin&coep=&channel=${channel.name}`;
popup.location = coop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
const payload = event.data;
assert_equals(payload.name, hasOpener ? channelName : "");
assert_equals(payload.opener, hasOpener);
assert_equals(w.closed, !hasOpener);
bc.close()

// test the same url for cache
Expand All @@ -23,9 +24,7 @@

const w = window.open(url, channelName);

// w will be closed by its postback iframe. When out of process,
// window.close() does not work.
t.add_cleanup(() => w.close());
// The popup is closed by url_test.
}

// Redirect from hostA to hostB with same coop and coep.
Expand Down
19 changes: 15 additions & 4 deletions html/cross-origin-opener-policy/resources/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ function url_test(t, url, channelName, hasOpener, openerDOMAccess) {
if (openerDOMAccess !== undefined) {
assert_equals(payload.openerDOMAccess, openerDOMAccess, 'openerDOMAccess');
}
assert_equals(w.closed, !hasOpener, 'Openee browsing context closed');
});

const w = window.open(url, channelName);

// w will be closed by its postback iframe. When out of process,
// window.close() does not work.
t.add_cleanup(() => w.close());
// Close the popup once the test is complete.
// The browsing context might be closed hence use the broadcast channel
// to trigger the closure.
t.add_cleanup(() => {
bc.postMessage("close");
});
}

function coop_coep_test(t, host, coop, coep, channelName, hasOpener, openerDOMAccess) {
Expand All @@ -43,7 +47,14 @@ function run_coop_test_iframe (documentTitle, iframe_origin, popup_origin, popup
const name = iframe_origin.name + "_iframe_opening_" + popup_origin.name + "_popup_with_coop_" + popup_coop;
async_test(t => {
const frame = document.createElement("iframe");
t.add_cleanup(() => { frame.remove(); });

// Close the popup and remove the frame once the test is
// complete. The browsing context might be closed hence use the
// broadcast channel to trigger the closure.
t.add_cleanup(() => {
frame.remove();
bc.postMessage("close");
});

const origin = CROSS_ORIGIN.origin;
const path = new URL("resources/iframe-popup.sub.html", window.location).pathname;
Expand Down
7 changes: 7 additions & 0 deletions html/cross-origin-opener-policy/resources/coop-coep.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def main(request, response):
openerDOMAccessAllowed = !!self.opener.document.URL;
} catch(ex) {
}
// Handle the response from the frame, closing the popup once the
// test completes.
addEventListener("message", event => {
if (event.data == "close") {
close();
}
});
const iframe = document.querySelector("iframe");
iframe.onload = () => {
const payload = { name: self.name, opener: !!self.opener, openerDOMAccess: openerDOMAccessAllowed };
Expand Down
11 changes: 10 additions & 1 deletion html/cross-origin-opener-policy/resources/postback.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
<script>
const channelName = new URL(location).searchParams.get("channel");
const bc = new BroadcastChannel(channelName);

// Handle the close message from the test-cleanup, forwarding it to the
// top level document, as this iframe and the opening document might not
// be able to close the popup.
bc.onmessage = event => {
if (event.data == "close") {
top.postMessage("close", "*");
}
};

window.addEventListener("message", event => {
bc.postMessage(event.data);
window.parent.close();
});
</script>

0 comments on commit 3624a87

Please sign in to comment.