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/PaymentTestHelper.h" | 5 #include "modules/payments/PaymentTestHelper.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
9 #include "modules/payments/PaymentCurrencyAmount.h" | 9 #include "modules/payments/PaymentCurrencyAmount.h" |
10 #include "modules/payments/PaymentMethodData.h" | 10 #include "modules/payments/PaymentMethodData.h" |
11 #include "platform/heap/HeapAllocator.h" | 11 #include "platform/heap/HeapAllocator.h" |
12 | 12 |
13 namespace blink { | 13 namespace blink { |
14 namespace { | 14 namespace { |
15 | 15 |
| 16 static int gUniqueId = 0; |
16 // PaymentItem and PaymentShippingOption have identical structure | 17 // PaymentItem and PaymentShippingOption have identical structure |
17 // except for the "id" field, which is present only in PaymentShippingOption. | 18 // except for the "id" field, which is present only in PaymentShippingOption. |
18 template <typename PaymentItemOrPaymentShippingOption> | 19 template <typename PaymentItemOrPaymentShippingOption> |
19 void setValues(PaymentItemOrPaymentShippingOption& original, PaymentTestDataToCh
ange data, PaymentTestModificationType modificationType, const String& valueToUs
e) | 20 void setValues(PaymentItemOrPaymentShippingOption& original, PaymentTestDataToCh
ange data, PaymentTestModificationType modificationType, const String& valueToUs
e) |
20 { | 21 { |
21 PaymentCurrencyAmount itemAmount; | 22 PaymentCurrencyAmount itemAmount; |
22 if (data == PaymentTestDataCurrencyCode) { | 23 if (data == PaymentTestDataCurrencyCode) { |
23 if (modificationType == PaymentTestOverwriteValue) | 24 if (modificationType == PaymentTestOverwriteValue) |
24 itemAmount.setCurrency(valueToUse); | 25 itemAmount.setCurrency(valueToUse); |
25 } else { | 26 } else { |
(...skipping 27 matching lines...) Expand all Loading... |
53 return item; | 54 return item; |
54 } | 55 } |
55 | 56 |
56 PaymentShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, P
aymentTestModificationType modificationType, const String& valueToUse) | 57 PaymentShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, P
aymentTestModificationType modificationType, const String& valueToUse) |
57 { | 58 { |
58 PaymentShippingOption shippingOption; | 59 PaymentShippingOption shippingOption; |
59 if (data == PaymentTestDataId) { | 60 if (data == PaymentTestDataId) { |
60 if (modificationType == PaymentTestOverwriteValue) | 61 if (modificationType == PaymentTestOverwriteValue) |
61 shippingOption.setId(valueToUse); | 62 shippingOption.setId(valueToUse); |
62 } else { | 63 } else { |
63 shippingOption.setId("id"); | 64 shippingOption.setId("id" + String::number(gUniqueId++)); |
64 } | 65 } |
65 setValues(shippingOption, data, modificationType, valueToUse); | 66 setValues(shippingOption, data, modificationType, valueToUse); |
66 return shippingOption; | 67 return shippingOption; |
67 } | 68 } |
68 | 69 |
69 PaymentDetailsModifier buildPaymentDetailsModifierForTest(PaymentTestDetailToCha
nge detail, PaymentTestDataToChange data, PaymentTestModificationType modificati
onType, const String& valueToUse) | 70 PaymentDetailsModifier buildPaymentDetailsModifierForTest(PaymentTestDetailToCha
nge detail, PaymentTestDataToChange data, PaymentTestModificationType modificati
onType, const String& valueToUse) |
70 { | 71 { |
71 PaymentItem total; | 72 PaymentItem total; |
72 if (detail == PaymentTestDetailModifierTotal) | 73 if (detail == PaymentTestDetailModifierTotal) |
73 total = buildPaymentItemForTest(data, modificationType, valueToUse); | 74 total = buildPaymentItemForTest(data, modificationType, valueToUse); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 110 |
110 PaymentDetailsModifier modifier; | 111 PaymentDetailsModifier modifier; |
111 if (detail == PaymentTestDetailModifierTotal || detail == PaymentTestDetailM
odifierItem) | 112 if (detail == PaymentTestDetailModifierTotal || detail == PaymentTestDetailM
odifierItem) |
112 modifier = buildPaymentDetailsModifierForTest(detail, data, modification
Type, valueToUse); | 113 modifier = buildPaymentDetailsModifierForTest(detail, data, modification
Type, valueToUse); |
113 else | 114 else |
114 modifier = buildPaymentDetailsModifierForTest(); | 115 modifier = buildPaymentDetailsModifierForTest(); |
115 | 116 |
116 PaymentDetails result; | 117 PaymentDetails result; |
117 result.setTotal(total); | 118 result.setTotal(total); |
118 result.setDisplayItems(HeapVector<PaymentItem>(1, item)); | 119 result.setDisplayItems(HeapVector<PaymentItem>(1, item)); |
119 result.setShippingOptions(HeapVector<PaymentShippingOption>(2, shippingOptio
n)); | 120 result.setShippingOptions(HeapVector<PaymentShippingOption>(1, shippingOptio
n)); |
120 result.setModifiers(HeapVector<PaymentDetailsModifier>(1, modifier)); | 121 result.setModifiers(HeapVector<PaymentDetailsModifier>(1, modifier)); |
121 | 122 |
122 return result; | 123 return result; |
123 } | 124 } |
124 | 125 |
125 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() | 126 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() |
126 { | 127 { |
127 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); | 128 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); |
128 methodData[0].setSupportedMethods(Vector<String>(1, "foo")); | 129 methodData[0].setSupportedMethods(Vector<String>(1, "foo")); |
129 return methodData; | 130 return methodData; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 { | 173 { |
173 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); | 174 ON_CALL(*this, call(testing::_)).WillByDefault(testing::ReturnArg<0>()); |
174 } | 175 } |
175 | 176 |
176 v8::Local<v8::Function> PaymentRequestMockFunctionScope::MockFunction::bind() | 177 v8::Local<v8::Function> PaymentRequestMockFunctionScope::MockFunction::bind() |
177 { | 178 { |
178 return bindToV8Function(); | 179 return bindToV8Function(); |
179 } | 180 } |
180 | 181 |
181 } // namespace blink | 182 } // namespace blink |
OLD | NEW |