Skip to content

Commit

Permalink
Fix ui_controlsui_controls::internal::SendMouseMoveImpl on HiDPI.
Browse files Browse the repository at this point in the history
Windows needs the location in screen coordinates rather than DIP.

Also:

- Added a timeout to ui_controls::internal::SendMouseMoveImpl so that an
  error message is logged and the callback is run after
  TestTimeout::action_timeout(). This helps protect against cases where
  another window is on top of the test window, or the mouse is moved
  into la la land where Windows doesn't call the test's hook proc.

- New logging in the guts of ui_controls_internal_win.cc will emit error
  messages when the mouse ends up in the wrong place following a call to
  ui_controls::internal::SendMouseMoveImpl.

- SendMouseMoveUITest.Probe has been added to interactive_ui_tests to
  verify some simple calls to controls::SendMouseMoveNotifyWhenDone.

BUG=764415
R=sky@chromium.org

Change-Id: I27d6ffad59635913b28ae41e1410f4d6461d3355
Reviewed-on: https://chromium-review.googlesource.com/753905
Commit-Queue: Greg Thompson <grt@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515015}
  • Loading branch information
GregTho authored and Commit Bot committed Nov 9, 2017
1 parent 8ddd95e commit 63e5386
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 93 deletions.
43 changes: 38 additions & 5 deletions chrome/browser/ui/send_mouse_move_uitest_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "ui/base/test/ui_controls.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"

class SendMouseMoveUITest : public InProcessBrowserTest {
Expand All @@ -28,7 +29,9 @@ class SendMouseMoveUITest : public InProcessBrowserTest {
// --gtest_filter=SendMouseMoveUITest.DISABLED_Fullscreen
IN_PROC_BROWSER_TEST_F(SendMouseMoveUITest, DISABLED_Fullscreen) {
// Make the browser fullscreen so that we can position the mouse anywhere on
// the display.
// the display, as ui_controls::SendMouseMoveNotifyWhenDone can only provide
// notifications when the mouse is moved over a window belonging to the
// current process.
chrome::ToggleFullscreenMode(browser());

display::Screen* const screen = display::Screen::GetScreen();
Expand All @@ -47,11 +50,41 @@ IN_PROC_BROWSER_TEST_F(SendMouseMoveUITest, DISABLED_Fullscreen) {
scan_x, scan_y, run_loop.QuitClosure()));
run_loop.Run();

// Check it two ways.
POINT cursor_pos = {};
ASSERT_NE(::GetCursorPos(&cursor_pos), FALSE);
EXPECT_EQ(gfx::Point(cursor_pos), gfx::Point(scan_x, scan_y));
// Check it.
EXPECT_EQ(screen->GetCursorScreenPoint(), gfx::Point(scan_x, scan_y));
}
}
}

// Test that the mouse can be positioned at a few locations on the screen.
IN_PROC_BROWSER_TEST_F(SendMouseMoveUITest, Probe) {
// Make the browser fullscreen so that we can position the mouse anywhere on
// the display, as ui_controls::SendMouseMoveNotifyWhenDone can only provide
// notifications when the mouse is moved over a window belonging to the
// current process.
chrome::ToggleFullscreenMode(browser());

display::Screen* const screen = display::Screen::GetScreen();
const gfx::Rect screen_bounds = screen->GetPrimaryDisplay().bounds();

// Position the mouse at the corners and the center.
const gfx::Point kPoints[] = {
screen_bounds.origin(),
gfx::Point(screen_bounds.right() - 1, screen_bounds.y()),
gfx::Point(screen_bounds.x(), screen_bounds.bottom() - 1),
gfx::Point(screen_bounds.right() - 1, screen_bounds.bottom() - 1),
screen_bounds.CenterPoint()};

for (const auto& point : kPoints) {
SCOPED_TRACE(testing::Message()
<< "(" << point.x() << ", " << point.y() << ")");
// Move the pointer.
base::RunLoop run_loop;
EXPECT_TRUE(ui_controls::SendMouseMoveNotifyWhenDone(
point.x(), point.y(), run_loop.QuitClosure()));
run_loop.Run();

// Check it.
EXPECT_EQ(screen->GetCursorScreenPoint(), point);
}
}
1 change: 1 addition & 0 deletions ui/base/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ static_library("test_support") {
"//skia",
"//testing/gtest",
"//ui/base:ui_data_pack",
"//ui/display:test_support",
"//ui/events:events_base",
"//ui/events:test_support",
"//ui/gfx",
Expand Down
3 changes: 3 additions & 0 deletions ui/base/test/ui_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,

// Simulate a mouse move.
bool SendMouseMove(long screen_x, long screen_y);

// Returns false on Windows if the desired position is not over a window
// belonging to the current process.
bool SendMouseMoveNotifyWhenDone(long screen_x,
long screen_y,
const base::Closure& task);
Expand Down
Loading

0 comments on commit 63e5386

Please sign in to comment.