Chromium Code Reviews| 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 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.
| |
| 29 webMethodData.stringifiedData = "{\"merchantId\":\"12345\"}"; | |
| 30 return webMethodData; | |
| 31 } | |
| 32 | |
| 33 static WebPaymentAppRequestData createWebPaymentAppRequestDataForTest() { | |
| 34 WebPaymentAppRequestData webData; | |
| 35 webData.origin = WebString::fromUTF8("https://example.com"); | |
| 36 Vector<WebPaymentMethodData> methodData; | |
| 37 methodData.append(createWebPaymentMethodDataForTest()); | |
| 38 webData.methodData = WebVector<WebPaymentMethodData>(methodData); | |
| 39 webData.total = createWebPaymentItemForTest(); | |
| 40 webData.optionId = WebString::fromUTF8("payment-app-id"); | |
| 41 return webData; | |
| 42 } | |
| 43 | |
| 44 TEST(PaymentAppRequestDataConversionTest, ToPaymentAppRequestData) { | |
| 45 V8TestingScope scope; | |
| 46 WebPaymentAppRequestData webData = createWebPaymentAppRequestDataForTest(); | |
| 47 PaymentAppRequestData data = | |
| 48 PaymentAppRequestDataConversion::toPaymentAppRequestData( | |
| 49 scope.getScriptState(), webData); | |
| 50 | |
| 51 ASSERT_TRUE(data.hasMethodData()); | |
| 52 ASSERT_EQ(1UL, data.methodData().size()); | |
| 53 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.
| |
| 54 ASSERT_EQ(1UL, data.methodData()[0].supportedMethods().size()); | |
| 55 ASSERT_EQ("foo", data.methodData()[0].supportedMethods()[0]); | |
| 56 ASSERT_TRUE(data.methodData()[0].hasData()); | |
| 57 ASSERT_TRUE(data.methodData()[0].data().isObject()); | |
| 58 String stringifiedData = v8StringToWebCoreString<String>( | |
| 59 v8::JSON::Stringify( | |
| 60 scope.context(), | |
| 61 data.methodData()[0].data().v8Value().As<v8::Object>()) | |
| 62 .ToLocalChecked(), | |
| 63 DoNotExternalize); | |
| 64 EXPECT_EQ("{\"merchantId\":\"12345\"}", stringifiedData); | |
| 65 | |
| 66 ASSERT_TRUE(data.hasTotal()); | |
| 67 ASSERT_TRUE(data.total().hasLabel()); | |
| 68 EXPECT_EQ("Label", data.total().label()); | |
| 69 ASSERT_TRUE(data.total().hasAmount()); | |
| 70 ASSERT_TRUE(data.total().amount().hasCurrency()); | |
| 71 EXPECT_EQ("USD", data.total().amount().currency()); | |
| 72 ASSERT_TRUE(data.total().amount().hasValue()); | |
| 73 EXPECT_EQ("9.99", data.total().amount().value()); | |
| 74 | |
| 75 ASSERT_TRUE(data.hasOptionId()); | |
| 76 EXPECT_EQ("payment-app-id", data.optionId()); | |
| 77 | |
| 78 ASSERT_TRUE(data.hasOrigin()); | |
| 79 EXPECT_EQ("https://example.com", data.origin()); | |
| 80 } | |
| 81 | |
| 82 } // namespace | |
| 83 } // namespace blink | |
| OLD | NEW |