Bug 1609120 [wpt PR 21161] - Verify that COOP severed the relationship on the Opener's side, with the popup's initial Browsing context closed., a=testonly

Automatic update from web-platform-tests
Verify that COOP severed the relationship on the Opener's side, with the popup's initial Browsing context closed. (#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

--

wpt-commits: 3624a87d4176e814d2e67cfa5e427bc217c9c5b0
wpt-pr: 21161
This commit is contained in:
Pâris Meuleman 2020-01-23 22:51:17 +00:00 committed by moz-wptsync-bot
parent ca15f7bc53
commit efa607006f
6 changed files with 48 additions and 14 deletions

View File

@ -20,15 +20,17 @@ async_test(t => {
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);

View File

@ -12,7 +12,12 @@ async_test(t => {
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);
@ -23,6 +28,7 @@ async_test(t => {
// 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;

View File

@ -15,6 +15,7 @@ function url_test_cache(t, url, channelName, hasOpener) {
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
@ -23,9 +24,7 @@ function url_test_cache(t, url, channelName, hasOpener) {
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.

View File

@ -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) {
@ -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;

View File

@ -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 };

View File

@ -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>