Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / ServiceWorkerGlobalScope / unregister.html
blobe4cbdad3c3e0f290b016fba051f1708fcb2a7119
1 <!DOCTYPE html>
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>
6 <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');
16 .then(function() {
17 return navigator.serviceWorker.getRegistration(scope);
19 .then(function(result) {
20 assert_equals(
21 result,
22 undefined,
23 'After unregister(), the registration should not found');
24 return service_worker_unregister_and_done(t, scope);
25 });
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');
36 .then(function() {
37 return navigator.serviceWorker.getRegistration(scope);
39 .then(function(result) {
40 assert_equals(
41 result,
42 undefined,
43 'After unregister(), the registration should not found');
44 return service_worker_unregister_and_done(t, scope);
45 });
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');
56 .then(function() {
57 return navigator.serviceWorker.getRegistration(scope);
59 .then(function(result) {
60 assert_equals(
61 result,
62 undefined,
63 'After unregister(), the registration should not found');
64 return service_worker_unregister_and_done(t, scope);
65 });
66 }, 'Unregister on activate event');
68 promise_test(function(t) {
69 var script = 'resources/unregister-worker.js';
70 var scope = 'resources/unregister-controlling-worker';
72 var controller;
73 var frame;
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); })
80 .then(function(f) {
81 frame = f;
82 controller = frame.contentWindow.navigator.serviceWorker.controller;
84 assert_equals(
85 controller.scriptURL,
86 normalizeURL(script),
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');
95 resolve();
96 });
97 });
98 controller.postMessage({port: channel.port2}, [channel.port2]);
99 return promise;
101 .then(function() {
102 return navigator.serviceWorker.getRegistration(scope);
104 .then(function(result) {
105 assert_equals(
106 result,
107 undefined,
108 'After unregister(), the registration should not found');
109 assert_equals(
110 frame.contentWindow.navigator.serviceWorker.controller,
111 controller,
112 'After unregister(), the worker should still control the document');
113 return with_iframe(scope);
115 .then(function(new_frame) {
116 assert_equals(
117 new_frame.contentWindow.navigator.serviceWorker.controller,
118 null,
119 'After unregister(), the worker should not control a new document');
121 frame.remove();
122 new_frame.remove();
123 return service_worker_unregister_and_done(t, scope);
125 }, 'Unregister controlling service worker');
127 </script>