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

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

Issue 2171973005: Add test to check that the payment response details field is a JSON-serializable object. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 62
63 ASSERT_FALSE(scope.getExceptionState().hadException()); 63 ASSERT_FALSE(scope.getExceptionState().hadException());
64 ASSERT_TRUE(details.v8Value()->IsObject()); 64 ASSERT_TRUE(details.v8Value()->IsObject());
65 65
66 ScriptValue transactionId(scope.getScriptState(), details.v8Value().As<v8::O bject>()->Get(v8String(scope.getScriptState()->isolate(), "transactionId"))); 66 ScriptValue transactionId(scope.getScriptState(), details.v8Value().As<v8::O bject>()->Get(v8String(scope.getScriptState()->isolate(), "transactionId")));
67 67
68 ASSERT_TRUE(transactionId.v8Value()->IsNumber()); 68 ASSERT_TRUE(transactionId.v8Value()->IsNumber());
69 EXPECT_EQ(123, transactionId.v8Value().As<v8::Number>()->Value()); 69 EXPECT_EQ(123, transactionId.v8Value().As<v8::Number>()->Value());
70 } 70 }
71 71
72 TEST(PaymentResponseTest, PaymentResponseDetailsJSONObject)
73 {
74 V8TestingScope scope;
75 mojom::blink::PaymentResponsePtr input = buildPaymentResponseForTest();
76 input->stringified_details = "transactionId";
77 MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
78
please use gerrit instead 2016/07/22 16:58:54 Remove this empty line. A typical test has three s
79 PaymentResponse output(std::move(input), completeCallback);
80
81 ScriptValue details = output.details(scope.getScriptState(), scope.getExcept ionState());
82
83 ASSERT_TRUE(scope.getExceptionState().hadException());
84 }
85
72 TEST(PaymentResponseTest, CompleteCalledWithSuccess) 86 TEST(PaymentResponseTest, CompleteCalledWithSuccess)
73 { 87 {
74 V8TestingScope scope; 88 V8TestingScope scope;
75 mojom::blink::PaymentResponsePtr input = buildPaymentResponseForTest(); 89 mojom::blink::PaymentResponsePtr input = buildPaymentResponseForTest();
76 input->method_name = "foo"; 90 input->method_name = "foo";
77 input->stringified_details = "{\"transactionId\": 123}"; 91 input->stringified_details = "{\"transactionId\": 123}";
78 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; 92 MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
79 PaymentResponse output(std::move(input), completeCallback); 93 PaymentResponse output(std::move(input), completeCallback);
80 94
81 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), Success)); 95 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), Success));
(...skipping 10 matching lines...) Expand all
92 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; 106 MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
93 PaymentResponse output(std::move(input), completeCallback); 107 PaymentResponse output(std::move(input), completeCallback);
94 108
95 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), Fail)); 109 EXPECT_CALL(*completeCallback, complete(scope.getScriptState(), Fail));
96 110
97 output.complete(scope.getScriptState(), "fail"); 111 output.complete(scope.getScriptState(), "fail");
98 } 112 }
99 113
100 } // namespace 114 } // namespace
101 } // namespace blink 115 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698