Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(115)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardsVariationParameters.java

Issue 2607333002: [NTP Suggestions] Updating the suggestions before going below the fold. (Closed)
Patch Set: Fix a unit-test Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardsVariationParameters.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardsVariationParameters.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardsVariationParameters.java
index f2da71542c9303ef5052736573a1de076e47e90b..0681a57b3270c3496a151102334e9ed8aac7a419 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardsVariationParameters.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/CardsVariationParameters.java
@@ -7,12 +7,18 @@ package org.chromium.chrome.browser.ntp.cards;
import android.text.TextUtils;
import org.chromium.base.Log;
+import org.chromium.base.VisibleForTesting;
import org.chromium.components.variations.VariationsAssociatedData;
+import java.util.Map;
+
/**
* Provides easy access to data for field trials to do with the Cards UI.
*/
public final class CardsVariationParameters {
+ /** Map that stores substitution values for params. */
+ private static Map<String, String> sTestVariationParams;
+
// Tags are limited to 20 characters.
private static final String TAG = "CardsVariationParams";
@@ -24,6 +30,8 @@ public final class CardsVariationParameters {
private static final String PARAM_FIRST_CARD_ANIMATION_MAX_RUNS =
"first_card_animation_max_runs";
private static final String PARAM_SCROLL_BELOW_THE_FOLD = "scroll_below_the_fold";
+ private static final String PARAM_IGNORE_UPDATES_FOR_EXISTING_SUGGESTIONS =
+ "ignore_updates_for_existing_suggestions";
private static final String PARAM_DISABLED_VALUE = "off";
@@ -31,6 +39,16 @@ public final class CardsVariationParameters {
private CardsVariationParameters() {}
+ // TODO(jkrcal): Do a proper general fix in VariationsAssociatedData in the spirit of
+ // @EnableFeatures and ChromeFeatureList.
+ /**
+ * Sets the parameter values to use in JUnit tests, since native calls are not available there.
+ */
+ @VisibleForTesting
+ public static void setTestVariationParams(Map<String, String> variationParams) {
+ sTestVariationParams = variationParams;
+ }
+
/**
* Provides the value of the field trial to offset the peeking card (can be overridden
* with a command line flag). It will return 0 if there is no such field trial.
@@ -50,19 +68,23 @@ public final class CardsVariationParameters {
* @return Whether the NTP should initially be scrolled below the fold.
*/
public static boolean isScrollBelowTheFoldEnabled() {
- return Boolean.parseBoolean(VariationsAssociatedData.getVariationParamValue(
- FIELD_TRIAL_NAME, PARAM_SCROLL_BELOW_THE_FOLD));
+ return Boolean.parseBoolean(getParamValue(PARAM_SCROLL_BELOW_THE_FOLD));
+ }
+
+ /**
+ * @return Whether the NTP should ignore updates for suggestions that have not been seen yet.
+ */
+ public static boolean ignoreUpdatesForExistingSuggestions() {
+ return Boolean.parseBoolean(getParamValue(PARAM_IGNORE_UPDATES_FOR_EXISTING_SUGGESTIONS));
}
public static boolean isFaviconServiceEnabled() {
- return !PARAM_DISABLED_VALUE.equals(VariationsAssociatedData.getVariationParamValue(
- FIELD_TRIAL_NAME, PARAM_FAVICON_SERVICE_NAME));
+ return !PARAM_DISABLED_VALUE.equals(getParamValue(PARAM_FAVICON_SERVICE_NAME));
}
private static int getIntValue(String paramName, int defaultValue) {
// TODO(jkrcal): Get parameter by feature name, not field trial name.
- String value = VariationsAssociatedData.getVariationParamValue(
- FIELD_TRIAL_NAME, paramName);
+ String value = getParamValue(paramName);
if (!TextUtils.isEmpty(value)) {
try {
@@ -74,4 +96,14 @@ public final class CardsVariationParameters {
return defaultValue;
}
+
+ private static String getParamValue(String paramName) {
+ if (sTestVariationParams != null) {
+ String value = sTestVariationParams.get(paramName);
+ if (value == null) return "";
+ return value;
+ }
+
+ return VariationsAssociatedData.getVariationParamValue(FIELD_TRIAL_NAME, paramName);
+ }
}
« no previous file with comments | « no previous file | chrome/android/java/src/org/chromium/chrome/browser/ntp/cards/NewTabPageRecyclerView.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698