mobile/android/base/tests/testSettingsMenuItems.java

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 package org.mozilla.gecko.tests;
michael@0 2
michael@0 3 import java.util.ArrayList;
michael@0 4 import java.util.Arrays;
michael@0 5 import java.util.HashMap;
michael@0 6 import java.util.List;
michael@0 7 import java.util.Map;
michael@0 8 import java.util.Map.Entry;
michael@0 9
michael@0 10 import org.mozilla.gecko.Actions;
michael@0 11 import org.mozilla.gecko.AppConstants;
michael@0 12
michael@0 13 /** This patch tests the Sections present in the Settings Menu and the
michael@0 14 * default values for them
michael@0 15 */
michael@0 16 public class testSettingsMenuItems extends PixelTest {
michael@0 17 String BRAND_NAME = "(Fennec|Nightly|Aurora|Firefox|Firefox Beta)";
michael@0 18
michael@0 19 /**
michael@0 20 * The following String[][] (arrays) match the menu hierarchy for each section.
michael@0 21 * Each String[] (array) represents the menu items/choices in the following order:
michael@0 22 *
michael@0 23 * itemTitle { defaultValue [options] }
michael@0 24 *
michael@0 25 * where defaultValue is optional, and there can be multiple options.
michael@0 26 *
michael@0 27 * These menu items are the ones that are always present - to test menu items that differ
michael@0 28 * based on build (e.g., release vs. nightly), add the items in <code>addConditionalSettings</code>.
michael@0 29 */
michael@0 30
michael@0 31 // Customize menu items.
michael@0 32 String[] PATH_CUSTOMIZE = { "Customize" };
michael@0 33 String[][] OPTIONS_CUSTOMIZE = {
michael@0 34 { "Home" },
michael@0 35 { "Search", "", "Show search suggestions", "Installed search engines"},
michael@0 36 { "Tabs", "Don't restore after quitting " + BRAND_NAME, "Always restore", "Don't restore after quitting " + BRAND_NAME },
michael@0 37 { "Import from Android", "", "Bookmarks", "History", "Import" },
michael@0 38 };
michael@0 39
michael@0 40 // Home panel menu items.
michael@0 41 String[] PATH_HOME = { "Customize", "Home" };
michael@0 42 String[][] OPTIONS_HOME = {
michael@0 43 { "Panels" },
michael@0 44 { "Automatic updates", "Enabled", "Enabled", "Only over Wi-Fi" },
michael@0 45 };
michael@0 46
michael@0 47 // Display menu items.
michael@0 48 String[] PATH_DISPLAY = { "Display" };
michael@0 49 String[][] OPTIONS_DISPLAY = {
michael@0 50 { "Text size" },
michael@0 51 { "Title bar", "Show page title", "Show page title", "Show page address" },
michael@0 52 { "Advanced" },
michael@0 53 { "Character encoding", "Don't show menu", "Show menu", "Don't show menu" },
michael@0 54 { "Plugins", "Tap to play", "Enabled", "Tap to play", "Disabled" },
michael@0 55 };
michael@0 56
michael@0 57 // Privacy menu items.
michael@0 58 String[] PATH_PRIVACY = { "Privacy" };
michael@0 59 String[][] OPTIONS_PRIVACY = {
michael@0 60 { "Tracking", "Do not tell sites anything about my tracking preferences", "Tell sites that I do not want to be tracked", "Tell sites that I want to be tracked", "Do not tell sites anything about my tracking preferences" },
michael@0 61 { "Cookies", "Enabled", "Enabled, excluding 3rd party", "Disabled" },
michael@0 62 { "Remember passwords" },
michael@0 63 { "Use master password" },
michael@0 64 { "Clear private data", "", "Browsing history", "Downloads", "Form & search history", "Cookies & active logins", "Saved passwords", "Cache", "Offline website data", "Site settings", "Clear data" },
michael@0 65 };
michael@0 66
michael@0 67 // Mozilla/vendor menu items.
michael@0 68 String[] PATH_MOZILLA = { "Mozilla" };
michael@0 69 String[][] OPTIONS_MOZILLA = {
michael@0 70 { "About " + BRAND_NAME },
michael@0 71 { "FAQs" },
michael@0 72 { "Give feedback" },
michael@0 73 { "Show product announcements" },
michael@0 74 { "Data choices" },
michael@0 75 { BRAND_NAME + " Health Report", "Shares data with Mozilla about your browser health and helps you understand your browser performance" },
michael@0 76 { "View my Health Report" },
michael@0 77 };
michael@0 78
michael@0 79 /*
michael@0 80 * This sets up a hierarchy of settings to test.
michael@0 81 *
michael@0 82 * The keys are String arrays representing the path through menu items
michael@0 83 * (the single-item arrays being top-level categories), and each value
michael@0 84 * is a List of menu items contained within each category.
michael@0 85 *
michael@0 86 * Each menu item is itself an array as follows:
michael@0 87 * - item title
michael@0 88 * - default string value of item (optional)
michael@0 89 * - string values of options that are displayed once clicked (optional).
michael@0 90 */
michael@0 91 public void setupSettingsMap(Map<String[], List<String[]>> settingsMap) {
michael@0 92 settingsMap.put(PATH_CUSTOMIZE, new ArrayList<String[]>(Arrays.asList(OPTIONS_CUSTOMIZE)));
michael@0 93 settingsMap.put(PATH_HOME, new ArrayList<String[]>(Arrays.asList(OPTIONS_HOME)));
michael@0 94 settingsMap.put(PATH_DISPLAY, new ArrayList<String[]>(Arrays.asList(OPTIONS_DISPLAY)));
michael@0 95 settingsMap.put(PATH_PRIVACY, new ArrayList<String[]>(Arrays.asList(OPTIONS_PRIVACY)));
michael@0 96 settingsMap.put(PATH_MOZILLA, new ArrayList<String[]>(Arrays.asList(OPTIONS_MOZILLA)));
michael@0 97 }
michael@0 98
michael@0 99 public void testSettingsMenuItems() {
michael@0 100 blockForGeckoReady();
michael@0 101
michael@0 102 Map<String[], List<String[]>> settingsMenuItems = new HashMap<String[], List<String[]>>();
michael@0 103 setupSettingsMap(settingsMenuItems);
michael@0 104
michael@0 105 // Set special handling for Settings items that are conditionally built.
michael@0 106 addConditionalSettings(settingsMenuItems);
michael@0 107
michael@0 108 selectMenuItem("Settings");
michael@0 109 waitForText("Settings");
michael@0 110
michael@0 111 // Dismiss the Settings screen and verify that the view is returned to about:home page
michael@0 112 mActions.sendSpecialKey(Actions.SpecialKey.BACK);
michael@0 113
michael@0 114 // Waiting for page title to appear to be sure that is fully loaded before opening the menu
michael@0 115 waitForText("Enter Search");
michael@0 116 verifyUrl("about:home");
michael@0 117
michael@0 118 selectMenuItem("Settings");
michael@0 119 waitForText("Settings");
michael@0 120
michael@0 121 checkForSync(mDevice);
michael@0 122
michael@0 123 checkMenuHierarchy(settingsMenuItems);
michael@0 124 }
michael@0 125
michael@0 126 /**
michael@0 127 * Check for Sync in settings.
michael@0 128 *
michael@0 129 * Sync location is a top level menu item on phones, but is under "Customize" on tablets.
michael@0 130 *
michael@0 131 */
michael@0 132 public void checkForSync(Device device) {
michael@0 133 if (device.type.equals("tablet")) {
michael@0 134 // Select "Customize" from settings.
michael@0 135 String customizeString = "^Customize$";
michael@0 136 waitForEnabledText(customizeString);
michael@0 137 mSolo.clickOnText(customizeString);
michael@0 138 }
michael@0 139 mAsserter.ok(mSolo.waitForText("Sync"), "Waiting for Sync option", "The Sync option is present");
michael@0 140 }
michael@0 141
michael@0 142 /**
michael@0 143 * Check for conditions for building certain settings, and add them to be tested
michael@0 144 * if they are present.
michael@0 145 */
michael@0 146 public void addConditionalSettings(Map<String[], List<String[]>> settingsMap) {
michael@0 147 // Preferences dependent on RELEASE_BUILD
michael@0 148 if (!AppConstants.RELEASE_BUILD) {
michael@0 149 // Text reflow - only built if *not* release build
michael@0 150 String[] textReflowUi = { "Text reflow" };
michael@0 151 settingsMap.get(PATH_DISPLAY).add(textReflowUi);
michael@0 152
michael@0 153 // Anonymous cell tower/wifi collection - only built if *not* release build
michael@0 154 String[] networkReportingUi = { "Mozilla Location Service", "Receives Wi-Fi and cellular location data when running in the background and shares it with Mozilla to improve our geolocation service" };
michael@0 155 settingsMap.get(PATH_MOZILLA).add(networkReportingUi);
michael@0 156
michael@0 157 String[] learnMoreUi = { "Learn more" };
michael@0 158 settingsMap.get(PATH_MOZILLA).add(learnMoreUi);
michael@0 159 }
michael@0 160
michael@0 161 // Automatic updates
michael@0 162 if (AppConstants.MOZ_UPDATER) {
michael@0 163 String[] autoUpdateUi = { "Download updates automatically", "Only over Wi-Fi", "Always", "Only over Wi-Fi", "Never" };
michael@0 164 settingsMap.get(PATH_CUSTOMIZE).add(autoUpdateUi);
michael@0 165 }
michael@0 166
michael@0 167 // Crash reporter
michael@0 168 if (AppConstants.MOZ_CRASHREPORTER) {
michael@0 169 String[] crashReporterUi = { "Crash Reporter", BRAND_NAME + " submits crash reports to help Mozilla make your browser more stable and secure" };
michael@0 170 settingsMap.get(PATH_MOZILLA).add(crashReporterUi);
michael@0 171 }
michael@0 172
michael@0 173 // Telemetry
michael@0 174 if (AppConstants.MOZ_TELEMETRY_REPORTING) {
michael@0 175 String[] telemetryUi = { "Telemetry", "Shares performance, usage, hardware and customization data about your browser with Mozilla to help us make " + BRAND_NAME + " better" };
michael@0 176 settingsMap.get(PATH_MOZILLA).add(telemetryUi);
michael@0 177 }
michael@0 178 }
michael@0 179
michael@0 180 public void checkMenuHierarchy(Map<String[], List<String[]>> settingsMap) {
michael@0 181 // Check the items within each category.
michael@0 182 String section = null;
michael@0 183 for (Entry<String[], List<String[]>> e : settingsMap.entrySet()) {
michael@0 184 final String[] menuPath = e.getKey();
michael@0 185
michael@0 186 for (String menuItem : menuPath) {
michael@0 187 section = "^" + menuItem + "$";
michael@0 188
michael@0 189 waitForEnabledText(section);
michael@0 190 mSolo.clickOnText(section);
michael@0 191 }
michael@0 192
michael@0 193 List<String[]> sectionItems = e.getValue();
michael@0 194
michael@0 195 // Check each item of the section.
michael@0 196 for (String[] item : sectionItems) {
michael@0 197 int itemLen = item.length;
michael@0 198
michael@0 199 // Each item must at least have a title.
michael@0 200 mAsserter.ok(item.length > 0, "Section-item", "Each item must at least have a title");
michael@0 201
michael@0 202 // Check item title.
michael@0 203 String itemTitle = "^" + item[0] + "$";
michael@0 204 boolean foundText = waitForPreferencesText(itemTitle);
michael@0 205
michael@0 206 mAsserter.ok(foundText, "Waiting for settings item " + itemTitle + " in section " + section,
michael@0 207 "The " + itemTitle + " option is present in section " + section);
michael@0 208 // Check item default, if it exists.
michael@0 209 if (itemLen > 1) {
michael@0 210 String itemDefault = "^" + item[1] + "$";
michael@0 211 foundText = waitForPreferencesText(itemDefault);
michael@0 212 mAsserter.ok(foundText, "Waiting for settings item default " + itemDefault
michael@0 213 + " in section " + section,
michael@0 214 "The " + itemDefault + " default is present in section " + section);
michael@0 215 }
michael@0 216 // Check item choices, if they exist.
michael@0 217 if (itemLen > 2) {
michael@0 218 waitForEnabledText(itemTitle);
michael@0 219 mSolo.clickOnText(itemTitle);
michael@0 220 for (int i = 2; i < itemLen; i++) {
michael@0 221 String itemChoice = "^" + item[i] + "$";
michael@0 222 foundText = waitForPreferencesText(itemChoice);
michael@0 223 mAsserter.ok(foundText, "Waiting for settings item choice " + itemChoice
michael@0 224 + " in section " + section,
michael@0 225 "The " + itemChoice + " choice is present in section " + section);
michael@0 226 }
michael@0 227
michael@0 228 // Leave submenu after checking.
michael@0 229 if (waitForText("^Cancel$")) {
michael@0 230 mSolo.clickOnText("^Cancel$");
michael@0 231 } else {
michael@0 232 // Some submenus aren't dialogs, but are nested screens; exit using "back".
michael@0 233 mActions.sendSpecialKey(Actions.SpecialKey.BACK);
michael@0 234 }
michael@0 235 }
michael@0 236 }
michael@0 237
michael@0 238 // Navigate back if on a phone. Tablets shouldn't do this because they use headers and fragments.
michael@0 239 if (mDevice.type.equals("phone")) {
michael@0 240 int menuDepth = menuPath.length;
michael@0 241 while (menuDepth > 0) {
michael@0 242 mActions.sendSpecialKey(Actions.SpecialKey.BACK);
michael@0 243 menuDepth--;
michael@0 244 // Sleep so subsequent back actions aren't lost.
michael@0 245 mSolo.sleep(150);
michael@0 246 }
michael@0 247 }
michael@0 248 }
michael@0 249 }
michael@0 250 }

mercurial