mobile/android/base/tests/testMasterPassword.java

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 package org.mozilla.gecko.tests;
michael@0 2
michael@0 3 import org.mozilla.gecko.Actions;
michael@0 4
michael@0 5 /* This patch tests the Master Password feature first by enabling the password,
michael@0 6 then testing it on a login page and finally disabling the password */
michael@0 7 public class testMasterPassword extends PixelTest {
michael@0 8 Device dev;
michael@0 9
michael@0 10 public void testMasterPassword() {
michael@0 11 blockForGeckoReady();
michael@0 12
michael@0 13 dev = new Device();
michael@0 14 String password = ("Good");
michael@0 15 String badPassword = ("Bad");
michael@0 16
michael@0 17 enableMasterPassword(password, badPassword);
michael@0 18 verifyLoginPage(password, badPassword);
michael@0 19 disableMasterPassword(password, badPassword);
michael@0 20 }
michael@0 21
michael@0 22 public void enableMasterPassword(String password, String badPassword) {
michael@0 23
michael@0 24 // Look for the 'Settings' menu if this device/OS uses it
michael@0 25 selectSettingsItem("Privacy", "Use master password");
michael@0 26 waitForText("^Create Master Password$");
michael@0 27
michael@0 28 // Verify that the OK button is not activated until both fields are filled
michael@0 29 closeTabletKeyboard();
michael@0 30 mAsserter.ok(!mSolo.getButton("OK").isEnabled(), "Verify if the OK button is inactive", "The OK button is inactive until both fields are filled");
michael@0 31
michael@0 32 // Verify that the OK button is not activated until the Confirm password field is filled
michael@0 33 editPasswordField(0, password);
michael@0 34 mAsserter.ok(!mSolo.getButton("OK").isEnabled(), "Verify if the OK button is inactive", "The OK button is inactive until the Confirm password field is filled");
michael@0 35
michael@0 36 // Verify that the OK button is not activated until both fields contain the same password
michael@0 37 editPasswordField(1, badPassword);
michael@0 38 mAsserter.ok(!mSolo.getButton("OK").isEnabled(), "Verify if the OK button is inactive", "The OK button is inactive until both fields contain the same password");
michael@0 39
michael@0 40 // Verify that the OK button is not activated until the Password field is filled
michael@0 41 mSolo.clearEditText(0);
michael@0 42 mAsserter.ok(!mSolo.getButton("OK").isEnabled(), "Verify if the OK button is inactive", "The OK button is inactive until the Password field is filled");
michael@0 43
michael@0 44 // Check that the Master Password is not set when canceling the action
michael@0 45 mSolo.clickOnEditText(0);
michael@0 46 mActions.sendKeys(password);
michael@0 47 mSolo.clearEditText(1);
michael@0 48 mSolo.clickOnEditText(1);
michael@0 49 mActions.sendKeys(password);
michael@0 50 waitForText("^Cancel$");
michael@0 51 mSolo.clickOnText("^Cancel$");
michael@0 52 waitForText("^Use master password$");
michael@0 53 mSolo.clickOnText("^Use master password$");
michael@0 54 mAsserter.ok(mSolo.waitForText("^Create Master Password$"), "Checking if no password was set if the action was canceled", "No password was set");
michael@0 55
michael@0 56 // Enable Master Password
michael@0 57 mSolo.clickOnEditText(0);
michael@0 58 mActions.sendKeys(password);
michael@0 59 mSolo.clickOnEditText(1);
michael@0 60 mActions.sendKeys(password);
michael@0 61
michael@0 62 // Verify that the input characters are converted to dots automatically
michael@0 63 mAsserter.ok(waitForText("."), "waiting to convert the letters in dots", "The letters are converted in dots");
michael@0 64 mSolo.clickOnButton("OK");
michael@0 65
michael@0 66 // Verify that the Master Password was set
michael@0 67 mSolo.searchText("Privacy");
michael@0 68 mAsserter.ok(mSolo.waitForText("^Use master password$"), "Checking if Use master password is present", "Use master password is present");
michael@0 69 mSolo.clickOnText("^Use master password$");
michael@0 70 mAsserter.ok(mSolo.waitForText("Remove Master Password"), "Checking if the password is enabled", "The password is enabled");
michael@0 71 clickOnButton("Cancel"); // Go back to settings menu
michael@0 72
michael@0 73 if ("phone".equals(mDevice.type)) {
michael@0 74 // Phones don't have headers like tablets, so we need to pop up one more level.
michael@0 75 waitForText("Use master password");
michael@0 76 mActions.sendSpecialKey(Actions.SpecialKey.BACK);
michael@0 77 }
michael@0 78 waitForText("Settings");
michael@0 79 mActions.sendSpecialKey(Actions.SpecialKey.BACK);// Close the Settings Menu
michael@0 80 }
michael@0 81
michael@0 82 public void disableMasterPassword(String password, String badPassword) {
michael@0 83
michael@0 84 // Look for the 'Settings' menu if this device/OS uses it
michael@0 85 selectSettingsItem("Privacy", "Use master password");
michael@0 86 waitForText("^Remove Master Password$");
michael@0 87
michael@0 88 // Verify that the OK button is not activated if the password field is empty
michael@0 89 closeTabletKeyboard();
michael@0 90 mAsserter.ok(!mSolo.getButton("OK").isEnabled(), "Verify if the OK button is inactive", "The OK button is inactive if the password field is empty");
michael@0 91
michael@0 92 // Verify that the OK button is activated if the password field contains characters
michael@0 93 editPasswordField(0, badPassword);
michael@0 94 mAsserter.ok(mSolo.getButton("OK").isEnabled(), "Verify if the OK button is activated", "The OK button is activated even if the wrong password is filled");
michael@0 95 mSolo.clickOnButton("OK");
michael@0 96 mAsserter.ok(mSolo.waitForText("^Incorrect password$"), "Waiting for Incorrect password notification", "The Incorrect password notification appears");
michael@0 97
michael@0 98 // Disable Master Password
michael@0 99 mSolo.clickOnText("^Use master password$");
michael@0 100 waitForText("^Remove Master Password$");
michael@0 101 closeTabletKeyboard();
michael@0 102 editPasswordField(0, password);
michael@0 103 mSolo.clickOnButton("OK");
michael@0 104
michael@0 105 // Verify that the Master Password was disabled
michael@0 106 mSolo.searchText("Privacy");
michael@0 107 mAsserter.ok(mSolo.waitForText("^Use master password$"), "Checking if Use master password is present", "Use master password is present");
michael@0 108 mSolo.clickOnText("^Use master password$");
michael@0 109 mAsserter.ok(waitForText("^Create Master Password$"), "Checking if the password is disabled", "The password is disabled");
michael@0 110 clickOnButton("Cancel"); // Go back to settings menu
michael@0 111 }
michael@0 112
michael@0 113 public void editPasswordField(int i, String password) {
michael@0 114 mSolo.clickOnEditText(i);
michael@0 115 mActions.sendKeys(password);
michael@0 116 toggleVKB(); // Don't use BACK; this will close the password dialog on devices with hardware keyboard.
michael@0 117 }
michael@0 118
michael@0 119 public void noDoorhangerDisplayed(String LOGIN_URL) {
michael@0 120 waitForText("Browser Blank Page 01|Enter Search or Address");
michael@0 121 inputAndLoadUrl(LOGIN_URL);
michael@0 122 mAsserter.is(waitForText("Save password for"), false, "Doorhanger notification is hidden");
michael@0 123 }
michael@0 124
michael@0 125 public void doorhangerDisplayed(String LOGIN_URL) {
michael@0 126 waitForText("Browser Blank Page 01|Enter Search or Address");
michael@0 127 inputAndLoadUrl(LOGIN_URL);
michael@0 128 mAsserter.is(mSolo.waitForText("Save password for"), true, "Doorhanger notification is displayed");
michael@0 129 }
michael@0 130
michael@0 131 // Checks to see if the device is a Tablet, because for those devices we need an extra back action to close the keyboard
michael@0 132 public void closeTabletKeyboard() {
michael@0 133 if (dev.type.equals("tablet")) {
michael@0 134 mSolo.sleep(1500);
michael@0 135 toggleVKB();// Close the keyboard for tablets
michael@0 136 }
michael@0 137 }
michael@0 138
michael@0 139 public void clearPrivateData() {
michael@0 140
michael@0 141 // Look for the 'Settings' menu if this device/OS uses it
michael@0 142 selectSettingsItem("Privacy", "Clear private data");
michael@0 143
michael@0 144 waitForText("Browsing history"); // Make sure the Clear private data pop-up is displayed
michael@0 145 Actions.EventExpecter clearPrivateDataEventExpecter = mActions.expectGeckoEvent("Sanitize:Finished");
michael@0 146 if (mSolo.searchText("Clear data") && !mSolo.searchText("Cookies")) {
michael@0 147 mSolo.clickOnText("^Clear data$");
michael@0 148 clearPrivateDataEventExpecter.blockForEvent();
michael@0 149 } else { // For some reason the pop-up was not opened
michael@0 150 if (mSolo.searchText("Cookies")) {
michael@0 151 mSolo.clickOnText("^Clear private data$");
michael@0 152 waitForText("Browsing history"); // Make sure the Clear private data pop-up is displayed
michael@0 153 mSolo.clickOnText("^Clear data$");
michael@0 154 clearPrivateDataEventExpecter.blockForEvent();
michael@0 155 } else {
michael@0 156 mAsserter.ok(false, "Something happened and the clear data dialog could not be opened", "Failed to clear data");
michael@0 157 }
michael@0 158 }
michael@0 159
michael@0 160 // Check that the Master Password isn't disabled by clearing private data
michael@0 161 waitForText("^Use master password$");
michael@0 162 mSolo.clickOnText("^Use master password$");
michael@0 163 mAsserter.ok(mSolo.searchText("^Remove Master Password$"), "Checking if the master password was disabled by clearing private data", "The master password is not disabled by clearing private data");
michael@0 164 clickOnButton("Cancel"); // Close the Master Password menu
michael@0 165
michael@0 166 if ("phone".equals(mDevice.type)) {
michael@0 167 // Phones don't have headers like tablets, so we need to pop up one more level.
michael@0 168 waitForText("Use master password");
michael@0 169 mActions.sendSpecialKey(Actions.SpecialKey.BACK);
michael@0 170 }
michael@0 171 waitForText("Settings");
michael@0 172 mActions.sendSpecialKey(Actions.SpecialKey.BACK);// Close the Settings Menu
michael@0 173 // Make sure the settings menu has been closed.
michael@0 174 mAsserter.ok(mSolo.waitForText("Browser Blank Page 01"), "Waiting for blank browser page after exiting settings", "Blank browser page present");
michael@0 175 }
michael@0 176
michael@0 177 public void verifyLoginPage(String password, String badPassword) {
michael@0 178 String LOGIN_URL = getAbsoluteUrl("/robocop/robocop_login.html");
michael@0 179 String option [] = {"Save", "Don't save"};
michael@0 180
michael@0 181 doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed
michael@0 182
michael@0 183 // TODO: Remove this hack -- see bug 915449
michael@0 184 mSolo.sleep(2000);
michael@0 185
michael@0 186 for (String item:option) {
michael@0 187 if (item.equals("Save")) {
michael@0 188 final String OK_BUTTON_LABEL = "^OK$";
michael@0 189 final String SAVE_BUTTON_LABEL = "^Save$";
michael@0 190 mAsserter.ok(mSolo.waitForText(SAVE_BUTTON_LABEL), "Checking if Save option is present", "Save option is present");
michael@0 191 mSolo.clickOnButton(SAVE_BUTTON_LABEL);
michael@0 192
michael@0 193 // Verify that the Master Password isn't deactivated when the password field is empty
michael@0 194 closeTabletKeyboard();
michael@0 195 waitForText(OK_BUTTON_LABEL);
michael@0 196 mSolo.clickOnButton(OK_BUTTON_LABEL);
michael@0 197
michael@0 198 // Verify that the Master Password isn't deactivated when using the wrong password
michael@0 199 closeTabletKeyboard();
michael@0 200 editPasswordField(0, badPassword);
michael@0 201 waitForText(OK_BUTTON_LABEL);
michael@0 202 mSolo.clickOnButton(OK_BUTTON_LABEL);
michael@0 203
michael@0 204 // Verify that the Master Password is deactivated when using the right password
michael@0 205 closeTabletKeyboard();
michael@0 206 editPasswordField(0, password);
michael@0 207 waitForText(OK_BUTTON_LABEL);
michael@0 208 mSolo.clickOnButton(OK_BUTTON_LABEL);
michael@0 209
michael@0 210 // Verify that the Master Password is triggered once per session
michael@0 211 noDoorhangerDisplayed(LOGIN_URL);// Check that the doorhanger isn't displayed
michael@0 212 } else {
michael@0 213 clearPrivateData();
michael@0 214 doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed
michael@0 215 mAsserter.ok(mSolo.waitForText("Don't save"), "Checking if Don't save option is present again", "Don't save option is present again");
michael@0 216 mSolo.clickOnText("Don't save");
michael@0 217 doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed again
michael@0 218 mAsserter.ok(mSolo.waitForText("Don't save"), "Checking if Don't save option is present again", "Don't save option is present again");
michael@0 219 mSolo.clickOnText("Don't save");
michael@0 220 // Make sure the settings menu has been closed.
michael@0 221 mAsserter.ok(mSolo.waitForText("Browser Blank Page 01"), "Waiting for blank browser page after exiting settings", "Blank browser page present");
michael@0 222 }
michael@0 223 }
michael@0 224 }
michael@0 225 }

mercurial