Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(604)

Unified Diff: third_party/WebKit/Source/modules/payments/MockPaymentRequest.cpp

Issue 1753543002: PaymentRequest Mojo bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@interface
Patch Set: Fix linking error Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f62cf9f8ee936af46a815c4bc2d92ab8b9465eea
--- /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, ModificaitonType modificaitonType, const String& valueToUse)
+{
+ CurrencyAmount itemAmount;
+ if (detail == DetailItem && data == DataCurrencyCode) {
+ if (modificaitonType == OverwriteValue)
+ itemAmount.setCurrencyCode(valueToUse);
+ } else {
+ itemAmount.setCurrencyCode("USD");
+ }
+ if (detail == DetailItem && data == DataAmount) {
+ if (modificaitonType == OverwriteValue)
+ itemAmount.setValue(valueToUse);
+ } else {
+ itemAmount.setValue("9.99");
+ }
+
+ PaymentItem item;
+ item.setAmount(itemAmount);
+ if (detail == DetailItem && data == DataId) {
+ if (modificaitonType == OverwriteValue)
+ item.setId(valueToUse);
+ } else {
+ item.setId("total");
+ }
+ if (detail == DetailItem && data == DataLabel) {
+ if (modificaitonType == OverwriteValue)
+ item.setLabel(valueToUse);
+ } else {
+ item.setLabel("Total charge");
+ }
+
+ CurrencyAmount shippingAmount;
+ if (detail == DetailShippingOption && data == DataCurrencyCode) {
+ if (modificaitonType == OverwriteValue)
+ shippingAmount.setCurrencyCode(valueToUse);
+ } else {
+ shippingAmount.setCurrencyCode("USD");
+ }
+ if (detail == DetailShippingOption && data == DataAmount) {
+ if (modificaitonType == OverwriteValue)
+ shippingAmount.setValue(valueToUse);
+ } else {
+ shippingAmount.setValue("9.99");
+ }
+
+ ShippingOption shippingOption;
+ shippingOption.setAmount(shippingAmount);
+ if (detail == DetailShippingOption && data == DataId) {
+ if (modificaitonType == OverwriteValue)
+ shippingOption.setId(valueToUse);
+ } else {
+ shippingOption.setId("standard");
+ }
+ if (detail == DetailShippingOption && data == DataLabel) {
+ if (modificaitonType == 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::_))
+ .WillByDefault(testing::ReturnPointee(&m_dummyPromise));
+}
+
+MockPaymentRequest::~MockPaymentRequest() {}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698