[Cronet] Delay StartNetLog and StopNetLog until native request context is initialized
[chromium-blink-merge.git] / chrome / browser / devtools / device / webrtc / devtools_bridge_client_browsertest.js
blobdbb67385c9c3e78005c3031bb20bd85c5a650d46
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"');
8 /**
9 * Test fixture for DevToolsBridgeClientBrowserTest.
10 * @constructor
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,
20 /** @override */
21 typedefCppFixture: 'DevToolsBridgeClientBrowserTest',
23 /** @override */
24 isAsync: true,
26 /** @override */
27 browsePreload: DUMMY_URL,
29 setUp: function() {
30 this.callbacksMock = mock(DevToolsBridgeClientBrowserTest.NativeCallbacks);
31 window.callbacks = this.callbacksMock.proxy();
34 /**
35 * Simulates user sign in. DevToolsBridgeClient creates
36 * background_worker only in this case.
38 signIn: function() {
39 chrome.send('signIn', []);
40 return new Promise(function(resolve) {
41 this.callbacksMock.expects(once()).workerLoaded().will(
42 callFunction(resolve));
43 }.bind(this));
46 /**
47 * Creates GCD device definition which could be recognized as a
48 * DevToolsBridge.
50 * @param {string} id GCD instance id.
51 * @param {string} displayName Display name.
53 createInstanceDef: function(id, displayName) {
54 return {
55 'kind': 'clouddevices#device',
56 'deviceKind': 'vendor',
57 'id': id,
58 'displayName': displayName,
59 'commandDefs': {
60 'base': {
61 '_iceExchange': {'kind': 'clouddevices#commandDef'},
62 '_renegotiate': {'kind': 'clouddevices#commandDef'},
63 '_startSession': {'kind': 'clouddevices#commandDef'},
70 /**
71 * Callbacks from native DevToolsBridgeClientBrowserTest.
72 * @constructor
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() {
83 testDone();
84 });
86 TEST_F('DevToolsBridgeClientBrowserTest', 'testSignIn', function() {
87 this.signIn().then(testDone);
88 });
90 TEST_F('DevToolsBridgeClientBrowserTest', 'testQueryBrowsers', function() {
91 this.signIn().then(function() {
92 chrome.send('queryDevices');
93 });
94 var savedArgs = new SaveMockArguments();
95 this.callbacksMock.expects(once()).gcdApiRequest(
96 savedArgs.match(ANYTHING), DEVICES_URL, '').will(
97 callFunctionWithSavedArgs(savedArgs, function(id) {
98 var response = {
99 'kind': 'clouddevices#devicesListResponse',
100 'devices': [
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]);
110 }.bind(this)));
112 var browsersCount = 3;
114 this.callbacksMock.expects(once()).browserListUpdated(browsersCount).will(
115 callFunction(testDone));