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/subsequent-register';
11 var previous_registration;
13 service_worker_unregister_and_register(t, worker_url, scope)
14 .then(function(registration) {
15 previous_registration = registration;
16 return wait_for_update(t, registration);
18 .then(function(installing_worker) {
19 worker = installing_worker;
20 return wait_for_state(t, worker, 'activated');
23 return navigator.serviceWorker.register(worker_url, { scope: scope });
25 .then(function(registration) {
26 assert_equals(previous_registration, registration,
27 'register should resolve to the same registration');
28 // FIXME: When crbug.com/400602 is fixed, assert that active equals the
30 assert_not_equals(registration.active, worker,
31 'register should resolve to the same worker');
32 assert_equals(registration.active.state, 'activated',
33 'the worker should be in state "activated"');
34 service_worker_unregister_and_done(t, scope);
36 .catch(unreached_rejection(t));
37 }, 'Subsequent registrations resolve to the same registration object');
39 async_test(function(t) {
40 var scope = 'scope/concurrent-register';
42 navigator.serviceWorker.unregister(scope)
45 for (var i = 0; i < 100; ++i) {
46 promises.push(navigator.serviceWorker.register(worker_url,
49 return Promise.all(promises);
51 .then(function(registrations) {
52 registrations.forEach(function(registration) {
53 assert_equals(registration, registrations[0],
54 'register should resolve to the same registration');
56 service_worker_unregister_and_done(t, scope);
58 .catch(unreached_rejection(t));
59 }, 'Concurrent registrations resolve to the same registration object');
61 async_test(function(t) {
62 var scope = 'scope/multiple-frames';
63 var previous_registration;
65 service_worker_unregister_and_register(t, worker_url, scope)
66 .then(function(registration) {
67 previous_registration = registration;
68 return with_iframe('nothing-here.html');
70 .then(function(frame) {
71 return frame.contentWindow.navigator.serviceWorker.register(
72 worker_url, { scope: scope });
74 .then(function(registration) {
75 assert_not_equals(previous_registration, registration);
76 service_worker_unregister_and_done(t, scope);
78 .catch(unreached_rejection(t));
79 }, 'Registrations in separate frames resolve to different ' +
80 'registration objects');