Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / unregister-then-register-new-script.html
blobcc5ee7936347855d6f75764c887e9351ad8e0e5e
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';
8 async_test(function(t) {
9 var scope = 'resources/scope/unregister-then-register-new-script-that-exists';
10 var new_worker_url = worker_url + '?new';
11 var iframe;
12 var registration;
13 var new_registration;
15 service_worker_unregister_and_register(t, worker_url, scope)
16 .then(function(r) {
17 registration = r;
18 return wait_for_state(t, r.installing, 'activated');
20 .then(function() {
21 return with_iframe(scope);
23 .then(function(frame) {
24 iframe = frame;
25 return registration.unregister();
27 .then(function() {
28 return navigator.serviceWorker.register(new_worker_url,
29 { scope: scope });
31 .then(function(r) {
32 new_registration = r;
33 assert_equals(registration.installing.scriptURL,
34 normalizeURL(new_worker_url),
35 'before activated registration.installing');
36 assert_equals(registration.waiting, null,
37 'before activated registration.waiting');
38 assert_equals(registration.active.scriptURL, normalizeURL(worker_url),
39 'before activated registration.active');
40 assert_equals(new_registration.installing.scriptURL,
41 normalizeURL(new_worker_url),
42 'before activated new_registration.installing');
43 assert_equals(new_registration.waiting, null,
44 'before activated new_registration.waiting');
45 assert_equals(new_registration.active.scriptURL,
46 normalizeURL(worker_url),
47 'before activated new_registration.active');
48 iframe.remove();
49 return wait_for_state(t, registration.installing, 'activated');
51 .then(function() {
52 assert_equals(new_registration.installing, null,
53 'after activated new_registration.installing');
54 assert_equals(new_registration.waiting, null,
55 'after activated new_registration.waiting');
56 assert_equals(new_registration.active.scriptURL,
57 normalizeURL(new_worker_url),
58 'after activated new_registration.active');
59 return with_iframe(scope);
61 .then(function(frame) {
62 assert_equals(
63 frame.contentWindow.navigator.serviceWorker.controller.scriptURL,
64 normalizeURL(new_worker_url),
65 'the new worker should control a new document');
66 frame.remove();
67 return registration.unregister();
69 .then(function() {
70 t.done();
72 .catch(unreached_rejection(t));
73 }, 'Registering a new script URL while an unregistered registration is in use');
75 async_test(function(t) {
76 var scope = 'resources/scope/unregister-then-register-new-script-that-404s';
77 var iframe;
78 var registration;
80 service_worker_unregister_and_register(t, worker_url, scope)
81 .then(function(r) {
82 registration = r;
83 return wait_for_state(t, r.installing, 'activated');
85 .then(function() {
86 return with_iframe(scope);
88 .then(function(frame) {
89 iframe = frame;
90 return registration.unregister();
92 .then(function() {
93 var promise = navigator.serviceWorker.register('this-will-404',
94 { scope: scope });
95 iframe.remove();
96 return promise;
98 .then(
99 function() {
100 assert_unreached('register should reject the promise');
102 function() {
103 return with_iframe(scope);
105 .then(function(frame) {
106 assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
107 null,
108 'document should not load with a controller');
109 frame.remove();
110 t.done();
112 .catch(unreached_rejection(t));
113 }, 'Registering a new script URL that 404s does not resurrect an ' +
114 'unregistered registration');
116 async_test(function(t) {
117 var scope = 'resources/scope/unregister-then-register-reject-install-worker';
118 var iframe;
119 var registration;
121 service_worker_unregister_and_register(t, worker_url, scope)
122 .then(function(r) {
123 registration = r;
124 return wait_for_state(t, r.installing, 'activated');
126 .then(function() {
127 return with_iframe(scope);
129 .then(function(frame) {
130 iframe = frame;
131 return registration.unregister();
133 .then(function() {
134 var promise = navigator.serviceWorker.register(
135 'resources/reject-install-worker.js', { scope: scope });
136 iframe.remove();
137 return promise;
139 .then(function(r) {
140 registration = r;
141 return wait_for_state(t, r.installing, 'redundant');
143 .then(function() {
144 return with_iframe(scope);
146 .then(function(frame) {
147 assert_equals(frame.contentWindow.navigator.serviceWorker.controller,
148 null,
149 'document should not load with a controller');
150 frame.remove();
151 return registration.unregister();
153 .then(function() {
154 t.done();
156 .catch(unreached_rejection(t));
157 }, 'Registering a new script URL that fails to install does not resurrect ' +
158 'an unregistered registration');
159 </script>