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