Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: remoting/webapp/browser_test/browser_test.js

Issue 838543002: Implement browser test for It2Me (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 * @suppress {checkTypes} By default, JSCompile is not run on test files. 7 * @suppress {checkTypes} By default, JSCompile is not run on test files.
8 * However, you can modify |remoting_webapp_files.gypi| locally to include 8 * However, you can modify |remoting_webapp_files.gypi| locally to include
9 * the test in the package to expedite local development. This suppress 9 * the test in the package to expedite local development. This suppress
10 * is here so that JSCompile won't complain. 10 * is here so that JSCompile won't complain.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 browserTest.init = function() { 49 browserTest.init = function() {
50 // The domAutomationController is used to communicate progress back to the 50 // The domAutomationController is used to communicate progress back to the
51 // C++ calling code. It will only exist if chrome is run with the flag 51 // C++ calling code. It will only exist if chrome is run with the flag
52 // --dom-automation. It is stubbed out here so that browser test can be run 52 // --dom-automation. It is stubbed out here so that browser test can be run
53 // under the regular app. 53 // under the regular app.
54 browserTest.automationController_ = window.domAutomationController || { 54 browserTest.automationController_ = window.domAutomationController || {
55 send: function(json) { 55 send: function(json) {
56 var result = JSON.parse(json); 56 var result = JSON.parse(json);
57 if (result.succeeded) { 57 if (result.succeeded) {
58 console.log('Test Passed.'); 58 console.log('Test Passed.' +
59 ((result.value !== undefined)? ' Value: ' + result.value : ''));
Jamie 2015/01/06 22:18:52 Nit: Space before '?'
kelvinp 2015/01/09 22:21:30 Done.
59 } else { 60 } else {
60 console.error('Test Failed.\n' + 61 console.error('Test Failed.\n' +
61 result.error_message + '\n' + result.stack_trace); 62 result.error_message + '\n' + result.stack_trace);
62 } 63 }
63 } 64 }
64 }; 65 };
65 }; 66 };
66 67
67 browserTest.expect = function(expr, message) { 68 browserTest.expect = function(expr, message) {
68 if (!expr) { 69 if (!expr) {
(...skipping 21 matching lines...) Expand all
90 // failure. 91 // failure.
91 debugger; 92 debugger;
92 93
93 browserTest.automationController_.send(JSON.stringify({ 94 browserTest.automationController_.send(JSON.stringify({
94 succeeded: false, 95 succeeded: false,
95 error_message: error_message, 96 error_message: error_message,
96 stack_trace: stack_trace 97 stack_trace: stack_trace
97 })); 98 }));
98 }; 99 };
99 100
100 browserTest.pass = function() { 101 /**
101 browserTest.automationController_.send(JSON.stringify({ 102 * @param {?} opt_value An optional value to return when the test succeeds.
Jamie 2015/01/06 22:18:52 I think this should be ?=
kelvinp 2015/01/09 22:21:30 Done.
103 */
104 browserTest.pass = function(opt_value) {
105 browserTest.automationController_.send(JSON.stringify({
102 succeeded: true, 106 succeeded: true,
103 error_message: '', 107 error_message: '',
104 stack_trace: '' 108 stack_trace: '',
109 value: opt_value
105 })); 110 }));
106 }; 111 };
107 112
108 browserTest.clickOnControl = function(id) { 113 browserTest.clickOnControl = function(id) {
109 var element = document.getElementById(id); 114 var element = document.getElementById(id);
110 browserTest.expect(element); 115 browserTest.expect(element);
111 element.click(); 116 element.click();
112 }; 117 };
113 118
114 /** @enum {number} */ 119 /** @enum {number} */
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 }, function() { 171 }, function() {
167 // On time out. 172 // On time out.
168 return Promise.resolve(); 173 return Promise.resolve();
169 }).then(function() { 174 }).then(function() {
170 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); 175 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000);
171 }); 176 });
172 }; 177 };
173 178
174 browserTest.disconnect = function() { 179 browserTest.disconnect = function() {
175 var AppMode = remoting.AppMode; 180 var AppMode = remoting.AppMode;
181 var finished_mode = AppMode.CLIENT_SESSION_FINISHED_ME2ME;
182 var finished_button = 'client-finished-me2me-button';
183 if (remoting.clientSession.getMode() == remoting.ClientSession.Mode.IT2ME) {
184 finished_mode = AppMode.CLIENT_SESSION_FINISHED_IT2ME;
185 finished_button = 'client-finished-it2me-button';
186 }
176 remoting.disconnect(); 187 remoting.disconnect();
177 return browserTest.onUIMode(AppMode.CLIENT_SESSION_FINISHED_ME2ME).then( 188 return browserTest.onUIMode(finished_mode).then(function() {
178 function() { 189 browserTest.clickOnControl(finished_button);
179 browserTest.clickOnControl('client-finished-me2me-button'); 190 return browserTest.onUIMode(AppMode.HOME);
180 return browserTest.onUIMode(AppMode.HOME); 191 });
181 });
182 }; 192 };
183 193
184 browserTest.enterPIN = function(pin, opt_expectError) { 194 browserTest.enterPIN = function(pin, opt_expectError) {
185 // Wait for 500ms before hitting the PIN button. From experiment, sometimes 195 // Wait for 500ms before hitting the PIN button. From experiment, sometimes
186 // the PIN prompt does not dismiss without the timeout. 196 // the PIN prompt does not dismiss without the timeout.
187 var CONNECT_PIN_WAIT = 500; 197 var CONNECT_PIN_WAIT = 500;
188 198
189 document.getElementById('pin-entry').value = pin; 199 document.getElementById('pin-entry').value = pin;
190 200
191 return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() { 201 return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() {
192 browserTest.clickOnControl('pin-connect-button'); 202 browserTest.clickOnControl('pin-connect-button');
193 }).then(function() { 203 }).then(function() {
194 if (opt_expectError) { 204 if (opt_expectError) {
195 return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE); 205 return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE);
196 } else { 206 } else {
197 return browserTest.expectMe2MeConnected(); 207 return browserTest.expectConnected();
198 } 208 }
199 }); 209 });
200 }; 210 };
201 211
202 browserTest.expectMe2MeError = function(errorTag) { 212 browserTest.expectMe2MeError = function(errorTag) {
203 var AppMode = remoting.AppMode; 213 var AppMode = remoting.AppMode;
204 var Timeout = browserTest.Timeout; 214 var Timeout = browserTest.Timeout;
205 215
206 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.None); 216 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.None);
207 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME); 217 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME);
(...skipping 12 matching lines...) Expand all
220 230
221 if (actual != expected) { 231 if (actual != expected) {
222 return Promise.reject('Unexpected failure. actual:' + actual + 232 return Promise.reject('Unexpected failure. actual:' + actual +
223 ' expected:' + expected); 233 ' expected:' + expected);
224 } 234 }
225 }); 235 });
226 236
227 return Promise.race([onConnected, onFailure]); 237 return Promise.race([onConnected, onFailure]);
228 }; 238 };
229 239
230 browserTest.expectMe2MeConnected = function() { 240 browserTest.expectConnected = function() {
231 var AppMode = remoting.AppMode; 241 var AppMode = remoting.AppMode;
232 // Timeout if the session is not connected within 30 seconds. 242 // Timeout if the session is not connected within 30 seconds.
233 var SESSION_CONNECTION_TIMEOUT = 30000; 243 var SESSION_CONNECTION_TIMEOUT = 30000;
234 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, 244 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION,
235 SESSION_CONNECTION_TIMEOUT); 245 SESSION_CONNECTION_TIMEOUT);
236 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME, 246 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME,
237 browserTest.Timeout.NONE); 247 browserTest.Timeout.NONE);
238 onFailure = onFailure.then(function() { 248 onFailure = onFailure.then(function() {
239 var errorDiv = document.getElementById('connect-error-message'); 249 var errorDiv = document.getElementById('connect-error-message');
240 var errorMsg = errorDiv.innerText; 250 var errorMsg = errorDiv.innerText;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 browserTest.ensureRemoteConnectionEnabled = function(pin) { 334 browserTest.ensureRemoteConnectionEnabled = function(pin) {
325 browserTest.ensureHostStartedWithPIN(pin).then(function(){ 335 browserTest.ensureHostStartedWithPIN(pin).then(function(){
326 browserTest.automationController_.send(true); 336 browserTest.automationController_.send(true);
327 }, function(errorMessage){ 337 }, function(errorMessage){
328 console.error(errorMessage); 338 console.error(errorMessage);
329 browserTest.automationController_.send(false); 339 browserTest.automationController_.send(false);
330 }); 340 });
331 }; 341 };
332 342
333 browserTest.init(); 343 browserTest.init();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698