Revert "[Android] Remove ShadowPaymentFeatureList"
This reverts commit dff693dab0ae831b758dc77177370255eb00105d.
Reason for revert: Suspected culprit of compilation failure
Original change's description:
> [Android] Remove ShadowPaymentFeatureList
>
> With downstream usages removed, this can now be cleaned up.
>
> Bug: 1445758
> Change-Id: I7972f8283e3e1a9fc35a64495a98e40bd5f190c2
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4534200
> Reviewed-by: Rouslan Solomakhin <rouslan@chromium.org>
> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1145489}
Bug: 1445758
Change-Id: Ica70460b7b3715ad3ec2a8e058f1618cfbff5efc
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4546065
Reviewed-by: Zach Katz <katzz@google.com>
Commit-Queue: Zach Katz <katzz@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Owners-Override: Zach Katz <katzz@google.com>
Cr-Commit-Position: refs/heads/main@{#1145758}
diff --git a/components/payments/content/android/BUILD.gn b/components/payments/content/android/BUILD.gn
index b3a9b85..c72ee42 100644
--- a/components/payments/content/android/BUILD.gn
+++ b/components/payments/content/android/BUILD.gn
@@ -334,6 +334,7 @@
"junit/src/org/chromium/components/payments/test_support/DefaultPaymentFeatureConfig.java",
"junit/src/org/chromium/components/payments/test_support/FakeClock.java",
"junit/src/org/chromium/components/payments/test_support/PaymentRequestServiceBuilder.java",
+ "junit/src/org/chromium/components/payments/test_support/ShadowPaymentFeatureList.java",
"junit/src/org/chromium/components/payments/test_support/ShadowWebContentsStatics.java",
]
deps = [
diff --git a/components/payments/content/android/junit/src/org/chromium/components/payments/test_support/ShadowPaymentFeatureList.java b/components/payments/content/android/junit/src/org/chromium/components/payments/test_support/ShadowPaymentFeatureList.java
new file mode 100644
index 0000000..352a12e
--- /dev/null
+++ b/components/payments/content/android/junit/src/org/chromium/components/payments/test_support/ShadowPaymentFeatureList.java
@@ -0,0 +1,68 @@
+// Copyright 2020 The Chromium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.components.payments.test_support;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+import org.robolectric.annotation.Resetter;
+
+import org.chromium.components.payments.PaymentFeatureList;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The shadow of PaymentFeatureList that allows unit tests to avoid loading native libraries to
+ * check payment feature flag states. Usage example:
+ *
+ * @RunWith(BaseRobolectricTestRunner.class)
+ * @Config(manifest = Config.NONE, shadows = {ShadowPaymentFeatureList.class})
+ * public class MyTest {}
+ *
+ * @deprecated use {@link DefaultPaymentFeatureConfig} with @Enable/DisableFeatures and
+ * JUnitProcessor instead.
+ */
+@Deprecated
+@Implements(PaymentFeatureList.class)
+public class ShadowPaymentFeatureList {
+ private static final Map<String, Boolean> sFeatureStatuses = new HashMap<>();
+
+ public static void setDefaultStatuses() {
+ ShadowPaymentFeatureList.setFeatureEnabled(PaymentFeatureList.WEB_PAYMENTS, true);
+ ShadowPaymentFeatureList.setFeatureEnabled(
+ PaymentFeatureList.WEB_PAYMENTS_SINGLE_APP_UI_SKIP, true);
+ ShadowPaymentFeatureList.setFeatureEnabled(
+ PaymentFeatureList.GPAY_APP_DYNAMIC_UPDATE, true);
+ ShadowPaymentFeatureList.setFeatureEnabled(
+ PaymentFeatureList.WEB_PAYMENTS_EXPERIMENTAL_FEATURES, true);
+ ShadowPaymentFeatureList.setFeatureEnabled(
+ PaymentFeatureList.SECURE_PAYMENT_CONFIRMATION, true);
+ ShadowPaymentFeatureList.setFeatureEnabled(
+ PaymentFeatureList.ADD_IDENTITY_IN_CAN_MAKE_PAYMENT_EVENT, false);
+ ShadowPaymentFeatureList.setFeatureEnabled(
+ PaymentFeatureList.OMIT_PARAMETERS_IN_READY_TO_PAY, false);
+ }
+
+ @Resetter
+ public static void reset() {
+ sFeatureStatuses.clear();
+ setDefaultStatuses();
+ }
+
+ @Implementation
+ public static boolean isEnabled(String featureName) {
+ assert sFeatureStatuses.containsKey(featureName) : "The feature state has yet been set.";
+ return sFeatureStatuses.get(featureName);
+ }
+
+ /**
+ * Set the given feature to be enabled.
+ * @param featureName The name of the feature.
+ * @param enabled Whether to enable the feature.
+ */
+ public static void setFeatureEnabled(String featureName, boolean enabled) {
+ sFeatureStatuses.put(featureName, enabled);
+ }
+}