Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / serviceworker / unregister-then-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/re-register-resolves-to-new-value';
10     var iframe;
11     var registration;
12
13     service_worker_unregister_and_register(t, worker_url, scope)
14       .then(function(r) {
15           registration = r;
16           return wait_for_update(t, registration);
17         })
18       .then(function(worker) {
19           return wait_for_state(t, worker, 'activated');
20         })
21       .then(function() {
22           return registration.unregister();
23         })
24       .then(function() {
25           return navigator.serviceWorker.register(worker_url, { scope: scope });
26         })
27       .then(function(new_registration) {
28           assert_not_equals(registration, new_registration,
29                             'register should resolve to a new value');
30           service_worker_unregister_and_done(t, scope);
31         })
32       .catch(unreached_rejection(t));
33   }, 'Unregister then register resolves to a new value');
34
35 async_test(function(t) {
36     var scope = 'scope/re-register-while-old-registration-in-use';
37     var registration;
38
39     service_worker_unregister_and_register(t, worker_url, scope)
40       .then(function(r) {
41           registration = r;
42           return wait_for_update(t, registration);
43         })
44       .then(function(worker) {
45           return wait_for_state(t, worker, 'activated');
46         })
47       .then(function() {
48           return with_iframe(scope);
49         })
50       .then(function(frame) {
51           return registration.unregister();
52         })
53       .then(function() {
54           return navigator.serviceWorker.register(worker_url, { scope: scope });
55         })
56       .then(function(new_registration) {
57           assert_equals(registration, new_registration,
58                         'register should resolve to the same value');
59           service_worker_unregister_and_done(t, scope);
60         })
61       .catch(unreached_rejection(t));
62   }, 'Unregister then register resolves to the original value if the ' +
63          'registration is in use.');
64
65 async_test(function(t) {
66     var scope = 'scope/re-register-does-not-affect-existing-controllee';
67     var iframe;
68     var registration;
69     var controller;
70
71     service_worker_unregister_and_register(t, worker_url, scope)
72       .then(function(r) {
73           registration = r;
74           return wait_for_update(t, registration);
75         })
76       .then(function(worker) {
77           return wait_for_state(t, worker, 'activated');
78         })
79       .then(function() {
80           return with_iframe(scope);
81         })
82       .then(function(frame) {
83           iframe = frame;
84           controller = iframe.contentWindow.navigator.serviceWorker.controller;
85           return registration.unregister();
86         })
87       .then(function() {
88           return navigator.serviceWorker.register(worker_url, { scope: scope });
89         })
90       .then(function(registration) {
91           assert_equals(registration.installing, null,
92                         'installing version is null');
93           assert_equals(registration.waiting, null, 'waiting version is null');
94           assert_equals(
95               iframe.contentWindow.navigator.serviceWorker.controller,
96               controller,
97               'the worker from the first registration is the controller');
98           service_worker_unregister_and_done(t, scope);
99         })
100       .catch(unreached_rejection(t));
101   }, 'Unregister then register does not affect existing controllee');
102
103 async_test(function(t) {
104     var scope = 'scope/resurrection';
105     var iframe;
106     var registration;
107
108     service_worker_unregister_and_register(t, worker_url, scope)
109       .then(function(r) {
110           registration = r;
111           return wait_for_update(t, registration);
112         })
113       .then(function(worker) {
114           return wait_for_state(t, worker, 'activated');
115         })
116       .then(function() {
117           return with_iframe(scope);
118         })
119       .then(function(frame) {
120           iframe = frame;
121           return registration.unregister();
122         })
123       .then(function() {
124           return navigator.serviceWorker.register(worker_url, { scope: scope });
125         })
126       .then(function() {
127           return unload_iframe(iframe);
128         })
129       .then(function() {
130           return with_iframe(scope);
131         })
132       .then(function(frame) {
133           // FIXME: When crbug.com/400602 is fixed, assert that controller
134           // equals the original worker.
135           assert_not_equals(
136               frame.contentWindow.navigator.serviceWorker.controller, null,
137               'document should have a controller');
138           service_worker_unregister_and_done(t, scope);
139         })
140       .catch(unreached_rejection(t));
141   }, 'Unregister then register resurrects the registration');
142 </script>