OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 /** |
| 6 * @fileoverview |
| 7 * @suppress {checkTypes} |
| 8 * Browser test for the scenario below: |
| 9 * 1. Change the PIN. |
| 10 * 2. Connect with the new PIN. |
| 11 * 3. Verify the connection succeeded. |
| 12 * 4. Disconnect and reconnect with the old PIN. |
| 13 * 5. Verify the connection failed. |
| 14 */ |
| 15 |
| 16 'use strict'; |
| 17 |
| 18 /** @constructor */ |
| 19 browserTest.Update_PIN = function() {}; |
| 20 |
| 21 browserTest.Update_PIN.prototype.run = function(data) { |
| 22 var LOGIN_BACKOFF_WAIT = 2000; |
| 23 // Input validation |
| 24 browserTest.expect(typeof data.new_pin == 'string'); |
| 25 browserTest.expect(typeof data.old_pin == 'string'); |
| 26 browserTest.expect(data.new_pin != data.old_pin, |
| 27 'The new PIN and the old PIN cannot be the same'); |
| 28 |
| 29 this.changePIN_(data.new_pin).then( |
| 30 this.connect_.bind(this) |
| 31 ).then( |
| 32 this.enterPIN_.bind(this, data.old_pin, true /* expectError*/) |
| 33 ).then( |
| 34 // Sleep for two seconds to allow for the login backoff logic to reset. |
| 35 base.Promise.sleep.bind(null, LOGIN_BACKOFF_WAIT) |
| 36 ).then( |
| 37 this.connect_.bind(this) |
| 38 ).then( |
| 39 this.enterPIN_.bind(this, data.new_pin, false /* expectError*/) |
| 40 ).then( |
| 41 // Clean up the test by disconnecting and changing the PIN back |
| 42 this.disconnect_.bind(this) |
| 43 ).then( |
| 44 // The PIN must be restored regardless of success or failure. |
| 45 this.changePIN_.bind(this, data.old_pin), |
| 46 this.changePIN_.bind(this, data.old_pin) |
| 47 ).then( |
| 48 // On fulfilled. |
| 49 browserTest.pass, |
| 50 // On rejected. |
| 51 browserTest.fail |
| 52 ); |
| 53 }; |
| 54 |
| 55 browserTest.Update_PIN.prototype.changePIN_ = function(newPin) { |
| 56 var AppMode = remoting.AppMode; |
| 57 var HOST_RESTART_WAIT = 10000; |
| 58 |
| 59 browserTest.clickOnControl('change-daemon-pin'); |
| 60 |
| 61 return browserTest.onUIMode(AppMode.HOST_SETUP_ASK_PIN).then(function() { |
| 62 var onSetupDone = browserTest.onUIMode(AppMode.HOST_SETUP_DONE); |
| 63 document.getElementById('daemon-pin-entry').value = newPin; |
| 64 document.getElementById('daemon-pin-confirm').value = newPin; |
| 65 browserTest.clickOnControl('daemon-pin-ok'); |
| 66 return onSetupDone; |
| 67 }).then(function() { |
| 68 browserTest.clickOnControl('host-config-done-dismiss'); |
| 69 // On Linux, we restart the host after changing the PIN, need to sleep |
| 70 // for ten seconds before the host is ready for connection. |
| 71 return base.Promise.sleep(HOST_RESTART_WAIT); |
| 72 }); |
| 73 }; |
| 74 |
| 75 browserTest.Update_PIN.prototype.connect_ = function() { |
| 76 browserTest.clickOnControl('this-host-connect'); |
| 77 return browserTest.onUIMode(remoting.AppMode.CLIENT_PIN_PROMPT); |
| 78 }; |
| 79 |
| 80 browserTest.Update_PIN.prototype.disconnect_ = function() { |
| 81 var AppMode = remoting.AppMode; |
| 82 |
| 83 remoting.disconnect(); |
| 84 |
| 85 return browserTest.onUIMode(AppMode.CLIENT_SESSION_FINISHED_ME2ME) |
| 86 .then(function() { |
| 87 var onHome = browserTest.onUIMode(AppMode.HOME); |
| 88 browserTest.clickOnControl('client-finished-me2me-button'); |
| 89 return onHome; |
| 90 }); |
| 91 }; |
| 92 |
| 93 browserTest.Update_PIN.prototype.enterPIN_ = function(pin, expectError) { |
| 94 // Wait for 500ms before hitting the PIN button. From experiment, sometimes |
| 95 // the PIN prompt does not dismiss without the timeout. |
| 96 var CONNECT_PIN_WAIT = 500; |
| 97 |
| 98 document.getElementById('pin-entry').value = pin; |
| 99 |
| 100 return base.Promise.sleep(CONNECT_PIN_WAIT).then(function() { |
| 101 browserTest.clickOnControl('pin-connect-button'); |
| 102 }).then(function() { |
| 103 if (expectError) { |
| 104 return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE); |
| 105 } else { |
| 106 return browserTest.expectMe2MeConnected(); |
| 107 } |
| 108 }); |
| 109 }; |
OLD | NEW |