Index: third_party/WebKit/Source/modules/payments/MockPaymentRequest.cpp |
diff --git a/third_party/WebKit/Source/modules/payments/MockPaymentRequest.cpp b/third_party/WebKit/Source/modules/payments/MockPaymentRequest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2be2487f31acccde0c14f9c38e7628748c7022a3 |
--- /dev/null |
+++ b/third_party/WebKit/Source/modules/payments/MockPaymentRequest.cpp |
@@ -0,0 +1,93 @@ |
+// Copyright 2016 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "modules/payments/MockPaymentRequest.h" |
+ |
+#include "bindings/core/v8/ExceptionState.h" |
+#include "bindings/core/v8/ScriptState.h" |
+#include "modules/payments/CurrencyAmount.h" |
+#include "modules/payments/PaymentDetails.h" |
+#include "modules/payments/PaymentItem.h" |
+#include "modules/payments/PaymentOptions.h" |
+#include "platform/heap/HeapAllocator.h" |
+ |
+namespace blink { |
+ |
+PaymentDetails MockPaymentRequest::buildDetails(DetailToChange detail, DataToChange data, ModificationType modificationType, const String& valueToUse) |
+{ |
+ CurrencyAmount itemAmount; |
+ if (detail == DetailItem && data == DataCurrencyCode) { |
+ if (modificationType == OverwriteValue) |
+ itemAmount.setCurrencyCode(valueToUse); |
+ } else { |
+ itemAmount.setCurrencyCode("USD"); |
+ } |
+ if (detail == DetailItem && data == DataAmount) { |
+ if (modificationType == OverwriteValue) |
+ itemAmount.setValue(valueToUse); |
+ } else { |
+ itemAmount.setValue("9.99"); |
+ } |
+ |
+ PaymentItem item; |
+ item.setAmount(itemAmount); |
+ if (detail == DetailItem && data == DataId) { |
+ if (modificationType == OverwriteValue) |
+ item.setId(valueToUse); |
+ } else { |
+ item.setId("total"); |
+ } |
+ if (detail == DetailItem && data == DataLabel) { |
+ if (modificationType == OverwriteValue) |
+ item.setLabel(valueToUse); |
+ } else { |
+ item.setLabel("Total charge"); |
+ } |
+ |
+ CurrencyAmount shippingAmount; |
+ if (detail == DetailShippingOption && data == DataCurrencyCode) { |
+ if (modificationType == OverwriteValue) |
+ shippingAmount.setCurrencyCode(valueToUse); |
+ } else { |
+ shippingAmount.setCurrencyCode("USD"); |
+ } |
+ if (detail == DetailShippingOption && data == DataAmount) { |
+ if (modificationType == OverwriteValue) |
+ shippingAmount.setValue(valueToUse); |
+ } else { |
+ shippingAmount.setValue("9.99"); |
+ } |
+ |
+ ShippingOption shippingOption; |
+ shippingOption.setAmount(shippingAmount); |
+ if (detail == DetailShippingOption && data == DataId) { |
+ if (modificationType == OverwriteValue) |
+ shippingOption.setId(valueToUse); |
+ } else { |
+ shippingOption.setId("standard"); |
+ } |
+ if (detail == DetailShippingOption && data == DataLabel) { |
+ if (modificationType == OverwriteValue) |
+ shippingOption.setLabel(valueToUse); |
+ } else { |
+ shippingOption.setLabel("Standard shipping"); |
+ } |
+ |
+ PaymentDetails result; |
+ result.setItems(HeapVector<PaymentItem>(1, item)); |
+ result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); |
+ |
+ return result; |
+} |
+ |
+MockPaymentRequest::MockPaymentRequest(ScriptState* scriptState, const Vector<String>& supportedMethods, const PaymentDetails& paymentDetails, ExceptionState& exceptionState) |
+ : PaymentRequest(scriptState, supportedMethods, paymentDetails, PaymentOptions(), ScriptValue(), exceptionState) |
+{ |
+ ON_CALL(*this, complete(testing::_, testing::_)) |
esprehn
2016/03/25 23:48:39
Yeah I really think we want to either mock some pu
please use gerrit instead
2016/03/29 22:15:45
Done.
|
+ .WillByDefault(testing::ReturnPointee(&m_dummyPromise)); |
+} |
+ |
+MockPaymentRequest::~MockPaymentRequest() {} |
+ |
+} // namespace blink |