Bug 1273920 P3 Add mochitest that demonstrates we cancel sw install if install event is GC'd. r=asuth

This commit is contained in:
Ben Kelly 2016-05-24 14:08:20 -07:00
parent 748fae34c5
commit 4020ec6404
3 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,17 @@
function postMessageToTest(msg) {
return clients.matchAll({ includeUncontrolled: true })
.then(list => {
for (var client of list) {
if (client.url.endsWith('test_install_event_gc.html')) {
client.postMessage(msg);
break;
}
}
});
}
addEventListener('install', evt => {
// This must be a simple promise to trigger the CC failure.
evt.waitUntil(new Promise(function() { }));
postMessageToTest({ type: 'INSTALL_EVENT' });
});

View File

@ -203,6 +203,7 @@ support-files =
!/dom/security/test/cors/file_CrossSiteXHR_server.sjs
!/dom/tests/mochitest/notification/MockServices.js
!/dom/tests/mochitest/notification/NotificationTest.js
blocking_install_event_worker.js
[test_bug1151916.html]
[test_bug1240436.html]
@ -235,6 +236,7 @@ skip-if = (debug && e10s) # Bug 1262224
[test_importscript_mixedcontent.html]
tags = mcb
[test_install_event.html]
[test_install_event_gc.html]
[test_installation_simple.html]
[test_match_all.html]
[test_match_all_advanced.html]

View File

@ -0,0 +1,86 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Test install event being GC'd before waitUntil fulfills</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
var script = 'blocking_install_event_worker.js';
var scope = 'sw_clients/simple.html?install-event-gc';
var registration;
function register() {
return navigator.serviceWorker.register(script, { scope: scope })
.then(swr => registration = swr);
}
function unregister() {
if (!registration) {
return;
}
return registration.unregister();
}
function waitForInstallEvent() {
return new Promise((resolve, reject) => {
navigator.serviceWorker.addEventListener('message', evt => {
if (evt.data.type === 'INSTALL_EVENT') {
resolve();
}
});
});
}
function gcWorker() {
return new Promise(function(resolve) {
// XXX: We need to trigger a CC/GC on the worker thread, but special
// powers does not support that. A setTimeout() longer than our
// CC period is the only solution I have found.
SimpleTest.requestFlakyTimeout('No way to force an immediate CC/GC of a ' +
'worker JS runtime.');
setTimeout(resolve, 10000);
});
}
function terminateWorker() {
return SpecialPowers.pushPrefEnv({
set: [
["dom.serviceWorkers.idle_timeout", 0],
["dom.serviceWorkers.idle_extended_timeout", 0]
]
}).then(_ => {
registration.installing.postMessage({ type: 'RESET_TIMER' });
});
}
function runTest() {
Promise.all([
waitForInstallEvent(),
register()
]).then(_ => ok(registration.installing, 'service worker is installing'))
.then(gcWorker)
.then(_ => ok(registration.installing, 'service worker is still installing'))
.then(terminateWorker)
.catch(e => ok(false, e))
.then(unregister)
.then(SimpleTest.finish);
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [
["dom.serviceWorkers.exemptFromPerDomainMax", true],
["dom.serviceWorkers.enabled", true],
["dom.serviceWorkers.testing.enabled", true],
["dom.caches.enabled", true],
]}, runTest);
</script>
</pre>
</body>
</html>