Commit 961ddc20 authored by Adithya Srinivasan's avatar Adithya Srinivasan Committed by Commit Bot

Portals: Simplify tests (5/5)

Uses portal postMessage APIs instead of broadcast channel in the
following tests:

- portals-activate-inside-portal.html
- portals-no-referrer.html

Change-Id: Iaa4d8a79fed99f7b39181eec59f26d89b7e38864
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1591804Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarLucas Gadani <lfg@chromium.org>
Commit-Queue: Adithya Srinivasan <adithyas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#657757}
parent 2b93b1fb
......@@ -7,11 +7,7 @@
var portal = document.createElement("portal");
portal.src = "resources/portal-activate-inside-portal.html";
let waitForMessage = new Promise((resolve, reject) => {
var bc = new BroadcastChannel("portals-activate-inside-portal");
bc.onmessage = e => {
bc.close();
resolve(e.data);
}
portal.onmessage = e => resolve(e.data);
document.body.appendChild(portal);
});
var error = await waitForMessage;
......
......@@ -3,30 +3,20 @@
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// TODO(jbroman): Remove use of BroadcastChannel for messaging once it is
// possible to postMessage to a portal the normal way.
promise_test(async () => {
assert_true('HTMLPortalElement' in self, 'HTMLPortalElement is required for this test');
let portal = document.createElement('portal');
let channelName = 'portals-no-referrer';
let broadcastChannel = new BroadcastChannel(channelName);
let referrerPromise = new Promise((resolve, reject) => {
portal.addEventListener('message', e => resolve(e.data), {once: true});
});
portal.src = 'resources/postmessage-referrer.sub.html';
document.body.appendChild(portal);
try {
let referrerPromise = new Promise((resolve, reject) => {
broadcastChannel.addEventListener('message', e => {
resolve(e.data);
}, {once: true});
});
portal.src = `resources/postmessage-referrer.sub.html?broadcastchannel=${channelName}`;
document.body.appendChild(portal);
try {
let {httpReferrer, documentReferrer} = await referrerPromise;
assert_equals(httpReferrer, 'no-http-referrer', 'No HTTP Referer header should be sent');
assert_equals(documentReferrer, 'no-document-referrer', 'No document.referrer should be present');
} finally {
document.body.removeChild(portal);
}
let {httpReferrer, documentReferrer} = await referrerPromise;
assert_equals(httpReferrer, 'no-http-referrer', 'No HTTP Referer header should be sent');
assert_equals(documentReferrer, 'no-document-referrer', 'No document.referrer should be present');
} finally {
broadcastChannel.close();
document.body.removeChild(portal);
}
}, "portal contents should be loaded with no referrer");
</script>
......
......@@ -4,11 +4,7 @@
var portal = document.createElement("portal");
portal.src = "simple-portal.html";
portal.onmessage = () => {
portal.activate().catch(e => {
var bc2 = new BroadcastChannel("portals-activate-inside-portal");
bc2.postMessage(e.name);
bc2.close();
});
portal.activate().catch(e => window.portalHost.postMessage(e.name, "*"));
}
document.body.appendChild(portal);
</script>
......
......@@ -12,9 +12,7 @@
}
});
var bc = new BroadcastChannel("portal");
bc.postMessage("loaded");
bc.close();
window.portalHost.postMessage("loaded", "*");
Promise.all([postMessagePromise, activatePromise])
.then(values => {
......
......@@ -5,11 +5,9 @@
portal.src = "portal-post-message-before-activate-portal.html";
document.body.appendChild(portal);
var bc = new BroadcastChannel("portal");
bc.onmessage = () => {
portal.onmessage = () => {
portal.postMessage("message");
portal.activate();
bc.close();
}
</script>
</body>
<!DOCTYPE html>
<script>
let message = {
httpReferrer: '{{header_or_default(Referer, no-http-referrer)}}',
documentReferrer: document.referrer || 'no-document-referrer',
};
let broadcastChannel = new BroadcastChannel(new URL(location).searchParams.get('broadcastchannel'));
try {
broadcastChannel.postMessage(message);
} finally {
broadcastChannel.close();
}
let message = {
httpReferrer: '{{header_or_default(Referer, no-http-referrer)}}',
documentReferrer: document.referrer || 'no-document-referrer',
};
window.portalHost.postMessage(message, "*");
</script>
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