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