Chromium Code Reviews| 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 HOST_RESTART_WAIT = 10000; | |
| 23 var LOGIN_BACKOFF_WAIT = 2000; | |
| 24 // Input validation | |
| 25 browserTest.expect(typeof data.new_pin == 'string'); | |
| 26 browserTest.expect(typeof data.old_pin == 'string'); | |
| 27 browserTest.expect(data.new_pin != data.old_pin, | |
| 28 'The new PIN and the old PIN cannot be the same'); | |
| 29 | |
| 30 this.changePIN_(data.new_pin).then(function() { | |
| 31 browserTest.clickOnControl('host-config-done-dismiss'); | |
| 32 // On Linux, we restart the host after changing the password, need to sleep | |
|
Jamie
2014/05/13 18:59:54
s/password/PIN/
kelvinp
2014/05/13 23:11:01
Done.
| |
| 33 // for ten seconds before the host is ready for connection. | |
| 34 return base.Promise.sleep(HOST_RESTART_WAIT); | |
|
Jamie
2014/05/13 18:59:54
There are a few places you change the PIN. Would i
kelvinp
2014/05/13 23:11:01
Done.
| |
| 35 }).then( | |
| 36 this.connect_.bind(this) | |
| 37 ).then( | |
| 38 this.enterPIN_.bind(this, data.old_pin, true /* expectError*/) | |
| 39 ).then( | |
| 40 // Sleep for two seconds to allow for the login backoff logic to reset. | |
| 41 base.Promise.sleep.bind(null, LOGIN_BACKOFF_WAIT) | |
| 42 ).then( | |
| 43 this.connect_.bind(this) | |
| 44 ).then( | |
| 45 this.enterPIN_.bind(this, data.new_pin, false /* expectError*/) | |
| 46 ).then( | |
| 47 // clean up the test by disconnecting and changing the PIN back | |
| 48 this.disconnect_.bind(this) | |
| 49 ).then( | |
| 50 // On fulfilled. | |
| 51 this.changePIN_.bind(this, data.old_pin), | |
| 52 // On rejected. | |
| 53 this.changePIN_.bind(this, data.old_pin) | |
|
Jamie
2014/05/13 18:59:54
Do promises have a concept of "finally"? Restoring
kelvinp
2014/05/13 23:11:01
The WinJS implementation has the done() method whi
| |
| 54 ).then( | |
| 55 // On fulfilled. | |
| 56 browserTest.pass, | |
| 57 // On rejected. | |
| 58 browserTest.fail | |
| 59 ); | |
| 60 }; | |
| 61 | |
| 62 browserTest.Update_PIN.prototype.changePIN_ = function(newPin) { | |
| 63 var AppMode = remoting.AppMode; | |
| 64 var promise = browserTest.onUIMode(AppMode.HOST_SETUP_ASK_PIN) | |
| 65 .then(function() { | |
| 66 var onSetupDone = browserTest.onUIMode(AppMode.HOST_SETUP_DONE); | |
| 67 document.getElementById('daemon-pin-entry').value = newPin; | |
| 68 document.getElementById('daemon-pin-confirm').value = newPin; | |
| 69 browserTest.clickOnControl('daemon-pin-ok'); | |
| 70 return onSetupDone; | |
| 71 }); | |
| 72 browserTest.clickOnControl('change-daemon-pin'); | |
| 73 return promise; | |
| 74 }; | |
| 75 | |
| 76 browserTest.Update_PIN.prototype.connect_ = function() { | |
| 77 var promise = browserTest.onUIMode(remoting.AppMode.CLIENT_PIN_PROMPT); | |
| 78 browserTest.clickOnControl('this-host-connect'); | |
| 79 return promise; | |
| 80 }; | |
| 81 | |
| 82 browserTest.Update_PIN.prototype.disconnect_ = function() { | |
| 83 var AppMode = remoting.AppMode; | |
| 84 var promise = browserTest.onUIMode(AppMode.CLIENT_SESSION_FINISHED_ME2ME) | |
| 85 .then(function() { | |
| 86 var onHome = browserTest.onUIMode(AppMode.HOME); | |
| 87 browserTest.clickOnControl('client-finished-me2me-button'); | |
| 88 return onHome; | |
| 89 }); | |
| 90 remoting.disconnect(); | |
| 91 return promise; | |
| 92 }; | |
| 93 | |
| 94 browserTest.Update_PIN.prototype.enterPIN_ = function(pin, expectError) { | |
| 95 var CONNECT_PIN_WAIT = 500; | |
| 96 document.getElementById('pin-entry').value = pin; | |
| 97 | |
| 98 // Wait for 500ms before hitting the PIN button. From experiment, sometimes | |
| 99 // the PIN prompt is still up without the timeout. | |
|
Jamie
2014/05/13 18:59:54
s/is still up/does not dismiss/
kelvinp
2014/05/13 23:11:01
Done.
Jamie
2014/05/13 23:27:05
I don't see this change.
kelvinp
2014/05/13 23:50:59
My bad. Fixed.
| |
| 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 }.bind(this)); | |
|
Jamie
2014/05/13 18:59:54
Is this the bind you mentioned wanting to remove?
kelvinp
2014/05/13 23:11:01
Bingo!
| |
| 109 }; | |
| 110 | |
| 111 | |
| OLD | NEW |