OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ipc/mojo/async_handle_waiter.h" | 5 #include "ipc/mojo/async_handle_waiter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.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 "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 EXPECT_EQ(MOJO_RESULT_OK, Start()); | 197 EXPECT_EQ(MOJO_RESULT_OK, Start()); |
198 WriteToPipe(); | 198 WriteToPipe(); |
199 run_loop_->Run(); | 199 run_loop_->Run(); |
200 | 200 |
201 EXPECT_TRUE(handler.IsClosingHandled()); | 201 EXPECT_TRUE(handler.IsClosingHandled()); |
202 | 202 |
203 // |HandlerThatReenters::RestartAndClose| already closed it. | 203 // |HandlerThatReenters::RestartAndClose| already closed it. |
204 ignore_result(pipe_to_read_.release()); | 204 ignore_result(pipe_to_read_.release()); |
205 } | 205 } |
206 | 206 |
| 207 class AsyncHandleWaiterIOObserverTest : public testing::Test { |
| 208 public: |
| 209 void SetUp() override { |
| 210 message_loop_.reset(new base::MessageLoopForIO()); |
| 211 target_.reset(new AsyncHandleWaiter( |
| 212 base::Bind(&AsyncHandleWaiterIOObserverTest::HandleIsReady, |
| 213 base::Unretained(this)))); |
| 214 invocation_count_ = 0; |
| 215 } |
| 216 |
| 217 void HandleIsReady(MojoResult result) { invocation_count_++; } |
| 218 |
| 219 scoped_ptr<base::MessageLoop> message_loop_; |
| 220 scoped_ptr<AsyncHandleWaiter> target_; |
| 221 size_t invocation_count_; |
| 222 }; |
| 223 |
| 224 TEST_F(AsyncHandleWaiterIOObserverTest, OutsideIOEvnet) { |
| 225 target_->GetWaitCallbackForTest().Run(MOJO_RESULT_OK); |
| 226 EXPECT_EQ(0U, invocation_count_); |
| 227 message_loop_->RunUntilIdle(); |
| 228 EXPECT_EQ(1U, invocation_count_); |
| 229 } |
| 230 |
| 231 TEST_F(AsyncHandleWaiterIOObserverTest, InsideIOEvnet) { |
| 232 target_->GetIOObserverForTest()->WillProcessIOEvent(); |
| 233 target_->GetWaitCallbackForTest().Run(MOJO_RESULT_OK); |
| 234 EXPECT_EQ(0U, invocation_count_); |
| 235 target_->GetIOObserverForTest()->DidProcessIOEvent(); |
| 236 EXPECT_EQ(1U, invocation_count_); |
| 237 } |
| 238 |
| 239 TEST_F(AsyncHandleWaiterIOObserverTest, Reenter) { |
| 240 target_->GetIOObserverForTest()->WillProcessIOEvent(); |
| 241 target_->GetWaitCallbackForTest().Run(MOJO_RESULT_OK); |
| 242 EXPECT_EQ(0U, invocation_count_); |
| 243 |
| 244 // As if some other io handler start nested loop. |
| 245 target_->GetIOObserverForTest()->WillProcessIOEvent(); |
| 246 target_->GetWaitCallbackForTest().Run(MOJO_RESULT_OK); |
| 247 target_->GetIOObserverForTest()->DidProcessIOEvent(); |
| 248 EXPECT_EQ(0U, invocation_count_); |
| 249 |
| 250 target_->GetIOObserverForTest()->DidProcessIOEvent(); |
| 251 EXPECT_EQ(1U, invocation_count_); |
| 252 } |
| 253 |
207 } // namespace | 254 } // namespace |
208 } // namespace internal | 255 } // namespace internal |
209 } // namespace IPC | 256 } // namespace IPC |
OLD | NEW |