Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / serviceworker / multiple-register.html
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/test-helpers.js"></script>
5 <script>
6 var worker_url = 'resources/empty-worker.js';
7
8 async_test(function(t) {
9   var scope = 'scope/subsequent-register';
10   var worker;
11   var previous_registration;
12
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);
17       })
18     .then(function(installing_worker) {
19         worker = installing_worker;
20         return wait_for_state(t, worker, 'activated');
21       })
22     .then(function() {
23         return navigator.serviceWorker.register(worker_url, { scope: scope });
24       })
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
29         // original worker.
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);
35       })
36     .catch(unreached_rejection(t));
37 }, 'Subsequent registrations resolve to the same registration object');
38
39 async_test(function(t) {
40   var scope = 'scope/concurrent-register';
41
42   navigator.serviceWorker.unregister(scope)
43     .then(function() {
44         var promises = [];
45         for (var i = 0; i < 100; ++i) {
46           promises.push(navigator.serviceWorker.register(worker_url,
47                                                          { scope: scope }));
48         }
49         return Promise.all(promises);
50       })
51     .then(function(registrations) {
52         registrations.forEach(function(registration) {
53             assert_equals(registration, registrations[0],
54                           'register should resolve to the same registration');
55         });
56         service_worker_unregister_and_done(t, scope);
57       })
58     .catch(unreached_rejection(t));
59 }, 'Concurrent registrations resolve to the same registration object');
60
61 async_test(function(t) {
62     var scope = 'scope/multiple-frames';
63     var previous_registration;
64
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');
69         })
70       .then(function(frame) {
71           return frame.contentWindow.navigator.serviceWorker.register(
72               worker_url, { scope: scope });
73         })
74       .then(function(registration) {
75           assert_not_equals(previous_registration, registration);
76           service_worker_unregister_and_done(t, scope);
77         })
78       .catch(unreached_rejection(t));
79   }, 'Registrations in separate frames resolve to different ' +
80          'registration objects');
81 </script>