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/message_pump/message_pump_mojo.h" | 5 #include "mojo/message_pump/message_pump_mojo.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/message_loop/message_loop_test.h" | 8 #include "base/message_loop/message_loop_test.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "mojo/message_pump/message_pump_mojo_handler.h" | 10 #include "mojo/message_pump/message_pump_mojo_handler.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 MessagePipe handles; | 152 MessagePipe handles; |
153 MessagePumpMojo::current()->AddHandler( | 153 MessagePumpMojo::current()->AddHandler( |
154 &handler, | 154 &handler, |
155 handles.handle0.get(), | 155 handles.handle0.get(), |
156 MOJO_HANDLE_SIGNAL_READABLE, | 156 MOJO_HANDLE_SIGNAL_READABLE, |
157 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1)); | 157 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(1)); |
158 run_loop.Run(); | 158 run_loop.Run(); |
159 EXPECT_EQ(1, handler.error_count()); | 159 EXPECT_EQ(1, handler.error_count()); |
160 } | 160 } |
161 | 161 |
| 162 TEST(MessagePumpMojo, AddClosedHandle) { |
| 163 base::MessageLoop message_loop(MessagePumpMojo::Create()); |
| 164 CountingMojoHandler handler; |
| 165 MessagePipe handles; |
| 166 Handle closed_handle = handles.handle0.get(); |
| 167 handles.handle0.reset(); |
| 168 MessagePumpMojo::current()->AddHandler( |
| 169 &handler, closed_handle, MOJO_HANDLE_SIGNAL_READABLE, base::TimeTicks()); |
| 170 base::RunLoop run_loop; |
| 171 run_loop.RunUntilIdle(); |
| 172 MessagePumpMojo::current()->RemoveHandler(closed_handle); |
| 173 EXPECT_EQ(0, handler.error_count()); |
| 174 EXPECT_EQ(0, handler.success_count()); |
| 175 } |
| 176 |
| 177 TEST(MessagePumpMojo, CloseAfterAdding) { |
| 178 base::MessageLoop message_loop(MessagePumpMojo::Create()); |
| 179 CountingMojoHandler handler; |
| 180 MessagePipe handles; |
| 181 MessagePumpMojo::current()->AddHandler(&handler, handles.handle0.get(), |
| 182 MOJO_HANDLE_SIGNAL_READABLE, |
| 183 base::TimeTicks()); |
| 184 handles.handle0.reset(); |
| 185 base::RunLoop run_loop; |
| 186 run_loop.RunUntilIdle(); |
| 187 EXPECT_EQ(1, handler.error_count()); |
| 188 EXPECT_EQ(0, handler.success_count()); |
| 189 } |
| 190 |
162 } // namespace test | 191 } // namespace test |
163 } // namespace common | 192 } // namespace common |
164 } // namespace mojo | 193 } // namespace mojo |
OLD | NEW |