--- a/mobile/android/base/tests/BaseTest.java
+++ b/mobile/android/base/tests/BaseTest.java
@@ -580,16 +580,38 @@ abstract class BaseTest extends BaseRobo
// We set the left compound drawable (index 0) to the pin icon.
final TextView gridItemTextView = mSolo.getText(gridItemTitle);
return isPinned == (gridItemTextView.getCompoundDrawables()[0] != null);
}
}, MAX_WAIT_MS);
mAsserter.ok(success, "Top site item was pinned: " + isPinned, null);
}
+ public void pinTopSite(String gridItemTitle) {
+ verifyPinned(false, gridItemTitle);
+ mSolo.clickLongOnText(gridItemTitle);
+ boolean dialogOpened = mSolo.waitForDialogToOpen();
+ mAsserter.ok(dialogOpened, "Pin site dialog opened: " + gridItemTitle, null);
+ boolean pinSiteFound = waitForText(StringHelper.CONTEXT_MENU_PIN_SITE);
+ mAsserter.ok(pinSiteFound, "Found pin site menu item", null);
+ mSolo.clickOnText(StringHelper.CONTEXT_MENU_PIN_SITE);
+ verifyPinned(true, gridItemTitle);
+ }
+
+ public void unpinTopSite(String gridItemTitle) {
+ verifyPinned(true, gridItemTitle);
+ mSolo.clickLongOnText(gridItemTitle);
+ boolean dialogOpened = mSolo.waitForDialogToOpen();
+ mAsserter.ok(dialogOpened, "Pin site dialog opened: " + gridItemTitle, null);
+ boolean unpinSiteFound = waitForText(StringHelper.CONTEXT_MENU_UNPIN_SITE);
+ mAsserter.ok(unpinSiteFound, "Found unpin site menu item", null);
+ mSolo.clickOnText(StringHelper.CONTEXT_MENU_UNPIN_SITE);
+ verifyPinned(false, gridItemTitle);
+ }
+
// Used to perform clicks on pop-up buttons without having to close the virtual keyboard
public void clickOnButton(String label) {
final Button button = mSolo.getButton(label);
try {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
button.performClick();
--- a/mobile/android/base/tests/testDistribution.java
+++ b/mobile/android/base/tests/testDistribution.java
@@ -2,24 +2,27 @@ package org.mozilla.gecko.tests;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URI;
+import java.util.Locale;
import java.util.jar.JarInputStream;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.Actions;
import org.mozilla.gecko.AppConstants;
+import org.mozilla.gecko.BrowserLocaleManager;
+import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.db.BrowserContract;
import org.mozilla.gecko.db.BrowserDB;
import org.mozilla.gecko.db.SuggestedSites;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.distribution.ReferrerDescriptor;
import org.mozilla.gecko.distribution.ReferrerReceiver;
import org.mozilla.gecko.util.ThreadUtils;
@@ -124,17 +127,24 @@ public class testDistribution extends Co
// finish. This reduces the chance of us racing with startup pref writes.
waitForBackgroundHappiness();
// Pre-clear distribution pref, override suggested sites and run tiles tests.
clearDistributionPref();
Distribution dist = initDistribution(mockPackagePath);
SuggestedSites suggestedSites = new SuggestedSites(mActivity, dist);
BrowserDB.setSuggestedSites(suggestedSites);
- checkTilesReporting();
+
+ // Test tiles uploading for an en-US OS locale with no app locale.
+ setOSLocale(Locale.US);
+ checkTilesReporting("en-US");
+
+ // Test tiles uploading for an es-MX OS locale with no app locale.
+ setOSLocale(new Locale("es", "MX"));
+ checkTilesReporting("es-MX");
// Pre-clear distribution pref, run basic preferences and en-US localized preferences Tests
clearDistributionPref();
setTestLocale("en-US");
initDistribution(mockPackagePath);
checkPreferences();
checkLocalizedPreferences("en-US");
checkSearchPlugin();
@@ -149,16 +159,21 @@ public class testDistribution extends Co
setTestLocale("en-US");
clearDistributionPref();
doTestValidReferrerIntent();
clearDistributionPref();
doTestInvalidReferrerIntent();
}
+ private void setOSLocale(Locale locale) {
+ Locale.setDefault(locale);
+ BrowserLocaleManager.storeAndNotifyOSLocale(GeckoSharedPrefs.forProfile(mActivity), locale);
+ }
+
private void doReferrerTest(String ref, final TestableDistribution distribution, final Runnable distributionReady) throws InterruptedException {
final Intent intent = new Intent(ACTION_INSTALL_REFERRER);
intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, CLASS_REFERRER_RECEIVER);
intent.putExtra("referrer", ref);
final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -325,47 +340,19 @@ public class testDistribution extends Co
}
}
mAsserter.ok(foundEngine, "check search plugin", "found test search plugin");
} catch (JSONException e) {
mAsserter.ok(false, "exception getting search plugins", e.toString());
}
}
- // Sets the distribution locale preference for the test
- private void setTestLocale(String aLocale) {
- String prefUseragentLocale = "general.useragent.locale";
-
- JSONObject jsonPref = new JSONObject();
- try {
- // Request the pref change to the locale.
- jsonPref.put("name", prefUseragentLocale);
- jsonPref.put("type", "string");
- jsonPref.put("value", aLocale);
- mActions.sendGeckoEvent("Preferences:Set", jsonPref.toString());
-
- // Wait for confirmation of the pref change.
- final String[] prefNames = { prefUseragentLocale };
-
- Actions.RepeatedEventExpecter eventExpecter = mActions.expectGeckoEvent("Preferences:Data");
- mActions.sendPreferencesGetEvent(PREF_REQUEST_ID, prefNames);
-
- JSONObject data = null;
- int requestId = -1;
-
- // Wait until we get the correct "Preferences:Data" event
- while (requestId != PREF_REQUEST_ID) {
- data = new JSONObject(eventExpecter.blockForEventData());
- requestId = data.getInt("requestId");
- }
- eventExpecter.unregisterListener();
-
- } catch (Exception e) {
- mAsserter.ok(false, "exception setting test locale", e.toString());
- }
+ // Sets the distribution locale preference for the test.
+ private void setTestLocale(String locale) {
+ BrowserLocaleManager.getInstance().setSelectedLocale(mActivity, locale);
}
// Test localized distribution and preferences values stored in preferences.json
private void checkLocalizedPreferences(String aLocale) {
String prefAbout = "distribution.about";
String prefLocalizeable = "distribution.test.localizeable";
String prefLocalizeableOverride = "distribution.test.localizeable-override";
@@ -449,42 +436,41 @@ public class testDistribution extends Co
private void clearDistributionPref() {
mAsserter.dumpLog("Clearing distribution pref.");
SharedPreferences settings = mActivity.getSharedPreferences("GeckoApp", Activity.MODE_PRIVATE);
String keyName = mActivity.getPackageName() + ".distribution_state";
settings.edit().remove(keyName).commit();
TestableDistribution.clearReferrerDescriptorForTesting();
}
- public void checkTilesReporting() throws JSONException {
+ public void checkTilesReporting(String localeCode) throws JSONException {
// Slight hack: Force top sites grid to reload.
inputAndLoadUrl(StringHelper.ABOUT_BLANK_URL);
inputAndLoadUrl(StringHelper.ABOUT_HOME_URL);
// Click the first tracking tile and verify the posted data.
JSONObject response = clickTrackingTile(StringHelper.DISTRIBUTION1_LABEL);
- mAsserter.is(0, response.getInt("click"), "JSON click index matched");
- mAsserter.is("[{\"id\":123},{\"id\":456},{},{},{},{}]", response.getString("tiles"), "JSON tiles data matched");
+ mAsserter.is(response.getInt("click"), 0, "JSON click index matched");
+ mAsserter.is(response.getString("locale"), localeCode, "JSON locale code matched");
+ mAsserter.is(response.getString("tiles"), "[{\"id\":123},{\"id\":456},{},{},{},{}]", "JSON tiles data matched");
inputAndLoadUrl(StringHelper.ABOUT_HOME_URL);
// Pin the second tracking tile.
- verifyPinned(false, StringHelper.DISTRIBUTION2_LABEL);
- mSolo.clickLongOnText(StringHelper.DISTRIBUTION2_LABEL);
- boolean dialogOpened = mSolo.waitForDialogToOpen();
- mAsserter.ok(dialogOpened, "Pin site dialog opened", null);
- boolean pinSiteFound = waitForText(StringHelper.CONTEXT_MENU_PIN_SITE);
- mAsserter.ok(pinSiteFound, "Found pin site menu item", null);
- mSolo.clickOnText(StringHelper.CONTEXT_MENU_PIN_SITE);
- verifyPinned(true, StringHelper.DISTRIBUTION2_LABEL);
+ pinTopSite(StringHelper.DISTRIBUTION2_LABEL);
// Click the second tracking tile and verify the posted data.
response = clickTrackingTile(StringHelper.DISTRIBUTION2_LABEL);
- mAsserter.is(1, response.getInt("click"), "JSON click index matched");
- mAsserter.is("[{\"id\":123},{\"id\":456,\"pin\":true},{},{},{},{}]", response.getString("tiles"), "JSON tiles data matched");
+ mAsserter.is(response.getInt("click"), 1, "JSON click index matched");
+ mAsserter.is(response.getString("tiles"), "[{\"id\":123},{\"id\":456,\"pin\":true},{},{},{},{}]", "JSON tiles data matched");
+
+ inputAndLoadUrl(StringHelper.ABOUT_HOME_URL);
+
+ // Unpin the second tracking tile.
+ unpinTopSite(StringHelper.DISTRIBUTION2_LABEL);
}
private JSONObject clickTrackingTile(String text) throws JSONException {
boolean tileFound = waitForText(text);
mAsserter.ok(tileFound, "Found tile: " + text, null);
Actions.EventExpecter loadExpecter = mActions.expectGeckoEvent("Robocop:TilesResponse");
mSolo.clickOnText(text);