Remove selection expansion finch finch flag.
[chromium-blink-merge.git] / ash / display / mouse_cursor_event_filter_unittest.cc
blobfe0554ab9c7279c9fae15d89dafe70830c0791d5
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/display/mouse_cursor_event_filter.h"
7 #include "ash/display/display_layout_store.h"
8 #include "ash/display/display_manager.h"
9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/cursor_manager_test_api.h"
12 #include "ash/test/display_manager_test_api.h"
13 #include "ui/aura/env.h"
14 #include "ui/events/test/event_generator.h"
16 namespace ash {
18 class MouseCursorEventFilterTest : public test::AshTestBase {
19 public:
20 MouseCursorEventFilterTest() {}
21 ~MouseCursorEventFilterTest() override {}
23 protected:
24 MouseCursorEventFilter* event_filter() {
25 return Shell::GetInstance()->mouse_cursor_filter();
28 bool TestIfMouseWarpsAt(const gfx::Point& point_in_screen) {
29 return test::DisplayManagerTestApi::TestIfMouseWarpsAt(GetEventGenerator(),
30 point_in_screen);
33 private:
34 DISALLOW_COPY_AND_ASSIGN(MouseCursorEventFilterTest);
37 // Verifies if the mouse pointer correctly moves to another display when there
38 // are two displays.
39 TEST_F(MouseCursorEventFilterTest, WarpMouse) {
40 if (!SupportsMultipleDisplays())
41 return;
43 UpdateDisplay("500x500,500x500");
45 ASSERT_EQ(
46 DisplayLayout::RIGHT,
47 Shell::GetInstance()->display_manager()->layout_store()->
48 default_display_layout().position);
50 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 11)));
52 // Touch the right edge of the primary root window. Pointer should warp.
53 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11)));
54 EXPECT_EQ("501,11", // by 2px.
55 aura::Env::GetInstance()->last_mouse_location().ToString());
57 // Touch the left edge of the secondary root window. Pointer should warp.
58 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 11)));
59 EXPECT_EQ("498,11", // by 2px.
60 aura::Env::GetInstance()->last_mouse_location().ToString());
62 // Touch the left edge of the primary root window.
63 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(0, 11)));
64 // Touch the top edge of the primary root window.
65 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
66 // Touch the bottom edge of the primary root window.
67 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));
68 // Touch the right edge of the secondary root window.
69 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(999, 11)));
70 // Touch the top edge of the secondary root window.
71 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 0)));
72 // Touch the bottom edge of the secondary root window.
73 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(11, 499)));
76 // Verifies if the mouse pointer correctly moves to another display even when
77 // two displays are not the same size.
78 TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentSizeDisplays) {
79 if (!SupportsMultipleDisplays())
80 return;
82 UpdateDisplay("500x500,600x600"); // the second one is larger.
84 ASSERT_EQ(
85 DisplayLayout::RIGHT,
86 Shell::GetInstance()->display_manager()->
87 GetCurrentDisplayLayout().position);
89 // Touch the left edge of the secondary root window. Pointer should NOT warp
90 // because 1px left of (0, 500) is outside the primary root window.
91 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(501, 500)));
92 EXPECT_EQ("501,500",
93 aura::Env::GetInstance()->last_mouse_location().ToString());
95 // Touch the left edge of the secondary root window. Pointer should warp
96 // because 1px left of (0, 480) is inside the primary root window.
97 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 480)));
98 EXPECT_EQ("498,480", // by 2px.
99 aura::Env::GetInstance()->last_mouse_location().ToString());
102 // Verifies if the mouse pointer correctly moves between displays with
103 // different scale factors. In native coords mode, there is no
104 // difference between drag and move.
105 TEST_F(MouseCursorEventFilterTest, WarpMouseDifferentScaleDisplaysInNative) {
106 if (!SupportsMultipleDisplays())
107 return;
109 UpdateDisplay("500x500,600x600*2");
111 ASSERT_EQ(DisplayLayout::RIGHT,
112 Shell::GetInstance()
113 ->display_manager()
114 ->GetCurrentDisplayLayout()
115 .position);
117 aura::Env::GetInstance()->set_last_mouse_location(gfx::Point(900, 123));
119 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 123)));
120 EXPECT_EQ("500,123",
121 aura::Env::GetInstance()->last_mouse_location().ToString());
122 // Touch the edge of 2nd display again and make sure it warps to
123 // 1st dislay.
124 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(500, 123)));
125 // TODO(oshima): Due to a bug in EventGenerator, the screen coordinates
126 // is shrinked by dsf once. Fix this.
127 EXPECT_EQ("498,61",
128 aura::Env::GetInstance()->last_mouse_location().ToString());
131 // Verifies if MouseCursorEventFilter::set_mouse_warp_enabled() works as
132 // expected.
133 TEST_F(MouseCursorEventFilterTest, SetMouseWarpModeFlag) {
134 if (!SupportsMultipleDisplays())
135 return;
137 UpdateDisplay("500x500,500x500");
139 event_filter()->set_mouse_warp_enabled(false);
140 EXPECT_FALSE(TestIfMouseWarpsAt(gfx::Point(499, 11)));
141 EXPECT_EQ("499,11",
142 aura::Env::GetInstance()->last_mouse_location().ToString());
144 event_filter()->set_mouse_warp_enabled(true);
145 EXPECT_TRUE(TestIfMouseWarpsAt(gfx::Point(499, 11)));
146 EXPECT_EQ("501,11",
147 aura::Env::GetInstance()->last_mouse_location().ToString());
150 // Verifies cursor's device scale factor is updated when a cursor has moved
151 // across root windows with different device scale factors
152 // (http://crbug.com/154183).
153 TEST_F(MouseCursorEventFilterTest, CursorDeviceScaleFactor) {
154 if (!SupportsMultipleDisplays())
155 return;
157 UpdateDisplay("400x400,800x800*2");
158 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
159 display_manager->SetLayoutForCurrentDisplays(
160 DisplayLayout(DisplayLayout::RIGHT, 0));
161 test::CursorManagerTestApi cursor_test_api(
162 Shell::GetInstance()->cursor_manager());
164 EXPECT_EQ(1.0f, cursor_test_api.GetCurrentCursor().device_scale_factor());
165 TestIfMouseWarpsAt(gfx::Point(399, 200));
166 EXPECT_EQ(2.0f, cursor_test_api.GetCurrentCursor().device_scale_factor());
167 TestIfMouseWarpsAt(gfx::Point(400, 200));
168 EXPECT_EQ(1.0f, cursor_test_api.GetCurrentCursor().device_scale_factor());
171 } // namespace ash