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/MockPaymentRequest.h" |
| 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "modules/payments/CurrencyAmount.h" |
| 10 #include "modules/payments/PaymentDetails.h" |
| 11 #include "modules/payments/PaymentItem.h" |
| 12 #include "modules/payments/PaymentOptions.h" |
| 13 #include "platform/heap/HeapAllocator.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 PaymentDetails MockPaymentRequest::buildDetails(DetailToChange detail, DataToCha
nge data, ModificaitonType modificaitonType, const String& valueToUse) |
| 18 { |
| 19 CurrencyAmount itemAmount; |
| 20 if (detail == DetailItem && data == DataCurrencyCode) { |
| 21 if (modificaitonType == OverwriteValue) |
| 22 itemAmount.setCurrencyCode(valueToUse); |
| 23 } else { |
| 24 itemAmount.setCurrencyCode("USD"); |
| 25 } |
| 26 if (detail == DetailItem && data == DataAmount) { |
| 27 if (modificaitonType == OverwriteValue) |
| 28 itemAmount.setValue(valueToUse); |
| 29 } else { |
| 30 itemAmount.setValue("9.99"); |
| 31 } |
| 32 |
| 33 PaymentItem item; |
| 34 item.setAmount(itemAmount); |
| 35 if (detail == DetailItem && data == DataId) { |
| 36 if (modificaitonType == OverwriteValue) |
| 37 item.setId(valueToUse); |
| 38 } else { |
| 39 item.setId("total"); |
| 40 } |
| 41 if (detail == DetailItem && data == DataLabel) { |
| 42 if (modificaitonType == OverwriteValue) |
| 43 item.setLabel(valueToUse); |
| 44 } else { |
| 45 item.setLabel("Total charge"); |
| 46 } |
| 47 |
| 48 CurrencyAmount shippingAmount; |
| 49 if (detail == DetailShippingOption && data == DataCurrencyCode) { |
| 50 if (modificaitonType == OverwriteValue) |
| 51 shippingAmount.setCurrencyCode(valueToUse); |
| 52 } else { |
| 53 shippingAmount.setCurrencyCode("USD"); |
| 54 } |
| 55 if (detail == DetailShippingOption && data == DataAmount) { |
| 56 if (modificaitonType == OverwriteValue) |
| 57 shippingAmount.setValue(valueToUse); |
| 58 } else { |
| 59 shippingAmount.setValue("9.99"); |
| 60 } |
| 61 |
| 62 ShippingOption shippingOption; |
| 63 shippingOption.setAmount(shippingAmount); |
| 64 if (detail == DetailShippingOption && data == DataId) { |
| 65 if (modificaitonType == OverwriteValue) |
| 66 shippingOption.setId(valueToUse); |
| 67 } else { |
| 68 shippingOption.setId("standard"); |
| 69 } |
| 70 if (detail == DetailShippingOption && data == DataLabel) { |
| 71 if (modificaitonType == OverwriteValue) |
| 72 shippingOption.setLabel(valueToUse); |
| 73 } else { |
| 74 shippingOption.setLabel("Standard shipping"); |
| 75 } |
| 76 |
| 77 PaymentDetails result; |
| 78 result.setItems(HeapVector<PaymentItem>(1, item)); |
| 79 result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); |
| 80 |
| 81 return result; |
| 82 } |
| 83 |
| 84 MockPaymentRequest::MockPaymentRequest(ScriptState* scriptState, const Vector<St
ring>& supportedMethods, const PaymentDetails& paymentDetails, ExceptionState& e
xceptionState) |
| 85 : PaymentRequest(scriptState, supportedMethods, paymentDetails, PaymentOptio
ns(), ScriptValue(), exceptionState) |
| 86 { |
| 87 ON_CALL(*this, complete(testing::_, testing::_)) |
| 88 .WillByDefault(testing::ReturnPointee(&m_dummyPromise)); |
| 89 } |
| 90 |
| 91 MockPaymentRequest::~MockPaymentRequest() {} |
| 92 |
| 93 } // namespace blink |
OLD | NEW |