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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.js
diff --git a/chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.js b/chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.js
new file mode 100644
index 0000000000000000000000000000000000000000..dbb67385c9c3e78005c3031bb20bd85c5a650d46
--- /dev/null
+++ b/chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.js
@@ -0,0 +1,116 @@
+// 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.
+
+GEN('#include "chrome/browser/devtools/device/webrtc/' +
+ 'devtools_bridge_client_browsertest.h"');
+
+/**
+ * Test fixture for DevToolsBridgeClientBrowserTest.
+ * @constructor
+ * @extends {testing.Test}
+ */
+function DevToolsBridgeClientBrowserTest() {}
+
+var DEVICES_URL = "https://www.googleapis.com/clouddevices/v1/devices";
+
+DevToolsBridgeClientBrowserTest.prototype = {
+ __proto__: testing.Test.prototype,
+
+ /** @override */
+ typedefCppFixture: 'DevToolsBridgeClientBrowserTest',
+
+ /** @override */
+ isAsync: true,
+
+ /** @override */
+ browsePreload: DUMMY_URL,
+
+ setUp: function() {
+ this.callbacksMock = mock(DevToolsBridgeClientBrowserTest.NativeCallbacks);
+ window.callbacks = this.callbacksMock.proxy();
+ },
+
+ /**
+ * Simulates user sign in. DevToolsBridgeClient creates
+ * background_worker only in this case.
+ */
+ signIn: function() {
+ chrome.send('signIn', []);
+ return new Promise(function(resolve) {
+ this.callbacksMock.expects(once()).workerLoaded().will(
+ callFunction(resolve));
+ }.bind(this));
+ },
+
+ /**
+ * Creates GCD device definition which could be recognized as a
+ * DevToolsBridge.
+ *
+ * @param {string} id GCD instance id.
+ * @param {string} displayName Display name.
+ */
+ createInstanceDef: function(id, displayName) {
+ return {
+ 'kind': 'clouddevices#device',
+ 'deviceKind': 'vendor',
+ 'id': id,
+ 'displayName': displayName,
+ 'commandDefs': {
+ 'base': {
+ '_iceExchange': {'kind': 'clouddevices#commandDef'},
+ '_renegotiate': {'kind': 'clouddevices#commandDef'},
+ '_startSession': {'kind': 'clouddevices#commandDef'},
+ }
+ },
+ };
+ }
+};
+
+/**
+ * Callbacks from native DevToolsBridgeClientBrowserTest.
+ * @constructor
+ */
+DevToolsBridgeClientBrowserTest.NativeCallbacks = function() {}
+
+DevToolsBridgeClientBrowserTest.NativeCallbacks.prototype = {
+ workerLoaded: function() {},
+ gcdApiRequest: function(id, body) {},
+ browserListUpdated: function(count) {},
+};
+
+TEST_F('DevToolsBridgeClientBrowserTest', 'testSetUpOnMainThread', function() {
+ testDone();
+});
+
+TEST_F('DevToolsBridgeClientBrowserTest', 'testSignIn', function() {
+ this.signIn().then(testDone);
+});
+
+TEST_F('DevToolsBridgeClientBrowserTest', 'testQueryBrowsers', function() {
+ this.signIn().then(function() {
+ chrome.send('queryDevices');
+ });
+ var savedArgs = new SaveMockArguments();
+ this.callbacksMock.expects(once()).gcdApiRequest(
+ savedArgs.match(ANYTHING), DEVICES_URL, '').will(
+ callFunctionWithSavedArgs(savedArgs, function(id) {
+ var response = {
+ 'kind': 'clouddevices#devicesListResponse',
+ 'devices': [
+ this.createInstanceDef(
+ 'ab911465-83c7-e335-ea64-cb656868cbe0', 'Test 1'),
+ this.createInstanceDef(
+ 'ab911465-83c7-e335-ea64-cb656868cbe1', 'Test 2'),
+ this.createInstanceDef(
+ 'ab911465-83c7-e335-ea64-cb656868cbe2', 'Test 3'),
+ ],
+ };
+ chrome.send('gcdApiResponse', [id, response]);
+ }.bind(this)));
+
+ var browsersCount = 3;
+
+ this.callbacksMock.expects(once()).browserListUpdated(browsersCount).will(
+ callFunction(testDone));
+});

Powered by Google App Engine
This is Rietveld 408576698