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/MockPaymentRequest.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "wtf/OwnPtr.h" |
| 14 #include <utility> |
| 15 |
| 16 namespace blink { |
| 17 namespace { |
| 18 |
| 19 class PaymentResponseTest : public testing::Test { |
| 20 public: |
| 21 PaymentResponseTest() |
| 22 : m_page(DummyPageHolder::create()) |
| 23 { |
| 24 m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(),
"https://www.example.com/"))); |
| 25 } |
| 26 |
| 27 ~PaymentResponseTest() override {} |
| 28 |
| 29 ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->doc
ument().frame()); } |
| 30 ExceptionState& getExceptionState() { return m_exceptionState; } |
| 31 |
| 32 private: |
| 33 OwnPtr<DummyPageHolder> m_page; |
| 34 NonThrowableExceptionState m_exceptionState; |
| 35 }; |
| 36 |
| 37 TEST_F(PaymentResponseTest, DataCopiedOver) |
| 38 { |
| 39 mojom::wtf::PaymentResponsePtr input = mojom::wtf::PaymentResponse::New(); |
| 40 input->method_name = "foo"; |
| 41 input->stringified_details = "{\"transactionId\": 123}"; |
| 42 |
| 43 PaymentResponse output(std::move(input), PaymentRequest::create(getScriptSta
te(), Vector<String>(1, "foo"), MockPaymentRequest::buildDetails(), getException
State())); |
| 44 |
| 45 // TODO(rouslan): Verify that output.details() contains parsed input->string
ified_details. |
| 46 EXPECT_FALSE(getExceptionState().hadException()); |
| 47 EXPECT_EQ("foo", output.methodName()); |
| 48 } |
| 49 |
| 50 TEST_F(PaymentResponseTest, CompleteCalled) |
| 51 { |
| 52 MockPaymentRequest* completeCallback = new MockPaymentRequest(getScriptState
(), Vector<String>(1, "foo"), MockPaymentRequest::buildDetails(), getExceptionSt
ate()); |
| 53 mojom::wtf::PaymentResponsePtr input = mojom::wtf::PaymentResponse::New(); |
| 54 input->method_name = "foo"; |
| 55 input->stringified_details = "{\"transactionId\": 123}"; |
| 56 PaymentResponse output(std::move(input), completeCallback); |
| 57 |
| 58 EXPECT_FALSE(getExceptionState().hadException()); |
| 59 EXPECT_CALL(*completeCallback, complete(getScriptState(), true)); |
| 60 |
| 61 output.complete(getScriptState(), true); |
| 62 } |
| 63 |
| 64 } // namespace |
| 65 } // namespace blink |
OLD | NEW |