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.
7 * @suppress {checkTypes}
8 * Browser test for the scenario below:
9 * 1. Generates an access code.
10 * 2. Launches another chromoting app instance.
11 * 3. Connects with the generated access code.
12 * 4. Verifies that the session is connected.
18 browserTest
.ConnectIt2Me = function() {};
21 * @param {{pin: string, accessCode: string}} data
23 browserTest
.ConnectIt2Me
.prototype.run = function(data
) {
24 browserTest
.expect(typeof data
.accessCode
== 'string',
25 'The access code should be an non-empty string');
26 browserTest
.clickOnControl('get-started-it2me');
28 browserTest
.ConnectIt2Me
.clickOnAccessButton().then(function() {
29 return that
.enterAccessCode_(data
.accessCode
);
31 return browserTest
.disconnect();
34 /** @param {*} reason */
36 browserTest
.fail(reason
);
40 /** @return {Promise} */
41 browserTest
.ConnectIt2Me
.clickOnAccessButton = function() {
42 browserTest
.clickOnControl('access-mode-button');
43 return browserTest
.onUIMode(remoting
.AppMode
.CLIENT_UNCONNECTED
);
47 * @param {string} code
51 browserTest
.ConnectIt2Me
.prototype.enterAccessCode_ = function(code
) {
52 document
.getElementById('access-code-entry').value
= code
;
53 browserTest
.clickOnControl('connect-button');
54 return browserTest
.expectConnected();
58 browserTest
.InvalidAccessCode = function() {};
61 * @param {{pin: string, accessCode: string}} data
63 browserTest
.InvalidAccessCode
.prototype.run = function(data
) {
64 browserTest
.expect(typeof data
.accessCode
== 'string',
65 'The access code should be an non-empty string');
66 browserTest
.ConnectIt2Me
.clickOnAccessButton().then(function() {
67 document
.getElementById('access-code-entry').value
= data
.accessCode
;
68 browserTest
.clickOnControl('connect-button');
69 return browserTest
.expectConnectionError(
70 remoting
.DesktopConnectedView
.Mode
.IT2ME
,
71 remoting
.Error
.INVALID_ACCESS_CODE
);
75 browserTest
.fail(reason
);
80 browserTest
.GetAccessCode = function() {};
82 browserTest
.GetAccessCode
.prototype.run = function() {
83 browserTest
.clickOnControl('get-started-it2me');
84 this.onUserInfoReady_().then(function() {
85 browserTest
.clickOnControl('share-button');
87 return browserTest
.onUIMode(remoting
.AppMode
.HOST_WAITING_FOR_CONNECTION
);
89 var accessCode
= document
.getElementById('access-code-display').innerText
;
90 var numericAccessCode
= parseFloat(accessCode
);
91 browserTest
.expect(accessCode
.length
=== 12,
92 "The access code should be 12 digits long.");
94 Number
.isInteger(numericAccessCode
) && numericAccessCode
> 0,
95 "The access code should be a positive integer.");
96 browserTest
.pass(accessCode
);
98 browserTest
.fail(reason
);
103 * Wait for the email address of the local user to become available. The email
104 * address is required in an It2Me connection for domain policy enforcement.
105 * TODO:(kelvinp) Fix this awkward behavior in the production code so that this
106 * hack is no longer required.
111 browserTest
.GetAccessCode
.prototype.onUserInfoReady_ = function() {
112 return new Promise(function(resolve
, reject
){
113 remoting
.identity
.getUserInfo(resolve
, reject
);