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

Unified Diff: mojo/edk/embedder/embedder_test_util.h

Issue 728783003: Add infrastructure to run tests on android. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Use file_hash Created 6 years, 1 month 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
Index: mojo/edk/embedder/embedder_test_util.h
diff --git a/mojo/edk/embedder/embedder_test_util.h b/mojo/edk/embedder/embedder_test_util.h
new file mode 100644
index 0000000000000000000000000000000000000000..bf0f96ae54d66432d878b46eba2612a9c31b6855
--- /dev/null
+++ b/mojo/edk/embedder/embedder_test_util.h
@@ -0,0 +1,83 @@
+// Copyright 2014 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.
+
+#ifndef MOJO_EDK_EMBEDDER_EMBEDDER_TEST_UTIL_H_
+#define MOJO_EDK_EMBEDDER_EMBEDDER_TEST_UTIL_H_
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/synchronization/waitable_event.h"
+#include "base/task_runner.h"
+#include "base/test/test_io_thread.h"
+#include "mojo/edk/embedder/channel_info_forward.h"
+#include "mojo/edk/embedder/platform_channel_pair.h"
+#include "mojo/public/c/system/core.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace mojo {
+namespace embedder {
+
+class ScopedTestChannel {
+ public:
+ // Creates a channel that lives on a given I/O thread (determined by the given
+ // |TaskRunner|) attached to the given |platform_handle|. After construction,
+ // |bootstrap_message_pipe()| gives the Mojo handle for the bootstrap message
+ // pipe on this channel; it is up to the caller to close this handle.
+ // Note: The I/O thread must outlive this object (and its message loop must
+ // continue pumping messages while this object is alive).
+ ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner,
+ ScopedPlatformHandle platform_handle);
+
+ // Destructor: Shuts down the channel. (As noted above, for this to happen,
+ // the I/O thread must be alive and pumping messages.)
+ ~ScopedTestChannel();
+
+ // Waits for channel creation to be completed.
+ void WaitForChannelCreationCompletion();
+
+ MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; }
+
+ // Call only after |WaitForChannelCreationCompletion()|. Use only to check
+ // that it's not null.
+ const ChannelInfo* channel_info() const { return channel_info_; }
+
+ private:
+ void DidCreateChannel(ChannelInfo* channel_info);
+
+ scoped_refptr<base::TaskRunner> io_thread_task_runner_;
+
+ // Valid from creation until whenever it gets closed (by the "owner" of this
+ // object).
+ // Note: We don't want use the C++ wrappers here, since we want to test the
+ // API at the lowest level.
+ MojoHandle bootstrap_message_pipe_;
+
+ // Set after channel creation has been completed (i.e., the callback to
+ // |CreateChannel()| has been called).
+ base::WaitableEvent did_create_channel_event_;
+
+ // Valid after channel creation completion until destruction.
+ ChannelInfo* channel_info_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedTestChannel);
+};
+
+class EmbedderTest : public testing::Test {
+ public:
+ EmbedderTest();
+ ~EmbedderTest() override;
+
+ protected:
+ base::TestIOThread* test_io_thread() { return &test_io_thread_; }
+
+ private:
+ base::TestIOThread test_io_thread_;
+
+ DISALLOW_COPY_AND_ASSIGN(EmbedderTest);
+};
+
+} // namespace embedder
+} // namespace mojo
+
+#endif // MOJO_EDK_EMBEDDER_EMBEDDER_TEST_UTIL_H_

Powered by Google App Engine
This is Rietveld 408576698