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

Side by Side Diff: chrome/test/data/extensions/api_test/runtime/restartOnWatchdog/test.js

Issue 1970613003: Add a new app API to enable watchdog behavior restarts in kiosk apps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase + Nits Created 4 years, 7 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 var assertEq = chrome.test.assertEq;
6 var assertTrue = chrome.test.assertTrue;
7 var assertFalse = chrome.test.assertFalse;
8 var fail = chrome.test.fail;
9 var succeed = chrome.test.succeed;
10
11 chrome.test.runTests([
12
13 function testRestartOnWatchdog() {
14 chrome.runtime.restartOnWatchdog(-1, function(success, message) {
15 // Even though there's nothing schduled right now, this call should
16 // succeed.
17 assertTrue(success);
18 assertEq(message, 'No more restarts are scheduled.');
19 });
20
21 chrome.runtime.restartOnWatchdog(1, function(success, message) {
22 // This will be canceled by the following call, and this callback should
23 // be invoked with the correct parameters.
24 assertFalse(success);
25 assertEq(message, 'Restart request was cancelled.');
26 });
27
28 chrome.runtime.restartOnWatchdog(1, function(success, message) {
29 // This will be canceled by the following call with -1, and this callback
30 // should be invoked with the correct parameters.
31 assertFalse(success);
32 assertEq(message, 'Restart request was cancelled.');
33 });
34
35 chrome.runtime.restartOnWatchdog(-1, function(success, message) {
36 // Even though there's nothing schduled right now, this call should
37 // succeed.
38 assertTrue(success);
39 assertEq(message, 'No more restarts are scheduled.');
40 });
41
42 // Currently no restarts are scheduled.
43
44 var start = Date.now();
45 chrome.runtime.restartOnWatchdog(2, function(success, message) {
46 assertTrue(success);
47 assertEq(message, 'Success.');
48
49 var end = Date.now();
50 // Use 1950 instead of 2000 to avoid any potential flakiness.
51 if ((end - start) < 1950) {
52 console.log('Error: Restarting sooner than requested: ' +
53 (end - start) + ' ms.');
54 fail();
55 }
56
57 succeed();
58 });
59 },
60
61 function testThrottlingRestartRequests() {
62 chrome.runtime.restartOnWatchdog(3, function(success, message) {
63 // This request will succeed.
64 assertTrue(success);
65
66 // Minimum duration allowed between two successive restarts are set to 3
67 // seconds in this test.
68 var start = Date.now();
69 chrome.runtime.restartOnWatchdog(1, function(success, message) {
70 // This request will be throttled. It will be executed not less than
71 // 3 seconds later than the previous one.
72 assertTrue(success);
73 assertEq(message, 'Success.');
74
75 var end = Date.now();
76 // Use 2950 instead of 3000 to avoid any potential flakiness.
77 if ((end - start) < 2950) {
78 console.log('Error: Request was not throttled properly: ' +
79 (end - start) + ' ms.');
80 fail();
81 }
82
83 succeed();
84 });
85 });
86 }
87
88 ]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698