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 @@ ...@@ -4,17 +4,14 @@
<body> <body>
<script> <script>
promise_test(async () => { 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"); var portal = document.createElement("portal");
portal.src = "http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-cross-origin.sub.html"; 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); document.body.appendChild(portal);
return receiveMessage; var message = await receiveMessage;
assert_equals(message, "loaded");
}); });
</script> </script>
</body> </body>
...@@ -3,41 +3,28 @@ ...@@ -3,41 +3,28 @@
<script src="/resources/testharnessreport.js"></script> <script src="/resources/testharnessreport.js"></script>
<body> <body>
<script> <script>
let channelIndex = 0; function openPortalAndReceiveMessage(portalSrc) {
async function openPortalAndReceiveMessage(portalSrc) { let portal = document.createElement('portal');
let channelName = `portals-host-exposure-${channelIndex++}` portal.src = portalSrc;
let broadcastChannel = new BroadcastChannel(channelName); let received = new Promise((resolve, reject) => {
try { portal.onmessage = resolve;
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); document.body.appendChild(portal);
return await received; });
} finally { return received;
broadcastChannel.close();
}
} }
promise_test(async t => { promise_test(() => {
let {hasHost} = await openPortalAndReceiveMessage( return openPortalAndReceiveMessage("resources/portal-host.html");
'resources/portal-host.html');
assert_true(hasHost, "window.portalHost should be defined");
}, "window.portalHost should be exposed in same-origin portal"); }, "window.portalHost should be exposed in same-origin portal");
promise_test(async t => { promise_test(() => {
let {hasHost} = await openPortalAndReceiveMessage( return openPortalAndReceiveMessage(
'http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host-cross-origin.sub.html'); "http://{{hosts[alt][www]}}:{{ports[http][0]}}/portals/resources/portal-host.html");
assert_true(hasHost, "window.portalHost should be defined");
}, "window.portalHost should be exposed in cross-origin portal"); }, "window.portalHost should be exposed in cross-origin portal");
promise_test(async t => { promise_test(() => {
let {hasHost} = await openPortalAndReceiveMessage( return openPortalAndReceiveMessage(
'resources/portal-host-cross-origin-navigate.sub.html'); '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"); }, "window.portalHost should be exposed in portal after cross-origin navigation");
</script> </script>
......
...@@ -3,14 +3,15 @@ ...@@ -3,14 +3,15 @@
<title>Portals rendering test</title> <title>Portals rendering test</title>
<link rel="match" href="references/portals-rendering.html"> <link rel="match" href="references/portals-rendering.html">
<body> <body>
<portal src="resources/portals-rendering-portal.html" style="background-color: red; width: 100px; height: 100px"></portal>
<script> <script>
var bc = new BroadcastChannel('portal'); var portal = document.createElement('portal');
bc.onmessage = function(e) { portal.src = 'resources/portals-rendering-portal.html';
portal.style = 'background-color: red; width: 100px; height: 100px';
portal.onmessage = e => {
window.requestAnimationFrame(function(ts) { window.requestAnimationFrame(function(ts) {
document.documentElement.classList.remove('reftest-wait'); document.documentElement.classList.remove('reftest-wait');
}); });
bc.close();
} }
document.body.appendChild(portal);
</script> </script>
</body> </body>
<!DOCTYPE html> <!DOCTYPE html>
<body> <body>
<script> <script>
var iframe = document.createElement("iframe"); window.portalHost.postMessage("loaded", "*");
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);
</script> </script>
</body> </body>
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
<body> <body>
<script> <script>
let channelName = new URL(location).searchParams.get('broadcastchannel'); 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> </script>
</body> </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> <!DOCTYPE html>
<body> <body>
<script> <script>
let message = { if (window.portalHost)
hasHost: !!window.portalHost window.portalHost.postMessage("has host", "*");
};
let broadcastChannel = new BroadcastChannel(new URL(location).searchParams.get('broadcastchannel'));
try {
broadcastChannel.postMessage(message);
} finally {
broadcastChannel.close();
}
</script> </script>
</body> </body>
...@@ -2,9 +2,7 @@ ...@@ -2,9 +2,7 @@
<body style="background-color: green"> <body style="background-color: green">
<script> <script>
window.requestAnimationFrame(function(ts) { window.requestAnimationFrame(function(ts) {
var bc = new BroadcastChannel('portal'); window.portalHost.postMessage("loaded", "*");
bc.postMessage('loaded');
bc.close();
}); });
</script> </script>
</body> </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