| 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 "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "mojo/edk/base_edk/platform_task_runner_impl.h" | 10 #include "mojo/edk/base_edk/platform_task_runner_impl.h" |
| 11 #include "mojo/edk/embedder/platform_channel_pair.h" | 11 #include "mojo/edk/embedder/platform_channel_pair.h" |
| 12 #include "mojo/edk/embedder/platform_task_runner.h" | |
| 13 #include "mojo/edk/embedder/simple_platform_support.h" | 12 #include "mojo/edk/embedder/simple_platform_support.h" |
| 13 #include "mojo/edk/platform/task_runner.h" |
| 14 #include "mojo/edk/system/channel.h" | 14 #include "mojo/edk/system/channel.h" |
| 15 #include "mojo/edk/system/channel_endpoint.h" | 15 #include "mojo/edk/system/channel_endpoint.h" |
| 16 #include "mojo/edk/system/message_pipe_dispatcher.h" | 16 #include "mojo/edk/system/message_pipe_dispatcher.h" |
| 17 #include "mojo/edk/system/test/simple_test_thread.h" | 17 #include "mojo/edk/system/test/simple_test_thread.h" |
| 18 #include "mojo/edk/util/ref_ptr.h" | 18 #include "mojo/edk/util/ref_ptr.h" |
| 19 #include "mojo/public/cpp/system/macros.h" | 19 #include "mojo/public/cpp/system/macros.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 using mojo::platform::TaskRunner; |
| 22 using mojo::util::MakeRefCounted; | 23 using mojo::util::MakeRefCounted; |
| 23 using mojo::util::RefPtr; | 24 using mojo::util::RefPtr; |
| 24 | 25 |
| 25 namespace mojo { | 26 namespace mojo { |
| 26 namespace system { | 27 namespace system { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 class ChannelManagerTest : public testing::Test { | 30 class ChannelManagerTest : public testing::Test { |
| 30 public: | 31 public: |
| 31 ChannelManagerTest() | 32 ChannelManagerTest() |
| 32 : message_loop_(base::MessageLoop::TYPE_IO), | 33 : message_loop_(base::MessageLoop::TYPE_IO), |
| 33 task_runner_(MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( | 34 task_runner_(MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( |
| 34 message_loop_.task_runner())), | 35 message_loop_.task_runner())), |
| 35 channel_manager_(&platform_support_, task_runner_.Clone(), nullptr) {} | 36 channel_manager_(&platform_support_, task_runner_.Clone(), nullptr) {} |
| 36 ~ChannelManagerTest() override {} | 37 ~ChannelManagerTest() override {} |
| 37 | 38 |
| 38 protected: | 39 protected: |
| 39 const RefPtr<embedder::PlatformTaskRunner>& task_runner() { | 40 const RefPtr<TaskRunner>& task_runner() { return task_runner_; } |
| 40 return task_runner_; | |
| 41 } | |
| 42 ChannelManager& channel_manager() { return channel_manager_; } | 41 ChannelManager& channel_manager() { return channel_manager_; } |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 embedder::SimplePlatformSupport platform_support_; | 44 embedder::SimplePlatformSupport platform_support_; |
| 46 base::MessageLoop message_loop_; | 45 base::MessageLoop message_loop_; |
| 47 RefPtr<embedder::PlatformTaskRunner> task_runner_; | 46 RefPtr<TaskRunner> task_runner_; |
| 48 // Note: This should be *after* the above, since they must be initialized | 47 // Note: This should be *after* the above, since they must be initialized |
| 49 // before it (and should outlive it). | 48 // before it (and should outlive it). |
| 50 ChannelManager channel_manager_; | 49 ChannelManager channel_manager_; |
| 51 | 50 |
| 52 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManagerTest); | 51 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManagerTest); |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 TEST_F(ChannelManagerTest, Basic) { | 54 TEST_F(ChannelManagerTest, Basic) { |
| 56 embedder::PlatformChannelPair channel_pair; | 55 embedder::PlatformChannelPair channel_pair; |
| 57 | 56 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 EXPECT_TRUE(ch2->HasOneRef()); | 103 EXPECT_TRUE(ch2->HasOneRef()); |
| 105 | 104 |
| 106 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); | 105 EXPECT_EQ(MOJO_RESULT_OK, d1->Close()); |
| 107 EXPECT_EQ(MOJO_RESULT_OK, d2->Close()); | 106 EXPECT_EQ(MOJO_RESULT_OK, d2->Close()); |
| 108 } | 107 } |
| 109 | 108 |
| 110 class OtherThread : public test::SimpleTestThread { | 109 class OtherThread : public test::SimpleTestThread { |
| 111 public: | 110 public: |
| 112 // Note: There should be no other refs to the channel identified by | 111 // Note: There should be no other refs to the channel identified by |
| 113 // |channel_id| outside the channel manager. | 112 // |channel_id| outside the channel manager. |
| 114 OtherThread(RefPtr<embedder::PlatformTaskRunner>&& task_runner, | 113 OtherThread(RefPtr<TaskRunner>&& task_runner, |
| 115 ChannelManager* channel_manager, | 114 ChannelManager* channel_manager, |
| 116 ChannelId channel_id, | 115 ChannelId channel_id, |
| 117 const base::Closure& quit_closure) | 116 const base::Closure& quit_closure) |
| 118 : task_runner_(std::move(task_runner)), | 117 : task_runner_(std::move(task_runner)), |
| 119 channel_manager_(channel_manager), | 118 channel_manager_(channel_manager), |
| 120 channel_id_(channel_id), | 119 channel_id_(channel_id), |
| 121 quit_closure_(quit_closure) {} | 120 quit_closure_(quit_closure) {} |
| 122 ~OtherThread() override {} | 121 ~OtherThread() override {} |
| 123 | 122 |
| 124 private: | 123 private: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 141 channel_manager_->ShutdownChannel( | 140 channel_manager_->ShutdownChannel( |
| 142 channel_id_, run_loop.QuitClosure(), | 141 channel_id_, run_loop.QuitClosure(), |
| 143 MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( | 142 MakeRefCounted<base_edk::PlatformTaskRunnerImpl>( |
| 144 message_loop.task_runner())); | 143 message_loop.task_runner())); |
| 145 run_loop.Run(); | 144 run_loop.Run(); |
| 146 } | 145 } |
| 147 | 146 |
| 148 task_runner_->PostTask(quit_closure_); | 147 task_runner_->PostTask(quit_closure_); |
| 149 } | 148 } |
| 150 | 149 |
| 151 const RefPtr<embedder::PlatformTaskRunner> task_runner_; | 150 const RefPtr<TaskRunner> task_runner_; |
| 152 ChannelManager* const channel_manager_; | 151 ChannelManager* const channel_manager_; |
| 153 const ChannelId channel_id_; | 152 const ChannelId channel_id_; |
| 154 base::Closure quit_closure_; | 153 base::Closure quit_closure_; |
| 155 | 154 |
| 156 MOJO_DISALLOW_COPY_AND_ASSIGN(OtherThread); | 155 MOJO_DISALLOW_COPY_AND_ASSIGN(OtherThread); |
| 157 }; | 156 }; |
| 158 | 157 |
| 159 TEST_F(ChannelManagerTest, CallsFromOtherThread) { | 158 TEST_F(ChannelManagerTest, CallsFromOtherThread) { |
| 160 embedder::PlatformChannelPair channel_pair; | 159 embedder::PlatformChannelPair channel_pair; |
| 161 | 160 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 | 171 |
| 173 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); | 172 EXPECT_EQ(MOJO_RESULT_OK, d->Close()); |
| 174 } | 173 } |
| 175 | 174 |
| 176 // TODO(vtl): Test |CreateChannelWithoutBootstrapOnIOThread()|. (This will | 175 // TODO(vtl): Test |CreateChannelWithoutBootstrapOnIOThread()|. (This will |
| 177 // require additional functionality in |Channel|.) | 176 // require additional functionality in |Channel|.) |
| 178 | 177 |
| 179 } // namespace | 178 } // namespace |
| 180 } // namespace system | 179 } // namespace system |
| 181 } // namespace mojo | 180 } // namespace mojo |
| OLD | NEW |