| Index: services/test/service_unittest.cc
|
| diff --git a/services/test/service_unittest.cc b/services/test/service_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2640361216a9ee9172d7598a7c72ee9fb4cd63a1
|
| --- /dev/null
|
| +++ b/services/test/service_unittest.cc
|
| @@ -0,0 +1,61 @@
|
| +// 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 "base/memory/ref_counted.h"
|
| +#include "base/run_loop.h"
|
| +#include "base/test/mock_callback.h"
|
| +#include "mojo/public/cpp/bindings/binding.h"
|
| +#include "services/service_manager/public/cpp/service_test.h"
|
| +#include "services/test/public/interfaces/service.mojom.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +
|
| +using testing::Exactly;
|
| +using testing::_;
|
| +using testing::InvokeWithoutArgs;
|
| +
|
| +namespace test {
|
| +
|
| +class TestServiceTest : public service_manager::test::ServiceTest {
|
| + public:
|
| + TestServiceTest() : service_manager::test::ServiceTest("test_unittests") {}
|
| + ~TestServiceTest() override {}
|
| +
|
| + void SetUp() override {
|
| + service_manager::test::ServiceTest::SetUp();
|
| + connector()->BindInterface("test", &service_);
|
| + }
|
| +
|
| + protected:
|
| + mojom::ServicePtr service_;
|
| +};
|
| +
|
| +class MockReceiver : public mojom::Receiver {
|
| + public:
|
| + MockReceiver(mojom::ReceiverRequest request)
|
| + : binding_(this, std::move(request)) {}
|
| + ~MockReceiver() override {}
|
| +
|
| + // Use forwarding method to work around gmock not supporting move-only types.
|
| + void ReceiveBufferHandle(
|
| + mojo::ScopedSharedBufferHandle buffer_handle) override {
|
| + DoReceiveBufferHandle(&buffer_handle);
|
| + }
|
| +
|
| + MOCK_METHOD1(DoReceiveBufferHandle, void(mojo::ScopedSharedBufferHandle*));
|
| +
|
| + private:
|
| + const mojo::Binding<mojom::Receiver> binding_;
|
| +};
|
| +
|
| +TEST_F(TestServiceTest, ReceiveTestBufferHandle) {
|
| + base::RunLoop wait_loop;
|
| + mojom::ReceiverPtr receiver_proxy;
|
| + MockReceiver receiver(mojo::MakeRequest(&receiver_proxy));
|
| + EXPECT_CALL(receiver, DoReceiveBufferHandle(_))
|
| + .WillOnce(InvokeWithoutArgs([&wait_loop]() { wait_loop.Quit(); }));
|
| + service_->ShareBufferToTestReceiver(std::move(receiver_proxy));
|
| + wait_loop.Run();
|
| +}
|
| +
|
| +} // namespace test
|
|
|