OLD | NEW |
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> |
11 | 11 |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "mojo/edk/base_edk/platform_task_runner_impl.h" | 15 #include "mojo/edk/base_edk/platform_task_runner_impl.h" |
16 #include "mojo/edk/embedder/master_process_delegate.h" | 16 #include "mojo/edk/embedder/master_process_delegate.h" |
17 #include "mojo/edk/embedder/platform_channel_pair.h" | |
18 #include "mojo/edk/embedder/simple_platform_support.h" | 17 #include "mojo/edk/embedder/simple_platform_support.h" |
19 #include "mojo/edk/embedder/slave_process_delegate.h" | 18 #include "mojo/edk/embedder/slave_process_delegate.h" |
20 #include "mojo/edk/platform/message_loop.h" | 19 #include "mojo/edk/platform/message_loop.h" |
21 #include "mojo/edk/platform/platform_handle.h" | 20 #include "mojo/edk/platform/platform_handle.h" |
| 21 #include "mojo/edk/platform/platform_pipe.h" |
22 #include "mojo/edk/platform/test_message_loops.h" | 22 #include "mojo/edk/platform/test_message_loops.h" |
23 #include "mojo/edk/system/master_connection_manager.h" | 23 #include "mojo/edk/system/master_connection_manager.h" |
24 #include "mojo/edk/system/slave_connection_manager.h" | 24 #include "mojo/edk/system/slave_connection_manager.h" |
25 #include "mojo/edk/test/test_utils.h" | 25 #include "mojo/edk/test/test_utils.h" |
26 #include "mojo/edk/util/ref_ptr.h" | 26 #include "mojo/edk/util/ref_ptr.h" |
27 #include "mojo/edk/util/thread_checker.h" | 27 #include "mojo/edk/util/thread_checker.h" |
28 #include "mojo/public/cpp/system/macros.h" | 28 #include "mojo/public/cpp/system/macros.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 | 30 |
31 using mojo::platform::MessageLoop; | 31 using mojo::platform::MessageLoop; |
32 using mojo::platform::PlatformHandle; | 32 using mojo::platform::PlatformHandle; |
| 33 using mojo::platform::PlatformPipe; |
33 using mojo::platform::ScopedPlatformHandle; | 34 using mojo::platform::ScopedPlatformHandle; |
34 using mojo::platform::TaskRunner; | 35 using mojo::platform::TaskRunner; |
35 using mojo::platform::test::CreateTestMessageLoop; | 36 using mojo::platform::test::CreateTestMessageLoop; |
36 using mojo::util::MakeRefCounted; | 37 using mojo::util::MakeRefCounted; |
37 using mojo::util::RefPtr; | 38 using mojo::util::RefPtr; |
38 using mojo::util::ThreadChecker; | 39 using mojo::util::ThreadChecker; |
39 | 40 |
40 namespace mojo { | 41 namespace mojo { |
41 namespace system { | 42 namespace system { |
42 namespace { | 43 namespace { |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 191 } |
191 | 192 |
192 // Connects the given |slave| (with the given |slave_process_delegate|) to the | 193 // Connects the given |slave| (with the given |slave_process_delegate|) to the |
193 // given master, creating and using a |TestSlaveInfo| with the given | 194 // given master, creating and using a |TestSlaveInfo| with the given |
194 // |slave_name|, and returns the process identifier for the slave. | 195 // |slave_name|, and returns the process identifier for the slave. |
195 ProcessIdentifier ConnectSlave( | 196 ProcessIdentifier ConnectSlave( |
196 MasterConnectionManager* master, | 197 MasterConnectionManager* master, |
197 embedder::SlaveProcessDelegate* slave_process_delegate, | 198 embedder::SlaveProcessDelegate* slave_process_delegate, |
198 SlaveConnectionManager* slave, | 199 SlaveConnectionManager* slave, |
199 const std::string& slave_name) { | 200 const std::string& slave_name) { |
200 embedder::PlatformChannelPair platform_channel_pair; | 201 PlatformPipe platform_channel_pair; |
201 ProcessIdentifier slave_process_identifier = master->AddSlave( | 202 ProcessIdentifier slave_process_identifier = master->AddSlave( |
202 new TestSlaveInfo(slave_name), platform_channel_pair.handle0.Pass()); | 203 new TestSlaveInfo(slave_name), platform_channel_pair.handle0.Pass()); |
203 slave->Init(task_runner().Clone(), slave_process_delegate, | 204 slave->Init(task_runner().Clone(), slave_process_delegate, |
204 platform_channel_pair.handle1.Pass()); | 205 platform_channel_pair.handle1.Pass()); |
205 return slave_process_identifier; | 206 return slave_process_identifier; |
206 } | 207 } |
207 | 208 |
208 private: | 209 private: |
209 embedder::SimplePlatformSupport platform_support_; | 210 embedder::SimplePlatformSupport platform_support_; |
210 std::unique_ptr<MessageLoop> message_loop_; | 211 std::unique_ptr<MessageLoop> message_loop_; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 slave.Shutdown(); | 643 slave.Shutdown(); |
643 master.Shutdown(); | 644 master.Shutdown(); |
644 } | 645 } |
645 | 646 |
646 TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) { | 647 TEST_F(ConnectionManagerTest, AddSlaveThenImmediateShutdown) { |
647 MasterConnectionManager master(platform_support()); | 648 MasterConnectionManager master(platform_support()); |
648 master.Init(task_runner().Clone(), &master_process_delegate()); | 649 master.Init(task_runner().Clone(), &master_process_delegate()); |
649 | 650 |
650 MockSlaveProcessDelegate slave_process_delegate; | 651 MockSlaveProcessDelegate slave_process_delegate; |
651 SlaveConnectionManager slave(platform_support()); | 652 SlaveConnectionManager slave(platform_support()); |
652 embedder::PlatformChannelPair platform_channel_pair; | 653 PlatformPipe platform_channel_pair; |
653 ProcessIdentifier slave_id = master.AddSlave( | 654 ProcessIdentifier slave_id = master.AddSlave( |
654 new TestSlaveInfo("slave"), platform_channel_pair.handle0.Pass()); | 655 new TestSlaveInfo("slave"), platform_channel_pair.handle0.Pass()); |
655 master.Shutdown(); | 656 master.Shutdown(); |
656 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); | 657 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); |
657 // Since we never initialized |slave|, we don't have to shut it down. | 658 // Since we never initialized |slave|, we don't have to shut it down. |
658 } | 659 } |
659 | 660 |
660 TEST_F(ConnectionManagerTest, AddSlaveAndBootstrap) { | 661 TEST_F(ConnectionManagerTest, AddSlaveAndBootstrap) { |
661 MasterConnectionManager master(platform_support()); | 662 MasterConnectionManager master(platform_support()); |
662 master.Init(task_runner().Clone(), &master_process_delegate()); | 663 master.Init(task_runner().Clone(), &master_process_delegate()); |
663 | 664 |
664 embedder::PlatformChannelPair platform_channel_pair; | 665 PlatformPipe platform_channel_pair; |
665 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); | 666 ConnectionIdentifier connection_id = master.GenerateConnectionIdentifier(); |
666 ProcessIdentifier slave_id = master.AddSlaveAndBootstrap( | 667 ProcessIdentifier slave_id = master.AddSlaveAndBootstrap( |
667 new TestSlaveInfo("slave"), platform_channel_pair.handle0.Pass(), | 668 new TestSlaveInfo("slave"), platform_channel_pair.handle0.Pass(), |
668 connection_id); | 669 connection_id); |
669 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); | 670 EXPECT_TRUE(IsValidSlaveProcessIdentifier(slave_id)); |
670 | 671 |
671 ScopedPlatformHandle h1; | 672 ScopedPlatformHandle h1; |
672 ProcessIdentifier master_peer = kInvalidProcessIdentifier; | 673 ProcessIdentifier master_peer = kInvalidProcessIdentifier; |
673 bool is_first = false; | 674 bool is_first = false; |
674 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, | 675 EXPECT_EQ(ConnectionManager::Result::SUCCESS_CONNECT_NEW_CONNECTION, |
(...skipping 19 matching lines...) Expand all Loading... |
694 | 695 |
695 slave.Shutdown(); | 696 slave.Shutdown(); |
696 master.Shutdown(); | 697 master.Shutdown(); |
697 } | 698 } |
698 | 699 |
699 // TODO(vtl): More shutdown cases for |AddSlaveAndBootstrap()|? | 700 // TODO(vtl): More shutdown cases for |AddSlaveAndBootstrap()|? |
700 | 701 |
701 } // namespace | 702 } // namespace |
702 } // namespace system | 703 } // namespace system |
703 } // namespace mojo | 704 } // namespace mojo |
OLD | NEW |