2 <title>ServiceWorkerGlobalScope: unregister
</title>
3 <script src='../../resources/testharness.js'
></script>
4 <script src='../../resources/testharnessreport.js'
></script>
5 <script src='../resources/test-helpers.js'
></script>
8 promise_test(function(t
) {
9 var script
= 'resources/unregister-worker.js?evaluation';
10 var scope
= 'resources/scope/unregister-on-script-evaluation';
12 return service_worker_unregister_and_register(t
, script
, scope
)
13 .then(function(registration
) {
14 return wait_for_state(t
, registration
.installing
, 'redundant');
17 return navigator
.serviceWorker
.getRegistration(scope
);
19 .then(function(result
) {
23 'After unregister(), the registration should not found');
24 return service_worker_unregister_and_done(t
, scope
);
26 }, 'Unregister on script evaluation');
28 promise_test(function(t
) {
29 var script
= 'resources/unregister-worker.js?install';
30 var scope
= 'resources/scope/unregister-on-install-event';
32 return service_worker_unregister_and_register(t
, script
, scope
)
33 .then(function(registration
) {
34 return wait_for_state(t
, registration
.installing
, 'redundant');
37 return navigator
.serviceWorker
.getRegistration(scope
);
39 .then(function(result
) {
43 'After unregister(), the registration should not found');
44 return service_worker_unregister_and_done(t
, scope
);
46 }, 'Unregister on installing event');
48 promise_test(function(t
) {
49 var script
= 'resources/unregister-worker.js?activate';
50 var scope
= 'resources/scope/unregister-on-activate-event';
52 return service_worker_unregister_and_register(t
, script
, scope
)
53 .then(function(registration
) {
54 return wait_for_state(t
, registration
.installing
, 'redundant');
57 return navigator
.serviceWorker
.getRegistration(scope
);
59 .then(function(result
) {
63 'After unregister(), the registration should not found');
64 return service_worker_unregister_and_done(t
, scope
);
66 }, 'Unregister on activate event');
68 promise_test(function(t
) {
69 var script
= 'resources/unregister-worker.js';
70 var scope
= 'resources/unregister-controlling-worker';
75 return service_worker_unregister_and_register(t
, script
, scope
)
76 .then(function(registration
) {
77 return wait_for_state(t
, registration
.installing
, 'activated');
79 .then(function() { return with_iframe(scope
); })
82 controller
= frame
.contentWindow
.navigator
.serviceWorker
.controller
;
87 'Service worker should control a new document')
89 // Wait for the completion of unregister() on the worker.
90 var channel
= new MessageChannel();
91 var promise
= new Promise(function(resolve
) {
92 channel
.port1
.onmessage
= t
.step_func(function(e
) {
93 assert_true(e
.data
.result
,
94 'unregister() should successfully finish');
98 controller
.postMessage({port
: channel
.port2
}, [channel
.port2
]);
102 return navigator
.serviceWorker
.getRegistration(scope
);
104 .then(function(result
) {
108 'After unregister(), the registration should not found');
110 frame
.contentWindow
.navigator
.serviceWorker
.controller
,
112 'After unregister(), the worker should still control the document');
113 return with_iframe(scope
);
115 .then(function(new_frame
) {
117 new_frame
.contentWindow
.navigator
.serviceWorker
.controller
,
119 'After unregister(), the worker should not control a new document');
123 return service_worker_unregister_and_done(t
, scope
);
125 }, 'Unregister controlling service worker');