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

Side by Side Diff: base/message_loop/message_loop_unittest.cc

Issue 2211473003: Remove calls to deprecated MessageLoop methods on Windows and Linux. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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_ANDROID) 30 #if defined(OS_ANDROID)
30 #include "base/android/jni_android.h" 31 #include "base/android/jni_android.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 MessageLoop::current()->SetNestableTasksAllowed(true); 151 MessageLoop::current()->SetNestableTasksAllowed(true);
151 MSG msg; 152 MSG msg;
152 while (GetMessage(&msg, NULL, 0, 0)) { 153 while (GetMessage(&msg, NULL, 0, 0)) {
153 TranslateMessage(&msg); 154 TranslateMessage(&msg);
154 DispatchMessage(&msg); 155 DispatchMessage(&msg);
155 } 156 }
156 MessageLoop::current()->QuitWhenIdle(); 157 MessageLoop::current()->QuitWhenIdle();
157 } 158 }
158 159
159 void RunTest_PostDelayedTask_SharedTimer_SubPump() { 160 void RunTest_PostDelayedTask_SharedTimer_SubPump() {
160 MessageLoop loop(MessageLoop::TYPE_UI); 161 MessageLoop message_loop(MessageLoop::TYPE_UI);
161 162
162 // Test that the interval of the timer, used to run the next delayed task, is 163 // Test that the interval of the timer, used to run the next delayed task, is
163 // set to a value corresponding to when the next delayed task should run. 164 // set to a value corresponding to when the next delayed task should run.
164 165
165 // By setting num_tasks to 1, we ensure that the first task to run causes the 166 // By setting num_tasks to 1, we ensure that the first task to run causes the
166 // run loop to exit. 167 // run loop to exit.
167 int num_tasks = 1; 168 int num_tasks = 1;
168 Time run_time; 169 Time run_time;
169 170
170 loop.PostTask(FROM_HERE, Bind(&SubPumpFunc)); 171 message_loop.task_runner()->PostTask(FROM_HERE, Bind(&SubPumpFunc));
171 172
172 // This very delayed task should never run. 173 // This very delayed task should never run.
173 loop.PostDelayedTask( 174 message_loop.task_runner()->PostDelayedTask(
174 FROM_HERE, 175 FROM_HERE, Bind(&RecordRunTimeFunc, &run_time, &num_tasks),
175 Bind(&RecordRunTimeFunc, &run_time, &num_tasks),
176 TimeDelta::FromSeconds(1000)); 176 TimeDelta::FromSeconds(1000));
177 177
178 // This slightly delayed task should run from within SubPumpFunc. 178 // This slightly delayed task should run from within SubPumpFunc.
179 loop.PostDelayedTask( 179 message_loop.task_runner()->PostDelayedTask(
180 FROM_HERE, 180 FROM_HERE, Bind(&PostQuitMessage, 0), TimeDelta::FromMilliseconds(10));
181 Bind(&PostQuitMessage, 0),
182 TimeDelta::FromMilliseconds(10));
183 181
184 Time start_time = Time::Now(); 182 Time start_time = Time::Now();
185 183
186 loop.Run(); 184 RunLoop().Run();
187 EXPECT_EQ(1, num_tasks); 185 EXPECT_EQ(1, num_tasks);
188 186
189 // Ensure that we ran in far less time than the slower timer. 187 // Ensure that we ran in far less time than the slower timer.
190 TimeDelta total_time = Time::Now() - start_time; 188 TimeDelta total_time = Time::Now() - start_time;
191 EXPECT_GT(5000, total_time.InMilliseconds()); 189 EXPECT_GT(5000, total_time.InMilliseconds());
192 190
193 // In case both timers somehow run at nearly the same time, sleep a little 191 // In case both timers somehow run at nearly the same time, sleep a little
194 // and then run all pending to force them both to have run. This is just 192 // and then run all pending to force them both to have run. This is just
195 // encouraging flakiness if there is any. 193 // encouraging flakiness if there is any.
196 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); 194 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 314 }
317 order->RecordEnd(RECURSIVE, cookie); 315 order->RecordEnd(RECURSIVE, cookie);
318 } 316 }
319 317
320 void QuitFunc(TaskList* order, int cookie) { 318 void QuitFunc(TaskList* order, int cookie) {
321 order->RecordStart(QUITMESSAGELOOP, cookie); 319 order->RecordStart(QUITMESSAGELOOP, cookie);
322 MessageLoop::current()->QuitWhenIdle(); 320 MessageLoop::current()->QuitWhenIdle();
323 order->RecordEnd(QUITMESSAGELOOP, cookie); 321 order->RecordEnd(QUITMESSAGELOOP, cookie);
324 } 322 }
325 323
326 void RecursiveFuncWin(MessageLoop* target, 324 void RecursiveFuncWin(scoped_refptr<SingleThreadTaskRunner> task_runner,
327 HANDLE event, 325 HANDLE event,
328 bool expect_window, 326 bool expect_window,
329 TaskList* order, 327 TaskList* order,
330 bool is_reentrant) { 328 bool is_reentrant) {
331 target->PostTask(FROM_HERE, 329 task_runner->PostTask(FROM_HERE,
332 Bind(&RecursiveFunc, order, 1, 2, is_reentrant)); 330 Bind(&RecursiveFunc, order, 1, 2, is_reentrant));
333 target->PostTask(FROM_HERE, 331 task_runner->PostTask(FROM_HERE,
334 Bind(&MessageBoxFunc, order, 2, is_reentrant)); 332 Bind(&MessageBoxFunc, order, 2, is_reentrant));
335 target->PostTask(FROM_HERE, 333 task_runner->PostTask(FROM_HERE,
336 Bind(&RecursiveFunc, order, 3, 2, is_reentrant)); 334 Bind(&RecursiveFunc, order, 3, 2, is_reentrant));
337 // The trick here is that for recursive task processing, this task will be 335 // The trick here is that for recursive task processing, this task will be
338 // ran _inside_ the MessageBox message loop, dismissing the MessageBox 336 // ran _inside_ the MessageBox message loop, dismissing the MessageBox
339 // without a chance. 337 // without a chance.
340 // For non-recursive task processing, this will be executed _after_ the 338 // For non-recursive task processing, this will be executed _after_ the
341 // MessageBox will have been dismissed by the code below, where 339 // MessageBox will have been dismissed by the code below, where
342 // expect_window_ is true. 340 // expect_window_ is true.
343 target->PostTask(FROM_HERE, 341 task_runner->PostTask(FROM_HERE, Bind(&EndDialogFunc, order, 4));
344 Bind(&EndDialogFunc, order, 4)); 342 task_runner->PostTask(FROM_HERE, Bind(&QuitFunc, order, 5));
345 target->PostTask(FROM_HERE,
346 Bind(&QuitFunc, order, 5));
347 343
348 // Enforce that every tasks are sent before starting to run the main thread 344 // Enforce that every tasks are sent before starting to run the main thread
349 // message loop. 345 // message loop.
350 ASSERT_TRUE(SetEvent(event)); 346 ASSERT_TRUE(SetEvent(event));
351 347
352 // Poll for the MessageBox. Don't do this at home! At the speed we do it, 348 // Poll for the MessageBox. Don't do this at home! At the speed we do it,
353 // you will never realize one MessageBox was shown. 349 // you will never realize one MessageBox was shown.
354 for (; expect_window;) { 350 for (; expect_window;) {
355 HWND window = FindWindow(L"#32770", kMessageBoxTitle); 351 HWND window = FindWindow(L"#32770", kMessageBoxTitle);
356 if (window) { 352 if (window) {
(...skipping 17 matching lines...) Expand all
374 // A side effect of this test is the generation a beep. Sorry. 370 // A side effect of this test is the generation a beep. Sorry.
375 void RunTest_RecursiveDenial2(MessageLoop::Type message_loop_type) { 371 void RunTest_RecursiveDenial2(MessageLoop::Type message_loop_type) {
376 MessageLoop loop(message_loop_type); 372 MessageLoop loop(message_loop_type);
377 373
378 Thread worker("RecursiveDenial2_worker"); 374 Thread worker("RecursiveDenial2_worker");
379 Thread::Options options; 375 Thread::Options options;
380 options.message_loop_type = message_loop_type; 376 options.message_loop_type = message_loop_type;
381 ASSERT_EQ(true, worker.StartWithOptions(options)); 377 ASSERT_EQ(true, worker.StartWithOptions(options));
382 TaskList order; 378 TaskList order;
383 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); 379 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL));
384 worker.message_loop()->PostTask(FROM_HERE, 380 worker.task_runner()->PostTask(
385 Bind(&RecursiveFuncWin, 381 FROM_HERE, Bind(&RecursiveFuncWin, ThreadTaskRunnerHandle::Get(),
386 MessageLoop::current(), 382 event.Get(), true, &order, false));
387 event.Get(),
388 true,
389 &order,
390 false));
391 // Let the other thread execute. 383 // Let the other thread execute.
392 WaitForSingleObject(event.Get(), INFINITE); 384 WaitForSingleObject(event.Get(), INFINITE);
393 MessageLoop::current()->Run(); 385 RunLoop().Run();
394 386
395 ASSERT_EQ(17u, order.Size()); 387 ASSERT_EQ(17u, order.Size());
396 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); 388 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true));
397 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); 389 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false));
398 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); 390 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true));
399 EXPECT_EQ(order.Get(3), TaskItem(MESSAGEBOX, 2, false)); 391 EXPECT_EQ(order.Get(3), TaskItem(MESSAGEBOX, 2, false));
400 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, true)); 392 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, true));
401 EXPECT_EQ(order.Get(5), TaskItem(RECURSIVE, 3, false)); 393 EXPECT_EQ(order.Get(5), TaskItem(RECURSIVE, 3, false));
402 // When EndDialogFunc is processed, the window is already dismissed, hence no 394 // When EndDialogFunc is processed, the window is already dismissed, hence no
403 // "end" entry. 395 // "end" entry.
(...skipping 14 matching lines...) Expand all
418 // needs to process windows messages on the current thread. 410 // needs to process windows messages on the current thread.
419 void RunTest_RecursiveSupport2(MessageLoop::Type message_loop_type) { 411 void RunTest_RecursiveSupport2(MessageLoop::Type message_loop_type) {
420 MessageLoop loop(message_loop_type); 412 MessageLoop loop(message_loop_type);
421 413
422 Thread worker("RecursiveSupport2_worker"); 414 Thread worker("RecursiveSupport2_worker");
423 Thread::Options options; 415 Thread::Options options;
424 options.message_loop_type = message_loop_type; 416 options.message_loop_type = message_loop_type;
425 ASSERT_EQ(true, worker.StartWithOptions(options)); 417 ASSERT_EQ(true, worker.StartWithOptions(options));
426 TaskList order; 418 TaskList order;
427 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL)); 419 win::ScopedHandle event(CreateEvent(NULL, FALSE, FALSE, NULL));
428 worker.message_loop()->PostTask(FROM_HERE, 420 worker.task_runner()->PostTask(
429 Bind(&RecursiveFuncWin, 421 FROM_HERE, Bind(&RecursiveFuncWin, ThreadTaskRunnerHandle::Get(),
430 MessageLoop::current(), 422 event.Get(), false, &order, true));
431 event.Get(),
432 false,
433 &order,
434 true));
435 // Let the other thread execute. 423 // Let the other thread execute.
436 WaitForSingleObject(event.Get(), INFINITE); 424 WaitForSingleObject(event.Get(), INFINITE);
437 MessageLoop::current()->Run(); 425 RunLoop().Run();
438 426
439 ASSERT_EQ(18u, order.Size()); 427 ASSERT_EQ(18u, order.Size());
440 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true)); 428 EXPECT_EQ(order.Get(0), TaskItem(RECURSIVE, 1, true));
441 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false)); 429 EXPECT_EQ(order.Get(1), TaskItem(RECURSIVE, 1, false));
442 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true)); 430 EXPECT_EQ(order.Get(2), TaskItem(MESSAGEBOX, 2, true));
443 // Note that this executes in the MessageBox modal loop. 431 // Note that this executes in the MessageBox modal loop.
444 EXPECT_EQ(order.Get(3), TaskItem(RECURSIVE, 3, true)); 432 EXPECT_EQ(order.Get(3), TaskItem(RECURSIVE, 3, true));
445 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, false)); 433 EXPECT_EQ(order.Get(4), TaskItem(RECURSIVE, 3, false));
446 EXPECT_EQ(order.Get(5), TaskItem(ENDDIALOG, 4, true)); 434 EXPECT_EQ(order.Get(5), TaskItem(ENDDIALOG, 4, true));
447 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, false)); 435 EXPECT_EQ(order.Get(6), TaskItem(ENDDIALOG, 4, false));
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 const wchar_t* kPipeName = L"\\\\.\\pipe\\iohandler_pipe"; 522 const wchar_t* kPipeName = L"\\\\.\\pipe\\iohandler_pipe";
535 win::ScopedHandle server( 523 win::ScopedHandle server(
536 CreateNamedPipe(kPipeName, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL)); 524 CreateNamedPipe(kPipeName, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL));
537 ASSERT_TRUE(server.IsValid()); 525 ASSERT_TRUE(server.IsValid());
538 526
539 Thread thread("IOHandler test"); 527 Thread thread("IOHandler test");
540 Thread::Options options; 528 Thread::Options options;
541 options.message_loop_type = MessageLoop::TYPE_IO; 529 options.message_loop_type = MessageLoop::TYPE_IO;
542 ASSERT_TRUE(thread.StartWithOptions(options)); 530 ASSERT_TRUE(thread.StartWithOptions(options));
543 531
544 MessageLoop* thread_loop = thread.message_loop();
545 ASSERT_TRUE(NULL != thread_loop);
546
547 TestIOHandler handler(kPipeName, callback_called.Get(), false); 532 TestIOHandler handler(kPipeName, callback_called.Get(), false);
548 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, 533 thread.task_runner()->PostTask(
549 Unretained(&handler))); 534 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler)));
550 // Make sure the thread runs and sleeps for lack of work. 535 // Make sure the thread runs and sleeps for lack of work.
551 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100)); 536 PlatformThread::Sleep(TimeDelta::FromMilliseconds(100));
552 537
553 const char buffer[] = "Hello there!"; 538 const char buffer[] = "Hello there!";
554 DWORD written; 539 DWORD written;
555 EXPECT_TRUE(WriteFile(server.Get(), buffer, sizeof(buffer), &written, NULL)); 540 EXPECT_TRUE(WriteFile(server.Get(), buffer, sizeof(buffer), &written, NULL));
556 541
557 DWORD result = WaitForSingleObject(callback_called.Get(), 1000); 542 DWORD result = WaitForSingleObject(callback_called.Get(), 1000);
558 EXPECT_EQ(WAIT_OBJECT_0, result); 543 EXPECT_EQ(WAIT_OBJECT_0, result);
559 544
(...skipping 15 matching lines...) Expand all
575 win::ScopedHandle server2( 560 win::ScopedHandle server2(
576 CreateNamedPipe(kPipeName2, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL)); 561 CreateNamedPipe(kPipeName2, PIPE_ACCESS_OUTBOUND, 0, 1, 0, 0, 0, NULL));
577 ASSERT_TRUE(server1.IsValid()); 562 ASSERT_TRUE(server1.IsValid());
578 ASSERT_TRUE(server2.IsValid()); 563 ASSERT_TRUE(server2.IsValid());
579 564
580 Thread thread("IOHandler test"); 565 Thread thread("IOHandler test");
581 Thread::Options options; 566 Thread::Options options;
582 options.message_loop_type = MessageLoop::TYPE_IO; 567 options.message_loop_type = MessageLoop::TYPE_IO;
583 ASSERT_TRUE(thread.StartWithOptions(options)); 568 ASSERT_TRUE(thread.StartWithOptions(options));
584 569
585 MessageLoop* thread_loop = thread.message_loop();
586 ASSERT_TRUE(NULL != thread_loop);
587
588 TestIOHandler handler1(kPipeName1, callback1_called.Get(), false); 570 TestIOHandler handler1(kPipeName1, callback1_called.Get(), false);
589 TestIOHandler handler2(kPipeName2, callback2_called.Get(), true); 571 TestIOHandler handler2(kPipeName2, callback2_called.Get(), true);
590 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, 572 thread.task_runner()->PostTask(
591 Unretained(&handler1))); 573 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler1)));
592 // TODO(ajwong): Do we really need such long Sleeps in this function? 574 // TODO(ajwong): Do we really need such long Sleeps in this function?
593 // Make sure the thread runs and sleeps for lack of work. 575 // Make sure the thread runs and sleeps for lack of work.
594 TimeDelta delay = TimeDelta::FromMilliseconds(100); 576 TimeDelta delay = TimeDelta::FromMilliseconds(100);
595 PlatformThread::Sleep(delay); 577 PlatformThread::Sleep(delay);
596 thread_loop->PostTask(FROM_HERE, Bind(&TestIOHandler::Init, 578 thread.task_runner()->PostTask(
597 Unretained(&handler2))); 579 FROM_HERE, Bind(&TestIOHandler::Init, Unretained(&handler2)));
598 PlatformThread::Sleep(delay); 580 PlatformThread::Sleep(delay);
599 581
600 // At this time handler1 is waiting to be called, and the thread is waiting 582 // At this time handler1 is waiting to be called, and the thread is waiting
601 // on the Init method of handler2, filtering only handler2 callbacks. 583 // on the Init method of handler2, filtering only handler2 callbacks.
602 584
603 const char buffer[] = "Hello there!"; 585 const char buffer[] = "Hello there!";
604 DWORD written; 586 DWORD written;
605 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL)); 587 EXPECT_TRUE(WriteFile(server1.Get(), buffer, sizeof(buffer), &written, NULL));
606 PlatformThread::Sleep(2 * delay); 588 PlatformThread::Sleep(2 * delay);
607 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT), 589 EXPECT_EQ(static_cast<DWORD>(WAIT_TIMEOUT),
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 #if defined(OS_WIN) 682 #if defined(OS_WIN)
701 TEST(MessageLoopTest, IOHandler) { 683 TEST(MessageLoopTest, IOHandler) {
702 RunTest_IOHandler(); 684 RunTest_IOHandler();
703 } 685 }
704 686
705 TEST(MessageLoopTest, WaitForIO) { 687 TEST(MessageLoopTest, WaitForIO) {
706 RunTest_WaitForIO(); 688 RunTest_WaitForIO();
707 } 689 }
708 690
709 TEST(MessageLoopTest, HighResolutionTimer) { 691 TEST(MessageLoopTest, HighResolutionTimer) {
710 MessageLoop loop; 692 MessageLoop message_loop;
711 Time::EnableHighResolutionTimer(true); 693 Time::EnableHighResolutionTimer(true);
712 694
713 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5); 695 const TimeDelta kFastTimer = TimeDelta::FromMilliseconds(5);
714 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100); 696 const TimeDelta kSlowTimer = TimeDelta::FromMilliseconds(100);
715 697
716 EXPECT_FALSE(loop.HasHighResolutionTasks()); 698 EXPECT_FALSE(message_loop.HasHighResolutionTasks());
717 // Post a fast task to enable the high resolution timers. 699 // Post a fast task to enable the high resolution timers.
718 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), 700 message_loop.task_runner()->PostDelayedTask(
719 kFastTimer); 701 FROM_HERE, Bind(&PostNTasksThenQuit, 1), kFastTimer);
720 EXPECT_TRUE(loop.HasHighResolutionTasks()); 702 EXPECT_TRUE(message_loop.HasHighResolutionTasks());
721 loop.Run(); 703 RunLoop().Run();
722 EXPECT_FALSE(loop.HasHighResolutionTasks()); 704 EXPECT_FALSE(message_loop.HasHighResolutionTasks());
723 EXPECT_FALSE(Time::IsHighResolutionTimerInUse()); 705 EXPECT_FALSE(Time::IsHighResolutionTimerInUse());
724 // Check that a slow task does not trigger the high resolution logic. 706 // Check that a slow task does not trigger the high resolution logic.
725 loop.PostDelayedTask(FROM_HERE, Bind(&PostNTasksThenQuit, 1), 707 message_loop.task_runner()->PostDelayedTask(
726 kSlowTimer); 708 FROM_HERE, Bind(&PostNTasksThenQuit, 1), kSlowTimer);
727 EXPECT_FALSE(loop.HasHighResolutionTasks()); 709 EXPECT_FALSE(message_loop.HasHighResolutionTasks());
728 loop.Run(); 710 RunLoop().Run();
729 EXPECT_FALSE(loop.HasHighResolutionTasks()); 711 EXPECT_FALSE(message_loop.HasHighResolutionTasks());
730 Time::EnableHighResolutionTimer(false); 712 Time::EnableHighResolutionTimer(false);
731 } 713 }
732 714
733 #endif // defined(OS_WIN) 715 #endif // defined(OS_WIN)
734 716
735 #if defined(OS_POSIX) && !defined(OS_NACL) 717 #if defined(OS_POSIX) && !defined(OS_NACL)
736 718
737 namespace { 719 namespace {
738 720
739 class QuitDelegate : public MessageLoopForIO::Watcher { 721 class QuitDelegate : public MessageLoopForIO::Watcher {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 wc.lpszClassName = L"MessageLoopTest_HWND"; 967 wc.lpszClassName = L"MessageLoopTest_HWND";
986 ATOM atom = RegisterClassEx(&wc); 968 ATOM atom = RegisterClassEx(&wc);
987 ASSERT_TRUE(atom); 969 ASSERT_TRUE(atom);
988 970
989 HWND message_hwnd = CreateWindow(MAKEINTATOM(atom), 0, 0, 0, 0, 0, 0, 971 HWND message_hwnd = CreateWindow(MAKEINTATOM(atom), 0, 0, 0, 0, 0, 0,
990 HWND_MESSAGE, 0, instance, 0); 972 HWND_MESSAGE, 0, instance, 0);
991 ASSERT_TRUE(message_hwnd) << GetLastError(); 973 ASSERT_TRUE(message_hwnd) << GetLastError();
992 974
993 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); 975 ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1));
994 976
995 loop.Run(); 977 RunLoop().Run();
996 978
997 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance)); 979 ASSERT_TRUE(UnregisterClass(MAKEINTATOM(atom), instance));
998 } 980 }
999 #endif // defined(OS_WIN) 981 #endif // defined(OS_WIN)
1000 982
1001 TEST(MessageLoopTest, SetTaskRunner) { 983 TEST(MessageLoopTest, SetTaskRunner) {
1002 MessageLoop loop; 984 MessageLoop loop;
1003 scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner()); 985 scoped_refptr<SingleThreadTaskRunner> new_runner(new TestSimpleTaskRunner());
1004 986
1005 loop.SetTaskRunner(new_runner); 987 loop.SetTaskRunner(new_runner);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 1023
1042 { 1024 {
1043 std::string kThreadName("bar"); 1025 std::string kThreadName("bar");
1044 base::Thread thread(kThreadName); 1026 base::Thread thread(kThreadName);
1045 ASSERT_TRUE(thread.StartAndWaitForTesting()); 1027 ASSERT_TRUE(thread.StartAndWaitForTesting());
1046 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); 1028 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName());
1047 } 1029 }
1048 } 1030 }
1049 1031
1050 } // namespace base 1032 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_loop_task_runner_unittest.cc ('k') | base/message_loop/message_pump_glib_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698