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

Side by Side Diff: chrome/test/data/budget_service/service_worker.js

Issue 2370103003: Added browser tests to test the BudgetAPI. Also added BudgetAPI to ExperimentalWebPlatformFeatures. (Closed)
Patch Set: Rebase and add script tag for result_queue.js to subscope tests. Created 4 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Accept messages from the test JavaScript to trigger worker based tests.
6 self.addEventListener('message', function (event) {
7 if (event.data.command == 'workerGet') {
8 workerGetBudget();
9 } else if (event.data.command == 'workerReserve') {
10 workerReserve();
11 } else {
12 sendMessageToClients('message', 'error - unknown message request');
13 return;
14 }
15 });
16
17 // Query for the budget and return the current total.
18 function workerGetBudget() {
19 navigator.budget.getBudget().then(function(budget) {
20 sendMessageToClients('message',
21 'ok - budget returned value of ' + budget[0].budgetAt);
22 }, function() {
23 sendMessageToClients('message', 'failed - unable to get budget values');
24 });
25 }
26
27 // Request a reservation for a silent push.
28 function workerReserve() {
29 navigator.budget.reserve('silent-push').then(function(reserved) {
30 if (reserved)
31 sendMessageToClients('message', 'ok - reserved budget');
32 else
33 sendMessageToClients('message', 'failed - not able to reserve budget');
34 }, function() {
35 sendMessageToClients('message',
36 'failed - error while trying to reserve budget');
37 });
38 }
39
40 function sendMessageToClients(type, data) {
41 const message = JSON.stringify({
42 'type': type,
43 'data': data
44 });
45 clients.matchAll().then(function(clients) {
46 clients.forEach(function(client) {
47 client.postMessage(message);
48 });
49 }, function(error) {
50 console.log(error);
51 });
52 }
OLDNEW
« no previous file with comments | « chrome/test/data/budget_service/budget_test.js ('k') | chrome/test/data/budget_service/test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698