| 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/PaymentDetailsTestHelper.h" | 5 #include "modules/payments/PaymentDetailsTestHelper.h" |
| 6 | 6 |
| 7 #include "modules/payments/CurrencyAmount.h" | 7 #include "modules/payments/CurrencyAmount.h" |
| 8 #include "modules/payments/PaymentItem.h" | |
| 9 #include "modules/payments/ShippingOption.h" | |
| 10 #include "platform/heap/HeapAllocator.h" | 8 #include "platform/heap/HeapAllocator.h" |
| 11 | 9 |
| 12 namespace blink { | 10 namespace blink { |
| 13 | 11 |
| 14 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym
entTestDataToChange data, PaymentTestModificationType modificationType, const St
ring& valueToUse) | 12 PaymentItem buildPaymentItemForTest(PaymentTestDataToChange data, PaymentTestMod
ificationType modificationType, const String& valueToUse) |
| 15 { | 13 { |
| 16 CurrencyAmount itemAmount; | 14 CurrencyAmount itemAmount; |
| 17 if (detail == PaymentTestDetailItem && data == PaymentTestDataCurrencyCode)
{ | 15 if (data == PaymentTestDataCurrencyCode) { |
| 18 if (modificationType == PaymentTestOverwriteValue) | 16 if (modificationType == PaymentTestOverwriteValue) |
| 19 itemAmount.setCurrencyCode(valueToUse); | 17 itemAmount.setCurrencyCode(valueToUse); |
| 20 } else { | 18 } else { |
| 21 itemAmount.setCurrencyCode("USD"); | 19 itemAmount.setCurrencyCode("USD"); |
| 22 } | 20 } |
| 23 if (detail == PaymentTestDetailItem && data == PaymentTestDataAmount) { | 21 if (data == PaymentTestDataAmount) { |
| 24 if (modificationType == PaymentTestOverwriteValue) | 22 if (modificationType == PaymentTestOverwriteValue) |
| 25 itemAmount.setValue(valueToUse); | 23 itemAmount.setValue(valueToUse); |
| 26 } else { | 24 } else { |
| 27 itemAmount.setValue("9.99"); | 25 itemAmount.setValue("9.99"); |
| 28 } | 26 } |
| 29 | 27 |
| 30 PaymentItem item; | 28 PaymentItem item; |
| 31 item.setAmount(itemAmount); | 29 item.setAmount(itemAmount); |
| 32 if (detail == PaymentTestDetailItem && data == PaymentTestDataId) { | 30 if (data == PaymentTestDataId) { |
| 33 if (modificationType == PaymentTestOverwriteValue) | 31 if (modificationType == PaymentTestOverwriteValue) |
| 34 item.setId(valueToUse); | 32 item.setId(valueToUse); |
| 35 } else { | 33 } else { |
| 36 item.setId("total"); | 34 item.setId("total"); |
| 37 } | 35 } |
| 38 if (detail == PaymentTestDetailItem && data == PaymentTestDataLabel) { | 36 if (data == PaymentTestDataLabel) { |
| 39 if (modificationType == PaymentTestOverwriteValue) | 37 if (modificationType == PaymentTestOverwriteValue) |
| 40 item.setLabel(valueToUse); | 38 item.setLabel(valueToUse); |
| 41 } else { | 39 } else { |
| 42 item.setLabel("Total charge"); | 40 item.setLabel("Total charge"); |
| 43 } | 41 } |
| 44 | 42 |
| 43 return item; |
| 44 } |
| 45 |
| 46 ShippingOption buildShippingOptionForTest(PaymentTestDataToChange data, PaymentT
estModificationType modificationType, const String& valueToUse) |
| 47 { |
| 45 CurrencyAmount shippingAmount; | 48 CurrencyAmount shippingAmount; |
| 46 if (detail == PaymentTestDetailShippingOption && data == PaymentTestDataCurr
encyCode) { | 49 if (data == PaymentTestDataCurrencyCode) { |
| 47 if (modificationType == PaymentTestOverwriteValue) | 50 if (modificationType == PaymentTestOverwriteValue) |
| 48 shippingAmount.setCurrencyCode(valueToUse); | 51 shippingAmount.setCurrencyCode(valueToUse); |
| 49 } else { | 52 } else { |
| 50 shippingAmount.setCurrencyCode("USD"); | 53 shippingAmount.setCurrencyCode("USD"); |
| 51 } | 54 } |
| 52 if (detail == PaymentTestDetailShippingOption && data == PaymentTestDataAmou
nt) { | 55 if (data == PaymentTestDataAmount) { |
| 53 if (modificationType == PaymentTestOverwriteValue) | 56 if (modificationType == PaymentTestOverwriteValue) |
| 54 shippingAmount.setValue(valueToUse); | 57 shippingAmount.setValue(valueToUse); |
| 55 } else { | 58 } else { |
| 56 shippingAmount.setValue("9.99"); | 59 shippingAmount.setValue("9.99"); |
| 57 } | 60 } |
| 58 | 61 |
| 59 ShippingOption shippingOption; | 62 ShippingOption shippingOption; |
| 60 shippingOption.setAmount(shippingAmount); | 63 shippingOption.setAmount(shippingAmount); |
| 61 if (detail == PaymentTestDetailShippingOption && data == PaymentTestDataId)
{ | 64 if (data == PaymentTestDataId) { |
| 62 if (modificationType == PaymentTestOverwriteValue) | 65 if (modificationType == PaymentTestOverwriteValue) |
| 63 shippingOption.setId(valueToUse); | 66 shippingOption.setId(valueToUse); |
| 64 } else { | 67 } else { |
| 65 shippingOption.setId("standard"); | 68 shippingOption.setId("standard"); |
| 66 } | 69 } |
| 67 if (detail == PaymentTestDetailShippingOption && data == PaymentTestDataLabe
l) { | 70 if (data == PaymentTestDataLabel) { |
| 68 if (modificationType == PaymentTestOverwriteValue) | 71 if (modificationType == PaymentTestOverwriteValue) |
| 69 shippingOption.setLabel(valueToUse); | 72 shippingOption.setLabel(valueToUse); |
| 70 } else { | 73 } else { |
| 71 shippingOption.setLabel("Standard shipping"); | 74 shippingOption.setLabel("Standard shipping"); |
| 72 } | 75 } |
| 73 | 76 |
| 77 return shippingOption; |
| 78 } |
| 79 |
| 80 PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, Paym
entTestDataToChange data, PaymentTestModificationType modificationType, const St
ring& valueToUse) |
| 81 { |
| 82 |
| 83 PaymentItem item; |
| 84 if (detail == PaymentTestDetailItem) |
| 85 item = buildPaymentItemForTest(data, modificationType, valueToUse); |
| 86 else |
| 87 item = buildPaymentItemForTest(); |
| 88 |
| 89 ShippingOption shippingOption; |
| 90 if (detail == PaymentTestDetailShippingOption) |
| 91 shippingOption = buildShippingOptionForTest(data, modificationType, valu
eToUse); |
| 92 else |
| 93 shippingOption = buildShippingOptionForTest(); |
| 94 |
| 74 PaymentDetails result; | 95 PaymentDetails result; |
| 75 result.setItems(HeapVector<PaymentItem>(1, item)); | 96 result.setItems(HeapVector<PaymentItem>(1, item)); |
| 76 result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); | 97 result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); |
| 77 | 98 |
| 78 return result; | 99 return result; |
| 79 } | 100 } |
| 80 | 101 |
| 81 } // namespace blink | 102 } // namespace blink |
| OLD | NEW |