OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/payments/PaymentAppRequestDataConversion.h" | 5 #include "modules/payments/PaymentAppRequestConversion.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptState.h" | 7 #include "bindings/core/v8/ScriptState.h" |
8 #include "bindings/core/v8/ScriptValue.h" | 8 #include "bindings/core/v8/ScriptValue.h" |
9 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
10 #include "bindings/core/v8/V8BindingForTesting.h" | 10 #include "bindings/core/v8/V8BindingForTesting.h" |
11 #include "public/platform/modules/payments/WebPaymentAppRequestData.h" | 11 #include "public/platform/modules/payments/WebPaymentAppRequest.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 namespace { | 16 namespace { |
17 | 17 |
18 static WebPaymentItem createWebPaymentItemForTest() { | 18 static WebPaymentItem createWebPaymentItemForTest() { |
19 WebPaymentItem webItem; | 19 WebPaymentItem webItem; |
20 webItem.label = WebString::fromUTF8("Label"); | 20 webItem.label = WebString::fromUTF8("Label"); |
21 webItem.amount.currency = WebString::fromUTF8("USD"); | 21 webItem.amount.currency = WebString::fromUTF8("USD"); |
22 webItem.amount.value = WebString::fromUTF8("9.99"); | 22 webItem.amount.value = WebString::fromUTF8("9.99"); |
23 return webItem; | 23 return webItem; |
24 } | 24 } |
25 | 25 |
26 static WebPaymentMethodData createWebPaymentMethodDataForTest() { | 26 static WebPaymentMethodData createWebPaymentMethodDataForTest() { |
27 WebPaymentMethodData webMethodData; | 27 WebPaymentMethodData webMethodData; |
28 WebString method = WebString::fromUTF8("foo"); | 28 WebString method = WebString::fromUTF8("foo"); |
29 webMethodData.supportedMethods = WebVector<WebString>(&method, 1); | 29 webMethodData.supportedMethods = WebVector<WebString>(&method, 1); |
30 webMethodData.stringifiedData = "{\"merchantId\":\"12345\"}"; | 30 webMethodData.stringifiedData = "{\"merchantId\":\"12345\"}"; |
31 return webMethodData; | 31 return webMethodData; |
32 } | 32 } |
33 | 33 |
34 static WebPaymentAppRequestData createWebPaymentAppRequestDataForTest() { | 34 static WebPaymentAppRequest createWebPaymentAppRequestForTest() { |
35 WebPaymentAppRequestData webData; | 35 WebPaymentAppRequest webData; |
36 webData.origin = WebString::fromUTF8("https://example.com"); | 36 webData.origin = WebString::fromUTF8("https://example.com"); |
37 Vector<WebPaymentMethodData> methodData; | 37 Vector<WebPaymentMethodData> methodData; |
38 methodData.push_back(createWebPaymentMethodDataForTest()); | 38 methodData.push_back(createWebPaymentMethodDataForTest()); |
39 webData.methodData = WebVector<WebPaymentMethodData>(methodData); | 39 webData.methodData = WebVector<WebPaymentMethodData>(methodData); |
40 webData.total = createWebPaymentItemForTest(); | 40 webData.total = createWebPaymentItemForTest(); |
41 webData.optionId = WebString::fromUTF8("payment-app-id"); | 41 webData.optionId = WebString::fromUTF8("payment-app-id"); |
42 return webData; | 42 return webData; |
43 } | 43 } |
44 | 44 |
45 TEST(PaymentAppRequestDataConversionTest, ToPaymentAppRequestData) { | 45 TEST(PaymentAppRequestConversionTest, ToPaymentAppRequest) { |
46 V8TestingScope scope; | 46 V8TestingScope scope; |
47 WebPaymentAppRequestData webData = createWebPaymentAppRequestDataForTest(); | 47 WebPaymentAppRequest webData = createWebPaymentAppRequestForTest(); |
48 PaymentAppRequestData data = | 48 PaymentAppRequest data = PaymentAppRequestConversion::toPaymentAppRequest( |
49 PaymentAppRequestDataConversion::toPaymentAppRequestData( | 49 scope.getScriptState(), webData); |
50 scope.getScriptState(), webData); | |
51 | 50 |
52 ASSERT_TRUE(data.hasMethodData()); | 51 ASSERT_TRUE(data.hasMethodData()); |
53 ASSERT_EQ(1UL, data.methodData().size()); | 52 ASSERT_EQ(1UL, data.methodData().size()); |
54 ASSERT_TRUE(data.methodData().front().hasSupportedMethods()); | 53 ASSERT_TRUE(data.methodData().front().hasSupportedMethods()); |
55 ASSERT_EQ(1UL, data.methodData().front().supportedMethods().size()); | 54 ASSERT_EQ(1UL, data.methodData().front().supportedMethods().size()); |
56 ASSERT_EQ("foo", data.methodData().front().supportedMethods().front()); | 55 ASSERT_EQ("foo", data.methodData().front().supportedMethods().front()); |
57 ASSERT_TRUE(data.methodData().front().hasData()); | 56 ASSERT_TRUE(data.methodData().front().hasData()); |
58 ASSERT_TRUE(data.methodData().front().data().isObject()); | 57 ASSERT_TRUE(data.methodData().front().data().isObject()); |
59 String stringifiedData = v8StringToWebCoreString<String>( | 58 String stringifiedData = v8StringToWebCoreString<String>( |
60 v8::JSON::Stringify( | 59 v8::JSON::Stringify( |
(...skipping 14 matching lines...) Expand all Loading... |
75 | 74 |
76 ASSERT_TRUE(data.hasOptionId()); | 75 ASSERT_TRUE(data.hasOptionId()); |
77 EXPECT_EQ("payment-app-id", data.optionId()); | 76 EXPECT_EQ("payment-app-id", data.optionId()); |
78 | 77 |
79 ASSERT_TRUE(data.hasOrigin()); | 78 ASSERT_TRUE(data.hasOrigin()); |
80 EXPECT_EQ("https://example.com", data.origin()); | 79 EXPECT_EQ("https://example.com", data.origin()); |
81 } | 80 } |
82 | 81 |
83 } // namespace | 82 } // namespace |
84 } // namespace blink | 83 } // namespace blink |
OLD | NEW |