Remove linux_chromium_gn_dbg from the chromium CQ.
[chromium-blink-merge.git] / extensions / test / data / keep_alive_client_unittest.js
blob7b88fb0a8ecdc4e4061555d8063ddc4b172babae
1 // Copyright 2014 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.
5 /**
6  * Unit tests for the keep-alive client.
7  *
8  * They are launched by extensions/renderer/mojo/keep_alive_client_unittest.cc.
9  */
11 var test = require('test').binding;
12 var unittestBindings = require('test_environment_specific_bindings');
13 var utils = require('utils');
15 var shouldSucceed;
17 // We need to set custom bindings for a real API and serial.getDevices has a
18 // simple signature.
19 var binding = require('binding').Binding.create('serial');
20 binding.registerCustomHook(function(bindingsAPI) {
21   bindingsAPI.apiFunctions.setHandleRequestWithPromise('getDevices',
22       function() {
23     if (shouldSucceed)
24       return Promise.resolve([]);
25     else
26       return Promise.reject();
27   });
28 });
29 var apiFunction = binding.generate().getDevices;
31 unittestBindings.exportTests([
32   // Test that a keep alive is created and destroyed for a successful API call.
33   function testKeepAliveWithSuccessfulCall() {
34     shouldSucceed = true;
35     utils.promise(apiFunction).then(test.succeed, test.fail);
36   },
38   // Test that a keep alive is created and destroyed for an unsuccessful API
39   // call.
40   function testKeepAliveWithError() {
41     shouldSucceed = false;
42     utils.promise(apiFunction).then(test.fail, test.succeed);
43   },
44 ], test.runTests, exports);