Debian Codegraph @

testing/web-platform/mozilla/tests/service-workers/update_completes_in_disconnected_global.https.html

raw
1 <!DOCTYPE html>
2 <title>Service Worker: Disconnected Global Update()</title>
3 <script src="/resources/testharness.js"></script>
4 <script src="/resources/testharnessreport.js"></script>
5 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script>
6 <script>
7 'use strict';
8
9 /**
10 * Gecko-only pseudo-crash-test to verify that if we call
11 * ServiceWorkerRegistration.update() from a global that will be destroyed
12 * before any IPC call could return that we don't crash.
13 *
14 * We use an iframe to create a global that we can destroy on demand.
15 */
16 promise_test(async function(t) {
17 const scope = 'resources/blank.html';
18 const sw_url = 'resources/empty.js';
19
20 let reg = await service_worker_unregister_and_register(t, sw_url, scope);
21 t.add_cleanup(function() {
22 return service_worker_unregister(t, scope);
23 });
24
25 // Wait for the worker to be activated so that we are in a known state.
26 await wait_for_state(t, reg.installing, 'activated');
27
28 let f = await with_iframe(scope);
29 let f_global = f.contentWindow;
30 // The frame should be controlled, although it's not necessary for the test.
31 assert_true(!!f_global.navigator.serviceWorker.controller);
32 t.add_cleanup(function() {
33 if (f) {
34 f.remove();
35 }
36 });
37
38 // Get a registration object that lives in the iframe's global.
39 let f_reg = await f_global.navigator.serviceWorker.getRegistration(reg.scope);
40 assert_true(!!f_reg, 'got registration');
41 assert_equals(reg.scope, f_reg.scope, 'Right registration');
42
43 // Trigger the update and destroy the global.
44 let update_resolved = false;
45 let update_rejected = false;
46
47 let update_promise = f_reg.update();
48 update_promise.then(
49 () => { update_resolved = true; }, () => { update_rejected = true; });
50
51 f.remove();
52 f = null;
53 f_global = null;
54
55 // Now we want to wait on an update call that should fire strictly after the
56 // update call above.
57 await reg.update();
58
59 assert_false(update_resolved, "frame update() should not have resolved");
60 assert_true(update_rejected, "frame update() should have rejected");
61 }, 'ServiceWorkerRegistration.update() concluding in a disconnected global');
62
63 </script>