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>
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');
21 return with_iframe(scope
);
25 return navigator
.serviceWorker
.register(url2
, {scope
: scope
});
27 .then(function(registration
) {
28 return wait_for_state(t
, registration
.installing
, 'installed');
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');
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');
50 return service_worker_unregister_and_done(t
, scope
);
52 }, 'Test skipWaiting with both active and waiting workers');