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/re-register-resolves-to-new-value';
13 service_worker_unregister_and_register(t
, worker_url
, scope
)
16 return wait_for_state(t
, r
.installing
, 'activated');
19 return registration
.unregister();
22 return navigator
.serviceWorker
.register(worker_url
, { scope
: scope
});
24 .then(function(new_registration
) {
25 assert_not_equals(registration
, new_registration
,
26 'register should resolve to a new value');
27 service_worker_unregister_and_done(t
, scope
);
29 .catch(unreached_rejection(t
));
30 }, 'Unregister then register resolves to a new value');
32 async_test(function(t
) {
33 var scope
= 'resources/scope/re-register-while-old-registration-in-use';
36 service_worker_unregister_and_register(t
, worker_url
, scope
)
39 return wait_for_state(t
, r
.installing
, 'activated');
42 return with_iframe(scope
);
44 .then(function(frame
) {
45 return registration
.unregister();
48 return navigator
.serviceWorker
.register(worker_url
, { scope
: scope
});
50 .then(function(new_registration
) {
51 assert_registration_equals(
52 registration
, new_registration
,
53 'register should resolve to the same registration');
54 service_worker_unregister_and_done(t
, scope
);
56 .catch(unreached_rejection(t
));
57 }, 'Unregister then register resolves to the original value if the ' +
58 'registration is in use.');
60 async_test(function(t
) {
61 var scope
= 'resources/scope/re-register-does-not-affect-existing-controllee';
66 service_worker_unregister_and_register(t
, worker_url
, scope
)
69 return wait_for_state(t
, r
.installing
, 'activated');
72 return with_iframe(scope
);
74 .then(function(frame
) {
76 controller
= iframe
.contentWindow
.navigator
.serviceWorker
.controller
;
77 return registration
.unregister();
80 return navigator
.serviceWorker
.register(worker_url
, { scope
: scope
});
82 .then(function(registration
) {
83 assert_equals(registration
.installing
, null,
84 'installing version is null');
85 assert_equals(registration
.waiting
, null, 'waiting version is null');
87 iframe
.contentWindow
.navigator
.serviceWorker
.controller
,
89 'the worker from the first registration is the controller');
90 service_worker_unregister_and_done(t
, scope
);
92 .catch(unreached_rejection(t
));
93 }, 'Unregister then register does not affect existing controllee');
95 async_test(function(t
) {
96 var scope
= 'resources/scope/resurrection';
100 service_worker_unregister_and_register(t
, worker_url
, scope
)
103 return wait_for_state(t
, r
.installing
, 'activated');
106 return with_iframe(scope
);
108 .then(function(frame
) {
110 return registration
.unregister();
113 return navigator
.serviceWorker
.register(worker_url
, { scope
: scope
});
117 return with_iframe(scope
);
119 .then(function(frame
) {
120 // FIXME: When crbug.com/400602 is fixed, assert that controller
121 // equals the original worker.
123 frame
.contentWindow
.navigator
.serviceWorker
.controller
, null,
124 'document should have a controller');
125 service_worker_unregister_and_done(t
, scope
);
127 .catch(unreached_rejection(t
));
128 }, 'Unregister then register resurrects the registration');