Commit b07da295 authored by Rouslan Solomakhin's avatar Rouslan Solomakhin Committed by Commit Bot

[Payments] More verbose 'payment method not supported' message.

Before this patch, PaymentRequest.show() could reject with "Payment
method not supported" message, which did not clarify which payment
methods were not supported. This could be debugging confusing in a large
production environment, where multiple PaymentRequest instances with
different payment method names are created.

This patch stores the set of payment method names for each instance of
PaymentRequest and prints them out in the error message, if none of them
are supported.

After this patch, PaymentRequest.show() can reject with error message
"Payment method 'xyz' is not supported". (Plurals are handled
correctly.)

Bug: 785992
Change-Id: I976b11b84f788ea98b4e413ca983edd8f792052d
Reviewed-on: https://chromium-review.googlesource.com/775045Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517243}
parent 8c036a86
...@@ -60,7 +60,7 @@ public class PaymentRequestFieldTrialTest implements MainActivityStartCallback { ...@@ -60,7 +60,7 @@ public class PaymentRequestFieldTrialTest implements MainActivityStartCallback {
throws InterruptedException, ExecutionException, TimeoutException { throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed()); mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"The payment method is not supported"}); new String[] {"The payment method", "not supported"});
} }
/** /**
......
...@@ -1065,7 +1065,7 @@ public class PaymentRequestJourneyLoggerTest implements MainActivityStartCallbac ...@@ -1065,7 +1065,7 @@ public class PaymentRequestJourneyLoggerTest implements MainActivityStartCallbac
mPaymentRequestTestRule.openPageAndClickNodeAndWait( mPaymentRequestTestRule.openPageAndClickNodeAndWait(
"androidPayBuy", mPaymentRequestTestRule.getShowFailed()); "androidPayBuy", mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"The payment method is not supported"}); new String[] {"The payment method", "not supported"});
// Make sure that no journey metrics were logged. // Make sure that no journey metrics were logged.
Assert.assertEquals(0, Assert.assertEquals(0,
......
...@@ -272,7 +272,7 @@ public class PaymentRequestMetricsTest implements MainActivityStartCallback { ...@@ -272,7 +272,7 @@ public class PaymentRequestMetricsTest implements MainActivityStartCallback {
mPaymentRequestTestRule.openPageAndClickNodeAndWait( mPaymentRequestTestRule.openPageAndClickNodeAndWait(
"androidPayBuy", mPaymentRequestTestRule.getShowFailed()); "androidPayBuy", mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"The payment method is not supported"}); new String[] {"The payment method", "not supported"});
// Make sure that it is not logged as an abort. // Make sure that it is not logged as an abort.
mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(-1 /* none */); mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(-1 /* none */);
...@@ -302,7 +302,7 @@ public class PaymentRequestMetricsTest implements MainActivityStartCallback { ...@@ -302,7 +302,7 @@ public class PaymentRequestMetricsTest implements MainActivityStartCallback {
mPaymentRequestTestRule.openPageAndClickNodeAndWait( mPaymentRequestTestRule.openPageAndClickNodeAndWait(
"noSupported", mPaymentRequestTestRule.getShowFailed()); "noSupported", mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"The payment method is not supported"}); new String[] {"The payment method", "not supported"});
// Make sure that it is not logged as an abort. // Make sure that it is not logged as an abort.
mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(-1 /* none */); mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(-1 /* none */);
......
...@@ -42,6 +42,6 @@ public class PaymentRequestModifierTest implements MainActivityStartCallback { ...@@ -42,6 +42,6 @@ public class PaymentRequestModifierTest implements MainActivityStartCallback {
public void testNoCrash() throws InterruptedException, ExecutionException, TimeoutException { public void testNoCrash() throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed()); mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"The payment method is not supported"}); new String[] {"The payment method", "not supported"});
} }
} }
...@@ -49,7 +49,7 @@ public class PaymentRequestPaymentAppTest { ...@@ -49,7 +49,7 @@ public class PaymentRequestPaymentAppTest {
throws InterruptedException, ExecutionException, TimeoutException { throws InterruptedException, ExecutionException, TimeoutException {
mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed()); mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"show() rejected", "The payment method is not supported"}); new String[] {"show() rejected", "The payment method", "not supported"});
} }
/** /**
...@@ -64,7 +64,7 @@ public class PaymentRequestPaymentAppTest { ...@@ -64,7 +64,7 @@ public class PaymentRequestPaymentAppTest {
mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, IMMEDIATE_RESPONSE); mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, IMMEDIATE_RESPONSE);
mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed()); mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"show() rejected", "The payment method is not supported"}); new String[] {"show() rejected", "The payment method", "not supported"});
} }
/** /**
...@@ -79,7 +79,7 @@ public class PaymentRequestPaymentAppTest { ...@@ -79,7 +79,7 @@ public class PaymentRequestPaymentAppTest {
mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, DELAYED_RESPONSE); mPaymentRequestTestRule.installPaymentApp(NO_INSTRUMENTS, DELAYED_RESPONSE);
mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed()); mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"show() rejected", "The payment method is not supported"}); new String[] {"show() rejected", "The payment method", "not supported"});
} }
/** /**
...@@ -122,7 +122,7 @@ public class PaymentRequestPaymentAppTest { ...@@ -122,7 +122,7 @@ public class PaymentRequestPaymentAppTest {
mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed()); mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed());
ThreadUtils.runOnUiThreadBlocking(() -> app.respond()); ThreadUtils.runOnUiThreadBlocking(() -> app.respond());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"show() rejected", "The payment method is not supported"}); new String[] {"show() rejected", "The payment method", "not supported"});
} }
/** /**
......
...@@ -70,7 +70,7 @@ public class PaymentRequestServiceWorkerPaymentAppTest { ...@@ -70,7 +70,7 @@ public class PaymentRequestServiceWorkerPaymentAppTest {
mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed()); mPaymentRequestTestRule.openPageAndClickBuyAndWait(mPaymentRequestTestRule.getShowFailed());
mPaymentRequestTestRule.expectResultContains( mPaymentRequestTestRule.expectResultContains(
new String[] {"show() rejected", "The payment method is not supported"}); new String[] {"show() rejected", "The payment method", "not supported"});
} }
@Test @Test
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "platform/runtime_enabled_features.h" #include "platform/runtime_enabled_features.h"
#include "platform/weborigin/KURL.h" #include "platform/weborigin/KURL.h"
#include "platform/wtf/HashSet.h" #include "platform/wtf/HashSet.h"
#include "platform/wtf/text/StringBuilder.h"
#include "public/platform/Platform.h" #include "public/platform/Platform.h"
#include "public/platform/TaskType.h" #include "public/platform/TaskType.h"
#include "public/platform/WebTraceLocation.h" #include "public/platform/WebTraceLocation.h"
...@@ -662,6 +663,7 @@ void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate& input, ...@@ -662,6 +663,7 @@ void ValidateAndConvertPaymentDetailsUpdate(const PaymentDetailsUpdate& input,
void ValidateAndConvertPaymentMethodData( void ValidateAndConvertPaymentMethodData(
const HeapVector<PaymentMethodData>& input, const HeapVector<PaymentMethodData>& input,
Vector<payments::mojom::blink::PaymentMethodDataPtr>& output, Vector<payments::mojom::blink::PaymentMethodDataPtr>& output,
HashSet<String>& method_names,
ExecutionContext& execution_context, ExecutionContext& execution_context,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (input.IsEmpty()) { if (input.IsEmpty()) {
...@@ -715,6 +717,7 @@ void ValidateAndConvertPaymentMethodData( ...@@ -715,6 +717,7 @@ void ValidateAndConvertPaymentMethodData(
"Invalid payment method identifier format"); "Invalid payment method identifier format");
return; return;
} }
method_names.insert(identifier);
} }
CountPaymentRequestNetworkNameInSupportedMethods(supported_methods, CountPaymentRequestNetworkNameInSupportedMethods(supported_methods,
...@@ -1016,7 +1019,8 @@ PaymentRequest::PaymentRequest(ExecutionContext* execution_context, ...@@ -1016,7 +1019,8 @@ PaymentRequest::PaymentRequest(ExecutionContext* execution_context,
Vector<payments::mojom::blink::PaymentMethodDataPtr> validated_method_data; Vector<payments::mojom::blink::PaymentMethodDataPtr> validated_method_data;
ValidateAndConvertPaymentMethodData(method_data, validated_method_data, ValidateAndConvertPaymentMethodData(method_data, validated_method_data,
*GetExecutionContext(), exception_state); method_names_, *GetExecutionContext(),
exception_state);
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
...@@ -1156,18 +1160,39 @@ void PaymentRequest::OnError(PaymentErrorReason error) { ...@@ -1156,18 +1160,39 @@ void PaymentRequest::OnError(PaymentErrorReason error) {
String message; String message;
switch (error) { switch (error) {
case PaymentErrorReason::USER_CANCEL: case PaymentErrorReason::USER_CANCEL: {
ec = kAbortError; ec = kAbortError;
message = "Request cancelled"; message = "Request cancelled";
break; break;
case PaymentErrorReason::NOT_SUPPORTED: }
case PaymentErrorReason::NOT_SUPPORTED: {
ec = kNotSupportedError; ec = kNotSupportedError;
message = "The payment method is not supported"; DCHECK_LE(1U, method_names_.size());
auto it = method_names_.begin();
if (method_names_.size() == 1U) {
message = "The payment method \"" + *it + "\" is not supported";
} else {
StringBuilder sb;
sb.Append("The payment methods \"");
sb.Append(*it);
sb.Append("\"");
while (++it != method_names_.end()) {
sb.Append(", \"");
sb.Append(*it);
sb.Append("\"");
}
sb.Append(" are not supported");
message = sb.ToString();
}
break; break;
case PaymentErrorReason::UNKNOWN: }
case PaymentErrorReason::UNKNOWN: {
ec = kUnknownError; ec = kUnknownError;
message = "Request failed"; message = "Request failed";
break; break;
}
} }
DCHECK(!message.IsEmpty()); DCHECK(!message.IsEmpty());
......
...@@ -130,6 +130,7 @@ class MODULES_EXPORT PaymentRequest final ...@@ -130,6 +130,7 @@ class MODULES_EXPORT PaymentRequest final
String id_; String id_;
String shipping_option_; String shipping_option_;
String shipping_type_; String shipping_type_;
HashSet<String> method_names_;
Member<ScriptPromiseResolver> show_resolver_; Member<ScriptPromiseResolver> show_resolver_;
Member<ScriptPromiseResolver> complete_resolver_; Member<ScriptPromiseResolver> complete_resolver_;
Member<ScriptPromiseResolver> abort_resolver_; Member<ScriptPromiseResolver> abort_resolver_;
......
...@@ -343,7 +343,7 @@ TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) { ...@@ -343,7 +343,7 @@ TEST(PaymentRequestTest, RejectShowPromiseOnErrorPaymentMethodNotSupported) {
payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED); payments::mojom::blink::PaymentErrorReason::NOT_SUPPORTED);
v8::MicrotasksScope::PerformCheckpoint(scope.GetScriptState()->GetIsolate()); v8::MicrotasksScope::PerformCheckpoint(scope.GetScriptState()->GetIsolate());
EXPECT_EQ("NotSupportedError: The payment method is not supported", EXPECT_EQ("NotSupportedError: The payment method \"foo\" is not supported",
error_message); error_message);
} }
......
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