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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 return browserTest.onUIMode(AppMode.CLIENT_HOST_NEEDS_UPGRADE).then( | 162 return browserTest.onUIMode(AppMode.CLIENT_HOST_NEEDS_UPGRADE).then( |
163 function() { | 163 function() { |
164 // On fulfilled. | 164 // On fulfilled. |
165 browserTest.clickOnControl('host-needs-update-connect-button'); | 165 browserTest.clickOnControl('host-needs-update-connect-button'); |
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); | 170 return browserTest.onUIMode(AppMode.CLIENT_PIN_PROMPT); |
171 }); | 171 }); |
172 } | 172 }; |
173 | 173 |
174 browserTest.expectMe2MeError = function(errorTag) { | 174 browserTest.expectMe2MeError = function(errorTag) { |
175 var AppMode = remoting.AppMode; | 175 var AppMode = remoting.AppMode; |
176 var Timeout = browserTest.Timeout; | 176 var Timeout = browserTest.Timeout; |
177 | 177 |
178 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.None); | 178 var onConnected = browserTest.onUIMode(AppMode.IN_SESSION, Timeout.None); |
179 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME); | 179 var onFailure = browserTest.onUIMode(AppMode.CLIENT_CONNECT_FAILED_ME2ME); |
180 | 180 |
181 onConnected = onConnected.then(function() { | 181 onConnected = onConnected.then(function() { |
182 return Promise.reject( | 182 return Promise.reject( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 browserTest.runTest = function(testClass, data) { | 218 browserTest.runTest = function(testClass, data) { |
219 try { | 219 try { |
220 var test = new testClass(); | 220 var test = new testClass(); |
221 browserTest.expect(typeof test.run == 'function'); | 221 browserTest.expect(typeof test.run == 'function'); |
222 test.run(data); | 222 test.run(data); |
223 } catch (e) { | 223 } catch (e) { |
224 browserTest.fail(e); | 224 browserTest.fail(e); |
225 } | 225 } |
226 }; | 226 }; |
227 | 227 |
| 228 browserTest.setupPIN = function(newPin) { |
| 229 var AppMode = remoting.AppMode; |
| 230 var HOST_SETUP_WAIT = 10000; |
| 231 var Timeout = browserTest.Timeout; |
| 232 |
| 233 return browserTest.onUIMode(AppMode.HOST_SETUP_ASK_PIN).then(function() { |
| 234 document.getElementById('daemon-pin-entry').value = newPin; |
| 235 document.getElementById('daemon-pin-confirm').value = newPin; |
| 236 browserTest.clickOnControl('daemon-pin-ok'); |
| 237 |
| 238 var success = browserTest.onUIMode(AppMode.HOST_SETUP_DONE, Timeout.NONE); |
| 239 var failure = browserTest.onUIMode(AppMode.HOST_SETUP_ERROR, Timeout.NONE); |
| 240 failure = failure.then(function(){ |
| 241 return Promise.reject('Unexpected host setup failure'); |
| 242 }); |
| 243 return Promise.race([success, failure]); |
| 244 }).then(function() { |
| 245 console.log('browserTest: PIN Setup is done.'); |
| 246 browserTest.clickOnControl('host-config-done-dismiss'); |
| 247 |
| 248 // On Linux, we restart the host after changing the PIN, need to sleep |
| 249 // for ten seconds before the host is ready for connection. |
| 250 return base.Promise.sleep(HOST_SETUP_WAIT); |
| 251 }); |
| 252 }; |
| 253 |
| 254 browserTest.isLocalHostStarted = function() { |
| 255 return new Promise(function(resolve) { |
| 256 remoting.hostController.getLocalHostState(function(state) { |
| 257 resolve(remoting.HostController.State.STARTED == state); |
| 258 }); |
| 259 }); |
| 260 }; |
| 261 |
| 262 browserTest.ensureHostStartedWithPIN = function(pin) { |
| 263 // Return if host is already |
| 264 return browserTest.isLocalHostStarted().then(function(started){ |
| 265 if (!started) { |
| 266 console.log('browserTest: Enabling remote connection.'); |
| 267 browserTest.clickOnControl('start-daemon'); |
| 268 } else { |
| 269 console.log('browserTest: Changing the PIN of the host to: ' + pin + '.'); |
| 270 browserTest.clickOnControl('change-daemon-pin'); |
| 271 } |
| 272 return browserTest.setupPIN(pin); |
| 273 }); |
| 274 }; |
| 275 |
| 276 // Called by Browser Test in C++ |
| 277 browserTest.ensureRemoteConnectionEnabled = function(pin) { |
| 278 browserTest.ensureHostStartedWithPIN(pin).then(function(){ |
| 279 browserTest.automationController_.send(true); |
| 280 }).catch(function(errorMessage){ |
| 281 console.error(errorMessage); |
| 282 browserTest.automationController_.send(false); |
| 283 }); |
| 284 }; |
| 285 |
228 browserTest.init(); | 286 browserTest.init(); |
OLD | NEW |