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/message_pump/handle_watcher.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/at_exit.h" | 9 #include "base/at_exit.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/test/simple_test_tick_clock.h" | 14 #include "base/test/simple_test_tick_clock.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "mojo/common/message_pump_mojo.h" | 16 #include "mojo/message_pump/message_pump_mojo.h" |
17 #include "mojo/common/time_helper.h" | 17 #include "mojo/message_pump/time_helper.h" |
| 18 #include "mojo/public/cpp/system/message_pipe.h" |
| 19 #include "mojo/public/cpp/test_support/test_utils.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "third_party/mojo/src/mojo/public/cpp/system/core.h" | |
20 #include "third_party/mojo/src/mojo/public/cpp/test_support/test_utils.h" | |
21 | 21 |
22 namespace mojo { | 22 namespace mojo { |
23 namespace common { | 23 namespace common { |
24 namespace test { | 24 namespace test { |
25 | 25 |
26 enum MessageLoopConfig { | 26 enum MessageLoopConfig { |
27 MESSAGE_LOOP_CONFIG_DEFAULT = 0, | 27 MESSAGE_LOOP_CONFIG_DEFAULT = 0, |
28 MESSAGE_LOOP_CONFIG_MOJO = 1 | 28 MESSAGE_LOOP_CONFIG_MOJO = 1 |
29 }; | 29 }; |
30 | 30 |
(...skipping 16 matching lines...) Expand all Loading... |
47 delete watcher; | 47 delete watcher; |
48 next_callback.Run(result); | 48 next_callback.Run(result); |
49 } | 49 } |
50 | 50 |
51 scoped_ptr<base::MessageLoop> CreateMessageLoop(MessageLoopConfig config) { | 51 scoped_ptr<base::MessageLoop> CreateMessageLoop(MessageLoopConfig config) { |
52 scoped_ptr<base::MessageLoop> loop; | 52 scoped_ptr<base::MessageLoop> loop; |
53 if (config == MESSAGE_LOOP_CONFIG_DEFAULT) | 53 if (config == MESSAGE_LOOP_CONFIG_DEFAULT) |
54 loop.reset(new base::MessageLoop()); | 54 loop.reset(new base::MessageLoop()); |
55 else | 55 else |
56 loop.reset(new base::MessageLoop(MessagePumpMojo::Create())); | 56 loop.reset(new base::MessageLoop(MessagePumpMojo::Create())); |
57 return loop.Pass(); | 57 return loop; |
58 } | 58 } |
59 | 59 |
60 // Helper class to manage the callback and running the message loop waiting for | 60 // Helper class to manage the callback and running the message loop waiting for |
61 // message to be received. Typical usage is something like: | 61 // message to be received. Typical usage is something like: |
62 // Schedule callback returned from GetCallback(). | 62 // Schedule callback returned from GetCallback(). |
63 // RunUntilGotCallback(); | 63 // RunUntilGotCallback(); |
64 // EXPECT_TRUE(got_callback()); | 64 // EXPECT_TRUE(got_callback()); |
65 // clear_callback(); | 65 // clear_callback(); |
66 class CallbackHelper { | 66 class CallbackHelper { |
67 public: | 67 public: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 base::WeakPtrFactory<CallbackHelper> weak_factory_; | 115 base::WeakPtrFactory<CallbackHelper> weak_factory_; |
116 | 116 |
117 private: | 117 private: |
118 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); | 118 DISALLOW_COPY_AND_ASSIGN(CallbackHelper); |
119 }; | 119 }; |
120 | 120 |
121 class HandleWatcherTest : public testing::TestWithParam<MessageLoopConfig> { | 121 class HandleWatcherTest : public testing::TestWithParam<MessageLoopConfig> { |
122 public: | 122 public: |
123 HandleWatcherTest() : message_loop_(CreateMessageLoop(GetParam())) {} | 123 HandleWatcherTest() : message_loop_(CreateMessageLoop(GetParam())) {} |
124 virtual ~HandleWatcherTest() { | 124 ~HandleWatcherTest() override { |
125 test::SetTickClockForTest(NULL); | 125 test::SetTickClockForTest(NULL); |
126 } | 126 } |
127 | 127 |
128 protected: | 128 protected: |
129 void TearDownMessageLoop() { | 129 void TearDownMessageLoop() { |
130 message_loop_.reset(); | 130 message_loop_.reset(); |
131 } | 131 } |
132 | 132 |
133 void InstallTickClock() { | 133 void InstallTickClock() { |
134 test::SetTickClockForTest(&tick_clock_); | 134 test::SetTickClockForTest(&tick_clock_); |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 message_loop.task_runner(), | 474 message_loop.task_runner(), |
475 &run_loop, &threads_active_counter)); | 475 &run_loop, &threads_active_counter)); |
476 } | 476 } |
477 run_loop.Run(); | 477 run_loop.Run(); |
478 ASSERT_EQ(0, threads_active_counter); | 478 ASSERT_EQ(0, threads_active_counter); |
479 } | 479 } |
480 | 480 |
481 } // namespace test | 481 } // namespace test |
482 } // namespace common | 482 } // namespace common |
483 } // namespace mojo | 483 } // namespace mojo |
OLD | NEW |