mobile/android/base/tests/testMasterPassword.java

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

mercurial