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

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

Issue 588193004: Mojo: Have |ProxyMessagePipeEndpoint|s constructed with a |ChannelEndpoint|. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « mojo/embedder/embedder.cc ('k') | mojo/system/message_pipe.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 2014 The Chromium Authors. All rights reserved. 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 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 #include "mojo/system/channel.h" 5 #include "mojo/system/channel.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/test/test_io_thread.h" 10 #include "base/test/test_io_thread.h"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 io_thread()->PostTaskAndWait(FROM_HERE, 187 io_thread()->PostTaskAndWait(FROM_HERE,
188 base::Bind(&ChannelTest::CreateChannelOnIOThread, 188 base::Bind(&ChannelTest::CreateChannelOnIOThread,
189 base::Unretained(this))); 189 base::Unretained(this)));
190 ASSERT_TRUE(channel()); 190 ASSERT_TRUE(channel());
191 191
192 io_thread()->PostTaskAndWait( 192 io_thread()->PostTaskAndWait(
193 FROM_HERE, 193 FROM_HERE,
194 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); 194 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this)));
195 EXPECT_EQ(TRISTATE_TRUE, init_result()); 195 EXPECT_EQ(TRISTATE_TRUE, init_result());
196 196
197 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); 197 scoped_refptr<ChannelEndpoint> channel_endpoint;
198 scoped_refptr<MessagePipe> mp(
199 MessagePipe::CreateLocalProxy(&channel_endpoint));
198 200
199 MessageInTransit::EndpointId local_id = channel()->AttachEndpoint( 201 MessageInTransit::EndpointId local_id =
200 make_scoped_refptr(new ChannelEndpoint(mp.get(), 1))); 202 channel()->AttachEndpoint(channel_endpoint);
201 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); 203 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id);
202 204
203 mp->Close(0); 205 mp->Close(0);
204 206
205 // TODO(vtl): Currently, the |Close()| above won't detach (since it thinks 207 // TODO(vtl): Currently, the |Close()| above won't detach (since it thinks
206 // we're still expecting a "run" message from the other side), so the 208 // we're still expecting a "run" message from the other side), so the
207 // |RunMessagePipeEndpoint()| below will return true. We need to refactor 209 // |RunMessagePipeEndpoint()| below will return true. We need to refactor
208 // |AttachEndpoint()| to indicate whether |Run...()| will necessarily be 210 // |AttachEndpoint()| to indicate whether |Run...()| will necessarily be
209 // called or not. (Then, in the case that it may not be called, this will 211 // called or not. (Then, in the case that it may not be called, this will
210 // return false.) 212 // return false.)
(...skipping 14 matching lines...) Expand all
225 io_thread()->PostTaskAndWait(FROM_HERE, 227 io_thread()->PostTaskAndWait(FROM_HERE,
226 base::Bind(&ChannelTest::CreateChannelOnIOThread, 228 base::Bind(&ChannelTest::CreateChannelOnIOThread,
227 base::Unretained(this))); 229 base::Unretained(this)));
228 ASSERT_TRUE(channel()); 230 ASSERT_TRUE(channel());
229 231
230 io_thread()->PostTaskAndWait( 232 io_thread()->PostTaskAndWait(
231 FROM_HERE, 233 FROM_HERE,
232 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); 234 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this)));
233 EXPECT_EQ(TRISTATE_TRUE, init_result()); 235 EXPECT_EQ(TRISTATE_TRUE, init_result());
234 236
235 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); 237 scoped_refptr<ChannelEndpoint> channel_endpoint;
238 scoped_refptr<MessagePipe> mp(
239 MessagePipe::CreateLocalProxy(&channel_endpoint));
236 240
237 MessageInTransit::EndpointId local_id = channel()->AttachEndpoint( 241 MessageInTransit::EndpointId local_id =
238 make_scoped_refptr(new ChannelEndpoint(mp.get(), 1))); 242 channel()->AttachEndpoint(channel_endpoint);
239 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); 243 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id);
240 244
241 // TODO(vtl): Currently, we always "expect" a |RunMessagePipeEndpoint()| after 245 // TODO(vtl): Currently, we always "expect" a |RunMessagePipeEndpoint()| after
242 // an |AttachEndpoint()| (which is actually incorrect). We need to refactor 246 // an |AttachEndpoint()| (which is actually incorrect). We need to refactor
243 // |AttachEndpoint()| to indicate whether |Run...()| will necessarily be 247 // |AttachEndpoint()| to indicate whether |Run...()| will necessarily be
244 // called or not. (Then, in the case that it may not be called, we should test 248 // called or not. (Then, in the case that it may not be called, we should test
245 // a |Shutdown()| without the |Run...()|.) 249 // a |Shutdown()| without the |Run...()|.)
246 EXPECT_TRUE(channel()->RunMessagePipeEndpoint(local_id, 250 EXPECT_TRUE(channel()->RunMessagePipeEndpoint(local_id,
247 Channel::kBootstrapEndpointId)); 251 Channel::kBootstrapEndpointId));
248 252
(...skipping 26 matching lines...) Expand all
275 io_thread()->PostTaskAndWait(FROM_HERE, 279 io_thread()->PostTaskAndWait(FROM_HERE,
276 base::Bind(&ChannelTest::CreateChannelOnIOThread, 280 base::Bind(&ChannelTest::CreateChannelOnIOThread,
277 base::Unretained(this))); 281 base::Unretained(this)));
278 ASSERT_TRUE(channel()); 282 ASSERT_TRUE(channel());
279 283
280 io_thread()->PostTaskAndWait( 284 io_thread()->PostTaskAndWait(
281 FROM_HERE, 285 FROM_HERE,
282 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this))); 286 base::Bind(&ChannelTest::InitChannelOnIOThread, base::Unretained(this)));
283 EXPECT_EQ(TRISTATE_TRUE, init_result()); 287 EXPECT_EQ(TRISTATE_TRUE, init_result());
284 288
285 scoped_refptr<MessagePipe> mp(MessagePipe::CreateLocalProxy()); 289 scoped_refptr<ChannelEndpoint> channel_endpoint;
290 scoped_refptr<MessagePipe> mp(
291 MessagePipe::CreateLocalProxy(&channel_endpoint));
286 292
287 MessageInTransit::EndpointId local_id = channel()->AttachEndpoint( 293 MessageInTransit::EndpointId local_id =
288 make_scoped_refptr(new ChannelEndpoint(mp.get(), 1))); 294 channel()->AttachEndpoint(channel_endpoint);
289 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id); 295 EXPECT_EQ(Channel::kBootstrapEndpointId, local_id);
290 296
291 EXPECT_TRUE(channel()->RunMessagePipeEndpoint(local_id, 297 EXPECT_TRUE(channel()->RunMessagePipeEndpoint(local_id,
292 Channel::kBootstrapEndpointId)); 298 Channel::kBootstrapEndpointId));
293 299
294 io_thread()->PostTaskAndWait( 300 io_thread()->PostTaskAndWait(
295 FROM_HERE, 301 FROM_HERE,
296 base::Bind(&ChannelTest::ShutdownChannelOnIOThread, 302 base::Bind(&ChannelTest::ShutdownChannelOnIOThread,
297 base::Unretained(this))); 303 base::Unretained(this)));
298 304
299 Waiter waiter; 305 Waiter waiter;
300 waiter.Init(); 306 waiter.Init();
301 HandleSignalsState hss; 307 HandleSignalsState hss;
302 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, 308 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION,
303 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, &hss)); 309 mp->AddWaiter(0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 123, &hss));
304 EXPECT_EQ(0u, hss.satisfied_signals); 310 EXPECT_EQ(0u, hss.satisfied_signals);
305 EXPECT_EQ(0u, hss.satisfiable_signals); 311 EXPECT_EQ(0u, hss.satisfiable_signals);
306 312
307 mp->Close(0); 313 mp->Close(0);
308 314
309 EXPECT_TRUE(channel()->HasOneRef()); 315 EXPECT_TRUE(channel()->HasOneRef());
310 } 316 }
311 317
312 // TODO(vtl): More. ------------------------------------------------------------ 318 // TODO(vtl): More. ------------------------------------------------------------
313 319
314 } // namespace 320 } // namespace
315 } // namespace system 321 } // namespace system
316 } // namespace mojo 322 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/embedder/embedder.cc ('k') | mojo/system/message_pipe.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698