Rewrite AndroidSyncSettings to be significantly simpler.
[chromium-blink-merge.git] / remoting / webapp / browser_test / it2me_browser_test.js
blobc3be9bc726c84314e92ced599b62b69e78a128d6
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.
5 /**
6 * @fileoverview
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.
15 'use strict';
17 /** @constructor */
18 browserTest.ConnectIt2Me = function() {};
20 /**
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');
27 var that = this;
28 browserTest.ConnectIt2Me.clickOnAccessButton().then(function() {
29 return that.enterAccessCode_(data.accessCode);
30 }).then(function() {
31 return browserTest.disconnect();
32 }).then(function() {
33 browserTest.pass();
34 /** @param {*} reason */
35 }, function(reason) {
36 browserTest.fail(reason);
37 });
40 /** @return {Promise} */
41 browserTest.ConnectIt2Me.clickOnAccessButton = function() {
42 browserTest.clickOnControl('access-mode-button');
43 return browserTest.onUIMode(remoting.AppMode.CLIENT_UNCONNECTED);
46 /**
47 * @param {string} code
48 * @return {Promise}
49 * @private
51 browserTest.ConnectIt2Me.prototype.enterAccessCode_ = function(code) {
52 document.getElementById('access-code-entry').value = code;
53 browserTest.clickOnControl('connect-button');
54 return browserTest.expectConnected();
57 /** @constructor */
58 browserTest.InvalidAccessCode = function() {};
60 /**
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);
72 }).then(function() {
73 browserTest.pass();
74 }, function(reason) {
75 browserTest.fail(reason);
76 });
79 /** @constructor */
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');
86 }).then(function(){
87 return browserTest.onUIMode(remoting.AppMode.HOST_WAITING_FOR_CONNECTION);
88 }).then(function() {
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.");
93 browserTest.expect(
94 Number.isInteger(numericAccessCode) && numericAccessCode > 0,
95 "The access code should be a positive integer.");
96 browserTest.pass(accessCode);
97 },function(reason) {
98 browserTest.fail(reason);
99 });
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.
108 * @return {Promise}
109 * @private
111 browserTest.GetAccessCode.prototype.onUserInfoReady_ = function() {
112 return new Promise(function(resolve, reject){
113 remoting.identity.getUserInfo(resolve, reject);