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/subsequent-register-from-same-window';
12 service_worker_unregister_and_register(t
, worker_url
, scope
)
15 return wait_for_state(t
, r
.installing
, 'activated');
18 return navigator
.serviceWorker
.register(worker_url
, { scope
: scope
});
20 .then(function(new_registration
) {
21 assert_registration_equals(new_registration
, registration
);
23 new_registration
, registration
,
24 'register should resolve to a new registration object');
25 assert_equals(new_registration
.active
, registration
.active
,
26 'register should resolve to the same worker');
27 assert_equals(new_registration
.active
.state
, 'activated',
28 'the worker should be in state "activated"');
29 return registration
.unregister();
31 .then(function() { t
.done(); })
32 .catch(unreached_rejection(t
));
33 }, 'Subsequent registrations resolve to a different registration object ' +
34 'but they refer to the same registration and workers');
36 async_test(function(t
) {
37 var scope
= 'resources/scope/subsequent-register-from-different-iframe';
41 service_worker_unregister_and_register(t
, worker_url
, scope
)
44 return wait_for_state(t
, r
.installing
, 'activated');
46 .then(function() { return with_iframe('out-of-scope'); })
49 return frame
.contentWindow
.navigator
.serviceWorker
.register(
50 worker_url
, { scope
: scope
});
52 .then(function(new_registration
) {
54 registration
, new_registration
,
55 'register should resolve to a different registration');
57 registration
.scope
, new_registration
.scope
,
58 'registrations should have the same scope');
61 registration
.installing
, null,
62 'installing worker should be null');
64 new_registration
.installing
, null,
65 'installing worker should be null');
67 registration
.waiting
, null,
68 'waiting worker should be null')
70 new_registration
.waiting
, null,
71 'waiting worker should be null')
74 registration
.active
, new_registration
.active
,
75 'registration should have a different active worker');
77 registration
.active
.scriptURL
,
78 new_registration
.active
.scriptURL
,
79 'active workers should have the same script URL');
81 registration
.active
.state
,
82 new_registration
.active
.state
,
83 'active workers should be in the same state');
86 return registration
.unregister();
88 .then(function() { t
.done(); })
89 .catch(unreached_rejection(t
));
90 }, 'Subsequent registrations from a different iframe resolve to the ' +
91 'different registration object but they refer to the same ' +
92 'registration and workers');
94 async_test(function(t
) {
95 var scope
= 'resources/scope/concurrent-register';
96 var number_of_registrations
= 10;
98 service_worker_unregister(t
, scope
)
101 for (var i
= 0; i
< number_of_registrations
; ++i
) {
102 promises
.push(navigator
.serviceWorker
.register(worker_url
,
105 return Promise
.all(promises
);
107 .then(function(registrations
) {
108 for (var i
= 1; i
< number_of_registrations
; ++i
) {
109 assert_registration_equals(registrations
[i
], registrations
[0]);
111 registrations
[i
], registrations
[0],
112 'register should resolve to a new registration object');
114 registrations
.forEach(function(registration
) {
116 return registrations
[0].unregister();
118 .then(function() { t
.done(); })
119 .catch(unreached_rejection(t
));
120 }, 'Concurrent registrations resolve to a different registration object ' +
121 'but they refer to the same registration and workers');