1 // Copyright 2015 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.
6 /** @suppress {duplicate} */
7 var remoting = remoting || {};
13 /** @type {remoting.Me2MeTestDriver} */
16 QUnit.module('Me2Me Telemetry Integration', {
17 // We rely on our telemetry data to gain insight into the reliability and
18 // the durability on our connections. This test verifies the integrity of our
19 // telemetry by ensuring that certain well known connection sequences will
20 // generate the correct sequence of telemetry data.
21 beforeEach: function() {
22 testDriver = new remoting.Me2MeTestDriver();
24 afterEach: function() {
25 base.dispose(testDriver);
31 * @param {remoting.Me2MeTestDriver} testDriver
32 * @param {Object} baseEvent
34 var expectSucceeded = function(testDriver, baseEvent) {
35 var ChromotingEvent = remoting.ChromotingEvent;
37 session_state: ChromotingEvent.SessionState.STARTED,
39 session_state: ChromotingEvent.SessionState.SIGNALING,
40 previous_session_state: ChromotingEvent.SessionState.STARTED
42 session_state: ChromotingEvent.SessionState.CREATING_PLUGIN,
43 previous_session_state: ChromotingEvent.SessionState.SIGNALING
45 session_state: ChromotingEvent.SessionState.CONNECTING,
46 previous_session_state: ChromotingEvent.SessionState.CREATING_PLUGIN
48 session_state: ChromotingEvent.SessionState.AUTHENTICATED,
49 previous_session_state: ChromotingEvent.SessionState.CONNECTING
51 session_state: ChromotingEvent.SessionState.CONNECTED,
52 previous_session_state: ChromotingEvent.SessionState.AUTHENTICATED
54 session_state: ChromotingEvent.SessionState.CLOSED,
55 previous_session_state: ChromotingEvent.SessionState.CONNECTED
58 var expectedEvents = sequence.map(function(/** Object */ sequenceValue) {
59 var event = /** @type {Object} */ (base.deepCopy(baseEvent));
60 base.mix(event, sequenceValue);
63 testDriver.expectEvents(expectedEvents);
67 * @param {remoting.Me2MeTestDriver} testDriver
68 * @param {Object} baseEvent
70 var expectCanceled = function(testDriver, baseEvent) {
71 var ChromotingEvent = remoting.ChromotingEvent;
73 session_state: ChromotingEvent.SessionState.STARTED,
75 session_state: ChromotingEvent.SessionState.SIGNALING,
76 previous_session_state: ChromotingEvent.SessionState.STARTED
78 session_state: ChromotingEvent.SessionState.CREATING_PLUGIN,
79 previous_session_state: ChromotingEvent.SessionState.SIGNALING
81 session_state: ChromotingEvent.SessionState.CONNECTING,
82 previous_session_state: ChromotingEvent.SessionState.CREATING_PLUGIN
84 session_state: ChromotingEvent.SessionState.CONNECTION_CANCELED,
85 previous_session_state: ChromotingEvent.SessionState.CONNECTING
88 var expectedEvents = sequence.map(function(/** Object */ sequenceValue) {
89 var event = /** @type {Object} */ (base.deepCopy(baseEvent));
90 base.mix(event, sequenceValue);
93 testDriver.expectEvents(expectedEvents);
97 * @param {remoting.Me2MeTestDriver} testDriver
98 * @param {Object} baseEvent
99 * @param {remoting.ChromotingEvent.ConnectionError} error
101 var expectFailed = function(testDriver, baseEvent, error) {
102 var ChromotingEvent = remoting.ChromotingEvent;
104 session_state: ChromotingEvent.SessionState.STARTED,
106 session_state: ChromotingEvent.SessionState.SIGNALING,
107 previous_session_state: ChromotingEvent.SessionState.STARTED
109 session_state: ChromotingEvent.SessionState.CREATING_PLUGIN,
110 previous_session_state: ChromotingEvent.SessionState.SIGNALING
112 session_state: ChromotingEvent.SessionState.CONNECTING,
113 previous_session_state: ChromotingEvent.SessionState.CREATING_PLUGIN
115 session_state: ChromotingEvent.SessionState.CONNECTION_FAILED,
116 previous_session_state: ChromotingEvent.SessionState.CONNECTING,
117 connection_error: error
120 var expectedEvents = sequence.map(function(/** Object */ sequenceValue) {
121 var event = /** @type {Object} */ (base.deepCopy(baseEvent));
122 base.mix(event, sequenceValue);
125 testDriver.expectEvents(expectedEvents);
128 QUnit.test('Connection succeeded', function() {
129 expectSucceeded(testDriver, {
131 remoting.ChromotingEvent.SessionEntryPoint.CONNECT_BUTTON,
132 role: remoting.ChromotingEvent.Role.CLIENT,
133 mode: remoting.ChromotingEvent.Mode.ME2ME,
137 * @param {remoting.MockClientPlugin} plugin
138 * @param {remoting.ClientSession.State} state
140 function onStatusChanged(plugin, state) {
141 if (state == remoting.ClientSession.State.CONNECTED) {
142 testDriver.me2meActivity().stop();
143 testDriver.endTest();
147 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged(
150 return testDriver.startTest();
153 QUnit.test('Connection canceled - Pin prompt', function() {
154 expectCanceled(testDriver, {
156 remoting.ChromotingEvent.SessionEntryPoint.CONNECT_BUTTON,
157 role: remoting.ChromotingEvent.Role.CLIENT,
158 mode: remoting.ChromotingEvent.Mode.ME2ME,
162 * @param {remoting.MockClientPlugin} plugin
163 * @param {remoting.ClientSession.State} state
165 function onStatusChanged(plugin, state) {
166 if (state == remoting.ClientSession.State.CONNECTING) {
167 testDriver.cancelWhenPinPrompted();
168 plugin.mock$onDisposed().then(function(){
169 testDriver.endTest();
174 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged(
177 return testDriver.startTest();
180 QUnit.test('Connection failed - Signal strategy', function() {
181 var EntryPoint = remoting.ChromotingEvent.SessionEntryPoint;
182 testDriver.expectEvents([{
183 session_entry_point: EntryPoint.CONNECT_BUTTON,
184 session_state: remoting.ChromotingEvent.SessionState.STARTED
186 session_entry_point: EntryPoint.CONNECT_BUTTON,
187 session_state: remoting.ChromotingEvent.SessionState.SIGNALING,
188 previous_session_state: remoting.ChromotingEvent.SessionState.STARTED
190 session_entry_point: EntryPoint.CONNECT_BUTTON,
191 previous_session_state: remoting.ChromotingEvent.SessionState.SIGNALING,
192 session_state: remoting.ChromotingEvent.SessionState.CONNECTION_FAILED,
193 connection_error: remoting.ChromotingEvent.ConnectionError.UNEXPECTED
196 var promise = testDriver.startTest();
198 // The message dialog is shown when the connection fails.
199 testDriver.mockDialogFactory().messageDialog.show = function() {
200 testDriver.endTest();
201 return Promise.resolve(remoting.MessageDialog.Result.PRIMARY);
204 var signalStrategy = testDriver.mockConnection().signalStrategy();
205 signalStrategy.connect = function() {
206 Promise.resolve().then(function(){
207 signalStrategy.setStateForTesting(remoting.SignalStrategy.State.FAILED);
214 QUnit.test('Reconnect', function() {
215 var EntryPoint = remoting.ChromotingEvent.SessionEntryPoint;
216 expectSucceeded(testDriver, {
217 session_entry_point: EntryPoint.CONNECT_BUTTON,
218 role: remoting.ChromotingEvent.Role.CLIENT,
219 mode: remoting.ChromotingEvent.Mode.ME2ME,
221 expectSucceeded(testDriver, {
222 session_entry_point: EntryPoint.RECONNECT_BUTTON,
223 role: remoting.ChromotingEvent.Role.CLIENT,
224 mode: remoting.ChromotingEvent.Mode.ME2ME,
229 * @param {remoting.MockClientPlugin} plugin
230 * @param {remoting.ClientSession.State} state
232 function onStatusChanged(plugin, state) {
233 if (state == remoting.ClientSession.State.CONNECTED) {
236 testDriver.clickReconnectWhenFinished();
237 testDriver.me2meActivity().stop();
238 } else if (count == 2) {
239 testDriver.clickOkWhenFinished();
240 testDriver.me2meActivity().stop();
241 testDriver.endTest();
246 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged(
249 return testDriver.startTest();
252 QUnit.test('HOST_OFFLINE - JID refresh failed', function() {
253 var EntryPoint = remoting.ChromotingEvent.SessionEntryPoint;
254 // Expects the first connection to fail with HOST_OFFLINE
255 expectFailed(testDriver, {
256 session_entry_point:EntryPoint.CONNECT_BUTTON,
257 role: remoting.ChromotingEvent.Role.CLIENT,
258 mode: remoting.ChromotingEvent.Mode.ME2ME,
259 }, remoting.ChromotingEvent.ConnectionError.HOST_OFFLINE);
261 function onPluginCreated(/** remoting.MockClientPlugin */ plugin) {
262 plugin.mock$returnErrorOnConnect(
263 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE);
267 * @param {remoting.MockClientPlugin} plugin
268 * @param {remoting.ClientSession.State} state
270 function onStatusChanged(plugin, state) {
271 if (state == remoting.ClientSession.State.FAILED) {
272 testDriver.endTest();
276 testDriver.mockConnection().pluginFactory().mock$setPluginCreated(
278 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged(
280 sinon.stub(testDriver.mockHostList(), 'refresh',
281 function(/** function(boolean)*/ callback) {
283 Promise.resolve().then(function(){
288 return testDriver.startTest();
291 QUnit.test('HOST_OFFLINE - JID refresh succeeded', function() {
292 var EntryPoint = remoting.ChromotingEvent.SessionEntryPoint;
293 // Expects the first connection to fail with HOST_OFFLINE
294 expectFailed(testDriver, {
295 session_entry_point:EntryPoint.CONNECT_BUTTON,
296 role: remoting.ChromotingEvent.Role.CLIENT,
297 mode: remoting.ChromotingEvent.Mode.ME2ME,
298 }, remoting.ChromotingEvent.ConnectionError.HOST_OFFLINE);
299 // Expects the second connection to succeed with RECONNECT
300 expectSucceeded(testDriver, {
301 session_entry_point: EntryPoint.AUTO_RECONNECT_ON_HOST_OFFLINE,
302 role: remoting.ChromotingEvent.Role.CLIENT,
303 mode: remoting.ChromotingEvent.Mode.ME2ME,
307 function onPluginCreated(/** remoting.MockClientPlugin */ plugin) {
310 plugin.mock$returnErrorOnConnect(
311 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE);
312 } else if (count == 2) {
313 plugin.mock$useDefaultBehavior(
314 remoting.MockClientPlugin.AuthMethod.PIN);
319 * @param {remoting.MockClientPlugin} plugin
320 * @param {remoting.ClientSession.State} state
322 function onStatusChanged(plugin, state) {
323 if (state == remoting.ClientSession.State.CONNECTED) {
324 testDriver.me2meActivity().stop();
325 testDriver.endTest();
329 testDriver.mockConnection().pluginFactory().mock$setPluginCreated(
331 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged(
334 return testDriver.startTest();
337 QUnit.test('HOST_OFFLINE - Reconnect failed', function() {
338 var EntryPoint = remoting.ChromotingEvent.SessionEntryPoint;
339 // Expects the first connection to fail with HOST_OFFLINE
340 expectFailed(testDriver, {
341 session_entry_point:EntryPoint.CONNECT_BUTTON,
342 role: remoting.ChromotingEvent.Role.CLIENT,
343 mode: remoting.ChromotingEvent.Mode.ME2ME,
344 }, remoting.ChromotingEvent.ConnectionError.HOST_OFFLINE);
345 // Expects the second connection to fail with HOST_OVERLOAD
346 expectFailed(testDriver, {
347 session_entry_point:EntryPoint.AUTO_RECONNECT_ON_HOST_OFFLINE,
348 role: remoting.ChromotingEvent.Role.CLIENT,
349 mode: remoting.ChromotingEvent.Mode.ME2ME,
350 }, remoting.ChromotingEvent.ConnectionError.HOST_OVERLOAD);
353 function onPluginCreated(/** remoting.MockClientPlugin */ plugin) {
356 plugin.mock$returnErrorOnConnect(
357 remoting.ClientSession.ConnectionError.HOST_IS_OFFLINE);
358 } else if (count == 2) {
359 plugin.mock$returnErrorOnConnect(
360 remoting.ClientSession.ConnectionError.HOST_OVERLOAD);
364 var failureCount = 0;
366 * @param {remoting.MockClientPlugin} plugin
367 * @param {remoting.ClientSession.State} state
369 function onStatusChanged(plugin, state) {
370 if (state == remoting.ClientSession.State.FAILED) {
373 if (failureCount == 2) {
374 testDriver.endTest();
378 testDriver.mockConnection().pluginFactory().mock$setPluginCreated(
380 testDriver.mockConnection().pluginFactory().mock$setPluginStatusChanged(
382 return testDriver.startTest();