| 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/common/handle_watcher.h" | 5 #include "mojo/common/handle_watcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/at_exit.h" | |
| 10 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 11 #include "base/bind.h" | 10 #include "base/bind.h" |
| 12 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 13 #include "base/test/simple_test_tick_clock.h" | 12 #include "base/test/simple_test_tick_clock.h" |
| 14 #include "mojo/common/time_helper.h" | 13 #include "mojo/common/time_helper.h" |
| 14 #include "mojo/public/cpp/environment/environment.h" |
| 15 #include "mojo/public/cpp/system/core.h" | 15 #include "mojo/public/cpp/system/core.h" |
| 16 #include "mojo/public/cpp/test_support/test_utils.h" | 16 #include "mojo/public/cpp/test_support/test_utils.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace mojo { | 19 namespace mojo { |
| 20 namespace common { | 20 namespace common { |
| 21 namespace test { | 21 namespace test { |
| 22 | 22 |
| 23 void ObserveCallback(bool* was_signaled, | 23 void ObserveCallback(bool* was_signaled, |
| 24 MojoResult* result_observed, | 24 MojoResult* result_observed, |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 109 } |
| 110 | 110 |
| 111 protected: | 111 protected: |
| 112 void InstallTickClock() { | 112 void InstallTickClock() { |
| 113 test::SetTickClockForTest(&tick_clock_); | 113 test::SetTickClockForTest(&tick_clock_); |
| 114 } | 114 } |
| 115 | 115 |
| 116 base::SimpleTestTickClock tick_clock_; | 116 base::SimpleTestTickClock tick_clock_; |
| 117 | 117 |
| 118 private: | 118 private: |
| 119 base::ShadowingAtExitManager at_exit_; | 119 Environment environment_; |
| 120 base::MessageLoop message_loop_; | 120 base::MessageLoop message_loop_; |
| 121 | 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest); | 122 DISALLOW_COPY_AND_ASSIGN(HandleWatcherTest); |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 // Trivial test case with a single handle to watch. | 125 // Trivial test case with a single handle to watch. |
| 126 TEST_F(HandleWatcherTest, SingleHandler) { | 126 TEST_F(HandleWatcherTest, SingleHandler) { |
| 127 MessagePipe test_pipe; | 127 MessagePipe test_pipe; |
| 128 ASSERT_TRUE(test_pipe.handle0.is_valid()); | 128 ASSERT_TRUE(test_pipe.handle0.is_valid()); |
| 129 CallbackHelper callback_helper; | 129 CallbackHelper callback_helper; |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 EXPECT_TRUE(mojo::test::WriteTextMessage(test_pipe.handle0.get(), | 311 EXPECT_TRUE(mojo::test::WriteTextMessage(test_pipe.handle0.get(), |
| 312 std::string())); | 312 std::string())); |
| 313 callback_helper.RunUntilGotCallback(); | 313 callback_helper.RunUntilGotCallback(); |
| 314 EXPECT_TRUE(callback_helper.got_callback()); | 314 EXPECT_TRUE(callback_helper.got_callback()); |
| 315 } | 315 } |
| 316 | 316 |
| 317 TEST(HandleWatcherCleanEnvironmentTest, AbortedOnMessageLoopDestruction) { | 317 TEST(HandleWatcherCleanEnvironmentTest, AbortedOnMessageLoopDestruction) { |
| 318 bool was_signaled = false; | 318 bool was_signaled = false; |
| 319 MojoResult result = MOJO_RESULT_OK; | 319 MojoResult result = MOJO_RESULT_OK; |
| 320 | 320 |
| 321 base::ShadowingAtExitManager at_exit; | 321 Environment env; |
| 322 |
| 322 MessagePipe pipe; | 323 MessagePipe pipe; |
| 323 HandleWatcher watcher; | 324 HandleWatcher watcher; |
| 324 { | 325 { |
| 325 base::MessageLoop loop; | 326 base::MessageLoop loop; |
| 326 | 327 |
| 327 watcher.Start(pipe.handle0.get(), | 328 watcher.Start(pipe.handle0.get(), |
| 328 MOJO_WAIT_FLAG_READABLE, | 329 MOJO_WAIT_FLAG_READABLE, |
| 329 MOJO_DEADLINE_INDEFINITE, | 330 MOJO_DEADLINE_INDEFINITE, |
| 330 base::Bind(&ObserveCallback, &was_signaled, &result)); | 331 base::Bind(&ObserveCallback, &was_signaled, &result)); |
| 331 | 332 |
| 332 // Now, let the MessageLoop get torn down. We expect our callback to run. | 333 // Now, let the MessageLoop get torn down. We expect our callback to run. |
| 333 } | 334 } |
| 334 | 335 |
| 335 EXPECT_TRUE(was_signaled); | 336 EXPECT_TRUE(was_signaled); |
| 336 EXPECT_EQ(MOJO_RESULT_ABORTED, result); | 337 EXPECT_EQ(MOJO_RESULT_ABORTED, result); |
| 337 } | 338 } |
| 338 | 339 |
| 339 } // namespace test | 340 } // namespace test |
| 340 } // namespace common | 341 } // namespace common |
| 341 } // namespace mojo | 342 } // namespace mojo |
| OLD | NEW |