OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: Skip waiting</title> | 2 <title>Service Worker: Skip waiting</title> |
3 <script src="/resources/testharness.js"></script> | 3 <script src="/resources/testharness.js"></script> |
4 <script src="resources/testharness-helpers.js"></script> | |
5 <script src="/resources/testharnessreport.js"></script> | 4 <script src="/resources/testharnessreport.js"></script> |
6 <script src="resources/test-helpers.sub.js"></script> | 5 <script src="resources/test-helpers.sub.js"></script> |
7 <script> | 6 <script> |
| 7 'use strict'; |
8 | 8 |
9 promise_test(function(t) { | 9 promise_test(function(t) { |
10 var scope = 'resources/blank.html?skip-waiting'; | 10 var scope = 'resources/blank.html?skip-waiting'; |
11 var url1 = 'resources/empty.js'; | 11 var url1 = 'resources/empty.js'; |
12 var url2 = 'resources/empty-worker.js'; | 12 var url2 = 'resources/empty-worker.js'; |
13 var url3 = 'resources/skip-waiting-worker.js'; | 13 var url3 = 'resources/skip-waiting-worker.js'; |
14 var frame, sw_registration, activated_worker, waiting_worker; | 14 var sw_registration, activated_worker, waiting_worker; |
15 return service_worker_unregister_and_register(t, url1, scope) | 15 return service_worker_unregister_and_register(t, url1, scope) |
16 .then(function(registration) { | 16 .then(function(registration) { |
17 sw_registration = registration; | 17 sw_registration = registration; |
18 return wait_for_state(t, registration.installing, 'activated'); | 18 return wait_for_state(t, registration.installing, 'activated'); |
19 }) | 19 }) |
20 .then(function() { | 20 .then(function() { |
21 return with_iframe(scope); | 21 return with_iframe(scope); |
22 }) | 22 }) |
23 .then(function(f) { | 23 .then(function(f) { |
24 frame = f; | 24 t.add_cleanup(function() { |
| 25 f.remove(); |
| 26 }); |
25 return navigator.serviceWorker.register(url2, {scope: scope}); | 27 return navigator.serviceWorker.register(url2, {scope: scope}); |
26 }) | 28 }) |
27 .then(function(registration) { | 29 .then(function(registration) { |
28 return wait_for_state(t, registration.installing, 'installed'); | 30 return wait_for_state(t, registration.installing, 'installed'); |
29 }) | 31 }) |
30 .then(function() { | 32 .then(function() { |
31 activated_worker = sw_registration.active; | 33 activated_worker = sw_registration.active; |
32 waiting_worker = sw_registration.waiting; | 34 waiting_worker = sw_registration.waiting; |
33 assert_equals(activated_worker.scriptURL, normalizeURL(url1), | 35 assert_equals(activated_worker.scriptURL, normalizeURL(url1), |
34 'Worker with url1 should be activated'); | 36 'Worker with url1 should be activated'); |
35 assert_equals(waiting_worker.scriptURL, normalizeURL(url2), | 37 assert_equals(waiting_worker.scriptURL, normalizeURL(url2), |
36 'Worker with url2 should be waiting'); | 38 'Worker with url2 should be waiting'); |
37 return navigator.serviceWorker.register(url3, {scope: scope}); | 39 return navigator.serviceWorker.register(url3, {scope: scope}); |
38 }) | 40 }) |
39 .then(function(registration) { | 41 .then(function(registration) { |
40 return wait_for_state(t, registration.installing, 'activated'); | 42 return wait_for_state(t, registration.installing, 'activated'); |
41 }) | 43 }) |
42 .then(function() { | 44 .then(function() { |
43 assert_equals(activated_worker.state, 'redundant', | 45 assert_equals(activated_worker.state, 'redundant', |
44 'Worker with url1 should be redundant'); | 46 'Worker with url1 should be redundant'); |
45 assert_equals(waiting_worker.state, 'redundant', | 47 assert_equals(waiting_worker.state, 'redundant', |
46 'Worker with url2 should be redundant'); | 48 'Worker with url2 should be redundant'); |
47 assert_equals(sw_registration.active.scriptURL, normalizeURL(url3), | 49 assert_equals(sw_registration.active.scriptURL, normalizeURL(url3), |
48 'Worker with url3 should be activated'); | 50 'Worker with url3 should be activated'); |
49 frame.remove(); | |
50 return service_worker_unregister_and_done(t, scope); | 51 return service_worker_unregister_and_done(t, scope); |
51 }); | 52 }); |
52 }, 'Test skipWaiting with both active and waiting workers'); | 53 }, 'Test skipWaiting with both active and waiting workers'); |
53 | 54 |
54 </script> | 55 </script> |
OLD | NEW |