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

Side by Side Diff: chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.js

Issue 791083005: Browser tests for DevToolsBridgeClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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 unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 GEN('#include "chrome/browser/devtools/device/webrtc/' +
6 'devtools_bridge_client_browsertest.h"');
7
8 /**
9 * Test fixture for DevToolsBridgeClientBrowserTest.
10 * @constructor
11 * @extends {testing.Test}
12 */
13 function DevToolsBridgeClientBrowserTest() {}
14
15 var DEVICES_URL = "https://www.googleapis.com/clouddevices/v1/devices";
16
17 DevToolsBridgeClientBrowserTest.prototype = {
18 __proto__: testing.Test.prototype,
19
20 /** @override */
21 typedefCppFixture: 'DevToolsBridgeClientBrowserTest',
22
23 /** @override */
24 isAsync: true,
25
26 /** @override */
27 browsePreload: DUMMY_URL,
28
29 setUp: function() {
30 this.callbacksMock = mock(DevToolsBridgeClientBrowserTest.NativeCallbacks);
31 window.callbacks = this.callbacksMock.proxy();
32 },
33
34 /**
35 * Simulates user sign in. DevToolsBridgeClient creates
36 * background_worker only in this case.
37 */
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));
44 },
45
46 /**
47 * Creates GCD device definition with could be recognized as a DevToolsBridge.
dgozman 2014/12/22 17:08:38 typo: with -> which
SeRya 2014/12/22 17:14:42 Done.
48 *
49 * @param {string} id GCD instance id.
50 * @param {string} displayName Display name.
51 */
52 createInstanceDef: function(id, displayName) {
53 return {
54 'kind': 'clouddevices#device',
55 'deviceKind': 'vendor',
56 'id': id,
57 'displayName': displayName,
58 'commandDefs': {
59 'base': {
60 '_iceExchange': {'kind': 'clouddevices#commandDef'},
61 '_renegotiate': {'kind': 'clouddevices#commandDef'},
62 '_startSession': {'kind': 'clouddevices#commandDef'},
63 }
64 },
65 };
66 }
67 };
68
69 /**
70 * Callbacks from native DevToolsBridgeClientBrowserTest.
71 * @constructor
72 */
73 DevToolsBridgeClientBrowserTest.NativeCallbacks = function() {}
74
75 DevToolsBridgeClientBrowserTest.NativeCallbacks.prototype = {
76 workerLoaded: function() {},
77 gcdApiRequest: function(id, body) {},
78 browserListUpdated: function(count) {},
79 };
80
81 TEST_F('DevToolsBridgeClientBrowserTest', 'testSetUpOnMainThread', function() {
82 testDone();
83 });
84
85 TEST_F('DevToolsBridgeClientBrowserTest', 'testSignIn', function() {
86 this.signIn().then(testDone);
87 });
88
89 TEST_F('DevToolsBridgeClientBrowserTest', 'testQueryBrowsers', function() {
90 this.signIn().then(function() {
91 chrome.send('queryDevices');
92 });
93 var savedArgs = new SaveMockArguments();
94 this.callbacksMock.expects(once()).gcdApiRequest(
95 savedArgs.match(ANYTHING), DEVICES_URL, '').will(
96 callFunctionWithSavedArgs(savedArgs, function(id) {
97 var response = {
98 'kind': 'clouddevices#devicesListResponse',
99 'devices': [
100 this.createInstanceDef(
101 'ab911465-83c7-e335-ea64-cb656868cbe0', 'Test 1'),
102 this.createInstanceDef(
103 'ab911465-83c7-e335-ea64-cb656868cbe1', 'Test 2'),
104 this.createInstanceDef(
105 'ab911465-83c7-e335-ea64-cb656868cbe2', 'Test 3'),
106 ],
107 };
108 chrome.send('gcdApiResponse', [id, response]);
109 }.bind(this)));
110
111 this.callbacksMock.expects(once()).browserListUpdated(3).will(
dgozman 2014/12/22 17:08:38 Let's make 3 a named constant, e.g. |var browsersC
SeRya 2014/12/22 17:14:42 Done.
112 callFunction(testDone));
113 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698