| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shell/handle_watcher.h" | 5 #include "mojo/common/handle_watcher.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
| 11 #include "mojo/shell/scoped_message_pipe.h" | 11 #include "mojo/common/scoped_message_pipe.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 namespace shell { | 15 namespace common { |
| 16 namespace test { | 16 namespace test { |
| 17 | 17 |
| 18 MojoResult WriteToHandle(MojoHandle handle) { | 18 MojoResult WriteToHandle(MojoHandle handle) { |
| 19 return MojoWriteMessage(handle, NULL, 0, NULL, 0, | 19 return MojoWriteMessage(handle, NULL, 0, NULL, 0, |
| 20 MOJO_WRITE_MESSAGE_FLAG_NONE); | 20 MOJO_WRITE_MESSAGE_FLAG_NONE); |
| 21 } | 21 } |
| 22 | 22 |
| 23 MojoResult ReadFromHandle(MojoHandle handle) { | 23 MojoResult ReadFromHandle(MojoHandle handle) { |
| 24 uint32_t num_bytes = 0; | 24 uint32_t num_bytes = 0; |
| 25 uint32_t num_handles = 0; | 25 uint32_t num_handles = 0; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 protected: | 97 protected: |
| 98 void InstallTickClock() { | 98 void InstallTickClock() { |
| 99 HandleWatcher::tick_clock_ = &tick_clock_; | 99 HandleWatcher::tick_clock_ = &tick_clock_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 base::SimpleTestTickClock tick_clock_; | 102 base::SimpleTestTickClock tick_clock_; |
| 103 | 103 |
| 104 private: | 104 private: |
| 105 base::MessageLoop message_loop_; |
| 106 |
| 105 DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest); | 107 DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest); |
| 106 }; | 108 }; |
| 107 | 109 |
| 108 // Trivial test case with a single handle to watch. | 110 // Trivial test case with a single handle to watch. |
| 109 TEST_F(HandleWatcherTest, SingleHandler) { | 111 TEST_F(HandleWatcherTest, SingleHandler) { |
| 110 ScopedMessagePipe test_pipe; | 112 ScopedMessagePipe test_pipe; |
| 111 ASSERT_NE(MOJO_HANDLE_INVALID, test_pipe.handle_0()); | 113 ASSERT_NE(MOJO_HANDLE_INVALID, test_pipe.handle_0()); |
| 112 CallbackHelper callback_helper; | 114 CallbackHelper callback_helper; |
| 113 HandleWatcher watcher; | 115 HandleWatcher watcher; |
| 114 callback_helper.Start(&watcher, test_pipe.handle_0()); | 116 callback_helper.Start(&watcher, test_pipe.handle_0()); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 HandleWatcher watcher3; | 269 HandleWatcher watcher3; |
| 268 callback_helper3.Start(&watcher3, test_pipe3.handle_0()); | 270 callback_helper3.Start(&watcher3, test_pipe3.handle_0()); |
| 269 | 271 |
| 270 callback_helper2.RunUntilGotCallback(); | 272 callback_helper2.RunUntilGotCallback(); |
| 271 EXPECT_FALSE(callback_helper1.got_callback()); | 273 EXPECT_FALSE(callback_helper1.got_callback()); |
| 272 EXPECT_TRUE(callback_helper2.got_callback()); | 274 EXPECT_TRUE(callback_helper2.got_callback()); |
| 273 EXPECT_FALSE(callback_helper3.got_callback()); | 275 EXPECT_FALSE(callback_helper3.got_callback()); |
| 274 } | 276 } |
| 275 | 277 |
| 276 } // namespace test | 278 } // namespace test |
| 277 } // namespace shell | 279 } // namespace common |
| 278 } // namespace mojo | 280 } // namespace mojo |
| OLD | NEW |