Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Unified Diff: remoting/webapp/browser_test/update_pin_browser_test.js

Issue 273753002: Implement 3 PIN browser tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address CR feedbacks Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/browser_test/update_pin_browser_test.js
diff --git a/remoting/webapp/browser_test/update_pin_browser_test.js b/remoting/webapp/browser_test/update_pin_browser_test.js
new file mode 100644
index 0000000000000000000000000000000000000000..a1d3d5c91a31257f0ded972affdbeaf263779e2c
--- /dev/null
+++ b/remoting/webapp/browser_test/update_pin_browser_test.js
@@ -0,0 +1,111 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview
+ * @suppress {checkTypes}
+ * Browser test for the scenario below:
+ * 1. Change the PIN.
+ * 2. Connect with the new PIN.
+ * 3. Verify the connection succeeded.
+ * 4. Disconnect and reconnect with the old PIN.
+ * 5. Verify the connection failed.
+ */
+
+'use strict';
+
+/** @constructor */
+browserTest.Update_PIN = function() {};
+
+browserTest.Update_PIN.prototype.run = function(data) {
+ var HOST_RESTART_WAIT = 10000;
+ var LOGIN_BACKOFF_WAIT = 2000;
+ // Input validation
+ browserTest.expect(typeof data.new_pin == 'string');
+ browserTest.expect(typeof data.old_pin == 'string');
+ browserTest.expect(data.new_pin != data.old_pin,
+ 'The new PIN and the old PIN cannot be the same');
+
+ this.changePIN_(data.new_pin).then(function() {
+ browserTest.clickOnControl('host-config-done-dismiss');
+ // 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.
+ // for ten seconds before the host is ready for connection.
+ 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.
+ }).then(
+ this.connect_.bind(this)
+ ).then(
+ this.enterPIN_.bind(this, data.old_pin, true /* expectError*/)
+ ).then(
+ // Sleep for two seconds to allow for the login backoff logic to reset.
+ base.Promise.sleep.bind(null, LOGIN_BACKOFF_WAIT)
+ ).then(
+ this.connect_.bind(this)
+ ).then(
+ this.enterPIN_.bind(this, data.new_pin, false /* expectError*/)
+ ).then(
+ // clean up the test by disconnecting and changing the PIN back
+ this.disconnect_.bind(this)
+ ).then(
+ // On fulfilled.
+ this.changePIN_.bind(this, data.old_pin),
+ // On rejected.
+ 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
+ ).then(
+ // On fulfilled.
+ browserTest.pass,
+ // On rejected.
+ browserTest.fail
+ );
+};
+
+browserTest.Update_PIN.prototype.changePIN_ = function(newPin) {
+ var AppMode = remoting.AppMode;
+ var promise = browserTest.onUIMode(AppMode.HOST_SETUP_ASK_PIN)
+ .then(function() {
+ var onSetupDone = browserTest.onUIMode(AppMode.HOST_SETUP_DONE);
+ document.getElementById('daemon-pin-entry').value = newPin;
+ document.getElementById('daemon-pin-confirm').value = newPin;
+ browserTest.clickOnControl('daemon-pin-ok');
+ return onSetupDone;
+ });
+ browserTest.clickOnControl('change-daemon-pin');
+ return promise;
+};
+
+browserTest.Update_PIN.prototype.connect_ = function() {
+ var promise = browserTest.onUIMode(remoting.AppMode.CLIENT_PIN_PROMPT);
+ browserTest.clickOnControl('this-host-connect');
+ return promise;
+};
+
+browserTest.Update_PIN.prototype.disconnect_ = function() {
+ var AppMode = remoting.AppMode;
+ var promise = browserTest.onUIMode(AppMode.CLIENT_SESSION_FINISHED_ME2ME)
+ .then(function() {
+ var onHome = browserTest.onUIMode(AppMode.HOME);
+ browserTest.clickOnControl('client-finished-me2me-button');
+ return onHome;
+ });
+ remoting.disconnect();
+ return promise;
+};
+
+browserTest.Update_PIN.prototype.enterPIN_ = function(pin, expectError) {
+ var CONNECT_PIN_WAIT = 500;
+ document.getElementById('pin-entry').value = pin;
+
+ // Wait for 500ms before hitting the PIN button. From experiment, sometimes
+ // 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.
+ return base.Promise.sleep(CONNECT_PIN_WAIT).then(function(){
+ browserTest.clickOnControl('pin-connect-button');
+ }).then(function() {
+ if (expectError) {
+ return browserTest.expectMe2MeError(remoting.Error.INVALID_ACCESS_CODE);
+ } else {
+ return browserTest.expectMe2MeConnected();
+ }
+ }.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!
+};
+
+

Powered by Google App Engine
This is Rietveld 408576698