Commit 5d2f94cd authored by sebsg's avatar sebsg Committed by Commit Bot

[Payments] Blink: Throw TypeError if 2 shipping option have same id.

Relevant section of the spec:
https://www.w3.org/TR/payment-request/#constructor

"If seenIDs contains option.id, then throw a TypeError.
 Optionally, inform the developer that shipping option
 IDs must be unique."

Since those were the last 2 Failures for the payment-request-constructor
.https.txt, removing the associates expected file.

Bug: 766316
Test: blink_tests
Change-Id: I65c1f924c15e134c9f5ff68649802358fc43e074
Reviewed-on: https://chromium-review.googlesource.com/671820
Commit-Queue: Sebastien Seguin-Gagnon <sebsg@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502877}
parent 01b28422
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
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.
FAIL If there are any duplicate shipping option ids, and shipping is requested, then throw a TypeError Test bug: unrecognized DOMException code "() => {
const request = new PaymentRequest(defaultMethods, details, {
requestShipping: true,
});
}" passed to assert_throws()
FAIL Throw when there are duplicate shippingOption ids, even if other values are different assert_throws: Expected to throw a TypeError because duplicate IDs function "() => {
new PaymentRequest(defaultMethods, details, { requestShipping: true });
}" did not throw
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.
......@@ -476,11 +476,13 @@ test(() => {
null,
"shippingOption must be null, because requestShipping is false"
);
assert_throws(() => {
const request = new PaymentRequest(defaultMethods, details, {
requestShipping: true,
});
});
assert_throws(
new TypeError(),
() => {
new PaymentRequest(defaultMethods, details, { requestShipping: true });
},
"Expected to throw a TypeError because duplicate IDs"
);
}, "If there are any duplicate shipping option ids, and shipping is requested, then throw a TypeError");
test(() => {
......
......@@ -157,9 +157,14 @@ test(function() {
test(function() {
var shippingOptions = [buildItem({'id': 'express', 'selected': false}), buildItem({'id': 'express', 'selected': true})];
var request = new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), 'displayItems': [buildItem()], 'shippingOptions': shippingOptions}, {'requestShipping': true});
assert_equals(null, request.shippingOption);
}, 'No shipping option selected for duplicate shipping option identifiers.');
assert_throws(
new TypeError(),
() => {
new PaymentRequest([{'supportedMethods': ['foo']}], {'total': buildItem(), 'displayItems': [buildItem()], 'shippingOptions': shippingOptions}, {'requestShipping': true});
},
"Expected to throw a TypeError because duplicate shipping option IDs"
);
}, 'A TypeError should be thrown for duplicate shipping option identifiers.');
test(function() {
var request = new PaymentRequest([{'supportedMethods': ['foo']}], buildDetails(), {'requestShipping': false});
......
......@@ -268,13 +268,8 @@ void ValidateAndConvertShippingOptions(
}
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.
output.clear();
shipping_option_output = String();
exception_state.ThrowTypeError(
"Cannot have duplicate shipping option identifiers");
return;
}
......
......@@ -564,7 +564,7 @@ TEST(PaymentRequestTest, NoExceptionWithErrorMessageInUpdate) {
}
TEST(PaymentRequestTest,
ShouldResolveWithEmptyShippingOptionsIfIDsOfShippingOptionsAreDuplicated) {
ShouldResolveWithExceptionIfIDsOfShippingOptionsAreDuplicated) {
V8TestingScope scope;
PaymentRequestMockFunctionScope funcs(scope.GetScriptState());
MakePaymentRequestOriginSecure(scope.GetDocument());
......@@ -579,29 +579,10 @@ TEST(PaymentRequestTest,
details.setShippingOptions(shipping_options);
PaymentOptions options;
options.setRequestShipping(true);
PaymentRequest* request = PaymentRequest::Create(
scope.GetExecutionContext(), BuildPaymentMethodDataForTest(), details,
options, scope.GetExceptionState());
EXPECT_FALSE(scope.GetExceptionState().HadException());
EXPECT_TRUE(request->shippingOption().IsNull());
request->show(scope.GetScriptState())
.Then(funcs.ExpectNoCall(), funcs.ExpectNoCall());
String detail_with_shipping_options =
"{\"total\": {\"label\": \"Total\", \"amount\": {\"currency\": \"USD\", "
"\"value\": \"5.00\"}},"
"\"shippingOptions\": [{\"id\": \"standardShippingOption\", \"label\": "
"\"Standard shipping\", \"amount\": {\"currency\": \"USD\", \"value\": "
"\"5.00\"}, \"selected\": true}, {\"id\": \"standardShippingOption\", "
"\"label\": \"Standard shipping\", \"amount\": {\"currency\": \"USD\", "
"\"value\": \"5.00\"}, \"selected\": true}]}";
request->OnUpdatePaymentDetails(ScriptValue::From(
scope.GetScriptState(),
FromJSONString(scope.GetScriptState()->GetIsolate(),
detail_with_shipping_options, scope.GetExceptionState())));
EXPECT_FALSE(scope.GetExceptionState().HadException());
EXPECT_TRUE(request->shippingOption().IsNull());
PaymentRequest::Create(scope.GetExecutionContext(),
BuildPaymentMethodDataForTest(), details, options,
scope.GetExceptionState());
EXPECT_TRUE(scope.GetExceptionState().HadException());
}
TEST(PaymentRequestTest, DetailsIdIsSet) {
......
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