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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 if (result.succeeded) { | 57 if (result.succeeded) { |
58 console.log('Test Passed.'); | 58 console.log('Test Passed.'); |
59 } else { | 59 } else { |
60 console.error('Test Failed.\n' + | 60 console.error('Test Failed.\n' + |
61 result.error_message + '\n' + result.stack_trace); | 61 result.error_message + '\n' + result.stack_trace); |
62 } | 62 } |
63 } | 63 } |
64 }; | 64 }; |
65 }; | 65 }; |
66 | 66 |
| 67 /** |
| 68 * Fails the C++ calling browser test with |message| if |expr| is false. |
| 69 * @param {boolean} expr |
| 70 * @param {string} message |
| 71 */ |
67 browserTest.expect = function(expr, message) { | 72 browserTest.expect = function(expr, message) { |
68 if (!expr) { | 73 if (!expr) { |
69 message = (message) ? '<' + message + '>' : ''; | 74 message = (message) ? '<' + message + '>' : ''; |
70 browserTest.fail('Expectation failed.' + message); | 75 browserTest.fail('Expectation failed.' + message); |
71 } | 76 } |
72 }; | 77 }; |
73 | 78 |
74 browserTest.fail = function(error) { | 79 browserTest.fail = function(error) { |
75 var error_message = error; | 80 var error_message = error; |
76 var stack_trace = base.debug.callstack(); | 81 var stack_trace = base.debug.callstack(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 }, function() { | 165 }, function() { |
161 // On time out. | 166 // On time out. |
162 return Promise.resolve(); | 167 return Promise.resolve(); |
163 }).then(function() { | 168 }).then(function() { |
164 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); | 169 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT, 10000); |
165 }); | 170 }); |
166 }; | 171 }; |
167 | 172 |
168 browserTest.disconnect = function() { | 173 browserTest.disconnect = function() { |
169 var AppMode = remoting.AppMode; | 174 var AppMode = remoting.AppMode; |
| 175 var finishedMode = AppMode.CLIENT_SESSION_FINISHED_ME2ME; |
| 176 var finishedButton = 'client-finished-me2me-button'; |
| 177 if (remoting.clientSession.getMode() == remoting.ClientSession.Mode.IT2ME) { |
| 178 finishedMode = AppMode.CLIENT_SESSION_FINISHED_IT2ME; |
| 179 finishedButton = 'client-finished-it2me-button'; |
| 180 } |
| 181 |
170 remoting.disconnect(); | 182 remoting.disconnect(); |
171 return browserTest.onUIMode(AppMode.CLIENT_SESSION_FINISHED_ME2ME).then( | 183 |
172 function() { | 184 return browserTest.onUIMode(finishedMode).then(function() { |
173 browserTest.clickOnControl('client-finished-me2me-button'); | 185 browserTest.clickOnControl(finishedButton); |
174 return browserTest.onUIMode(AppMode.HOME); | 186 return browserTest.onUIMode(AppMode.HOME); |
175 }); | 187 }); |
176 }; | 188 }; |
177 | 189 |
178 browserTest.enterPIN = function(pin, opt_expectError) { | 190 browserTest.enterPIN = function(pin, opt_expectError) { |
179 // Wait for 500ms before hitting the PIN button. From experiment, sometimes | 191 // Wait for 500ms before hitting the PIN button. From experiment, sometimes |
180 // the PIN prompt does not dismiss without the timeout. | 192 // the PIN prompt does not dismiss without the timeout. |
181 var CONNECT_PIN_WAIT = 500; | 193 var CONNECT_PIN_WAIT = 500; |
182 | 194 |
183 document.getElementById('pin-entry').value = pin; | 195 document.getElementById('pin-entry').value = pin; |
184 | 196 |
185 return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() { | 197 return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() { |
186 browserTest.clickOnControl('pin-connect-button'); | 198 browserTest.clickOnControl('pin-connect-button'); |
187 }).then(function() { | 199 }).then(function() { |
188 if (opt_expectError) { | 200 if (opt_expectError) { |
189 return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE); | 201 return browserTest.expectConnectionError( |
| 202 remoting.ClientSession.Mode.ME2ME, |
| 203 remoting.Error.INVALID_ACCESS_CODE); |
190 } else { | 204 } else { |
191 return browserTest.expectMe2MeConnected(); | 205 return browserTest.expectConnected(); |
192 } | 206 } |
193 }); | 207 }); |
194 }; | 208 }; |
195 | 209 |
196 browserTest.expectMe2MeError = function(errorTag) { | 210 browserTest.expectConnectionError = function(connectionMode, errorTag) { |
197 var AppMode = remoting.AppMode; | 211 var AppMode = remoting.AppMode; |
198 var Timeout = browserTest.Timeout; | 212 var Timeout = browserTest.Timeout; |
199 | 213 |
200 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.None); | 214 var finishButton = 'client-finished-me2me-button'; |
201 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME); | 215 var failureMode = AppMode.CLIENT_CONNECT_FAILED_ME2ME; |
| 216 |
| 217 if (connectionMode == remoting.ClientSession.Mode.IT2ME) { |
| 218 failureMode = AppMode.CLIENT_CONNECT_FAILED_IT2ME; |
| 219 finishButton = 'client-finished-it2me-button'; |
| 220 } |
| 221 |
| 222 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.NONE); |
| 223 var onFailure = browserTest.onUIMode(failureMode); |
202 | 224 |
203 onConnected = onConnected.then(function() { | 225 onConnected = onConnected.then(function() { |
204 return Promise.reject( | 226 return Promise.reject( |
205 'Expected the Me2Me connection to fail.'); | 227 'Expected the connection to fail.'); |
206 }); | 228 }); |
207 | 229 |
208 onFailure = onFailure.then(function() { | 230 onFailure = onFailure.then(function() { |
209 var errorDiv = document.getElementById('connect-error-message'); | 231 var errorDiv = document.getElementById('connect-error-message'); |
210 var actual = errorDiv.innerText; | 232 var actual = errorDiv.innerText; |
211 var expected = l10n.getTranslationOrError(errorTag); | 233 var expected = l10n.getTranslationOrError(errorTag); |
212 | 234 browserTest.clickOnControl(finishButton); |
213 browserTest.clickOnControl('client-finished-me2me-button'); | |
214 | 235 |
215 if (actual != expected) { | 236 if (actual != expected) { |
216 return Promise.reject('Unexpected failure. actual:' + actual + | 237 return Promise.reject('Unexpected failure. actual:' + actual + |
217 ' expected:' + expected); | 238 ' expected:' + expected); |
218 } | 239 } |
219 }); | 240 }); |
220 | 241 |
221 return Promise.race([onConnected, onFailure]); | 242 return Promise.race([onConnected, onFailure]); |
222 }; | 243 }; |
223 | 244 |
224 browserTest.expectMe2MeConnected = function() { | 245 browserTest.expectConnected = function() { |
225 var AppMode = remoting.AppMode; | 246 var AppMode = remoting.AppMode; |
226 // Timeout if the session is not connected within 30 seconds. | 247 // Timeout if the session is not connected within 30 seconds. |
227 var SESSION_CONNECTION_TIMEOUT = 30000; | 248 var SESSION_CONNECTION_TIMEOUT = 30000; |
228 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, | 249 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, |
229 SESSION_CONNECTION_TIMEOUT); | 250 SESSION_CONNECTION_TIMEOUT); |
230 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME, | 251 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME, |
231 browserTest.Timeout.NONE); | 252 browserTest.Timeout.NONE); |
232 onFailure = onFailure.then(function() { | 253 onFailure = onFailure.then(function() { |
233 var errorDiv = document.getElementById('connect-error-message'); | 254 var errorDiv = document.getElementById('connect-error-message'); |
234 var errorMsg = errorDiv.innerText; | 255 var errorMsg = errorDiv.innerText; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 browserTest.ensureRemoteConnectionEnabled = function(pin) { | 339 browserTest.ensureRemoteConnectionEnabled = function(pin) { |
319 browserTest.ensureHostStartedWithPIN(pin).then(function(){ | 340 browserTest.ensureHostStartedWithPIN(pin).then(function(){ |
320 browserTest.automationController_.send(true); | 341 browserTest.automationController_.send(true); |
321 }, function(errorMessage){ | 342 }, function(errorMessage){ |
322 console.error(errorMessage); | 343 console.error(errorMessage); |
323 browserTest.automationController_.send(false); | 344 browserTest.automationController_.send(false); |
324 }); | 345 }); |
325 }; | 346 }; |
326 | 347 |
327 browserTest.init(); | 348 browserTest.init(); |
OLD | NEW |