Chromium Code Reviews| Index: third_party/WebKit/Source/modules/payments/PaymentDetailsTestHelper.cpp |
| diff --git a/third_party/WebKit/Source/modules/payments/PaymentDetailsTestHelper.cpp b/third_party/WebKit/Source/modules/payments/PaymentDetailsTestHelper.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..be2f2721fcdf1db362cc429833855c5a4c505f68 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentDetailsTestHelper.cpp |
| @@ -0,0 +1,81 @@ |
| +// 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/PaymentDetailsTestHelper.h" |
| + |
| +#include "modules/payments/CurrencyAmount.h" |
| +#include "modules/payments/PaymentItem.h" |
| +#include "modules/payments/ShippingOption.h" |
| +#include "platform/heap/HeapAllocator.h" |
| + |
| +namespace blink { |
| + |
| +PaymentDetails buildPaymentDetailsForTest(PaymentTestDetailToChange detail, PaymentTestDataToChange data, PaymentTestModificationType modificationType, const String& valueToUse) |
|
Marijn Kruisselbrink
2016/03/31 18:21:14
What is the purpose of the modificationType parame
please use gerrit instead
2016/03/31 20:43:08
I specify both PaymentTestOverwriteValue and Payme
|
| +{ |
| + CurrencyAmount itemAmount; |
| + if (detail == PaymentTestDetailItem && data == PaymentTestDataCurrencyCode) { |
| + if (modificationType == PaymentTestOverwriteValue) |
| + itemAmount.setCurrencyCode(valueToUse); |
| + } else { |
| + itemAmount.setCurrencyCode("USD"); |
| + } |
| + if (detail == PaymentTestDetailItem && data == PaymentTestDataAmount) { |
| + if (modificationType == PaymentTestOverwriteValue) |
| + itemAmount.setValue(valueToUse); |
| + } else { |
| + itemAmount.setValue("9.99"); |
| + } |
| + |
| + PaymentItem item; |
| + item.setAmount(itemAmount); |
| + if (detail == PaymentTestDetailItem && data == PaymentTestDataId) { |
| + if (modificationType == PaymentTestOverwriteValue) |
| + item.setId(valueToUse); |
| + } else { |
| + item.setId("total"); |
| + } |
| + if (detail == PaymentTestDetailItem && data == PaymentTestDataLabel) { |
| + if (modificationType == PaymentTestOverwriteValue) |
| + item.setLabel(valueToUse); |
| + } else { |
| + item.setLabel("Total charge"); |
| + } |
| + |
| + CurrencyAmount shippingAmount; |
| + if (detail == PaymentTestDetailShippingOption && data == PaymentTestDataCurrencyCode) { |
| + if (modificationType == PaymentTestOverwriteValue) |
| + shippingAmount.setCurrencyCode(valueToUse); |
| + } else { |
| + shippingAmount.setCurrencyCode("USD"); |
| + } |
| + if (detail == PaymentTestDetailShippingOption && data == PaymentTestDataAmount) { |
| + if (modificationType == PaymentTestOverwriteValue) |
| + shippingAmount.setValue(valueToUse); |
| + } else { |
| + shippingAmount.setValue("9.99"); |
| + } |
| + |
| + ShippingOption shippingOption; |
| + shippingOption.setAmount(shippingAmount); |
| + if (detail == PaymentTestDetailShippingOption && data == PaymentTestDataId) { |
| + if (modificationType == PaymentTestOverwriteValue) |
| + shippingOption.setId(valueToUse); |
| + } else { |
| + shippingOption.setId("standard"); |
| + } |
| + if (detail == PaymentTestDetailShippingOption && data == PaymentTestDataLabel) { |
| + if (modificationType == PaymentTestOverwriteValue) |
| + shippingOption.setLabel(valueToUse); |
| + } else { |
| + shippingOption.setLabel("Standard shipping"); |
| + } |
| + |
| + PaymentDetails result; |
| + result.setItems(HeapVector<PaymentItem>(1, item)); |
| + result.setShippingOptions(HeapVector<ShippingOption>(2, shippingOption)); |
| + |
| + return result; |
| +} |
| + |
| +} // namespace blink |