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

Unified Diff: extensions/test/data/keep_alive_client_unittest.js

Issue 669303002: Add an extensions keep-alive client. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@keep-alive-service
Patch Set: keep alive client tests Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/renderer/resources/keep_alive.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/test/data/keep_alive_client_unittest.js
diff --git a/extensions/test/data/keep_alive_client_unittest.js b/extensions/test/data/keep_alive_client_unittest.js
new file mode 100644
index 0000000000000000000000000000000000000000..7b88fb0a8ecdc4e4061555d8063ddc4b172babae
--- /dev/null
+++ b/extensions/test/data/keep_alive_client_unittest.js
@@ -0,0 +1,44 @@
+// Copyright 2014 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.
+
+/**
+ * Unit tests for the keep-alive client.
+ *
+ * They are launched by extensions/renderer/mojo/keep_alive_client_unittest.cc.
+ */
+
+var test = require('test').binding;
+var unittestBindings = require('test_environment_specific_bindings');
+var utils = require('utils');
+
+var shouldSucceed;
+
+// We need to set custom bindings for a real API and serial.getDevices has a
+// simple signature.
+var binding = require('binding').Binding.create('serial');
+binding.registerCustomHook(function(bindingsAPI) {
+ bindingsAPI.apiFunctions.setHandleRequestWithPromise('getDevices',
+ function() {
+ if (shouldSucceed)
+ return Promise.resolve([]);
+ else
+ return Promise.reject();
+ });
+});
+var apiFunction = binding.generate().getDevices;
+
+unittestBindings.exportTests([
+ // Test that a keep alive is created and destroyed for a successful API call.
+ function testKeepAliveWithSuccessfulCall() {
+ shouldSucceed = true;
+ utils.promise(apiFunction).then(test.succeed, test.fail);
+ },
+
+ // Test that a keep alive is created and destroyed for an unsuccessful API
+ // call.
+ function testKeepAliveWithError() {
+ shouldSucceed = false;
+ utils.promise(apiFunction).then(test.fail, test.succeed);
+ },
+], test.runTests, exports);
« no previous file with comments | « extensions/renderer/resources/keep_alive.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698