summaryrefslogtreecommitdiffstats
path: root/ash/extended_desktop_unittest.cc
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-12 04:46:37 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-12 04:46:37 +0000
commit2ca7594cad9b497998b2b5102be086e51dc00d08 (patch)
tree80c0c6eb902fae1ac51bf6733e1e34d4b8aed061 /ash/extended_desktop_unittest.cc
parent1820b9a5d154a84fd490a8e92b0bcad21b56bbb2 (diff)
downloadchromium_src-2ca7594cad9b497998b2b5102be086e51dc00d08.zip
chromium_src-2ca7594cad9b497998b2b5102be086e51dc00d08.tar.gz
chromium_src-2ca7594cad9b497998b2b5102be086e51dc00d08.tar.bz2
aura: Make sure redirected events have the correct location.
If an event is redirected to a different WindowTreeHost because the target window belongs to that, then make sure the event is in the WindowTreeHost's root-window's coordinate space. This is necessary to make sure that the target (and the pre/post-target handlers) see the event in the correct location. BUG=385770 R=sky@chromium.org Review URL: https://codereview.chromium.org/380343002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282794 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/extended_desktop_unittest.cc')
-rw-r--r--ash/extended_desktop_unittest.cc132
1 files changed, 132 insertions, 0 deletions
diff --git a/ash/extended_desktop_unittest.cc b/ash/extended_desktop_unittest.cc
index eb8591d..c1ce930 100644
--- a/ash/extended_desktop_unittest.cc
+++ b/ash/extended_desktop_unittest.cc
@@ -117,6 +117,29 @@ class EventLocationRecordingEventHandler : public ui::EventHandler {
DISALLOW_COPY_AND_ASSIGN(EventLocationRecordingEventHandler);
};
+class EventLocationHandler : public ui::EventHandler {
+ public:
+ EventLocationHandler() {}
+ virtual ~EventLocationHandler() {}
+
+ const gfx::Point& press_location() const { return press_location_; }
+ const gfx::Point& release_location() const { return release_location_; }
+
+ private:
+ // ui::EventHandler:
+ virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ if (event->type() == ui::ET_MOUSE_PRESSED)
+ press_location_ = event->location();
+ else if (event->type() == ui::ET_MOUSE_RELEASED)
+ release_location_ = event->location();
+ }
+
+ gfx::Point press_location_;
+ gfx::Point release_location_;
+
+ DISALLOW_COPY_AND_ASSIGN(EventLocationHandler);
+};
+
} // namespace
class ExtendedDesktopTest : public test::AshTestBase {
@@ -415,6 +438,115 @@ TEST_F(ExtendedDesktopTest, Capture) {
EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset());
}
+TEST_F(ExtendedDesktopTest, CaptureEventLocation) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ UpdateDisplay("1000x600,600x400");
+ aura::Window::Windows root_windows = Shell::GetAllRootWindows();
+
+ aura::test::EventCountDelegate r1_d1;
+ aura::test::EventCountDelegate r1_d2;
+ aura::test::EventCountDelegate r2_d1;
+
+ scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
+ &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
+ scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
+ &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
+ scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
+ &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
+
+ r1_w1->SetCapture();
+
+ aura::test::EventGenerator& generator = GetEventGenerator();
+ generator.MoveMouseToCenterOf(r2_w1.get());
+ EXPECT_EQ(gfx::Point(1060, 60).ToString(),
+ generator.current_location().ToString());
+
+ EventLocationHandler location_handler;
+ r1_w1->AddPreTargetHandler(&location_handler);
+ generator.ClickLeftButton();
+ r1_w1->RemovePreTargetHandler(&location_handler);
+ EXPECT_EQ(gfx::Point(1050, 50).ToString(),
+ location_handler.press_location().ToString());
+ EXPECT_EQ(gfx::Point(1050, 50).ToString(),
+ location_handler.release_location().ToString());
+}
+
+TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ UpdateDisplay("1000x600*2,600x400");
+ aura::Window::Windows root_windows = Shell::GetAllRootWindows();
+
+ aura::test::EventCountDelegate r1_d1;
+ aura::test::EventCountDelegate r1_d2;
+ aura::test::EventCountDelegate r2_d1;
+
+ scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
+ &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
+ scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
+ &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
+ scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
+ &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
+
+ r1_w1->SetCapture();
+
+ aura::test::EventGenerator& generator = GetEventGenerator();
+ generator.MoveMouseToCenterOf(r2_w1.get());
+ EXPECT_EQ(gfx::Point(560, 60).ToString(),
+ generator.current_location().ToString());
+
+ EventLocationHandler location_handler;
+ r1_w1->AddPreTargetHandler(&location_handler);
+ generator.ClickLeftButton();
+ r1_w1->RemovePreTargetHandler(&location_handler);
+ EXPECT_EQ(gfx::Point(550, 50).ToString(),
+ location_handler.press_location().ToString());
+ EXPECT_EQ(gfx::Point(550, 50).ToString(),
+ location_handler.release_location().ToString());
+}
+
+TEST_F(ExtendedDesktopTest, CaptureEventLocationHighDPI_2) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ UpdateDisplay("1000x600,600x400*2");
+ aura::Window::Windows root_windows = Shell::GetAllRootWindows();
+
+ aura::test::EventCountDelegate r1_d1;
+ aura::test::EventCountDelegate r1_d2;
+ aura::test::EventCountDelegate r2_d1;
+
+ scoped_ptr<aura::Window> r1_w1(aura::test::CreateTestWindowWithDelegate(
+ &r1_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[0]));
+ scoped_ptr<aura::Window> r1_w2(aura::test::CreateTestWindowWithDelegate(
+ &r1_d2, 0, gfx::Rect(10, 100, 100, 100), root_windows[0]));
+ scoped_ptr<aura::Window> r2_w1(aura::test::CreateTestWindowWithDelegate(
+ &r2_d1, 0, gfx::Rect(10, 10, 100, 100), root_windows[1]));
+
+ r1_w1->SetCapture();
+
+ aura::test::EventGenerator& generator = GetEventGenerator();
+ generator.MoveMouseToCenterOf(r2_w1.get());
+ EXPECT_EQ(gfx::Point(1060, 60).ToString(),
+ generator.current_location().ToString());
+
+ EventLocationHandler location_handler;
+ r1_w1->AddPreTargetHandler(&location_handler);
+ generator.ClickLeftButton();
+ r1_w1->RemovePreTargetHandler(&location_handler);
+ // Event-generator dispatches the event in the primary root-window's coord
+ // space. Since the location is (1060, 60), it goes to the secondary
+ // root-window as (30, 30) since the secondary root-window has a device scale
+ // factor of 2.
+ EXPECT_EQ(gfx::Point(1020, 20).ToString(),
+ location_handler.press_location().ToString());
+ EXPECT_EQ(gfx::Point(1020, 20).ToString(),
+ location_handler.release_location().ToString());
+}
+
TEST_F(ExtendedDesktopTest, MoveWindow) {
if (!SupportsMultipleDisplays())
return;