Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 function onMessageDefault(e) { | |
|
jsbell
2014/11/13 23:07:50
Please rename file to skip-waiting-worker.js, to m
xiang
2014/11/28 08:00:47
Done.
| |
| 2 var message = e.data; | |
| 3 if ('port' in message) { | |
| 4 if (self.done) | |
|
jsbell
2014/11/13 23:07:50
The way this worker is designed, if anything fails
xiang
2014/11/28 08:00:47
Done.
| |
| 5 message.port.postMessage('done'); | |
| 6 } | |
| 7 } | |
| 8 | |
| 9 function testSkipWaiting() { | |
| 10 onmessage = onMessageDefault; | |
| 11 | |
| 12 skipWaiting() | |
|
jsbell
2014/11/13 23:07:50
Just as a style thing, we tend to use self.onmessa
xiang
2014/11/28 08:00:47
Done.
| |
| 13 .then(function(result) { | |
| 14 if (result === undefined) | |
|
jsbell
2014/11/13 23:07:50
otherwise, throw so the promise rejects? (see comm
xiang
2014/11/28 08:00:47
Done.
| |
| 15 self.done = true; | |
| 16 }); | |
| 17 } | |
| 18 | |
| 19 function testMultipleSkipWaiting() { | |
| 20 onmessage = onMessageDefault; | |
| 21 | |
| 22 var promises = []; | |
| 23 for (var i = 0; i < 8; ++i) { | |
| 24 promises.push(skipWaiting()); | |
| 25 } | |
| 26 Promise.all(promises) | |
| 27 .then(function(results) { | |
| 28 self.done = true; | |
| 29 }); | |
| 30 } | |
| 31 | |
| 32 function testSkipWaitingAfterInstalled() { | |
| 33 var sate = 'starting'; | |
|
jsbell
2014/11/13 23:07:50
This line doesn't look like it does anything? line
xiang
2014/11/28 08:00:47
Done.
| |
| 34 | |
| 35 onmessage = function(e) { | |
| 36 var message = e.data; | |
| 37 if ('port' in message) { | |
| 38 var messagePort = message.port; | |
| 39 if (self.state !== 'installing') { | |
| 40 messagePort.postMessage(state); | |
| 41 return; | |
| 42 } | |
| 43 skipWaiting() | |
| 44 .then(function() { | |
| 45 messagePort.postMessage(state); | |
| 46 }); | |
| 47 } | |
| 48 }; | |
| 49 | |
| 50 oninstall = function() { | |
| 51 state = 'installing'; | |
|
jsbell
2014/11/13 23:07:50
Be consistent with tests above (i.e. use self.stat
xiang
2014/11/28 08:00:47
Done.
| |
| 52 }; | |
| 53 | |
| 54 onactivate = function() { | |
| 55 state = 'activating'; | |
| 56 }; | |
| 57 } | |
| 58 | |
| 59 if (scope.match('blank')) { | |
|
jsbell
2014/11/13 23:07:50
Use /blank/ to make it clear the match is being do
| |
| 60 testSkipWaitingAfterInstalled(); | |
| 61 } else if (scope.match('multiple-skip-waiting')) { | |
|
jsbell
2014/11/13 23:07:50
Use /multiple-skip-waiting/
xiang
2014/11/28 08:00:47
don't need them anymore.
| |
| 62 testMultipleSkipWaiting(); | |
| 63 } else { | |
| 64 testSkipWaiting(); | |
| 65 } | |
| OLD | NEW |