Index: LayoutTests/http/tests/serviceworker/resources/skip-waiting.js |
diff --git a/LayoutTests/http/tests/serviceworker/resources/skip-waiting.js b/LayoutTests/http/tests/serviceworker/resources/skip-waiting.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9d279f3370e5af4669b23f88b6afaf67338b7346 |
--- /dev/null |
+++ b/LayoutTests/http/tests/serviceworker/resources/skip-waiting.js |
@@ -0,0 +1,65 @@ |
+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.
|
+ var message = e.data; |
+ if ('port' in message) { |
+ 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.
|
+ message.port.postMessage('done'); |
+ } |
+} |
+ |
+function testSkipWaiting() { |
+ onmessage = onMessageDefault; |
+ |
+ 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.
|
+ .then(function(result) { |
+ 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.
|
+ self.done = true; |
+ }); |
+} |
+ |
+function testMultipleSkipWaiting() { |
+ onmessage = onMessageDefault; |
+ |
+ var promises = []; |
+ for (var i = 0; i < 8; ++i) { |
+ promises.push(skipWaiting()); |
+ } |
+ Promise.all(promises) |
+ .then(function(results) { |
+ self.done = true; |
+ }); |
+} |
+ |
+function testSkipWaitingAfterInstalled() { |
+ 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.
|
+ |
+ onmessage = function(e) { |
+ var message = e.data; |
+ if ('port' in message) { |
+ var messagePort = message.port; |
+ if (self.state !== 'installing') { |
+ messagePort.postMessage(state); |
+ return; |
+ } |
+ skipWaiting() |
+ .then(function() { |
+ messagePort.postMessage(state); |
+ }); |
+ } |
+ }; |
+ |
+ oninstall = function() { |
+ 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.
|
+ }; |
+ |
+ onactivate = function() { |
+ state = 'activating'; |
+ }; |
+} |
+ |
+if (scope.match('blank')) { |
jsbell
2014/11/13 23:07:50
Use /blank/ to make it clear the match is being do
|
+ testSkipWaitingAfterInstalled(); |
+} 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.
|
+ testMultipleSkipWaiting(); |
+} else { |
+ testSkipWaiting(); |
+} |