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

Unified Diff: services/test/service_unittest.cc

Issue 2829003005: Test service as minimum repro for sharing memory handle (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/test/service_manifest.json ('k') | services/test/service_unittest_manifest.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « services/test/service_manifest.json ('k') | services/test/service_unittest_manifest.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698