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

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

Issue 2273743002: Framework and tests for WorkerNavigatorBudget (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo_service
Patch Set: Changed formatting of javascript in html files Created 4 years, 4 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
OLDNEW
(Empty)
1 // Allows a document to exercise the Budget API within a service worker by sendi ng commands.
2
3 self.addEventListener('message', function(workerEvent) {
4 port = workerEvent.data;
5
6 // Listen to incoming commands on the message port.
7 port.onmessage = function(event) {
8 if (typeof event.data != 'object' || !event.data.command)
9 return;
10 var options = event.data.options || {}
Peter Beverloo 2016/08/24 15:28:23 ;
harkness 2016/08/24 16:22:50 Done.
11 switch (event.data.command) {
12
13 case 'getCost':
14 navigator.budget.getCost('silent-push').then(function(cost) {
15 port.postMessage({ command: event.data.command,
16 success: true,
17 cost: cost });
Peter Beverloo 2016/08/24 15:28:23 The alignment of this (and lines 23+, 31+, 39+ and
harkness 2016/08/24 16:22:50 Done.
18 }).catch(makeErrorHandler(event.data.command));
19 break;
20
21 case 'getCostInvalidType':
22 navigator.budget.getCost('frobinator').then(function(cost) {
23 port.postMessage({ command: event.data.command,
24 success: true,
25 cost: cost });
26 }).catch(makeErrorHandler(event.data.command));
27 break;
28
29 case 'getBudget':
30 navigator.budget.getBudget().then(budget => {
31 port.postMessage({ command: event.data.command,
32 success: true,
33 budgetAt: budget[0].budgetAt,
34 time: budget[0].time });
35 }).catch(makeErrorHandler(event.data.command));
36 break;
37
38 default:
39 port.postMessage({ command: 'error',
40 errorMessage: 'Invalid command: ' + event.data.command });
41 break;
42 }
43 };
44
45 // Notify the controller that the worker is now available.
46 port.postMessage('ready');
47 });
48
49 function makeErrorHandler(command) {
50 return function(error) {
51 var errorMessage = error ? error.message : 'unknown error';
52 port.postMessage({ command: command,
53 success: false,
54 errorMessage: errorMessage });
55 };
56 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698