Index: chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsConfig.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsConfig.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsConfig.java |
index d5c43b27ebeca7588944d3edabfaf7e76aef17fd..ae1e361760ec255804c3f2853aa9fcfdda050772 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsConfig.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsConfig.java |
@@ -4,25 +4,44 @@ |
package org.chromium.chrome.browser.ntp.snippets; |
+import org.chromium.base.VisibleForTesting; |
import org.chromium.chrome.browser.ChromeFeatureList; |
import org.chromium.chrome.browser.offlinepages.OfflinePageBridge; |
+import java.util.Set; |
+ |
/** |
* Provides configuration details for NTP snippets. |
*/ |
public final class SnippetsConfig { |
+ /** Map that stores substitution feature flags for tests. */ |
+ private static Set<String> sTestEnabledFeatures; |
private SnippetsConfig() {} |
+ /** |
+ * Sets the feature flags to use in JUnit tests, since native calls are not available there. |
+ * Note: Always set it back to {@code null} at the end of the test! |
+ */ |
+ @VisibleForTesting |
+ public static void setTestEnabledFeatures(Set<String> featureList) { |
+ sTestEnabledFeatures = featureList; |
+ } |
+ |
public static boolean isEnabled() { |
- return ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SNIPPETS); |
+ return isFeatureEnabled(ChromeFeatureList.NTP_SNIPPETS); |
} |
public static boolean isSaveToOfflineEnabled() { |
- return ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SNIPPETS_SAVE_TO_OFFLINE) |
+ return isFeatureEnabled(ChromeFeatureList.NTP_SNIPPETS_SAVE_TO_OFFLINE) |
&& OfflinePageBridge.isBackgroundLoadingEnabled(); |
} |
public static boolean isSectionDismissalEnabled() { |
- return ChromeFeatureList.isEnabled(ChromeFeatureList.NTP_SUGGESTIONS_SECTION_DISMISSAL); |
+ return isFeatureEnabled(ChromeFeatureList.NTP_SUGGESTIONS_SECTION_DISMISSAL); |
+ } |
+ |
+ private static boolean isFeatureEnabled(String feature) { |
+ if (sTestEnabledFeatures == null) return ChromeFeatureList.isEnabled(feature); |
+ return sTestEnabledFeatures.contains(feature); |
} |
} |