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" | |
22 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
23 #include "base/test/test_simple_task_runner.h" | 22 #include "base/test/test_simple_task_runner.h" |
24 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
25 #include "base/threading/thread.h" | 24 #include "base/threading/thread.h" |
26 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
27 #include "build/build_config.h" | 26 #include "build/build_config.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
29 | 28 |
30 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
31 #include "base/message_loop/message_pump_win.h" | 30 #include "base/message_loop/message_pump_win.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 order->RecordEnd(ENDDIALOG, cookie); | 252 order->RecordEnd(ENDDIALOG, cookie); |
254 } | 253 } |
255 } | 254 } |
256 | 255 |
257 void RecursiveFunc(TaskList* order, int cookie, int depth, | 256 void RecursiveFunc(TaskList* order, int cookie, int depth, |
258 bool is_reentrant) { | 257 bool is_reentrant) { |
259 order->RecordStart(RECURSIVE, cookie); | 258 order->RecordStart(RECURSIVE, cookie); |
260 if (depth > 0) { | 259 if (depth > 0) { |
261 if (is_reentrant) | 260 if (is_reentrant) |
262 MessageLoop::current()->SetNestableTasksAllowed(true); | 261 MessageLoop::current()->SetNestableTasksAllowed(true); |
263 MessageLoop::current()->PostTask( | 262 ThreadTaskRunnerHandle::Get()->PostTask( |
264 FROM_HERE, | 263 FROM_HERE, |
265 Bind(&RecursiveFunc, order, cookie, depth - 1, is_reentrant)); | 264 Bind(&RecursiveFunc, order, cookie, depth - 1, is_reentrant)); |
266 } | 265 } |
267 order->RecordEnd(RECURSIVE, cookie); | 266 order->RecordEnd(RECURSIVE, cookie); |
268 } | 267 } |
269 | 268 |
270 void QuitFunc(TaskList* order, int cookie) { | 269 void QuitFunc(TaskList* order, int cookie) { |
271 order->RecordStart(QUITMESSAGELOOP, cookie); | 270 order->RecordStart(QUITMESSAGELOOP, cookie); |
272 MessageLoop::current()->QuitWhenIdle(); | 271 MessageLoop::current()->QuitWhenIdle(); |
273 order->RecordEnd(QUITMESSAGELOOP, cookie); | 272 order->RecordEnd(QUITMESSAGELOOP, cookie); |
(...skipping 580 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 MessageLoop loop(MessageLoop::TYPE_UI); | 853 MessageLoop loop(MessageLoop::TYPE_UI); |
855 EXPECT_TRUE(loop.IsType(MessageLoop::TYPE_UI)); | 854 EXPECT_TRUE(loop.IsType(MessageLoop::TYPE_UI)); |
856 EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_IO)); | 855 EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_IO)); |
857 EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_DEFAULT)); | 856 EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_DEFAULT)); |
858 } | 857 } |
859 | 858 |
860 #if defined(OS_WIN) | 859 #if defined(OS_WIN) |
861 void EmptyFunction() {} | 860 void EmptyFunction() {} |
862 | 861 |
863 void PostMultipleTasks() { | 862 void PostMultipleTasks() { |
864 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&EmptyFunction)); | 863 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
865 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&EmptyFunction)); | 864 base::Bind(&EmptyFunction)); |
| 865 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 866 base::Bind(&EmptyFunction)); |
866 } | 867 } |
867 | 868 |
868 static const int kSignalMsg = WM_USER + 2; | 869 static const int kSignalMsg = WM_USER + 2; |
869 | 870 |
870 void PostWindowsMessage(HWND message_hwnd) { | 871 void PostWindowsMessage(HWND message_hwnd) { |
871 PostMessage(message_hwnd, kSignalMsg, 0, 2); | 872 PostMessage(message_hwnd, kSignalMsg, 0, 2); |
872 } | 873 } |
873 | 874 |
874 void EndTest(bool* did_run, HWND hwnd) { | 875 void EndTest(bool* did_run, HWND hwnd) { |
875 *did_run = true; | 876 *did_run = true; |
876 PostMessage(hwnd, WM_CLOSE, 0, 0); | 877 PostMessage(hwnd, WM_CLOSE, 0, 0); |
877 } | 878 } |
878 | 879 |
879 int kMyMessageFilterCode = 0x5002; | 880 int kMyMessageFilterCode = 0x5002; |
880 | 881 |
881 LRESULT CALLBACK TestWndProcThunk(HWND hwnd, UINT message, | 882 LRESULT CALLBACK TestWndProcThunk(HWND hwnd, UINT message, |
882 WPARAM wparam, LPARAM lparam) { | 883 WPARAM wparam, LPARAM lparam) { |
883 if (message == WM_CLOSE) | 884 if (message == WM_CLOSE) |
884 EXPECT_TRUE(DestroyWindow(hwnd)); | 885 EXPECT_TRUE(DestroyWindow(hwnd)); |
885 if (message != kSignalMsg) | 886 if (message != kSignalMsg) |
886 return DefWindowProc(hwnd, message, wparam, lparam); | 887 return DefWindowProc(hwnd, message, wparam, lparam); |
887 | 888 |
888 switch (lparam) { | 889 switch (lparam) { |
889 case 1: | 890 case 1: |
890 // First, we post a task that will post multiple no-op tasks to make sure | 891 // First, we post a task that will post multiple no-op tasks to make sure |
891 // that the pump's incoming task queue does not become empty during the | 892 // that the pump's incoming task queue does not become empty during the |
892 // test. | 893 // test. |
893 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&PostMultipleTasks)); | 894 ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 895 base::Bind(&PostMultipleTasks)); |
894 // Next, we post a task that posts a windows message to trigger the second | 896 // Next, we post a task that posts a windows message to trigger the second |
895 // stage of the test. | 897 // stage of the test. |
896 MessageLoop::current()->PostTask(FROM_HERE, | 898 ThreadTaskRunnerHandle::Get()->PostTask( |
897 base::Bind(&PostWindowsMessage, hwnd)); | 899 FROM_HERE, base::Bind(&PostWindowsMessage, hwnd)); |
898 break; | 900 break; |
899 case 2: | 901 case 2: |
900 // Since we're about to enter a modal loop, tell the message loop that we | 902 // Since we're about to enter a modal loop, tell the message loop that we |
901 // intend to nest tasks. | 903 // intend to nest tasks. |
902 MessageLoop::current()->SetNestableTasksAllowed(true); | 904 MessageLoop::current()->SetNestableTasksAllowed(true); |
903 bool did_run = false; | 905 bool did_run = false; |
904 MessageLoop::current()->PostTask(FROM_HERE, | 906 ThreadTaskRunnerHandle::Get()->PostTask( |
905 base::Bind(&EndTest, &did_run, hwnd)); | 907 FROM_HERE, base::Bind(&EndTest, &did_run, hwnd)); |
906 // Run a nested windows-style message loop and verify that our task runs. If | 908 // Run a nested windows-style message loop and verify that our task runs. If |
907 // it doesn't, then we'll loop here until the test times out. | 909 // it doesn't, then we'll loop here until the test times out. |
908 MSG msg; | 910 MSG msg; |
909 while (GetMessage(&msg, 0, 0, 0)) { | 911 while (GetMessage(&msg, 0, 0, 0)) { |
910 if (!CallMsgFilter(&msg, kMyMessageFilterCode)) | 912 if (!CallMsgFilter(&msg, kMyMessageFilterCode)) |
911 DispatchMessage(&msg); | 913 DispatchMessage(&msg); |
912 // If this message is a WM_CLOSE, explicitly exit the modal loop. Posting | 914 // If this message is a WM_CLOSE, explicitly exit the modal loop. Posting |
913 // a WM_QUIT should handle this, but unfortunately MessagePumpWin eats | 915 // a WM_QUIT should handle this, but unfortunately MessagePumpWin eats |
914 // WM_QUIT messages even when running inside a modal loop. | 916 // WM_QUIT messages even when running inside a modal loop. |
915 if (msg.message == WM_CLOSE) | 917 if (msg.message == WM_CLOSE) |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
988 | 990 |
989 { | 991 { |
990 std::string kThreadName("bar"); | 992 std::string kThreadName("bar"); |
991 base::Thread thread(kThreadName); | 993 base::Thread thread(kThreadName); |
992 ASSERT_TRUE(thread.StartAndWaitForTesting()); | 994 ASSERT_TRUE(thread.StartAndWaitForTesting()); |
993 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); | 995 EXPECT_EQ(kThreadName, thread.message_loop()->GetThreadName()); |
994 } | 996 } |
995 } | 997 } |
996 | 998 |
997 } // namespace base | 999 } // namespace base |
OLD | NEW |