Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: components/payments/content/payment_details_validation.cc

Issue 2851383002: Verify behavior of PaymentRequest constructor. (Closed)
Patch Set: Comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/external/wpt/payment-request/payment-request-constructor.https.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/payments/content/payment_details_validation.h" 5 #include "components/payments/content/payment_details_validation.h"
6 6
7 #include <set> 7 #include <set>
8 #include <vector> 8 #include <vector>
9 9
10 #include "components/payments/content/payments_validators.h" 10 #include "components/payments/content/payments_validators.h"
11 #include "components/payments/mojom/payment_request.mojom.h" 11 #include "components/payments/mojom/payment_request.mojom.h"
12 12
13 namespace payments { 13 namespace payments {
14 namespace { 14 namespace {
15 15
16 // Validates ShippingOption or PaymentItem, which happen to have identical 16 // Validates ShippingOption or PaymentItem, which happen to have identical
17 // fields, except for "id", which is present only in ShippingOption. 17 // fields, except for "id", which is present only in ShippingOption.
18 template <typename T> 18 template <typename T>
19 bool validateShippingOptionOrPaymentItem( 19 bool validateShippingOptionOrPaymentItem(
20 const T& item, 20 const T& item,
21 const payments::mojom::PaymentItemPtr& total, 21 const payments::mojom::PaymentItemPtr& total,
22 std::string* error_message) { 22 std::string* error_message) {
23 if (item->label.empty()) {
24 *error_message = "Item label required";
25 return false;
26 }
27
28 if (!item->amount) { 23 if (!item->amount) {
29 *error_message = "Currency amount required"; 24 *error_message = "Currency amount required";
30 return false; 25 return false;
31 } 26 }
32 27
33 if (item->amount->currency.empty()) { 28 if (item->amount->currency.empty()) {
34 *error_message = "Currency code required"; 29 *error_message = "Currency code required";
35 return false; 30 return false;
36 } 31 }
37 32
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 if (!validatePaymentDetailsModifiers(details->modifiers, details->total, 164 if (!validatePaymentDetailsModifiers(details->modifiers, details->total,
170 error_message)) 165 error_message))
171 return false; 166 return false;
172 } 167 }
173 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message)) 168 if (!PaymentsValidators::isValidErrorMsgFormat(details->error, error_message))
174 return false; 169 return false;
175 return true; 170 return true;
176 } 171 }
177 172
178 } // namespace payments 173 } // namespace payments
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/external/wpt/payment-request/payment-request-constructor.https.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698