Commit 01aceb84 authored by Adithya Srinivasan's avatar Adithya Srinivasan Committed by Commit Bot

Portals: Simplify tests (1/5)

Uses portal/portalHost.postMessage instead of broadcast channels in the
following tests:

- portals-cross-origin-load.html
- portals-host-exposure.html
- portals-rendering.html

Change-Id: I1c2a74f07d3566d7046e48d2355508c5f0e6149e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1591876Reviewed-by: default avatarLucas Gadani <lfg@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Commit-Queue: Adithya Srinivasan <adithyas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656389}
parent e6842f5e
......@@ -4,17 +4,14 @@
<body>
<script>
promise_test(async () => {
var bc = new BroadcastChannel("portals-cross-origin-load");
var receiveMessage = new Promise((resolve, reject) => {
bc.onmessage = e => {
bc.close();
resolve();
}
});
var portal = document.createElement("portal");
portal.src = "http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-cross-origin.sub.html";
var receiveMessage = new Promise((resolve, reject) => {
portal.onmessage = e => { resolve(e.data) };
});
document.body.appendChild(portal);
return receiveMessage;
var message = await receiveMessage;
assert_equals(message, "loaded");
});
</script>
</body>
......@@ -3,41 +3,28 @@
<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}`;
function openPortalAndReceiveMessage(portalSrc) {
let portal = document.createElement('portal');
portal.src = portalSrc;
let received = new Promise((resolve, reject) => {
portal.onmessage = resolve;
document.body.appendChild(portal);
return await received;
} finally {
broadcastChannel.close();
}
});
return received;
}
promise_test(async t => {
let {hasHost} = await openPortalAndReceiveMessage(
'resources/portal-host.html');
assert_true(hasHost, "window.portalHost should be defined");
promise_test(() => {
return openPortalAndReceiveMessage("resources/portal-host.html");
}, "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");
promise_test(() => {
return openPortalAndReceiveMessage(
"http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host.html");
}, "window.portalHost should be exposed in cross-origin portal");
promise_test(async t => {
let {hasHost} = await openPortalAndReceiveMessage(
promise_test(() => {
return 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>
......
......@@ -3,14 +3,15 @@
<title>Portals rendering test</title>
<link rel="match" href="references/portals-rendering.html">
<body>
<portal src="resources/portals-rendering-portal.html" style="background-color: red; width: 100px; height: 100px"></portal>
<script>
var bc = new BroadcastChannel('portal');
bc.onmessage = function(e) {
var portal = document.createElement('portal');
portal.src = 'resources/portals-rendering-portal.html';
portal.style = 'background-color: red; width: 100px; height: 100px';
portal.onmessage = e => {
window.requestAnimationFrame(function(ts) {
document.documentElement.classList.remove('reftest-wait');
});
bc.close();
}
document.body.appendChild(portal);
</script>
</body>
<!DOCTYPE html>
<body>
<script>
var iframe = document.createElement("iframe");
iframe.src = "http://{{host}}:{{ports[http][0]}}/portals/resources/portal-forward-with-broadcast.html?broadcastchannel=portals-cross-origin-load";
iframe.onload = e => {
iframe.contentWindow.postMessage("loaded", "*");
}
document.body.appendChild(iframe);
window.portalHost.postMessage("loaded", "*");
</script>
</body>
......@@ -2,6 +2,6 @@
<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}`;
window.location.href = `http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host.html`;
</script>
</body>
<!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>
<!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();
}
if (window.portalHost)
window.portalHost.postMessage("has host", "*");
</script>
</body>
......@@ -2,9 +2,7 @@
<body style="background-color: green">
<script>
window.requestAnimationFrame(function(ts) {
var bc = new BroadcastChannel('portal');
bc.postMessage('loaded');
bc.close();
window.portalHost.postMessage("loaded", "*");
});
</script>
</body>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment