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 GEN('#include "chrome/browser/devtools/device/webrtc/' +
6 'devtools_bridge_client_browsertest.h"');
9 * Test fixture for DevToolsBridgeClientBrowserTest.
11 * @extends {testing.Test}
13 function DevToolsBridgeClientBrowserTest() {}
15 var DEVICES_URL
= "https://www.googleapis.com/clouddevices/v1/devices";
17 DevToolsBridgeClientBrowserTest
.prototype = {
18 __proto__
: testing
.Test
.prototype,
21 typedefCppFixture
: 'DevToolsBridgeClientBrowserTest',
27 browsePreload
: DUMMY_URL
,
30 this.callbacksMock
= mock(DevToolsBridgeClientBrowserTest
.NativeCallbacks
);
31 window
.callbacks
= this.callbacksMock
.proxy();
35 * Simulates user sign in. DevToolsBridgeClient creates
36 * background_worker only in this case.
39 chrome
.send('signIn', []);
40 return new Promise(function(resolve
) {
41 this.callbacksMock
.expects(once()).workerLoaded().will(
42 callFunction(resolve
));
47 * Creates GCD device definition which could be recognized as a
50 * @param {string} id GCD instance id.
51 * @param {string} displayName Display name.
53 createInstanceDef: function(id
, displayName
) {
55 'kind': 'clouddevices#device',
56 'deviceKind': 'vendor',
58 'displayName': displayName
,
61 '_iceExchange': {'kind': 'clouddevices#commandDef'},
62 '_renegotiate': {'kind': 'clouddevices#commandDef'},
63 '_startSession': {'kind': 'clouddevices#commandDef'},
71 * Callbacks from native DevToolsBridgeClientBrowserTest.
74 DevToolsBridgeClientBrowserTest
.NativeCallbacks = function() {}
76 DevToolsBridgeClientBrowserTest
.NativeCallbacks
.prototype = {
77 workerLoaded: function() {},
78 gcdApiRequest: function(id
, body
) {},
79 browserListUpdated: function(count
) {},
82 TEST_F('DevToolsBridgeClientBrowserTest', 'testSetUpOnMainThread', function() {
86 TEST_F('DevToolsBridgeClientBrowserTest', 'testSignIn', function() {
87 this.signIn().then(testDone
);
90 TEST_F('DevToolsBridgeClientBrowserTest', 'testQueryBrowsers', function() {
91 this.signIn().then(function() {
92 chrome
.send('queryDevices');
94 var savedArgs
= new SaveMockArguments();
95 this.callbacksMock
.expects(once()).gcdApiRequest(
96 savedArgs
.match(ANYTHING
), DEVICES_URL
, '').will(
97 callFunctionWithSavedArgs(savedArgs
, function(id
) {
99 'kind': 'clouddevices#devicesListResponse',
101 this.createInstanceDef(
102 'ab911465-83c7-e335-ea64-cb656868cbe0', 'Test 1'),
103 this.createInstanceDef(
104 'ab911465-83c7-e335-ea64-cb656868cbe1', 'Test 2'),
105 this.createInstanceDef(
106 'ab911465-83c7-e335-ea64-cb656868cbe2', 'Test 3'),
109 chrome
.send('gcdApiResponse', [id
, response
]);
112 var browsersCount
= 3;
114 this.callbacksMock
.expects(once()).browserListUpdated(browsersCount
).will(
115 callFunction(testDone
));