Bug 1436763 Fix detached-context.https.html to not timeout due to promise reaction callbacks not firing for detached globals. r=catalinb

This commit is contained in:
Ben Kelly 2018-02-12 10:30:54 -08:00
parent 1828d1aec0
commit de9d4b4c65
4 changed files with 35 additions and 24 deletions

View File

@ -583054,7 +583054,7 @@
"testharness"
],
"service-workers/service-worker/activation.https.html": [
"cdd7cd200ff4ec3df61c257305953b3a1f369ab8",
"b7a9ca969b4122f1b9adc973c60044a6ab2a2a95",
"testharness"
],
"service-workers/service-worker/active.https.html": [
@ -583150,7 +583150,7 @@
"testharness"
],
"service-workers/service-worker/detached-context.https.html": [
"c7645323ba0753f35beaef90836631ca16f64d3a",
"a4e96edc51927eb29873b0c97a7232f71ae43378",
"testharness"
],
"service-workers/service-worker/extendable-event-async-waituntil.https.html": [
@ -584534,7 +584534,7 @@
"support"
],
"service-workers/service-worker/resources/test-helpers.sub.js": [
"55acaa1edd73a39a834e1a1ee0952f47a03e3c78",
"5567e4c45d07a90c4fc7fefa3475e564f0d46e5a",
"support"
],
"service-workers/service-worker/resources/testharness-helpers.js": [

View File

@ -6,24 +6,6 @@
<script src="resources/test-helpers.sub.js"></script>
<body>
<script>
// Registers, waits for activation, then unregisters on a dummy scope.
//
// This helper can be used in tests that assert that activation doesn't happen.
// It would not be sufficient to check the .waiting/.active properties once,
// since activation could be scheduled and just hasn't happened yet. Since this
// helper shows that activation of another registration completed, we can be
// sure that activation really will not happen.
function wait_for_activation_on_dummy_scope(t) {
var dummy_scope = 'resources/there/is/no/there/there';
var registration;
return navigator.serviceWorker.register('resources/empty-worker.js',
{ scope: dummy_scope })
.then(r => {
registration = r;
return wait_for_state(t, registration.installing, 'activated');
})
.then(() => registration.unregister());
}
// Returns {registration, iframe}, where |registration| has an active and
// waiting worker. The active worker controls |iframe| and has an inflight
// message event that can be finished by calling

View File

@ -16,6 +16,7 @@ promise_test(t => {
const scope_for_main = 'resources/' + scope_for_iframe;
const script = 'resources/empty-worker.js';
let frame;
let resolvedCount = 0;
return service_worker_unregister(t, scope_for_main)
.then(() => {
@ -41,9 +42,23 @@ promise_test(t => {
assert_equals(r.active.state, 'activated');
assert_equals(r.scope, normalizeURL(scope_for_main));
r.onupdatefound = () => { /* empty */ };
return Promise.all([
promise_rejects(t, 'InvalidStateError', r.unregister()),
promise_rejects(t, 'InvalidStateError', r.update())]);
// We want to verify that unregister() and update() do not
// resolve on a detached registration. We can't check for
// an explicit rejection, though, because not all browsers
// fire rejection callbacks on detached promises. Instead
// we wait for a dummy scope to install, activate, and
// unregister before declaring that the promises did not
// resolve.
r.unregister().then(() => resolvedCount += 1,
() => {});
r.update().then(() => resolvedCount += 1,
() => {});
return wait_for_activation_on_dummy_scope(t);
})
.then(() => {
assert_equals(resolvedCount, 0,
'methods called on a detached registration should not resolve');
})
}, 'accessing a ServiceWorkerRegistration from a removed iframe');

View File

@ -257,3 +257,17 @@ function with_sandboxed_iframe(url, sandbox) {
document.body.appendChild(frame);
});
}
// Registers, waits for activation, then unregisters on a dummy scope.
//
// This can be used to wait for a period of time needed to register,
// activate, and then unregister a service worker. When checking that
// certain behavior does *NOT* happen, this is preferable to using an
// arbitrary setTimeout() delay.
async function wait_for_activation_on_dummy_scope(t) {
const script = 'resources/empty-worker.js';
const scope = 'resources/there/is/no/there/there?' + Date.now();
let registration = await navigator.serviceWorker.register(script, { scope });
await wait_for_state(t, registration.installing, 'activated');
await registration.unregister();
}