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

Side by Side Diff: content/test/data/background_sync/service_worker.js

Issue 1358063004: Use mojo to connect to BackgroundSyncManager object (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix crash in HasWindowProviderHost Created 5 years, 2 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 | « content/test/data/background_sync/background_sync_test_helpers.js ('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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // The "onsync" event currently understands commands (passed as 5 // The "onsync" event currently understands commands (passed as
6 // registration tags) coming from the test. Any other tag is 6 // registration tags) coming from the test. Any other tag is
7 // passed through to the document unchanged. 7 // passed through to the document unchanged.
8 // 8 //
9 // "delay" - Delays finishing the sync event with event.waitUntil. 9 // "delay" - Delays finishing the sync event with event.waitUntil.
10 // Send a postMessage of "completeDelayedOneShot" to finish the 10 // Send a postMessage of "completeDelayedOneShot" to finish the
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 sendMessageToClients('sync', 'ok - ' + tag + ' done'); 45 sendMessageToClients('sync', 'ok - ' + tag + ' done');
46 return syncRegistration.done; 46 return syncRegistration.done;
47 }) 47 })
48 .then(function(success) { 48 .then(function(success) {
49 sendMessageToClients('sync', tag + " done result: " + success); 49 sendMessageToClients('sync', tag + " done result: " + success);
50 }, function(error) { 50 }, function(error) {
51 sendMessageToClients('sync', tag + " done result: error"); 51 sendMessageToClients('sync', tag + " done result: error");
52 }) 52 })
53 .catch(sendSyncErrorToClients); 53 .catch(sendSyncErrorToClients);
54 } 54 }
55
56 if (event.data['action'] === 'registerOneShot') {
57 var tag = event.data['tag'];
58 registration.sync.register({'tag': tag})
59 .then(function (syncRegistration) {
60 sendMessageToClients('register', 'ok - ' + tag + ' registered in SW');
61 })
62 .catch(sendSyncErrorToClients);
63 }
64
65 if (event.data['action'] === 'getRegistrationOneShot') {
66 var tag = event.data['tag'];
67 registration.sync.getRegistration(tag)
68 .then(function(syncRegistration) {
69 if (!syncRegistration) {
70 sendMessageToClients('register', 'error - ' + tag + ' not found');
71 return;
72 }
73 sendMessageToClients('register', 'ok - ' + tag + ' found');
74 })
75 .catch(sendSyncErrorToClients);
76 }
77
78 if (event.data['action'] === 'getRegistrationsOneShot') {
79 registration.sync.getRegistrations()
80 .then(function(syncRegistrations) {
81 var tags = syncRegistrations.map(function(syncRegistration) {
82 return syncRegistration.tag;
83 });
84 sendMessageToClients('register', 'ok - ' + tags.toString());
85 })
86 .catch(sendSyncErrorToClients);
87 }
55 } 88 }
56 89
57 this.onsync = function(event) { 90 this.onsync = function(event) {
58 var eventProperties = [ 91 var eventProperties = [
59 // Extract name from toString result: "[object <Class>]" 92 // Extract name from toString result: "[object <Class>]"
60 Object.prototype.toString.call(event).match(/\s([a-zA-Z]+)/)[1], 93 Object.prototype.toString.call(event).match(/\s([a-zA-Z]+)/)[1],
61 (typeof event.waitUntil) 94 (typeof event.waitUntil)
62 ]; 95 ];
63 96
64 if (eventProperties[0] != 'SyncEvent') { 97 if (eventProperties[0] != 'SyncEvent') {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 client.postMessage({type, data}); 141 client.postMessage({type, data});
109 }); 142 });
110 }, function(error) { 143 }, function(error) {
111 console.log(error); 144 console.log(error);
112 }); 145 });
113 } 146 }
114 147
115 function sendSyncErrorToClients(error) { 148 function sendSyncErrorToClients(error) {
116 sendMessageToClients('sync', error.name + ' - ' + error.message); 149 sendMessageToClients('sync', error.name + ' - ' + error.message);
117 } 150 }
OLDNEW
« no previous file with comments | « content/test/data/background_sync/background_sync_test_helpers.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698