2 <title>Service Worker: Skip waiting installed worker
</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/skip-waiting-installed-worker.js';
13 var frame
, frame_sw
, service_worker
, onmessage
, oncontrollerchanged
;
14 var saw_message
= new Promise(function(resolve
) {
15 onmessage = function(e
) {
19 'skipWaiting promise should be resolved after activated');
23 var saw_controllerchanged
= new Promise(function(resolve
) {
24 oncontrollerchanged = function() {
26 frame_sw
.controller
.scriptURL
, normalizeURL(url2
),
27 'Controller scriptURL should change to the second one');
31 return service_worker_unregister_and_register(t
, url1
, scope
)
32 .then(function(registration
) {
33 return wait_for_state(t
, registration
.installing
, 'activated');
36 return with_iframe(scope
);
40 frame_sw
= f
.contentWindow
.navigator
.serviceWorker
;
42 frame_sw
.controller
.scriptURL
, normalizeURL(url1
),
43 'Document controller scriptURL should equal to the first one');
44 frame_sw
.oncontrollerchange
= t
.step_func(oncontrollerchanged
);
45 return navigator
.serviceWorker
.register(url2
, {scope
: scope
});
47 .then(function(registration
) {
48 service_worker
= registration
.installing
;
49 return wait_for_state(t
, service_worker
, 'installed');
52 var channel
= new MessageChannel();
53 channel
.port1
.onmessage
= t
.step_func(onmessage
);
54 service_worker
.postMessage({port
: channel
.port2
}, [channel
.port2
]);
55 return Promise
.all([saw_message
, saw_controllerchanged
]);
59 return service_worker_unregister_and_done(t
, scope
);
61 }, 'Test skipWaiting when a installed worker is waiting');