Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp

Issue 2349133002: PaymentRequest: Make the PaymentResponse interface serializable. (Closed)
Patch Set: PaymentRequest: Make the PaymentResponse interface serializable. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 input->method_name = "foo"; 106 input->method_name = "foo";
106 input->stringified_details = "{\"transactionId\": 123}"; 107 input->stringified_details = "{\"transactionId\": 123}";
107 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; 108 MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
108 PaymentResponse output(std::move(input), completeCallback); 109 PaymentResponse output(std::move(input), completeCallback);
109 110
110 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), PaymentCompl eter::Fail)); 111 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), PaymentCompl eter::Fail));
111 112
112 output.complete(scope.getScriptState(), "fail"); 113 output.complete(scope.getScriptState(), "fail");
113 } 114 }
114 115
116 TEST(PaymentResponseTest, JSONSerializerTest)
117 {
118 V8TestingScope scope;
119 mojom::blink::PaymentResponsePtr input = buildPaymentResponseForTest();
please use gerrit instead 2016/09/20 08:15:46 This function is just "mojom::blink::PaymentRespon
zino 2016/09/20 16:55:43 Done.
120 input->method_name = "foo";
121 input->stringified_details = "{\"transactionId\": 123}";
122 input->shipping_option = "standardShippingOption";
123 input->payer_email = "abc@gmail.com";
124 input->payer_phone = "0123";
125 input->shipping_address = mojom::blink::PaymentAddress::New();
126 input->shipping_address->country = "US";
127 input->shipping_address->language_code = "en";
128 input->shipping_address->script_code = "Latn";
129 input->shipping_address->address_line = mojo::WTFArray<WTF::String>::New(3);
130 input->shipping_address->address_line[0] = "340 Main St";
131 input->shipping_address->address_line[1] = "BIN1";
132 input->shipping_address->address_line[2] = "First floor";
133 MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
134
135 PaymentResponse output(std::move(input), completeCallback);
please use gerrit instead 2016/09/20 08:15:46 Inline the completeCallback, because you're using
zino 2016/09/20 16:55:43 Done.
136 ScriptValue jsonObject = output.toJSONForBinding(scope.getScriptState());
137 EXPECT_TRUE(jsonObject.isObject());
138
139 String jsonString = v8StringToWebCoreString<String>(
140 v8::JSON::Stringify(scope.context(),
141 jsonObject.v8Value().As<v8::Object>()).ToLocalChecked(),
142 DoNotExternalize);
143 String expected = "{\"methodName\":\"foo\",\"details\":{\"transactionId\":12 3},"
144 "\"shippingAddress\":{\"country\":\"US\",\"addressLine\":[\"340 Main St\ ","
145 "\"BIN1\",\"First floor\"],\"region\":\"\",\"city\":\"\",\"dependentLoca lity\":"
146 "\"\",\"postalCode\":\"\",\"sortingCode\":\"\",\"languageCode\":\"en-Lat n\","
147 "\"organization\":\"\",\"recipient\":\"\",\"phone\":\"\"},\"shippingOpti on\":"
148 "\"standardShippingOption\",\"payerEmail\":\"abc@gmail.com\",\"payerPhon e\":\"0123\"}";
149 EXPECT_EQ(expected, jsonString);
150 }
151
115 } // namespace 152 } // namespace
116 } // namespace blink 153 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698