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