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