| 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 "modules/payments/CurrencyAmount.h" | 7 #include "modules/payments/PaymentCurrencyAmount.h" |
| 8 #include "platform/heap/HeapAllocator.h" | 8 #include "platform/heap/HeapAllocator.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // PaymentItem and ShippingOption have identical structure | 13 // PaymentItem and PaymentShippingOption have identical structure |
| 14 // except for the "id" field, which is present only in ShippingOption. | 14 // except for the "id" field, which is present only in PaymentShippingOption. |
| 15 template <typename PaymentItemOrShippingOption> | 15 template <typename PaymentItemOrPaymentShippingOption> |
| 16 void setValues(PaymentItemOrShippingOption& original, PaymentTestDataToChange da
ta, PaymentTestModificationType modificationType, const String& valueToUse) | 16 void setValues(PaymentItemOrPaymentShippingOption& original, PaymentTestDataToCh
ange data, PaymentTestModificationType modificationType, const String& valueToUs
e) |
| 17 { | 17 { |
| 18 CurrencyAmount itemAmount; | 18 PaymentCurrencyAmount itemAmount; |
| 19 if (data == PaymentTestDataCurrencyCode) { | 19 if (data == PaymentTestDataCurrencyCode) { |
| 20 if (modificationType == PaymentTestOverwriteValue) | 20 if (modificationType == PaymentTestOverwriteValue) |
| 21 itemAmount.setCurrency(valueToUse); | 21 itemAmount.setCurrency(valueToUse); |
| 22 } else { | 22 } else { |
| 23 itemAmount.setCurrency("USD"); | 23 itemAmount.setCurrency("USD"); |
| 24 } | 24 } |
| 25 if (data == PaymentTestDataValue) { | 25 if (data == PaymentTestDataValue) { |
| 26 if (modificationType == PaymentTestOverwriteValue) | 26 if (modificationType == PaymentTestOverwriteValue) |
| 27 itemAmount.setValue(valueToUse); | 27 itemAmount.setValue(valueToUse); |
| 28 } else { | 28 } else { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 PaymentItem buildPaymentItemForTest(PaymentTestDataToChange data, PaymentTestMod
ificationType modificationType, const String& valueToUse) | 45 PaymentItem buildPaymentItemForTest(PaymentTestDataToChange data, PaymentTestMod
ificationType modificationType, const String& valueToUse) |
| 46 { | 46 { |
| 47 DCHECK_NE(data, PaymentTestDataId); | 47 DCHECK_NE(data, PaymentTestDataId); |
| 48 PaymentItem item; | 48 PaymentItem item; |
| 49 setValues(item, data, modificationType, valueToUse); | 49 setValues(item, data, modificationType, valueToUse); |
| 50 return item; | 50 return item; |
| 51 } | 51 } |
| 52 | 52 |
| 53 ShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, PaymentT
estModificationType modificationType, const String& valueToUse) | 53 PaymentShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, P
aymentTestModificationType modificationType, const String& valueToUse) |
| 54 { | 54 { |
| 55 ShippingOption shippingOption; | 55 PaymentShippingOption shippingOption; |
| 56 if (data == PaymentTestDataId) { | 56 if (data == PaymentTestDataId) { |
| 57 if (modificationType == PaymentTestOverwriteValue) | 57 if (modificationType == PaymentTestOverwriteValue) |
| 58 shippingOption.setId(valueToUse); | 58 shippingOption.setId(valueToUse); |
| 59 } else { | 59 } else { |
| 60 shippingOption.setId("id"); | 60 shippingOption.setId("id"); |
| 61 } | 61 } |
| 62 setValues(shippingOption, data, modificationType, valueToUse); | 62 setValues(shippingOption, data, modificationType, valueToUse); |
| 63 return shippingOption; | 63 return shippingOption; |
| 64 } | 64 } |
| 65 | 65 |
| 66 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym
entTestDataToChange data, PaymentTestModificationType modificationType, const St
ring& valueToUse) | 66 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym
entTestDataToChange data, PaymentTestModificationType modificationType, const St
ring& valueToUse) |
| 67 { | 67 { |
| 68 PaymentItem total; | 68 PaymentItem total; |
| 69 if (detail == PaymentTestDetailTotal) | 69 if (detail == PaymentTestDetailTotal) |
| 70 total = buildPaymentItemForTest(data, modificationType, valueToUse); | 70 total = buildPaymentItemForTest(data, modificationType, valueToUse); |
| 71 else | 71 else |
| 72 total = buildPaymentItemForTest(); | 72 total = buildPaymentItemForTest(); |
| 73 | 73 |
| 74 PaymentItem item; | 74 PaymentItem item; |
| 75 if (detail == PaymentTestDetailItem) | 75 if (detail == PaymentTestDetailItem) |
| 76 item = buildPaymentItemForTest(data, modificationType, valueToUse); | 76 item = buildPaymentItemForTest(data, modificationType, valueToUse); |
| 77 else | 77 else |
| 78 item = buildPaymentItemForTest(); | 78 item = buildPaymentItemForTest(); |
| 79 | 79 |
| 80 ShippingOption shippingOption; | 80 PaymentShippingOption shippingOption; |
| 81 if (detail == PaymentTestDetailShippingOption) | 81 if (detail == PaymentTestDetailShippingOption) |
| 82 shippingOption = buildShippingOptionForTest(data, modificationType, valu
eToUse); | 82 shippingOption = buildShippingOptionForTest(data, modificationType, valu
eToUse); |
| 83 else | 83 else |
| 84 shippingOption = buildShippingOptionForTest(); | 84 shippingOption = buildShippingOptionForTest(); |
| 85 | 85 |
| 86 PaymentDetails result; | 86 PaymentDetails result; |
| 87 result.setTotal(total); | 87 result.setTotal(total); |
| 88 result.setDisplayItems(HeapVector<PaymentItem>(1, item)); | 88 result.setDisplayItems(HeapVector<PaymentItem>(1, item)); |
| 89 result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); | 89 result.setShippingOptions(HeapVector<PaymentShippingOption>(2, shippingOptio
n)); |
| 90 | 90 |
| 91 return result; | 91 return result; |
| 92 } | 92 } |
| 93 | 93 |
| 94 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() | 94 HeapVector<PaymentMethodData> buildPaymentMethodDataForTest() |
| 95 { | 95 { |
| 96 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); | 96 HeapVector<PaymentMethodData> methodData(1, PaymentMethodData()); |
| 97 methodData[0].setSupportedMethods(Vector<String>(1, "foo")); | 97 methodData[0].setSupportedMethods(Vector<String>(1, "foo")); |
| 98 return methodData; | 98 return methodData; |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace blink | 101 } // namespace blink |
| OLD | NEW |