Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // TODO(nhiroki): stop using global states because service workers can be killed | 1 // TODO(nhiroki): stop using global states because service workers can be killed |
| 2 // at any point (http://crbug.com/558244). | 2 // at any point (http://crbug.com/558244). |
| 3 self.state = 'starting'; | 3 self.state = 'starting'; |
| 4 | 4 |
| 5 self.addEventListener('install', function() { | 5 self.addEventListener('install', function() { |
| 6 self.state = 'installing'; | 6 self.state = 'installing'; |
| 7 }); | 7 }); |
| 8 | 8 |
| 9 self.addEventListener('activate', function() { | 9 self.addEventListener('activate', function() { |
| 10 self.state = 'activating'; | 10 self.state = 'activating'; |
| 11 }); | 11 }); |
| 12 | 12 |
| 13 self.addEventListener('message', function(event) { | 13 self.addEventListener('message', function(event) { |
| 14 var port = event.data.port; | 14 var port = event.data.port; |
| 15 if (self.state !== 'installing') { | 15 if (self.state !== 'installing') { |
| 16 port.postMessage('FAIL: Worker should be waiting in installed state'); | 16 port.postMessage('FAIL: Worker should be waiting in installed state'); |
| 17 return; | 17 return; |
| 18 } | 18 } |
| 19 event.waitUntil(self.skipWaiting() | 19 event.waitUntil(self.skipWaiting() |
| 20 .then(function(result) { | 20 .then(function(result) { |
| 21 if (result !== undefined) { | 21 if (result !== undefined) { |
| 22 port.postMessage('FAIL: Promise should be resolved with undefined'); | 22 port.postMessage('FAIL: Promise should be resolved with undefined'); |
| 23 return; | 23 return; |
| 24 } | 24 } |
| 25 if (self.state !== 'activating') { | 25 if (self.state !== 'activating') { |
| 26 port.postMessage( | 26 port.postMessage( |
| 27 'FAIL: Promise should be resolved after worker activated'); | 27 'This assertion is invalid. See https://crbug.com/725616'); |
|
falken
2017/05/29 03:54:17
I'd be more explicit. The negative asserts in this
mike3
2017/05/29 15:11:49
Done.
| |
| 28 return; | 28 return; |
| 29 } | 29 } |
| 30 port.postMessage('PASS'); | 30 port.postMessage('PASS'); |
| 31 }) | 31 }) |
| 32 .catch(function(e) { | 32 .catch(function(e) { |
| 33 port.postMessage('FAIL: unexpected exception: ' + e); | 33 port.postMessage('FAIL: unexpected exception: ' + e); |
| 34 })); | 34 })); |
| 35 }); | 35 }); |
| OLD | NEW |