Chromium Code Reviews| 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" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 original.setAmount(itemAmount); | 48 original.setAmount(itemAmount); |
| 49 | 49 |
| 50 if (data == PaymentTestDataLabel) { | 50 if (data == PaymentTestDataLabel) { |
| 51 if (modificationType == PaymentTestOverwriteValue) | 51 if (modificationType == PaymentTestOverwriteValue) |
| 52 original.setLabel(valueToUse); | 52 original.setLabel(valueToUse); |
| 53 } else { | 53 } else { |
| 54 original.setLabel("Label"); | 54 original.setLabel("Label"); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 void buildPaymentDetailsBaseInternal( | |
|
please use gerrit instead
2017/03/21 13:42:21
No need to use the "Internal" suffix. The "Base" w
zino
2017/03/22 16:43:45
Done.
| |
| 59 PaymentDetailsBase* details, | |
|
please use gerrit instead
2017/03/21 13:42:21
The output parameter should be the last one.
zino
2017/03/22 16:43:45
Done.
| |
| 60 PaymentTestDetailToChange detail, | |
| 61 PaymentTestDataToChange data, | |
| 62 PaymentTestModificationType modificationType, | |
| 63 const String& valueToUse) { | |
| 64 PaymentItem item; | |
| 65 if (detail == PaymentTestDetailItem) | |
| 66 item = buildPaymentItemForTest(data, modificationType, valueToUse); | |
| 67 else | |
| 68 item = buildPaymentItemForTest(); | |
| 69 | |
| 70 PaymentShippingOption shippingOption; | |
| 71 if (detail == PaymentTestDetailShippingOption) { | |
| 72 shippingOption = | |
| 73 buildShippingOptionForTest(data, modificationType, valueToUse); | |
| 74 } else { | |
| 75 shippingOption = buildShippingOptionForTest(); | |
| 76 } | |
| 77 | |
| 78 PaymentDetailsModifier modifier; | |
| 79 if (detail == PaymentTestDetailModifierTotal || | |
| 80 detail == PaymentTestDetailModifierItem) { | |
| 81 modifier = buildPaymentDetailsModifierForTest(detail, data, | |
| 82 modificationType, valueToUse); | |
| 83 } else { | |
| 84 modifier = buildPaymentDetailsModifierForTest(); | |
| 85 } | |
| 86 | |
| 87 details->setDisplayItems(HeapVector<PaymentItem>(1, item)); | |
| 88 details->setShippingOptions( | |
| 89 HeapVector<PaymentShippingOption>(1, shippingOption)); | |
| 90 details->setModifiers(HeapVector<PaymentDetailsModifier>(1, modifier)); | |
| 91 } | |
| 92 | |
| 58 } // namespace | 93 } // namespace |
| 59 | 94 |
| 60 PaymentItem buildPaymentItemForTest( | 95 PaymentItem buildPaymentItemForTest( |
| 61 PaymentTestDataToChange data, | 96 PaymentTestDataToChange data, |
| 62 PaymentTestModificationType modificationType, | 97 PaymentTestModificationType modificationType, |
| 63 const String& valueToUse) { | 98 const String& valueToUse) { |
| 64 DCHECK_NE(data, PaymentTestDataId); | 99 DCHECK_NE(data, PaymentTestDataId); |
| 65 PaymentItem item; | 100 PaymentItem item; |
| 66 setValues(item, data, modificationType, valueToUse); | 101 setValues(item, data, modificationType, valueToUse); |
| 67 return item; | 102 return item; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 else | 134 else |
| 100 item = buildPaymentItemForTest(); | 135 item = buildPaymentItemForTest(); |
| 101 | 136 |
| 102 PaymentDetailsModifier modifier; | 137 PaymentDetailsModifier modifier; |
| 103 modifier.setSupportedMethods(Vector<String>(1, "foo")); | 138 modifier.setSupportedMethods(Vector<String>(1, "foo")); |
| 104 modifier.setTotal(total); | 139 modifier.setTotal(total); |
| 105 modifier.setAdditionalDisplayItems(HeapVector<PaymentItem>(1, item)); | 140 modifier.setAdditionalDisplayItems(HeapVector<PaymentItem>(1, item)); |
| 106 return modifier; | 141 return modifier; |
| 107 } | 142 } |
| 108 | 143 |
| 109 PaymentDetails buildPaymentDetailsForTest( | 144 PaymentDetailsInit buildPaymentDetailsInitForTest( |
| 110 PaymentTestDetailToChange detail, | 145 PaymentTestDetailToChange detail, |
| 111 PaymentTestDataToChange data, | 146 PaymentTestDataToChange data, |
| 112 PaymentTestModificationType modificationType, | 147 PaymentTestModificationType modificationType, |
| 113 const String& valueToUse) { | 148 const String& valueToUse) { |
| 114 PaymentItem total; | 149 PaymentDetailsInit details; |
| 115 if (detail == PaymentTestDetailTotal) | 150 buildPaymentDetailsBaseInternal(&details, detail, data, modificationType, |
| 116 total = buildPaymentItemForTest(data, modificationType, valueToUse); | 151 valueToUse); |
| 117 else | |
| 118 total = buildPaymentItemForTest(); | |
| 119 | 152 |
| 120 PaymentItem item; | 153 if (detail == PaymentTestDetailTotal) { |
| 121 if (detail == PaymentTestDetailItem) | 154 details.setTotal( |
| 122 item = buildPaymentItemForTest(data, modificationType, valueToUse); | 155 buildPaymentItemForTest(data, modificationType, valueToUse)); |
| 123 else | 156 } else { |
| 124 item = buildPaymentItemForTest(); | 157 details.setTotal(buildPaymentItemForTest()); |
| 158 } | |
| 125 | 159 |
| 126 PaymentShippingOption shippingOption; | 160 return details; |
| 127 if (detail == PaymentTestDetailShippingOption) | 161 } |
| 128 shippingOption = | |
| 129 buildShippingOptionForTest(data, modificationType, valueToUse); | |
| 130 else | |
| 131 shippingOption = buildShippingOptionForTest(); | |
| 132 | 162 |
| 133 PaymentDetailsModifier modifier; | 163 PaymentDetailsUpdate buildPaymentDetailsUpdateForTest( |
| 134 if (detail == PaymentTestDetailModifierTotal || | 164 PaymentTestDetailToChange detail, |
| 135 detail == PaymentTestDetailModifierItem) | 165 PaymentTestDataToChange data, |
| 136 modifier = buildPaymentDetailsModifierForTest(detail, data, | 166 PaymentTestModificationType modificationType, |
| 137 modificationType, valueToUse); | 167 const String& valueToUse) { |
| 138 else | 168 PaymentDetailsUpdate details; |
| 139 modifier = buildPaymentDetailsModifierForTest(); | 169 buildPaymentDetailsBaseInternal(&details, detail, data, modificationType, |
| 170 valueToUse); | |
| 140 | 171 |
| 141 PaymentDetails result; | 172 if (detail == PaymentTestDetailTotal) { |
| 142 result.setTotal(total); | 173 details.setTotal( |
| 143 result.setDisplayItems(HeapVector<PaymentItem>(1, item)); | 174 buildPaymentItemForTest(data, modificationType, valueToUse)); |
| 144 result.setShippingOptions( | 175 } else { |
| 145 HeapVector<PaymentShippingOption>(1, shippingOption)); | 176 details.setTotal(buildPaymentItemForTest()); |
| 146 result.setModifiers(HeapVector<PaymentDetailsModifier>(1, modifier)); | 177 } |
| 147 | 178 |
| 148 if (detail == PaymentTestDetailError) | 179 if (detail == PaymentTestDetailError) |
| 149 result.setError(valueToUse); | 180 details.setError(valueToUse); |
| 150 | 181 |
| 151 return result; | 182 return details; |
| 152 } | 183 } |
| 153 | 184 |
| 154 PaymentDetails buildPaymentDetailsErrorMsgForTest(const String& valueToUse) { | 185 PaymentDetailsUpdate buildPaymentDetailsErrorMsgForTest( |
| 155 return buildPaymentDetailsForTest(PaymentTestDetailError, PaymentTestDataNone, | 186 const String& valueToUse) { |
| 156 PaymentTestOverwriteValue, valueToUse); | 187 return buildPaymentDetailsUpdateForTest( |
| 188 PaymentTestDetailError, PaymentTestDataNone, PaymentTestOverwriteValue, | |
| 189 valueToUse); | |
| 157 } | 190 } |
| 158 | 191 |
| 159 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() { | 192 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() { |
| 160 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); | 193 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); |
| 161 methodData[0].setSupportedMethods(Vector<String>(1, "foo")); | 194 methodData[0].setSupportedMethods(Vector<String>(1, "foo")); |
| 162 return methodData; | 195 return methodData; |
| 163 } | 196 } |
| 164 | 197 |
| 165 payments::mojom::blink::PaymentResponsePtr buildPaymentResponseForTest() { | 198 payments::mojom::blink::PaymentResponsePtr buildPaymentResponseForTest() { |
| 166 payments::mojom::blink::PaymentResponsePtr result = | 199 payments::mojom::blink::PaymentResponsePtr result = |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 ON_CALL(*this, call(testing::_)) | 255 ON_CALL(*this, call(testing::_)) |
| 223 .WillByDefault( | 256 .WillByDefault( |
| 224 testing::DoAll(SaveValueIn(m_value), testing::ReturnArg<0>())); | 257 testing::DoAll(SaveValueIn(m_value), testing::ReturnArg<0>())); |
| 225 } | 258 } |
| 226 | 259 |
| 227 v8::Local<v8::Function> PaymentRequestMockFunctionScope::MockFunction::bind() { | 260 v8::Local<v8::Function> PaymentRequestMockFunctionScope::MockFunction::bind() { |
| 228 return bindToV8Function(); | 261 return bindToV8Function(); |
| 229 } | 262 } |
| 230 | 263 |
| 231 } // namespace blink | 264 } // namespace blink |
| OLD | NEW |