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