mobile/android/base/tests/testDoorHanger.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/base/tests/testDoorHanger.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,153 @@
     1.4 +package org.mozilla.gecko.tests;
     1.5 +
     1.6 +import org.json.JSONArray;
     1.7 +import org.json.JSONException;
     1.8 +import org.json.JSONObject;
     1.9 +import org.mozilla.gecko.Actions;
    1.10 +
    1.11 +/* This test will test if doorhangers are displayed and dismissed
    1.12 +   The test will test:
    1.13 +   * geolocation doorhangers - sharing and not sharing the location dismisses the doorhanger
    1.14 +   * opening a new tab hides the doorhanger
    1.15 +   * offline storage permission doorhangers - allowing and not allowing offline storage dismisses the doorhanger
    1.16 +   * Password Manager doorhangers - Remember and Not Now options dismiss the doorhanger
    1.17 +*/
    1.18 +public class testDoorHanger extends BaseTest {
    1.19 +    public void testDoorHanger() {
    1.20 +        String GEO_URL = getAbsoluteUrl("/robocop/robocop_geolocation.html");
    1.21 +        String BLANK_URL = getAbsoluteUrl("/robocop/robocop_blank_01.html");
    1.22 +        String OFFLINE_STORAGE_URL = getAbsoluteUrl("/robocop/robocop_offline_storage.html");
    1.23 +        String LOGIN_URL = getAbsoluteUrl("/robocop/robocop_login.html");
    1.24 +
    1.25 +        // Strings used in doorhanger messages and buttons
    1.26 +        String GEO_MESSAGE = "Share your location with";
    1.27 +        String GEO_ALLOW = "Share";
    1.28 +        String GEO_DENY = "Don't share";
    1.29 +
    1.30 +        String OFFLINE_MESSAGE = "to store data on your device for offline use";
    1.31 +        String OFFLINE_ALLOW = "Allow";
    1.32 +        String OFFLINE_DENY = "Don't allow";
    1.33 +
    1.34 +        String LOGIN_MESSAGE = "Save password";
    1.35 +        String LOGIN_ALLOW = "Save";
    1.36 +        String LOGIN_DENY = "Don't save";
    1.37 +
    1.38 +        blockForGeckoReady();
    1.39 +
    1.40 +        // Test geolocation notification
    1.41 +        inputAndLoadUrl(GEO_URL);
    1.42 +        waitForText(GEO_MESSAGE);
    1.43 +        mAsserter.is(mSolo.searchText(GEO_MESSAGE), true, "Geolocation doorhanger has been displayed");
    1.44 +
    1.45 +        // Test "Share" button hides the notification
    1.46 +        mSolo.clickOnCheckBox(0);
    1.47 +        mSolo.clickOnButton(GEO_ALLOW);
    1.48 +        mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger has been hidden when allowing share");
    1.49 +
    1.50 +        // Re-trigger geolocation notification
    1.51 +        inputAndLoadUrl(GEO_URL);
    1.52 +        waitForText(GEO_MESSAGE);
    1.53 +
    1.54 +        // Test "Don't share" button hides the notification
    1.55 +        mSolo.clickOnCheckBox(0);
    1.56 +        mSolo.clickOnButton(GEO_DENY);
    1.57 +        mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger has been hidden when denying share");
    1.58 +
    1.59 +        /* FIXME: disabled on fig - bug 880060 (for some reason this fails because of some raciness)
    1.60 +        // Re-trigger geolocation notification
    1.61 +        inputAndLoadUrl(GEO_URL);
    1.62 +        waitForText(GEO_MESSAGE);
    1.63 +
    1.64 +        // Add a new tab
    1.65 +        addTab(BLANK_URL);
    1.66 +
    1.67 +        // Make sure doorhanger is hidden
    1.68 +        mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger notification is hidden when opening a new tab");
    1.69 +        */
    1.70 +
    1.71 +
    1.72 +        boolean offlineAllowedByDefault = true;
    1.73 +        // Save offline-allow-by-default preferences first
    1.74 +        final String[] prefNames = { "offline-apps.allow_by_default" };
    1.75 +        final int ourRequestId = 0x7357;
    1.76 +        final Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
    1.77 +        mActions.sendPreferencesGetEvent(ourRequestId, prefNames);
    1.78 +        try {
    1.79 +            JSONObject data = null;
    1.80 +            int requestId = -1;
    1.81 +
    1.82 +            // Wait until we get the correct "Preferences:Data" event
    1.83 +            while (requestId != ourRequestId) {
    1.84 +                data = new JSONObject(eventExpecter.blockForEventData());
    1.85 +                requestId = data.getInt("requestId");
    1.86 +            }
    1.87 +            eventExpecter.unregisterListener();
    1.88 +
    1.89 +            JSONArray preferences = data.getJSONArray("preferences");
    1.90 +            if (preferences.length() > 0) {
    1.91 +                JSONObject pref = (JSONObject) preferences.get(0);
    1.92 +                offlineAllowedByDefault = pref.getBoolean("value");
    1.93 +            }
    1.94 +
    1.95 +            // Turn off offline-allow-by-default
    1.96 +            JSONObject jsonPref = new JSONObject();
    1.97 +            jsonPref.put("name", "offline-apps.allow_by_default");
    1.98 +            jsonPref.put("type", "bool");
    1.99 +            jsonPref.put("value", false);
   1.100 +            setPreferenceAndWaitForChange(jsonPref);
   1.101 +        } catch (JSONException e) {
   1.102 +            mAsserter.ok(false, "exception getting preference", e.toString());
   1.103 +        }
   1.104 +
   1.105 +        // Load offline storage page
   1.106 +        inputAndLoadUrl(OFFLINE_STORAGE_URL);
   1.107 +        waitForText(OFFLINE_MESSAGE);
   1.108 +
   1.109 +        // Test doorhanger dismissed when tapping "Don't share"
   1.110 +        mSolo.clickOnCheckBox(0);
   1.111 +        mSolo.clickOnButton(OFFLINE_DENY);
   1.112 +        mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger notification is hidden when denying storage");
   1.113 +
   1.114 +        // Load offline storage page
   1.115 +        inputAndLoadUrl(OFFLINE_STORAGE_URL);
   1.116 +        waitForText(OFFLINE_MESSAGE);
   1.117 +
   1.118 +        // Test doorhanger dismissed when tapping "Allow" and is not displayed again
   1.119 +        mSolo.clickOnButton(OFFLINE_ALLOW);
   1.120 +        mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger notification is hidden when allowing storage");
   1.121 +        inputAndLoadUrl(OFFLINE_STORAGE_URL);
   1.122 +        mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger is no longer triggered");
   1.123 +
   1.124 +        try {
   1.125 +            // Revert offline setting
   1.126 +            JSONObject jsonPref = new JSONObject();
   1.127 +            jsonPref.put("name", "offline-apps.allow_by_default");
   1.128 +            jsonPref.put("type", "bool");
   1.129 +            jsonPref.put("value", offlineAllowedByDefault);
   1.130 +            setPreferenceAndWaitForChange(jsonPref);
   1.131 +        } catch (JSONException e) {
   1.132 +            mAsserter.ok(false, "exception setting preference", e.toString());
   1.133 +        }
   1.134 +
   1.135 +
   1.136 +        // Load login page
   1.137 +        inputAndLoadUrl(LOGIN_URL);
   1.138 +        waitForText(LOGIN_MESSAGE);
   1.139 +
   1.140 +        // Test doorhanger is dismissed when tapping "Don't save"
   1.141 +        mSolo.clickOnButton(LOGIN_DENY);
   1.142 +        mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger notification is hidden when denying saving password");
   1.143 +
   1.144 +        // Load login page
   1.145 +        inputAndLoadUrl(LOGIN_URL);
   1.146 +        waitForText(LOGIN_MESSAGE);
   1.147 +
   1.148 +        // Test doorhanger is dismissed when tapping "Save" and is no longer triggered
   1.149 +        mSolo.clickOnButton(LOGIN_ALLOW);
   1.150 +        mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger notification is hidden when allowing saving password");
   1.151 +
   1.152 +        // Reload the page and check that there is no doorhanger displayed
   1.153 +        inputAndLoadUrl(LOGIN_URL);
   1.154 +        mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger is not re-triggered");
   1.155 +    }
   1.156 +}

mercurial