Index: base/message_loop/message_loop_unittest.cc |
diff --git a/base/message_loop/message_loop_unittest.cc b/base/message_loop/message_loop_unittest.cc |
index fe2d728fe408c8cd3baef46d692e920cee8e3571..5d7f488abf2fc9fbcd849e536db1a195583c2d12 100644 |
--- a/base/message_loop/message_loop_unittest.cc |
+++ b/base/message_loop/message_loop_unittest.cc |
@@ -23,6 +23,8 @@ |
#if defined(OS_WIN) |
#include "base/message_loop/message_pump_win.h" |
+#include "base/process/memory.h" |
+#include "base/strings/string16.h" |
#include "base/win/scoped_handle.h" |
#endif |
@@ -1080,4 +1082,81 @@ TEST(MessageLoopTest, IsType) { |
EXPECT_FALSE(loop.IsType(MessageLoop::TYPE_DEFAULT)); |
} |
+#if defined(OS_WIN) |
+void EmptyFunction() {} |
+ |
+void PostMultipleTasks() { |
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&EmptyFunction)); |
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&EmptyFunction)); |
+} |
+ |
+static const int kSignalMsg = WM_USER + 2; |
+ |
+void PostWindowsMessage(HWND message_hwnd) { |
+ PostMessage(message_hwnd, kSignalMsg, 0, 2); |
+} |
+ |
+void DidRun(bool* did_run) { *did_run = true; } |
+ |
+UINT_PTR timer_id = 0; |
+ |
+LRESULT CALLBACK TestWndProcThunk(HWND hwnd, UINT message, |
+ WPARAM wparam, LPARAM lparam) { |
+ if (message == WM_TIMER) { |
+ KillTimer(hwnd, timer_id); |
+ PostQuitMessage(0); |
+ return 0; |
+ } |
cpu_(ooo_6.6-7.5)
2013/11/20 21:31:25
check message
|
+ switch (lparam) { |
+ case 1: |
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&PostMultipleTasks)); |
+ MessageLoop::current()->PostTask(FROM_HERE, |
+ base::Bind(&PostWindowsMessage, hwnd)); |
+ return 0; |
+ case 2: |
+ MessageLoop::current()->SetNestableTasksAllowed(true); |
+ // Make sure we have a kMsgHaveWork "tickler" in the windows message queue. |
+ // If we don't, and this enters a synchronous windows message loop, we won't |
+ // get to run any posted tasks. |
cpu_(ooo_6.6-7.5)
2013/11/20 21:31:25
comment is stale?
|
+ // Run a nested windows-style message loop and verify that our tasks run. |
+ bool did_run = false; |
+ MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&DidRun, &did_run)); |
+ unsigned timer = SetTimer(hwnd, 1, 10, NULL); |
+ MSG msg; |
+ while (GetMessage(&msg, 0, 0, 0)) { |
+ DispatchMessage(&msg); |
+ } |
+ EXPECT_TRUE(did_run); |
jamesr
2013/11/20 21:00:54
this check fails without the message_loop.cc patch
|
+ MessageLoop::current()->Quit(); |
+ return 0; |
+ } |
+ return DefWindowProc(hwnd, message, wparam, lparam); |
+} |
+ |
+TEST(MessageLoopTest, AlwaysHaveUserMessageWhenNesting) { |
+ MessageLoop loop(MessageLoop::TYPE_UI); |
+ ATOM atom; |
+ string16 class_name = L"MessageLoopTest_HWND"; |
cpu_(ooo_6.6-7.5)
2013/11/20 21:31:25
unneeded class_name
|
+ HINSTANCE instance = GetModuleFromAddress(&TestWndProcThunk); |
+ WNDCLASSEX wc = {0}; |
+ wc.cbSize = sizeof(wc); |
+ wc.lpfnWndProc = TestWndProcThunk; |
+ wc.hInstance = instance; |
+ wc.lpszClassName = class_name.c_str(); |
+ atom = RegisterClassEx(&wc); |
cpu_(ooo_6.6-7.5)
2013/11/20 21:31:25
ATOM atom =
|
+ ASSERT_TRUE(atom); |
+ |
+ HWND message_hwnd = CreateWindow(MAKEINTATOM(atom), 0, 0, 0, 0, 0, 0, |
+ HWND_MESSAGE, 0, instance, 0); |
+ int error = GetLastError(); |
+ ASSERT_TRUE(message_hwnd) << error; |
+ |
+ ASSERT_TRUE(PostMessage(message_hwnd, kSignalMsg, 0, 1)); |
+ |
+ loop.Run(); |
+ |
+ ASSERT_TRUE(DestroyWindow(message_hwnd)); |
cpu_(ooo_6.6-7.5)
2013/11/20 21:31:25
UnregisterClass(atom)
|
+} |
+#endif // defined(OS_WIN) |
+ |
} // namespace base |