Commit 010e75ed authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Android][Payment]changePaymentMethod should work with missing details

Without this cl changePaymentMethod would fail when the "details" key
did not exist in input bundle. With this change the "StringifiedDetails"
passed to changePaymentMethodfromInvokedApp()[1] will have the default
stringified empty JSON object value.

[1]https://cs.chromium.org/chromium/src/components/payments/content/android/java/src/org/chromium/components/payments/PaymentRequestUpdateEventListener.java?l=32

Bug: 1026667
Change-Id: I55ac9d3e5d6dc6923290223317164d1dfdd3faa6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2255656
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781458}
parent b67d6fc1
......@@ -328,7 +328,8 @@ public class PaymentDetailsUpdateServiceHelperTest {
installAndInvokePaymentApp();
startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "data");
bundle.putString(
PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, "{\"key\": \"value\"}");
mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(false);
......@@ -336,6 +337,25 @@ public class PaymentDetailsUpdateServiceHelperTest {
Assert.assertEquals(ErrorStrings.METHOD_NAME_REQUIRED, receivedErrorString());
}
@Test
@MediumTest
@Feature({"Payments"})
public void testSuccessfulChangePaymentMethodWithMissingDetails() throws Throwable {
installAndInvokePaymentApp();
startPaymentDetailsUpdateService();
Bundle bundle = new Bundle();
bundle.putString(PaymentHandlerMethodData.EXTRA_METHOD_NAME, "method-name");
// Skip populating "PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS" to verify that it is
// not a mandatory field.
mIPaymentDetailsUpdateService.changePaymentMethod(
bundle, new PaymentDetailsUpdateServiceCallback());
verifyIsWaitingForPaymentDetailsUpdate(true);
Assert.assertTrue(mMethodChangeListenerNotified);
updateWithDefaultDetails();
verifyUpdatedDefaultDetails();
verifyIsWaitingForPaymentDetailsUpdate(false);
}
@Test
@MediumTest
@Feature({"Payments"})
......
......@@ -89,9 +89,8 @@ public class PaymentDetailsUpdateServiceHelper {
return;
}
@Nullable
String stringifiedDetails = paymentHandlerMethodData.getString(
PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS);
PaymentHandlerMethodData.EXTRA_STRINGIFIED_DETAILS, /*defaultValue=*/"{}");
if (isWaitingForPaymentDetailsUpdate() || mListener == null
|| !mListener.changePaymentMethodFromInvokedApp(methodName, stringifiedDetails)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment