oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 1 | // Copyright 2015 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. |
| 4 | |
| 5 | #include "ash/display/extended_mouse_warp_controller.h" |
| 6 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 7 | #include "ash/display/mouse_cursor_event_filter.h" |
| 8 | #include "ash/shell.h" |
| 9 | #include "ash/test/ash_test_base.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 10 | #include "ui/display/display.h" |
kylechar | 731f85f9 | 2016-12-01 20:50:46 | [diff] [blame] | 11 | #include "ui/display/display_layout.h" |
| 12 | #include "ui/display/display_layout_builder.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 13 | #include "ui/display/manager/display_manager.h" |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 14 | #include "ui/display/screen.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 15 | #include "ui/display/test/display_manager_test_api.h" |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 16 | #include "ui/events/test/event_generator.h" |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 17 | |
| 18 | namespace ash { |
| 19 | |
James Cook | 317781a | 2017-07-18 02:08:06 | [diff] [blame] | 20 | class ExtendedMouseWarpControllerTest : public AshTestBase { |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 21 | public: |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame^] | 22 | ExtendedMouseWarpControllerTest() = default; |
| 23 | ~ExtendedMouseWarpControllerTest() override = default; |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 24 | |
| 25 | protected: |
| 26 | MouseCursorEventFilter* event_filter() { |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 27 | return Shell::Get()->mouse_cursor_filter(); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | ExtendedMouseWarpController* mouse_warp_controller() { |
| 31 | return static_cast<ExtendedMouseWarpController*>( |
| 32 | event_filter()->mouse_warp_controller_for_test()); |
| 33 | } |
| 34 | |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 35 | size_t GetWarpRegionsCount() { |
| 36 | return mouse_warp_controller()->warp_regions_.size(); |
| 37 | } |
| 38 | |
| 39 | const ExtendedMouseWarpController::WarpRegion* GetWarpRegion(size_t index) { |
| 40 | return mouse_warp_controller()->warp_regions_[index].get(); |
| 41 | } |
| 42 | |
| 43 | const gfx::Rect& GetIndicatorBounds(int64_t id) { |
| 44 | return GetWarpRegion(0)->GetIndicatorBoundsForTest(id); |
| 45 | } |
| 46 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 47 | private: |
| 48 | DISALLOW_COPY_AND_ASSIGN(ExtendedMouseWarpControllerTest); |
| 49 | }; |
| 50 | |
| 51 | // Verifies if MouseCursorEventFilter's bounds calculation works correctly. |
| 52 | TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnRight) { |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 53 | UpdateDisplay("360x360,700x700"); |
| 54 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 55 | int64_t display_0_id = display::Screen::GetScreen() |
| 56 | ->GetDisplayNearestWindow(root_windows[0]) |
| 57 | .id(); |
| 58 | int64_t display_1_id = display::Screen::GetScreen() |
| 59 | ->GetDisplayNearestWindow(root_windows[1]) |
| 60 | .id(); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 61 | |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 62 | std::unique_ptr<display::DisplayLayout> layout( |
| 63 | display::test::CreateDisplayLayout(display_manager(), |
| 64 | display::DisplayPlacement::RIGHT, 0)); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 65 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 66 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 67 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
jdufault | fb0a4212 | 2016-01-21 21:40:41 | [diff] [blame] | 68 | |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 69 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 70 | EXPECT_EQ(gfx::Rect(359, 16, 1, 344), GetIndicatorBounds(display_0_id)); |
| 71 | EXPECT_EQ(gfx::Rect(360, 0, 1, 360), GetIndicatorBounds(display_1_id)); |
| 72 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 73 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 74 | EXPECT_EQ(gfx::Rect(359, 0, 1, 360), GetIndicatorBounds(display_0_id)); |
| 75 | EXPECT_EQ(gfx::Rect(360, 16, 1, 344), GetIndicatorBounds(display_1_id)); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 76 | |
| 77 | // Move 2nd display downwards a bit. |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 78 | layout->placement_list[0].offset = 5; |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 79 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 80 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
| 81 | // This is same as before because the 2nd display's y is above |
| 82 | // the indicator's x. |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 83 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 84 | EXPECT_EQ(gfx::Rect(359, 16, 1, 344), GetIndicatorBounds(display_0_id)); |
| 85 | EXPECT_EQ(gfx::Rect(360, 5, 1, 355), GetIndicatorBounds(display_1_id)); |
| 86 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 87 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 88 | EXPECT_EQ(gfx::Rect(359, 5, 1, 355), GetIndicatorBounds(display_0_id)); |
| 89 | EXPECT_EQ(gfx::Rect(360, 21, 1, 339), GetIndicatorBounds(display_1_id)); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 90 | |
| 91 | // Move it down further so that the shared edge is shorter than |
| 92 | // minimum hole size (160). |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 93 | layout->placement_list[0].offset = 200; |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 94 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 95 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 96 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 97 | EXPECT_EQ(gfx::Rect(359, 200, 1, 160), GetIndicatorBounds(display_0_id)); |
| 98 | EXPECT_EQ(gfx::Rect(360, 200, 1, 160), GetIndicatorBounds(display_1_id)); |
| 99 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 100 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 101 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 102 | EXPECT_EQ(gfx::Rect(359, 200, 1, 160), GetIndicatorBounds(display_0_id)); |
| 103 | EXPECT_EQ(gfx::Rect(360, 200, 1, 160), GetIndicatorBounds(display_1_id)); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 104 | |
| 105 | // Now move 2nd display upwards |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 106 | layout->placement_list[0].offset = -5; |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 107 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 108 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 109 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 110 | EXPECT_EQ(gfx::Rect(359, 16, 1, 344), GetIndicatorBounds(display_0_id)); |
| 111 | EXPECT_EQ(gfx::Rect(360, 0, 1, 360), GetIndicatorBounds(display_1_id)); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 112 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
| 113 | // 16 px are reserved on 2nd display from top, so y must be |
| 114 | // (16 - 5) = 11 |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 115 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 116 | EXPECT_EQ(gfx::Rect(359, 0, 1, 360), GetIndicatorBounds(display_0_id)); |
| 117 | EXPECT_EQ(gfx::Rect(360, 11, 1, 349), GetIndicatorBounds(display_1_id)); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 118 | |
| 119 | event_filter()->HideSharedEdgeIndicator(); |
| 120 | } |
| 121 | |
| 122 | TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnLeft) { |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 123 | UpdateDisplay("360x360,700x700"); |
| 124 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 125 | |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 126 | int64_t display_0_id = display::Screen::GetScreen() |
| 127 | ->GetDisplayNearestWindow(root_windows[0]) |
| 128 | .id(); |
| 129 | int64_t display_1_id = display::Screen::GetScreen() |
| 130 | ->GetDisplayNearestWindow(root_windows[1]) |
| 131 | .id(); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 132 | |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 133 | std::unique_ptr<display::DisplayLayout> layout( |
| 134 | display::test::CreateDisplayLayout(display_manager(), |
| 135 | display::DisplayPlacement::LEFT, 0)); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 136 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 137 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 138 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 139 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 140 | EXPECT_EQ(gfx::Rect(0, 16, 1, 344), GetIndicatorBounds(display_0_id)); |
| 141 | EXPECT_EQ(gfx::Rect(-1, 0, 1, 360), GetIndicatorBounds(display_1_id)); |
| 142 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 143 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 144 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 145 | EXPECT_EQ(gfx::Rect(0, 0, 1, 360), GetIndicatorBounds(display_0_id)); |
| 146 | EXPECT_EQ(gfx::Rect(-1, 16, 1, 344), GetIndicatorBounds(display_1_id)); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 147 | |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 148 | layout->placement_list[0].offset = 250; |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 149 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 150 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 151 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 152 | EXPECT_EQ(gfx::Rect(0, 250, 1, 110), GetIndicatorBounds(display_0_id)); |
| 153 | EXPECT_EQ(gfx::Rect(-1, 250, 1, 110), GetIndicatorBounds(display_1_id)); |
| 154 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 155 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 156 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 157 | EXPECT_EQ(gfx::Rect(0, 250, 1, 110), GetIndicatorBounds(display_0_id)); |
| 158 | EXPECT_EQ(gfx::Rect(-1, 250, 1, 110), GetIndicatorBounds(display_1_id)); |
| 159 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 160 | event_filter()->HideSharedEdgeIndicator(); |
| 161 | } |
| 162 | |
| 163 | TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestOnTopBottom) { |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 164 | UpdateDisplay("360x360,700x700"); |
| 165 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 166 | int64_t display_0_id = display::Screen::GetScreen() |
| 167 | ->GetDisplayNearestWindow(root_windows[0]) |
| 168 | .id(); |
| 169 | int64_t display_1_id = display::Screen::GetScreen() |
| 170 | ->GetDisplayNearestWindow(root_windows[1]) |
| 171 | .id(); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 172 | |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 173 | std::unique_ptr<display::DisplayLayout> layout( |
| 174 | display::test::CreateDisplayLayout(display_manager(), |
| 175 | display::DisplayPlacement::TOP, 0)); |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 176 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 177 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 178 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 179 | EXPECT_EQ(gfx::Rect(0, 0, 360, 1), GetIndicatorBounds(display_0_id)); |
| 180 | EXPECT_EQ(gfx::Rect(0, -1, 360, 1), GetIndicatorBounds(display_1_id)); |
| 181 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 182 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 183 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 184 | EXPECT_EQ(gfx::Rect(0, 0, 360, 1), GetIndicatorBounds(display_0_id)); |
| 185 | EXPECT_EQ(gfx::Rect(0, -1, 360, 1), GetIndicatorBounds(display_1_id)); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 186 | |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 187 | layout->placement_list[0].offset = 250; |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 188 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 189 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 190 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 191 | EXPECT_EQ(gfx::Rect(250, 0, 110, 1), GetIndicatorBounds(display_0_id)); |
| 192 | EXPECT_EQ(gfx::Rect(250, -1, 110, 1), GetIndicatorBounds(display_1_id)); |
| 193 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 194 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 195 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 196 | EXPECT_EQ(gfx::Rect(250, 0, 110, 1), GetIndicatorBounds(display_0_id)); |
| 197 | EXPECT_EQ(gfx::Rect(250, -1, 110, 1), GetIndicatorBounds(display_1_id)); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 198 | |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 199 | layout->placement_list[0].position = display::DisplayPlacement::BOTTOM; |
robliao | df37203 | 2016-03-23 00:42:34 | [diff] [blame] | 200 | layout->placement_list[0].offset = 0; |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 201 | display_manager()->SetLayoutForCurrentDisplays(layout->Copy()); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 202 | event_filter()->ShowSharedEdgeIndicator(root_windows[0] /* primary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 203 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 204 | EXPECT_EQ(gfx::Rect(0, 359, 360, 1), GetIndicatorBounds(display_0_id)); |
| 205 | EXPECT_EQ(gfx::Rect(0, 360, 360, 1), GetIndicatorBounds(display_1_id)); |
| 206 | |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 207 | event_filter()->ShowSharedEdgeIndicator(root_windows[1] /* secondary */); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 208 | ASSERT_EQ(1U, GetWarpRegionsCount()); |
| 209 | EXPECT_EQ(gfx::Rect(0, 359, 360, 1), GetIndicatorBounds(display_0_id)); |
| 210 | EXPECT_EQ(gfx::Rect(0, 360, 360, 1), GetIndicatorBounds(display_1_id)); |
jdufault | fb0a4212 | 2016-01-21 21:40:41 | [diff] [blame] | 211 | |
| 212 | event_filter()->HideSharedEdgeIndicator(); |
| 213 | } |
| 214 | |
| 215 | // Verify indicators show up as expected with 3+ displays. |
| 216 | TEST_F(ExtendedMouseWarpControllerTest, IndicatorBoundsTestThreeDisplays) { |
jdufault | fb0a4212 | 2016-01-21 21:40:41 | [diff] [blame] | 217 | UpdateDisplay("360x360,700x700,1000x1000"); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 218 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 219 | display::Screen* screen = display::Screen::GetScreen(); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 220 | int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); |
| 221 | int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); |
| 222 | int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); |
jdufault | fb0a4212 | 2016-01-21 21:40:41 | [diff] [blame] | 223 | |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 224 | // Drag from left most display |
| 225 | event_filter()->ShowSharedEdgeIndicator(root_windows[0]); |
| 226 | ASSERT_EQ(2U, GetWarpRegionsCount()); |
| 227 | const ExtendedMouseWarpController::WarpRegion* region_0 = GetWarpRegion(0); |
| 228 | const ExtendedMouseWarpController::WarpRegion* region_1 = GetWarpRegion(1); |
| 229 | EXPECT_EQ(gfx::Rect(359, 16, 1, 344), |
| 230 | region_1->GetIndicatorBoundsForTest(display_0_id)); |
| 231 | EXPECT_EQ(gfx::Rect(360, 0, 1, 360), |
| 232 | region_1->GetIndicatorBoundsForTest(display_1_id)); |
| 233 | EXPECT_EQ(gfx::Rect(1059, 0, 1, 700), |
| 234 | region_0->GetIndicatorBoundsForTest(display_1_id)); |
| 235 | EXPECT_EQ(gfx::Rect(1060, 0, 1, 700), |
| 236 | region_0->GetIndicatorBoundsForTest(display_2_id)); |
| 237 | |
| 238 | // Drag from middle display |
| 239 | event_filter()->ShowSharedEdgeIndicator(root_windows[1]); |
| 240 | ASSERT_EQ(2U, mouse_warp_controller()->warp_regions_.size()); |
| 241 | region_0 = GetWarpRegion(0); |
| 242 | region_1 = GetWarpRegion(1); |
| 243 | EXPECT_EQ(gfx::Rect(359, 0, 1, 360), |
| 244 | region_1->GetIndicatorBoundsForTest(display_0_id)); |
| 245 | EXPECT_EQ(gfx::Rect(360, 16, 1, 344), |
| 246 | region_1->GetIndicatorBoundsForTest(display_1_id)); |
| 247 | EXPECT_EQ(gfx::Rect(1059, 16, 1, 684), |
| 248 | region_0->GetIndicatorBoundsForTest(display_1_id)); |
| 249 | EXPECT_EQ(gfx::Rect(1060, 0, 1, 700), |
| 250 | region_0->GetIndicatorBoundsForTest(display_2_id)); |
| 251 | |
| 252 | // Right most display |
| 253 | event_filter()->ShowSharedEdgeIndicator(root_windows[2]); |
| 254 | ASSERT_EQ(2U, mouse_warp_controller()->warp_regions_.size()); |
| 255 | region_0 = GetWarpRegion(0); |
| 256 | region_1 = GetWarpRegion(1); |
| 257 | EXPECT_EQ(gfx::Rect(359, 0, 1, 360), |
| 258 | region_1->GetIndicatorBoundsForTest(display_0_id)); |
| 259 | EXPECT_EQ(gfx::Rect(360, 0, 1, 360), |
| 260 | region_1->GetIndicatorBoundsForTest(display_1_id)); |
| 261 | EXPECT_EQ(gfx::Rect(1059, 0, 1, 700), |
| 262 | region_0->GetIndicatorBoundsForTest(display_1_id)); |
| 263 | EXPECT_EQ(gfx::Rect(1060, 16, 1, 684), |
| 264 | region_0->GetIndicatorBoundsForTest(display_2_id)); |
| 265 | event_filter()->HideSharedEdgeIndicator(); |
| 266 | // TODO(oshima): Add test cases primary swap. |
| 267 | } |
| 268 | |
| 269 | TEST_F(ExtendedMouseWarpControllerTest, |
| 270 | IndicatorBoundsTestThreeDisplaysWithLayout) { |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 271 | UpdateDisplay("700x500,500x500,1000x1000"); |
| 272 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 273 | display::Screen* screen = display::Screen::GetScreen(); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 274 | int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); |
| 275 | int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); |
| 276 | int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); |
| 277 | |
| 278 | // Layout so that all displays touches togter like this: |
| 279 | // +-----+---+ |
| 280 | // | 0 | 1 | |
| 281 | // +-+---+--++ |
| 282 | // | 2 | |
| 283 | // +------+ |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 284 | display::DisplayLayoutBuilder builder(display_0_id); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 285 | builder.AddDisplayPlacement(display_1_id, display_0_id, |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 286 | display::DisplayPlacement::RIGHT, 0); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 287 | builder.AddDisplayPlacement(display_2_id, display_0_id, |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 288 | display::DisplayPlacement::BOTTOM, 100); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 289 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 290 | display_manager()->SetLayoutForCurrentDisplays(builder.Build()); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 291 | ASSERT_EQ(3U, GetWarpRegionsCount()); |
| 292 | |
| 293 | // Drag from 0. |
| 294 | event_filter()->ShowSharedEdgeIndicator(root_windows[0]); |
| 295 | ASSERT_EQ(3U, GetWarpRegionsCount()); |
| 296 | const ExtendedMouseWarpController::WarpRegion* region_0 = GetWarpRegion(0); |
| 297 | const ExtendedMouseWarpController::WarpRegion* region_1 = GetWarpRegion(1); |
| 298 | const ExtendedMouseWarpController::WarpRegion* region_2 = GetWarpRegion(2); |
| 299 | // between 2 and 0 |
| 300 | EXPECT_EQ(gfx::Rect(100, 499, 600, 1), |
| 301 | region_0->GetIndicatorBoundsForTest(display_0_id)); |
| 302 | EXPECT_EQ(gfx::Rect(100, 500, 600, 1), |
| 303 | region_0->GetIndicatorBoundsForTest(display_2_id)); |
| 304 | // between 2 and 1 |
| 305 | EXPECT_EQ(gfx::Rect(700, 499, 400, 1), |
| 306 | region_1->GetIndicatorBoundsForTest(display_1_id)); |
| 307 | EXPECT_EQ(gfx::Rect(700, 500, 400, 1), |
| 308 | region_1->GetIndicatorBoundsForTest(display_2_id)); |
| 309 | // between 1 and 0 |
| 310 | EXPECT_EQ(gfx::Rect(699, 16, 1, 484), |
| 311 | region_2->GetIndicatorBoundsForTest(display_0_id)); |
| 312 | EXPECT_EQ(gfx::Rect(700, 0, 1, 500), |
| 313 | region_2->GetIndicatorBoundsForTest(display_1_id)); |
| 314 | event_filter()->HideSharedEdgeIndicator(); |
| 315 | } |
| 316 | |
| 317 | TEST_F(ExtendedMouseWarpControllerTest, |
| 318 | IndicatorBoundsTestThreeDisplaysWithLayout2) { |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 319 | UpdateDisplay("700x500,500x500,1000x1000"); |
| 320 | aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
oshima | f84b0da72 | 2016-04-27 19:47:19 | [diff] [blame] | 321 | display::Screen* screen = display::Screen::GetScreen(); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 322 | int64_t display_0_id = screen->GetDisplayNearestWindow(root_windows[0]).id(); |
| 323 | int64_t display_1_id = screen->GetDisplayNearestWindow(root_windows[1]).id(); |
| 324 | int64_t display_2_id = screen->GetDisplayNearestWindow(root_windows[2]).id(); |
| 325 | |
| 326 | // Layout so that 0 and 1 displays are disconnected. |
| 327 | // +-----+ +---+ |
| 328 | // | 0 | |1 | |
| 329 | // +-+---+-+++ |
| 330 | // | 2 | |
| 331 | // +------+ |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 332 | display::DisplayLayoutBuilder builder(display_0_id); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 333 | builder.AddDisplayPlacement(display_2_id, display_0_id, |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 334 | display::DisplayPlacement::BOTTOM, 100); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 335 | builder.AddDisplayPlacement(display_1_id, display_2_id, |
robliao | c0dfd6b | 2016-04-07 21:33:56 | [diff] [blame] | 336 | display::DisplayPlacement::TOP, 800); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 337 | |
rjkroege | 980ccfd | 2016-10-06 18:00:24 | [diff] [blame] | 338 | display_manager()->SetLayoutForCurrentDisplays(builder.Build()); |
oshima | 77570cb | 2016-03-24 21:33:23 | [diff] [blame] | 339 | ASSERT_EQ(2U, GetWarpRegionsCount()); |
| 340 | |
| 341 | // Drag from 0. |
| 342 | event_filter()->ShowSharedEdgeIndicator(root_windows[0]); |
| 343 | ASSERT_EQ(2U, GetWarpRegionsCount()); |
| 344 | const ExtendedMouseWarpController::WarpRegion* region_0 = GetWarpRegion(0); |
| 345 | const ExtendedMouseWarpController::WarpRegion* region_1 = GetWarpRegion(1); |
| 346 | // between 2 and 0 |
| 347 | EXPECT_EQ(gfx::Rect(100, 499, 600, 1), |
| 348 | region_0->GetIndicatorBoundsForTest(display_0_id)); |
| 349 | EXPECT_EQ(gfx::Rect(100, 500, 600, 1), |
| 350 | region_0->GetIndicatorBoundsForTest(display_2_id)); |
| 351 | // between 2 and 1 |
| 352 | EXPECT_EQ(gfx::Rect(900, 499, 200, 1), |
| 353 | region_1->GetIndicatorBoundsForTest(display_1_id)); |
| 354 | EXPECT_EQ(gfx::Rect(900, 500, 200, 1), |
| 355 | region_1->GetIndicatorBoundsForTest(display_2_id)); |
| 356 | event_filter()->HideSharedEdgeIndicator(); |
oshima | 83e6f6f | 2015-04-24 00:30:28 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | } // namespace ash |