Update To 11.40.268.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 = 'resources/scope/subsequent-register-from-same-window';
10   var registration;
11
12   service_worker_unregister_and_register(t, worker_url, scope)
13     .then(function(r) {
14         registration = r;
15         return wait_for_activated(t, registration);
16       })
17     .then(function() {
18         return navigator.serviceWorker.register(worker_url, { scope: scope });
19       })
20     .then(function(new_registration) {
21         assert_equals(new_registration, registration,
22                       'register should resolve to the same registration');
23         assert_equals(new_registration.active, registration.active,
24                       'register should resolve to the same worker');
25         assert_equals(new_registration.active.state, 'activated',
26                       'the worker should be in state "activated"');
27         return registration.unregister();
28       })
29     .then(function() { t.done(); })
30     .catch(unreached_rejection(t));
31 }, 'Subsequent registrations resolve to the same registration object');
32
33 async_test(function(t) {
34   var scope = 'resources/scope/subsequent-register-from-different-iframe';
35   var frame;
36   var registration;
37
38   service_worker_unregister_and_register(t, worker_url, scope)
39     .then(function(r) {
40         registration = r;
41         return wait_for_activated(t, registration);
42       })
43     .then(function() { return with_iframe('out-of-scope'); })
44     .then(function(f) {
45         frame = f;
46         return frame.contentWindow.navigator.serviceWorker.register(
47             worker_url, { scope: scope });
48       })
49     .then(function(new_registration) {
50         assert_not_equals(
51           registration, new_registration,
52           'register should resolve to the different registration');
53         assert_equals(
54           registration.scope, new_registration.scope,
55           'registrations should have the same scope');
56
57         assert_equals(
58           registration.installing, null,
59           'installing worker should be null');
60         assert_equals(
61           new_registration.installing, null,
62           'installing worker should be null');
63         assert_equals(
64           registration.waiting, null,
65           'waiting worker should be null')
66         assert_equals(
67           new_registration.waiting, null,
68           'waiting worker should be null')
69
70         assert_not_equals(
71           registration.active, new_registration.active,
72           'registration should have the different active worker');
73         assert_equals(
74           registration.active.scriptURL,
75           new_registration.active.scriptURL,
76           'active workers should have the same script URL');
77         assert_equals(
78           registration.active.state,
79           new_registration.active.state,
80           'active workers should be in the same state');
81
82         unload_iframe(frame);
83         return registration.unregister();
84       })
85     .then(function() { t.done(); })
86     .catch(unreached_rejection(t));
87 }, 'Subsequent registrations from a different iframe resolve to the ' +
88        'different registration object but they refer to the same ' +
89        'registration and workers');
90
91 async_test(function(t) {
92   var scope = 'resources/scope/concurrent-register';
93
94   service_worker_unregister(t, scope)
95     .then(function() {
96         var promises = [];
97         for (var i = 0; i < 10; ++i) {
98           promises.push(navigator.serviceWorker.register(worker_url,
99                                                          { scope: scope }));
100         }
101         return Promise.all(promises);
102       })
103     .then(function(registrations) {
104         registrations.forEach(function(registration) {
105             assert_equals(registration, registrations[0],
106                           'register should resolve to the same registration');
107         });
108         return registrations[0].unregister();
109       })
110     .then(function() { t.done(); })
111     .catch(unreached_rejection(t));
112 }, 'Concurrent registrations resolve to the same registration object');
113
114 </script>