Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / resources / extendable-event-waituntil.js
blob48fdf1b99fd1931818e64f57c78af2fbe1087c50
1 var pendingPorts = [];
2 var portResolves = [];
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   }
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       });
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     });
43 function stripScopeName(url) {
44   return url.split('/').slice(-1)[0];
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   }
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   }