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

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

Issue 1941633002: PaymentResponse tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 "core/testing/DummyPageHolder.h" 10 #include "core/testing/DummyPageHolder.h"
10 #include "modules/payments/PaymentCompleter.h" 11 #include "modules/payments/PaymentCompleter.h"
11 #include "modules/payments/PaymentDetailsTestHelper.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "wtf/OwnPtr.h" 14 #include "wtf/OwnPtr.h"
15 #include <utility> 15 #include <utility>
16 16
17 namespace blink { 17 namespace blink {
18 namespace {
Marijn Kruisselbrink 2016/05/02 18:04:58 Any particular reason you got rid of the anonymous
please use gerrit instead 2016/05/02 18:17:24 `git cl format` kept trying to indent anonymous na
Marijn Kruisselbrink 2016/05/02 18:53:48 Ah, yeah, git cl format on blink code never seems
19 18
20 class MockPaymentCompleter : public GarbageCollectedFinalized<MockPaymentComplet er>, public PaymentCompleter { 19 class MockPaymentCompleter : public GarbageCollectedFinalized<MockPaymentComplet er>, public PaymentCompleter {
21 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentCompleter); 20 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentCompleter);
22 WTF_MAKE_NONCOPYABLE(MockPaymentCompleter); 21 WTF_MAKE_NONCOPYABLE(MockPaymentCompleter);
23 22
24 public: 23 public:
25 MockPaymentCompleter() 24 MockPaymentCompleter()
26 { 25 {
27 ON_CALL(*this, complete(testing::_, testing::_)) 26 ON_CALL(*this, complete(testing::_, testing::_))
28 .WillByDefault(testing::ReturnPointee(&m_dummyPromise)); 27 .WillByDefault(testing::ReturnPointee(&m_dummyPromise));
29 } 28 }
30 29
31 ~MockPaymentCompleter() override {} 30 ~MockPaymentCompleter() override {}
32 31
33 MOCK_METHOD2(complete, ScriptPromise(ScriptState*, bool success)); 32 MOCK_METHOD2(complete, ScriptPromise(ScriptState*, bool success));
34 33
35 DEFINE_INLINE_TRACE() {} 34 DEFINE_INLINE_TRACE() {}
36 35
37 private: 36 private:
38 ScriptPromise m_dummyPromise; 37 ScriptPromise m_dummyPromise;
39 }; 38 };
40 39
41 class PaymentResponseTest : public testing::Test { 40 class PaymentResponseTest : public testing::Test {
42 public: 41 public:
43 PaymentResponseTest() 42 PaymentResponseTest()
44 : m_page(DummyPageHolder::create()) 43 : m_page(DummyPageHolder::create())
45 { 44 {
46 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://www.example.com/")));
47 } 45 }
48 46
49 ~PaymentResponseTest() override {} 47 ~PaymentResponseTest() override {}
50 48
51 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); } 49 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc ument().frame()); }
52 ExceptionState& getExceptionState() { return m_exceptionState; } 50 ExceptionState& getExceptionState() { return m_exceptionState; }
53 51
54 private: 52 private:
55 OwnPtr<DummyPageHolder> m_page; 53 OwnPtr<DummyPageHolder> m_page;
56 NonThrowableExceptionState m_exceptionState; 54 NonThrowableExceptionState m_exceptionState;
57 }; 55 };
58 56
59 TEST_F(PaymentResponseTest, DataCopiedOver) 57 TEST_F(PaymentResponseTest, DataCopiedOver)
60 { 58 {
59 ScriptState::Scope scope(getScriptState());
61 mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New( ); 60 mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New( );
62 input->method_name = "foo"; 61 input->method_name = "foo";
63 input->stringified_details = "{\"transactionId\": 123}"; 62 input->stringified_details = "{\"transactionId\": 123}";
64 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; 63 MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
65 64
66 PaymentResponse output(std::move(input), completeCallback); 65 PaymentResponse output(std::move(input), completeCallback);
67 66
68 // TODO(rouslan): Verify that output.details() contains parsed input->string ified_details. 67 ASSERT_FALSE(getExceptionState().hadException());
Marijn Kruisselbrink 2016/05/02 18:04:58 This assert seems a bit unnecessary? At this point
please use gerrit instead 2016/05/02 18:17:24 Removed. Not sure why it was here.
69 EXPECT_FALSE(getExceptionState().hadException());
70 EXPECT_EQ("foo", output.methodName()); 68 EXPECT_EQ("foo", output.methodName());
69
70 ScriptValue details = output.details(getScriptState(), getExceptionState());
71
72 ASSERT_FALSE(getExceptionState().hadException());
73 ASSERT_TRUE(details.v8Value()->IsObject());
74
75 ScriptValue transactionId(getScriptState(), details.v8Value().As<v8::Object> ()->Get(v8String(getScriptState()->isolate(), "transactionId")));
76
77 ASSERT_TRUE(transactionId.v8Value()->IsNumber());
78 EXPECT_EQ(123, transactionId.v8Value().As<v8::Number>()->Value());
71 } 79 }
72 80
73 TEST_F(PaymentResponseTest, CompleteCalled) 81 TEST_F(PaymentResponseTest, CompleteCalledWithSuccess)
74 { 82 {
75 mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New( ); 83 mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New( );
76 input->method_name = "foo"; 84 input->method_name = "foo";
77 input->stringified_details = "{\"transactionId\": 123}"; 85 input->stringified_details = "{\"transactionId\": 123}";
78 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; 86 MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
79 PaymentResponse output(std::move(input), completeCallback); 87 PaymentResponse output(std::move(input), completeCallback);
80 88
81 EXPECT_FALSE(getExceptionState().hadException()); 89 EXPECT_FALSE(getExceptionState().hadException());
82 EXPECT_CALL(*completeCallback, complete(getScriptState(), true)); 90 EXPECT_CALL(*completeCallback, complete(getScriptState(), true));
83 91
84 output.complete(getScriptState(), true); 92 output.complete(getScriptState(), true);
85 } 93 }
86 94
87 } // namespace 95 TEST_F(PaymentResponseTest, CompleteCalledWithFailure)
96 {
97 mojom::blink::PaymentResponsePtr input = mojom::blink::PaymentResponse::New( );
98 input->method_name = "foo";
99 input->stringified_details = "{\"transactionId\": 123}";
100 MockPaymentCompleter* completeCallback = new MockPaymentCompleter;
101 PaymentResponse output(std::move(input), completeCallback);
102
103 EXPECT_FALSE(getExceptionState().hadException());
104 EXPECT_CALL(*completeCallback, complete(getScriptState(), false));
105
106 output.complete(getScriptState(), false);
107 }
108
88 } // namespace blink 109 } // 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