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

Side by Side Diff: ipc/mojo/ipc_channel_mojo_unittest.cc

Issue 954643002: Update mojo sdk to rev 3d23dae011859a2aae49f1d1adde705c8e85d819 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use run_renderer_in_process() Created 5 years, 9 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 | « ipc/mojo/ipc_channel_mojo.cc ('k') | ipc/mojo/ipc_mojo.gyp » ('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 "ipc/mojo/ipc_channel_mojo.h" 5 #include "ipc/mojo/ipc_channel_mojo.h"
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 #include "base/files/file.h" 8 #include "base/files/file.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/pickle.h" 11 #include "base/pickle.h"
12 #include "base/run_loop.h"
12 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
13 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
14 #include "ipc/ipc_message.h" 15 #include "ipc/ipc_message.h"
15 #include "ipc/ipc_test_base.h" 16 #include "ipc/ipc_test_base.h"
16 #include "ipc/ipc_test_channel_listener.h" 17 #include "ipc/ipc_test_channel_listener.h"
17 #include "ipc/mojo/ipc_channel_mojo_host.h" 18 #include "ipc/mojo/ipc_channel_mojo_host.h"
18 #include "ipc/mojo/ipc_mojo_handle_attachment.h" 19 #include "ipc/mojo/ipc_mojo_handle_attachment.h"
19 #include "ipc/mojo/ipc_mojo_message_helper.h" 20 #include "ipc/mojo/ipc_mojo_message_helper.h"
21 #include "ipc/mojo/scoped_ipc_support.h"
20 22
21 #if defined(OS_POSIX) 23 #if defined(OS_POSIX)
22 #include "base/file_descriptor_posix.h" 24 #include "base/file_descriptor_posix.h"
23 #include "ipc/ipc_platform_file_attachment_posix.h" 25 #include "ipc/ipc_platform_file_attachment_posix.h"
24 #endif 26 #endif
25 27
26 namespace { 28 namespace {
27 29
28 class ListenerThatExpectsOK : public IPC::Listener { 30 class ListenerThatExpectsOK : public IPC::Listener {
29 public: 31 public:
(...skipping 26 matching lines...) Expand all
56 ASSERT_TRUE(sender->Send(message)); 58 ASSERT_TRUE(sender->Send(message));
57 } 59 }
58 60
59 private: 61 private:
60 bool received_ok_; 62 bool received_ok_;
61 }; 63 };
62 64
63 class ChannelClient { 65 class ChannelClient {
64 public: 66 public:
65 explicit ChannelClient(IPC::Listener* listener, const char* name) { 67 explicit ChannelClient(IPC::Listener* listener, const char* name) {
68 ipc_support_.reset(
69 new IPC::ScopedIPCSupport(main_message_loop_.task_runner()));
66 channel_ = IPC::ChannelMojo::Create(NULL, 70 channel_ = IPC::ChannelMojo::Create(NULL,
67 IPCTestBase::GetChannelName(name), 71 IPCTestBase::GetChannelName(name),
68 IPC::Channel::MODE_CLIENT, 72 IPC::Channel::MODE_CLIENT,
69 listener); 73 listener);
70 } 74 }
71 75
72 void Connect() { 76 void Connect() {
73 CHECK(channel_->Connect()); 77 CHECK(channel_->Connect());
74 } 78 }
75 79
80 void Close() {
81 channel_->Close();
82
83 base::RunLoop run_loop;
84 base::MessageLoop::current()->PostTask(FROM_HERE, run_loop.QuitClosure());
85 run_loop.Run();
86 }
87
76 IPC::ChannelMojo* channel() const { return channel_.get(); } 88 IPC::ChannelMojo* channel() const { return channel_.get(); }
77 89
78 private: 90 private:
79 base::MessageLoopForIO main_message_loop_; 91 base::MessageLoopForIO main_message_loop_;
92 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_;
80 scoped_ptr<IPC::ChannelMojo> channel_; 93 scoped_ptr<IPC::ChannelMojo> channel_;
81 }; 94 };
82 95
83 class IPCChannelMojoTest : public IPCTestBase { 96 class IPCChannelMojoTestBase : public IPCTestBase {
97 public:
98 void InitWithMojo(const std::string& test_client_name) {
99 Init(test_client_name);
100 ipc_support_.reset(new IPC::ScopedIPCSupport(task_runner()));
101 }
102
103 void TearDown() override {
104 // Make sure Mojo IPC support is properly shutdown on the I/O loop before
105 // TearDown continues.
106 ipc_support_.reset();
107 base::RunLoop run_loop;
108 task_runner()->PostTask(FROM_HERE, run_loop.QuitClosure());
109 run_loop.Run();
110
111 IPCTestBase::TearDown();
112 }
113
114 private:
115 scoped_ptr<IPC::ScopedIPCSupport> ipc_support_;
116 };
117
118 class IPCChannelMojoTest : public IPCChannelMojoTestBase {
84 protected: 119 protected:
85 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( 120 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
86 const IPC::ChannelHandle& handle, 121 const IPC::ChannelHandle& handle,
87 base::TaskRunner* runner) override { 122 base::TaskRunner* runner) override {
88 host_.reset(new IPC::ChannelMojoHost(task_runner())); 123 host_.reset(new IPC::ChannelMojoHost(task_runner()));
89 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), 124 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
90 handle); 125 handle);
91 } 126 }
92 127
93 bool DidStartClient() override { 128 bool DidStartClient() override {
(...skipping 21 matching lines...) Expand all
115 is_connected_called_ = true; 150 is_connected_called_ = true;
116 } 151 }
117 152
118 bool is_connected_called() const { return is_connected_called_; } 153 bool is_connected_called() const { return is_connected_called_; }
119 154
120 private: 155 private:
121 bool is_connected_called_; 156 bool is_connected_called_;
122 }; 157 };
123 158
124 TEST_F(IPCChannelMojoTest, ConnectedFromClient) { 159 TEST_F(IPCChannelMojoTest, ConnectedFromClient) {
125 Init("IPCChannelMojoTestClient"); 160 InitWithMojo("IPCChannelMojoTestClient");
126 161
127 // Set up IPC channel and start client. 162 // Set up IPC channel and start client.
128 TestChannelListenerWithExtraExpectations listener; 163 TestChannelListenerWithExtraExpectations listener;
129 CreateChannel(&listener); 164 CreateChannel(&listener);
130 listener.Init(sender()); 165 listener.Init(sender());
131 ASSERT_TRUE(ConnectChannel()); 166 ASSERT_TRUE(ConnectChannel());
132 ASSERT_TRUE(StartClient()); 167 ASSERT_TRUE(StartClient());
133 168
134 IPC::TestChannelListener::SendOneMessage( 169 IPC::TestChannelListener::SendOneMessage(
135 sender(), "hello from parent"); 170 sender(), "hello from parent");
(...skipping 16 matching lines...) Expand all
152 ChannelClient client(&listener, "IPCChannelMojoTestClient"); 187 ChannelClient client(&listener, "IPCChannelMojoTestClient");
153 client.Connect(); 188 client.Connect();
154 listener.Init(client.channel()); 189 listener.Init(client.channel());
155 190
156 IPC::TestChannelListener::SendOneMessage( 191 IPC::TestChannelListener::SendOneMessage(
157 client.channel(), "hello from child"); 192 client.channel(), "hello from child");
158 base::MessageLoop::current()->Run(); 193 base::MessageLoop::current()->Run();
159 EXPECT_TRUE(listener.is_connected_called()); 194 EXPECT_TRUE(listener.is_connected_called());
160 EXPECT_TRUE(listener.HasSentAll()); 195 EXPECT_TRUE(listener.HasSentAll());
161 196
197 client.Close();
198
162 return 0; 199 return 0;
163 } 200 }
164 201
165 class ListenerExpectingErrors : public IPC::Listener { 202 class ListenerExpectingErrors : public IPC::Listener {
166 public: 203 public:
167 ListenerExpectingErrors() 204 ListenerExpectingErrors()
168 : has_error_(false) { 205 : has_error_(false) {
169 } 206 }
170 207
171 void OnChannelConnected(int32 peer_pid) override { 208 void OnChannelConnected(int32 peer_pid) override {
172 base::MessageLoop::current()->Quit(); 209 base::MessageLoop::current()->Quit();
173 } 210 }
174 211
175 bool OnMessageReceived(const IPC::Message& message) override { return true; } 212 bool OnMessageReceived(const IPC::Message& message) override { return true; }
176 213
177 void OnChannelError() override { 214 void OnChannelError() override {
178 has_error_ = true; 215 has_error_ = true;
179 base::MessageLoop::current()->Quit(); 216 base::MessageLoop::current()->Quit();
180 } 217 }
181 218
182 bool has_error() const { return has_error_; } 219 bool has_error() const { return has_error_; }
183 220
184 private: 221 private:
185 bool has_error_; 222 bool has_error_;
186 }; 223 };
187 224
188 225
189 class IPCChannelMojoErrorTest : public IPCTestBase { 226 class IPCChannelMojoErrorTest : public IPCChannelMojoTestBase {
190 protected: 227 protected:
191 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( 228 scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
192 const IPC::ChannelHandle& handle, 229 const IPC::ChannelHandle& handle,
193 base::TaskRunner* runner) override { 230 base::TaskRunner* runner) override {
194 host_.reset(new IPC::ChannelMojoHost(task_runner())); 231 host_.reset(new IPC::ChannelMojoHost(task_runner()));
195 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), 232 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
196 handle); 233 handle);
197 } 234 }
198 235
199 bool DidStartClient() override { 236 bool DidStartClient() override {
(...skipping 22 matching lines...) Expand all
222 }; 259 };
223 260
224 // A long running process that connects to us. 261 // A long running process that connects to us.
225 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoErraticTestClient) { 262 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoErraticTestClient) {
226 ListenerThatQuits listener; 263 ListenerThatQuits listener;
227 ChannelClient client(&listener, "IPCChannelMojoErraticTestClient"); 264 ChannelClient client(&listener, "IPCChannelMojoErraticTestClient");
228 client.Connect(); 265 client.Connect();
229 266
230 base::MessageLoop::current()->Run(); 267 base::MessageLoop::current()->Run();
231 268
269 client.Close();
270
232 return 0; 271 return 0;
233 } 272 }
234 273
235 TEST_F(IPCChannelMojoErrorTest, SendFailWithPendingMessages) { 274 TEST_F(IPCChannelMojoErrorTest, SendFailWithPendingMessages) {
236 Init("IPCChannelMojoErraticTestClient"); 275 InitWithMojo("IPCChannelMojoErraticTestClient");
237 276
238 // Set up IPC channel and start client. 277 // Set up IPC channel and start client.
239 ListenerExpectingErrors listener; 278 ListenerExpectingErrors listener;
240 CreateChannel(&listener); 279 CreateChannel(&listener);
241 ASSERT_TRUE(ConnectChannel()); 280 ASSERT_TRUE(ConnectChannel());
242 281
243 // This matches a value in mojo/edk/system/constants.h 282 // This matches a value in mojo/edk/system/constants.h
244 const int kMaxMessageNumBytes = 4 * 1024 * 1024; 283 const int kMaxMessageNumBytes = 4 * 1024 * 1024;
245 std::string overly_large_data(kMaxMessageNumBytes, '*'); 284 std::string overly_large_data(kMaxMessageNumBytes, '*');
246 // This messages are queued as pending. 285 // This messages are queued as pending.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 405
367 void OnChannelError() override { NOTREACHED(); } 406 void OnChannelError() override { NOTREACHED(); }
368 407
369 void set_sender(IPC::Sender* sender) { sender_ = sender; } 408 void set_sender(IPC::Sender* sender) { sender_ = sender; }
370 409
371 private: 410 private:
372 IPC::Sender* sender_; 411 IPC::Sender* sender_;
373 }; 412 };
374 413
375 TEST_F(IPCChannelMojoTest, SendMessagePipe) { 414 TEST_F(IPCChannelMojoTest, SendMessagePipe) {
376 Init("IPCChannelMojoTestSendMessagePipeClient"); 415 InitWithMojo("IPCChannelMojoTestSendMessagePipeClient");
377 416
378 ListenerThatExpectsOK listener; 417 ListenerThatExpectsOK listener;
379 CreateChannel(&listener); 418 CreateChannel(&listener);
380 ASSERT_TRUE(ConnectChannel()); 419 ASSERT_TRUE(ConnectChannel());
381 ASSERT_TRUE(StartClient()); 420 ASSERT_TRUE(StartClient());
382 421
383 TestingMessagePipe pipe; 422 TestingMessagePipe pipe;
384 HandleSendingHelper::WritePipeThenSend(channel(), &pipe); 423 HandleSendingHelper::WritePipeThenSend(channel(), &pipe);
385 424
386 base::MessageLoop::current()->Run(); 425 base::MessageLoop::current()->Run();
387 this->channel()->Close(); 426 this->channel()->Close();
388 427
389 EXPECT_TRUE(WaitForClientShutdown()); 428 EXPECT_TRUE(WaitForClientShutdown());
390 DestroyChannel(); 429 DestroyChannel();
391 } 430 }
392 431
393 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestSendMessagePipeClient) { 432 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestSendMessagePipeClient) {
394 ListenerThatExpectsMessagePipe listener; 433 ListenerThatExpectsMessagePipe listener;
395 ChannelClient client(&listener, "IPCChannelMojoTestSendPlatformHandleClient"); 434 ChannelClient client(&listener, "IPCChannelMojoTestSendPlatformHandleClient");
396 client.Connect(); 435 client.Connect();
397 listener.set_sender(client.channel()); 436 listener.set_sender(client.channel());
398 437
399 base::MessageLoop::current()->Run(); 438 base::MessageLoop::current()->Run();
400 439
440 client.Close();
441
401 return 0; 442 return 0;
402 } 443 }
403 444
404 #if defined(OS_WIN) 445 #if defined(OS_WIN)
405 class IPCChannelMojoDeadHandleTest : public IPCTestBase { 446 class IPCChannelMojoDeadHandleTest : public IPCChannelMojoTestBase {
406 protected: 447 protected:
407 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory( 448 virtual scoped_ptr<IPC::ChannelFactory> CreateChannelFactory(
408 const IPC::ChannelHandle& handle, 449 const IPC::ChannelHandle& handle,
409 base::TaskRunner* runner) override { 450 base::TaskRunner* runner) override {
410 host_.reset(new IPC::ChannelMojoHost(task_runner())); 451 host_.reset(new IPC::ChannelMojoHost(task_runner()));
411 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(), 452 return IPC::ChannelMojo::CreateServerFactory(host_->channel_delegate(),
412 handle); 453 handle);
413 } 454 }
414 455
415 virtual bool DidStartClient() override { 456 virtual bool DidStartClient() override {
416 IPCTestBase::DidStartClient(); 457 IPCTestBase::DidStartClient();
417 const base::ProcessHandle client = client_process().Handle(); 458 const base::ProcessHandle client = client_process().Handle();
418 // Forces GetFileHandleForProcess() fail. It happens occasionally 459 // Forces GetFileHandleForProcess() fail. It happens occasionally
419 // in production, so we should exercise it somehow. 460 // in production, so we should exercise it somehow.
420 // TODO(morrita): figure out how to safely test this. 461 // TODO(morrita): figure out how to safely test this.
421 // ::CloseHandle(client); 462 // ::CloseHandle(client);
422 host_->OnClientLaunched(client); 463 host_->OnClientLaunched(client);
423 return true; 464 return true;
424 } 465 }
425 466
426 private: 467 private:
427 scoped_ptr<IPC::ChannelMojoHost> host_; 468 scoped_ptr<IPC::ChannelMojoHost> host_;
428 }; 469 };
429 470
430 TEST_F(IPCChannelMojoDeadHandleTest, InvalidClientHandle) { 471 TEST_F(IPCChannelMojoDeadHandleTest, InvalidClientHandle) {
431 // Any client type is fine as it is going to be killed anyway. 472 // Any client type is fine as it is going to be killed anyway.
432 Init("IPCChannelMojoTestDoNothingClient"); 473 InitWithMojo("IPCChannelMojoTestDoNothingClient");
433 474
434 // Set up IPC channel and start client. 475 // Set up IPC channel and start client.
435 ListenerExpectingErrors listener; 476 ListenerExpectingErrors listener;
436 CreateChannel(&listener); 477 CreateChannel(&listener);
437 ASSERT_TRUE(ConnectChannel()); 478 ASSERT_TRUE(ConnectChannel());
438 479
439 ASSERT_TRUE(StartClient()); 480 ASSERT_TRUE(StartClient());
440 base::MessageLoop::current()->Run(); 481 base::MessageLoop::current()->Run();
441 482
442 this->channel()->Close(); 483 this->channel()->Close();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 523 }
483 524
484 void set_sender(IPC::Sender* sender) { sender_ = sender; } 525 void set_sender(IPC::Sender* sender) { sender_ = sender; }
485 526
486 private: 527 private:
487 IPC::Sender* sender_; 528 IPC::Sender* sender_;
488 }; 529 };
489 530
490 531
491 TEST_F(IPCChannelMojoTest, SendPlatformHandle) { 532 TEST_F(IPCChannelMojoTest, SendPlatformHandle) {
492 Init("IPCChannelMojoTestSendPlatformHandleClient"); 533 InitWithMojo("IPCChannelMojoTestSendPlatformHandleClient");
493 534
494 ListenerThatExpectsOK listener; 535 ListenerThatExpectsOK listener;
495 CreateChannel(&listener); 536 CreateChannel(&listener);
496 ASSERT_TRUE(ConnectChannel()); 537 ASSERT_TRUE(ConnectChannel());
497 ASSERT_TRUE(StartClient()); 538 ASSERT_TRUE(StartClient());
498 539
499 base::File file(HandleSendingHelper::GetSendingFilePath(), 540 base::File file(HandleSendingHelper::GetSendingFilePath(),
500 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | 541 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
501 base::File::FLAG_READ); 542 base::File::FLAG_READ);
502 HandleSendingHelper::WriteFileThenSend(channel(), file); 543 HandleSendingHelper::WriteFileThenSend(channel(), file);
503 base::MessageLoop::current()->Run(); 544 base::MessageLoop::current()->Run();
504 545
505 this->channel()->Close(); 546 this->channel()->Close();
506 547
507 EXPECT_TRUE(WaitForClientShutdown()); 548 EXPECT_TRUE(WaitForClientShutdown());
508 DestroyChannel(); 549 DestroyChannel();
509 } 550 }
510 551
511 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestSendPlatformHandleClient) { 552 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestSendPlatformHandleClient) {
512 ListenerThatExpectsFile listener; 553 ListenerThatExpectsFile listener;
513 ChannelClient client( 554 ChannelClient client(
514 &listener, "IPCChannelMojoTestSendPlatformHandleClient"); 555 &listener, "IPCChannelMojoTestSendPlatformHandleClient");
515 client.Connect(); 556 client.Connect();
516 listener.set_sender(client.channel()); 557 listener.set_sender(client.channel());
517 558
518 base::MessageLoop::current()->Run(); 559 base::MessageLoop::current()->Run();
519 560
561 client.Close();
562
520 return 0; 563 return 0;
521 } 564 }
522 565
523 class ListenerThatExpectsFileAndPipe : public IPC::Listener { 566 class ListenerThatExpectsFileAndPipe : public IPC::Listener {
524 public: 567 public:
525 ListenerThatExpectsFileAndPipe() : sender_(NULL) {} 568 ListenerThatExpectsFileAndPipe() : sender_(NULL) {}
526 569
527 ~ListenerThatExpectsFileAndPipe() override {} 570 ~ListenerThatExpectsFileAndPipe() override {}
528 571
529 bool OnMessageReceived(const IPC::Message& message) override { 572 bool OnMessageReceived(const IPC::Message& message) override {
530 PickleIterator iter(message); 573 PickleIterator iter(message);
531 HandleSendingHelper::ReadReceivedFile(message, &iter); 574 HandleSendingHelper::ReadReceivedFile(message, &iter);
532 HandleSendingHelper::ReadReceivedPipe(message, &iter); 575 HandleSendingHelper::ReadReceivedPipe(message, &iter);
533 base::MessageLoop::current()->Quit(); 576 base::MessageLoop::current()->Quit();
534 ListenerThatExpectsOK::SendOK(sender_); 577 ListenerThatExpectsOK::SendOK(sender_);
535 return true; 578 return true;
536 } 579 }
537 580
538 void OnChannelError() override { NOTREACHED(); } 581 void OnChannelError() override { NOTREACHED(); }
539 582
540 void set_sender(IPC::Sender* sender) { sender_ = sender; } 583 void set_sender(IPC::Sender* sender) { sender_ = sender; }
541 584
542 private: 585 private:
543 IPC::Sender* sender_; 586 IPC::Sender* sender_;
544 }; 587 };
545 588
546 TEST_F(IPCChannelMojoTest, SendPlatformHandleAndPipe) { 589 TEST_F(IPCChannelMojoTest, SendPlatformHandleAndPipe) {
547 Init("IPCChannelMojoTestSendPlatformHandleAndPipeClient"); 590 InitWithMojo("IPCChannelMojoTestSendPlatformHandleAndPipeClient");
548 591
549 ListenerThatExpectsOK listener; 592 ListenerThatExpectsOK listener;
550 CreateChannel(&listener); 593 CreateChannel(&listener);
551 ASSERT_TRUE(ConnectChannel()); 594 ASSERT_TRUE(ConnectChannel());
552 ASSERT_TRUE(StartClient()); 595 ASSERT_TRUE(StartClient());
553 596
554 base::File file(HandleSendingHelper::GetSendingFilePath(), 597 base::File file(HandleSendingHelper::GetSendingFilePath(),
555 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | 598 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
556 base::File::FLAG_READ); 599 base::File::FLAG_READ);
557 TestingMessagePipe pipe; 600 TestingMessagePipe pipe;
558 HandleSendingHelper::WriteFileAndPipeThenSend(channel(), file, &pipe); 601 HandleSendingHelper::WriteFileAndPipeThenSend(channel(), file, &pipe);
559 602
560 base::MessageLoop::current()->Run(); 603 base::MessageLoop::current()->Run();
561 this->channel()->Close(); 604 this->channel()->Close();
562 605
563 EXPECT_TRUE(WaitForClientShutdown()); 606 EXPECT_TRUE(WaitForClientShutdown());
564 DestroyChannel(); 607 DestroyChannel();
565 } 608 }
566 609
567 MULTIPROCESS_IPC_TEST_CLIENT_MAIN( 610 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(
568 IPCChannelMojoTestSendPlatformHandleAndPipeClient) { 611 IPCChannelMojoTestSendPlatformHandleAndPipeClient) {
569 ListenerThatExpectsFileAndPipe listener; 612 ListenerThatExpectsFileAndPipe listener;
570 ChannelClient client(&listener, 613 ChannelClient client(&listener,
571 "IPCChannelMojoTestSendPlatformHandleAndPipeClient"); 614 "IPCChannelMojoTestSendPlatformHandleAndPipeClient");
572 client.Connect(); 615 client.Connect();
573 listener.set_sender(client.channel()); 616 listener.set_sender(client.channel());
574 617
575 base::MessageLoop::current()->Run(); 618 base::MessageLoop::current()->Run();
576 619
620 client.Close();
621
577 return 0; 622 return 0;
578 } 623 }
579 624
580 #endif 625 #endif
581 626
582 #if defined(OS_LINUX) 627 #if defined(OS_LINUX)
583 628
584 const base::ProcessId kMagicChildId = 54321; 629 const base::ProcessId kMagicChildId = 54321;
585 630
586 class ListenerThatVerifiesPeerPid : public IPC::Listener { 631 class ListenerThatVerifiesPeerPid : public IPC::Listener {
587 public: 632 public:
588 void OnChannelConnected(int32 peer_pid) override { 633 void OnChannelConnected(int32 peer_pid) override {
589 EXPECT_EQ(peer_pid, kMagicChildId); 634 EXPECT_EQ(peer_pid, kMagicChildId);
590 base::MessageLoop::current()->Quit(); 635 base::MessageLoop::current()->Quit();
591 } 636 }
592 637
593 bool OnMessageReceived(const IPC::Message& message) override { 638 bool OnMessageReceived(const IPC::Message& message) override {
594 NOTREACHED(); 639 NOTREACHED();
595 return true; 640 return true;
596 } 641 }
597 }; 642 };
598 643
599 TEST_F(IPCChannelMojoTest, VerifyGlobalPid) { 644 TEST_F(IPCChannelMojoTest, VerifyGlobalPid) {
600 Init("IPCChannelMojoTestVerifyGlobalPidClient"); 645 InitWithMojo("IPCChannelMojoTestVerifyGlobalPidClient");
601 646
602 ListenerThatVerifiesPeerPid listener; 647 ListenerThatVerifiesPeerPid listener;
603 CreateChannel(&listener); 648 CreateChannel(&listener);
604 ASSERT_TRUE(ConnectChannel()); 649 ASSERT_TRUE(ConnectChannel());
605 ASSERT_TRUE(StartClient()); 650 ASSERT_TRUE(StartClient());
606 651
607 base::MessageLoop::current()->Run(); 652 base::MessageLoop::current()->Run();
608 this->channel()->Close(); 653 channel()->Close();
609 654
610 EXPECT_TRUE(WaitForClientShutdown()); 655 EXPECT_TRUE(WaitForClientShutdown());
611 DestroyChannel(); 656 DestroyChannel();
612 } 657 }
613 658
614 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestVerifyGlobalPidClient) { 659 MULTIPROCESS_IPC_TEST_CLIENT_MAIN(IPCChannelMojoTestVerifyGlobalPidClient) {
615 IPC::Channel::SetGlobalPid(kMagicChildId); 660 IPC::Channel::SetGlobalPid(kMagicChildId);
616 ListenerThatQuits listener; 661 ListenerThatQuits listener;
617 ChannelClient client(&listener, 662 ChannelClient client(&listener,
618 "IPCChannelMojoTestVerifyGlobalPidClient"); 663 "IPCChannelMojoTestVerifyGlobalPidClient");
619 client.Connect(); 664 client.Connect();
620 665
621 base::MessageLoop::current()->Run(); 666 base::MessageLoop::current()->Run();
622 667
668 client.Close();
669
623 return 0; 670 return 0;
624 } 671 }
625 672
626 #endif // OS_LINUX 673 #endif // OS_LINUX
627 674
628 } // namespace 675 } // namespace
OLDNEW
« no previous file with comments | « ipc/mojo/ipc_channel_mojo.cc ('k') | ipc/mojo/ipc_mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698