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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/budget/resources/instrumentation-service-worker.js

Issue 2571453002: Expose the BudgetService interface to Workers. (Closed)
Patch Set: Created 4 years 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
1 // Allows a document to exercise the Budget API within a service worker by sendi ng commands. 1 // Allows a document to exercise the Budget API within a service worker by sendi ng commands.
2 2
3 self.addEventListener('message', function(workerEvent) { 3 self.addEventListener('message', function(workerEvent) {
4 port = workerEvent.data; 4 port = workerEvent.data;
5 5
6 // Listen to incoming commands on the message port. 6 // Listen to incoming commands on the message port.
7 port.onmessage = function(event) { 7 port.onmessage = function(event) {
8 if (typeof event.data != 'object' || !event.data.command) 8 if (typeof event.data != 'object' || !event.data.command)
9 return; 9 return;
10 var options = event.data.options || {}; 10 var options = event.data.options || {};
(...skipping 28 matching lines...) Expand all
39 break; 39 break;
40 40
41 case 'reserve': 41 case 'reserve':
42 navigator.budget.reserve('silent-push').then(success => { 42 navigator.budget.reserve('silent-push').then(success => {
43 port.postMessage({ 43 port.postMessage({
44 command: event.data.command, 44 command: event.data.command,
45 success: success }); 45 success: success });
46 }).catch(makeErrorHandler(event.data.command)); 46 }).catch(makeErrorHandler(event.data.command));
47 break; 47 break;
48 48
49 case 'checkInterfaces':
50 var success = false;
51 var message = "";
52 try {
53 if ('BudgetService' in self &&
54 WorkerNavigator.prototype.hasOwnProperty('budget') &&
55 BudgetService.prototype.hasOwnProperty('getCost') &&
56 BudgetService.prototype.hasOwnProperty('getBudget') &&
57 BudgetService.prototype.hasOwnProperty('reserve')
58 )
59 success = true;
60 } catch(err) {
61 message = err.message;
62 }
Peter Beverloo 2016/12/12 14:28:43 What exception do you expect to be thrown here? I
harkness 2016/12/12 16:00:34 Updated the code to remove the if statement, but l
63 port.postMessage({
64 command: event.data.command,
65 success: success,
66 message: message});
67 break;
68
49 default: 69 default:
50 port.postMessage({ 70 port.postMessage({
51 command: 'error', 71 command: 'error',
52 errorMessage: 'Invalid command: ' + event.data.command }); 72 errorMessage: 'Invalid command: ' + event.data.command });
53 break; 73 break;
54 } 74 }
55 }; 75 };
56 76
57 // Notify the controller that the worker is now available. 77 // Notify the controller that the worker is now available.
58 port.postMessage('ready'); 78 port.postMessage('ready');
59 }); 79 });
60 80
61 function makeErrorHandler(command) { 81 function makeErrorHandler(command) {
62 return function(error) { 82 return function(error) {
63 var errorMessage = error ? error.message : 'unknown error'; 83 var errorMessage = error ? error.message : 'unknown error';
64 port.postMessage({ 84 port.postMessage({
65 command: command, 85 command: command,
66 success: false, 86 success: false,
67 errorMessage: errorMessage }); 87 errorMessage: errorMessage });
68 }; 88 };
69 } 89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698