Chromium Code Reviews| Index: third_party/WebKit/Source/modules/payments/PaymentAppRequestDataConversionTest.cpp |
| diff --git a/third_party/WebKit/Source/modules/payments/PaymentAppRequestDataConversionTest.cpp b/third_party/WebKit/Source/modules/payments/PaymentAppRequestDataConversionTest.cpp |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee915bb8f9ba91edec39250e737cc7d61a7c6031 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/payments/PaymentAppRequestDataConversionTest.cpp |
| @@ -0,0 +1,83 @@ |
| +// 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/PaymentAppRequestDataConversion.h" |
| + |
| +#include "bindings/core/v8/ScriptState.h" |
| +#include "bindings/core/v8/ScriptValue.h" |
| +#include "bindings/core/v8/V8Binding.h" |
| +#include "bindings/core/v8/V8BindingForTesting.h" |
| +#include "public/platform/modules/payments/WebPaymentAppRequestData.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace blink { |
| +namespace { |
| + |
| +static WebPaymentItem createWebPaymentItemForTest() { |
| + WebPaymentItem webItem; |
| + webItem.label = WebString::fromUTF8("Label"); |
| + webItem.amount.currency = WebString::fromUTF8("USD"); |
| + webItem.amount.value = WebString::fromUTF8("9.99"); |
| + return webItem; |
| +} |
| + |
| +static WebPaymentMethodData createWebPaymentMethodDataForTest() { |
| + WebPaymentMethodData webMethodData; |
| + webMethodData.supportedMethods = WebVector<WebString>(&"foo", 1); |
|
please use gerrit instead
2016/11/29 15:10:35
Eh, this is awkward. Can you do WebString::fromUTF
zino
2016/11/30 16:09:32
Done.
|
| + webMethodData.stringifiedData = "{\"merchantId\":\"12345\"}"; |
| + return webMethodData; |
| +} |
| + |
| +static WebPaymentAppRequestData createWebPaymentAppRequestDataForTest() { |
| + WebPaymentAppRequestData webData; |
| + webData.origin = WebString::fromUTF8("https://example.com"); |
| + Vector<WebPaymentMethodData> methodData; |
| + methodData.append(createWebPaymentMethodDataForTest()); |
| + webData.methodData = WebVector<WebPaymentMethodData>(methodData); |
| + webData.total = createWebPaymentItemForTest(); |
| + webData.optionId = WebString::fromUTF8("payment-app-id"); |
| + return webData; |
| +} |
| + |
| +TEST(PaymentAppRequestDataConversionTest, ToPaymentAppRequestData) { |
| + V8TestingScope scope; |
| + WebPaymentAppRequestData webData = createWebPaymentAppRequestDataForTest(); |
| + PaymentAppRequestData data = |
| + PaymentAppRequestDataConversion::toPaymentAppRequestData( |
| + scope.getScriptState(), webData); |
| + |
| + ASSERT_TRUE(data.hasMethodData()); |
| + ASSERT_EQ(1UL, data.methodData().size()); |
| + ASSERT_TRUE(data.methodData()[0].hasSupportedMethods()); |
|
please use gerrit instead
2016/11/29 15:10:35
It's easier to read .front() instead of [0]
zino
2016/11/30 16:09:32
Done.
|
| + ASSERT_EQ(1UL, data.methodData()[0].supportedMethods().size()); |
| + ASSERT_EQ("foo", data.methodData()[0].supportedMethods()[0]); |
| + ASSERT_TRUE(data.methodData()[0].hasData()); |
| + ASSERT_TRUE(data.methodData()[0].data().isObject()); |
| + String stringifiedData = v8StringToWebCoreString<String>( |
| + v8::JSON::Stringify( |
| + scope.context(), |
| + data.methodData()[0].data().v8Value().As<v8::Object>()) |
| + .ToLocalChecked(), |
| + DoNotExternalize); |
| + EXPECT_EQ("{\"merchantId\":\"12345\"}", stringifiedData); |
| + |
| + ASSERT_TRUE(data.hasTotal()); |
| + ASSERT_TRUE(data.total().hasLabel()); |
| + EXPECT_EQ("Label", data.total().label()); |
| + ASSERT_TRUE(data.total().hasAmount()); |
| + ASSERT_TRUE(data.total().amount().hasCurrency()); |
| + EXPECT_EQ("USD", data.total().amount().currency()); |
| + ASSERT_TRUE(data.total().amount().hasValue()); |
| + EXPECT_EQ("9.99", data.total().amount().value()); |
| + |
| + ASSERT_TRUE(data.hasOptionId()); |
| + EXPECT_EQ("payment-app-id", data.optionId()); |
| + |
| + ASSERT_TRUE(data.hasOrigin()); |
| + EXPECT_EQ("https://example.com", data.origin()); |
| +} |
| + |
| +} // namespace |
| +} // namespace blink |