Backed out changeset 14c09980119b (bug 1249783) for android 'unit' test failures

MozReview-Commit-ID: 5kusYiW1bsG
This commit is contained in:
Wes Kocher 2016-03-11 12:23:24 -08:00
Родитель 5e78e651d9
Коммит 8d3ad16663
6 изменённых файлов: 47 добавлений и 0 удалений

Просмотреть файл

@ -41,6 +41,7 @@ import org.mozilla.gecko.Locales;
import org.mozilla.gecko.R;
import org.mozilla.gecko.distribution.Distribution;
import org.mozilla.gecko.Restrictions;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.util.RawResource;
import org.mozilla.gecko.util.ThreadUtils;
@ -407,6 +408,11 @@ public class SuggestedSites {
editor.apply();
}
private boolean isEnabled() {
final SharedPreferences prefs = GeckoSharedPrefs.forApp(context);
return prefs.getBoolean(GeckoPreferences.PREFS_SUGGESTED_SITES, true);
}
private synchronized Site getSiteForUrl(String url) {
if (cachedSites == null) {
return null;
@ -453,6 +459,13 @@ public class SuggestedSites {
*/
public synchronized Cursor get(int limit, Locale locale, List<String> excludeUrls) {
final MatrixCursor cursor = new MatrixCursor(COLUMNS);
// Return an empty cursor if suggested sites have been
// disabled by the user.
if (!isEnabled()) {
return cursor;
}
final boolean isNewLocale = isNewLocale(context, locale);
// Force the suggested sites file in profile dir to be re-generated

Просмотреть файл

@ -160,6 +160,7 @@ OnSharedPreferenceChangeListener
private static final String PREFS_BROWSER_LOCALE = "locale";
public static final String PREFS_RESTORE_SESSION = NON_PREF_PREFIX + "restoreSession3";
public static final String PREFS_SUGGESTED_SITES = NON_PREF_PREFIX + "home_suggested_sites";
public static final String PREFS_TAB_QUEUE = NON_PREF_PREFIX + "tab_queue";
public static final String PREFS_TAB_QUEUE_LAST_SITE = NON_PREF_PREFIX + "last_site";
public static final String PREFS_TAB_QUEUE_LAST_TIME = NON_PREF_PREFIX + "last_time";
@ -1182,6 +1183,8 @@ OnSharedPreferenceChangeListener
if (PREFS_BROWSER_LOCALE.equals(key)) {
onLocaleSelected(Locales.getLanguageTag(lastLocale),
sharedPreferences.getString(key, null));
} else if (PREFS_SUGGESTED_SITES.equals(key)) {
refreshSuggestedSites();
}
}

Просмотреть файл

@ -178,6 +178,8 @@
<!ENTITY pref_home_updates2 "Content updates">
<!ENTITY pref_home_updates_enabled "Enabled">
<!ENTITY pref_home_updates_wifi "Only over Wi-Fi">
<!ENTITY pref_home_suggested_sites "Show site suggestions">
<!ENTITY pref_home_suggested_sites_summary "Display shortcuts to sites on your homepage that we think you might find interesting">
<!ENTITY pref_category_home_homepage "Homepage">
<!ENTITY home_homepage_title "Set a Homepage">
<!-- Localization note (home_homepage_radio_user_address): The user will see a series of radio

Просмотреть файл

@ -21,6 +21,15 @@
<org.mozilla.gecko.preferences.PanelsPreferenceCategory
android:title="@string/pref_category_home_panels"/>
<PreferenceCategory android:title="@string/pref_category_home_content_settings">
<CheckBoxPreference android:key="android.not_a_preference.home_suggested_sites"
android:title="@string/pref_home_suggested_sites"
android:summary="@string/pref_home_suggested_sites_summary"
android:defaultValue="true" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_home_add_ons">
<ListPreference android:key="home.sync.updateMode"

Просмотреть файл

@ -169,6 +169,8 @@
<string name="pref_category_home_panels">&pref_category_home_panels;</string>
<string name="pref_category_home_content_settings">&pref_category_home_content_settings;</string>
<string name="pref_home_updates_wifi">&pref_home_updates_wifi;</string>
<string name="pref_home_suggested_sites">&pref_home_suggested_sites;</string>
<string name="pref_home_suggested_sites_summary">&pref_home_suggested_sites_summary;</string>
<string name="pref_category_home_add_ons">&pref_category_home_add_ons;</string>
<string name="pref_home_updates">&pref_home_updates2;</string>
<string name="pref_home_updates_enabled">&pref_home_updates_enabled;</string>

Просмотреть файл

@ -324,6 +324,24 @@ public class TestSuggestedSites extends InstrumentationTestCase {
c.close();
}
public void testDisabledState() {
resources.setSuggestedSitesResource(generateSites(3));
Cursor c = new SuggestedSites(context).get(DEFAULT_LIMIT);
assertEquals(3, c.getCount());
c.close();
// Disable suggested sites
GeckoSharedPrefs.forApp(context).edit()
.putBoolean(GeckoPreferences.PREFS_SUGGESTED_SITES, false)
.commit();
c = new SuggestedSites(context).get(DEFAULT_LIMIT);
assertNotNull(c);
assertEquals(0, c.getCount());
c.close();
}
public void testImageUrlAndBgColor() {
final int count = 3;
resources.setSuggestedSitesResource(generateSites(count));