зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1526506 [wpt PR 14974] - Reland "Portals: Expose portalHost to portal's browsing context", a=testonly
Automatic update from web-platform-tests Reland "Portals: Expose portalHost to portal's browsing context" This is a reland of 9d4738420905a6b28407a8282512d8307d413780 Original change's description: > Portals: Expose portalHost to portal's browsing context > > window.portalHost returns a PortalHost to script running inside the main > frame within a portal. > > Bug: 914117 > Change-Id: I26fb4ae9676261bee4446bfbc6ee34b28dc618b1 > Reviewed-on: https://chromium-review.googlesource.com/c/1399569 > Commit-Queue: Adithya Srinivasan <adithyas@chromium.org> > Reviewed-by: Daniel Cheng <dcheng@chromium.org> > Reviewed-by: Charlie Reis <creis@chromium.org> > Reviewed-by: Lucas Gadani <lfg@chromium.org> > Reviewed-by: Jeremy Roman <jbroman@chromium.org> > Cr-Commit-Position: refs/heads/master@{#624316} Bug: 914117 Change-Id: I2830cafac26928229d474fd91921fbf2f9a47952 Reviewed-on: https://chromium-review.googlesource.com/c/1425041 Commit-Queue: Adithya Srinivasan <adithyas@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Charlie Reis <creis@chromium.org> Reviewed-by: Jeremy Roman <jbroman@chromium.org> Cr-Commit-Position: refs/heads/master@{#628329} -- wpt-commits: b0020d5df18998609b38786878f7a0b92cc680aa wpt-pr: 14974
This commit is contained in:
Родитель
77cc78d290
Коммит
36db1ae243
|
@ -0,0 +1,44 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<body>
|
||||
<script>
|
||||
let channelIndex = 0;
|
||||
async function openPortalAndReceiveMessage(portalSrc) {
|
||||
let channelName = `portals-host-exposure-${channelIndex++}`
|
||||
let broadcastChannel = new BroadcastChannel(channelName);
|
||||
try {
|
||||
let received = new Promise((resolve, reject) => {
|
||||
broadcastChannel.addEventListener('message', e => {
|
||||
resolve(e.data);
|
||||
}, {once: true})
|
||||
});
|
||||
let portal = document.createElement('portal');
|
||||
portal.src = `${portalSrc}?broadcastchannel=${channelName}`;
|
||||
document.body.appendChild(portal);
|
||||
return await received;
|
||||
} finally {
|
||||
broadcastChannel.close();
|
||||
}
|
||||
}
|
||||
|
||||
promise_test(async t => {
|
||||
let {hasHost} = await openPortalAndReceiveMessage(
|
||||
'resources/portal-host.html');
|
||||
assert_true(hasHost, "window.portalHost should be defined");
|
||||
}, "window.portalHost should be exposed in same-origin portal");
|
||||
|
||||
promise_test(async t => {
|
||||
let {hasHost} = await openPortalAndReceiveMessage(
|
||||
'http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host-cross-origin.sub.html');
|
||||
assert_true(hasHost, "window.portalHost should be defined");
|
||||
}, "window.portalHost should be exposed in cross-origin portal");
|
||||
|
||||
promise_test(async t => {
|
||||
let {hasHost} = await openPortalAndReceiveMessage(
|
||||
'resources/portal-host-cross-origin-navigate.sub.html');
|
||||
assert_true(hasHost, "window.portalHost should be defined");
|
||||
}, "window.portalHost should be exposed in portal after cross-origin navigation");
|
||||
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE html>
|
||||
<body>
|
||||
<script>
|
||||
let channelName = new URL(location).searchParams.get('broadcastchannel');
|
||||
window.location.href = `http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host-cross-origin.sub.html?broadcastchannel=${channelName}`;
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,15 @@
|
|||
<!DOCTYPE html>
|
||||
<body>
|
||||
<script>
|
||||
let forwardingIframe = document.createElement('iframe');
|
||||
let channelName = new URL(location).searchParams.get('broadcastchannel');
|
||||
forwardingIframe.src = `http://{{host}}:{{ports[http][0]}}/portals/resources/portal-forward-with-broadcast.html?broadcastchannel=${channelName}`;
|
||||
forwardingIframe.onload = () => {
|
||||
let message = {
|
||||
hasHost: !!window.portalHost
|
||||
};
|
||||
forwardingIframe.contentWindow.postMessage(message, '*');
|
||||
}
|
||||
document.body.appendChild(forwardingIframe);
|
||||
</script>
|
||||
</body>
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<body>
|
||||
<script>
|
||||
let message = {
|
||||
hasHost: !!window.portalHost
|
||||
};
|
||||
let broadcastChannel = new BroadcastChannel(new URL(location).searchParams.get('broadcastchannel'));
|
||||
try {
|
||||
broadcastChannel.postMessage(message);
|
||||
} finally {
|
||||
broadcastChannel.close();
|
||||
}
|
||||
</script>
|
||||
</body>
|
Загрузка…
Ссылка в новой задаче