Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Unified Diff: ipc/mojo/async_handle_waiter_unittest.cc

Issue 973213002: Make AsyncHandleWaiter reenterancy-safe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Landing Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ipc/mojo/async_handle_waiter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/mojo/async_handle_waiter_unittest.cc
diff --git a/ipc/mojo/async_handle_waiter_unittest.cc b/ipc/mojo/async_handle_waiter_unittest.cc
index fbaf3ca421e64b43971eaa9aade6f328b5131195..38f3bd68e40cde36f9ce1d098b25bb8ba4e481f2 100644
--- a/ipc/mojo/async_handle_waiter_unittest.cc
+++ b/ipc/mojo/async_handle_waiter_unittest.cc
@@ -204,6 +204,53 @@ TEST_F(AsyncHandleWaiterTest, RestartWaitingWhileSignaled) {
ignore_result(pipe_to_read_.release());
}
+class AsyncHandleWaiterIOObserverTest : public testing::Test {
+ public:
+ void SetUp() override {
+ message_loop_.reset(new base::MessageLoopForIO());
+ target_.reset(new AsyncHandleWaiter(
+ base::Bind(&AsyncHandleWaiterIOObserverTest::HandleIsReady,
+ base::Unretained(this))));
+ invocation_count_ = 0;
+ }
+
+ void HandleIsReady(MojoResult result) { invocation_count_++; }
+
+ scoped_ptr<base::MessageLoop> message_loop_;
+ scoped_ptr<AsyncHandleWaiter> target_;
+ size_t invocation_count_;
+};
+
+TEST_F(AsyncHandleWaiterIOObserverTest, OutsideIOEvnet) {
+ target_->GetWaitCallbackForTest().Run(MOJO_RESULT_OK);
+ EXPECT_EQ(0U, invocation_count_);
+ message_loop_->RunUntilIdle();
+ EXPECT_EQ(1U, invocation_count_);
+}
+
+TEST_F(AsyncHandleWaiterIOObserverTest, InsideIOEvnet) {
+ target_->GetIOObserverForTest()->WillProcessIOEvent();
+ target_->GetWaitCallbackForTest().Run(MOJO_RESULT_OK);
+ EXPECT_EQ(0U, invocation_count_);
+ target_->GetIOObserverForTest()->DidProcessIOEvent();
+ EXPECT_EQ(1U, invocation_count_);
+}
+
+TEST_F(AsyncHandleWaiterIOObserverTest, Reenter) {
+ target_->GetIOObserverForTest()->WillProcessIOEvent();
+ target_->GetWaitCallbackForTest().Run(MOJO_RESULT_OK);
+ EXPECT_EQ(0U, invocation_count_);
+
+ // As if some other io handler start nested loop.
+ target_->GetIOObserverForTest()->WillProcessIOEvent();
+ target_->GetWaitCallbackForTest().Run(MOJO_RESULT_OK);
+ target_->GetIOObserverForTest()->DidProcessIOEvent();
+ EXPECT_EQ(0U, invocation_count_);
+
+ target_->GetIOObserverForTest()->DidProcessIOEvent();
+ EXPECT_EQ(1U, invocation_count_);
+}
+
} // namespace
} // namespace internal
} // namespace IPC
« no previous file with comments | « ipc/mojo/async_handle_waiter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698