2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script>
6 var worker_url = 'resources/empty-worker.js';
8 async_test(function(t) {
9 var scope = 'scope/re-register-resolves-to-new-value';
13 service_worker_unregister_and_register(t, worker_url, scope)
16 return wait_for_update(t, registration);
18 .then(function(worker) {
19 return wait_for_state(t, worker, 'activated');
22 return registration.unregister();
25 return navigator.serviceWorker.register(worker_url, { scope: scope });
27 .then(function(new_registration) {
28 assert_not_equals(registration, new_registration,
29 'register should resolve to a new value');
30 service_worker_unregister_and_done(t, scope);
32 .catch(unreached_rejection(t));
33 }, 'Unregister then register resolves to a new value');
35 async_test(function(t) {
36 var scope = 'scope/re-register-while-old-registration-in-use';
39 service_worker_unregister_and_register(t, worker_url, scope)
42 return wait_for_update(t, registration);
44 .then(function(worker) {
45 return wait_for_state(t, worker, 'activated');
48 return with_iframe(scope);
50 .then(function(frame) {
51 return registration.unregister();
54 return navigator.serviceWorker.register(worker_url, { scope: scope });
56 .then(function(new_registration) {
57 assert_equals(registration, new_registration,
58 'register should resolve to the same value');
59 service_worker_unregister_and_done(t, scope);
61 .catch(unreached_rejection(t));
62 }, 'Unregister then register resolves to the original value if the ' +
63 'registration is in use.');
65 async_test(function(t) {
66 var scope = 'scope/re-register-does-not-affect-existing-controllee';
71 service_worker_unregister_and_register(t, worker_url, scope)
74 return wait_for_update(t, registration);
76 .then(function(worker) {
77 return wait_for_state(t, worker, 'activated');
80 return with_iframe(scope);
82 .then(function(frame) {
84 controller = iframe.contentWindow.navigator.serviceWorker.controller;
85 return registration.unregister();
88 return navigator.serviceWorker.register(worker_url, { scope: scope });
90 .then(function(registration) {
91 assert_equals(registration.installing, null,
92 'installing version is null');
93 assert_equals(registration.waiting, null, 'waiting version is null');
95 iframe.contentWindow.navigator.serviceWorker.controller,
97 'the worker from the first registration is the controller');
98 service_worker_unregister_and_done(t, scope);
100 .catch(unreached_rejection(t));
101 }, 'Unregister then register does not affect existing controllee');
103 async_test(function(t) {
104 var scope = 'scope/resurrection';
108 service_worker_unregister_and_register(t, worker_url, scope)
111 return wait_for_update(t, registration);
113 .then(function(worker) {
114 return wait_for_state(t, worker, 'activated');
117 return with_iframe(scope);
119 .then(function(frame) {
121 return registration.unregister();
124 return navigator.serviceWorker.register(worker_url, { scope: scope });
127 return unload_iframe(iframe);
130 return with_iframe(scope);
132 .then(function(frame) {
133 // FIXME: When crbug.com/400602 is fixed, assert that controller
134 // equals the original worker.
136 frame.contentWindow.navigator.serviceWorker.controller, null,
137 'document should have a controller');
138 service_worker_unregister_and_done(t, scope);
140 .catch(unreached_rejection(t));
141 }, 'Unregister then register resurrects the registration');