summaryrefslogtreecommitdiffstats
path: root/chrome/browser/devtools/device/webrtc/devtools_bridge_client_browsertest.js
blob: dbb67385c9c3e78005c3031bb20bd85c5a650d46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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));
});