Commit fed3fc66 authored by rouslan's avatar rouslan Committed by Commit bot

Log duplicate shipping option ID warning in web payments API.

Before this patch, passing duplicate shipping option identifiers into
web payments API was silently treated as an indicator of invalid
shipping address. This matches the spec, but the web developer may be
confused.

The fix is to add a warning message in console:
  "Duplicate shipping option identifier '<id>' is treated as an invalid
  address indicator."

Spec:
https://w3c.github.io/browser-payment-api/#constructor
(See step 8, "Process shipping options.")

BUG=711677

Review-Url: https://codereview.chromium.org/2830683002
Cr-Commit-Position: refs/heads/master@{#465751}
parent e7c580f5
CONSOLE WARNING: line 160: Duplicate shipping option identifier 'express' is treated as an invalid address indicator.
CONSOLE WARNING: line 248: Cannot yet distinguish credit, debit, and prepaid cards. CONSOLE WARNING: line 248: Cannot yet distinguish credit, debit, and prepaid cards.
CONSOLE WARNING: line 252: Cannot yet distinguish credit, debit, and prepaid cards. CONSOLE WARNING: line 252: Cannot yet distinguish credit, debit, and prepaid cards.
This is a testharness.js-based test. This is a testharness.js-based test.
......
...@@ -190,6 +190,7 @@ void ValidateAndConvertDisplayItems(const HeapVector<PaymentItem>& input, ...@@ -190,6 +190,7 @@ void ValidateAndConvertDisplayItems(const HeapVector<PaymentItem>& input,
void ValidateAndConvertShippingOptions( void ValidateAndConvertShippingOptions(
const HeapVector<PaymentShippingOption>& input, const HeapVector<PaymentShippingOption>& input,
Vector<PaymentShippingOptionPtr>& output, Vector<PaymentShippingOptionPtr>& output,
ExecutionContext& execution_context,
ExceptionState& exception_state) { ExceptionState& exception_state) {
HashSet<String> unique_ids; HashSet<String> unique_ids;
for (const PaymentShippingOption& option : input) { for (const PaymentShippingOption& option : input) {
...@@ -199,6 +200,10 @@ void ValidateAndConvertShippingOptions( ...@@ -199,6 +200,10 @@ void ValidateAndConvertShippingOptions(
} }
if (unique_ids.Contains(option.id())) { if (unique_ids.Contains(option.id())) {
execution_context.AddConsoleMessage(ConsoleMessage::Create(
kJSMessageSource, kWarningMessageLevel,
"Duplicate shipping option identifier '" + option.id() +
"' is treated as an invalid address indicator."));
// Clear |output| instead of throwing an exception. // Clear |output| instead of throwing an exception.
output.clear(); output.clear();
return; return;
...@@ -496,8 +501,9 @@ void ValidateAndConvertPaymentDetailsBase(const PaymentDetailsBase& input, ...@@ -496,8 +501,9 @@ void ValidateAndConvertPaymentDetailsBase(const PaymentDetailsBase& input,
} }
if (input.hasShippingOptions() && request_shipping) { if (input.hasShippingOptions() && request_shipping) {
ValidateAndConvertShippingOptions( ValidateAndConvertShippingOptions(input.shippingOptions(),
input.shippingOptions(), output->shipping_options, exception_state); output->shipping_options,
execution_context, exception_state);
if (exception_state.HadException()) if (exception_state.HadException())
return; return;
} }
......
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