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

Side by Side Diff: mojo/system/remote_message_pipe_posix_unittest.cc

Issue 140403002: Mojo: Add the ability to hook up a channel to the embedder API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « mojo/system/raw_channel_posix_unittest.cc ('k') | mojo/system/test_embedder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(vtl): The POSIX-specific bits have been factored out. Apply this test to 5 // TODO(vtl): The POSIX-specific bits have been factored out. Apply this test to
6 // non-POSIX once we have a non-POSIX implementation. 6 // non-POSIX once we have a non-POSIX implementation.
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/callback.h"
14 #include "base/location.h" 13 #include "base/location.h"
15 #include "base/logging.h" 14 #include "base/logging.h"
16 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
17 #include "base/threading/thread.h" 16 #include "base/threading/thread.h"
18 #include "mojo/system/channel.h" 17 #include "mojo/system/channel.h"
19 #include "mojo/system/local_message_pipe_endpoint.h" 18 #include "mojo/system/local_message_pipe_endpoint.h"
20 #include "mojo/system/message_pipe.h" 19 #include "mojo/system/message_pipe.h"
21 #include "mojo/system/platform_channel_pair.h" 20 #include "mojo/system/platform_channel_pair.h"
22 #include "mojo/system/proxy_message_pipe_endpoint.h" 21 #include "mojo/system/proxy_message_pipe_endpoint.h"
23 #include "mojo/system/scoped_platform_handle.h" 22 #include "mojo/system/scoped_platform_handle.h"
24 #include "mojo/system/test_utils.h" 23 #include "mojo/system/test_utils.h"
25 #include "mojo/system/waiter.h" 24 #include "mojo/system/waiter.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 25
28 namespace mojo { 26 namespace mojo {
29 namespace system { 27 namespace system {
30 namespace { 28 namespace {
31 29
32 class RemoteMessagePipeTest : public testing::Test { 30 class RemoteMessagePipeTest : public test::TestWithIOThreadBase {
33 public: 31 public:
34 RemoteMessagePipeTest() : io_thread_("io_thread") { 32 RemoteMessagePipeTest() {}
35 } 33 virtual ~RemoteMessagePipeTest() {}
36
37 virtual ~RemoteMessagePipeTest() {
38 }
39 34
40 virtual void SetUp() OVERRIDE { 35 virtual void SetUp() OVERRIDE {
41 io_thread_.StartWithOptions( 36 test::TestWithIOThreadBase::SetUp();
42 base::Thread::Options(base::MessageLoop::TYPE_IO, 0));
43
44 test::PostTaskAndWait(io_thread_task_runner(), 37 test::PostTaskAndWait(io_thread_task_runner(),
45 FROM_HERE, 38 FROM_HERE,
46 base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread, 39 base::Bind(&RemoteMessagePipeTest::SetUpOnIOThread,
47 base::Unretained(this))); 40 base::Unretained(this)));
48 } 41 }
49 42
50 virtual void TearDown() OVERRIDE { 43 virtual void TearDown() OVERRIDE {
51 test::PostTaskAndWait(io_thread_task_runner(), 44 test::PostTaskAndWait(io_thread_task_runner(),
52 FROM_HERE, 45 FROM_HERE,
53 base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread, 46 base::Bind(&RemoteMessagePipeTest::TearDownOnIOThread,
54 base::Unretained(this))); 47 base::Unretained(this)));
55 io_thread_.Stop(); 48 test::TestWithIOThreadBase::TearDown();
56 } 49 }
57 50
58 // This connects MP 0, port 1 and MP 1, port 0 (leaving MP 0, port 0 and MP 1, 51 // This connects MP 0, port 1 and MP 1, port 0 (leaving MP 0, port 0 and MP 1,
59 // port 1 as the user-visible endpoints) to channel 0 and 1, respectively. MP 52 // port 1 as the user-visible endpoints) to channel 0 and 1, respectively. MP
60 // 0, port 1 and MP 1, port 0 must have |ProxyMessagePipeEndpoint|s. 53 // 0, port 1 and MP 1, port 0 must have |ProxyMessagePipeEndpoint|s.
61 void ConnectMessagePipes(scoped_refptr<MessagePipe> mp_0, 54 void ConnectMessagePipes(scoped_refptr<MessagePipe> mp_0,
62 scoped_refptr<MessagePipe> mp_1) { 55 scoped_refptr<MessagePipe> mp_1) {
63 test::PostTaskAndWait( 56 test::PostTaskAndWait(
64 io_thread_task_runner(), 57 io_thread_task_runner(),
65 FROM_HERE, 58 FROM_HERE,
66 base::Bind(&RemoteMessagePipeTest::ConnectMessagePipesOnIOThread, 59 base::Bind(&RemoteMessagePipeTest::ConnectMessagePipesOnIOThread,
67 base::Unretained(this), mp_0, mp_1)); 60 base::Unretained(this), mp_0, mp_1));
68 } 61 }
69 62
70 // This connects |mp|'s port |channel_index ^ 1| to channel |channel_index|. 63 // This connects |mp|'s port |channel_index ^ 1| to channel |channel_index|.
71 // It assumes/requires that this is the bootstrap case, i.e., that the 64 // It assumes/requires that this is the bootstrap case, i.e., that the
72 // endpoint IDs are both/will both be |Channel::kBootstrapEndpointId|. This 65 // endpoint IDs are both/will both be |Channel::kBootstrapEndpointId|. This
73 // returns *without* waiting for it to finish connecting. 66 // returns *without* waiting for it to finish connecting.
74 void BootstrapMessagePipeNoWait(unsigned channel_index, 67 void BootstrapMessagePipeNoWait(unsigned channel_index,
75 scoped_refptr<MessagePipe> mp) { 68 scoped_refptr<MessagePipe> mp) {
76 io_thread_task_runner()->PostTask( 69 io_thread_task_runner()->PostTask(
77 FROM_HERE, 70 FROM_HERE,
78 base::Bind(&RemoteMessagePipeTest::BootstrapMessagePipeOnIOThread, 71 base::Bind(&RemoteMessagePipeTest::BootstrapMessagePipeOnIOThread,
79 base::Unretained(this), channel_index, mp)); 72 base::Unretained(this), channel_index, mp));
80 } 73 }
81 74
82 protected:
83 base::MessageLoop* io_thread_message_loop() {
84 return io_thread_.message_loop();
85 }
86
87 scoped_refptr<base::TaskRunner> io_thread_task_runner() {
88 return io_thread_message_loop()->message_loop_proxy();
89 }
90
91 private: 75 private:
92 void SetUpOnIOThread() { 76 void SetUpOnIOThread() {
93 CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop()); 77 CHECK_EQ(base::MessageLoop::current(), io_thread_message_loop());
94 78
95 PlatformChannelPair channel_pair; 79 PlatformChannelPair channel_pair;
96 platform_handles_[0] = channel_pair.PassServerHandle(); 80 platform_handles_[0] = channel_pair.PassServerHandle();
97 platform_handles_[1] = channel_pair.PassClientHandle(); 81 platform_handles_[1] = channel_pair.PassClientHandle();
98 } 82 }
99 83
100 void CreateAndInitChannel(unsigned channel_index) { 84 void CreateAndInitChannel(unsigned channel_index) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (channels_[0].get()) { 128 if (channels_[0].get()) {
145 channels_[0]->Shutdown(); 129 channels_[0]->Shutdown();
146 channels_[0] = NULL; 130 channels_[0] = NULL;
147 } 131 }
148 if (channels_[1].get()) { 132 if (channels_[1].get()) {
149 channels_[1]->Shutdown(); 133 channels_[1]->Shutdown();
150 channels_[1] = NULL; 134 channels_[1] = NULL;
151 } 135 }
152 } 136 }
153 137
154 base::Thread io_thread_;
155 ScopedPlatformHandle platform_handles_[2]; 138 ScopedPlatformHandle platform_handles_[2];
156 scoped_refptr<Channel> channels_[2]; 139 scoped_refptr<Channel> channels_[2];
157 140
158 DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest); 141 DISALLOW_COPY_AND_ASSIGN(RemoteMessagePipeTest);
159 }; 142 };
160 143
161 TEST_F(RemoteMessagePipeTest, Basic) { 144 TEST_F(RemoteMessagePipeTest, Basic) {
162 const char hello[] = "hello"; 145 const char hello[] = "hello";
163 const char world[] = "world!!!1!!!1!"; 146 const char world[] = "world!!!1!!!1!";
164 char buffer[100] = { 0 }; 147 char buffer[100] = { 0 };
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 MOJO_READ_MESSAGE_FLAG_NONE)); 400 MOJO_READ_MESSAGE_FLAG_NONE));
418 EXPECT_EQ(sizeof(hello), static_cast<size_t>(buffer_size)); 401 EXPECT_EQ(sizeof(hello), static_cast<size_t>(buffer_size));
419 EXPECT_EQ(0, strcmp(buffer, hello)); 402 EXPECT_EQ(0, strcmp(buffer, hello));
420 403
421 // And MP 1, port 1. 404 // And MP 1, port 1.
422 mp_1->Close(1); 405 mp_1->Close(1);
423 } 406 }
424 } // namespace 407 } // namespace
425 } // namespace system 408 } // namespace system
426 } // namespace mojo 409 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/raw_channel_posix_unittest.cc ('k') | mojo/system/test_embedder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698