michael@0: package org.mozilla.gecko.tests;
michael@0:
michael@0: import java.util.ArrayList;
michael@0: import java.util.Arrays;
michael@0: import java.util.HashMap;
michael@0: import java.util.List;
michael@0: import java.util.Map;
michael@0: import java.util.Map.Entry;
michael@0:
michael@0: import org.mozilla.gecko.Actions;
michael@0: import org.mozilla.gecko.AppConstants;
michael@0:
michael@0: /** This patch tests the Sections present in the Settings Menu and the
michael@0: * default values for them
michael@0: */
michael@0: public class testSettingsMenuItems extends PixelTest {
michael@0: String BRAND_NAME = "(Fennec|Nightly|Aurora|Firefox|Firefox Beta)";
michael@0:
michael@0: /**
michael@0: * The following String[][] (arrays) match the menu hierarchy for each section.
michael@0: * Each String[] (array) represents the menu items/choices in the following order:
michael@0: *
michael@0: * itemTitle { defaultValue [options] }
michael@0: *
michael@0: * where defaultValue is optional, and there can be multiple options.
michael@0: *
michael@0: * These menu items are the ones that are always present - to test menu items that differ
michael@0: * based on build (e.g., release vs. nightly), add the items in addConditionalSettings
.
michael@0: */
michael@0:
michael@0: // Customize menu items.
michael@0: String[] PATH_CUSTOMIZE = { "Customize" };
michael@0: String[][] OPTIONS_CUSTOMIZE = {
michael@0: { "Home" },
michael@0: { "Search", "", "Show search suggestions", "Installed search engines"},
michael@0: { "Tabs", "Don't restore after quitting " + BRAND_NAME, "Always restore", "Don't restore after quitting " + BRAND_NAME },
michael@0: { "Import from Android", "", "Bookmarks", "History", "Import" },
michael@0: };
michael@0:
michael@0: // Home panel menu items.
michael@0: String[] PATH_HOME = { "Customize", "Home" };
michael@0: String[][] OPTIONS_HOME = {
michael@0: { "Panels" },
michael@0: { "Automatic updates", "Enabled", "Enabled", "Only over Wi-Fi" },
michael@0: };
michael@0:
michael@0: // Display menu items.
michael@0: String[] PATH_DISPLAY = { "Display" };
michael@0: String[][] OPTIONS_DISPLAY = {
michael@0: { "Text size" },
michael@0: { "Title bar", "Show page title", "Show page title", "Show page address" },
michael@0: { "Advanced" },
michael@0: { "Character encoding", "Don't show menu", "Show menu", "Don't show menu" },
michael@0: { "Plugins", "Tap to play", "Enabled", "Tap to play", "Disabled" },
michael@0: };
michael@0:
michael@0: // Privacy menu items.
michael@0: String[] PATH_PRIVACY = { "Privacy" };
michael@0: String[][] OPTIONS_PRIVACY = {
michael@0: { "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: { "Cookies", "Enabled", "Enabled, excluding 3rd party", "Disabled" },
michael@0: { "Remember passwords" },
michael@0: { "Use master password" },
michael@0: { "Clear private data", "", "Browsing history", "Downloads", "Form & search history", "Cookies & active logins", "Saved passwords", "Cache", "Offline website data", "Site settings", "Clear data" },
michael@0: };
michael@0:
michael@0: // Mozilla/vendor menu items.
michael@0: String[] PATH_MOZILLA = { "Mozilla" };
michael@0: String[][] OPTIONS_MOZILLA = {
michael@0: { "About " + BRAND_NAME },
michael@0: { "FAQs" },
michael@0: { "Give feedback" },
michael@0: { "Show product announcements" },
michael@0: { "Data choices" },
michael@0: { BRAND_NAME + " Health Report", "Shares data with Mozilla about your browser health and helps you understand your browser performance" },
michael@0: { "View my Health Report" },
michael@0: };
michael@0:
michael@0: /*
michael@0: * This sets up a hierarchy of settings to test.
michael@0: *
michael@0: * The keys are String arrays representing the path through menu items
michael@0: * (the single-item arrays being top-level categories), and each value
michael@0: * is a List of menu items contained within each category.
michael@0: *
michael@0: * Each menu item is itself an array as follows:
michael@0: * - item title
michael@0: * - default string value of item (optional)
michael@0: * - string values of options that are displayed once clicked (optional).
michael@0: */
michael@0: public void setupSettingsMap(Map> settingsMap) {
michael@0: settingsMap.put(PATH_CUSTOMIZE, new ArrayList(Arrays.asList(OPTIONS_CUSTOMIZE)));
michael@0: settingsMap.put(PATH_HOME, new ArrayList(Arrays.asList(OPTIONS_HOME)));
michael@0: settingsMap.put(PATH_DISPLAY, new ArrayList(Arrays.asList(OPTIONS_DISPLAY)));
michael@0: settingsMap.put(PATH_PRIVACY, new ArrayList(Arrays.asList(OPTIONS_PRIVACY)));
michael@0: settingsMap.put(PATH_MOZILLA, new ArrayList(Arrays.asList(OPTIONS_MOZILLA)));
michael@0: }
michael@0:
michael@0: public void testSettingsMenuItems() {
michael@0: blockForGeckoReady();
michael@0:
michael@0: Map> settingsMenuItems = new HashMap>();
michael@0: setupSettingsMap(settingsMenuItems);
michael@0:
michael@0: // Set special handling for Settings items that are conditionally built.
michael@0: addConditionalSettings(settingsMenuItems);
michael@0:
michael@0: selectMenuItem("Settings");
michael@0: waitForText("Settings");
michael@0:
michael@0: // Dismiss the Settings screen and verify that the view is returned to about:home page
michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK);
michael@0:
michael@0: // Waiting for page title to appear to be sure that is fully loaded before opening the menu
michael@0: waitForText("Enter Search");
michael@0: verifyUrl("about:home");
michael@0:
michael@0: selectMenuItem("Settings");
michael@0: waitForText("Settings");
michael@0:
michael@0: checkForSync(mDevice);
michael@0:
michael@0: checkMenuHierarchy(settingsMenuItems);
michael@0: }
michael@0:
michael@0: /**
michael@0: * Check for Sync in settings.
michael@0: *
michael@0: * Sync location is a top level menu item on phones, but is under "Customize" on tablets.
michael@0: *
michael@0: */
michael@0: public void checkForSync(Device device) {
michael@0: if (device.type.equals("tablet")) {
michael@0: // Select "Customize" from settings.
michael@0: String customizeString = "^Customize$";
michael@0: waitForEnabledText(customizeString);
michael@0: mSolo.clickOnText(customizeString);
michael@0: }
michael@0: mAsserter.ok(mSolo.waitForText("Sync"), "Waiting for Sync option", "The Sync option is present");
michael@0: }
michael@0:
michael@0: /**
michael@0: * Check for conditions for building certain settings, and add them to be tested
michael@0: * if they are present.
michael@0: */
michael@0: public void addConditionalSettings(Map> settingsMap) {
michael@0: // Preferences dependent on RELEASE_BUILD
michael@0: if (!AppConstants.RELEASE_BUILD) {
michael@0: // Text reflow - only built if *not* release build
michael@0: String[] textReflowUi = { "Text reflow" };
michael@0: settingsMap.get(PATH_DISPLAY).add(textReflowUi);
michael@0:
michael@0: // Anonymous cell tower/wifi collection - only built if *not* release build
michael@0: 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: settingsMap.get(PATH_MOZILLA).add(networkReportingUi);
michael@0:
michael@0: String[] learnMoreUi = { "Learn more" };
michael@0: settingsMap.get(PATH_MOZILLA).add(learnMoreUi);
michael@0: }
michael@0:
michael@0: // Automatic updates
michael@0: if (AppConstants.MOZ_UPDATER) {
michael@0: String[] autoUpdateUi = { "Download updates automatically", "Only over Wi-Fi", "Always", "Only over Wi-Fi", "Never" };
michael@0: settingsMap.get(PATH_CUSTOMIZE).add(autoUpdateUi);
michael@0: }
michael@0:
michael@0: // Crash reporter
michael@0: if (AppConstants.MOZ_CRASHREPORTER) {
michael@0: String[] crashReporterUi = { "Crash Reporter", BRAND_NAME + " submits crash reports to help Mozilla make your browser more stable and secure" };
michael@0: settingsMap.get(PATH_MOZILLA).add(crashReporterUi);
michael@0: }
michael@0:
michael@0: // Telemetry
michael@0: if (AppConstants.MOZ_TELEMETRY_REPORTING) {
michael@0: String[] telemetryUi = { "Telemetry", "Shares performance, usage, hardware and customization data about your browser with Mozilla to help us make " + BRAND_NAME + " better" };
michael@0: settingsMap.get(PATH_MOZILLA).add(telemetryUi);
michael@0: }
michael@0: }
michael@0:
michael@0: public void checkMenuHierarchy(Map> settingsMap) {
michael@0: // Check the items within each category.
michael@0: String section = null;
michael@0: for (Entry> e : settingsMap.entrySet()) {
michael@0: final String[] menuPath = e.getKey();
michael@0:
michael@0: for (String menuItem : menuPath) {
michael@0: section = "^" + menuItem + "$";
michael@0:
michael@0: waitForEnabledText(section);
michael@0: mSolo.clickOnText(section);
michael@0: }
michael@0:
michael@0: List sectionItems = e.getValue();
michael@0:
michael@0: // Check each item of the section.
michael@0: for (String[] item : sectionItems) {
michael@0: int itemLen = item.length;
michael@0:
michael@0: // Each item must at least have a title.
michael@0: mAsserter.ok(item.length > 0, "Section-item", "Each item must at least have a title");
michael@0:
michael@0: // Check item title.
michael@0: String itemTitle = "^" + item[0] + "$";
michael@0: boolean foundText = waitForPreferencesText(itemTitle);
michael@0:
michael@0: mAsserter.ok(foundText, "Waiting for settings item " + itemTitle + " in section " + section,
michael@0: "The " + itemTitle + " option is present in section " + section);
michael@0: // Check item default, if it exists.
michael@0: if (itemLen > 1) {
michael@0: String itemDefault = "^" + item[1] + "$";
michael@0: foundText = waitForPreferencesText(itemDefault);
michael@0: mAsserter.ok(foundText, "Waiting for settings item default " + itemDefault
michael@0: + " in section " + section,
michael@0: "The " + itemDefault + " default is present in section " + section);
michael@0: }
michael@0: // Check item choices, if they exist.
michael@0: if (itemLen > 2) {
michael@0: waitForEnabledText(itemTitle);
michael@0: mSolo.clickOnText(itemTitle);
michael@0: for (int i = 2; i < itemLen; i++) {
michael@0: String itemChoice = "^" + item[i] + "$";
michael@0: foundText = waitForPreferencesText(itemChoice);
michael@0: mAsserter.ok(foundText, "Waiting for settings item choice " + itemChoice
michael@0: + " in section " + section,
michael@0: "The " + itemChoice + " choice is present in section " + section);
michael@0: }
michael@0:
michael@0: // Leave submenu after checking.
michael@0: if (waitForText("^Cancel$")) {
michael@0: mSolo.clickOnText("^Cancel$");
michael@0: } else {
michael@0: // Some submenus aren't dialogs, but are nested screens; exit using "back".
michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK);
michael@0: }
michael@0: }
michael@0: }
michael@0:
michael@0: // Navigate back if on a phone. Tablets shouldn't do this because they use headers and fragments.
michael@0: if (mDevice.type.equals("phone")) {
michael@0: int menuDepth = menuPath.length;
michael@0: while (menuDepth > 0) {
michael@0: mActions.sendSpecialKey(Actions.SpecialKey.BACK);
michael@0: menuDepth--;
michael@0: // Sleep so subsequent back actions aren't lost.
michael@0: mSolo.sleep(150);
michael@0: }
michael@0: }
michael@0: }
michael@0: }
michael@0: }