Update web-platform-tests to revision 0f0b7a7e353421b600ee555bf354d3a98bb603ae

This commit is contained in:
WPT Sync Bot 2019-02-01 20:48:40 -05:00
parent 363073568e
commit 71dcf37d55
175 changed files with 2749 additions and 678 deletions

View file

@ -4,29 +4,35 @@
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var bc = new BroadcastChannel("test-eventlistener");
let test = "eventlistener";
var bc = new BroadcastChannel(`test-${test}`);
bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed");
bc.close();
});
window.open("resources/portal-activate-event-window.html?test=eventlistener");
const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
}, "Tests that the PortalActivateEvent is dispatched when a portal is activated.");
async_test(function(t) {
var bc = new BroadcastChannel("test-eventhandler");
let test = "eventhandler";
var bc = new BroadcastChannel(`test-${test}`);
bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed");
bc.close();
});
window.open("resources/portal-activate-event-window.html?test=eventhandler");
const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
}, "Tests that the portalactivate event handler is dispatched when a portal is activated.");
async_test(function(t) {
var bc = new BroadcastChannel("test-bodyeventhandler");
let test = "bodyeventhandler";
var bc = new BroadcastChannel(`test-${test}`);
bc.onmessage = t.step_func_done(function(e) {
assert_equals(e.data, "passed");
bc.close();
});
window.open("resources/portal-activate-event-window.html?test=bodyeventhandler");
const portalUrl = encodeURIComponent(`portal-activate-event-portal.html?test=${test}`);
window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}&channelName=portal-${test}`);
}, "Tests that the HTMLBodyElement has the portalactivate event handler.");
</script>

View file

@ -0,0 +1,9 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
let activatePromise = document.createElement('portal').activate();
await promise_rejects(t, 'InvalidStateError', activatePromise);
}, "A portal with nothing in it cannot be activated");
</script>

View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<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";
document.body.appendChild(portal);
return receiveMessage;
});
</script>
</body>

View file

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

View file

@ -0,0 +1,29 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<body>
<script>
// Waits for 2 messages from portal, one before activation and one after.
function waitForMessages() {
return new Promise((resolve, reject) => {
var results = [];
var bc = new BroadcastChannel("portals-host-hidden-after-activation");
bc.onmessage = e => {
results.push(e.data.hasHost);
if (results.length == 2) {
bc.close();
resolve(results);
}
};
});
}
promise_test(async () => {
const portalUrl = encodeURIComponent("portal-host-hidden-after-activation-portal.html");
window.open(`resources/portal-embed-and-activate.html?url=${portalUrl}`);
var results = await waitForMessages();
assert_true(results[0], "portalHost exposed before calling activate()");
assert_false(results[1], "portalHost hidden after receiving portalactivate event");
}, "window.portalHost should be null after portal is activated");
</script>
</body>

View file

@ -1,17 +0,0 @@
<!DOCTYPE html>
<script>
window.onload = function(e) {
var test = (new URL(location)).searchParams.get("test");
var portal = document.createElement("portal");
portal.src = "portal-activate-event-portal.html" + location.search;
document.body.appendChild(portal);
var bc = new BroadcastChannel("portal-" + test);
bc.onmessage = function(e) {
document.querySelector("portal").activate();
bc.close();
}
}
</script>
<body>
</body>

View file

@ -0,0 +1,11 @@
<!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);
</script>
</body>

View file

@ -0,0 +1,26 @@
<!DOCTYPE html>
<!--
Embeds a portal (src specified by query parameter "url") and activates it after
receiving a message from the portal. Use query parameter "channelName" to
specify the name of the channel used by the portal src send a message
indicating that it is ready for activation (default name used is "portal").
-->
</title>
<body>
<script>
var searchParams = new URL(location).searchParams;
// TODO(adithyas): Replace this with postmessage once it's implemented for
// portals.
var channelName = searchParams.get("channelName") || "portal";
var bc = new BroadcastChannel(channelName);
bc.onmessage = function(e) {
document.querySelector("portal").activate();
bc.close();
}
let portal = document.createElement("portal");
portal.src = searchParams.get("url");
document.body.appendChild(portal);
</script>
</body>

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<body>
<script>
function forwardMessage(e) {
let broadcastChannel = new BroadcastChannel(new URL(location).searchParams.get('broadcastchannel'));
try {
broadcastChannel.postMessage(e.data);
} finally {
broadcastChannel.close();
}
}
window.addEventListener("message", forwardMessage);
</script>
</body>

View file

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

View file

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

View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<script>
window.addEventListener("portalactivate", function(e) {
var bc = new BroadcastChannel("portals-host-hidden-after-activation");
bc.postMessage({ hasHost: !!window.portalHost });
bc.close();
});
var bc = new BroadcastChannel("portals-host-hidden-after-activation");
bc.postMessage({hasHost: !!window.portalHost });
bc.close();
bc = new BroadcastChannel("portal");
bc.postMessage("loaded");
bc.close();
</script>

View file

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