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
= 'resources/scope/unregister-then-register-new-script-that-exists';
10 var new_worker_url
= worker_url
+ '?new';
15 service_worker_unregister_and_register(t
, worker_url
, scope
)
18 return wait_for_state(t
, r
.installing
, 'activated');
21 return with_iframe(scope
);
23 .then(function(frame
) {
25 return registration
.unregister();
28 return navigator
.serviceWorker
.register(new_worker_url
,
33 assert_equals(registration
.installing
.scriptURL
,
34 normalizeURL(new_worker_url
),
35 'before activated registration.installing');
36 assert_equals(registration
.waiting
, null,
37 'before activated registration.waiting');
38 assert_equals(registration
.active
.scriptURL
, normalizeURL(worker_url
),
39 'before activated registration.active');
40 assert_equals(new_registration
.installing
.scriptURL
,
41 normalizeURL(new_worker_url
),
42 'before activated new_registration.installing');
43 assert_equals(new_registration
.waiting
, null,
44 'before activated new_registration.waiting');
45 assert_equals(new_registration
.active
.scriptURL
,
46 normalizeURL(worker_url
),
47 'before activated new_registration.active');
49 return wait_for_state(t
, registration
.installing
, 'activated');
52 assert_equals(new_registration
.installing
, null,
53 'after activated new_registration.installing');
54 assert_equals(new_registration
.waiting
, null,
55 'after activated new_registration.waiting');
56 assert_equals(new_registration
.active
.scriptURL
,
57 normalizeURL(new_worker_url
),
58 'after activated new_registration.active');
59 return with_iframe(scope
);
61 .then(function(frame
) {
63 frame
.contentWindow
.navigator
.serviceWorker
.controller
.scriptURL
,
64 normalizeURL(new_worker_url
),
65 'the new worker should control a new document');
67 return registration
.unregister();
72 .catch(unreached_rejection(t
));
73 }, 'Registering a new script URL while an unregistered registration is in use');
75 async_test(function(t
) {
76 var scope
= 'resources/scope/unregister-then-register-new-script-that-404s';
80 service_worker_unregister_and_register(t
, worker_url
, scope
)
83 return wait_for_state(t
, r
.installing
, 'activated');
86 return with_iframe(scope
);
88 .then(function(frame
) {
90 return registration
.unregister();
93 var promise
= navigator
.serviceWorker
.register('this-will-404',
100 assert_unreached('register should reject the promise');
103 return with_iframe(scope
);
105 .then(function(frame
) {
106 assert_equals(frame
.contentWindow
.navigator
.serviceWorker
.controller
,
108 'document should not load with a controller');
112 .catch(unreached_rejection(t
));
113 }, 'Registering a new script URL that 404s does not resurrect an ' +
114 'unregistered registration');
116 async_test(function(t
) {
117 var scope
= 'resources/scope/unregister-then-register-reject-install-worker';
121 service_worker_unregister_and_register(t
, worker_url
, scope
)
124 return wait_for_state(t
, r
.installing
, 'activated');
127 return with_iframe(scope
);
129 .then(function(frame
) {
131 return registration
.unregister();
134 var promise
= navigator
.serviceWorker
.register(
135 'resources/reject-install-worker.js', { scope
: scope
});
141 return wait_for_state(t
, r
.installing
, 'redundant');
144 return with_iframe(scope
);
146 .then(function(frame
) {
147 assert_equals(frame
.contentWindow
.navigator
.serviceWorker
.controller
,
149 'document should not load with a controller');
151 return registration
.unregister();
156 .catch(unreached_rejection(t
));
157 }, 'Registering a new script URL that fails to install does not resurrect ' +
158 'an unregistered registration');