Index: base/threading/thread_unittest.cc |
diff --git a/base/threading/thread_unittest.cc b/base/threading/thread_unittest.cc |
index dfa04c6ac48fce2e445daccb4e14911bda951757..48a8770a7b2c469499be4a642d8eebc4ac3528d0 100644 |
--- a/base/threading/thread_unittest.cc |
+++ b/base/threading/thread_unittest.cc |
@@ -164,10 +164,38 @@ TEST_F(ThreadTest, StartWithOptions_StackSize) { |
event.Wait(); |
} |
-TEST_F(ThreadTest, TwoTasks) { |
+TEST_F(ThreadTest, StartWithOptions_NonJoinable) { |
+ Thread a("StartNonJoinable"); |
+ Thread::Options options; |
+ options.joinable = false; |
+ EXPECT_TRUE(a.StartWithOptions(options)); |
+ EXPECT_TRUE(a.message_loop()); |
+ EXPECT_TRUE(a.IsRunning()); |
+ |
+ // Make the thread block until |block_event| is signaled. |
+ base::WaitableEvent block_event( |
+ base::WaitableEvent::ResetPolicy::AUTOMATIC, |
+ base::WaitableEvent::InitialState::NOT_SIGNALED); |
+ a.task_runner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&base::WaitableEvent::Wait, base::Unretained(&block_event))); |
+ |
+ // Stop() shouldn't block despite the thread still being alive. |
+ a.Stop(); |
+ EXPECT_TRUE(a.IsRunning()); |
+ |
+ // Unblock the task and give a bit of extra time to unwind QuitWhenIdle(). |
+ block_event.Signal(); |
+ base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
+ |
+ // The thread should now have stopped on its own. |
+ EXPECT_FALSE(a.IsRunning()); |
+} |
+ |
+TEST_F(ThreadTest, TwoTasksOnJoinableThread) { |
bool was_invoked = false; |
{ |
- Thread a("TwoTasks"); |
+ Thread a("TwoTasksOnJoinableThread"); |
EXPECT_TRUE(a.Start()); |
EXPECT_TRUE(a.message_loop()); |