Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / skip-waiting.html
blob1bc34f523b1531989e43f3ace430d953fbec4bf4
1 <!DOCTYPE html>
2 <title>Service Worker: Skip waiting</title>
3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharness-helpers.js"></script>
5 <script src="../resources/testharnessreport.js"></script>
6 <script src="resources/test-helpers.js"></script>
7 <script>
9 promise_test(function(t) {
10 var scope = 'resources/blank.html';
11 var url1 = 'resources/empty.js';
12 var url2 = 'resources/empty-worker.js';
13 var url3 = 'resources/skip-waiting-worker.js';
14 var frame, sw_registration, activated_worker, waiting_worker;
15 return service_worker_unregister_and_register(t, url1, scope)
16 .then(function(registration) {
17 sw_registration = registration;
18 return wait_for_state(t, registration.installing, 'activated');
20 .then(function() {
21 return with_iframe(scope);
23 .then(function(f) {
24 frame = f;
25 return navigator.serviceWorker.register(url2, {scope: scope});
27 .then(function(registration) {
28 return wait_for_state(t, registration.installing, 'installed');
30 .then(function() {
31 activated_worker = sw_registration.active;
32 waiting_worker = sw_registration.waiting;
33 assert_equals(activated_worker.scriptURL, normalizeURL(url1),
34 'Worker with url1 should be activated');
35 assert_equals(waiting_worker.scriptURL, normalizeURL(url2),
36 'Worker with url2 should be waiting');
37 return navigator.serviceWorker.register(url3, {scope: scope});
39 .then(function(registration) {
40 return wait_for_state(t, registration.installing, 'activated');
42 .then(function() {
43 assert_equals(activated_worker.state, 'redundant',
44 'Worker with url1 should be redundant');
45 assert_equals(waiting_worker.state, 'redundant',
46 'Worker with url2 should be redundant');
47 assert_equals(sw_registration.active.scriptURL, normalizeURL(url3),
48 'Worker with url3 should be activated');
49 frame.remove();
50 return service_worker_unregister_and_done(t, scope);
51 });
52 }, 'Test skipWaiting with both active and waiting workers');
54 </script>