| 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/PaymentResponse.h" | 5 #include "modules/payments/PaymentResponse.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" | 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptState.h" | 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "bindings/core/v8/ScriptValue.h" | 9 #include "bindings/core/v8/ScriptValue.h" |
| 10 #include "bindings/core/v8/V8Binding.h" | 10 #include "bindings/core/v8/V8Binding.h" |
| 11 #include "bindings/core/v8/V8BindingForTesting.h" | 11 #include "bindings/core/v8/V8BindingForTesting.h" |
| 12 #include "modules/payments/PaymentAddress.h" |
| 12 #include "modules/payments/PaymentCompleter.h" | 13 #include "modules/payments/PaymentCompleter.h" |
| 13 #include "modules/payments/PaymentTestHelper.h" | 14 #include "modules/payments/PaymentTestHelper.h" |
| 14 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include <memory> | 17 #include <memory> |
| 17 #include <utility> | 18 #include <utility> |
| 18 | 19 |
| 19 namespace blink { | 20 namespace blink { |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 input->method_name = "foo"; | 104 input->method_name = "foo"; |
| 104 input->stringified_details = "{\"transactionId\": 123}"; | 105 input->stringified_details = "{\"transactionId\": 123}"; |
| 105 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; | 106 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; |
| 106 PaymentResponse output(std::move(input), completeCallback); | 107 PaymentResponse output(std::move(input), completeCallback); |
| 107 | 108 |
| 108 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), PaymentCompl
eter::Fail)); | 109 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), PaymentCompl
eter::Fail)); |
| 109 | 110 |
| 110 output.complete(scope.getScriptState(), "fail"); | 111 output.complete(scope.getScriptState(), "fail"); |
| 111 } | 112 } |
| 112 | 113 |
| 114 TEST(PaymentResponseTest, JSONSerializerTest) |
| 115 { |
| 116 V8TestingScope scope; |
| 117 mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New(
); |
| 118 input->method_name = "foo"; |
| 119 input->stringified_details = "{\"transactionId\": 123}"; |
| 120 input->shipping_option = "standardShippingOption"; |
| 121 input->payer_email = "abc@gmail.com"; |
| 122 input->payer_phone = "0123"; |
| 123 input->shipping_address = mojom::blink::PaymentAddress::New(); |
| 124 input->shipping_address->country = "US"; |
| 125 input->shipping_address->language_code = "en"; |
| 126 input->shipping_address->script_code = "Latn"; |
| 127 input->shipping_address->address_line = mojo::WTFArray<WTF::String>::New(3); |
| 128 input->shipping_address->address_line[0] = "340 Main St"; |
| 129 input->shipping_address->address_line[1] = "BIN1"; |
| 130 input->shipping_address->address_line[2] = "First floor"; |
| 131 |
| 132 PaymentResponse output(std::move(input), new MockPaymentCompleter); |
| 133 ScriptValue jsonObject = output.toJSONForBinding(scope.getScriptState()); |
| 134 EXPECT_TRUE(jsonObject.isObject()); |
| 135 |
| 136 String jsonString = v8StringToWebCoreString<String>( |
| 137 v8::JSON::Stringify(scope.context(), |
| 138 jsonObject.v8Value().As<v8::Object>()).ToLocalChecked(), |
| 139 DoNotExternalize); |
| 140 String expected = "{\"methodName\":\"foo\",\"details\":{\"transactionId\":12
3}," |
| 141 "\"shippingAddress\":{\"country\":\"US\",\"addressLine\":[\"340 Main St\
"," |
| 142 "\"BIN1\",\"First floor\"],\"region\":\"\",\"city\":\"\",\"dependentLoca
lity\":" |
| 143 "\"\",\"postalCode\":\"\",\"sortingCode\":\"\",\"languageCode\":\"en-Lat
n\"," |
| 144 "\"organization\":\"\",\"recipient\":\"\",\"phone\":\"\"},\"shippingOpti
on\":" |
| 145 "\"standardShippingOption\",\"payerEmail\":\"abc@gmail.com\",\"payerPhon
e\":\"0123\"}"; |
| 146 EXPECT_EQ(expected, jsonString); |
| 147 } |
| 148 |
| 113 } // namespace | 149 } // namespace |
| 114 } // namespace blink | 150 } // namespace blink |
| OLD | NEW |