| 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} | 7 * @suppress {checkTypes} |
| 8 * Browser test for the scenario below: | 8 * Browser test for the scenario below: |
| 9 * 1. Change the PIN. | 9 * 1. Change the PIN. |
| 10 * 2. Connect with the new PIN. | 10 * 2. Connect with the new PIN. |
| 11 * 3. Verify the connection succeeded. | 11 * 3. Verify the connection succeeded. |
| 12 * 4. Disconnect and reconnect with the old PIN. | 12 * 4. Disconnect and reconnect with the old PIN. |
| 13 * 5. Verify the connection failed. | 13 * 5. Verify the connection failed. |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 'use strict'; | 16 'use strict'; |
| 17 | 17 |
| 18 /** @constructor */ | 18 /** @constructor */ |
| 19 browserTest.Update_PIN = function() {}; | 19 browserTest.Update_PIN = function() {}; |
| 20 | 20 |
| 21 /** |
| 22 * @param {{new_pin: string, old_pin: string}} data |
| 23 */ |
| 21 browserTest.Update_PIN.prototype.run = function(data) { | 24 browserTest.Update_PIN.prototype.run = function(data) { |
| 22 var LOGIN_BACKOFF_WAIT = 2000; | 25 var LOGIN_BACKOFF_WAIT = 2000; |
| 23 // Input validation | 26 // Input validation |
| 24 browserTest.expect(typeof data.new_pin == 'string'); | 27 browserTest.expect(typeof data.new_pin == 'string'); |
| 25 browserTest.expect(typeof data.old_pin == 'string'); | 28 browserTest.expect(typeof data.old_pin == 'string'); |
| 26 browserTest.expect(data.new_pin != data.old_pin, | 29 browserTest.expect(data.new_pin != data.old_pin, |
| 27 'The new PIN and the old PIN cannot be the same'); | 30 'The new PIN and the old PIN cannot be the same'); |
| 28 | 31 |
| 29 this.changePIN_(data.new_pin).then( | 32 this.changePIN_(data.new_pin).then( |
| 30 browserTest.connectMe2Me | 33 browserTest.connectMe2Me |
| 31 ).then(function(){ | 34 ).then(function(){ |
| 32 return browserTest.enterPIN(data.old_pin, true /* expectError*/); | 35 return browserTest.enterPIN(data.old_pin, true /* expectError*/); |
| 33 }).then( | 36 }).then( |
| 34 // Sleep for two seconds to allow for the login backoff logic to reset. | 37 // Sleep for two seconds to allow for the login backoff logic to reset. |
| 35 base.Promise.sleep.bind(null, LOGIN_BACKOFF_WAIT) | 38 base.Promise.sleep.bind(null, LOGIN_BACKOFF_WAIT) |
| 36 ).then( | 39 ).then( |
| 37 browserTest.connectMe2Me | 40 browserTest.connectMe2Me |
| 38 ).then(function(){ | 41 ).then(function(){ |
| 39 return browserTest.enterPIN_(data.new_pin, false /* expectError*/) | 42 return browserTest.enterPIN(data.new_pin, false /* expectError*/) |
| 40 }).then( | 43 }).then( |
| 41 // Clean up the test by disconnecting and changing the PIN back | 44 // Clean up the test by disconnecting and changing the PIN back |
| 42 browserTest.disconnect | 45 browserTest.disconnect |
| 43 ).then( | 46 ).then( |
| 44 // The PIN must be restored regardless of success or failure. | 47 // The PIN must be restored regardless of success or failure. |
| 45 this.changePIN_.bind(this, data.old_pin), | 48 this.changePIN_.bind(this, data.old_pin), |
| 46 this.changePIN_.bind(this, data.old_pin) | 49 this.changePIN_.bind(this, data.old_pin) |
| 47 ).then( | 50 ).then( |
| 48 // On fulfilled. | 51 // On fulfilled. |
| 49 browserTest.pass, | 52 browserTest.pass, |
| 50 // On rejected. | 53 // On rejected. |
| 51 browserTest.fail | 54 browserTest.fail |
| 52 ); | 55 ); |
| 53 }; | 56 }; |
| 54 | 57 |
| 58 /** |
| 59 * @param {string} newPin |
| 60 * @return {Promise} |
| 61 */ |
| 55 browserTest.Update_PIN.prototype.changePIN_ = function(newPin) { | 62 browserTest.Update_PIN.prototype.changePIN_ = function(newPin) { |
| 56 var AppMode = remoting.AppMode; | 63 var AppMode = remoting.AppMode; |
| 57 var HOST_RESTART_WAIT = 10000; | 64 var HOST_RESTART_WAIT = 10000; |
| 58 browserTest.clickOnControl('change-daemon-pin'); | 65 browserTest.clickOnControl('change-daemon-pin'); |
| 59 return browserTest.setupPIN(newPin); | 66 return browserTest.setupPIN(newPin); |
| 60 }; | 67 }; |
| OLD | NEW |