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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/message_loop/message_loop_test.h" | 17 #include "base/message_loop/message_loop_test.h" |
18 #include "base/pending_task.h" | 18 #include "base/pending_task.h" |
19 #include "base/posix/eintr_wrapper.h" | 19 #include "base/posix/eintr_wrapper.h" |
20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
21 #include "base/single_thread_task_runner.h" | |
21 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
22 #include "base/test/test_simple_task_runner.h" | 23 #include "base/test/test_simple_task_runner.h" |
23 #include "base/threading/platform_thread.h" | 24 #include "base/threading/platform_thread.h" |
24 #include "base/threading/thread.h" | 25 #include "base/threading/thread.h" |
25 #include "base/threading/thread_task_runner_handle.h" | 26 #include "base/threading/thread_task_runner_handle.h" |
26 #include "build/build_config.h" | 27 #include "build/build_config.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
30 #include "base/message_loop/message_pump_win.h" | 31 #include "base/message_loop/message_pump_win.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 MessageLoop::current()->SetNestableTasksAllowed(true); | 100 MessageLoop::current()->SetNestableTasksAllowed(true); |
100 MSG msg; | 101 MSG msg; |
101 while (GetMessage(&msg, NULL, 0, 0)) { | 102 while (GetMessage(&msg, NULL, 0, 0)) { |
102 TranslateMessage(&msg); | 103 TranslateMessage(&msg); |
103 DispatchMessage(&msg); | 104 DispatchMessage(&msg); |
104 } | 105 } |
105 MessageLoop::current()->QuitWhenIdle(); | 106 MessageLoop::current()->QuitWhenIdle(); |
106 } | 107 } |
107 | 108 |
108 void RunTest_PostDelayedTask_SharedTimer_SubPump() { | 109 void RunTest_PostDelayedTask_SharedTimer_SubPump() { |
109 MessageLoop loop(MessageLoop::TYPE_UI); | 110 MessageLoop message_loop(MessageLoop::TYPE_UI); |
110 | 111 |
111 // Test that the interval of the timer, used to run the next delayed task, is | 112 // Test that the interval of the timer, used to run the next delayed task, is |
112 // set to a value corresponding to when the next delayed task should run. | 113 // set to a value corresponding to when the next delayed task should run. |
113 | 114 |
114 // By setting num_tasks to 1, we ensure that the first task to run causes the | 115 // By setting num_tasks to 1, we ensure that the first task to run causes the |
115 // run loop to exit. | 116 // run loop to exit. |
116 int num_tasks = 1; | 117 int num_tasks = 1; |
117 Time run_time; | 118 Time run_time; |
118 | 119 |
119 loop.PostTask(FROM_HERE, Bind(&SubPumpFunc)); | 120 message_loop.task_runner()->PostTask(FROM_HERE, Bind(&SubPumpFunc)); |
120 | 121 |
121 // This very delayed task should never run. | 122 // This very delayed task should never run. |
122 loop.PostDelayedTask( | 123 message_loop.task_runner()->PostDelayedTask( |
123 FROM_HERE, | 124 FROM_HERE, Bind(&RecordRunTimeFunc, &run_time, &num_tasks), |
124 Bind(&RecordRunTimeFunc, &run_time, &num_tasks), | |
125 TimeDelta::FromSeconds(1000)); | 125 TimeDelta::FromSeconds(1000)); |
126 | 126 |
127 // This slightly delayed task should run from within SubPumpFunc. | 127 // This slightly delayed task should run from within SubPumpFunc. |
128 loop.PostDelayedTask( | 128 message_loop.task_runner()->PostDelayedTask( |
129 FROM_HERE, | 129 FROM_HERE, Bind(&PostQuitMessage, 0), TimeDelta::FromMilliseconds(10)); |
130 Bind(&PostQuitMessage, 0), | |
131 TimeDelta::FromMilliseconds(10)); | |
132 | 130 |
133 Time start_time = Time::Now(); | 131 Time start_time = Time::Now(); |
134 | 132 |
135 loop.Run(); | 133 RunLoop().Run(); |
136 EXPECT_EQ(1, num_tasks); | 134 EXPECT_EQ(1, num_tasks); |
137 | 135 |
138 // Ensure that we ran in far less time than the slower timer. | 136 // Ensure that we ran in far less time than the slower timer. |
139 TimeDelta total_time = Time::Now() - start_time; | 137 TimeDelta total_time = Time::Now() - start_time; |
140 EXPECT_GT(5000, total_time.InMilliseconds()); | 138 EXPECT_GT(5000, total_time.InMilliseconds()); |
141 | 139 |
142 // In case both timers somehow run at nearly the same time, sleep a little | 140 // In case both timers somehow run at nearly the same time, sleep a little |
143 // and then run all pending to force them both to have run. This is just | 141 // and then run all pending to force them both to have run. This is just |
144 // encouraging flakiness if there is any. | 142 // encouraging flakiness if there is any. |
145 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); | 143 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 } | 263 } |
266 order->RecordEnd(RECURSIVE, cookie); | 264 order->RecordEnd(RECURSIVE, cookie); |
267 } | 265 } |
268 | 266 |
269 void QuitFunc(TaskList* order, int cookie) { | 267 void QuitFunc(TaskList* order, int cookie) { |
270 order->RecordStart(QUITMESSAGELOOP, cookie); | 268 order->RecordStart(QUITMESSAGELOOP, cookie); |
271 MessageLoop::current()->QuitWhenIdle(); | 269 MessageLoop::current()->QuitWhenIdle(); |
272 order->RecordEnd(QUITMESSAGELOOP, cookie); | 270 order->RecordEnd(QUITMESSAGELOOP, cookie); |
273 } | 271 } |
274 | 272 |
275 void RecursiveFuncWin(MessageLoop* target, | 273 void RecursiveFuncWin(MessageLoop* target, |
gab
2016/08/05 01:09:57
Take SingleThreadTaskRunner* instead
fdoray
2016/08/05 16:10:35
Done.
| |
276 HANDLE event, | 274 HANDLE event, |
277 bool expect_window, | 275 bool expect_window, |
278 TaskList* order, | 276 TaskList* order, |
279 bool is_reentrant) { | 277 bool is_reentrant) { |
280 target->PostTask(FROM_HERE, | 278 target->task_runner()->PostTask( |
281 Bind(&RecursiveFunc, order, 1, 2, is_reentrant)); | 279 FROM_HERE, Bind(&RecursiveFunc, order, 1, 2, is_reentrant)); |
282 target->PostTask(FROM_HERE, | 280 target->task_runner()->PostTask( |
283 Bind(&MessageBoxFunc, order, 2, is_reentrant)); | 281 FROM_HERE, Bind(&MessageBoxFunc, order, 2, is_reentrant)); |
284 target->PostTask(FROM_HERE, | 282 target->task_runner()->PostTask( |
285 Bind(&RecursiveFunc, order, 3, 2, is_reentrant)); | 283 FROM_HERE, Bind(&RecursiveFunc, order, 3, 2, is_reentrant)); |
286 // The trick here is that for recursive task processing, this task will be | 284 // The trick here is that for recursive task processing, this task will be |
287 // ran _inside_ the MessageBox message loop, dismissing the MessageBox | 285 // ran _inside_ the MessageBox message loop, dismissing the MessageBox |
288 // without a chance. | 286 // without a chance. |
289 // For non-recursive task processing, this will be executed _after_ the | 287 // For non-recursive task processing, this will be executed _after_ the |
290 // MessageBox will have been dismissed by the code below, where | 288 // MessageBox will have been dismissed by the code below, where |
291 // expect_window_ is true. | 289 // expect_window_ is true. |
292 target->PostTask(FROM_HERE, | 290 target->task_runner()->PostTask(FROM_HERE, Bind(&EndDialogFunc, order, 4)); |
293 Bind(&EndDialogFunc, order, 4)); | 291 target->task_runner()->PostTask(FROM_HERE, Bind(&QuitFunc, order, 5)); |
294 target->PostTask(FROM_HERE, | |
295 Bind(&QuitFunc, order, 5)); | |
296 | 292 |
297 // Enforce that every tasks are sent before starting to run the main thread | 293 // Enforce that every tasks are sent before starting to run the main thread |
298 // message loop. | 294 // message loop. |
299 ASSERT_TRUE(SetEvent(event)); | 295 ASSERT_TRUE(SetEvent(event)); |
300 | 296 |
301 // Poll for the MessageBox. Don't do this at home! At the speed we do it, | 297 // Poll for the MessageBox. Don't do this at home! At the speed we do it, |
302 // you will never realize one MessageBox was shown. | 298 // you will never realize one MessageBox was shown. |
303 for (; expect_window;) { | 299 for (; expect_window;) { |
304 HWND window = FindWindow(L"#32770", kMessageBoxTitle); | 300 HWND window = FindWindow(L"#32770", kMessageBoxTitle); |
305 if (window) { | 301 if (window) { |
(...skipping 17 matching lines...) Expand all Loading... | |
323 // A side effect of this test is the generation a beep. Sorry. | 319 // A side effect of this test is the generation a beep. Sorry. |
324 void RunTest_RecursiveDenial2(MessageLoop::Type message_loop_type) { | 320 void RunTest_RecursiveDenial2(MessageLoop::Type message_loop_type) { |
325 MessageLoop loop(message_loop_type); | 321 MessageLoop loop(message_loop_type); |
326 | 322 |
327 Thread worker("RecursiveDenial2_worker"); | 323 Thread worker("RecursiveDenial2_worker"); |
328 Thread::Options options; | 324 Thread::Options options; |
329 options.message_loop_type = message_loop_type; | 325 options.message_loop_type = message_loop_type; |
330 ASSERT_EQ(true, worker.StartWithOptions(options)); | 326 ASSERT_EQ(true, worker.StartWithOptions(options)); |
331 TaskList order; | 327 TaskList order; |
332 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); | 328 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); |
333 worker.message_loop()->PostTask(FROM_HERE, | 329 worker.task_runner()->PostTask( |
334 Bind(&RecursiveFuncWin, | 330 FROM_HERE, Bind(&RecursiveFuncWin, MessageLoop::current(), event.Get(), |
335 MessageLoop::current(), | 331 true, &order, false)); |
336 event.Get(), | |
337 true, | |
338 &order, | |
339 false)); | |
340 // Let the other thread execute. | 332 // Let the other thread execute. |
341 WaitForSingleObject(event.Get(), INFINITE); | 333 WaitForSingleObject(event.Get(), INFINITE); |
342 MessageLoop::current()->Run(); | 334 RunLoop().Run(); |
343 | 335 |
344 ASSERT_EQ(17u, order.Size()); | 336 ASSERT_EQ(17u, order.Size()); |
345 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); | 337 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); |
346 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); | 338 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); |
347 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); | 339 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); |
348 EXPECT_EQ(order.Get(3), TaskItem(MESSAGEBOX, 2, false)); | 340 EXPECT_EQ(order.Get(3), TaskItem(MESSAGEBOX, 2, false)); |
349 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, true)); | 341 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, true)); |
350 EXPECT_EQ(order.Get(5), TaskItem(RECURSIVE, 3, false)); | 342 EXPECT_EQ(order.Get(5), TaskItem(RECURSIVE, 3, false)); |
351 // When EndDialogFunc is processed, the window is already dismissed, hence no | 343 // When EndDialogFunc is processed, the window is already dismissed, hence no |
352 // "end" entry. | 344 // "end" entry. |
(...skipping 14 matching lines...) Expand all Loading... | |
367 // needs to process windows messages on the current thread. | 359 // needs to process windows messages on the current thread. |
368 void RunTest_RecursiveSupport2(MessageLoop::Type message_loop_type) { | 360 void RunTest_RecursiveSupport2(MessageLoop::Type message_loop_type) { |
369 MessageLoop loop(message_loop_type); | 361 MessageLoop loop(message_loop_type); |
370 | 362 |
371 Thread worker("RecursiveSupport2_worker"); | 363 Thread worker("RecursiveSupport2_worker"); |
372 Thread::Options options; | 364 Thread::Options options; |
373 options.message_loop_type = message_loop_type; | 365 options.message_loop_type = message_loop_type; |
374 ASSERT_EQ(true, worker.StartWithOptions(options)); | 366 ASSERT_EQ(true, worker.StartWithOptions(options)); |
375 TaskList order; | 367 TaskList order; |
376 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); | 368 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); |
377 worker.message_loop()->PostTask(FROM_HERE, | 369 worker.task_runner()->PostTask( |
378 Bind(&RecursiveFuncWin, | 370 FROM_HERE, Bind(&RecursiveFuncWin, MessageLoop::current(), event.Get(), |
379 MessageLoop::current(), | 371 false, &order, true)); |
380 event.Get(), | |
381 false, | |
382 &order, | |
383 true)); | |
384 // Let the other thread execute. | 372 // Let the other thread execute. |
385 WaitForSingleObject(event.Get(), INFINITE); | 373 WaitForSingleObject(event.Get(), INFINITE); |
386 MessageLoop::current()->Run(); | 374 RunLoop().Run(); |
387 | 375 |
388 ASSERT_EQ(18u, order.Size()); | 376 ASSERT_EQ(18u, order.Size()); |
389 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); | 377 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); |
390 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); | 378 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); |
391 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); | 379 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); |
392 // Note that this executes in the MessageBox modal loop. | 380 // Note that this executes in the MessageBox modal loop. |
393 EXPECT_EQ(order.Get(3), TaskItem(RECURSIVE, 3, true)); | 381 EXPECT_EQ(order.Get(3), TaskItem(RECURSIVE, 3, true)); |
394 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, false)); | 382 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, false)); |
395 EXPECT_EQ(order.Get(5), TaskItem(ENDDIALOG, 4, true)); | 383 EXPECT_EQ(order.Get(5), TaskItem(ENDDIALOG, 4, true)); |
396 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, false)); | 384 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, false)); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 const wchar_t* kPipeName = L"\\\\.\\pipe\\iohandler_pipe"; | 471 const wchar_t* kPipeName = L"\\\\.\\pipe\\iohandler_pipe"; |
484 win::ScopedHandle server( | 472 win::ScopedHandle server( |
485 CreateNamedPipe(kPipeName, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL)); | 473 CreateNamedPipe(kPipeName, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL)); |
486 ASSERT_TRUE(server.IsValid()); | 474 ASSERT_TRUE(server.IsValid()); |
487 | 475 |
488 Thread thread("IOHandler test"); | 476 Thread thread("IOHandler test"); |
489 Thread::Options options; | 477 Thread::Options options; |
490 options.message_loop_type = MessageLoop::TYPE_IO; | 478 options.message_loop_type = MessageLoop::TYPE_IO; |
491 ASSERT_TRUE(thread.StartWithOptions(options)); | 479 ASSERT_TRUE(thread.StartWithOptions(options)); |
492 | 480 |
493 MessageLoop* thread_loop = thread.message_loop(); | 481 MessageLoop* thread_loop = thread.message_loop(); |
gab
2016/08/05 01:09:57
unused var
fdoray
2016/08/05 16:10:35
Done.
| |
494 ASSERT_TRUE(NULL != thread_loop); | 482 ASSERT_TRUE(NULL != thread_loop); |
495 | 483 |
496 TestIOHandler handler(kPipeName, callback_called.Get(), false); | 484 TestIOHandler handler(kPipeName, callback_called.Get(), false); |
497 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, | 485 thread_loop->task_runner()->PostTask( |
498 Unretained(&handler))); | 486 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler))); |
499 // Make sure the thread runs and sleeps for lack of work. | 487 // Make sure the thread runs and sleeps for lack of work. |
500 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); | 488 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); |
501 | 489 |
502 const char buffer[] = "Hello there!"; | 490 const char buffer[] = "Hello there!"; |
503 DWORD written; | 491 DWORD written; |
504 EXPECT_TRUE(WriteFile(server.Get(), buffer, sizeof(buffer), &written, NULL)); | 492 EXPECT_TRUE(WriteFile(server.Get(), buffer, sizeof(buffer), &written, NULL)); |
505 | 493 |
506 DWORD result = WaitForSingleObject(callback_called.Get(), 1000); | 494 DWORD result = WaitForSingleObject(callback_called.Get(), 1000); |
507 EXPECT_EQ(WAIT_OBJECT_0, result); | 495 EXPECT_EQ(WAIT_OBJECT_0, result); |
508 | 496 |
(...skipping 15 matching lines...) Expand all Loading... | |
524 win::ScopedHandle server2( | 512 win::ScopedHandle server2( |
525 CreateNamedPipe(kPipeName2, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL)); | 513 CreateNamedPipe(kPipeName2, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL)); |
526 ASSERT_TRUE(server1.IsValid()); | 514 ASSERT_TRUE(server1.IsValid()); |
527 ASSERT_TRUE(server2.IsValid()); | 515 ASSERT_TRUE(server2.IsValid()); |
528 | 516 |
529 Thread thread("IOHandler test"); | 517 Thread thread("IOHandler test"); |
530 Thread::Options options; | 518 Thread::Options options; |
531 options.message_loop_type = MessageLoop::TYPE_IO; | 519 options.message_loop_type = MessageLoop::TYPE_IO; |
532 ASSERT_TRUE(thread.StartWithOptions(options)); | 520 ASSERT_TRUE(thread.StartWithOptions(options)); |
533 | 521 |
534 MessageLoop* thread_loop = thread.message_loop(); | 522 MessageLoop* thread_loop = thread.message_loop(); |
gab
2016/08/05 01:09:57
unused var
fdoray
2016/08/05 16:10:35
Done.
| |
535 ASSERT_TRUE(NULL != thread_loop); | 523 ASSERT_TRUE(NULL != thread_loop); |
536 | 524 |
537 TestIOHandler handler1(kPipeName1, callback1_called.Get(), false); | 525 TestIOHandler handler1(kPipeName1, callback1_called.Get(), false); |
538 TestIOHandler handler2(kPipeName2, callback2_called.Get(), true); | 526 TestIOHandler handler2(kPipeName2, callback2_called.Get(), true); |
539 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, | 527 thread_loop->task_runner()->PostTask( |
540 Unretained(&handler1))); | 528 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler1))); |
541 // TODO(ajwong): Do we really need such long Sleeps in this function? | 529 // TODO(ajwong): Do we really need such long Sleeps in this function? |
542 // Make sure the thread runs and sleeps for lack of work. | 530 // Make sure the thread runs and sleeps for lack of work. |
543 TimeDelta delay = TimeDelta::FromMilliseconds(100); | 531 TimeDelta delay = TimeDelta::FromMilliseconds(100); |
544 PlatformThread::Sleep(delay); | 532 PlatformThread::Sleep(delay); |
545 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, | 533 thread_loop->task_runner()->PostTask( |
546 Unretained(&handler2))); | 534 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler2))); |
547 PlatformThread::Sleep(delay); | 535 PlatformThread::Sleep(delay); |
548 | 536 |
549 // At this time handler1 is waiting to be called, and the thread is waiting | 537 // At this time handler1 is waiting to be called, and the thread is waiting |
550 // on the Init method of handler2, filtering only handler2 callbacks. | 538 // on the Init method of handler2, filtering only handler2 callbacks. |
551 | 539 |
552 const char buffer[] = "Hello there!"; | 540 const char buffer[] = "Hello there!"; |
553 DWORD written; | 541 DWORD written; |
554 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL)); | 542 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL)); |
555 PlatformThread::Sleep(2 * delay); | 543 PlatformThread::Sleep(2 * delay); |
556 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), | 544 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
649 #if defined(OS_WIN) | 637 #if defined(OS_WIN) |
650 TEST(MessageLoopTest, IOHandler) { | 638 TEST(MessageLoopTest, IOHandler) { |
651 RunTest_IOHandler(); | 639 RunTest_IOHandler(); |
652 } | 640 } |
653 | 641 |
654 TEST(MessageLoopTest, WaitForIO) { | 642 TEST(MessageLoopTest, WaitForIO) { |
655 RunTest_WaitForIO(); | 643 RunTest_WaitForIO(); |
656 } | 644 } |
657 | 645 |
658 TEST(MessageLoopTest, HighResolutionTimer) { | 646 TEST(MessageLoopTest, HighResolutionTimer) { |
659 MessageLoop loop; | 647 MessageLoop message_loop; |
660 Time::EnableHighResolutionTimer(true); | 648 Time::EnableHighResolutionTimer(true); |
661 | 649 |
662 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5); | 650 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5); |
663 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100); | 651 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100); |
664 | 652 |
665 EXPECT_FALSE(loop.HasHighResolutionTasks()); | 653 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); |
666 // Post a fast task to enable the high resolution timers. | 654 // Post a fast task to enable the high resolution timers. |
667 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), | 655 message_loop.task_runner()->PostDelayedTask( |
668 kFastTimer); | 656 FROM_HERE, Bind(&PostNTasksThenQuit, 1), kFastTimer); |
669 EXPECT_TRUE(loop.HasHighResolutionTasks()); | 657 EXPECT_TRUE(message_loop.HasHighResolutionTasks()); |
670 loop.Run(); | 658 RunLoop().Run(); |
671 EXPECT_FALSE(loop.HasHighResolutionTasks()); | 659 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); |
672 EXPECT_FALSE(Time::IsHighResolutionTimerInUse()); | 660 EXPECT_FALSE(Time::IsHighResolutionTimerInUse()); |
673 // Check that a slow task does not trigger the high resolution logic. | 661 // Check that a slow task does not trigger the high resolution logic. |
674 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), | 662 message_loop.task_runner()->PostDelayedTask( |
675 kSlowTimer); | 663 FROM_HERE, Bind(&PostNTasksThenQuit, 1), kSlowTimer); |
676 EXPECT_FALSE(loop.HasHighResolutionTasks()); | 664 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); |
677 loop.Run(); | 665 RunLoop().Run(); |
678 EXPECT_FALSE(loop.HasHighResolutionTasks()); | 666 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); |
679 Time::EnableHighResolutionTimer(false); | 667 Time::EnableHighResolutionTimer(false); |
680 } | 668 } |
681 | 669 |
682 #endif // defined(OS_WIN) | 670 #endif // defined(OS_WIN) |
683 | 671 |
684 #if defined(OS_POSIX) && !defined(OS_NACL) | 672 #if defined(OS_POSIX) && !defined(OS_NACL) |
685 | 673 |
686 namespace { | 674 namespace { |
687 | 675 |
688 class QuitDelegate : public MessageLoopForIO::Watcher { | 676 class QuitDelegate : public MessageLoopForIO::Watcher { |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 wc.lpszClassName = L"MessageLoopTest_HWND"; | 922 wc.lpszClassName = L"MessageLoopTest_HWND"; |
935 ATOM atom = RegisterClassEx(&wc); | 923 ATOM atom = RegisterClassEx(&wc); |
936 ASSERT_TRUE(atom); | 924 ASSERT_TRUE(atom); |
937 | 925 |
938 HWND message_hwnd = CreateWindow(MAKEINTATOM(atom), 0, 0, 0, 0, 0, 0, | 926 HWND message_hwnd = CreateWindow(MAKEINTATOM(atom), 0, 0, 0, 0, 0, 0, |
939 HWND_MESSAGE, 0, instance, 0); | 927 HWND_MESSAGE, 0, instance, 0); |
940 ASSERT_TRUE(message_hwnd) << GetLastError(); | 928 ASSERT_TRUE(message_hwnd) << GetLastError(); |
941 | 929 |
942 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); | 930 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); |
943 | 931 |
944 loop.Run(); | 932 RunLoop().Run(); |
945 | 933 |
946 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); | 934 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); |
947 } | 935 } |
948 #endif // defined(OS_WIN) | 936 #endif // defined(OS_WIN) |
949 | 937 |
950 TEST(MessageLoopTest, SetTaskRunner) { | 938 TEST(MessageLoopTest, SetTaskRunner) { |
951 MessageLoop loop; | 939 MessageLoop loop; |
952 scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner()); | 940 scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner()); |
953 | 941 |
954 loop.SetTaskRunner(new_runner); | 942 loop.SetTaskRunner(new_runner); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
990 | 978 |
991 { | 979 { |
992 std::string kThreadName("bar"); | 980 std::string kThreadName("bar"); |
993 base::Thread thread(kThreadName); | 981 base::Thread thread(kThreadName); |
994 ASSERT_TRUE(thread.StartAndWaitForTesting()); | 982 ASSERT_TRUE(thread.StartAndWaitForTesting()); |
995 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); | 983 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); |
996 } | 984 } |
997 } | 985 } |
998 | 986 |
999 } // namespace base | 987 } // namespace base |
OLD | NEW |