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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698