Chromium Code Reviews| Index: content/test/data/background_sync/service_worker.js |
| diff --git a/content/test/data/background_sync/service_worker.js b/content/test/data/background_sync/service_worker.js |
| index 56be354933bffe02d4021c9b75ea32e6948e7641..08b910d219fc7f65fb4b90b5a7f410c659f0e639 100644 |
| --- a/content/test/data/background_sync/service_worker.js |
| +++ b/content/test/data/background_sync/service_worker.js |
| @@ -17,7 +17,7 @@ var resolveCallback = null; |
| var rejectCallback = null; |
| this.onmessage = function(event) { |
| - if (event.data === 'completeDelayedOneShot') { |
| + if (event.data['action'] === 'completeDelayedOneShot') { |
| if (resolveCallback === null) { |
| sendMessageToClients('sync', 'error - resolveCallback is null'); |
| return; |
| @@ -28,7 +28,7 @@ this.onmessage = function(event) { |
| return; |
| } |
| - if (event.data === 'rejectDelayedOneShot') { |
| + if (event.data['action'] === 'rejectDelayedOneShot') { |
| if (rejectCallback === null) { |
| sendMessageToClients('sync', 'error - rejectCallback is null'); |
| return; |
| @@ -37,6 +37,21 @@ this.onmessage = function(event) { |
| rejectCallback(); |
| sendMessageToClients('sync', 'ok - delay rejected'); |
| } |
| + |
| + if (event.data['action'] === 'notifyWhenDone') { |
| + var tag = event.data['tag']; |
| + registration.sync.getRegistration(tag) |
| + .then(function (syncRegistration) { |
| + sendMessageToClients('sync', 'ok - ' + tag + ' done'); |
| + return syncRegistration.done; |
| + }) |
| + .then(function(success) { |
| + sendMessageToClients('sync', tag + " done result: " + success); |
| + }, function(error) { |
| + sendMessageToClients('sync', tag + " done result: error"); |
| + }) |
| + .catch(sendSyncErrorToClients); |
| + } |
| } |
| this.onsync = function(event) { |
| @@ -96,3 +111,7 @@ function sendMessageToClients(type, data) { |
| console.log(error); |
| }); |
| } |
| + |
| +function sendSyncErrorToClients(error) { |
|
iclelland
2015/09/17 13:48:10
I'm sure there's an opportunity to refactor the re
jkarlin
2015/09/17 17:40:25
Acknowledged.
|
| + sendMessageToClients('sync', error.name + ' - ' + error.message); |
| +} |