OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/eintr_wrapper.h" | 10 #include "base/eintr_wrapper.h" |
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 PostMessage(NULL, WM_LBUTTONDOWN, 0, 0); | 1113 PostMessage(NULL, WM_LBUTTONDOWN, 0, 0); |
1114 PostMessage(NULL, WM_LBUTTONUP, 'A', 0); | 1114 PostMessage(NULL, WM_LBUTTONUP, 'A', 0); |
1115 } | 1115 } |
1116 | 1116 |
1117 void RunTest_Dispatcher(MessageLoop::Type message_loop_type) { | 1117 void RunTest_Dispatcher(MessageLoop::Type message_loop_type) { |
1118 MessageLoop loop(message_loop_type); | 1118 MessageLoop loop(message_loop_type); |
1119 | 1119 |
1120 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1120 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
1121 base::Bind(&MouseDownUp), 100); | 1121 base::Bind(&MouseDownUp), 100); |
1122 DispatcherImpl dispatcher; | 1122 DispatcherImpl dispatcher; |
1123 MessageLoopForUI::current()->Run(&dispatcher); | 1123 MessageLoopForUI::current()->RunWithDispatcher(&dispatcher); |
1124 ASSERT_EQ(2, dispatcher.dispatch_count_); | 1124 ASSERT_EQ(2, dispatcher.dispatch_count_); |
1125 } | 1125 } |
1126 | 1126 |
1127 LRESULT CALLBACK MsgFilterProc(int code, WPARAM wparam, LPARAM lparam) { | 1127 LRESULT CALLBACK MsgFilterProc(int code, WPARAM wparam, LPARAM lparam) { |
1128 if (code == base::MessagePumpForUI::kMessageFilterCode) { | 1128 if (code == base::MessagePumpForUI::kMessageFilterCode) { |
1129 MSG* msg = reinterpret_cast<MSG*>(lparam); | 1129 MSG* msg = reinterpret_cast<MSG*>(lparam); |
1130 if (msg->message == WM_LBUTTONDOWN) | 1130 if (msg->message == WM_LBUTTONDOWN) |
1131 return TRUE; | 1131 return TRUE; |
1132 } | 1132 } |
1133 return FALSE; | 1133 return FALSE; |
1134 } | 1134 } |
1135 | 1135 |
1136 void RunTest_DispatcherWithMessageHook(MessageLoop::Type message_loop_type) { | 1136 void RunTest_DispatcherWithMessageHook(MessageLoop::Type message_loop_type) { |
1137 MessageLoop loop(message_loop_type); | 1137 MessageLoop loop(message_loop_type); |
1138 | 1138 |
1139 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1139 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
1140 base::Bind(&MouseDownUp), 100); | 1140 base::Bind(&MouseDownUp), 100); |
1141 HHOOK msg_hook = SetWindowsHookEx(WH_MSGFILTER, | 1141 HHOOK msg_hook = SetWindowsHookEx(WH_MSGFILTER, |
1142 MsgFilterProc, | 1142 MsgFilterProc, |
1143 NULL, | 1143 NULL, |
1144 GetCurrentThreadId()); | 1144 GetCurrentThreadId()); |
1145 DispatcherImpl dispatcher; | 1145 DispatcherImpl dispatcher; |
1146 MessageLoopForUI::current()->Run(&dispatcher); | 1146 MessageLoopForUI::current()->RunWithDispatcher(&dispatcher); |
1147 ASSERT_EQ(1, dispatcher.dispatch_count_); | 1147 ASSERT_EQ(1, dispatcher.dispatch_count_); |
1148 UnhookWindowsHookEx(msg_hook); | 1148 UnhookWindowsHookEx(msg_hook); |
1149 } | 1149 } |
1150 | 1150 |
1151 class TestIOHandler : public MessageLoopForIO::IOHandler { | 1151 class TestIOHandler : public MessageLoopForIO::IOHandler { |
1152 public: | 1152 public: |
1153 TestIOHandler(const wchar_t* name, HANDLE signal, bool wait); | 1153 TestIOHandler(const wchar_t* name, HANDLE signal, bool wait); |
1154 | 1154 |
1155 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, | 1155 virtual void OnIOCompleted(MessageLoopForIO::IOContext* context, |
1156 DWORD bytes_transfered, DWORD error); | 1156 DWORD bytes_transfered, DWORD error); |
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1688 base::Bind(&DestructionObserverProbe::Run, | 1688 base::Bind(&DestructionObserverProbe::Run, |
1689 new DestructionObserverProbe(&task_destroyed, | 1689 new DestructionObserverProbe(&task_destroyed, |
1690 &destruction_observer_called)), | 1690 &destruction_observer_called)), |
1691 kDelayMS); | 1691 kDelayMS); |
1692 delete loop; | 1692 delete loop; |
1693 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); | 1693 EXPECT_TRUE(observer.task_destroyed_before_message_loop()); |
1694 // The task should have been destroyed when we deleted the loop. | 1694 // The task should have been destroyed when we deleted the loop. |
1695 EXPECT_TRUE(task_destroyed); | 1695 EXPECT_TRUE(task_destroyed); |
1696 EXPECT_TRUE(destruction_observer_called); | 1696 EXPECT_TRUE(destruction_observer_called); |
1697 } | 1697 } |
OLD | NEW |