| OLD | NEW |
| 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 "mojo/edk/system/channel_manager.h" | 5 #include "mojo/edk/system/channel_manager.h" |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "mojo/edk/embedder/platform_channel_pair.h" | 11 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 12 #include "mojo/edk/embedder/simple_platform_support.h" | 12 #include "mojo/edk/embedder/simple_platform_support.h" |
| 13 #include "mojo/edk/platform/message_loop.h" | 13 #include "mojo/edk/platform/message_loop.h" |
| 14 #include "mojo/edk/platform/message_loop_for_io.h" | |
| 15 #include "mojo/edk/platform/task_runner.h" | 14 #include "mojo/edk/platform/task_runner.h" |
| 16 #include "mojo/edk/platform/test_message_loops.h" | 15 #include "mojo/edk/platform/test_message_loops.h" |
| 17 #include "mojo/edk/system/channel.h" | 16 #include "mojo/edk/system/channel.h" |
| 18 #include "mojo/edk/system/channel_endpoint.h" | 17 #include "mojo/edk/system/channel_endpoint.h" |
| 19 #include "mojo/edk/system/message_pipe_dispatcher.h" | 18 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 20 #include "mojo/edk/system/test/simple_test_thread.h" | 19 #include "mojo/edk/system/test/simple_test_thread.h" |
| 21 #include "mojo/edk/util/ref_ptr.h" | 20 #include "mojo/edk/util/ref_ptr.h" |
| 22 #include "mojo/public/cpp/system/macros.h" | 21 #include "mojo/public/cpp/system/macros.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 23 |
| 25 using mojo::platform::MessageLoop; | 24 using mojo::platform::MessageLoop; |
| 26 using mojo::platform::MessageLoopForIO; | 25 using mojo::platform::PlatformHandleWatcher; |
| 27 using mojo::platform::TaskRunner; | 26 using mojo::platform::TaskRunner; |
| 28 using mojo::platform::test::CreateTestMessageLoop; | 27 using mojo::platform::test::CreateTestMessageLoop; |
| 29 using mojo::platform::test::CreateTestMessageLoopForIO; | 28 using mojo::platform::test::CreateTestMessageLoopForIO; |
| 30 using mojo::util::RefPtr; | 29 using mojo::util::RefPtr; |
| 31 | 30 |
| 32 namespace mojo { | 31 namespace mojo { |
| 33 namespace system { | 32 namespace system { |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 class ChannelManagerTest : public testing::Test { | 35 class ChannelManagerTest : public testing::Test { |
| 37 public: | 36 public: |
| 38 ChannelManagerTest() | 37 ChannelManagerTest() |
| 39 : message_loop_(CreateTestMessageLoopForIO()), | 38 : platform_handle_watcher_(nullptr), |
| 39 message_loop_(CreateTestMessageLoopForIO(&platform_handle_watcher_)), |
| 40 channel_manager_(&platform_support_, | 40 channel_manager_(&platform_support_, |
| 41 message_loop_->GetTaskRunner().Clone(), | 41 message_loop_->GetTaskRunner().Clone(), |
| 42 nullptr) {} | 42 nullptr) {} |
| 43 ~ChannelManagerTest() override {} | 43 ~ChannelManagerTest() override {} |
| 44 | 44 |
| 45 protected: | 45 protected: |
| 46 MessageLoop* message_loop() { return message_loop_.get(); } | 46 MessageLoop* message_loop() { return message_loop_.get(); } |
| 47 const RefPtr<TaskRunner>& task_runner() { | 47 const RefPtr<TaskRunner>& task_runner() { |
| 48 return message_loop_->GetTaskRunner(); | 48 return message_loop_->GetTaskRunner(); |
| 49 } | 49 } |
| 50 ChannelManager& channel_manager() { return channel_manager_; } | 50 ChannelManager& channel_manager() { return channel_manager_; } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 embedder::SimplePlatformSupport platform_support_; | 53 embedder::SimplePlatformSupport platform_support_; |
| 54 std::unique_ptr<MessageLoopForIO> message_loop_; | 54 // TODO(vtl): The |PlatformHandleWatcher| and |MessageLoop| should be injected |
| 55 // into the |ChannelManager|. |
| 56 // Valid while |message_loop_| is valid. |
| 57 PlatformHandleWatcher* platform_handle_watcher_; |
| 58 std::unique_ptr<MessageLoop> message_loop_; |
| 55 // Note: This should be *after* the above, since they must be initialized | 59 // Note: This should be *after* the above, since they must be initialized |
| 56 // before it (and should outlive it). | 60 // before it (and should outlive it). |
| 57 ChannelManager channel_manager_; | 61 ChannelManager channel_manager_; |
| 58 | 62 |
| 59 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManagerTest); | 63 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManagerTest); |
| 60 }; | 64 }; |
| 61 | 65 |
| 62 TEST_F(ChannelManagerTest, Basic) { | 66 TEST_F(ChannelManagerTest, Basic) { |
| 63 embedder::PlatformChannelPair channel_pair; | 67 embedder::PlatformChannelPair channel_pair; |
| 64 | 68 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 | 180 |
| 177 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 181 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 178 } | 182 } |
| 179 | 183 |
| 180 // TODO(vtl): Test |CreateChannelWithoutBootstrapOnIOThread()|. (This will | 184 // TODO(vtl): Test |CreateChannelWithoutBootstrapOnIOThread()|. (This will |
| 181 // require additional functionality in |Channel|.) | 185 // require additional functionality in |Channel|.) |
| 182 | 186 |
| 183 } // namespace | 187 } // namespace |
| 184 } // namespace system | 188 } // namespace system |
| 185 } // namespace mojo | 189 } // namespace mojo |
| OLD | NEW |