blob: fba8c7be4ea6980508affe7105cd4f0e29cbe434 [file] [log] [blame]
<!doctype html>
<html>
<head>
<script src="/common/utils.js"></script>
<script src="resources/routines.js"></script>
</head>
<body>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.setShouldLogDownloadCallbacks(true);
testRunner.setShouldLogDownloadSize(true);
testRunner.waitUntilDownloadFinished();
testRunner.setShouldDownloadUndisplayableMIMETypes(true);
}
var activeWorker;
var uuid = token();
var url = "/WebKit/service-workers/resources/fetch-service-worker-preload-script.py?download=yes&no-fetch-event-handling=yes&token=" + uuid;
var frame;
const channel = new MessageChannel();
function waitUntilActivating()
{
return new Promise(resolve => {
channel.port2.onmessage = (event) => {
if (event.data === "activating")
resolve();
};
});
}
function triggerActivation()
{
activeWorker.postMessage("activate");
}
async function doTest() {
if (window.testRunner) {
testRunner.setUseSeparateServiceWorkerProcess(true);
await fetch("").then(() => { }, () => { });
}
let registration = await navigator.serviceWorker.register("/WebKit/service-workers/fetch-service-worker-preload-worker.js", { scope : url });
if (!registration.installing) {
registration.unregister();
registration = await navigator.serviceWorker.register("/WebKit/service-workers/fetch-service-worker-preload-worker.js", { scope : url });
}
activeWorker = registration.installing;
activeWorker.postMessage({ port: channel.port1 }, [channel.port1]);
await waitUntilActivating();
fetch(url + "&value=use-preload", { method: 'POST' });
// Load iframe, with activating worker, so preload will start and will be the one to be downloaded, directly through preload since service worker did not handle the event.
// Download size should be size of "use-preload".
const promise = withIframe(url);
triggerActivation();
}
doTest();
</script>
</body>
</html>