1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/tests/testMasterPassword.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,225 @@ 1.4 +package org.mozilla.gecko.tests; 1.5 + 1.6 +import org.mozilla.gecko.Actions; 1.7 + 1.8 +/* This patch tests the Master Password feature first by enabling the password, 1.9 +then testing it on a login page and finally disabling the password */ 1.10 +public class testMasterPassword extends PixelTest { 1.11 + Device dev; 1.12 + 1.13 + public void testMasterPassword() { 1.14 + blockForGeckoReady(); 1.15 + 1.16 + dev = new Device(); 1.17 + String password = ("Good"); 1.18 + String badPassword = ("Bad"); 1.19 + 1.20 + enableMasterPassword(password, badPassword); 1.21 + verifyLoginPage(password, badPassword); 1.22 + disableMasterPassword(password, badPassword); 1.23 + } 1.24 + 1.25 + public void enableMasterPassword(String password, String badPassword) { 1.26 + 1.27 + // Look for the 'Settings' menu if this device/OS uses it 1.28 + selectSettingsItem("Privacy", "Use master password"); 1.29 + waitForText("^Create Master Password$"); 1.30 + 1.31 + // Verify that the OK button is not activated until both fields are filled 1.32 + closeTabletKeyboard(); 1.33 + mAsserter.ok(!mSolo.getButton("OK").isEnabled(), "Verify if the OK button is inactive", "The OK button is inactive until both fields are filled"); 1.34 + 1.35 + // Verify that the OK button is not activated until the Confirm password field is filled 1.36 + editPasswordField(0, password); 1.37 + 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"); 1.38 + 1.39 + // Verify that the OK button is not activated until both fields contain the same password 1.40 + editPasswordField(1, badPassword); 1.41 + 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"); 1.42 + 1.43 + // Verify that the OK button is not activated until the Password field is filled 1.44 + mSolo.clearEditText(0); 1.45 + mAsserter.ok(!mSolo.getButton("OK").isEnabled(), "Verify if the OK button is inactive", "The OK button is inactive until the Password field is filled"); 1.46 + 1.47 + // Check that the Master Password is not set when canceling the action 1.48 + mSolo.clickOnEditText(0); 1.49 + mActions.sendKeys(password); 1.50 + mSolo.clearEditText(1); 1.51 + mSolo.clickOnEditText(1); 1.52 + mActions.sendKeys(password); 1.53 + waitForText("^Cancel$"); 1.54 + mSolo.clickOnText("^Cancel$"); 1.55 + waitForText("^Use master password$"); 1.56 + mSolo.clickOnText("^Use master password$"); 1.57 + mAsserter.ok(mSolo.waitForText("^Create Master Password$"), "Checking if no password was set if the action was canceled", "No password was set"); 1.58 + 1.59 + // Enable Master Password 1.60 + mSolo.clickOnEditText(0); 1.61 + mActions.sendKeys(password); 1.62 + mSolo.clickOnEditText(1); 1.63 + mActions.sendKeys(password); 1.64 + 1.65 + // Verify that the input characters are converted to dots automatically 1.66 + mAsserter.ok(waitForText("."), "waiting to convert the letters in dots", "The letters are converted in dots"); 1.67 + mSolo.clickOnButton("OK"); 1.68 + 1.69 + // Verify that the Master Password was set 1.70 + mSolo.searchText("Privacy"); 1.71 + mAsserter.ok(mSolo.waitForText("^Use master password$"), "Checking if Use master password is present", "Use master password is present"); 1.72 + mSolo.clickOnText("^Use master password$"); 1.73 + mAsserter.ok(mSolo.waitForText("Remove Master Password"), "Checking if the password is enabled", "The password is enabled"); 1.74 + clickOnButton("Cancel"); // Go back to settings menu 1.75 + 1.76 + if ("phone".equals(mDevice.type)) { 1.77 + // Phones don't have headers like tablets, so we need to pop up one more level. 1.78 + waitForText("Use master password"); 1.79 + mActions.sendSpecialKey(Actions.SpecialKey.BACK); 1.80 + } 1.81 + waitForText("Settings"); 1.82 + mActions.sendSpecialKey(Actions.SpecialKey.BACK);// Close the Settings Menu 1.83 + } 1.84 + 1.85 + public void disableMasterPassword(String password, String badPassword) { 1.86 + 1.87 + // Look for the 'Settings' menu if this device/OS uses it 1.88 + selectSettingsItem("Privacy", "Use master password"); 1.89 + waitForText("^Remove Master Password$"); 1.90 + 1.91 + // Verify that the OK button is not activated if the password field is empty 1.92 + closeTabletKeyboard(); 1.93 + mAsserter.ok(!mSolo.getButton("OK").isEnabled(), "Verify if the OK button is inactive", "The OK button is inactive if the password field is empty"); 1.94 + 1.95 + // Verify that the OK button is activated if the password field contains characters 1.96 + editPasswordField(0, badPassword); 1.97 + 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"); 1.98 + mSolo.clickOnButton("OK"); 1.99 + mAsserter.ok(mSolo.waitForText("^Incorrect password$"), "Waiting for Incorrect password notification", "The Incorrect password notification appears"); 1.100 + 1.101 + // Disable Master Password 1.102 + mSolo.clickOnText("^Use master password$"); 1.103 + waitForText("^Remove Master Password$"); 1.104 + closeTabletKeyboard(); 1.105 + editPasswordField(0, password); 1.106 + mSolo.clickOnButton("OK"); 1.107 + 1.108 + // Verify that the Master Password was disabled 1.109 + mSolo.searchText("Privacy"); 1.110 + mAsserter.ok(mSolo.waitForText("^Use master password$"), "Checking if Use master password is present", "Use master password is present"); 1.111 + mSolo.clickOnText("^Use master password$"); 1.112 + mAsserter.ok(waitForText("^Create Master Password$"), "Checking if the password is disabled", "The password is disabled"); 1.113 + clickOnButton("Cancel"); // Go back to settings menu 1.114 + } 1.115 + 1.116 + public void editPasswordField(int i, String password) { 1.117 + mSolo.clickOnEditText(i); 1.118 + mActions.sendKeys(password); 1.119 + toggleVKB(); // Don't use BACK; this will close the password dialog on devices with hardware keyboard. 1.120 + } 1.121 + 1.122 + public void noDoorhangerDisplayed(String LOGIN_URL) { 1.123 + waitForText("Browser Blank Page 01|Enter Search or Address"); 1.124 + inputAndLoadUrl(LOGIN_URL); 1.125 + mAsserter.is(waitForText("Save password for"), false, "Doorhanger notification is hidden"); 1.126 + } 1.127 + 1.128 + public void doorhangerDisplayed(String LOGIN_URL) { 1.129 + waitForText("Browser Blank Page 01|Enter Search or Address"); 1.130 + inputAndLoadUrl(LOGIN_URL); 1.131 + mAsserter.is(mSolo.waitForText("Save password for"), true, "Doorhanger notification is displayed"); 1.132 + } 1.133 + 1.134 + // Checks to see if the device is a Tablet, because for those devices we need an extra back action to close the keyboard 1.135 + public void closeTabletKeyboard() { 1.136 + if (dev.type.equals("tablet")) { 1.137 + mSolo.sleep(1500); 1.138 + toggleVKB();// Close the keyboard for tablets 1.139 + } 1.140 + } 1.141 + 1.142 + public void clearPrivateData() { 1.143 + 1.144 + // Look for the 'Settings' menu if this device/OS uses it 1.145 + selectSettingsItem("Privacy", "Clear private data"); 1.146 + 1.147 + waitForText("Browsing history"); // Make sure the Clear private data pop-up is displayed 1.148 + Actions.EventExpecter clearPrivateDataEventExpecter = mActions.expectGeckoEvent("Sanitize:Finished"); 1.149 + if (mSolo.searchText("Clear data") && !mSolo.searchText("Cookies")) { 1.150 + mSolo.clickOnText("^Clear data$"); 1.151 + clearPrivateDataEventExpecter.blockForEvent(); 1.152 + } else { // For some reason the pop-up was not opened 1.153 + if (mSolo.searchText("Cookies")) { 1.154 + mSolo.clickOnText("^Clear private data$"); 1.155 + waitForText("Browsing history"); // Make sure the Clear private data pop-up is displayed 1.156 + mSolo.clickOnText("^Clear data$"); 1.157 + clearPrivateDataEventExpecter.blockForEvent(); 1.158 + } else { 1.159 + mAsserter.ok(false, "Something happened and the clear data dialog could not be opened", "Failed to clear data"); 1.160 + } 1.161 + } 1.162 + 1.163 + // Check that the Master Password isn't disabled by clearing private data 1.164 + waitForText("^Use master password$"); 1.165 + mSolo.clickOnText("^Use master password$"); 1.166 + 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"); 1.167 + clickOnButton("Cancel"); // Close the Master Password menu 1.168 + 1.169 + if ("phone".equals(mDevice.type)) { 1.170 + // Phones don't have headers like tablets, so we need to pop up one more level. 1.171 + waitForText("Use master password"); 1.172 + mActions.sendSpecialKey(Actions.SpecialKey.BACK); 1.173 + } 1.174 + waitForText("Settings"); 1.175 + mActions.sendSpecialKey(Actions.SpecialKey.BACK);// Close the Settings Menu 1.176 + // Make sure the settings menu has been closed. 1.177 + mAsserter.ok(mSolo.waitForText("Browser Blank Page 01"), "Waiting for blank browser page after exiting settings", "Blank browser page present"); 1.178 + } 1.179 + 1.180 + public void verifyLoginPage(String password, String badPassword) { 1.181 + String LOGIN_URL = getAbsoluteUrl("/robocop/robocop_login.html"); 1.182 + String option [] = {"Save", "Don't save"}; 1.183 + 1.184 + doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed 1.185 + 1.186 + // TODO: Remove this hack -- see bug 915449 1.187 + mSolo.sleep(2000); 1.188 + 1.189 + for (String item:option) { 1.190 + if (item.equals("Save")) { 1.191 + final String OK_BUTTON_LABEL = "^OK$"; 1.192 + final String SAVE_BUTTON_LABEL = "^Save$"; 1.193 + mAsserter.ok(mSolo.waitForText(SAVE_BUTTON_LABEL), "Checking if Save option is present", "Save option is present"); 1.194 + mSolo.clickOnButton(SAVE_BUTTON_LABEL); 1.195 + 1.196 + // Verify that the Master Password isn't deactivated when the password field is empty 1.197 + closeTabletKeyboard(); 1.198 + waitForText(OK_BUTTON_LABEL); 1.199 + mSolo.clickOnButton(OK_BUTTON_LABEL); 1.200 + 1.201 + // Verify that the Master Password isn't deactivated when using the wrong password 1.202 + closeTabletKeyboard(); 1.203 + editPasswordField(0, badPassword); 1.204 + waitForText(OK_BUTTON_LABEL); 1.205 + mSolo.clickOnButton(OK_BUTTON_LABEL); 1.206 + 1.207 + // Verify that the Master Password is deactivated when using the right password 1.208 + closeTabletKeyboard(); 1.209 + editPasswordField(0, password); 1.210 + waitForText(OK_BUTTON_LABEL); 1.211 + mSolo.clickOnButton(OK_BUTTON_LABEL); 1.212 + 1.213 + // Verify that the Master Password is triggered once per session 1.214 + noDoorhangerDisplayed(LOGIN_URL);// Check that the doorhanger isn't displayed 1.215 + } else { 1.216 + clearPrivateData(); 1.217 + doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed 1.218 + mAsserter.ok(mSolo.waitForText("Don't save"), "Checking if Don't save option is present again", "Don't save option is present again"); 1.219 + mSolo.clickOnText("Don't save"); 1.220 + doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed again 1.221 + mAsserter.ok(mSolo.waitForText("Don't save"), "Checking if Don't save option is present again", "Don't save option is present again"); 1.222 + mSolo.clickOnText("Don't save"); 1.223 + // Make sure the settings menu has been closed. 1.224 + mAsserter.ok(mSolo.waitForText("Browser Blank Page 01"), "Waiting for blank browser page after exiting settings", "Blank browser page present"); 1.225 + } 1.226 + } 1.227 + } 1.228 +}