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

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

Issue 2370103003: Added browser tests to test the BudgetAPI. Also added BudgetAPI to ExperimentalWebPlatformFeatures. (Closed)
Patch Set: Code review comments and separated out shared code. 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 'use strict';
6
7 // The ResultQueue is a mechanism for passing messages back to the test
8 // framework.
9 var resultQueue = new ResultQueue();
Peter Beverloo 2016/09/28 13:04:27 nit: const, on line 57 too (In general, you shoul
harkness 2016/09/28 14:34:19 Done.
10
11 function registerServiceWorker() {
12 // The base dir used to resolve service_worker.js.
13 navigator.serviceWorker.register('service_worker.js', {scope: './'}).then(
14 function(swRegistration) {
15 sendResultToTest('ok - service worker registered');
16 }, sendErrorToTest);
17 }
18
19 // Query for the budget and return the current total.
20 function documentGetBudget() {
21 navigator.budget.getBudget().then(function(budget) {
22 sendResultToTest("ok - budget returned value of " + budget[0].budgetAt);
23 }, function() {
24 sendResultToTest("failed - unable to get budget values");
25 });
26 }
27
28 // Request a reservation for a silent push.
29 function documentReserveBudget() {
30 navigator.budget.reserve('silent-push').then(function(reserved) {
31 if (reserved)
32 sendResultToTest("ok - reserved budget");
33 else
34 sendResultToTest("failed - not able to reserve budget");
35 }, function() {
36 sendResultToTest("failed - error while trying to reserve budget");
37 });
38 }
39
40 function workerGetBudget() {
41 navigator.serviceWorker.controller.postMessage({command: 'workerGet'});
42 }
43
44 function workerReserveBudget() {
45 navigator.serviceWorker.controller.postMessage({command: 'workerReserve'});
46 }
47
48 function isControlled() {
49 if (navigator.serviceWorker.controller) {
50 sendResultToTest('true - is controlled');
51 } else {
52 sendResultToTest('false - is not controlled');
53 }
54 }
55
56 navigator.serviceWorker.addEventListener('message', function(event) {
57 var message = JSON.parse(event.data);
58 if (message.type == 'push')
59 resultQueue.push(message.data);
60 else
61 sendResultToTest(message.data);
62 }, false);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698