| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9db394fc74f681e20173ca1fcf60535aa616587e
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/modules/payments/PaymentResponseTest.cpp
|
| @@ -0,0 +1,65 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "modules/payments/PaymentResponse.h"
|
| +
|
| +#include "bindings/core/v8/ExceptionState.h"
|
| +#include "bindings/core/v8/ScriptState.h"
|
| +#include "core/testing/DummyPageHolder.h"
|
| +#include "modules/payments/MockPaymentRequest.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "wtf/OwnPtr.h"
|
| +#include <utility>
|
| +
|
| +namespace blink {
|
| +namespace {
|
| +
|
| +class PaymentResponseTest : public testing::Test {
|
| +public:
|
| + PaymentResponseTest()
|
| + : m_page(DummyPageHolder::create())
|
| + {
|
| + m_page->document().setSecurityOrigin(SecurityOrigin::create(KURL(KURL(), "https://www.example.com/")));
|
| + }
|
| +
|
| + ~PaymentResponseTest() override {}
|
| +
|
| + ScriptState* getScriptState() { return ScriptState::forMainWorld(m_page->document().frame()); }
|
| + ExceptionState& getExceptionState() { return m_exceptionState; }
|
| +
|
| +private:
|
| + OwnPtr<DummyPageHolder> m_page;
|
| + NonThrowableExceptionState m_exceptionState;
|
| +};
|
| +
|
| +TEST_F(PaymentResponseTest, DataCopiedOver)
|
| +{
|
| + mojom::wtf::PaymentResponsePtr input = mojom::wtf::PaymentResponse::New();
|
| + input->method_name = "foo";
|
| + input->stringified_details = "{\"transactionId\": 123}";
|
| +
|
| + PaymentResponse output(std::move(input), PaymentRequest::create(getScriptState(), Vector<String>(1, "foo"), MockPaymentRequest::buildDetails(), getExceptionState()));
|
| +
|
| + // TODO(rouslan): Verify that output.details() contains parsed input->stringified_details.
|
| + EXPECT_FALSE(getExceptionState().hadException());
|
| + EXPECT_EQ("foo", output.methodName());
|
| +}
|
| +
|
| +TEST_F(PaymentResponseTest, CompleteCalled)
|
| +{
|
| + MockPaymentRequest* completeCallback = new MockPaymentRequest(getScriptState(), Vector<String>(1, "foo"), MockPaymentRequest::buildDetails(), getExceptionState());
|
| + mojom::wtf::PaymentResponsePtr input = mojom::wtf::PaymentResponse::New();
|
| + input->method_name = "foo";
|
| + input->stringified_details = "{\"transactionId\": 123}";
|
| + PaymentResponse output(std::move(input), completeCallback);
|
| +
|
| + EXPECT_FALSE(getExceptionState().hadException());
|
| + EXPECT_CALL(*completeCallback, complete(getScriptState(), true));
|
| +
|
| + output.complete(getScriptState(), true);
|
| +}
|
| +
|
| +} // namespace
|
| +} // namespace blink
|
|
|