mobile/android/base/tests/testSettingsMenuItems.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testSettingsMenuItems.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,250 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import java.util.ArrayList;
     1.7 +import java.util.Arrays;
     1.8 +import java.util.HashMap;
     1.9 +import java.util.List;
    1.10 +import java.util.Map;
    1.11 +import java.util.Map.Entry;
    1.12 +
    1.13 +import org.mozilla.gecko.Actions;
    1.14 +import org.mozilla.gecko.AppConstants;
    1.15 +
    1.16 +/** This patch tests the Sections present in the Settings Menu and the
    1.17 + *  default values for them
    1.18 + */
    1.19 +public class testSettingsMenuItems extends PixelTest {
    1.20 +    String BRAND_NAME = "(Fennec|Nightly|Aurora|Firefox|Firefox Beta)";
    1.21 +
    1.22 +    /**
    1.23 +     * The following String[][] (arrays) match the menu hierarchy for each section.
    1.24 +     * Each String[] (array) represents the menu items/choices in the following order:
    1.25 +     *
    1.26 +     * itemTitle { defaultValue [options] }
    1.27 +     *
    1.28 +     * where defaultValue is optional, and there can be multiple options.
    1.29 +     *
    1.30 +     * These menu items are the ones that are always present - to test menu items that differ
    1.31 +     * based on build (e.g., release vs. nightly), add the items in <code>addConditionalSettings</code>.
    1.32 +     */
    1.33 +
    1.34 +    // Customize menu items.
    1.35 +    String[] PATH_CUSTOMIZE = { "Customize" };
    1.36 +    String[][] OPTIONS_CUSTOMIZE = {
    1.37 +        { "Home" },
    1.38 +        { "Search", "", "Show search suggestions", "Installed search engines"},
    1.39 +        { "Tabs", "Don't restore after quitting " + BRAND_NAME, "Always restore", "Don't restore after quitting " + BRAND_NAME },
    1.40 +        { "Import from Android", "", "Bookmarks", "History", "Import" },
    1.41 +    };
    1.42 +
    1.43 +    // Home panel menu items.
    1.44 +    String[] PATH_HOME = { "Customize", "Home" };
    1.45 +    String[][] OPTIONS_HOME = {
    1.46 +      { "Panels" },
    1.47 +      { "Automatic updates", "Enabled", "Enabled", "Only over Wi-Fi" },
    1.48 +    };
    1.49 +
    1.50 +    // Display menu items.
    1.51 +    String[] PATH_DISPLAY = { "Display" };
    1.52 +    String[][] OPTIONS_DISPLAY = {
    1.53 +        { "Text size" },
    1.54 +        { "Title bar", "Show page title", "Show page title", "Show page address" },
    1.55 +        { "Advanced" },
    1.56 +        { "Character encoding", "Don't show menu", "Show menu", "Don't show menu" },
    1.57 +        { "Plugins", "Tap to play", "Enabled", "Tap to play", "Disabled" },
    1.58 +    };
    1.59 +
    1.60 +    // Privacy menu items.
    1.61 +    String[] PATH_PRIVACY = { "Privacy" };
    1.62 +    String[][] OPTIONS_PRIVACY = {
    1.63 +        { "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" },
    1.64 +        { "Cookies", "Enabled", "Enabled, excluding 3rd party", "Disabled" },
    1.65 +        { "Remember passwords" },
    1.66 +        { "Use master password" },
    1.67 +        { "Clear private data", "", "Browsing history", "Downloads", "Form & search history", "Cookies & active logins", "Saved passwords", "Cache", "Offline website data", "Site settings", "Clear data" },
    1.68 +    };
    1.69 +
    1.70 +    // Mozilla/vendor menu items.
    1.71 +    String[] PATH_MOZILLA = { "Mozilla" };
    1.72 +    String[][] OPTIONS_MOZILLA = {
    1.73 +        { "About " + BRAND_NAME },
    1.74 +        { "FAQs" },
    1.75 +        { "Give feedback" },
    1.76 +        { "Show product announcements" },
    1.77 +        { "Data choices" },
    1.78 +        { BRAND_NAME + " Health Report", "Shares data with Mozilla about your browser health and helps you understand your browser performance" },
    1.79 +        { "View my Health Report" },
    1.80 +    };
    1.81 +
    1.82 +    /*
    1.83 +     * This sets up a hierarchy of settings to test.
    1.84 +     *
    1.85 +     * The keys are String arrays representing the path through menu items
    1.86 +     * (the single-item arrays being top-level categories), and each value
    1.87 +     * is a List of menu items contained within each category.
    1.88 +     *
    1.89 +     * Each menu item is itself an array as follows:
    1.90 +     *  - item title
    1.91 +     *  - default string value of item (optional)
    1.92 +     *  - string values of options that are displayed once clicked (optional).
    1.93 +     */
    1.94 +    public void setupSettingsMap(Map<String[], List<String[]>> settingsMap) {
    1.95 +        settingsMap.put(PATH_CUSTOMIZE, new ArrayList<String[]>(Arrays.asList(OPTIONS_CUSTOMIZE)));
    1.96 +        settingsMap.put(PATH_HOME, new ArrayList<String[]>(Arrays.asList(OPTIONS_HOME)));
    1.97 +        settingsMap.put(PATH_DISPLAY, new ArrayList<String[]>(Arrays.asList(OPTIONS_DISPLAY)));
    1.98 +        settingsMap.put(PATH_PRIVACY, new ArrayList<String[]>(Arrays.asList(OPTIONS_PRIVACY)));
    1.99 +        settingsMap.put(PATH_MOZILLA, new ArrayList<String[]>(Arrays.asList(OPTIONS_MOZILLA)));
   1.100 +    }
   1.101 +
   1.102 +    public void testSettingsMenuItems() {
   1.103 +        blockForGeckoReady();
   1.104 +
   1.105 +        Map<String[], List<String[]>> settingsMenuItems = new HashMap<String[], List<String[]>>();
   1.106 +        setupSettingsMap(settingsMenuItems);
   1.107 +
   1.108 +        // Set special handling for Settings items that are conditionally built.
   1.109 +        addConditionalSettings(settingsMenuItems);
   1.110 +
   1.111 +        selectMenuItem("Settings");
   1.112 +        waitForText("Settings");
   1.113 +
   1.114 +        // Dismiss the Settings screen and verify that the view is returned to about:home page
   1.115 +        mActions.sendSpecialKey(Actions.SpecialKey.BACK);
   1.116 +
   1.117 +        // Waiting for page title to appear to be sure that is fully loaded before opening the menu
   1.118 +        waitForText("Enter Search");
   1.119 +        verifyUrl("about:home");
   1.120 +
   1.121 +        selectMenuItem("Settings");
   1.122 +        waitForText("Settings");
   1.123 +
   1.124 +        checkForSync(mDevice);
   1.125 +
   1.126 +        checkMenuHierarchy(settingsMenuItems);
   1.127 +    }
   1.128 +
   1.129 +    /**
   1.130 +     * Check for Sync in settings.
   1.131 +     *
   1.132 +     * Sync location is a top level menu item on phones, but is under "Customize" on tablets.
   1.133 +     *
   1.134 +     */
   1.135 +    public void checkForSync(Device device) {
   1.136 +        if (device.type.equals("tablet")) {
   1.137 +            // Select "Customize" from settings.
   1.138 +            String customizeString = "^Customize$";
   1.139 +            waitForEnabledText(customizeString);
   1.140 +            mSolo.clickOnText(customizeString);
   1.141 +        }
   1.142 +        mAsserter.ok(mSolo.waitForText("Sync"), "Waiting for Sync option", "The Sync option is present");
   1.143 +    }
   1.144 +
   1.145 +    /**
   1.146 +     * Check for conditions for building certain settings, and add them to be tested
   1.147 +     * if they are present.
   1.148 +     */
   1.149 +    public void addConditionalSettings(Map<String[], List<String[]>> settingsMap) {
   1.150 +        // Preferences dependent on RELEASE_BUILD
   1.151 +        if (!AppConstants.RELEASE_BUILD) {
   1.152 +            // Text reflow - only built if *not* release build
   1.153 +            String[] textReflowUi = { "Text reflow" };
   1.154 +            settingsMap.get(PATH_DISPLAY).add(textReflowUi);
   1.155 +
   1.156 +            // Anonymous cell tower/wifi collection - only built if *not* release build
   1.157 +            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" };
   1.158 +            settingsMap.get(PATH_MOZILLA).add(networkReportingUi);
   1.159 +
   1.160 +            String[] learnMoreUi = { "Learn more" };
   1.161 +            settingsMap.get(PATH_MOZILLA).add(learnMoreUi);
   1.162 +        }
   1.163 +
   1.164 +        // Automatic updates
   1.165 +        if (AppConstants.MOZ_UPDATER) {
   1.166 +            String[] autoUpdateUi = { "Download updates automatically", "Only over Wi-Fi", "Always", "Only over Wi-Fi", "Never" };
   1.167 +            settingsMap.get(PATH_CUSTOMIZE).add(autoUpdateUi);
   1.168 +        }
   1.169 +
   1.170 +        // Crash reporter
   1.171 +        if (AppConstants.MOZ_CRASHREPORTER) {
   1.172 +            String[] crashReporterUi = { "Crash Reporter", BRAND_NAME + " submits crash reports to help Mozilla make your browser more stable and secure" };
   1.173 +            settingsMap.get(PATH_MOZILLA).add(crashReporterUi);
   1.174 +        }
   1.175 +
   1.176 +        // Telemetry
   1.177 +        if (AppConstants.MOZ_TELEMETRY_REPORTING) {
   1.178 +            String[] telemetryUi = { "Telemetry", "Shares performance, usage, hardware and customization data about your browser with Mozilla to help us make " + BRAND_NAME + " better" };
   1.179 +            settingsMap.get(PATH_MOZILLA).add(telemetryUi);
   1.180 +        }
   1.181 +    }
   1.182 +
   1.183 +    public void checkMenuHierarchy(Map<String[], List<String[]>> settingsMap) {
   1.184 +        // Check the items within each category.
   1.185 +        String section = null;
   1.186 +        for (Entry<String[], List<String[]>> e : settingsMap.entrySet()) {
   1.187 +            final String[] menuPath = e.getKey();
   1.188 +
   1.189 +            for (String menuItem : menuPath) {
   1.190 +                section = "^" + menuItem + "$";
   1.191 +
   1.192 +                waitForEnabledText(section);
   1.193 +                mSolo.clickOnText(section);
   1.194 +            }
   1.195 +
   1.196 +            List<String[]> sectionItems = e.getValue();
   1.197 +
   1.198 +            // Check each item of the section.
   1.199 +            for (String[] item : sectionItems) {
   1.200 +                int itemLen = item.length;
   1.201 +
   1.202 +                // Each item must at least have a title.
   1.203 +                mAsserter.ok(item.length > 0, "Section-item", "Each item must at least have a title");
   1.204 +
   1.205 +                // Check item title.
   1.206 +                String itemTitle = "^" + item[0] + "$";
   1.207 +                boolean foundText = waitForPreferencesText(itemTitle);
   1.208 +
   1.209 +                mAsserter.ok(foundText, "Waiting for settings item " + itemTitle + " in section " + section,
   1.210 +                             "The " + itemTitle + " option is present in section " + section);
   1.211 +                // Check item default, if it exists.
   1.212 +                if (itemLen > 1) {
   1.213 +                    String itemDefault = "^" + item[1] + "$";
   1.214 +                    foundText = waitForPreferencesText(itemDefault);
   1.215 +                    mAsserter.ok(foundText, "Waiting for settings item default " + itemDefault
   1.216 +                                 + " in section " + section,
   1.217 +                                 "The " + itemDefault + " default is present in section " + section);
   1.218 +                }
   1.219 +                // Check item choices, if they exist.
   1.220 +                if (itemLen > 2) {
   1.221 +                    waitForEnabledText(itemTitle);
   1.222 +                    mSolo.clickOnText(itemTitle);
   1.223 +                    for (int i = 2; i < itemLen; i++) {
   1.224 +                        String itemChoice = "^" + item[i] + "$";
   1.225 +                        foundText = waitForPreferencesText(itemChoice);
   1.226 +                        mAsserter.ok(foundText, "Waiting for settings item choice " + itemChoice
   1.227 +                                     + " in section " + section,
   1.228 +                                     "The " + itemChoice + " choice is present in section " + section);
   1.229 +                    }
   1.230 +
   1.231 +                    // Leave submenu after checking.
   1.232 +                    if (waitForText("^Cancel$")) {
   1.233 +                        mSolo.clickOnText("^Cancel$");
   1.234 +                    } else {
   1.235 +                        // Some submenus aren't dialogs, but are nested screens; exit using "back".
   1.236 +                        mActions.sendSpecialKey(Actions.SpecialKey.BACK);
   1.237 +                    }
   1.238 +                }
   1.239 +            }
   1.240 +
   1.241 +            // Navigate back if on a phone. Tablets shouldn't do this because they use headers and fragments.
   1.242 +            if (mDevice.type.equals("phone")) {
   1.243 +                int menuDepth = menuPath.length;
   1.244 +                while (menuDepth > 0) {
   1.245 +                    mActions.sendSpecialKey(Actions.SpecialKey.BACK);
   1.246 +                    menuDepth--;
   1.247 +                    // Sleep so subsequent back actions aren't lost.
   1.248 +                    mSolo.sleep(150);
   1.249 +                }
   1.250 +            }
   1.251 +        }
   1.252 +    }
   1.253 +}

mercurial