Bug 1395409: wip - followup.
MozReview-Commit-ID: 2QxlAWEEzTo
--- a/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topstories/PocketStoriesLoader.java
+++ b/mobile/android/base/java/org/mozilla/gecko/activitystream/homepanel/topstories/PocketStoriesLoader.java
@@ -75,31 +75,33 @@ public class PocketStoriesLoader extends
private static final String PARAM_LOCALE = "locale_lang";
private static final long REFRESH_INTERVAL_MILLIS = TimeUnit.HOURS.toMillis(3);
private static final int BUFFER_SIZE = 2048;
private static final int CONNECT_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(15);
private static final int READ_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(15);
+ private static boolean isTesting = false;
+
private String localeLang;
private final SharedPreferences sharedPreferences;
private static String placeholderUrl;
public PocketStoriesLoader(Context context) {
super(context);
sharedPreferences = context.getSharedPreferences(POCKET_PREFS_FILE, Context.MODE_PRIVATE);
localeLang = Locales.getLanguageTag(Locale.getDefault());
}
@Override
protected void onStartLoading() {
- if (APIKEY == null) {
+ if (APIKEY == null || isTesting) {
deliverResult(makePlaceholderStories());
return;
}
// Check timestamp to determine if we have cached stories. This won't properly handle a client manually
// changing clock times, but this is not a time-sensitive task.
final long previousTime = sharedPreferences.getLong(CACHE_TIMESTAMP_MILLIS_PREFIX + localeLang, 0);
if (System.currentTimeMillis() - previousTime > REFRESH_INTERVAL_MILLIS) {
forceLoad();
@@ -190,19 +192,23 @@ public class PocketStoriesLoader extends
final List<TopStory> stories = new LinkedList<>();
for (int i = 0; i < 3; i++) {
// Urls must be different for bookmark/pinning UI to work properly. Assume this is true for Pocket stories.
stories.add(new TopStory(PLACEHOLDER_TITLE + i, placeholderUrl + i, null));
}
return stories;
}
- /** Overrides the placeholder URL - intended for use with testing. */
- @RobocopTarget
- @VisibleForTesting public static void setPlaceholderUrl(String placeholderUrl) {
+ private static void setPlaceholderUrl(String placeholderUrl) {
// See use of placeholderUrl for why suffix is necessary.
final String requiredSuffix = "#";
if (!placeholderUrl.endsWith(requiredSuffix)) {
placeholderUrl = placeholderUrl + requiredSuffix;
}
PocketStoriesLoader.placeholderUrl = placeholderUrl;
}
+
+ @RobocopTarget
+ @VisibleForTesting public static void configureForTesting(final String placeholderUrl) {
+ isTesting = true;
+ setPlaceholderUrl(placeholderUrl);
+ }
}
--- a/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testActivityStreamPocketReferrer.java
+++ b/mobile/android/tests/browser/robocop/src/org/mozilla/gecko/tests/testActivityStreamPocketReferrer.java
@@ -39,17 +39,17 @@ public class testActivityStreamPocketRef
private boolean tabLoadContainsPocketReferrer = false;
@Override
public void setUp() throws Exception {
super.setUp();
// Override the default placeholder URL so we don't access the network during testing.
// Note: this actually only seems to take effect after we load a page and go back to about:home.
- PocketStoriesLoader.setPlaceholderUrl(getAbsoluteHostnameUrl(StringHelper.get().ROBOCOP_BLANK_PAGE_01_URL));
+ PocketStoriesLoader.configureForTesting(getAbsoluteHostnameUrl(StringHelper.get().ROBOCOP_BLANK_PAGE_01_URL));
}
public void testActivityStreamPocketReferrer() throws Exception {
blockForReadyAndLoadJS(JS_FILE);
NavigationHelper.goBack(); // to top sites.
checkReferrerInTopStories();
checkReferrerInTopStoriesContextMenu();