| 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..8251e1fe7019cb16bd5e093af082bb5e61583999
|
| --- /dev/null
|
| +++ b/chrome/test/data/extensions/api_test/runtime/restartOnWatchdog/test.js
|
| @@ -0,0 +1,86 @@
|
| +// 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();
|
| + if ((end - start) < 2000) {
|
| + 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();
|
| + if ((end - start) < 3000) {
|
| + console.log('Error: Request was not throttled properly: ' +
|
| + (end - start) + ' ms.');
|
| + fail();
|
| + }
|
| +
|
| + succeed();
|
| + });
|
| + });
|
| + }
|
| +
|
| +]);
|
|
|