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 * @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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 }, function() { | 166 }, function() { |
167 // On time out. | 167 // On time out. |
168 return Promise.resolve(); | 168 return Promise.resolve(); |
169 }).then(function() { | 169 }).then(function() { |
170 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); | 170 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); |
171 }); | 171 }); |
172 }; | 172 }; |
173 | 173 |
174 browserTest.disconnect = function() { | 174 browserTest.disconnect = function() { |
175 var AppMode = remoting.AppMode; | 175 var AppMode = remoting.AppMode; |
| 176 var finishedMode = AppMode.CLIENT_SESSION_FINISHED_ME2ME; |
| 177 var finishedButton = 'client-finished-me2me-button'; |
| 178 if (remoting.clientSession.getMode() == remoting.ClientSession.Mode.IT2ME) { |
| 179 finishedMode = AppMode.CLIENT_SESSION_FINISHED_IT2ME; |
| 180 finishedButton = 'client-finished-it2me-button'; |
| 181 } |
| 182 |
176 remoting.disconnect(); | 183 remoting.disconnect(); |
177 return browserTest.onUIMode(AppMode.CLIENT_SESSION_FINISHED_ME2ME).then( | 184 |
178 function() { | 185 return browserTest.onUIMode(finishedMode).then(function() { |
179 browserTest.clickOnControl('client-finished-me2me-button'); | 186 browserTest.clickOnControl(finishedButton); |
180 return browserTest.onUIMode(AppMode.HOME); | 187 return browserTest.onUIMode(AppMode.HOME); |
181 }); | 188 }); |
182 }; | 189 }; |
183 | 190 |
184 browserTest.enterPIN = function(pin, opt_expectError) { | 191 browserTest.enterPIN = function(pin, opt_expectError) { |
185 // Wait for 500ms before hitting the PIN button. From experiment, sometimes | 192 // Wait for 500ms before hitting the PIN button. From experiment, sometimes |
186 // the PIN prompt does not dismiss without the timeout. | 193 // the PIN prompt does not dismiss without the timeout. |
187 var CONNECT_PIN_WAIT = 500; | 194 var CONNECT_PIN_WAIT = 500; |
188 | 195 |
189 document.getElementById('pin-entry').value = pin; | 196 document.getElementById('pin-entry').value = pin; |
190 | 197 |
191 return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() { | 198 return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() { |
192 browserTest.clickOnControl('pin-connect-button'); | 199 browserTest.clickOnControl('pin-connect-button'); |
193 }).then(function() { | 200 }).then(function() { |
194 if (opt_expectError) { | 201 if (opt_expectError) { |
195 return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE); | 202 return browserTest.expectConnectionError( |
| 203 remoting.ClientSession.Mode.ME2ME, |
| 204 remoting.Error.INVALID_ACCESS_CODE); |
196 } else { | 205 } else { |
197 return browserTest.expectMe2MeConnected(); | 206 return browserTest.expectConnected(); |
198 } | 207 } |
199 }); | 208 }); |
200 }; | 209 }; |
201 | 210 |
202 browserTest.expectMe2MeError = function(errorTag) { | 211 browserTest.expectConnectionError = function(connectionMode, errorTag) { |
203 var AppMode = remoting.AppMode; | 212 var AppMode = remoting.AppMode; |
204 var Timeout = browserTest.Timeout; | 213 var Timeout = browserTest.Timeout; |
205 | 214 |
206 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.None); | 215 var finishButton = 'client-finished-me2me-button'; |
207 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME); | 216 var failureMode = AppMode.CLIENT_CONNECT_FAILED_ME2ME; |
| 217 |
| 218 if (connectionMode == remoting.ClientSession.Mode.IT2ME) { |
| 219 failureMode = AppMode.CLIENT_CONNECT_FAILED_IT2ME; |
| 220 finishButton = 'client-finished-it2me-button'; |
| 221 } |
| 222 |
| 223 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.NONE); |
| 224 var onFailure = browserTest.onUIMode(failureMode); |
208 | 225 |
209 onConnected = onConnected.then(function() { | 226 onConnected = onConnected.then(function() { |
210 return Promise.reject( | 227 return Promise.reject( |
211 'Expected the Me2Me connection to fail.'); | 228 'Expected the connection to fail.'); |
212 }); | 229 }); |
213 | 230 |
214 onFailure = onFailure.then(function() { | 231 onFailure = onFailure.then(function() { |
215 var errorDiv = document.getElementById('connect-error-message'); | 232 var errorDiv = document.getElementById('connect-error-message'); |
216 var actual = errorDiv.innerText; | 233 var actual = errorDiv.innerText; |
217 var expected = l10n.getTranslationOrError(errorTag); | 234 var expected = l10n.getTranslationOrError(errorTag); |
218 | 235 browserTest.clickOnControl(finishButton); |
219 browserTest.clickOnControl('client-finished-me2me-button'); | |
220 | 236 |
221 if (actual != expected) { | 237 if (actual != expected) { |
222 return Promise.reject('Unexpected failure. actual:' + actual + | 238 return Promise.reject('Unexpected failure. actual:' + actual + |
223 ' expected:' + expected); | 239 ' expected:' + expected); |
224 } | 240 } |
225 }); | 241 }); |
226 | 242 |
227 return Promise.race([onConnected, onFailure]); | 243 return Promise.race([onConnected, onFailure]); |
228 }; | 244 }; |
229 | 245 |
230 browserTest.expectMe2MeConnected = function() { | 246 browserTest.expectConnected = function() { |
231 var AppMode = remoting.AppMode; | 247 var AppMode = remoting.AppMode; |
232 // Timeout if the session is not connected within 30 seconds. | 248 // Timeout if the session is not connected within 30 seconds. |
233 var SESSION_CONNECTION_TIMEOUT = 30000; | 249 var SESSION_CONNECTION_TIMEOUT = 30000; |
234 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, | 250 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, |
235 SESSION_CONNECTION_TIMEOUT); | 251 SESSION_CONNECTION_TIMEOUT); |
236 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME, | 252 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME, |
237 browserTest.Timeout.NONE); | 253 browserTest.Timeout.NONE); |
238 onFailure = onFailure.then(function() { | 254 onFailure = onFailure.then(function() { |
239 var errorDiv = document.getElementById('connect-error-message'); | 255 var errorDiv = document.getElementById('connect-error-message'); |
240 var errorMsg = errorDiv.innerText; | 256 var errorMsg = errorDiv.innerText; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 browserTest.ensureRemoteConnectionEnabled = function(pin) { | 340 browserTest.ensureRemoteConnectionEnabled = function(pin) { |
325 browserTest.ensureHostStartedWithPIN(pin).then(function(){ | 341 browserTest.ensureHostStartedWithPIN(pin).then(function(){ |
326 browserTest.automationController_.send(true); | 342 browserTest.automationController_.send(true); |
327 }, function(errorMessage){ | 343 }, function(errorMessage){ |
328 console.error(errorMessage); | 344 console.error(errorMessage); |
329 browserTest.automationController_.send(false); | 345 browserTest.automationController_.send(false); |
330 }); | 346 }); |
331 }; | 347 }; |
332 | 348 |
333 browserTest.init(); | 349 browserTest.init(); |
OLD | NEW |