michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.mozilla.gecko.Actions; michael@0: michael@0: /* This patch tests the Master Password feature first by enabling the password, michael@0: then testing it on a login page and finally disabling the password */ michael@0: public class testMasterPassword extends PixelTest { michael@0: Device dev; michael@0: michael@0: public void testMasterPassword() { michael@0: blockForGeckoReady(); michael@0: michael@0: dev = new Device(); michael@0: String password = ("Good"); michael@0: String badPassword = ("Bad"); michael@0: michael@0: enableMasterPassword(password, badPassword); michael@0: verifyLoginPage(password, badPassword); michael@0: disableMasterPassword(password, badPassword); michael@0: } michael@0: michael@0: public void enableMasterPassword(String password, String badPassword) { michael@0: michael@0: // Look for the 'Settings' menu if this device/OS uses it michael@0: selectSettingsItem("Privacy", "Use master password"); michael@0: waitForText("^Create Master Password$"); michael@0: michael@0: // Verify that the OK button is not activated until both fields are filled michael@0: closeTabletKeyboard(); michael@0: 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: michael@0: // Verify that the OK button is not activated until the Confirm password field is filled michael@0: editPasswordField(0, password); michael@0: 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: michael@0: // Verify that the OK button is not activated until both fields contain the same password michael@0: editPasswordField(1, badPassword); michael@0: 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: michael@0: // Verify that the OK button is not activated until the Password field is filled michael@0: mSolo.clearEditText(0); michael@0: 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: michael@0: // Check that the Master Password is not set when canceling the action michael@0: mSolo.clickOnEditText(0); michael@0: mActions.sendKeys(password); michael@0: mSolo.clearEditText(1); michael@0: mSolo.clickOnEditText(1); michael@0: mActions.sendKeys(password); michael@0: waitForText("^Cancel$"); michael@0: mSolo.clickOnText("^Cancel$"); michael@0: waitForText("^Use master password$"); michael@0: mSolo.clickOnText("^Use master password$"); michael@0: mAsserter.ok(mSolo.waitForText("^Create Master Password$"), "Checking if no password was set if the action was canceled", "No password was set"); michael@0: michael@0: // Enable Master Password michael@0: mSolo.clickOnEditText(0); michael@0: mActions.sendKeys(password); michael@0: mSolo.clickOnEditText(1); michael@0: mActions.sendKeys(password); michael@0: michael@0: // Verify that the input characters are converted to dots automatically michael@0: mAsserter.ok(waitForText("."), "waiting to convert the letters in dots", "The letters are converted in dots"); michael@0: mSolo.clickOnButton("OK"); michael@0: michael@0: // Verify that the Master Password was set michael@0: mSolo.searchText("Privacy"); michael@0: mAsserter.ok(mSolo.waitForText("^Use master password$"), "Checking if Use master password is present", "Use master password is present"); michael@0: mSolo.clickOnText("^Use master password$"); michael@0: mAsserter.ok(mSolo.waitForText("Remove Master Password"), "Checking if the password is enabled", "The password is enabled"); michael@0: clickOnButton("Cancel"); // Go back to settings menu michael@0: michael@0: if ("phone".equals(mDevice.type)) { michael@0: // Phones don't have headers like tablets, so we need to pop up one more level. michael@0: waitForText("Use master password"); michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK); michael@0: } michael@0: waitForText("Settings"); michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK);// Close the Settings Menu michael@0: } michael@0: michael@0: public void disableMasterPassword(String password, String badPassword) { michael@0: michael@0: // Look for the 'Settings' menu if this device/OS uses it michael@0: selectSettingsItem("Privacy", "Use master password"); michael@0: waitForText("^Remove Master Password$"); michael@0: michael@0: // Verify that the OK button is not activated if the password field is empty michael@0: closeTabletKeyboard(); michael@0: 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: michael@0: // Verify that the OK button is activated if the password field contains characters michael@0: editPasswordField(0, badPassword); michael@0: 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: mSolo.clickOnButton("OK"); michael@0: mAsserter.ok(mSolo.waitForText("^Incorrect password$"), "Waiting for Incorrect password notification", "The Incorrect password notification appears"); michael@0: michael@0: // Disable Master Password michael@0: mSolo.clickOnText("^Use master password$"); michael@0: waitForText("^Remove Master Password$"); michael@0: closeTabletKeyboard(); michael@0: editPasswordField(0, password); michael@0: mSolo.clickOnButton("OK"); michael@0: michael@0: // Verify that the Master Password was disabled michael@0: mSolo.searchText("Privacy"); michael@0: mAsserter.ok(mSolo.waitForText("^Use master password$"), "Checking if Use master password is present", "Use master password is present"); michael@0: mSolo.clickOnText("^Use master password$"); michael@0: mAsserter.ok(waitForText("^Create Master Password$"), "Checking if the password is disabled", "The password is disabled"); michael@0: clickOnButton("Cancel"); // Go back to settings menu michael@0: } michael@0: michael@0: public void editPasswordField(int i, String password) { michael@0: mSolo.clickOnEditText(i); michael@0: mActions.sendKeys(password); michael@0: toggleVKB(); // Don't use BACK; this will close the password dialog on devices with hardware keyboard. michael@0: } michael@0: michael@0: public void noDoorhangerDisplayed(String LOGIN_URL) { michael@0: waitForText("Browser Blank Page 01|Enter Search or Address"); michael@0: inputAndLoadUrl(LOGIN_URL); michael@0: mAsserter.is(waitForText("Save password for"), false, "Doorhanger notification is hidden"); michael@0: } michael@0: michael@0: public void doorhangerDisplayed(String LOGIN_URL) { michael@0: waitForText("Browser Blank Page 01|Enter Search or Address"); michael@0: inputAndLoadUrl(LOGIN_URL); michael@0: mAsserter.is(mSolo.waitForText("Save password for"), true, "Doorhanger notification is displayed"); michael@0: } michael@0: michael@0: // 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: public void closeTabletKeyboard() { michael@0: if (dev.type.equals("tablet")) { michael@0: mSolo.sleep(1500); michael@0: toggleVKB();// Close the keyboard for tablets michael@0: } michael@0: } michael@0: michael@0: public void clearPrivateData() { michael@0: michael@0: // Look for the 'Settings' menu if this device/OS uses it michael@0: selectSettingsItem("Privacy", "Clear private data"); michael@0: michael@0: waitForText("Browsing history"); // Make sure the Clear private data pop-up is displayed michael@0: Actions.EventExpecter clearPrivateDataEventExpecter = mActions.expectGeckoEvent("Sanitize:Finished"); michael@0: if (mSolo.searchText("Clear data") && !mSolo.searchText("Cookies")) { michael@0: mSolo.clickOnText("^Clear data$"); michael@0: clearPrivateDataEventExpecter.blockForEvent(); michael@0: } else { // For some reason the pop-up was not opened michael@0: if (mSolo.searchText("Cookies")) { michael@0: mSolo.clickOnText("^Clear private data$"); michael@0: waitForText("Browsing history"); // Make sure the Clear private data pop-up is displayed michael@0: mSolo.clickOnText("^Clear data$"); michael@0: clearPrivateDataEventExpecter.blockForEvent(); michael@0: } else { michael@0: mAsserter.ok(false, "Something happened and the clear data dialog could not be opened", "Failed to clear data"); michael@0: } michael@0: } michael@0: michael@0: // Check that the Master Password isn't disabled by clearing private data michael@0: waitForText("^Use master password$"); michael@0: mSolo.clickOnText("^Use master password$"); michael@0: 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: clickOnButton("Cancel"); // Close the Master Password menu michael@0: michael@0: if ("phone".equals(mDevice.type)) { michael@0: // Phones don't have headers like tablets, so we need to pop up one more level. michael@0: waitForText("Use master password"); michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK); michael@0: } michael@0: waitForText("Settings"); michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK);// Close the Settings Menu michael@0: // Make sure the settings menu has been closed. michael@0: mAsserter.ok(mSolo.waitForText("Browser Blank Page 01"), "Waiting for blank browser page after exiting settings", "Blank browser page present"); michael@0: } michael@0: michael@0: public void verifyLoginPage(String password, String badPassword) { michael@0: String LOGIN_URL = getAbsoluteUrl("/robocop/robocop_login.html"); michael@0: String option [] = {"Save", "Don't save"}; michael@0: michael@0: doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed michael@0: michael@0: // TODO: Remove this hack -- see bug 915449 michael@0: mSolo.sleep(2000); michael@0: michael@0: for (String item:option) { michael@0: if (item.equals("Save")) { michael@0: final String OK_BUTTON_LABEL = "^OK$"; michael@0: final String SAVE_BUTTON_LABEL = "^Save$"; michael@0: mAsserter.ok(mSolo.waitForText(SAVE_BUTTON_LABEL), "Checking if Save option is present", "Save option is present"); michael@0: mSolo.clickOnButton(SAVE_BUTTON_LABEL); michael@0: michael@0: // Verify that the Master Password isn't deactivated when the password field is empty michael@0: closeTabletKeyboard(); michael@0: waitForText(OK_BUTTON_LABEL); michael@0: mSolo.clickOnButton(OK_BUTTON_LABEL); michael@0: michael@0: // Verify that the Master Password isn't deactivated when using the wrong password michael@0: closeTabletKeyboard(); michael@0: editPasswordField(0, badPassword); michael@0: waitForText(OK_BUTTON_LABEL); michael@0: mSolo.clickOnButton(OK_BUTTON_LABEL); michael@0: michael@0: // Verify that the Master Password is deactivated when using the right password michael@0: closeTabletKeyboard(); michael@0: editPasswordField(0, password); michael@0: waitForText(OK_BUTTON_LABEL); michael@0: mSolo.clickOnButton(OK_BUTTON_LABEL); michael@0: michael@0: // Verify that the Master Password is triggered once per session michael@0: noDoorhangerDisplayed(LOGIN_URL);// Check that the doorhanger isn't displayed michael@0: } else { michael@0: clearPrivateData(); michael@0: doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed michael@0: 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: mSolo.clickOnText("Don't save"); michael@0: doorhangerDisplayed(LOGIN_URL);// Check that the doorhanger is displayed again michael@0: 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: mSolo.clickOnText("Don't save"); michael@0: // Make sure the settings menu has been closed. michael@0: mAsserter.ok(mSolo.waitForText("Browser Blank Page 01"), "Waiting for blank browser page after exiting settings", "Blank browser page present"); michael@0: } michael@0: } michael@0: } michael@0: }