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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 #ifndef MOJO_EDK_EMBEDDER_EMBEDDER_TEST_UTIL_H_
6 #define MOJO_EDK_EMBEDDER_EMBEDDER_TEST_UTIL_H_
7
8 #include "base/macros.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/synchronization/waitable_event.h"
11 #include "base/task_runner.h"
12 #include "base/test/test_io_thread.h"
13 #include "mojo/edk/embedder/channel_info_forward.h"
14 #include "mojo/edk/embedder/platform_channel_pair.h"
15 #include "mojo/public/c/system/core.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace mojo {
19 namespace embedder {
20
21 class ScopedTestChannel {
22 public:
23 // Creates a channel that lives on a given I/O thread (determined by the given
24 // |TaskRunner|) attached to the given |platform_handle|. After construction,
25 // |bootstrap_message_pipe()| gives the Mojo handle for the bootstrap message
26 // pipe on this channel; it is up to the caller to close this handle.
27 // Note: The I/O thread must outlive this object (and its message loop must
28 // continue pumping messages while this object is alive).
29 ScopedTestChannel(scoped_refptr<base::TaskRunner> io_thread_task_runner,
30 ScopedPlatformHandle platform_handle);
31
32 // Destructor: Shuts down the channel. (As noted above, for this to happen,
33 // the I/O thread must be alive and pumping messages.)
34 ~ScopedTestChannel();
35
36 // Waits for channel creation to be completed.
37 void WaitForChannelCreationCompletion();
38
39 MojoHandle bootstrap_message_pipe() const { return bootstrap_message_pipe_; }
40
41 // Call only after |WaitForChannelCreationCompletion()|. Use only to check
42 // that it's not null.
43 const ChannelInfo* channel_info() const { return channel_info_; }
44
45 private:
46 void DidCreateChannel(ChannelInfo* channel_info);
47
48 scoped_refptr<base::TaskRunner> io_thread_task_runner_;
49
50 // Valid from creation until whenever it gets closed (by the "owner" of this
51 // object).
52 // Note: We don't want use the C++ wrappers here, since we want to test the
53 // API at the lowest level.
54 MojoHandle bootstrap_message_pipe_;
55
56 // Set after channel creation has been completed (i.e., the callback to
57 // |CreateChannel()| has been called).
58 base::WaitableEvent did_create_channel_event_;
59
60 // Valid after channel creation completion until destruction.
61 ChannelInfo* channel_info_;
62
63 DISALLOW_COPY_AND_ASSIGN(ScopedTestChannel);
64 };
65
66 class EmbedderTest : public testing::Test {
67 public:
68 EmbedderTest();
69 ~EmbedderTest() override;
70
71 protected:
72 base::TestIOThread* test_io_thread() { return &test_io_thread_; }
73
74 private:
75 base::TestIOThread test_io_thread_;
76
77 DISALLOW_COPY_AND_ASSIGN(EmbedderTest);
78 };
79
80 } // namespace embedder
81 } // namespace mojo
82
83 #endif // MOJO_EDK_EMBEDDER_EMBEDDER_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698