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/PaymentAppRequestConversion.h" | 5 #include "modules/payments/PaymentAppRequestConversion.h" |
6 | 6 |
7 #include "bindings/core/v8/ScriptValue.h" | 7 #include "bindings/core/v8/ScriptValue.h" |
8 #include "bindings/core/v8/V8BindingForCore.h" | 8 #include "bindings/core/v8/V8BindingForCore.h" |
9 #include "bindings/core/v8/V8BindingForTesting.h" | 9 #include "bindings/core/v8/V8BindingForTesting.h" |
10 #include "platform/bindings/ScriptState.h" | 10 #include "platform/bindings/ScriptState.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 static WebPaymentMethodData CreateWebPaymentMethodDataForTest() { | 26 static WebPaymentMethodData CreateWebPaymentMethodDataForTest() { |
27 WebPaymentMethodData web_method_data; | 27 WebPaymentMethodData web_method_data; |
28 WebString method = WebString::FromUTF8("foo"); | 28 WebString method = WebString::FromUTF8("foo"); |
29 web_method_data.supported_methods = WebVector<WebString>(&method, 1); | 29 web_method_data.supported_methods = WebVector<WebString>(&method, 1); |
30 web_method_data.stringified_data = "{\"merchantId\":\"12345\"}"; | 30 web_method_data.stringified_data = "{\"merchantId\":\"12345\"}"; |
31 return web_method_data; | 31 return web_method_data; |
32 } | 32 } |
33 | 33 |
34 static WebPaymentAppRequest CreateWebPaymentAppRequestForTest() { | 34 static WebPaymentAppRequest CreateWebPaymentAppRequestForTest() { |
35 WebPaymentAppRequest web_data; | 35 WebPaymentAppRequest web_data; |
36 web_data.origin = WebString::FromUTF8("https://example.com"); | 36 web_data.top_level_origin = WebString::FromUTF8("https://example.com"); |
| 37 web_data.payment_request_origin = WebString::FromUTF8("https://example.com"); |
| 38 web_data.payment_request_id = WebString::FromUTF8("payment-request-id"); |
37 Vector<WebPaymentMethodData> method_data; | 39 Vector<WebPaymentMethodData> method_data; |
38 method_data.push_back(CreateWebPaymentMethodDataForTest()); | 40 method_data.push_back(CreateWebPaymentMethodDataForTest()); |
39 web_data.method_data = WebVector<WebPaymentMethodData>(method_data); | 41 web_data.method_data = WebVector<WebPaymentMethodData>(method_data); |
40 web_data.total = CreateWebPaymentItemForTest(); | 42 web_data.total = CreateWebPaymentItemForTest(); |
41 web_data.option_id = WebString::FromUTF8("payment-app-id"); | 43 web_data.instrument_key = WebString::FromUTF8("payment-instrument-key"); |
42 return web_data; | 44 return web_data; |
43 } | 45 } |
44 | 46 |
45 TEST(PaymentAppRequestConversionTest, ToPaymentAppRequest) { | 47 TEST(PaymentAppRequestConversionTest, ToPaymentAppRequest) { |
46 V8TestingScope scope; | 48 V8TestingScope scope; |
47 WebPaymentAppRequest web_data = CreateWebPaymentAppRequestForTest(); | 49 WebPaymentAppRequest web_data = CreateWebPaymentAppRequestForTest(); |
48 PaymentAppRequest data = PaymentAppRequestConversion::ToPaymentAppRequest( | 50 PaymentAppRequest data = PaymentAppRequestConversion::ToPaymentAppRequest( |
49 scope.GetScriptState(), web_data); | 51 scope.GetScriptState(), web_data); |
50 | 52 |
| 53 ASSERT_TRUE(data.hasTopLevelOrigin()); |
| 54 EXPECT_EQ("https://example.com", data.topLevelOrigin()); |
| 55 |
| 56 ASSERT_TRUE(data.hasPaymentRequestOrigin()); |
| 57 EXPECT_EQ("https://example.com", data.paymentRequestOrigin()); |
| 58 |
| 59 ASSERT_TRUE(data.hasPaymentRequestId()); |
| 60 EXPECT_EQ("payment-request-id", data.paymentRequestId()); |
| 61 |
51 ASSERT_TRUE(data.hasMethodData()); | 62 ASSERT_TRUE(data.hasMethodData()); |
52 ASSERT_EQ(1UL, data.methodData().size()); | 63 ASSERT_EQ(1UL, data.methodData().size()); |
53 ASSERT_TRUE(data.methodData().front().hasSupportedMethods()); | 64 ASSERT_TRUE(data.methodData().front().hasSupportedMethods()); |
54 ASSERT_EQ(1UL, data.methodData().front().supportedMethods().size()); | 65 ASSERT_EQ(1UL, data.methodData().front().supportedMethods().size()); |
55 ASSERT_EQ("foo", data.methodData().front().supportedMethods().front()); | 66 ASSERT_EQ("foo", data.methodData().front().supportedMethods().front()); |
56 ASSERT_TRUE(data.methodData().front().hasData()); | 67 ASSERT_TRUE(data.methodData().front().hasData()); |
57 ASSERT_TRUE(data.methodData().front().data().IsObject()); | 68 ASSERT_TRUE(data.methodData().front().data().IsObject()); |
58 String stringified_data = V8StringToWebCoreString<String>( | 69 String stringified_data = V8StringToWebCoreString<String>( |
59 v8::JSON::Stringify( | 70 v8::JSON::Stringify( |
60 scope.GetContext(), | 71 scope.GetContext(), |
61 data.methodData().front().data().V8Value().As<v8::Object>()) | 72 data.methodData().front().data().V8Value().As<v8::Object>()) |
62 .ToLocalChecked(), | 73 .ToLocalChecked(), |
63 kDoNotExternalize); | 74 kDoNotExternalize); |
64 EXPECT_EQ("{\"merchantId\":\"12345\"}", stringified_data); | 75 EXPECT_EQ("{\"merchantId\":\"12345\"}", stringified_data); |
65 | 76 |
66 ASSERT_TRUE(data.hasTotal()); | 77 ASSERT_TRUE(data.hasTotal()); |
67 ASSERT_TRUE(data.total().hasLabel()); | 78 ASSERT_TRUE(data.total().hasLabel()); |
68 EXPECT_EQ("Label", data.total().label()); | 79 EXPECT_EQ("Label", data.total().label()); |
69 ASSERT_TRUE(data.total().hasAmount()); | 80 ASSERT_TRUE(data.total().hasAmount()); |
70 ASSERT_TRUE(data.total().amount().hasCurrency()); | 81 ASSERT_TRUE(data.total().amount().hasCurrency()); |
71 EXPECT_EQ("USD", data.total().amount().currency()); | 82 EXPECT_EQ("USD", data.total().amount().currency()); |
72 ASSERT_TRUE(data.total().amount().hasValue()); | 83 ASSERT_TRUE(data.total().amount().hasValue()); |
73 EXPECT_EQ("9.99", data.total().amount().value()); | 84 EXPECT_EQ("9.99", data.total().amount().value()); |
74 | 85 |
75 ASSERT_TRUE(data.hasOptionId()); | 86 ASSERT_TRUE(data.hasInstrumentKey()); |
76 EXPECT_EQ("payment-app-id", data.optionId()); | 87 EXPECT_EQ("payment-instrument-key", data.instrumentKey()); |
77 | |
78 ASSERT_TRUE(data.hasOrigin()); | |
79 EXPECT_EQ("https://example.com", data.origin()); | |
80 } | 88 } |
81 | 89 |
82 } // namespace | 90 } // namespace |
83 } // namespace blink | 91 } // namespace blink |
OLD | NEW |