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

Side by Side Diff: mojo/edk/system/connection_manager_unittest.cc

Issue 1651183003: Make PlatformChannelPair "dumb". (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 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/edk/system/channel_test_base.cc ('k') | mojo/edk/system/data_pipe_impl_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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // This is really a unit test for |MasterConnectionManager| and 5 // This is really a unit test for |MasterConnectionManager| and
6 // |SlaveConnectionManager| (since they need to be tested together). 6 // |SlaveConnectionManager| (since they need to be tested together).
7 7
8 #include "mojo/edk/system/connection_manager.h" 8 #include "mojo/edk/system/connection_manager.h"
9 9
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 // Connects the given |slave| (with the given |slave_process_delegate|) to the 192 // Connects the given |slave| (with the given |slave_process_delegate|) to the
193 // given master, creating and using a |TestSlaveInfo| with the given 193 // given master, creating and using a |TestSlaveInfo| with the given
194 // |slave_name|, and returns the process identifier for the slave. 194 // |slave_name|, and returns the process identifier for the slave.
195 ProcessIdentifier ConnectSlave( 195 ProcessIdentifier ConnectSlave(
196 MasterConnectionManager* master, 196 MasterConnectionManager* master,
197 embedder::SlaveProcessDelegate* slave_process_delegate, 197 embedder::SlaveProcessDelegate* slave_process_delegate,
198 SlaveConnectionManager* slave, 198 SlaveConnectionManager* slave,
199 const std::string& slave_name) { 199 const std::string& slave_name) {
200 embedder::PlatformChannelPair platform_channel_pair; 200 embedder::PlatformChannelPair platform_channel_pair;
201 ProcessIdentifier slave_process_identifier = 201 ProcessIdentifier slave_process_identifier = master->AddSlave(
202 master->AddSlave(new TestSlaveInfo(slave_name), 202 new TestSlaveInfo(slave_name), platform_channel_pair.handle0.Pass());
203 platform_channel_pair.PassServerHandle());
204 slave->Init(task_runner().Clone(), slave_process_delegate, 203 slave->Init(task_runner().Clone(), slave_process_delegate,
205 platform_channel_pair.PassClientHandle()); 204 platform_channel_pair.handle1.Pass());
206 return slave_process_identifier; 205 return slave_process_identifier;
207 } 206 }
208 207
209 private: 208 private:
210 embedder::SimplePlatformSupport platform_support_; 209 embedder::SimplePlatformSupport platform_support_;
211 std::unique_ptr<MessageLoop> message_loop_; 210 std::unique_ptr<MessageLoop> message_loop_;
212 MockMasterProcessDelegate master_process_delegate_; 211 MockMasterProcessDelegate master_process_delegate_;
213 212
214 MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionManagerTest); 213 MOJO_DISALLOW_COPY_AND_ASSIGN(ConnectionManagerTest);
215 }; 214 };
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 } 644 }
646 645
647 TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) { 646 TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) {
648 MasterConnectionManager master(platform_support()); 647 MasterConnectionManager master(platform_support());
649 master.Init(task_runner().Clone(), &master_process_delegate()); 648 master.Init(task_runner().Clone(), &master_process_delegate());
650 649
651 MockSlaveProcessDelegate slave_process_delegate; 650 MockSlaveProcessDelegate slave_process_delegate;
652 SlaveConnectionManager slave(platform_support()); 651 SlaveConnectionManager slave(platform_support());
653 embedder::PlatformChannelPair platform_channel_pair; 652 embedder::PlatformChannelPair platform_channel_pair;
654 ProcessIdentifier slave_id = master.AddSlave( 653 ProcessIdentifier slave_id = master.AddSlave(
655 new TestSlaveInfo("slave"), platform_channel_pair.PassServerHandle()); 654 new TestSlaveInfo("slave"), platform_channel_pair.handle0.Pass());
656 master.Shutdown(); 655 master.Shutdown();
657 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); 656 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id));
658 // Since we never initialized |slave|, we don't have to shut it down. 657 // Since we never initialized |slave|, we don't have to shut it down.
659 } 658 }
660 659
661 TEST_F(ConnectionManagerTest, AddSlaveAndBootstrap) { 660 TEST_F(ConnectionManagerTest, AddSlaveAndBootstrap) {
662 MasterConnectionManager master(platform_support()); 661 MasterConnectionManager master(platform_support());
663 master.Init(task_runner().Clone(), &master_process_delegate()); 662 master.Init(task_runner().Clone(), &master_process_delegate());
664 663
665 embedder::PlatformChannelPair platform_channel_pair; 664 embedder::PlatformChannelPair platform_channel_pair;
666 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); 665 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
667 ProcessIdentifier slave_id = master.AddSlaveAndBootstrap( 666 ProcessIdentifier slave_id = master.AddSlaveAndBootstrap(
668 new TestSlaveInfo("slave"), platform_channel_pair.PassServerHandle(), 667 new TestSlaveInfo("slave"), platform_channel_pair.handle0.Pass(),
669 connection_id); 668 connection_id);
670 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); 669 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id));
671 670
672 ScopedPlatformHandle h1; 671 ScopedPlatformHandle h1;
673 ProcessIdentifier master_peer = kInvalidProcessIdentifier; 672 ProcessIdentifier master_peer = kInvalidProcessIdentifier;
674 bool is_first = false; 673 bool is_first = false;
675 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, 674 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION,
676 master.Connect(connection_id, &master_peer, &is_first, &h1)); 675 master.Connect(connection_id, &master_peer, &is_first, &h1));
677 EXPECT_EQ(slave_id, master_peer); 676 EXPECT_EQ(slave_id, master_peer);
678 EXPECT_TRUE(is_first); 677 EXPECT_TRUE(is_first);
679 EXPECT_TRUE(h1.is_valid()); 678 EXPECT_TRUE(h1.is_valid());
680 679
681 // We can delay creating/initializing |slave| for quite a while. 680 // We can delay creating/initializing |slave| for quite a while.
682 MockSlaveProcessDelegate slave_process_delegate; 681 MockSlaveProcessDelegate slave_process_delegate;
683 SlaveConnectionManager slave(platform_support()); 682 SlaveConnectionManager slave(platform_support());
684 slave.Init(task_runner().Clone(), &slave_process_delegate, 683 slave.Init(task_runner().Clone(), &slave_process_delegate,
685 platform_channel_pair.PassClientHandle()); 684 platform_channel_pair.handle1.Pass());
686 685
687 ProcessIdentifier slave_peer = kInvalidProcessIdentifier; 686 ProcessIdentifier slave_peer = kInvalidProcessIdentifier;
688 ScopedPlatformHandle h2; 687 ScopedPlatformHandle h2;
689 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, 688 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION,
690 slave.Connect(connection_id, &slave_peer, &is_first, &h2)); 689 slave.Connect(connection_id, &slave_peer, &is_first, &h2));
691 EXPECT_EQ(kMasterProcessIdentifier, slave_peer); 690 EXPECT_EQ(kMasterProcessIdentifier, slave_peer);
692 EXPECT_FALSE(is_first); 691 EXPECT_FALSE(is_first);
693 692
694 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get())); 693 EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get()));
695 694
696 slave.Shutdown(); 695 slave.Shutdown();
697 master.Shutdown(); 696 master.Shutdown();
698 } 697 }
699 698
700 // TODO(vtl): More shutdown cases for |AddSlaveAndBootstrap()|? 699 // TODO(vtl): More shutdown cases for |AddSlaveAndBootstrap()|?
701 700
702 } // namespace 701 } // namespace
703 } // namespace system 702 } // namespace system
704 } // namespace mojo 703 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/channel_test_base.cc ('k') | mojo/edk/system/data_pipe_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698