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

Unified Diff: ui/base/test/ui_controls_internal_win.cc

Issue 2286853002: Add temporary debug logging for crbug.com/639350. (Closed)
Patch Set: Add logging for mouse moves and events. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/test/ui_controls.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/test/ui_controls_internal_win.cc
diff --git a/ui/base/test/ui_controls_internal_win.cc b/ui/base/test/ui_controls_internal_win.cc
index ade37c9375840cb879cb213f184ecc652d2e5cd7..2b1265ad400fc9b55112b764fe184431cb21e78c 100644
--- a/ui/base/test/ui_controls_internal_win.cc
+++ b/ui/base/test/ui_controls_internal_win.cc
@@ -15,6 +15,13 @@
#include "ui/events/keycodes/keyboard_code_conversion_win.h"
#include "ui/events/keycodes/keyboard_codes.h"
+namespace ui_controls {
+
+// TODO(msw): Remove flaky test debug logging for http://crbug.com/639350.
+bool g_crbug_639350_logging = false;
+
+namespace internal {
+
namespace {
// InputDispatcher ------------------------------------------------------------
@@ -61,80 +68,143 @@ InputDispatcher* current_dispatcher_ = NULL;
// Callback from hook when a mouse message is received.
LRESULT CALLBACK MouseHook(int n_code, WPARAM w_param, LPARAM l_param) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 MouseHook A";
HHOOK next_hook = next_hook_;
if (n_code == HC_ACTION) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 MouseHook B";
DCHECK(current_dispatcher_);
current_dispatcher_->DispatchedMessage(w_param);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 MouseHook C";
}
- return CallNextHookEx(next_hook, n_code, w_param, l_param);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 MouseHook D";
+ LRESULT result = CallNextHookEx(next_hook, n_code, w_param, l_param);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 MouseHook E";
+ return result;
}
// Callback from hook when a key message is received.
LRESULT CALLBACK KeyHook(int n_code, WPARAM w_param, LPARAM l_param) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 KeyHook A";
HHOOK next_hook = next_hook_;
if (n_code == HC_ACTION) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 KeyHook B";
DCHECK(current_dispatcher_);
if (l_param & (1 << 30)) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 KeyHook C";
// Only send on key up.
current_dispatcher_->MatchingMessageFound();
}
}
- return CallNextHookEx(next_hook, n_code, w_param, l_param);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 KeyHook D";
+ LRESULT result = CallNextHookEx(next_hook, n_code, w_param, l_param);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 KeyHook E";
+ return result;
}
// Installs dispatcher as the current hook.
void InstallHook(InputDispatcher* dispatcher, bool key_hook) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InstallHook A";
DCHECK(!installed_hook_);
current_dispatcher_ = dispatcher;
installed_hook_ = true;
if (key_hook) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InstallHook B";
next_hook_ = SetWindowsHookEx(WH_KEYBOARD, &KeyHook, NULL,
GetCurrentThreadId());
} else {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InstallHook C";
// NOTE: I originally tried WH_CALLWNDPROCRET, but for some reason I
// didn't get a mouse message like I do with MouseHook.
next_hook_ = SetWindowsHookEx(WH_MOUSE, &MouseHook, NULL,
GetCurrentThreadId());
}
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InstallHook D";
DCHECK(next_hook_);
}
// Uninstalls the hook set in InstallHook.
void UninstallHook(InputDispatcher* dispatcher) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 UninstallHook A";
if (current_dispatcher_ == dispatcher) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 UninstallHook B";
installed_hook_ = false;
current_dispatcher_ = NULL;
UnhookWindowsHookEx(next_hook_);
}
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 UninstallHook C";
}
InputDispatcher::InputDispatcher(const base::Closure& task,
WPARAM message_waiting_for)
: task_(task), message_waiting_for_(message_waiting_for) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::InputDispatcher A";
InstallHook(this, message_waiting_for == WM_KEYUP);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::InputDispatcher B";
}
InputDispatcher::~InputDispatcher() {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::~InputDispatcher A";
// Make sure the hook isn't installed.
UninstallHook(this);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::~InputDispatcher B";
}
void InputDispatcher::DispatchedMessage(WPARAM message) {
- if (message == message_waiting_for_)
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::DispatchedMessage A";
+ if (message == message_waiting_for_) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::DispatchedMessage B";
MatchingMessageFound();
+ }
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::DispatchedMessage C";
}
void InputDispatcher::MatchingMessageFound() {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::MatchingMessageFound A";
UninstallHook(this);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::MatchingMessageFound B";
// At the time we're invoked the event has not actually been processed.
// Use PostTask to make sure the event has been processed before notifying.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&InputDispatcher::NotifyTask, this));
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::MatchingMessageFound C";
}
void InputDispatcher::NotifyTask() {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::NotifyTask A";
task_.Run();
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::NotifyTask B";
Release();
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 InputDispatcher::NotifyTask C";
}
// Private functions ----------------------------------------------------------
@@ -142,38 +212,48 @@ void InputDispatcher::NotifyTask() {
// Populate the INPUT structure with the appropriate keyboard event
// parameters required by SendInput
bool FillKeyboardInput(ui::KeyboardCode key, INPUT* input, bool key_up) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 FillKeyboardInput A";
memset(input, 0, sizeof(INPUT));
input->type = INPUT_KEYBOARD;
input->ki.wVk = ui::WindowsKeyCodeForKeyboardCode(key);
input->ki.dwFlags = key_up ? KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP :
KEYEVENTF_EXTENDEDKEY;
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 FillKeyboardInput B";
return true;
}
} // namespace
-namespace ui_controls {
-namespace internal {
-
bool SendKeyPressImpl(HWND window,
ui::KeyboardCode key,
bool control,
bool shift,
bool alt,
const base::Closure& task) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendKeyPressImpl A";
// SendInput only works as we expect it if one of our windows is the
// foreground window already.
HWND target_window = (::GetActiveWindow() &&
::GetWindow(::GetActiveWindow(), GW_OWNER) == window) ?
::GetActiveWindow() :
window;
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendKeyPressImpl B";
if (window && ::GetForegroundWindow() != target_window)
return false;
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendKeyPressImpl C";
scoped_refptr<InputDispatcher> dispatcher(
!task.is_null() ? new InputDispatcher(task, WM_KEYUP) : NULL);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendKeyPressImpl D";
+
// If a pop-up menu is open, it won't receive events sent using SendInput.
// Check for a pop-up menu using its window class (#32768) and if one
// exists, send the key event directly there.
@@ -188,6 +268,8 @@ bool SendKeyPressImpl(HWND window,
dispatcher->AddRef();
return true;
}
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendKeyPressImpl E";
INPUT input[8] = {}; // 8, assuming all the modifiers are activated.
@@ -235,27 +317,43 @@ bool SendKeyPressImpl(HWND window,
return false;
i++;
}
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendKeyPressImpl F";
if (::SendInput(i, input, sizeof(INPUT)) != i)
return false;
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendKeyPressImpl G";
if (dispatcher.get())
dispatcher->AddRef();
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendKeyPressImpl H";
return true;
}
bool SendMouseMoveImpl(long screen_x,
long screen_y,
const base::Closure& task) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl A";
// First check if the mouse is already there.
POINT current_pos;
::GetCursorPos(&current_pos);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl B";
if (screen_x == current_pos.x && screen_y == current_pos.y) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl C";
if (!task.is_null())
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, task);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl D";
return true;
}
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl E";
INPUT input = { 0 };
@@ -269,20 +367,31 @@ bool SendMouseMoveImpl(long screen_x,
input.mi.dx = pixel_x;
input.mi.dy = pixel_y;
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl F";
scoped_refptr<InputDispatcher> dispatcher(
!task.is_null() ? new InputDispatcher(task, WM_MOUSEMOVE) : NULL);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl G";
if (!::SendInput(1, &input, sizeof(INPUT)))
return false;
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl H";
+
if (dispatcher.get())
dispatcher->AddRef();
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseMoveImpl I";
return true;
}
bool SendMouseEventsImpl(MouseButton type, int state,
const base::Closure& task) {
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseEventsImpl A";
DWORD down_flags = MOUSEEVENTF_ABSOLUTE;
DWORD up_flags = MOUSEEVENTF_ABSOLUTE;
UINT last_event;
@@ -311,8 +420,12 @@ bool SendMouseEventsImpl(MouseButton type, int state,
return false;
}
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseEventsImpl B";
scoped_refptr<InputDispatcher> dispatcher(
!task.is_null() ? new InputDispatcher(task, last_event) : NULL);
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseEventsImpl C";
INPUT input = { 0 };
input.type = INPUT_MOUSE;
@@ -320,12 +433,18 @@ bool SendMouseEventsImpl(MouseButton type, int state,
if ((state & DOWN) && !::SendInput(1, &input, sizeof(INPUT)))
return false;
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseEventsImpl D";
input.mi.dwFlags = up_flags;
if ((state & UP) && !::SendInput(1, &input, sizeof(INPUT)))
return false;
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseEventsImpl E";
if (dispatcher.get())
dispatcher->AddRef();
+ if (g_crbug_639350_logging)
+ LOG(ERROR) << "crbug.com/639350 SendMouseEventsImpl F";
return true;
}
« no previous file with comments | « ui/base/test/ui_controls.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698