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/new-worker';
10 var new_worker_url = worker_url + '?new';
14 service_worker_unregister_and_register(t, worker_url, scope)
17 return wait_for_update(t, registration);
19 .then(function(worker) {
20 return wait_for_state(t, worker, 'activated');
23 return with_iframe(scope);
25 .then(function(frame) {
27 return registration.unregister();
30 // FIXME: Register should not resolve until controllees are unloaded.
31 return navigator.serviceWorker.register(new_worker_url,
34 .then(function(new_registration) {
35 return wait_for_update(t, new_registration);
37 .then(function(worker) {
38 return wait_for_state(t, worker, 'activated');
41 return with_iframe(scope);
43 .then(function(frame) {
45 frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
46 normalizeURL(new_worker_url),
47 'document controller is the new worker');
48 service_worker_unregister_and_done(t, scope);
50 .catch(unreached_rejection(t));
51 }, 'Unregister then register a new script URL');
53 async_test(function(t) {
54 var scope = 'scope/non-existent-worker';
58 service_worker_unregister_and_register(t, worker_url, scope)
61 return wait_for_update(t, registration);
63 .then(function(worker) {
64 return wait_for_state(t, worker, 'activated');
67 return with_iframe(scope);
69 .then(function(frame) {
71 return registration.unregister();
74 // FIXME: Register should not resolve until controllees are unloaded.
75 return navigator.serviceWorker.register('this-will-404',
80 assert_unreached('register should reject the promise');
83 return unload_iframe(iframe);
86 return with_iframe(scope);
88 .then(function(frame) {
89 assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
91 'document should not load with a controller');
92 service_worker_unregister_and_done(t, scope);
94 .catch(unreached_rejection(t));
95 }, 'Registering a new script URL that 404s does not resurrect an ' +
96 'unregistered registration');
98 async_test(function(t) {
99 var scope = 'scope/reject-install-worker';
103 service_worker_unregister_and_register(t, worker_url, scope)
106 return wait_for_update(t, registration);
108 .then(function(worker) {
109 return wait_for_state(t, worker, 'activated');
112 return with_iframe(scope);
114 .then(function(frame) {
116 return registration.unregister();
119 // FIXME: Register should not resolve until controllees are unloaded.
120 return navigator.serviceWorker.register(
121 'resources/reject-install-worker.js', { scope: scope });
123 .then(function(new_registration) {
124 return wait_for_update(t, new_registration);
126 .then(function(worker) {
127 return wait_for_state(t, worker, 'redundant');
129 .then(function(worker) {
130 return unload_iframe(iframe);
133 return with_iframe(scope);
135 .then(function(frame) {
136 assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
138 'document should not load with a controller');
139 service_worker_unregister_and_done(t, scope);
141 .catch(unreached_rejection(t));
142 }, 'Registering a new script URL that fails to install does not resurrect ' +
143 'an unregistered registration');