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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/extendable-event-waituntil.js

Issue 2789003002: Upstream service worker ext. event tests to WPT (Closed)
Patch Set: Created 3 years, 8 months 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
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/extendable-event-waituntil.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 var pendingPorts = [];
2 var portResolves = [];
3
4 onmessage = function(e) {
5 var message = e.data;
6 if ('port' in message) {
7 var resolve = self.portResolves.shift();
8 if (resolve)
9 resolve(message.port);
10 else
11 self.pendingPorts.push(message.port);
12 }
13 };
14
15 function fulfillPromise() {
16 return new Promise(function(resolve) {
17 // Make sure the oninstall/onactivate callback returns first.
18 Promise.resolve().then(function() {
19 var port = self.pendingPorts.shift();
20 if (port)
21 resolve(port);
22 else
23 self.portResolves.push(resolve);
24 });
25 }).then(function(port) {
26 port.postMessage('SYNC');
27 return new Promise(function(resolve) {
28 port.onmessage = function(e) {
29 if (e.data == 'ACK')
30 resolve();
31 };
32 });
33 });
34 }
35
36 function rejectPromise() {
37 return new Promise(function(resolve, reject) {
38 // Make sure the oninstall/onactivate callback returns first.
39 Promise.resolve().then(reject);
40 });
41 }
42
43 function stripScopeName(url) {
44 return url.split('/').slice(-1)[0];
45 }
46
47 oninstall = function(e) {
48 switch (stripScopeName(self.location.href)) {
49 case 'install-fulfilled':
50 e.waitUntil(fulfillPromise());
51 break;
52 case 'install-rejected':
53 e.waitUntil(rejectPromise());
54 break;
55 case 'install-multiple-fulfilled':
56 e.waitUntil(fulfillPromise());
57 e.waitUntil(fulfillPromise());
58 break;
59 case 'install-reject-precedence':
60 e.waitUntil(fulfillPromise());
61 e.waitUntil(rejectPromise());
62 break;
63 }
64 };
65
66 onactivate = function(e) {
67 switch (stripScopeName(self.location.href)) {
68 case 'activate-fulfilled':
69 e.waitUntil(fulfillPromise());
70 break;
71 case 'activate-rejected':
72 e.waitUntil(rejectPromise());
73 break;
74 }
75 };
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/serviceworker/extendable-event-waituntil.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698