mobile/android/base/tests/testDoorHanger.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.

     1 package org.mozilla.gecko.tests;
     3 import org.json.JSONArray;
     4 import org.json.JSONException;
     5 import org.json.JSONObject;
     6 import org.mozilla.gecko.Actions;
     8 /* This test will test if doorhangers are displayed and dismissed
     9    The test will test:
    10    * geolocation doorhangers - sharing and not sharing the location dismisses the doorhanger
    11    * opening a new tab hides the doorhanger
    12    * offline storage permission doorhangers - allowing and not allowing offline storage dismisses the doorhanger
    13    * Password Manager doorhangers - Remember and Not Now options dismiss the doorhanger
    14 */
    15 public class testDoorHanger extends BaseTest {
    16     public void testDoorHanger() {
    17         String GEO_URL = getAbsoluteUrl("/robocop/robocop_geolocation.html");
    18         String BLANK_URL = getAbsoluteUrl("/robocop/robocop_blank_01.html");
    19         String OFFLINE_STORAGE_URL = getAbsoluteUrl("/robocop/robocop_offline_storage.html");
    20         String LOGIN_URL = getAbsoluteUrl("/robocop/robocop_login.html");
    22         // Strings used in doorhanger messages and buttons
    23         String GEO_MESSAGE = "Share your location with";
    24         String GEO_ALLOW = "Share";
    25         String GEO_DENY = "Don't share";
    27         String OFFLINE_MESSAGE = "to store data on your device for offline use";
    28         String OFFLINE_ALLOW = "Allow";
    29         String OFFLINE_DENY = "Don't allow";
    31         String LOGIN_MESSAGE = "Save password";
    32         String LOGIN_ALLOW = "Save";
    33         String LOGIN_DENY = "Don't save";
    35         blockForGeckoReady();
    37         // Test geolocation notification
    38         inputAndLoadUrl(GEO_URL);
    39         waitForText(GEO_MESSAGE);
    40         mAsserter.is(mSolo.searchText(GEO_MESSAGE), true, "Geolocation doorhanger has been displayed");
    42         // Test "Share" button hides the notification
    43         mSolo.clickOnCheckBox(0);
    44         mSolo.clickOnButton(GEO_ALLOW);
    45         mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger has been hidden when allowing share");
    47         // Re-trigger geolocation notification
    48         inputAndLoadUrl(GEO_URL);
    49         waitForText(GEO_MESSAGE);
    51         // Test "Don't share" button hides the notification
    52         mSolo.clickOnCheckBox(0);
    53         mSolo.clickOnButton(GEO_DENY);
    54         mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger has been hidden when denying share");
    56         /* FIXME: disabled on fig - bug 880060 (for some reason this fails because of some raciness)
    57         // Re-trigger geolocation notification
    58         inputAndLoadUrl(GEO_URL);
    59         waitForText(GEO_MESSAGE);
    61         // Add a new tab
    62         addTab(BLANK_URL);
    64         // Make sure doorhanger is hidden
    65         mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger notification is hidden when opening a new tab");
    66         */
    69         boolean offlineAllowedByDefault = true;
    70         // Save offline-allow-by-default preferences first
    71         final String[] prefNames = { "offline-apps.allow_by_default" };
    72         final int ourRequestId = 0x7357;
    73         final Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
    74         mActions.sendPreferencesGetEvent(ourRequestId, prefNames);
    75         try {
    76             JSONObject data = null;
    77             int requestId = -1;
    79             // Wait until we get the correct "Preferences:Data" event
    80             while (requestId != ourRequestId) {
    81                 data = new JSONObject(eventExpecter.blockForEventData());
    82                 requestId = data.getInt("requestId");
    83             }
    84             eventExpecter.unregisterListener();
    86             JSONArray preferences = data.getJSONArray("preferences");
    87             if (preferences.length() > 0) {
    88                 JSONObject pref = (JSONObject) preferences.get(0);
    89                 offlineAllowedByDefault = pref.getBoolean("value");
    90             }
    92             // Turn off offline-allow-by-default
    93             JSONObject jsonPref = new JSONObject();
    94             jsonPref.put("name", "offline-apps.allow_by_default");
    95             jsonPref.put("type", "bool");
    96             jsonPref.put("value", false);
    97             setPreferenceAndWaitForChange(jsonPref);
    98         } catch (JSONException e) {
    99             mAsserter.ok(false, "exception getting preference", e.toString());
   100         }
   102         // Load offline storage page
   103         inputAndLoadUrl(OFFLINE_STORAGE_URL);
   104         waitForText(OFFLINE_MESSAGE);
   106         // Test doorhanger dismissed when tapping "Don't share"
   107         mSolo.clickOnCheckBox(0);
   108         mSolo.clickOnButton(OFFLINE_DENY);
   109         mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger notification is hidden when denying storage");
   111         // Load offline storage page
   112         inputAndLoadUrl(OFFLINE_STORAGE_URL);
   113         waitForText(OFFLINE_MESSAGE);
   115         // Test doorhanger dismissed when tapping "Allow" and is not displayed again
   116         mSolo.clickOnButton(OFFLINE_ALLOW);
   117         mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger notification is hidden when allowing storage");
   118         inputAndLoadUrl(OFFLINE_STORAGE_URL);
   119         mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger is no longer triggered");
   121         try {
   122             // Revert offline setting
   123             JSONObject jsonPref = new JSONObject();
   124             jsonPref.put("name", "offline-apps.allow_by_default");
   125             jsonPref.put("type", "bool");
   126             jsonPref.put("value", offlineAllowedByDefault);
   127             setPreferenceAndWaitForChange(jsonPref);
   128         } catch (JSONException e) {
   129             mAsserter.ok(false, "exception setting preference", e.toString());
   130         }
   133         // Load login page
   134         inputAndLoadUrl(LOGIN_URL);
   135         waitForText(LOGIN_MESSAGE);
   137         // Test doorhanger is dismissed when tapping "Don't save"
   138         mSolo.clickOnButton(LOGIN_DENY);
   139         mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger notification is hidden when denying saving password");
   141         // Load login page
   142         inputAndLoadUrl(LOGIN_URL);
   143         waitForText(LOGIN_MESSAGE);
   145         // Test doorhanger is dismissed when tapping "Save" and is no longer triggered
   146         mSolo.clickOnButton(LOGIN_ALLOW);
   147         mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger notification is hidden when allowing saving password");
   149         // Reload the page and check that there is no doorhanger displayed
   150         inputAndLoadUrl(LOGIN_URL);
   151         mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger is not re-triggered");
   152     }
   153 }

mercurial