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

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

Issue 2087163003: Remove calls to deprecated MessageLoop methods in ipc. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: manual changes Created 4 years, 5 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/ipc_sync_channel_unittest.cc ('k') | ipc/sync_socket_unittest.cc » ('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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 InitWithMojo("IPCChannelMojoTestClient"); 175 InitWithMojo("IPCChannelMojoTestClient");
176 176
177 // Set up IPC channel and start client. 177 // Set up IPC channel and start client.
178 TestChannelListenerWithExtraExpectations listener; 178 TestChannelListenerWithExtraExpectations listener;
179 CreateChannel(&listener); 179 CreateChannel(&listener);
180 listener.Init(sender()); 180 listener.Init(sender());
181 ASSERT_TRUE(ConnectChannel()); 181 ASSERT_TRUE(ConnectChannel());
182 182
183 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent"); 183 IPC::TestChannelListener::SendOneMessage(sender(), "hello from parent");
184 184
185 base::MessageLoop::current()->Run(); 185 base::RunLoop().Run();
186 186
187 channel()->Close(); 187 channel()->Close();
188 188
189 EXPECT_TRUE(WaitForClientShutdown()); 189 EXPECT_TRUE(WaitForClientShutdown());
190 EXPECT_TRUE(listener.is_connected_called()); 190 EXPECT_TRUE(listener.is_connected_called());
191 EXPECT_TRUE(listener.HasSentAll()); 191 EXPECT_TRUE(listener.HasSentAll());
192 192
193 DestroyChannel(); 193 DestroyChannel();
194 } 194 }
195 195
196 // A long running process that connects to us 196 // A long running process that connects to us
197 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestClient, ChannelClient) { 197 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestClient, ChannelClient) {
198 TestChannelListenerWithExtraExpectations listener; 198 TestChannelListenerWithExtraExpectations listener;
199 Connect(&listener); 199 Connect(&listener);
200 listener.Init(channel()); 200 listener.Init(channel());
201 201
202 IPC::TestChannelListener::SendOneMessage(channel(), "hello from child"); 202 IPC::TestChannelListener::SendOneMessage(channel(), "hello from child");
203 base::MessageLoop::current()->Run(); 203 base::RunLoop().Run();
204 EXPECT_TRUE(listener.is_connected_called()); 204 EXPECT_TRUE(listener.is_connected_called());
205 EXPECT_TRUE(listener.HasSentAll()); 205 EXPECT_TRUE(listener.HasSentAll());
206 206
207 Close(); 207 Close();
208 } 208 }
209 209
210 class ListenerExpectingErrors : public IPC::Listener { 210 class ListenerExpectingErrors : public IPC::Listener {
211 public: 211 public:
212 ListenerExpectingErrors() : has_error_(false) {} 212 ListenerExpectingErrors() : has_error_(false) {}
213 213
(...skipping 24 matching lines...) Expand all
238 base::MessageLoop::current()->QuitWhenIdle(); 238 base::MessageLoop::current()->QuitWhenIdle();
239 } 239 }
240 }; 240 };
241 241
242 // A long running process that connects to us. 242 // A long running process that connects to us.
243 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoErraticTestClient, 243 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoErraticTestClient,
244 ChannelClient) { 244 ChannelClient) {
245 ListenerThatQuits listener; 245 ListenerThatQuits listener;
246 Connect(&listener); 246 Connect(&listener);
247 247
248 base::MessageLoop::current()->Run(); 248 base::RunLoop().Run();
249 249
250 Close(); 250 Close();
251 } 251 }
252 252
253 TEST_F(IPCChannelMojoTest, SendFailWithPendingMessages) { 253 TEST_F(IPCChannelMojoTest, SendFailWithPendingMessages) {
254 InitWithMojo("IPCChannelMojoErraticTestClient"); 254 InitWithMojo("IPCChannelMojoErraticTestClient");
255 255
256 // Set up IPC channel and start client. 256 // Set up IPC channel and start client.
257 ListenerExpectingErrors listener; 257 ListenerExpectingErrors listener;
258 CreateChannel(&listener); 258 CreateChannel(&listener);
259 ASSERT_TRUE(ConnectChannel()); 259 ASSERT_TRUE(ConnectChannel());
260 260
261 // This matches a value in mojo/edk/system/constants.h 261 // This matches a value in mojo/edk/system/constants.h
262 const int kMaxMessageNumBytes = 4 * 1024 * 1024; 262 const int kMaxMessageNumBytes = 4 * 1024 * 1024;
263 std::string overly_large_data(kMaxMessageNumBytes, '*'); 263 std::string overly_large_data(kMaxMessageNumBytes, '*');
264 // This messages are queued as pending. 264 // This messages are queued as pending.
265 for (size_t i = 0; i < 10; ++i) { 265 for (size_t i = 0; i < 10; ++i) {
266 IPC::TestChannelListener::SendOneMessage(sender(), 266 IPC::TestChannelListener::SendOneMessage(sender(),
267 overly_large_data.c_str()); 267 overly_large_data.c_str());
268 } 268 }
269 269
270 base::MessageLoop::current()->Run(); 270 base::RunLoop().Run();
271 271
272 channel()->Close(); 272 channel()->Close();
273 273
274 EXPECT_TRUE(WaitForClientShutdown()); 274 EXPECT_TRUE(WaitForClientShutdown());
275 EXPECT_TRUE(listener.has_error()); 275 EXPECT_TRUE(listener.has_error());
276 276
277 DestroyChannel(); 277 DestroyChannel();
278 } 278 }
279 279
280 struct TestingMessagePipe { 280 struct TestingMessagePipe {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 TEST_F(IPCChannelMojoTest, SendMessagePipe) { 400 TEST_F(IPCChannelMojoTest, SendMessagePipe) {
401 InitWithMojo("IPCChannelMojoTestSendMessagePipeClient"); 401 InitWithMojo("IPCChannelMojoTestSendMessagePipeClient");
402 402
403 ListenerThatExpectsOK listener; 403 ListenerThatExpectsOK listener;
404 CreateChannel(&listener); 404 CreateChannel(&listener);
405 ASSERT_TRUE(ConnectChannel()); 405 ASSERT_TRUE(ConnectChannel());
406 406
407 TestingMessagePipe pipe; 407 TestingMessagePipe pipe;
408 HandleSendingHelper::WritePipeThenSend(channel(), &pipe); 408 HandleSendingHelper::WritePipeThenSend(channel(), &pipe);
409 409
410 base::MessageLoop::current()->Run(); 410 base::RunLoop().Run();
411 channel()->Close(); 411 channel()->Close();
412 412
413 EXPECT_TRUE(WaitForClientShutdown()); 413 EXPECT_TRUE(WaitForClientShutdown());
414 DestroyChannel(); 414 DestroyChannel();
415 } 415 }
416 416
417 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendMessagePipeClient, 417 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendMessagePipeClient,
418 ChannelClient) { 418 ChannelClient) {
419 ListenerThatExpectsMessagePipe listener; 419 ListenerThatExpectsMessagePipe listener;
420 Connect(&listener); 420 Connect(&listener);
421 listener.set_sender(channel()); 421 listener.set_sender(channel());
422 422
423 base::MessageLoop::current()->Run(); 423 base::RunLoop().Run();
424 424
425 Close(); 425 Close();
426 } 426 }
427 427
428 void ReadOK(mojo::MessagePipeHandle pipe) { 428 void ReadOK(mojo::MessagePipeHandle pipe) {
429 std::string should_be_ok("xx"); 429 std::string should_be_ok("xx");
430 uint32_t num_bytes = static_cast<uint32_t>(should_be_ok.size()); 430 uint32_t num_bytes = static_cast<uint32_t>(should_be_ok.size());
431 CHECK_EQ(MOJO_RESULT_OK, mojo::Wait(pipe, MOJO_HANDLE_SIGNAL_READABLE, 431 CHECK_EQ(MOJO_RESULT_OK, mojo::Wait(pipe, MOJO_HANDLE_SIGNAL_READABLE,
432 MOJO_DEADLINE_INDEFINITE, nullptr)); 432 MOJO_DEADLINE_INDEFINITE, nullptr));
433 CHECK_EQ(MOJO_RESULT_OK, 433 CHECK_EQ(MOJO_RESULT_OK,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 }; 477 };
478 478
479 class ParamTraitMessagePipeClient : public ChannelClient { 479 class ParamTraitMessagePipeClient : public ChannelClient {
480 public: 480 public:
481 void RunTest(bool receiving_valid_handle) { 481 void RunTest(bool receiving_valid_handle) {
482 ListenerThatExpectsMessagePipeUsingParamTrait listener( 482 ListenerThatExpectsMessagePipeUsingParamTrait listener(
483 receiving_valid_handle); 483 receiving_valid_handle);
484 Connect(&listener); 484 Connect(&listener);
485 listener.set_sender(channel()); 485 listener.set_sender(channel());
486 486
487 base::MessageLoop::current()->Run(); 487 base::RunLoop().Run();
488 488
489 Close(); 489 Close();
490 } 490 }
491 }; 491 };
492 492
493 TEST_F(IPCChannelMojoTest, ParamTraitValidMessagePipe) { 493 TEST_F(IPCChannelMojoTest, ParamTraitValidMessagePipe) {
494 InitWithMojo("ParamTraitValidMessagePipeClient"); 494 InitWithMojo("ParamTraitValidMessagePipeClient");
495 495
496 ListenerThatExpectsOK listener; 496 ListenerThatExpectsOK listener;
497 CreateChannel(&listener); 497 CreateChannel(&listener);
498 ASSERT_TRUE(ConnectChannel()); 498 ASSERT_TRUE(ConnectChannel());
499 499
500 TestingMessagePipe pipe; 500 TestingMessagePipe pipe;
501 501
502 std::unique_ptr<IPC::Message> message(new IPC::Message()); 502 std::unique_ptr<IPC::Message> message(new IPC::Message());
503 IPC::ParamTraits<mojo::MessagePipeHandle>::Write(message.get(), 503 IPC::ParamTraits<mojo::MessagePipeHandle>::Write(message.get(),
504 pipe.peer.release()); 504 pipe.peer.release());
505 WriteOK(pipe.self.get()); 505 WriteOK(pipe.self.get());
506 506
507 channel()->Send(message.release()); 507 channel()->Send(message.release());
508 base::MessageLoop::current()->Run(); 508 base::RunLoop().Run();
509 channel()->Close(); 509 channel()->Close();
510 510
511 EXPECT_TRUE(WaitForClientShutdown()); 511 EXPECT_TRUE(WaitForClientShutdown());
512 DestroyChannel(); 512 DestroyChannel();
513 } 513 }
514 514
515 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ParamTraitValidMessagePipeClient, 515 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ParamTraitValidMessagePipeClient,
516 ParamTraitMessagePipeClient) { 516 ParamTraitMessagePipeClient) {
517 RunTest(true); 517 RunTest(true);
518 } 518 }
519 519
520 TEST_F(IPCChannelMojoTest, ParamTraitInvalidMessagePipe) { 520 TEST_F(IPCChannelMojoTest, ParamTraitInvalidMessagePipe) {
521 InitWithMojo("ParamTraitInvalidMessagePipeClient"); 521 InitWithMojo("ParamTraitInvalidMessagePipeClient");
522 522
523 ListenerThatExpectsOK listener; 523 ListenerThatExpectsOK listener;
524 CreateChannel(&listener); 524 CreateChannel(&listener);
525 ASSERT_TRUE(ConnectChannel()); 525 ASSERT_TRUE(ConnectChannel());
526 526
527 mojo::MessagePipeHandle invalid_handle; 527 mojo::MessagePipeHandle invalid_handle;
528 std::unique_ptr<IPC::Message> message(new IPC::Message()); 528 std::unique_ptr<IPC::Message> message(new IPC::Message());
529 IPC::ParamTraits<mojo::MessagePipeHandle>::Write(message.get(), 529 IPC::ParamTraits<mojo::MessagePipeHandle>::Write(message.get(),
530 invalid_handle); 530 invalid_handle);
531 531
532 channel()->Send(message.release()); 532 channel()->Send(message.release());
533 base::MessageLoop::current()->Run(); 533 base::RunLoop().Run();
534 channel()->Close(); 534 channel()->Close();
535 535
536 EXPECT_TRUE(WaitForClientShutdown()); 536 EXPECT_TRUE(WaitForClientShutdown());
537 DestroyChannel(); 537 DestroyChannel();
538 } 538 }
539 539
540 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ParamTraitInvalidMessagePipeClient, 540 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(ParamTraitInvalidMessagePipeClient,
541 ParamTraitMessagePipeClient) { 541 ParamTraitMessagePipeClient) {
542 RunTest(false); 542 RunTest(false);
543 } 543 }
544 544
545 TEST_F(IPCChannelMojoTest, SendFailAfterClose) { 545 TEST_F(IPCChannelMojoTest, SendFailAfterClose) {
546 InitWithMojo("IPCChannelMojoTestSendOkClient"); 546 InitWithMojo("IPCChannelMojoTestSendOkClient");
547 547
548 ListenerThatExpectsOK listener; 548 ListenerThatExpectsOK listener;
549 CreateChannel(&listener); 549 CreateChannel(&listener);
550 ASSERT_TRUE(ConnectChannel()); 550 ASSERT_TRUE(ConnectChannel());
551 551
552 base::MessageLoop::current()->Run(); 552 base::RunLoop().Run();
553 channel()->Close(); 553 channel()->Close();
554 ASSERT_FALSE(channel()->Send(new IPC::Message())); 554 ASSERT_FALSE(channel()->Send(new IPC::Message()));
555 555
556 EXPECT_TRUE(WaitForClientShutdown()); 556 EXPECT_TRUE(WaitForClientShutdown());
557 DestroyChannel(); 557 DestroyChannel();
558 } 558 }
559 559
560 class ListenerSendingOneOk : public IPC::Listener { 560 class ListenerSendingOneOk : public IPC::Listener {
561 public: 561 public:
562 ListenerSendingOneOk() {} 562 ListenerSendingOneOk() {}
(...skipping 10 matching lines...) Expand all
573 private: 573 private:
574 IPC::Sender* sender_; 574 IPC::Sender* sender_;
575 }; 575 };
576 576
577 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendOkClient, 577 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendOkClient,
578 ChannelClient) { 578 ChannelClient) {
579 ListenerSendingOneOk listener; 579 ListenerSendingOneOk listener;
580 Connect(&listener); 580 Connect(&listener);
581 listener.set_sender(channel()); 581 listener.set_sender(channel());
582 582
583 base::MessageLoop::current()->Run(); 583 base::RunLoop().Run();
584 584
585 Close(); 585 Close();
586 } 586 }
587 587
588 #if defined(OS_POSIX) 588 #if defined(OS_POSIX)
589 class ListenerThatExpectsFile : public IPC::Listener { 589 class ListenerThatExpectsFile : public IPC::Listener {
590 public: 590 public:
591 ListenerThatExpectsFile() : sender_(NULL) {} 591 ListenerThatExpectsFile() : sender_(NULL) {}
592 592
593 ~ListenerThatExpectsFile() override {} 593 ~ListenerThatExpectsFile() override {}
(...skipping 19 matching lines...) Expand all
613 InitWithMojo("IPCChannelMojoTestSendPlatformHandleClient"); 613 InitWithMojo("IPCChannelMojoTestSendPlatformHandleClient");
614 614
615 ListenerThatExpectsOK listener; 615 ListenerThatExpectsOK listener;
616 CreateChannel(&listener); 616 CreateChannel(&listener);
617 ASSERT_TRUE(ConnectChannel()); 617 ASSERT_TRUE(ConnectChannel());
618 618
619 base::File file(HandleSendingHelper::GetSendingFilePath(), 619 base::File file(HandleSendingHelper::GetSendingFilePath(),
620 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | 620 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
621 base::File::FLAG_READ); 621 base::File::FLAG_READ);
622 HandleSendingHelper::WriteFileThenSend(channel(), file); 622 HandleSendingHelper::WriteFileThenSend(channel(), file);
623 base::MessageLoop::current()->Run(); 623 base::RunLoop().Run();
624 624
625 channel()->Close(); 625 channel()->Close();
626 626
627 EXPECT_TRUE(WaitForClientShutdown()); 627 EXPECT_TRUE(WaitForClientShutdown());
628 DestroyChannel(); 628 DestroyChannel();
629 } 629 }
630 630
631 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendPlatformHandleClient, 631 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestSendPlatformHandleClient,
632 ChannelClient) { 632 ChannelClient) {
633 ListenerThatExpectsFile listener; 633 ListenerThatExpectsFile listener;
634 Connect(&listener); 634 Connect(&listener);
635 listener.set_sender(channel()); 635 listener.set_sender(channel());
636 636
637 base::MessageLoop::current()->Run(); 637 base::RunLoop().Run();
638 638
639 Close(); 639 Close();
640 } 640 }
641 641
642 class ListenerThatExpectsFileAndPipe : public IPC::Listener { 642 class ListenerThatExpectsFileAndPipe : public IPC::Listener {
643 public: 643 public:
644 ListenerThatExpectsFileAndPipe() : sender_(NULL) {} 644 ListenerThatExpectsFileAndPipe() : sender_(NULL) {}
645 645
646 ~ListenerThatExpectsFileAndPipe() override {} 646 ~ListenerThatExpectsFileAndPipe() override {}
647 647
(...skipping 21 matching lines...) Expand all
669 ListenerThatExpectsOK listener; 669 ListenerThatExpectsOK listener;
670 CreateChannel(&listener); 670 CreateChannel(&listener);
671 ASSERT_TRUE(ConnectChannel()); 671 ASSERT_TRUE(ConnectChannel());
672 672
673 base::File file(HandleSendingHelper::GetSendingFilePath(), 673 base::File file(HandleSendingHelper::GetSendingFilePath(),
674 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE | 674 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE |
675 base::File::FLAG_READ); 675 base::File::FLAG_READ);
676 TestingMessagePipe pipe; 676 TestingMessagePipe pipe;
677 HandleSendingHelper::WriteFileAndPipeThenSend(channel(), file, &pipe); 677 HandleSendingHelper::WriteFileAndPipeThenSend(channel(), file, &pipe);
678 678
679 base::MessageLoop::current()->Run(); 679 base::RunLoop().Run();
680 channel()->Close(); 680 channel()->Close();
681 681
682 EXPECT_TRUE(WaitForClientShutdown()); 682 EXPECT_TRUE(WaitForClientShutdown());
683 DestroyChannel(); 683 DestroyChannel();
684 } 684 }
685 685
686 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT( 686 DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(
687 IPCChannelMojoTestSendPlatformHandleAndPipeClient, 687 IPCChannelMojoTestSendPlatformHandleAndPipeClient,
688 ChannelClient) { 688 ChannelClient) {
689 ListenerThatExpectsFileAndPipe listener; 689 ListenerThatExpectsFileAndPipe listener;
690 Connect(&listener); 690 Connect(&listener);
691 listener.set_sender(channel()); 691 listener.set_sender(channel());
692 692
693 base::MessageLoop::current()->Run(); 693 base::RunLoop().Run();
694 694
695 Close(); 695 Close();
696 } 696 }
697 697
698 #endif 698 #endif
699 699
700 #if defined(OS_LINUX) 700 #if defined(OS_LINUX)
701 701
702 const base::ProcessId kMagicChildId = 54321; 702 const base::ProcessId kMagicChildId = 54321;
703 703
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 Connect(&listener); 735 Connect(&listener);
736 736
737 base::MessageLoop::current()->Run(); 737 base::MessageLoop::current()->Run();
738 738
739 Close(); 739 Close();
740 } 740 }
741 741
742 #endif // OS_LINUX 742 #endif // OS_LINUX
743 743
744 } // namespace 744 } // namespace
OLDNEW
« no previous file with comments | « ipc/ipc_sync_channel_unittest.cc ('k') | ipc/sync_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698