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.

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

mercurial