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" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 android::JavaHandlerThreadForTesting::CreateJavaFirst(&test_done_event); | 104 android::JavaHandlerThreadForTesting::CreateJavaFirst(&test_done_event); |
105 } else { | 105 } else { |
106 java_thread = android::JavaHandlerThreadForTesting::Create( | 106 java_thread = android::JavaHandlerThreadForTesting::Create( |
107 "JavaHandlerThreadForTesting from AbortDontRunMoreTasks", | 107 "JavaHandlerThreadForTesting from AbortDontRunMoreTasks", |
108 &test_done_event); | 108 &test_done_event); |
109 } | 109 } |
110 java_thread->Start(); | 110 java_thread->Start(); |
111 | 111 |
112 if (delayed) { | 112 if (delayed) { |
113 java_thread->message_loop()->task_runner()->PostDelayedTask( | 113 java_thread->message_loop()->task_runner()->PostDelayedTask( |
114 FROM_HERE, Bind(&AbortMessagePump), TimeDelta::FromMilliseconds(10)); | 114 FROM_HERE, BindOnce(&AbortMessagePump), |
| 115 TimeDelta::FromMilliseconds(10)); |
115 } else { | 116 } else { |
116 java_thread->message_loop()->task_runner()->PostTask( | 117 java_thread->message_loop()->task_runner()->PostTask( |
117 FROM_HERE, Bind(&AbortMessagePump)); | 118 FROM_HERE, BindOnce(&AbortMessagePump)); |
118 } | 119 } |
119 | 120 |
120 // Wait to ensure we catch the correct exception (and don't crash) | 121 // Wait to ensure we catch the correct exception (and don't crash) |
121 test_done_event.Wait(); | 122 test_done_event.Wait(); |
122 | 123 |
123 java_thread->Stop(); | 124 java_thread->Stop(); |
124 java_thread.reset(); | 125 java_thread.reset(); |
125 } | 126 } |
126 | 127 |
127 TEST(MessageLoopTest, JavaExceptionAbort) { | 128 TEST(MessageLoopTest, JavaExceptionAbort) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 MessageLoop message_loop(MessageLoop::TYPE_UI); | 176 MessageLoop message_loop(MessageLoop::TYPE_UI); |
176 | 177 |
177 // Test that the interval of the timer, used to run the next delayed task, is | 178 // Test that the interval of the timer, used to run the next delayed task, is |
178 // set to a value corresponding to when the next delayed task should run. | 179 // set to a value corresponding to when the next delayed task should run. |
179 | 180 |
180 // By setting num_tasks to 1, we ensure that the first task to run causes the | 181 // By setting num_tasks to 1, we ensure that the first task to run causes the |
181 // run loop to exit. | 182 // run loop to exit. |
182 int num_tasks = 1; | 183 int num_tasks = 1; |
183 Time run_time; | 184 Time run_time; |
184 | 185 |
185 message_loop.task_runner()->PostTask(FROM_HERE, Bind(&SubPumpFunc)); | 186 message_loop.task_runner()->PostTask(FROM_HERE, BindOnce(&SubPumpFunc)); |
186 | 187 |
187 // This very delayed task should never run. | 188 // This very delayed task should never run. |
188 message_loop.task_runner()->PostDelayedTask( | 189 message_loop.task_runner()->PostDelayedTask( |
189 FROM_HERE, Bind(&RecordRunTimeFunc, &run_time, &num_tasks), | 190 FROM_HERE, BindOnce(&RecordRunTimeFunc, &run_time, &num_tasks), |
190 TimeDelta::FromSeconds(1000)); | 191 TimeDelta::FromSeconds(1000)); |
191 | 192 |
192 // This slightly delayed task should run from within SubPumpFunc. | 193 // This slightly delayed task should run from within SubPumpFunc. |
193 message_loop.task_runner()->PostDelayedTask( | 194 message_loop.task_runner()->PostDelayedTask(FROM_HERE, |
194 FROM_HERE, Bind(&PostQuitMessage, 0), TimeDelta::FromMilliseconds(10)); | 195 BindOnce(&PostQuitMessage, 0), |
| 196 TimeDelta::FromMilliseconds(10)); |
195 | 197 |
196 Time start_time = Time::Now(); | 198 Time start_time = Time::Now(); |
197 | 199 |
198 RunLoop().Run(); | 200 RunLoop().Run(); |
199 EXPECT_EQ(1, num_tasks); | 201 EXPECT_EQ(1, num_tasks); |
200 | 202 |
201 // Ensure that we ran in far less time than the slower timer. | 203 // Ensure that we ran in far less time than the slower timer. |
202 TimeDelta total_time = Time::Now() - start_time; | 204 TimeDelta total_time = Time::Now() - start_time; |
203 EXPECT_GT(5000, total_time.InMilliseconds()); | 205 EXPECT_GT(5000, total_time.InMilliseconds()); |
204 | 206 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 319 } |
318 | 320 |
319 void RecursiveFunc(TaskList* order, int cookie, int depth, | 321 void RecursiveFunc(TaskList* order, int cookie, int depth, |
320 bool is_reentrant) { | 322 bool is_reentrant) { |
321 order->RecordStart(RECURSIVE, cookie); | 323 order->RecordStart(RECURSIVE, cookie); |
322 if (depth > 0) { | 324 if (depth > 0) { |
323 if (is_reentrant) | 325 if (is_reentrant) |
324 MessageLoop::current()->SetNestableTasksAllowed(true); | 326 MessageLoop::current()->SetNestableTasksAllowed(true); |
325 ThreadTaskRunnerHandle::Get()->PostTask( | 327 ThreadTaskRunnerHandle::Get()->PostTask( |
326 FROM_HERE, | 328 FROM_HERE, |
327 Bind(&RecursiveFunc, order, cookie, depth - 1, is_reentrant)); | 329 BindOnce(&RecursiveFunc, order, cookie, depth - 1, is_reentrant)); |
328 } | 330 } |
329 order->RecordEnd(RECURSIVE, cookie); | 331 order->RecordEnd(RECURSIVE, cookie); |
330 } | 332 } |
331 | 333 |
332 void QuitFunc(TaskList* order, int cookie) { | 334 void QuitFunc(TaskList* order, int cookie) { |
333 order->RecordStart(QUITMESSAGELOOP, cookie); | 335 order->RecordStart(QUITMESSAGELOOP, cookie); |
334 MessageLoop::current()->QuitWhenIdle(); | 336 MessageLoop::current()->QuitWhenIdle(); |
335 order->RecordEnd(QUITMESSAGELOOP, cookie); | 337 order->RecordEnd(QUITMESSAGELOOP, cookie); |
336 } | 338 } |
337 | 339 |
338 void RecursiveFuncWin(scoped_refptr<SingleThreadTaskRunner> task_runner, | 340 void RecursiveFuncWin(scoped_refptr<SingleThreadTaskRunner> task_runner, |
339 HANDLE event, | 341 HANDLE event, |
340 bool expect_window, | 342 bool expect_window, |
341 TaskList* order, | 343 TaskList* order, |
342 bool is_reentrant) { | 344 bool is_reentrant) { |
343 task_runner->PostTask(FROM_HERE, | 345 task_runner->PostTask(FROM_HERE, |
344 Bind(&RecursiveFunc, order, 1, 2, is_reentrant)); | 346 BindOnce(&RecursiveFunc, order, 1, 2, is_reentrant)); |
345 task_runner->PostTask(FROM_HERE, | 347 task_runner->PostTask(FROM_HERE, |
346 Bind(&MessageBoxFunc, order, 2, is_reentrant)); | 348 BindOnce(&MessageBoxFunc, order, 2, is_reentrant)); |
347 task_runner->PostTask(FROM_HERE, | 349 task_runner->PostTask(FROM_HERE, |
348 Bind(&RecursiveFunc, order, 3, 2, is_reentrant)); | 350 BindOnce(&RecursiveFunc, order, 3, 2, is_reentrant)); |
349 // The trick here is that for recursive task processing, this task will be | 351 // The trick here is that for recursive task processing, this task will be |
350 // ran _inside_ the MessageBox message loop, dismissing the MessageBox | 352 // ran _inside_ the MessageBox message loop, dismissing the MessageBox |
351 // without a chance. | 353 // without a chance. |
352 // For non-recursive task processing, this will be executed _after_ the | 354 // For non-recursive task processing, this will be executed _after_ the |
353 // MessageBox will have been dismissed by the code below, where | 355 // MessageBox will have been dismissed by the code below, where |
354 // expect_window_ is true. | 356 // expect_window_ is true. |
355 task_runner->PostTask(FROM_HERE, Bind(&EndDialogFunc, order, 4)); | 357 task_runner->PostTask(FROM_HERE, BindOnce(&EndDialogFunc, order, 4)); |
356 task_runner->PostTask(FROM_HERE, Bind(&QuitFunc, order, 5)); | 358 task_runner->PostTask(FROM_HERE, BindOnce(&QuitFunc, order, 5)); |
357 | 359 |
358 // Enforce that every tasks are sent before starting to run the main thread | 360 // Enforce that every tasks are sent before starting to run the main thread |
359 // message loop. | 361 // message loop. |
360 ASSERT_TRUE(SetEvent(event)); | 362 ASSERT_TRUE(SetEvent(event)); |
361 | 363 |
362 // Poll for the MessageBox. Don't do this at home! At the speed we do it, | 364 // Poll for the MessageBox. Don't do this at home! At the speed we do it, |
363 // you will never realize one MessageBox was shown. | 365 // you will never realize one MessageBox was shown. |
364 for (; expect_window;) { | 366 for (; expect_window;) { |
365 HWND window = FindWindow(L"#32770", kMessageBoxTitle); | 367 HWND window = FindWindow(L"#32770", kMessageBoxTitle); |
366 if (window) { | 368 if (window) { |
(...skipping 18 matching lines...) Expand all Loading... |
385 void RunTest_RecursiveDenial2(MessageLoop::Type message_loop_type) { | 387 void RunTest_RecursiveDenial2(MessageLoop::Type message_loop_type) { |
386 MessageLoop loop(message_loop_type); | 388 MessageLoop loop(message_loop_type); |
387 | 389 |
388 Thread worker("RecursiveDenial2_worker"); | 390 Thread worker("RecursiveDenial2_worker"); |
389 Thread::Options options; | 391 Thread::Options options; |
390 options.message_loop_type = message_loop_type; | 392 options.message_loop_type = message_loop_type; |
391 ASSERT_EQ(true, worker.StartWithOptions(options)); | 393 ASSERT_EQ(true, worker.StartWithOptions(options)); |
392 TaskList order; | 394 TaskList order; |
393 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); | 395 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); |
394 worker.task_runner()->PostTask( | 396 worker.task_runner()->PostTask( |
395 FROM_HERE, Bind(&RecursiveFuncWin, ThreadTaskRunnerHandle::Get(), | 397 FROM_HERE, BindOnce(&RecursiveFuncWin, ThreadTaskRunnerHandle::Get(), |
396 event.Get(), true, &order, false)); | 398 event.Get(), true, &order, false)); |
397 // Let the other thread execute. | 399 // Let the other thread execute. |
398 WaitForSingleObject(event.Get(), INFINITE); | 400 WaitForSingleObject(event.Get(), INFINITE); |
399 RunLoop().Run(); | 401 RunLoop().Run(); |
400 | 402 |
401 ASSERT_EQ(17u, order.Size()); | 403 ASSERT_EQ(17u, order.Size()); |
402 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); | 404 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); |
403 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); | 405 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); |
404 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); | 406 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); |
405 EXPECT_EQ(order.Get(3), TaskItem(MESSAGEBOX, 2, false)); | 407 EXPECT_EQ(order.Get(3), TaskItem(MESSAGEBOX, 2, false)); |
406 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, true)); | 408 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, true)); |
(...skipping 18 matching lines...) Expand all Loading... |
425 void RunTest_RecursiveSupport2(MessageLoop::Type message_loop_type) { | 427 void RunTest_RecursiveSupport2(MessageLoop::Type message_loop_type) { |
426 MessageLoop loop(message_loop_type); | 428 MessageLoop loop(message_loop_type); |
427 | 429 |
428 Thread worker("RecursiveSupport2_worker"); | 430 Thread worker("RecursiveSupport2_worker"); |
429 Thread::Options options; | 431 Thread::Options options; |
430 options.message_loop_type = message_loop_type; | 432 options.message_loop_type = message_loop_type; |
431 ASSERT_EQ(true, worker.StartWithOptions(options)); | 433 ASSERT_EQ(true, worker.StartWithOptions(options)); |
432 TaskList order; | 434 TaskList order; |
433 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); | 435 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); |
434 worker.task_runner()->PostTask( | 436 worker.task_runner()->PostTask( |
435 FROM_HERE, Bind(&RecursiveFuncWin, ThreadTaskRunnerHandle::Get(), | 437 FROM_HERE, BindOnce(&RecursiveFuncWin, ThreadTaskRunnerHandle::Get(), |
436 event.Get(), false, &order, true)); | 438 event.Get(), false, &order, true)); |
437 // Let the other thread execute. | 439 // Let the other thread execute. |
438 WaitForSingleObject(event.Get(), INFINITE); | 440 WaitForSingleObject(event.Get(), INFINITE); |
439 RunLoop().Run(); | 441 RunLoop().Run(); |
440 | 442 |
441 ASSERT_EQ(18u, order.Size()); | 443 ASSERT_EQ(18u, order.Size()); |
442 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); | 444 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); |
443 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); | 445 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); |
444 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); | 446 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); |
445 // Note that this executes in the MessageBox modal loop. | 447 // Note that this executes in the MessageBox modal loop. |
446 EXPECT_EQ(order.Get(3), TaskItem(RECURSIVE, 3, true)); | 448 EXPECT_EQ(order.Get(3), TaskItem(RECURSIVE, 3, true)); |
447 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, false)); | 449 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, false)); |
448 EXPECT_EQ(order.Get(5), TaskItem(ENDDIALOG, 4, true)); | 450 EXPECT_EQ(order.Get(5), TaskItem(ENDDIALOG, 4, true)); |
449 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, false)); | 451 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, false)); |
450 EXPECT_EQ(order.Get(7), TaskItem(MESSAGEBOX, 2, false)); | 452 EXPECT_EQ(order.Get(7), TaskItem(MESSAGEBOX, 2, false)); |
451 /* The order can subtly change here. The reason is that when RecursiveFunc(1) | 453 /* The order can subtly change here. The reason is that when RecursiveFunc(1) |
452 is called in the main thread, if it is faster than getting to the | 454 is called in the main thread, if it is faster than getting to the |
453 PostTask(FROM_HERE, Bind(&QuitFunc) execution, the order of task | 455 PostTask(FROM_HERE, BindOnce(&QuitFunc) execution, the order of task |
454 execution can change. We don't care anyway that the order isn't correct. | 456 execution can change. We don't care anyway that the order isn't correct. |
455 EXPECT_EQ(order.Get(8), TaskItem(QUITMESSAGELOOP, 5, true)); | 457 EXPECT_EQ(order.Get(8), TaskItem(QUITMESSAGELOOP, 5, true)); |
456 EXPECT_EQ(order.Get(9), TaskItem(QUITMESSAGELOOP, 5, false)); | 458 EXPECT_EQ(order.Get(9), TaskItem(QUITMESSAGELOOP, 5, false)); |
457 EXPECT_EQ(order.Get(10), TaskItem(RECURSIVE, 1, true)); | 459 EXPECT_EQ(order.Get(10), TaskItem(RECURSIVE, 1, true)); |
458 EXPECT_EQ(order.Get(11), TaskItem(RECURSIVE, 1, false)); | 460 EXPECT_EQ(order.Get(11), TaskItem(RECURSIVE, 1, false)); |
459 */ | 461 */ |
460 EXPECT_EQ(order.Get(12), TaskItem(RECURSIVE, 3, true)); | 462 EXPECT_EQ(order.Get(12), TaskItem(RECURSIVE, 3, true)); |
461 EXPECT_EQ(order.Get(13), TaskItem(RECURSIVE, 3, false)); | 463 EXPECT_EQ(order.Get(13), TaskItem(RECURSIVE, 3, false)); |
462 EXPECT_EQ(order.Get(14), TaskItem(RECURSIVE, 1, true)); | 464 EXPECT_EQ(order.Get(14), TaskItem(RECURSIVE, 1, true)); |
463 EXPECT_EQ(order.Get(15), TaskItem(RECURSIVE, 1, false)); | 465 EXPECT_EQ(order.Get(15), TaskItem(RECURSIVE, 1, false)); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 CreateNamedPipe(kPipeName, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL)); | 540 CreateNamedPipe(kPipeName, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL)); |
539 ASSERT_TRUE(server.IsValid()); | 541 ASSERT_TRUE(server.IsValid()); |
540 | 542 |
541 Thread thread("IOHandler test"); | 543 Thread thread("IOHandler test"); |
542 Thread::Options options; | 544 Thread::Options options; |
543 options.message_loop_type = MessageLoop::TYPE_IO; | 545 options.message_loop_type = MessageLoop::TYPE_IO; |
544 ASSERT_TRUE(thread.StartWithOptions(options)); | 546 ASSERT_TRUE(thread.StartWithOptions(options)); |
545 | 547 |
546 TestIOHandler handler(kPipeName, callback_called.Get(), false); | 548 TestIOHandler handler(kPipeName, callback_called.Get(), false); |
547 thread.task_runner()->PostTask( | 549 thread.task_runner()->PostTask( |
548 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler))); | 550 FROM_HERE, BindOnce(&TestIOHandler::Init, Unretained(&handler))); |
549 // Make sure the thread runs and sleeps for lack of work. | 551 // Make sure the thread runs and sleeps for lack of work. |
550 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); | 552 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); |
551 | 553 |
552 const char buffer[] = "Hello there!"; | 554 const char buffer[] = "Hello there!"; |
553 DWORD written; | 555 DWORD written; |
554 EXPECT_TRUE(WriteFile(server.Get(), buffer, sizeof(buffer), &written, NULL)); | 556 EXPECT_TRUE(WriteFile(server.Get(), buffer, sizeof(buffer), &written, NULL)); |
555 | 557 |
556 DWORD result = WaitForSingleObject(callback_called.Get(), 1000); | 558 DWORD result = WaitForSingleObject(callback_called.Get(), 1000); |
557 EXPECT_EQ(WAIT_OBJECT_0, result); | 559 EXPECT_EQ(WAIT_OBJECT_0, result); |
558 | 560 |
(...skipping 18 matching lines...) Expand all Loading... |
577 ASSERT_TRUE(server2.IsValid()); | 579 ASSERT_TRUE(server2.IsValid()); |
578 | 580 |
579 Thread thread("IOHandler test"); | 581 Thread thread("IOHandler test"); |
580 Thread::Options options; | 582 Thread::Options options; |
581 options.message_loop_type = MessageLoop::TYPE_IO; | 583 options.message_loop_type = MessageLoop::TYPE_IO; |
582 ASSERT_TRUE(thread.StartWithOptions(options)); | 584 ASSERT_TRUE(thread.StartWithOptions(options)); |
583 | 585 |
584 TestIOHandler handler1(kPipeName1, callback1_called.Get(), false); | 586 TestIOHandler handler1(kPipeName1, callback1_called.Get(), false); |
585 TestIOHandler handler2(kPipeName2, callback2_called.Get(), true); | 587 TestIOHandler handler2(kPipeName2, callback2_called.Get(), true); |
586 thread.task_runner()->PostTask( | 588 thread.task_runner()->PostTask( |
587 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler1))); | 589 FROM_HERE, BindOnce(&TestIOHandler::Init, Unretained(&handler1))); |
588 // TODO(ajwong): Do we really need such long Sleeps in this function? | 590 // TODO(ajwong): Do we really need such long Sleeps in this function? |
589 // Make sure the thread runs and sleeps for lack of work. | 591 // Make sure the thread runs and sleeps for lack of work. |
590 TimeDelta delay = TimeDelta::FromMilliseconds(100); | 592 TimeDelta delay = TimeDelta::FromMilliseconds(100); |
591 PlatformThread::Sleep(delay); | 593 PlatformThread::Sleep(delay); |
592 thread.task_runner()->PostTask( | 594 thread.task_runner()->PostTask( |
593 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler2))); | 595 FROM_HERE, BindOnce(&TestIOHandler::Init, Unretained(&handler2))); |
594 PlatformThread::Sleep(delay); | 596 PlatformThread::Sleep(delay); |
595 | 597 |
596 // At this time handler1 is waiting to be called, and the thread is waiting | 598 // At this time handler1 is waiting to be called, and the thread is waiting |
597 // on the Init method of handler2, filtering only handler2 callbacks. | 599 // on the Init method of handler2, filtering only handler2 callbacks. |
598 | 600 |
599 const char buffer[] = "Hello there!"; | 601 const char buffer[] = "Hello there!"; |
600 DWORD written; | 602 DWORD written; |
601 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL)); | 603 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL)); |
602 PlatformThread::Sleep(2 * delay); | 604 PlatformThread::Sleep(2 * delay); |
603 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), | 605 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 TEST(MessageLoopTest, HighResolutionTimer) { | 705 TEST(MessageLoopTest, HighResolutionTimer) { |
704 MessageLoop message_loop; | 706 MessageLoop message_loop; |
705 Time::EnableHighResolutionTimer(true); | 707 Time::EnableHighResolutionTimer(true); |
706 | 708 |
707 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5); | 709 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5); |
708 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100); | 710 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100); |
709 | 711 |
710 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); | 712 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); |
711 // Post a fast task to enable the high resolution timers. | 713 // Post a fast task to enable the high resolution timers. |
712 message_loop.task_runner()->PostDelayedTask( | 714 message_loop.task_runner()->PostDelayedTask( |
713 FROM_HERE, Bind(&PostNTasksThenQuit, 1), kFastTimer); | 715 FROM_HERE, BindOnce(&PostNTasksThenQuit, 1), kFastTimer); |
714 EXPECT_TRUE(message_loop.HasHighResolutionTasks()); | 716 EXPECT_TRUE(message_loop.HasHighResolutionTasks()); |
715 RunLoop().Run(); | 717 RunLoop().Run(); |
716 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); | 718 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); |
717 EXPECT_FALSE(Time::IsHighResolutionTimerInUse()); | 719 EXPECT_FALSE(Time::IsHighResolutionTimerInUse()); |
718 // Check that a slow task does not trigger the high resolution logic. | 720 // Check that a slow task does not trigger the high resolution logic. |
719 message_loop.task_runner()->PostDelayedTask( | 721 message_loop.task_runner()->PostDelayedTask( |
720 FROM_HERE, Bind(&PostNTasksThenQuit, 1), kSlowTimer); | 722 FROM_HERE, BindOnce(&PostNTasksThenQuit, 1), kSlowTimer); |
721 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); | 723 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); |
722 RunLoop().Run(); | 724 RunLoop().Run(); |
723 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); | 725 EXPECT_FALSE(message_loop.HasHighResolutionTasks()); |
724 Time::EnableHighResolutionTimer(false); | 726 Time::EnableHighResolutionTimer(false); |
725 } | 727 } |
726 | 728 |
727 #endif // defined(OS_WIN) | 729 #endif // defined(OS_WIN) |
728 | 730 |
729 #if defined(OS_POSIX) && !defined(OS_NACL) | 731 #if defined(OS_POSIX) && !defined(OS_NACL) |
730 | 732 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 EXPECT_TRUE(loop.IsType(MessageLoop::TYPE_UI)); | 902 EXPECT_TRUE(loop.IsType(MessageLoop::TYPE_UI)); |
901 EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_IO)); | 903 EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_IO)); |
902 EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_DEFAULT)); | 904 EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_DEFAULT)); |
903 } | 905 } |
904 | 906 |
905 #if defined(OS_WIN) | 907 #if defined(OS_WIN) |
906 void EmptyFunction() {} | 908 void EmptyFunction() {} |
907 | 909 |
908 void PostMultipleTasks() { | 910 void PostMultipleTasks() { |
909 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 911 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
910 base::Bind(&EmptyFunction)); | 912 base::BindOnce(&EmptyFunction)); |
911 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 913 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
912 base::Bind(&EmptyFunction)); | 914 base::BindOnce(&EmptyFunction)); |
913 } | 915 } |
914 | 916 |
915 static const int kSignalMsg = WM_USER + 2; | 917 static const int kSignalMsg = WM_USER + 2; |
916 | 918 |
917 void PostWindowsMessage(HWND message_hwnd) { | 919 void PostWindowsMessage(HWND message_hwnd) { |
918 PostMessage(message_hwnd, kSignalMsg, 0, 2); | 920 PostMessage(message_hwnd, kSignalMsg, 0, 2); |
919 } | 921 } |
920 | 922 |
921 void EndTest(bool* did_run, HWND hwnd) { | 923 void EndTest(bool* did_run, HWND hwnd) { |
922 *did_run = true; | 924 *did_run = true; |
923 PostMessage(hwnd, WM_CLOSE, 0, 0); | 925 PostMessage(hwnd, WM_CLOSE, 0, 0); |
924 } | 926 } |
925 | 927 |
926 int kMyMessageFilterCode = 0x5002; | 928 int kMyMessageFilterCode = 0x5002; |
927 | 929 |
928 LRESULT CALLBACK TestWndProcThunk(HWND hwnd, UINT message, | 930 LRESULT CALLBACK TestWndProcThunk(HWND hwnd, UINT message, |
929 WPARAM wparam, LPARAM lparam) { | 931 WPARAM wparam, LPARAM lparam) { |
930 if (message == WM_CLOSE) | 932 if (message == WM_CLOSE) |
931 EXPECT_TRUE(DestroyWindow(hwnd)); | 933 EXPECT_TRUE(DestroyWindow(hwnd)); |
932 if (message != kSignalMsg) | 934 if (message != kSignalMsg) |
933 return DefWindowProc(hwnd, message, wparam, lparam); | 935 return DefWindowProc(hwnd, message, wparam, lparam); |
934 | 936 |
935 switch (lparam) { | 937 switch (lparam) { |
936 case 1: | 938 case 1: |
937 // First, we post a task that will post multiple no-op tasks to make sure | 939 // First, we post a task that will post multiple no-op tasks to make sure |
938 // that the pump's incoming task queue does not become empty during the | 940 // that the pump's incoming task queue does not become empty during the |
939 // test. | 941 // test. |
940 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 942 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
941 base::Bind(&PostMultipleTasks)); | 943 base::BindOnce(&PostMultipleTasks)); |
942 // Next, we post a task that posts a windows message to trigger the second | 944 // Next, we post a task that posts a windows message to trigger the second |
943 // stage of the test. | 945 // stage of the test. |
944 ThreadTaskRunnerHandle::Get()->PostTask( | 946 ThreadTaskRunnerHandle::Get()->PostTask( |
945 FROM_HERE, base::Bind(&PostWindowsMessage, hwnd)); | 947 FROM_HERE, base::BindOnce(&PostWindowsMessage, hwnd)); |
946 break; | 948 break; |
947 case 2: | 949 case 2: |
948 // Since we're about to enter a modal loop, tell the message loop that we | 950 // Since we're about to enter a modal loop, tell the message loop that we |
949 // intend to nest tasks. | 951 // intend to nest tasks. |
950 MessageLoop::current()->SetNestableTasksAllowed(true); | 952 MessageLoop::current()->SetNestableTasksAllowed(true); |
951 bool did_run = false; | 953 bool did_run = false; |
952 ThreadTaskRunnerHandle::Get()->PostTask( | 954 ThreadTaskRunnerHandle::Get()->PostTask( |
953 FROM_HERE, base::Bind(&EndTest, &did_run, hwnd)); | 955 FROM_HERE, base::BindOnce(&EndTest, &did_run, hwnd)); |
954 // Run a nested windows-style message loop and verify that our task runs. If | 956 // Run a nested windows-style message loop and verify that our task runs. If |
955 // it doesn't, then we'll loop here until the test times out. | 957 // it doesn't, then we'll loop here until the test times out. |
956 MSG msg; | 958 MSG msg; |
957 while (GetMessage(&msg, 0, 0, 0)) { | 959 while (GetMessage(&msg, 0, 0, 0)) { |
958 if (!CallMsgFilter(&msg, kMyMessageFilterCode)) | 960 if (!CallMsgFilter(&msg, kMyMessageFilterCode)) |
959 DispatchMessage(&msg); | 961 DispatchMessage(&msg); |
960 // If this message is a WM_CLOSE, explicitly exit the modal loop. Posting | 962 // If this message is a WM_CLOSE, explicitly exit the modal loop. Posting |
961 // a WM_QUIT should handle this, but unfortunately MessagePumpWin eats | 963 // a WM_QUIT should handle this, but unfortunately MessagePumpWin eats |
962 // WM_QUIT messages even when running inside a modal loop. | 964 // WM_QUIT messages even when running inside a modal loop. |
963 if (msg.message == WM_CLOSE) | 965 if (msg.message == WM_CLOSE) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 | 1037 |
1036 { | 1038 { |
1037 std::string kThreadName("bar"); | 1039 std::string kThreadName("bar"); |
1038 base::Thread thread(kThreadName); | 1040 base::Thread thread(kThreadName); |
1039 ASSERT_TRUE(thread.StartAndWaitForTesting()); | 1041 ASSERT_TRUE(thread.StartAndWaitForTesting()); |
1040 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); | 1042 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); |
1041 } | 1043 } |
1042 } | 1044 } |
1043 | 1045 |
1044 } // namespace base | 1046 } // namespace base |
OLD | NEW |