Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / resources / skip-waiting-installed-worker.js
blob12fdb47ba725c59f6aca71e1501c480a00e38ddd
1 self.state = 'starting';
3 self.addEventListener('install', function() {
4     self.state = 'installing';
5   });
7 self.addEventListener('activate', function() {
8     self.state = 'activating';
9   });
11 self.addEventListener('message', function(event) {
12     var port = event.data.port;
13     if (self.state !== 'installing') {
14       port.postMessage('FAIL: Worker should be waiting in installed state');
15       return;
16     }
17     self.skipWaiting()
18       .then(function(result) {
19           if (result !== undefined) {
20             port.postMessage('FAIL: Promise should be resolved with undefined');
21             return;
22           }
23           if (self.state !== 'activating') {
24             port.postMessage(
25                 'FAIL: Promise should be resolved after worker activated');
26             return;
27           }
28           port.postMessage('PASS');
29         })
30       .catch(function(e) {
31           port.postMessage('FAIL: unexpected exception: ' + e);
32         });
33   });