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

Unified Diff: third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc

Issue 1157843002: Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc
diff --git a/third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc b/third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc
index 2545788bbf01f73ab89e808ea2d83e2040127268..0d8f4795ae845cc90bba62984b9099a776d10f2f 100644
--- a/third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc
+++ b/third_party/mojo/src/mojo/edk/system/connection_manager_unittest.cc
@@ -84,10 +84,12 @@ class TestSlaveInfo {
void ConnectSlave(MasterConnectionManager* master,
embedder::SlaveProcessDelegate* slave_process_delegate,
SlaveConnectionManager* slave,
- const std::string& slave_name) {
+ const std::string& slave_name,
+ ProcessIdentifier* slave_process_identifier) {
embedder::PlatformChannelPair platform_channel_pair;
master->AddSlave(new TestSlaveInfo(slave_name),
- platform_channel_pair.PassServerHandle());
+ platform_channel_pair.PassServerHandle(),
+ slave_process_identifier);
slave->Init(base::MessageLoop::current()->task_runner(),
slave_process_delegate, platform_channel_pair.PassClientHandle());
}
@@ -205,11 +207,20 @@ TEST_F(ConnectionManagerTest, BasicConnectSlaves) {
MockSlaveProcessDelegate slave1_process_delegate;
SlaveConnectionManager slave1(platform_support());
- ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1");
+ ProcessIdentifier slave1_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1",
+ &slave1_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave1_id));
MockSlaveProcessDelegate slave2_process_delegate;
SlaveConnectionManager slave2(platform_support());
- ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2");
+ ProcessIdentifier slave2_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2",
+ &slave2_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave2_id));
+ // TODO(vtl): If/when I add the ability to get one's own process identifier,
+ // there'll be more we can check.
+ EXPECT_NE(slave1_id, slave2_id);
ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
EXPECT_TRUE(slave1.AllowConnect(connection_id));
@@ -218,17 +229,14 @@ TEST_F(ConnectionManagerTest, BasicConnectSlaves) {
ProcessIdentifier peer1 = kInvalidProcessIdentifier;
embedder::ScopedPlatformHandle h1;
EXPECT_TRUE(slave1.Connect(connection_id, &peer1, &h1));
- EXPECT_TRUE(IsValidSlaveProcessIdentifier(peer1));
+ EXPECT_EQ(slave2_id, peer1);
EXPECT_TRUE(h1.is_valid());
ProcessIdentifier peer2 = kInvalidProcessIdentifier;
embedder::ScopedPlatformHandle h2;
EXPECT_TRUE(slave2.Connect(connection_id, &peer2, &h2));
- EXPECT_TRUE(IsValidSlaveProcessIdentifier(peer2));
+ EXPECT_EQ(slave1_id, peer2);
EXPECT_TRUE(h2.is_valid());
- // TODO(vtl): If/when I add the ability to get one's own process identifier,
- // there'll be more we can check.
- EXPECT_NE(peer1, peer2);
EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get()));
// The process manager shouldn't have gotten any notifications yet. (Spin the
@@ -265,7 +273,9 @@ TEST_F(ConnectionManagerTest, ShutdownMasterBeforeSlave) {
MockSlaveProcessDelegate slave_process_delegate;
SlaveConnectionManager slave(platform_support());
- ConnectSlave(&master, &slave_process_delegate, &slave, "slave");
+ ProcessIdentifier slave_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave_process_delegate, &slave, "slave", &slave_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id));
// The process manager shouldn't have gotten any notifications yet. (Spin the
// message loop to make sure none were enqueued.)
@@ -293,11 +303,18 @@ TEST_F(ConnectionManagerTest, SlaveCancelConnect) {
MockSlaveProcessDelegate slave1_process_delegate;
SlaveConnectionManager slave1(platform_support());
- ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1");
+ ProcessIdentifier slave1_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1",
+ &slave1_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave1_id));
MockSlaveProcessDelegate slave2_process_delegate;
SlaveConnectionManager slave2(platform_support());
- ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2");
+ ProcessIdentifier slave2_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2",
+ &slave2_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave2_id));
+ EXPECT_NE(slave1_id, slave2_id);
ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
EXPECT_TRUE(slave1.AllowConnect(connection_id));
@@ -323,11 +340,18 @@ TEST_F(ConnectionManagerTest, ErrorRemovePending) {
MockSlaveProcessDelegate slave1_process_delegate;
SlaveConnectionManager slave1(platform_support());
- ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1");
+ ProcessIdentifier slave1_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1",
+ &slave1_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave1_id));
MockSlaveProcessDelegate slave2_process_delegate;
SlaveConnectionManager slave2(platform_support());
- ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2");
+ ProcessIdentifier slave2_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2",
+ &slave2_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave2_id));
+ EXPECT_NE(slave1_id, slave2_id);
ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
EXPECT_TRUE(slave1.AllowConnect(connection_id));
@@ -358,7 +382,9 @@ TEST_F(ConnectionManagerTest, ConnectSlaveToSelf) {
MockSlaveProcessDelegate slave_process_delegate;
SlaveConnectionManager slave(platform_support());
- ConnectSlave(&master, &slave_process_delegate, &slave, "slave");
+ ProcessIdentifier slave_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave_process_delegate, &slave, "slave", &slave_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id));
ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
EXPECT_TRUE(slave.AllowConnect(connection_id));
@@ -369,16 +395,14 @@ TEST_F(ConnectionManagerTest, ConnectSlaveToSelf) {
ProcessIdentifier peer1 = kInvalidProcessIdentifier;
embedder::ScopedPlatformHandle h1;
EXPECT_TRUE(slave.Connect(connection_id, &peer1, &h1));
- EXPECT_TRUE(IsValidSlaveProcessIdentifier(peer1));
+ EXPECT_EQ(slave_id, peer1);
EXPECT_FALSE(h1.is_valid());
ProcessIdentifier peer2 = kInvalidProcessIdentifier;
embedder::ScopedPlatformHandle h2;
EXPECT_TRUE(slave.Connect(connection_id, &peer2, &h2));
- EXPECT_TRUE(IsValidSlaveProcessIdentifier(peer2));
+ EXPECT_EQ(slave_id, peer2);
EXPECT_FALSE(h2.is_valid());
- EXPECT_EQ(peer1, peer2);
-
slave.Shutdown();
master.Shutdown();
}
@@ -390,11 +414,18 @@ TEST_F(ConnectionManagerTest, ConnectSlavesTwice) {
MockSlaveProcessDelegate slave1_process_delegate;
SlaveConnectionManager slave1(platform_support());
- ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1");
+ ProcessIdentifier slave1_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave1_process_delegate, &slave1, "slave1",
+ &slave1_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave1_id));
MockSlaveProcessDelegate slave2_process_delegate;
SlaveConnectionManager slave2(platform_support());
- ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2");
+ ProcessIdentifier slave2_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave2_process_delegate, &slave2, "slave2",
+ &slave2_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave2_id));
+ EXPECT_NE(slave1_id, slave2_id);
ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
EXPECT_TRUE(slave1.AllowConnect(connection_id));
@@ -403,11 +434,12 @@ TEST_F(ConnectionManagerTest, ConnectSlavesTwice) {
ProcessIdentifier peer1 = kInvalidProcessIdentifier;
embedder::ScopedPlatformHandle h1;
EXPECT_TRUE(slave1.Connect(connection_id, &peer1, &h1));
+ EXPECT_EQ(slave2_id, peer1);
ProcessIdentifier peer2 = kInvalidProcessIdentifier;
embedder::ScopedPlatformHandle h2;
EXPECT_TRUE(slave2.Connect(connection_id, &peer2, &h2));
+ EXPECT_EQ(slave1_id, peer2);
- EXPECT_NE(peer1, peer2);
EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get()));
// Currently, the master doesn't detect the case of connecting a pair of
@@ -442,7 +474,9 @@ TEST_F(ConnectionManagerTest, ConnectMasterToSlave) {
MockSlaveProcessDelegate slave_process_delegate;
SlaveConnectionManager slave(platform_support());
- ConnectSlave(&master, &slave_process_delegate, &slave, "slave");
+ ProcessIdentifier slave_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave_process_delegate, &slave, "slave", &slave_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id));
ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
EXPECT_TRUE(master.AllowConnect(connection_id));
@@ -451,7 +485,7 @@ TEST_F(ConnectionManagerTest, ConnectMasterToSlave) {
ProcessIdentifier master_peer = kInvalidProcessIdentifier;
embedder::ScopedPlatformHandle master_h;
EXPECT_TRUE(master.Connect(connection_id, &master_peer, &master_h));
- EXPECT_TRUE(IsValidSlaveProcessIdentifier(master_peer));
+ EXPECT_EQ(slave_id, master_peer);
EXPECT_TRUE(master_h.is_valid());
ProcessIdentifier slave_peer = kInvalidProcessIdentifier;
embedder::ScopedPlatformHandle slave_h;
@@ -459,7 +493,6 @@ TEST_F(ConnectionManagerTest, ConnectMasterToSlave) {
EXPECT_EQ(kMasterProcessIdentifier, slave_peer);
EXPECT_TRUE(slave_h.is_valid());
- EXPECT_NE(master_peer, slave_peer);
EXPECT_TRUE(ArePlatformHandlesConnected(master_h.get(), slave_h.get()));
slave.Shutdown();
@@ -500,7 +533,9 @@ TEST_F(ConnectionManagerTest, MasterCancelConnect) {
MockSlaveProcessDelegate slave_process_delegate;
SlaveConnectionManager slave(platform_support());
- ConnectSlave(&master, &slave_process_delegate, &slave, "slave");
+ ProcessIdentifier slave_id = kInvalidProcessIdentifier;
+ ConnectSlave(&master, &slave_process_delegate, &slave, "slave", &slave_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id));
ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
EXPECT_TRUE(master.AllowConnect(connection_id));
@@ -525,12 +560,52 @@ TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) {
MockSlaveProcessDelegate slave_process_delegate;
SlaveConnectionManager slave(platform_support());
embedder::PlatformChannelPair platform_channel_pair;
+ ProcessIdentifier slave_id = kInvalidProcessIdentifier;
master.AddSlave(new TestSlaveInfo("slave"),
- platform_channel_pair.PassServerHandle());
+ platform_channel_pair.PassServerHandle(), &slave_id);
master.Shutdown();
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id));
// Since we never initialized |slave|, we don't have to shut it down.
}
+TEST_F(ConnectionManagerTest, AddSlaveAndBootstrap) {
+ MasterConnectionManager master(platform_support());
+ master.Init(base::MessageLoop::current()->task_runner(),
+ &master_process_delegate());
+
+ embedder::PlatformChannelPair platform_channel_pair;
+ ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier();
+ ProcessIdentifier slave_id = kInvalidProcessIdentifier;
+ master.AddSlaveAndBootstrap(new TestSlaveInfo("slave"),
+ platform_channel_pair.PassServerHandle(),
+ connection_id, &slave_id);
+ EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id));
+
+ embedder::ScopedPlatformHandle h1;
+ ProcessIdentifier master_peer = kInvalidProcessIdentifier;
+ EXPECT_TRUE(master.Connect(connection_id, &master_peer, &h1));
+ EXPECT_EQ(slave_id, master_peer);
+ EXPECT_TRUE(h1.is_valid());
+
+ // We can delay creating/initializing |slave| for quite a while.
+ MockSlaveProcessDelegate slave_process_delegate;
+ SlaveConnectionManager slave(platform_support());
+ slave.Init(base::MessageLoop::current()->task_runner(),
+ &slave_process_delegate, platform_channel_pair.PassClientHandle());
+
+ ProcessIdentifier slave_peer = kInvalidProcessIdentifier;
+ embedder::ScopedPlatformHandle h2;
+ EXPECT_TRUE(slave.Connect(connection_id, &slave_peer, &h2));
+ EXPECT_EQ(kMasterProcessIdentifier, slave_peer);
+
+ EXPECT_TRUE(ArePlatformHandlesConnected(h1.get(), h2.get()));
+
+ slave.Shutdown();
+ master.Shutdown();
+}
+
+// TODO(vtl): More shutdown cases for |AddSlaveAndBootstrap()|?
+
} // namespace
} // namespace system
} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698