OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/threading/thread.h" | 5 #include "base/threading/thread.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 a->StopSoon(); | 314 a->StopSoon(); |
315 base::PlatformThread::YieldCurrentThread(); | 315 base::PlatformThread::YieldCurrentThread(); |
316 last_task_event.Wait(); | 316 last_task_event.Wait(); |
317 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); | 317 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(20)); |
318 | 318 |
319 // This test assumes that the above was sufficient to let the thread fully | 319 // This test assumes that the above was sufficient to let the thread fully |
320 // stop. | 320 // stop. |
321 ASSERT_FALSE(a->IsRunning()); | 321 ASSERT_FALSE(a->IsRunning()); |
322 | 322 |
323 // Restarting it should not be allowed. | 323 // Restarting it should not be allowed. |
324 EXPECT_DCHECK_DEATH(a->Start(), ""); | 324 EXPECT_DCHECK_DEATH(a->Start()); |
325 } | 325 } |
326 | 326 |
327 TEST_F(ThreadTest, ThreadName) { | 327 TEST_F(ThreadTest, ThreadName) { |
328 Thread a("ThreadName"); | 328 Thread a("ThreadName"); |
329 EXPECT_TRUE(a.Start()); | 329 EXPECT_TRUE(a.Start()); |
330 EXPECT_EQ("ThreadName", a.thread_name()); | 330 EXPECT_EQ("ThreadName", a.thread_name()); |
331 } | 331 } |
332 | 332 |
333 TEST_F(ThreadTest, ThreadId) { | 333 TEST_F(ThreadTest, ThreadId) { |
334 Thread a("ThreadId0"); | 334 Thread a("ThreadId0"); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 464 |
465 a.Stop(); | 465 a.Stop(); |
466 EXPECT_FALSE(a.message_loop()); | 466 EXPECT_FALSE(a.message_loop()); |
467 EXPECT_FALSE(a.IsRunning()); | 467 EXPECT_FALSE(a.IsRunning()); |
468 | 468 |
469 // Confirm that running any remaining tasks posted from Stop() goes smoothly | 469 // Confirm that running any remaining tasks posted from Stop() goes smoothly |
470 // (e.g. https://codereview.chromium.org/2135413003/#ps300001 crashed if | 470 // (e.g. https://codereview.chromium.org/2135413003/#ps300001 crashed if |
471 // StopSoon() posted Thread::ThreadQuitHelper() while |run_loop_| was null). | 471 // StopSoon() posted Thread::ThreadQuitHelper() while |run_loop_| was null). |
472 base::RunLoop().RunUntilIdle(); | 472 base::RunLoop().RunUntilIdle(); |
473 } | 473 } |
OLD | NEW |