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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp b/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp
index d2e54e322f4daafa359cd714d801d85caa37ab26..b15ab43bffea2d497ac2a6a627459929bd8cf940 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp
@@ -9,6 +9,7 @@
#include "bindings/core/v8/ScriptValue.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8BindingForTesting.h"
+#include "modules/payments/PaymentAddress.h"
#include "modules/payments/PaymentCompleter.h"
#include "modules/payments/PaymentTestHelper.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -112,5 +113,41 @@ TEST(PaymentResponseTest, CompleteCalledWithFailure)
output.complete(scope.getScriptState(), "fail");
}
+TEST(PaymentResponseTest, JSONSerializerTest)
+{
+ V8TestingScope scope;
+ 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.
+ input->method_name = "foo";
+ input->stringified_details = "{\"transactionId\": 123}";
+ input->shipping_option = "standardShippingOption";
+ input->payer_email = "abc@gmail.com";
+ input->payer_phone = "0123";
+ input->shipping_address = mojom::blink::PaymentAddress::New();
+ input->shipping_address->country = "US";
+ input->shipping_address->language_code = "en";
+ input->shipping_address->script_code = "Latn";
+ input->shipping_address->address_line = mojo::WTFArray<WTF::String>::New(3);
+ input->shipping_address->address_line[0] = "340 Main St";
+ input->shipping_address->address_line[1] = "BIN1";
+ input->shipping_address->address_line[2] = "First floor";
+ MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
+
+ 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.
+ ScriptValue jsonObject = output.toJSONForBinding(scope.getScriptState());
+ EXPECT_TRUE(jsonObject.isObject());
+
+ String jsonString = v8StringToWebCoreString<String>(
+ v8::JSON::Stringify(scope.context(),
+ jsonObject.v8Value().As<v8::Object>()).ToLocalChecked(),
+ DoNotExternalize);
+ String expected = "{\"methodName\":\"foo\",\"details\":{\"transactionId\":123},"
+ "\"shippingAddress\":{\"country\":\"US\",\"addressLine\":[\"340 Main St\","
+ "\"BIN1\",\"First floor\"],\"region\":\"\",\"city\":\"\",\"dependentLocality\":"
+ "\"\",\"postalCode\":\"\",\"sortingCode\":\"\",\"languageCode\":\"en-Latn\","
+ "\"organization\":\"\",\"recipient\":\"\",\"phone\":\"\"},\"shippingOption\":"
+ "\"standardShippingOption\",\"payerEmail\":\"abc@gmail.com\",\"payerPhone\":\"0123\"}";
+ EXPECT_EQ(expected, jsonString);
+}
+
} // namespace
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698