michael@0: package org.mozilla.gecko.tests; michael@0: michael@0: import org.json.JSONArray; michael@0: import org.json.JSONException; michael@0: import org.json.JSONObject; michael@0: import org.mozilla.gecko.Actions; michael@0: michael@0: /* This test will test if doorhangers are displayed and dismissed michael@0: The test will test: michael@0: * geolocation doorhangers - sharing and not sharing the location dismisses the doorhanger michael@0: * opening a new tab hides the doorhanger michael@0: * offline storage permission doorhangers - allowing and not allowing offline storage dismisses the doorhanger michael@0: * Password Manager doorhangers - Remember and Not Now options dismiss the doorhanger michael@0: */ michael@0: public class testDoorHanger extends BaseTest { michael@0: public void testDoorHanger() { michael@0: String GEO_URL = getAbsoluteUrl("/robocop/robocop_geolocation.html"); michael@0: String BLANK_URL = getAbsoluteUrl("/robocop/robocop_blank_01.html"); michael@0: String OFFLINE_STORAGE_URL = getAbsoluteUrl("/robocop/robocop_offline_storage.html"); michael@0: String LOGIN_URL = getAbsoluteUrl("/robocop/robocop_login.html"); michael@0: michael@0: // Strings used in doorhanger messages and buttons michael@0: String GEO_MESSAGE = "Share your location with"; michael@0: String GEO_ALLOW = "Share"; michael@0: String GEO_DENY = "Don't share"; michael@0: michael@0: String OFFLINE_MESSAGE = "to store data on your device for offline use"; michael@0: String OFFLINE_ALLOW = "Allow"; michael@0: String OFFLINE_DENY = "Don't allow"; michael@0: michael@0: String LOGIN_MESSAGE = "Save password"; michael@0: String LOGIN_ALLOW = "Save"; michael@0: String LOGIN_DENY = "Don't save"; michael@0: michael@0: blockForGeckoReady(); michael@0: michael@0: // Test geolocation notification michael@0: inputAndLoadUrl(GEO_URL); michael@0: waitForText(GEO_MESSAGE); michael@0: mAsserter.is(mSolo.searchText(GEO_MESSAGE), true, "Geolocation doorhanger has been displayed"); michael@0: michael@0: // Test "Share" button hides the notification michael@0: mSolo.clickOnCheckBox(0); michael@0: mSolo.clickOnButton(GEO_ALLOW); michael@0: mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger has been hidden when allowing share"); michael@0: michael@0: // Re-trigger geolocation notification michael@0: inputAndLoadUrl(GEO_URL); michael@0: waitForText(GEO_MESSAGE); michael@0: michael@0: // Test "Don't share" button hides the notification michael@0: mSolo.clickOnCheckBox(0); michael@0: mSolo.clickOnButton(GEO_DENY); michael@0: mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger has been hidden when denying share"); michael@0: michael@0: /* FIXME: disabled on fig - bug 880060 (for some reason this fails because of some raciness) michael@0: // Re-trigger geolocation notification michael@0: inputAndLoadUrl(GEO_URL); michael@0: waitForText(GEO_MESSAGE); michael@0: michael@0: // Add a new tab michael@0: addTab(BLANK_URL); michael@0: michael@0: // Make sure doorhanger is hidden michael@0: mAsserter.is(mSolo.searchText(GEO_MESSAGE), false, "Geolocation doorhanger notification is hidden when opening a new tab"); michael@0: */ michael@0: michael@0: michael@0: boolean offlineAllowedByDefault = true; michael@0: // Save offline-allow-by-default preferences first michael@0: final String[] prefNames = { "offline-apps.allow_by_default" }; michael@0: final int ourRequestId = 0x7357; michael@0: final Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data"); michael@0: mActions.sendPreferencesGetEvent(ourRequestId, prefNames); michael@0: try { michael@0: JSONObject data = null; michael@0: int requestId = -1; michael@0: michael@0: // Wait until we get the correct "Preferences:Data" event michael@0: while (requestId != ourRequestId) { michael@0: data = new JSONObject(eventExpecter.blockForEventData()); michael@0: requestId = data.getInt("requestId"); michael@0: } michael@0: eventExpecter.unregisterListener(); michael@0: michael@0: JSONArray preferences = data.getJSONArray("preferences"); michael@0: if (preferences.length() > 0) { michael@0: JSONObject pref = (JSONObject) preferences.get(0); michael@0: offlineAllowedByDefault = pref.getBoolean("value"); michael@0: } michael@0: michael@0: // Turn off offline-allow-by-default michael@0: JSONObject jsonPref = new JSONObject(); michael@0: jsonPref.put("name", "offline-apps.allow_by_default"); michael@0: jsonPref.put("type", "bool"); michael@0: jsonPref.put("value", false); michael@0: setPreferenceAndWaitForChange(jsonPref); michael@0: } catch (JSONException e) { michael@0: mAsserter.ok(false, "exception getting preference", e.toString()); michael@0: } michael@0: michael@0: // Load offline storage page michael@0: inputAndLoadUrl(OFFLINE_STORAGE_URL); michael@0: waitForText(OFFLINE_MESSAGE); michael@0: michael@0: // Test doorhanger dismissed when tapping "Don't share" michael@0: mSolo.clickOnCheckBox(0); michael@0: mSolo.clickOnButton(OFFLINE_DENY); michael@0: mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger notification is hidden when denying storage"); michael@0: michael@0: // Load offline storage page michael@0: inputAndLoadUrl(OFFLINE_STORAGE_URL); michael@0: waitForText(OFFLINE_MESSAGE); michael@0: michael@0: // Test doorhanger dismissed when tapping "Allow" and is not displayed again michael@0: mSolo.clickOnButton(OFFLINE_ALLOW); michael@0: mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger notification is hidden when allowing storage"); michael@0: inputAndLoadUrl(OFFLINE_STORAGE_URL); michael@0: mAsserter.is(mSolo.searchText(OFFLINE_MESSAGE), false, "Offline storage doorhanger is no longer triggered"); michael@0: michael@0: try { michael@0: // Revert offline setting michael@0: JSONObject jsonPref = new JSONObject(); michael@0: jsonPref.put("name", "offline-apps.allow_by_default"); michael@0: jsonPref.put("type", "bool"); michael@0: jsonPref.put("value", offlineAllowedByDefault); michael@0: setPreferenceAndWaitForChange(jsonPref); michael@0: } catch (JSONException e) { michael@0: mAsserter.ok(false, "exception setting preference", e.toString()); michael@0: } michael@0: michael@0: michael@0: // Load login page michael@0: inputAndLoadUrl(LOGIN_URL); michael@0: waitForText(LOGIN_MESSAGE); michael@0: michael@0: // Test doorhanger is dismissed when tapping "Don't save" michael@0: mSolo.clickOnButton(LOGIN_DENY); michael@0: mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger notification is hidden when denying saving password"); michael@0: michael@0: // Load login page michael@0: inputAndLoadUrl(LOGIN_URL); michael@0: waitForText(LOGIN_MESSAGE); michael@0: michael@0: // Test doorhanger is dismissed when tapping "Save" and is no longer triggered michael@0: mSolo.clickOnButton(LOGIN_ALLOW); michael@0: mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger notification is hidden when allowing saving password"); michael@0: michael@0: // Reload the page and check that there is no doorhanger displayed michael@0: inputAndLoadUrl(LOGIN_URL); michael@0: mAsserter.is(mSolo.searchText(LOGIN_MESSAGE), false, "Login doorhanger is not re-triggered"); michael@0: } michael@0: }