OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/mirror_window_controller.h" | 5 #include "ash/display/mirror_window_controller.h" |
6 | 6 |
7 #include "ash/display/display_manager.h" | |
8 #include "ash/display/window_tree_host_manager.h" | 7 #include "ash/display/window_tree_host_manager.h" |
9 #include "ash/shell.h" | 8 #include "ash/shell.h" |
10 #include "ash/test/ash_test_base.h" | 9 #include "ash/test/ash_test_base.h" |
11 #include "ash/test/cursor_manager_test_api.h" | 10 #include "ash/test/cursor_manager_test_api.h" |
12 #include "ash/test/display_manager_test_api.h" | |
13 #include "ash/test/mirror_window_test_api.h" | 11 #include "ash/test/mirror_window_test_api.h" |
14 #include "base/command_line.h" | 12 #include "base/command_line.h" |
15 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
16 #include "ui/aura/env.h" | 14 #include "ui/aura/env.h" |
17 #include "ui/aura/test/test_window_delegate.h" | 15 #include "ui/aura/test/test_window_delegate.h" |
18 #include "ui/aura/test/test_windows.h" | 16 #include "ui/aura/test/test_windows.h" |
19 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
20 #include "ui/aura/window_event_dispatcher.h" | 18 #include "ui/aura/window_event_dispatcher.h" |
21 #include "ui/base/hit_test.h" | 19 #include "ui/base/hit_test.h" |
22 #include "ui/display/display_switches.h" | 20 #include "ui/display/display_switches.h" |
| 21 #include "ui/display/manager/display_manager.h" |
| 22 #include "ui/display/test/display_manager_test_api.h" |
23 #include "ui/events/test/event_generator.h" | 23 #include "ui/events/test/event_generator.h" |
24 | 24 |
25 namespace ash { | 25 namespace ash { |
26 | 26 |
27 namespace { | 27 namespace { |
28 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id, | 28 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id, |
29 const gfx::Rect& bounds) { | 29 const gfx::Rect& bounds) { |
30 display::ManagedDisplayInfo info( | 30 display::ManagedDisplayInfo info( |
31 id, base::StringPrintf("x-%d", static_cast<int>(id)), false); | 31 id, base::StringPrintf("x-%d", static_cast<int>(id)), false); |
32 info.SetBounds(bounds); | 32 info.SetBounds(bounds); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #define MAYBE_MirrorCursorRotate MirrorCursorRotate | 69 #define MAYBE_MirrorCursorRotate MirrorCursorRotate |
70 #define MAYBE_DockMode DockMode | 70 #define MAYBE_DockMode DockMode |
71 #define MAYBE_MirrorOnBoot MirrorOnBoot | 71 #define MAYBE_MirrorOnBoot MirrorOnBoot |
72 #endif | 72 #endif |
73 | 73 |
74 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorBasic) { | 74 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorBasic) { |
75 test::MirrorWindowTestApi test_api; | 75 test::MirrorWindowTestApi test_api; |
76 aura::test::TestWindowDelegate test_window_delegate; | 76 aura::test::TestWindowDelegate test_window_delegate; |
77 test_window_delegate.set_window_component(HTTOP); | 77 test_window_delegate.set_window_component(HTTOP); |
78 | 78 |
79 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); | 79 display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING); |
80 UpdateDisplay("400x400,400x400"); | 80 UpdateDisplay("400x400,400x400"); |
81 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); | 81 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
82 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | 82 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
83 &test_window_delegate, 0, gfx::Rect(50, 50, 100, 100), root)); | 83 &test_window_delegate, 0, gfx::Rect(50, 50, 100, 100), root)); |
84 window->Show(); | 84 window->Show(); |
85 window->SetName("foo"); | 85 window->SetName("foo"); |
86 | 86 |
87 EXPECT_TRUE(test_api.GetCursorWindow()); | 87 EXPECT_TRUE(test_api.GetCursorWindow()); |
88 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); | 88 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); |
89 | 89 |
(...skipping 25 matching lines...) Expand all Loading... |
115 test_api.GetCursorHotPointLocationInRootWindow().ToString()); | 115 test_api.GetCursorHotPointLocationInRootWindow().ToString()); |
116 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); | 116 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); |
117 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); | 117 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); |
118 } | 118 } |
119 | 119 |
120 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorRotate) { | 120 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorRotate) { |
121 test::MirrorWindowTestApi test_api; | 121 test::MirrorWindowTestApi test_api; |
122 aura::test::TestWindowDelegate test_window_delegate; | 122 aura::test::TestWindowDelegate test_window_delegate; |
123 test_window_delegate.set_window_component(HTTOP); | 123 test_window_delegate.set_window_component(HTTOP); |
124 | 124 |
125 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); | 125 display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING); |
126 UpdateDisplay("400x400,400x400"); | 126 UpdateDisplay("400x400,400x400"); |
127 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); | 127 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
128 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | 128 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
129 &test_window_delegate, 0, gfx::Rect(50, 50, 100, 100), root)); | 129 &test_window_delegate, 0, gfx::Rect(50, 50, 100, 100), root)); |
130 window->Show(); | 130 window->Show(); |
131 window->SetName("foo"); | 131 window->SetName("foo"); |
132 | 132 |
133 EXPECT_TRUE(test_api.GetCursorWindow()); | 133 EXPECT_TRUE(test_api.GetCursorWindow()); |
134 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); | 134 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); |
135 | 135 |
(...skipping 30 matching lines...) Expand all Loading... |
166 EXPECT_EQ("12,14", test_api.GetCursorHotPoint().ToString()); | 166 EXPECT_EQ("12,14", test_api.GetCursorHotPoint().ToString()); |
167 EXPECT_EQ("100,300", | 167 EXPECT_EQ("100,300", |
168 test_api.GetCursorHotPointLocationInRootWindow().ToString()); | 168 test_api.GetCursorHotPointLocationInRootWindow().ToString()); |
169 } | 169 } |
170 | 170 |
171 // Make sure that the mirror cursor's location is same as | 171 // Make sure that the mirror cursor's location is same as |
172 // the source display's host location in the mirror root window's | 172 // the source display's host location in the mirror root window's |
173 // coordinates. | 173 // coordinates. |
174 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorLocations) { | 174 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorLocations) { |
175 test::MirrorWindowTestApi test_api; | 175 test::MirrorWindowTestApi test_api; |
176 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); | 176 display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING); |
177 | 177 |
178 // Test with device scale factor. | 178 // Test with device scale factor. |
179 UpdateDisplay("400x600*2,400x600"); | 179 UpdateDisplay("400x600*2,400x600"); |
180 | 180 |
181 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); | 181 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
182 ui::test::EventGenerator generator(root); | 182 ui::test::EventGenerator generator(root); |
183 generator.MoveMouseToInHost(10, 20); | 183 generator.MoveMouseToInHost(10, 20); |
184 | 184 |
185 EXPECT_EQ("7,7", test_api.GetCursorHotPoint().ToString()); | 185 EXPECT_EQ("7,7", test_api.GetCursorHotPoint().ToString()); |
186 EXPECT_EQ("10,20", | 186 EXPECT_EQ("10,20", |
(...skipping 20 matching lines...) Expand all Loading... |
207 // cursor's display. | 207 // cursor's display. |
208 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorMoveOnEnter) { | 208 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorMoveOnEnter) { |
209 aura::Env* env = aura::Env::GetInstance(); | 209 aura::Env* env = aura::Env::GetInstance(); |
210 Shell* shell = Shell::GetInstance(); | 210 Shell* shell = Shell::GetInstance(); |
211 WindowTreeHostManager* window_tree_host_manager = | 211 WindowTreeHostManager* window_tree_host_manager = |
212 shell->window_tree_host_manager(); | 212 shell->window_tree_host_manager(); |
213 | 213 |
214 UpdateDisplay("400x400*2/r,400x400"); | 214 UpdateDisplay("400x400*2/r,400x400"); |
215 int64_t primary_display_id = window_tree_host_manager->GetPrimaryDisplayId(); | 215 int64_t primary_display_id = window_tree_host_manager->GetPrimaryDisplayId(); |
216 int64_t secondary_display_id = display_manager()->GetSecondaryDisplay().id(); | 216 int64_t secondary_display_id = display_manager()->GetSecondaryDisplay().id(); |
217 test::ScopedSetInternalDisplayId set_internal(display_manager(), | 217 display::test::ScopedSetInternalDisplayId set_internal(display_manager(), |
218 primary_display_id); | 218 primary_display_id); |
219 | 219 |
220 // Chrome uses the internal display as the source display for software mirror | 220 // Chrome uses the internal display as the source display for software mirror |
221 // mode. Move the cursor to the external display. | 221 // mode. Move the cursor to the external display. |
222 aura::Window* secondary_root_window = | 222 aura::Window* secondary_root_window = |
223 window_tree_host_manager->GetRootWindowForDisplayId(secondary_display_id); | 223 window_tree_host_manager->GetRootWindowForDisplayId(secondary_display_id); |
224 secondary_root_window->MoveCursorTo(gfx::Point(100, 200)); | 224 secondary_root_window->MoveCursorTo(gfx::Point(100, 200)); |
225 EXPECT_EQ("300,200", env->last_mouse_location().ToString()); | 225 EXPECT_EQ("300,200", env->last_mouse_location().ToString()); |
226 test::CursorManagerTestApi cursor_test_api(shell->cursor_manager()); | 226 test::CursorManagerTestApi cursor_test_api(shell->cursor_manager()); |
227 EXPECT_EQ(1.0f, cursor_test_api.GetCurrentCursor().device_scale_factor()); | 227 EXPECT_EQ(1.0f, cursor_test_api.GetCurrentCursor().device_scale_factor()); |
228 EXPECT_EQ(display::Display::ROTATE_0, | 228 EXPECT_EQ(display::Display::ROTATE_0, |
229 cursor_test_api.GetCurrentCursorRotation()); | 229 cursor_test_api.GetCurrentCursorRotation()); |
230 | 230 |
231 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); | 231 display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING); |
232 UpdateDisplay("400x400*2/r,400x400"); | 232 UpdateDisplay("400x400*2/r,400x400"); |
233 | 233 |
234 // Entering mirror mode should have centered the cursor on the primary display | 234 // Entering mirror mode should have centered the cursor on the primary display |
235 // because the cursor's previous position is out of bounds. | 235 // because the cursor's previous position is out of bounds. |
236 // Check real cursor's position and properties. | 236 // Check real cursor's position and properties. |
237 EXPECT_EQ("100,100", env->last_mouse_location().ToString()); | 237 EXPECT_EQ("100,100", env->last_mouse_location().ToString()); |
238 EXPECT_EQ(2.0f, cursor_test_api.GetCurrentCursor().device_scale_factor()); | 238 EXPECT_EQ(2.0f, cursor_test_api.GetCurrentCursor().device_scale_factor()); |
239 EXPECT_EQ(display::Display::ROTATE_90, | 239 EXPECT_EQ(display::Display::ROTATE_90, |
240 cursor_test_api.GetCurrentCursorRotation()); | 240 cursor_test_api.GetCurrentCursorRotation()); |
241 | 241 |
(...skipping 14 matching lines...) Expand all Loading... |
256 TEST_F(MirrorWindowControllerTest, MAYBE_DockMode) { | 256 TEST_F(MirrorWindowControllerTest, MAYBE_DockMode) { |
257 const int64_t internal_id = 1; | 257 const int64_t internal_id = 1; |
258 const int64_t external_id = 2; | 258 const int64_t external_id = 2; |
259 | 259 |
260 const display::ManagedDisplayInfo internal_display_info = | 260 const display::ManagedDisplayInfo internal_display_info = |
261 CreateDisplayInfo(internal_id, gfx::Rect(0, 0, 500, 500)); | 261 CreateDisplayInfo(internal_id, gfx::Rect(0, 0, 500, 500)); |
262 const display::ManagedDisplayInfo external_display_info = | 262 const display::ManagedDisplayInfo external_display_info = |
263 CreateDisplayInfo(external_id, gfx::Rect(1, 1, 100, 100)); | 263 CreateDisplayInfo(external_id, gfx::Rect(1, 1, 100, 100)); |
264 std::vector<display::ManagedDisplayInfo> display_info_list; | 264 std::vector<display::ManagedDisplayInfo> display_info_list; |
265 | 265 |
266 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); | 266 display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING); |
267 | 267 |
268 // software mirroring. | 268 // software mirroring. |
269 display_info_list.push_back(internal_display_info); | 269 display_info_list.push_back(internal_display_info); |
270 display_info_list.push_back(external_display_info); | 270 display_info_list.push_back(external_display_info); |
271 display_manager()->OnNativeDisplaysChanged(display_info_list); | 271 display_manager()->OnNativeDisplaysChanged(display_info_list); |
272 const int64_t internal_display_id = | 272 const int64_t internal_display_id = |
273 test::DisplayManagerTestApi(display_manager()) | 273 display::test::DisplayManagerTestApi(display_manager()) |
274 .SetFirstDisplayAsInternalDisplay(); | 274 .SetFirstDisplayAsInternalDisplay(); |
275 EXPECT_EQ(internal_id, internal_display_id); | 275 EXPECT_EQ(internal_id, internal_display_id); |
276 | 276 |
277 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 277 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
278 EXPECT_TRUE(display_manager()->IsInMirrorMode()); | 278 EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
279 EXPECT_EQ(external_id, display_manager()->mirroring_display_id()); | 279 EXPECT_EQ(external_id, display_manager()->mirroring_display_id()); |
280 | 280 |
281 // dock mode. | 281 // dock mode. |
282 display_info_list.clear(); | 282 display_info_list.clear(); |
283 display_info_list.push_back(external_display_info); | 283 display_info_list.push_back(external_display_info); |
284 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); | 284 display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING); |
285 display_manager()->OnNativeDisplaysChanged(display_info_list); | 285 display_manager()->OnNativeDisplaysChanged(display_info_list); |
286 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 286 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
287 EXPECT_FALSE(display_manager()->IsInMirrorMode()); | 287 EXPECT_FALSE(display_manager()->IsInMirrorMode()); |
288 | 288 |
289 // back to software mirroring. | 289 // back to software mirroring. |
290 display_info_list.clear(); | 290 display_info_list.clear(); |
291 display_info_list.push_back(internal_display_info); | 291 display_info_list.push_back(internal_display_info); |
292 display_info_list.push_back(external_display_info); | 292 display_info_list.push_back(external_display_info); |
293 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); | 293 display_manager()->SetMultiDisplayMode(display::DisplayManager::MIRRORING); |
294 display_manager()->OnNativeDisplaysChanged(display_info_list); | 294 display_manager()->OnNativeDisplaysChanged(display_info_list); |
295 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | 295 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
296 EXPECT_TRUE(display_manager()->IsInMirrorMode()); | 296 EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
297 EXPECT_EQ(external_id, display_manager()->mirroring_display_id()); | 297 EXPECT_EQ(external_id, display_manager()->mirroring_display_id()); |
298 } | 298 } |
299 | 299 |
300 TEST_F(MirrorOnBootTest, MAYBE_MirrorOnBoot) { | 300 TEST_F(MirrorOnBootTest, MAYBE_MirrorOnBoot) { |
301 EXPECT_TRUE(display_manager()->IsInMirrorMode()); | 301 EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
302 RunAllPendingInMessageLoop(); | 302 RunAllPendingInMessageLoop(); |
303 test::MirrorWindowTestApi test_api; | 303 test::MirrorWindowTestApi test_api; |
304 EXPECT_TRUE(test_api.GetHost()); | 304 EXPECT_TRUE(test_api.GetHost()); |
305 } | 305 } |
306 | 306 |
307 } // namespace ash | 307 } // namespace ash |
OLD | NEW |