OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "modules/payments/PaymentDetailsTestHelper.h" | |
6 | |
7 #include "modules/payments/CurrencyAmount.h" | |
8 #include "platform/heap/HeapAllocator.h" | |
9 | |
10 namespace blink { | |
11 namespace { | |
12 | |
13 // PaymentItem and ShippingOption have identical structure | |
14 // except for the "id" field, which is present only in ShippingOption. | |
15 template <typename PaymentItemOrShippingOption> | |
16 void setValues(PaymentItemOrShippingOption& original, PaymentTestDataToChange da
ta, PaymentTestModificationType modificationType, const String& valueToUse) | |
17 { | |
18 CurrencyAmount itemAmount; | |
19 if (data == PaymentTestDataCurrencyCode) { | |
20 if (modificationType == PaymentTestOverwriteValue) | |
21 itemAmount.setCurrency(valueToUse); | |
22 } else { | |
23 itemAmount.setCurrency("USD"); | |
24 } | |
25 if (data == PaymentTestDataValue) { | |
26 if (modificationType == PaymentTestOverwriteValue) | |
27 itemAmount.setValue(valueToUse); | |
28 } else { | |
29 itemAmount.setValue("9.99"); | |
30 } | |
31 | |
32 if (data != PaymentTestDataAmount || modificationType != PaymentTestRemoveKe
y) | |
33 original.setAmount(itemAmount); | |
34 | |
35 if (data == PaymentTestDataLabel) { | |
36 if (modificationType == PaymentTestOverwriteValue) | |
37 original.setLabel(valueToUse); | |
38 } else { | |
39 original.setLabel("Label"); | |
40 } | |
41 } | |
42 | |
43 } // namespace | |
44 | |
45 PaymentItem buildPaymentItemForTest(PaymentTestDataToChange data, PaymentTestMod
ificationType modificationType, const String& valueToUse) | |
46 { | |
47 DCHECK_NE(data, PaymentTestDataId); | |
48 PaymentItem item; | |
49 setValues(item, data, modificationType, valueToUse); | |
50 return item; | |
51 } | |
52 | |
53 ShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, PaymentT
estModificationType modificationType, const String& valueToUse) | |
54 { | |
55 ShippingOption shippingOption; | |
56 if (data == PaymentTestDataId) { | |
57 if (modificationType == PaymentTestOverwriteValue) | |
58 shippingOption.setId(valueToUse); | |
59 } else { | |
60 shippingOption.setId("id"); | |
61 } | |
62 setValues(shippingOption, data, modificationType, valueToUse); | |
63 return shippingOption; | |
64 } | |
65 | |
66 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym
entTestDataToChange data, PaymentTestModificationType modificationType, const St
ring& valueToUse) | |
67 { | |
68 PaymentItem total; | |
69 if (detail == PaymentTestDetailTotal) | |
70 total = buildPaymentItemForTest(data, modificationType, valueToUse); | |
71 else | |
72 total = buildPaymentItemForTest(); | |
73 | |
74 PaymentItem item; | |
75 if (detail == PaymentTestDetailItem) | |
76 item = buildPaymentItemForTest(data, modificationType, valueToUse); | |
77 else | |
78 item = buildPaymentItemForTest(); | |
79 | |
80 ShippingOption shippingOption; | |
81 if (detail == PaymentTestDetailShippingOption) | |
82 shippingOption = buildShippingOptionForTest(data, modificationType, valu
eToUse); | |
83 else | |
84 shippingOption = buildShippingOptionForTest(); | |
85 | |
86 PaymentDetails result; | |
87 result.setTotal(total); | |
88 result.setDisplayItems(HeapVector<PaymentItem>(1, item)); | |
89 result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); | |
90 | |
91 return result; | |
92 } | |
93 | |
94 } // namespace blink | |
OLD | NEW |