OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/payments/PaymentResponse.h" |
| 6 |
| 7 #include "bindings/core/v8/ExceptionState.h" |
| 8 #include "bindings/core/v8/ScriptState.h" |
| 9 #include "core/testing/DummyPageHolder.h" |
| 10 #include "modules/payments/PaymentCompleter.h" |
| 11 #include "modules/payments/PaymentDetailsTestHelper.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "wtf/OwnPtr.h" |
| 15 #include <utility> |
| 16 |
| 17 namespace blink { |
| 18 namespace { |
| 19 |
| 20 class MockPaymentCompleter : public GarbageCollectedFinalized<MockPaymentComplet
er>, public PaymentCompleter { |
| 21 USING_GARBAGE_COLLECTED_MIXIN(MockPaymentCompleter); |
| 22 WTF_MAKE_NONCOPYABLE(MockPaymentCompleter); |
| 23 |
| 24 public: |
| 25 MockPaymentCompleter() |
| 26 { |
| 27 ON_CALL(*this, complete(testing::_, testing::_)) |
| 28 .WillByDefault(testing::ReturnPointee(&m_dummyPromise)); |
| 29 } |
| 30 |
| 31 ~MockPaymentCompleter() override {} |
| 32 |
| 33 MOCK_METHOD2(complete, ScriptPromise(ScriptState*, bool success)); |
| 34 |
| 35 DEFINE_INLINE_TRACE() {} |
| 36 |
| 37 private: |
| 38 ScriptPromise m_dummyPromise; |
| 39 }; |
| 40 |
| 41 class PaymentResponseTest : public testing::Test { |
| 42 public: |
| 43 PaymentResponseTest() |
| 44 : m_page(DummyPageHolder::create()) |
| 45 { |
| 46 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
"https://www.example.com/"))); |
| 47 } |
| 48 |
| 49 ~PaymentResponseTest() override {} |
| 50 |
| 51 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc
ument().frame()); } |
| 52 ExceptionState& getExceptionState() { return m_exceptionState; } |
| 53 |
| 54 private: |
| 55 OwnPtr<DummyPageHolder> m_page; |
| 56 NonThrowableExceptionState m_exceptionState; |
| 57 }; |
| 58 |
| 59 TEST_F(PaymentResponseTest, DataCopiedOver) |
| 60 { |
| 61 mojom::wtf::PaymentResponsePtr input = mojom::wtf::PaymentResponse::New(); |
| 62 input->method_name = "foo"; |
| 63 input->stringified_details = "{\"transactionId\": 123}"; |
| 64 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; |
| 65 |
| 66 PaymentResponse output(std::move(input), completeCallback); |
| 67 |
| 68 // TODO(rouslan): Verify that output.details() contains parsed input->string
ified_details. |
| 69 EXPECT_FALSE(getExceptionState().hadException()); |
| 70 EXPECT_EQ("foo", output.methodName()); |
| 71 } |
| 72 |
| 73 TEST_F(PaymentResponseTest, CompleteCalled) |
| 74 { |
| 75 mojom::wtf::PaymentResponsePtr input = mojom::wtf::PaymentResponse::New(); |
| 76 input->method_name = "foo"; |
| 77 input->stringified_details = "{\"transactionId\": 123}"; |
| 78 MockPaymentCompleter* completeCallback = new MockPaymentCompleter; |
| 79 PaymentResponse output(std::move(input), completeCallback); |
| 80 |
| 81 EXPECT_FALSE(getExceptionState().hadException()); |
| 82 EXPECT_CALL(*completeCallback, complete(getScriptState(), true)); |
| 83 |
| 84 output.complete(getScriptState(), true); |
| 85 } |
| 86 |
| 87 } // namespace |
| 88 } // namespace blink |
OLD | NEW |