| 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/PaymentAppRequestDataConversion.h" | |
| 6 | |
| 7 #include "bindings/core/v8/ScriptState.h" | |
| 8 #include "bindings/core/v8/ScriptValue.h" | |
| 9 #include "bindings/core/v8/V8Binding.h" | |
| 10 #include "bindings/core/v8/V8BindingForTesting.h" | |
| 11 #include "public/platform/modules/payments/WebPaymentAppRequestData.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace blink { | |
| 16 namespace { | |
| 17 | |
| 18 static WebPaymentItem createWebPaymentItemForTest() { | |
| 19 WebPaymentItem webItem; | |
| 20 webItem.label = WebString::fromUTF8("Label"); | |
| 21 webItem.amount.currency = WebString::fromUTF8("USD"); | |
| 22 webItem.amount.value = WebString::fromUTF8("9.99"); | |
| 23 return webItem; | |
| 24 } | |
| 25 | |
| 26 static WebPaymentMethodData createWebPaymentMethodDataForTest() { | |
| 27 WebPaymentMethodData webMethodData; | |
| 28 WebString method = WebString::fromUTF8("foo"); | |
| 29 webMethodData.supportedMethods = WebVector<WebString>(&method, 1); | |
| 30 webMethodData.stringifiedData = "{\"merchantId\":\"12345\"}"; | |
| 31 return webMethodData; | |
| 32 } | |
| 33 | |
| 34 static WebPaymentAppRequestData createWebPaymentAppRequestDataForTest() { | |
| 35 WebPaymentAppRequestData webData; | |
| 36 webData.origin = WebString::fromUTF8("https://example.com"); | |
| 37 Vector<WebPaymentMethodData> methodData; | |
| 38 methodData.push_back(createWebPaymentMethodDataForTest()); | |
| 39 webData.methodData = WebVector<WebPaymentMethodData>(methodData); | |
| 40 webData.total = createWebPaymentItemForTest(); | |
| 41 webData.optionId = WebString::fromUTF8("payment-app-id"); | |
| 42 return webData; | |
| 43 } | |
| 44 | |
| 45 TEST(PaymentAppRequestDataConversionTest, ToPaymentAppRequestData) { | |
| 46 V8TestingScope scope; | |
| 47 WebPaymentAppRequestData webData = createWebPaymentAppRequestDataForTest(); | |
| 48 PaymentAppRequestData data = | |
| 49 PaymentAppRequestDataConversion::toPaymentAppRequestData( | |
| 50 scope.getScriptState(), webData); | |
| 51 | |
| 52 ASSERT_TRUE(data.hasMethodData()); | |
| 53 ASSERT_EQ(1UL, data.methodData().size()); | |
| 54 ASSERT_TRUE(data.methodData().front().hasSupportedMethods()); | |
| 55 ASSERT_EQ(1UL, data.methodData().front().supportedMethods().size()); | |
| 56 ASSERT_EQ("foo", data.methodData().front().supportedMethods().front()); | |
| 57 ASSERT_TRUE(data.methodData().front().hasData()); | |
| 58 ASSERT_TRUE(data.methodData().front().data().isObject()); | |
| 59 String stringifiedData = v8StringToWebCoreString<String>( | |
| 60 v8::JSON::Stringify( | |
| 61 scope.context(), | |
| 62 data.methodData().front().data().v8Value().As<v8::Object>()) | |
| 63 .ToLocalChecked(), | |
| 64 DoNotExternalize); | |
| 65 EXPECT_EQ("{\"merchantId\":\"12345\"}", stringifiedData); | |
| 66 | |
| 67 ASSERT_TRUE(data.hasTotal()); | |
| 68 ASSERT_TRUE(data.total().hasLabel()); | |
| 69 EXPECT_EQ("Label", data.total().label()); | |
| 70 ASSERT_TRUE(data.total().hasAmount()); | |
| 71 ASSERT_TRUE(data.total().amount().hasCurrency()); | |
| 72 EXPECT_EQ("USD", data.total().amount().currency()); | |
| 73 ASSERT_TRUE(data.total().amount().hasValue()); | |
| 74 EXPECT_EQ("9.99", data.total().amount().value()); | |
| 75 | |
| 76 ASSERT_TRUE(data.hasOptionId()); | |
| 77 EXPECT_EQ("payment-app-id", data.optionId()); | |
| 78 | |
| 79 ASSERT_TRUE(data.hasOrigin()); | |
| 80 EXPECT_EQ("https://example.com", data.origin()); | |
| 81 } | |
| 82 | |
| 83 } // namespace | |
| 84 } // namespace blink | |
| OLD | NEW |