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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/runtime/restartOnWatchdog/test.js
diff --git a/chrome/test/data/extensions/api_test/runtime/restartOnWatchdog/test.js b/chrome/test/data/extensions/api_test/runtime/restartOnWatchdog/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..f58d1dcf84361b4db4b7c427fa4ad005cc24ae71
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/runtime/restartOnWatchdog/test.js
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var assertEq = chrome.test.assertEq;
+var assertTrue = chrome.test.assertTrue;
+var assertFalse = chrome.test.assertFalse;
+var fail = chrome.test.fail;
+var succeed = chrome.test.succeed;
+
+chrome.test.runTests([
+
+ function testRestartOnWatchdog() {
+ chrome.runtime.restartOnWatchdog(-1, function(success, message) {
+ // Even though there's nothing schduled right now, this call should
+ // succeed.
+ assertTrue(success);
+ assertEq(message, 'No more restarts are scheduled.');
+ });
+
+ chrome.runtime.restartOnWatchdog(1, function(success, message) {
+ // This will be canceled by the following call, and this callback should
+ // be invoked with the correct parameters.
+ assertFalse(success);
+ assertEq(message, 'Restart request was cancelled.');
+ });
+
+ chrome.runtime.restartOnWatchdog(1, function(success, message) {
+ // This will be canceled by the following call with -1, and this callback
+ // should be invoked with the correct parameters.
+ assertFalse(success);
+ assertEq(message, 'Restart request was cancelled.');
+ });
+
+ chrome.runtime.restartOnWatchdog(-1, function(success, message) {
+ // Even though there's nothing schduled right now, this call should
+ // succeed.
+ assertTrue(success);
+ assertEq(message, 'No more restarts are scheduled.');
+ });
+
+ // Currently no restarts are scheduled.
+
+ var start = Date.now();
+ chrome.runtime.restartOnWatchdog(2, function(success, message) {
+ assertTrue(success);
+ assertEq(message, 'Success.');
+
+ var end = Date.now();
+ // Use 1950 instead of 2000 to avoid any potential flakiness.
+ if ((end - start) < 1950) {
+ console.log('Error: Restarting sooner than requested: ' +
+ (end - start) + ' ms.');
+ fail();
+ }
+
+ succeed();
+ });
+ },
+
+ function testThrottlingRestartRequests() {
+ chrome.runtime.restartOnWatchdog(3, function(success, message) {
+ // This request will succeed.
+ assertTrue(success);
+
+ // Minimum duration allowed between two successive restarts are set to 3
+ // seconds in this test.
+ var start = Date.now();
+ chrome.runtime.restartOnWatchdog(1, function(success, message) {
+ // This request will be throttled. It will be executed not less than
+ // 3 seconds later than the previous one.
+ assertTrue(success);
+ assertEq(message, 'Success.');
+
+ var end = Date.now();
+ // Use 2950 instead of 3000 to avoid any potential flakiness.
+ if ((end - start) < 2950) {
+ console.log('Error: Request was not throttled properly: ' +
+ (end - start) + ' ms.');
+ fail();
+ }
+
+ succeed();
+ });
+ });
+ }
+
+]);

Powered by Google App Engine
This is Rietveld 408576698