Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: LayoutTests/http/tests/serviceworker/resources/skip-waiting.js

Issue 723923002: ServiceWorker: Add support for .skipWaiting and controllerchange event(1/3) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+}

Powered by Google App Engine
This is Rietveld 408576698