OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview | 6 * @fileoverview |
7 * | 7 * |
8 * Provides basic functionality for JavaScript based browser test. | 8 * Provides basic functionality for JavaScript based browser test. |
9 * | 9 * |
10 * To define a browser test, create a class under the browserTest namespace. | 10 * To define a browser test, create a class under the browserTest namespace. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 } | 183 } |
184 remoting.testEvents.addEventListener(uiModeChanged, onUIModeChanged); | 184 remoting.testEvents.addEventListener(uiModeChanged, onUIModeChanged); |
185 }); | 185 }); |
186 }; | 186 }; |
187 | 187 |
188 /** | 188 /** |
189 * @return {Promise} | 189 * @return {Promise} |
190 */ | 190 */ |
191 browserTest.connectMe2Me = function() { | 191 browserTest.connectMe2Me = function() { |
192 var AppMode = remoting.AppMode; | 192 var AppMode = remoting.AppMode; |
193 browserTest.clickOnControl('this-host-connect'); | 193 // The one second timeout is necessary because the click handler of |
194 return browserTest.onUIMode(AppMode.CLIENT_HOST_NEEDS_UPGRADE).then( | 194 // 'this-host-connect' is registered asynchronously. |
195 function() { | 195 return base.Promise.sleep(1000).then(function() { |
196 browserTest.clickOnControl('this-host-connect'); | |
197 }).then(function(){ | |
198 return browserTest.onUIMode(AppMode.CLIENT_HOST_NEEDS_UPGRADE); | |
199 }).then(function() { | |
196 // On fulfilled. | 200 // On fulfilled. |
197 browserTest.clickOnControl('host-needs-update-connect-button'); | 201 browserTest.clickOnControl('host-needs-update-connect-button'); |
198 }, function() { | 202 }, function() { |
199 // On time out. | 203 // On time out. |
200 return Promise.resolve(); | 204 return Promise.resolve(); |
201 }).then(function() { | 205 }).then(function() { |
202 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); | 206 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); |
203 }); | 207 }); |
204 }; | 208 }; |
205 | 209 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
252 /** | 256 /** |
253 * @param {remoting.DesktopConnectedView.Mode} connectionMode | 257 * @param {remoting.DesktopConnectedView.Mode} connectionMode |
254 * @param {string} errorTag | 258 * @param {string} errorTag |
255 * @return {Promise} | 259 * @return {Promise} |
256 */ | 260 */ |
257 browserTest.expectConnectionError = function(connectionMode, errorTag) { | 261 browserTest.expectConnectionError = function(connectionMode, errorTag) { |
258 var AppMode = remoting.AppMode; | 262 var AppMode = remoting.AppMode; |
259 var Timeout = browserTest.Timeout; | 263 var Timeout = browserTest.Timeout; |
260 | 264 |
261 var finishButton = 'client-finished-me2me-button'; | 265 var finishButton = 'client-finished-me2me-button'; |
262 var failureMode = AppMode.CLIENT_CONNECT_FAILED_ME2ME; | |
263 | 266 |
264 if (connectionMode == remoting.DesktopConnectedView.Mode.IT2ME) { | 267 if (connectionMode == remoting.DesktopConnectedView.Mode.IT2ME) { |
265 failureMode = AppMode.CLIENT_CONNECT_FAILED_IT2ME; | |
266 finishButton = 'client-finished-it2me-button'; | 268 finishButton = 'client-finished-it2me-button'; |
267 } | 269 } |
268 | 270 |
269 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.NONE); | 271 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.NONE); |
270 var onFailure = browserTest.onUIMode(failureMode); | 272 var onFailure = Promise.race([ |
273 browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME), | |
kelvinp
2015/02/23 21:17:51
Better handle test flakiness on IT2Me tests. This
| |
274 browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_IT2ME)]); | |
271 | 275 |
272 onConnected = onConnected.then(function() { | 276 onConnected = onConnected.then(function() { |
273 return Promise.reject( | 277 return Promise.reject( |
274 'Expected the connection to fail.'); | 278 'Expected the connection to fail.'); |
275 }); | 279 }); |
276 | 280 |
277 onFailure = onFailure.then(function() { | 281 onFailure = onFailure.then(function() { |
278 /** @type {Element} */ | 282 /** @type {Element} */ |
279 var errorDiv = document.getElementById('connect-error-message'); | 283 var errorDiv = document.getElementById('connect-error-message'); |
280 var actual = errorDiv.innerText; | 284 var actual = errorDiv.innerText; |
(...skipping 25 matching lines...) Expand all Loading... | |
306 var errorMsg = errorDiv.innerText; | 310 var errorMsg = errorDiv.innerText; |
307 return Promise.reject('Unexpected error - ' + errorMsg); | 311 return Promise.reject('Unexpected error - ' + errorMsg); |
308 }); | 312 }); |
309 return Promise.race([onConnected, onFailure]); | 313 return Promise.race([onConnected, onFailure]); |
310 }; | 314 }; |
311 | 315 |
312 /** | 316 /** |
313 * @param {base.EventSource} eventSource | 317 * @param {base.EventSource} eventSource |
314 * @param {string} event | 318 * @param {string} event |
315 * @param {number} timeoutMs | 319 * @param {number} timeoutMs |
316 * @param {?string} opt_expectedData | 320 * @param {*=} opt_expectedData |
317 * @return {Promise} | 321 * @return {Promise} |
318 */ | 322 */ |
319 browserTest.expectEvent = function(eventSource, event, timeoutMs, | 323 browserTest.expectEvent = function(eventSource, event, timeoutMs, |
320 opt_expectedData) { | 324 opt_expectedData) { |
321 return new Promise(function(fullfil, reject) { | 325 return new Promise(function(fullfil, reject) { |
322 /** @param {string=} actualData */ | 326 /** @param {string=} actualData */ |
323 var verifyEventParameters = function(actualData) { | 327 var verifyEventParameters = function(actualData) { |
324 if (opt_expectedData === undefined || opt_expectedData === actualData) { | 328 if (opt_expectedData === undefined || opt_expectedData === actualData) { |
325 fullfil(true); | 329 fullfil(true); |
326 } else { | 330 } else { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
376 console.log('browserTest: PIN Setup is done.'); | 380 console.log('browserTest: PIN Setup is done.'); |
377 browserTest.clickOnControl('host-config-done-dismiss'); | 381 browserTest.clickOnControl('host-config-done-dismiss'); |
378 | 382 |
379 // On Linux, we restart the host after changing the PIN, need to sleep | 383 // On Linux, we restart the host after changing the PIN, need to sleep |
380 // for ten seconds before the host is ready for connection. | 384 // for ten seconds before the host is ready for connection. |
381 return base.Promise.sleep(HOST_SETUP_WAIT); | 385 return base.Promise.sleep(HOST_SETUP_WAIT); |
382 }); | 386 }); |
383 }; | 387 }; |
384 | 388 |
385 /** | 389 /** |
386 * @return {Promise} | 390 * @return {Promise<boolean>} |
387 */ | 391 */ |
388 browserTest.isLocalHostStarted = function() { | 392 browserTest.isLocalHostStarted = function() { |
389 return new Promise(function(resolve) { | 393 return new Promise(function(resolve) { |
390 remoting.hostController.getLocalHostState(function(state) { | 394 remoting.hostController.getLocalHostState(function(state) { |
391 resolve(remoting.HostController.State.STARTED == state); | 395 resolve(remoting.HostController.State.STARTED == state); |
392 }); | 396 }); |
393 }); | 397 }); |
394 }; | 398 }; |
395 | 399 |
396 /** | 400 /** |
(...skipping 24 matching lines...) Expand all Loading... | |
421 */ | 425 */ |
422 browserTest.ensureRemoteConnectionEnabled = function(pin) { | 426 browserTest.ensureRemoteConnectionEnabled = function(pin) { |
423 browserTest.ensureHostStartedWithPIN(pin).then(function() { | 427 browserTest.ensureHostStartedWithPIN(pin).then(function() { |
424 browserTest.pass(); | 428 browserTest.pass(); |
425 }, function(reason) { | 429 }, function(reason) { |
426 browserTest.fail(reason); | 430 browserTest.fail(reason); |
427 }); | 431 }); |
428 }; | 432 }; |
429 | 433 |
430 browserTest.init(); | 434 browserTest.init(); |
OLD | NEW |