Commit 48ccd5c8 authored by Jihwan Marc Kim's avatar Jihwan Marc Kim Committed by Commit Bot

Disallow duplicate payment method identifiers.

Disallow duplicate payment method identifiers as specced in
https://github.com/w3c/payment-request/pull/908

Bug: 1085712
Change-Id: I9cb2d8d0960f248d1cbad83140ba6d6be92fbbb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214868
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772240}
parent cdb6b36a
...@@ -291,35 +291,6 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest, ...@@ -291,35 +291,6 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest,
EXPECT_EQ("visa", supported_card_networks[7]); EXPECT_EQ("visa", supported_card_networks[7]);
} }
// Specifying 'basic-card' with some networks after having explicitely included
// the same networks does not yield duplicates and has the expected order.
IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest,
RepeatedBasicCardWithSameNetworkAreDeduped) {
NavigateTo("/payment_request_payment_method_identifier_test.html");
InvokePaymentRequestWithJs(
"buyHelper([{"
" supportedMethods: 'basic-card',"
" data: {"
" supportedNetworks: ['mastercard'],"
" }"
"}, {"
" supportedMethods: 'basic-card',"
" data: {"
" supportedNetworks: ['visa', 'mastercard', 'jcb'],"
" }"
"}]);");
std::vector<PaymentRequest*> requests =
GetPaymentRequests(GetActiveWebContents());
EXPECT_EQ(1u, requests.size());
std::vector<std::string> supported_card_networks =
requests[0]->spec()->supported_card_networks();
EXPECT_EQ(3u, supported_card_networks.size());
EXPECT_EQ("mastercard", supported_card_networks[0]);
EXPECT_EQ("visa", supported_card_networks[1]);
EXPECT_EQ("jcb", supported_card_networks[2]);
}
// A url-based payment method identifier is only supported if it has an https // A url-based payment method identifier is only supported if it has an https
// scheme. // scheme.
IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest, Url_Valid) { IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest, Url_Valid) {
...@@ -340,41 +311,6 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest, Url_Valid) { ...@@ -340,41 +311,6 @@ IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest, Url_Valid) {
EXPECT_EQ(GURL("https://bobpay.xyz"), url_payment_method_identifiers[0]); EXPECT_EQ(GURL("https://bobpay.xyz"), url_payment_method_identifiers[0]);
} }
// Specifiying multiple different types of payment method identifiers still
// yields the correct supported methods in payment request.
IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentMethodIdentifierTest,
MultiplePaymentMethodIdentifiers) {
NavigateTo("/payment_request_payment_method_identifier_test.html");
InvokePaymentRequestWithJs(
"buyHelper([{"
" supportedMethods: 'https://bobpay.xyz'"
"}, {"
" supportedMethods: 'https://bobpay.xyz'"
"}, {"
" supportedMethods: 'https://alicepay.com'"
"}, {"
" supportedMethods: 'basic-card',"
" data: {"
" supportedNetworks: ['visa', 'mastercard', 'jcb'],"
" }"
"}]);");
std::vector<PaymentRequest*> requests =
GetPaymentRequests(GetActiveWebContents());
EXPECT_EQ(1u, requests.size());
std::vector<std::string> supported_card_networks =
requests[0]->spec()->supported_card_networks();
EXPECT_THAT(supported_card_networks,
UnorderedElementsAre("mastercard", "visa", "jcb"));
std::vector<GURL> url_payment_method_identifiers =
requests[0]->spec()->url_payment_method_identifiers();
EXPECT_EQ(2u, url_payment_method_identifiers.size());
EXPECT_EQ(GURL("https://bobpay.xyz"), url_payment_method_identifiers[0]);
EXPECT_EQ(GURL("https://alicepay.com"), url_payment_method_identifiers[1]);
}
// Test harness integrating with DialogBrowserTest to present the dialog in an // Test harness integrating with DialogBrowserTest to present the dialog in an
// interactive manner for visual testing. // interactive manner for visual testing.
class PaymentsRequestVisualTest class PaymentsRequestVisualTest
......
...@@ -659,6 +659,13 @@ void ValidateAndConvertPaymentMethodData( ...@@ -659,6 +659,13 @@ void ValidateAndConvertPaymentMethodData(
"Invalid payment method identifier format"); "Invalid payment method identifier format");
return; return;
} }
if (method_names.Contains(payment_method_data->supportedMethod())) {
exception_state.ThrowRangeError(
"Cannot have duplicate payment method identifiers");
return;
}
method_names.insert(payment_method_data->supportedMethod()); method_names.insert(payment_method_data->supportedMethod());
output.push_back(payments::mojom::blink::PaymentMethodData::New()); output.push_back(payments::mojom::blink::PaymentMethodData::New());
......
This is a testharness.js-based test.
PASS If details.id is missing, assign an identifier
PASS If details.id is missing, assign a unique identifier
PASS If the same id is provided, then use it
PASS Use ids even if they are strange
PASS Use provided request ID
PASS If the length of the methodData sequence is zero, then throw a TypeError
FAIL If payment method is duplicate, then throw a RangeError assert_throws_js: function "() => new PaymentRequest(duplicateMethods, defaultDetails)" did not throw
PASS Modifier method data must be JSON-serializable object
PASS Rethrow any exceptions of JSON-serializing paymentMethod.data into a string
PASS If details.total.amount.value is not a valid decimal monetary value, then throw a TypeError
PASS PaymentDetailsBase members can be 0 length
PASS If the first character of details.total.amount.value is U+002D HYPHEN-MINUS, then throw a TypeError
PASS For each item in details.displayItems: if item.amount.value is not a valid decimal monetary value, then throw a TypeError
PASS Negative values are allowed for displayItems.amount.value, irrespective of total amount
PASS it handles high precision currency values without throwing
PASS For each option in details.shippingOptions: if option.amount.value is not a valid decimal monetary value, then throw a TypeError
PASS If there is no selected shipping option, then PaymentRequest.shippingOption remains null
PASS If there is a selected shipping option, and requestShipping is set, then that option becomes synchronously selected
PASS If requestShipping is set, and if there is a multiple selected shipping options, only the last is selected.
PASS If there are any duplicate shipping option ids, and shipping is requested, then throw a TypeError
PASS Throw when there are duplicate shippingOption ids, even if other values are different
PASS Throw TypeError if modifier.total.amount.value is not a valid decimal monetary value
PASS If amount.value of additionalDisplayItems is not a valid decimal monetary value, then throw a TypeError
PASS Modifier data must be JSON-serializable object (an Array in this case)
PASS Modifier data must be JSON-serializable object (an Object in this case)
PASS Rethrow any exceptions of JSON-serializing modifier.data
PASS Shipping type should be valid
PASS PaymentRequest.shippingAddress must initially be null
PASS If options.requestShipping is not set, then request.shippingType attribute is null.
PASS If options.requestShipping is true, request.shippingType will be options.shippingType.
Harness: the test ran to completion.
...@@ -225,10 +225,6 @@ test(function() { ...@@ -225,10 +225,6 @@ test(function() {
new PaymentRequest([{'supportedMethods': 'foo'}], {'total': buildItem(), 'modifiers': [{'supportedMethods': 'foo', 'total': buildItem({'value': '0.0'})}]}); new PaymentRequest([{'supportedMethods': 'foo'}], {'total': buildItem(), 'modifiers': [{'supportedMethods': 'foo', 'total': buildItem({'value': '0.0'})}]});
}, 'Non-negative total value in PaymentDetailsModifier should not throw.'); }, 'Non-negative total value in PaymentDetailsModifier should not throw.');
test(function() {
new PaymentRequest([{'supportedMethods': 'foo'}, {'supportedMethods': 'foo'}], buildDetails(), {});
}, 'Duplicate supported payment method identifiers in separate methodData objects should not throw.');
test(function() { test(function() {
new PaymentRequest([{'supportedMethods': 'foo'}], {'total': buildItem(), 'modifiers': [{'supportedMethods': 'foo'}, {'supportedMethods': 'foo'}]}); new PaymentRequest([{'supportedMethods': 'foo'}], {'total': buildItem(), 'modifiers': [{'supportedMethods': 'foo'}, {'supportedMethods': 'foo'}]});
}, 'Duplicate supported payment method identifiers in separate methoData objects of modifiers should not throw.'); }, 'Duplicate supported payment method identifiers in separate methoData objects of modifiers should not throw.');
......
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