| 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" | 7 #include "ash/display/display_manager.h" |
| 8 #include "ash/display/window_tree_host_manager.h" | 8 #include "ash/display/window_tree_host_manager.h" |
| 9 #include "ash/screen_util.h" | |
| 10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/test/cursor_manager_test_api.h" | 11 #include "ash/test/cursor_manager_test_api.h" |
| 13 #include "ash/test/display_manager_test_api.h" | 12 #include "ash/test/display_manager_test_api.h" |
| 14 #include "ash/test/mirror_window_test_api.h" | 13 #include "ash/test/mirror_window_test_api.h" |
| 15 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 16 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 17 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 18 #include "ui/aura/test/test_window_delegate.h" | 17 #include "ui/aura/test/test_window_delegate.h" |
| 19 #include "ui/aura/test/test_windows.h" | 18 #include "ui/aura/test/test_windows.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 #define MAYBE_MirrorCursorRotate MirrorCursorRotate | 69 #define MAYBE_MirrorCursorRotate MirrorCursorRotate |
| 71 #define MAYBE_DockMode DockMode | 70 #define MAYBE_DockMode DockMode |
| 72 #define MAYBE_MirrorOnBoot MirrorOnBoot | 71 #define MAYBE_MirrorOnBoot MirrorOnBoot |
| 73 #endif | 72 #endif |
| 74 | 73 |
| 75 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorBasic) { | 74 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorBasic) { |
| 76 test::MirrorWindowTestApi test_api; | 75 test::MirrorWindowTestApi test_api; |
| 77 aura::test::TestWindowDelegate test_window_delegate; | 76 aura::test::TestWindowDelegate test_window_delegate; |
| 78 test_window_delegate.set_window_component(HTTOP); | 77 test_window_delegate.set_window_component(HTTOP); |
| 79 | 78 |
| 80 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 79 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); |
| 81 display_manager->SetMultiDisplayMode(DisplayManager::MIRRORING); | |
| 82 UpdateDisplay("400x400,400x400"); | 80 UpdateDisplay("400x400,400x400"); |
| 83 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); | 81 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 84 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | 82 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
| 85 &test_window_delegate, 0, gfx::Rect(50, 50, 100, 100), root)); | 83 &test_window_delegate, 0, gfx::Rect(50, 50, 100, 100), root)); |
| 86 window->Show(); | 84 window->Show(); |
| 87 window->SetName("foo"); | 85 window->SetName("foo"); |
| 88 | 86 |
| 89 EXPECT_TRUE(test_api.GetCursorWindow()); | 87 EXPECT_TRUE(test_api.GetCursorWindow()); |
| 90 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); | 88 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); |
| 91 | 89 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 117 test_api.GetCursorHotPointLocationInRootWindow().ToString()); | 115 test_api.GetCursorHotPointLocationInRootWindow().ToString()); |
| 118 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); | 116 EXPECT_EQ(ui::kCursorNull, test_api.GetCurrentCursorType()); |
| 119 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); | 117 EXPECT_TRUE(test_api.GetCursorWindow()->IsVisible()); |
| 120 } | 118 } |
| 121 | 119 |
| 122 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorRotate) { | 120 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorRotate) { |
| 123 test::MirrorWindowTestApi test_api; | 121 test::MirrorWindowTestApi test_api; |
| 124 aura::test::TestWindowDelegate test_window_delegate; | 122 aura::test::TestWindowDelegate test_window_delegate; |
| 125 test_window_delegate.set_window_component(HTTOP); | 123 test_window_delegate.set_window_component(HTTOP); |
| 126 | 124 |
| 127 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 125 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); |
| 128 display_manager->SetMultiDisplayMode(DisplayManager::MIRRORING); | |
| 129 UpdateDisplay("400x400,400x400"); | 126 UpdateDisplay("400x400,400x400"); |
| 130 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); | 127 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 131 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | 128 std::unique_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( |
| 132 &test_window_delegate, 0, gfx::Rect(50, 50, 100, 100), root)); | 129 &test_window_delegate, 0, gfx::Rect(50, 50, 100, 100), root)); |
| 133 window->Show(); | 130 window->Show(); |
| 134 window->SetName("foo"); | 131 window->SetName("foo"); |
| 135 | 132 |
| 136 EXPECT_TRUE(test_api.GetCursorWindow()); | 133 EXPECT_TRUE(test_api.GetCursorWindow()); |
| 137 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); | 134 EXPECT_EQ("50,50 100x100", window->bounds().ToString()); |
| 138 | 135 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 169 EXPECT_EQ("12,14", test_api.GetCursorHotPoint().ToString()); | 166 EXPECT_EQ("12,14", test_api.GetCursorHotPoint().ToString()); |
| 170 EXPECT_EQ("100,300", | 167 EXPECT_EQ("100,300", |
| 171 test_api.GetCursorHotPointLocationInRootWindow().ToString()); | 168 test_api.GetCursorHotPointLocationInRootWindow().ToString()); |
| 172 } | 169 } |
| 173 | 170 |
| 174 // Make sure that the mirror cursor's location is same as | 171 // Make sure that the mirror cursor's location is same as |
| 175 // 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 |
| 176 // coordinates. | 173 // coordinates. |
| 177 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorLocations) { | 174 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorLocations) { |
| 178 test::MirrorWindowTestApi test_api; | 175 test::MirrorWindowTestApi test_api; |
| 179 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 176 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); |
| 180 display_manager->SetMultiDisplayMode(DisplayManager::MIRRORING); | |
| 181 | 177 |
| 182 // Test with device scale factor. | 178 // Test with device scale factor. |
| 183 UpdateDisplay("400x600*2,400x600"); | 179 UpdateDisplay("400x600*2,400x600"); |
| 184 | 180 |
| 185 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); | 181 aura::Window* root = Shell::GetInstance()->GetPrimaryRootWindow(); |
| 186 ui::test::EventGenerator generator(root); | 182 ui::test::EventGenerator generator(root); |
| 187 generator.MoveMouseToInHost(10, 20); | 183 generator.MoveMouseToInHost(10, 20); |
| 188 | 184 |
| 189 EXPECT_EQ("7,7", test_api.GetCursorHotPoint().ToString()); | 185 EXPECT_EQ("7,7", test_api.GetCursorHotPoint().ToString()); |
| 190 EXPECT_EQ("10,20", | 186 EXPECT_EQ("10,20", |
| (...skipping 19 matching lines...) Expand all Loading... |
| 210 // Test the behavior of the cursor when entering software mirror mode swaps the | 206 // Test the behavior of the cursor when entering software mirror mode swaps the |
| 211 // cursor's display. | 207 // cursor's display. |
| 212 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorMoveOnEnter) { | 208 TEST_F(MirrorWindowControllerTest, MAYBE_MirrorCursorMoveOnEnter) { |
| 213 aura::Env* env = aura::Env::GetInstance(); | 209 aura::Env* env = aura::Env::GetInstance(); |
| 214 Shell* shell = Shell::GetInstance(); | 210 Shell* shell = Shell::GetInstance(); |
| 215 WindowTreeHostManager* window_tree_host_manager = | 211 WindowTreeHostManager* window_tree_host_manager = |
| 216 shell->window_tree_host_manager(); | 212 shell->window_tree_host_manager(); |
| 217 | 213 |
| 218 UpdateDisplay("400x400*2/r,400x400"); | 214 UpdateDisplay("400x400*2/r,400x400"); |
| 219 int64_t primary_display_id = window_tree_host_manager->GetPrimaryDisplayId(); | 215 int64_t primary_display_id = window_tree_host_manager->GetPrimaryDisplayId(); |
| 220 int64_t secondary_display_id = ScreenUtil::GetSecondaryDisplay().id(); | 216 int64_t secondary_display_id = display_manager()->GetSecondaryDisplay().id(); |
| 221 test::ScopedSetInternalDisplayId set_internal(primary_display_id); | 217 test::ScopedSetInternalDisplayId set_internal(display_manager(), |
| 218 primary_display_id); |
| 222 | 219 |
| 223 // 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 |
| 224 // mode. Move the cursor to the external display. | 221 // mode. Move the cursor to the external display. |
| 225 aura::Window* secondary_root_window = | 222 aura::Window* secondary_root_window = |
| 226 window_tree_host_manager->GetRootWindowForDisplayId(secondary_display_id); | 223 window_tree_host_manager->GetRootWindowForDisplayId(secondary_display_id); |
| 227 secondary_root_window->MoveCursorTo(gfx::Point(100, 200)); | 224 secondary_root_window->MoveCursorTo(gfx::Point(100, 200)); |
| 228 EXPECT_EQ("300,200", env->last_mouse_location().ToString()); | 225 EXPECT_EQ("300,200", env->last_mouse_location().ToString()); |
| 229 test::CursorManagerTestApi cursor_test_api(shell->cursor_manager()); | 226 test::CursorManagerTestApi cursor_test_api(shell->cursor_manager()); |
| 230 EXPECT_EQ(1.0f, cursor_test_api.GetCurrentCursor().device_scale_factor()); | 227 EXPECT_EQ(1.0f, cursor_test_api.GetCurrentCursor().device_scale_factor()); |
| 231 EXPECT_EQ(display::Display::ROTATE_0, | 228 EXPECT_EQ(display::Display::ROTATE_0, |
| 232 cursor_test_api.GetCurrentCursorRotation()); | 229 cursor_test_api.GetCurrentCursorRotation()); |
| 233 | 230 |
| 234 shell->display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); | 231 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); |
| 235 UpdateDisplay("400x400*2/r,400x400"); | 232 UpdateDisplay("400x400*2/r,400x400"); |
| 236 | 233 |
| 237 // 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 |
| 238 // because the cursor's previous position is out of bounds. | 235 // because the cursor's previous position is out of bounds. |
| 239 // Check real cursor's position and properties. | 236 // Check real cursor's position and properties. |
| 240 EXPECT_EQ("100,100", env->last_mouse_location().ToString()); | 237 EXPECT_EQ("100,100", env->last_mouse_location().ToString()); |
| 241 EXPECT_EQ(2.0f, cursor_test_api.GetCurrentCursor().device_scale_factor()); | 238 EXPECT_EQ(2.0f, cursor_test_api.GetCurrentCursor().device_scale_factor()); |
| 242 EXPECT_EQ(display::Display::ROTATE_90, | 239 EXPECT_EQ(display::Display::ROTATE_90, |
| 243 cursor_test_api.GetCurrentCursorRotation()); | 240 cursor_test_api.GetCurrentCursorRotation()); |
| 244 | 241 |
| 245 // Check mirrored cursor's location. | 242 // Check mirrored cursor's location. |
| 246 test::MirrorWindowTestApi test_api; | 243 test::MirrorWindowTestApi test_api; |
| 247 // Rotated hot point must be (25-7, 7). | 244 // Rotated hot point must be (25-7, 7). |
| 248 EXPECT_EQ("18,7", test_api.GetCursorHotPoint().ToString()); | 245 EXPECT_EQ("18,7", test_api.GetCursorHotPoint().ToString()); |
| 249 // New coordinates are not (200,200) because (200,200) is not the center of | 246 // New coordinates are not (200,200) because (200,200) is not the center of |
| 250 // the display. | 247 // the display. |
| 251 EXPECT_EQ("199,200", | 248 EXPECT_EQ("199,200", |
| 252 test_api.GetCursorHotPointLocationInRootWindow().ToString()); | 249 test_api.GetCursorHotPointLocationInRootWindow().ToString()); |
| 253 } | 250 } |
| 254 | 251 |
| 255 // Make sure that the compositor based mirroring can switch | 252 // Make sure that the compositor based mirroring can switch |
| 256 // from/to dock mode. | 253 // from/to dock mode. |
| 257 TEST_F(MirrorWindowControllerTest, MAYBE_DockMode) { | 254 TEST_F(MirrorWindowControllerTest, MAYBE_DockMode) { |
| 258 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 259 const int64_t internal_id = 1; | 255 const int64_t internal_id = 1; |
| 260 const int64_t external_id = 2; | 256 const int64_t external_id = 2; |
| 261 | 257 |
| 262 const display::ManagedDisplayInfo internal_display_info = | 258 const display::ManagedDisplayInfo internal_display_info = |
| 263 CreateDisplayInfo(internal_id, gfx::Rect(0, 0, 500, 500)); | 259 CreateDisplayInfo(internal_id, gfx::Rect(0, 0, 500, 500)); |
| 264 const display::ManagedDisplayInfo external_display_info = | 260 const display::ManagedDisplayInfo external_display_info = |
| 265 CreateDisplayInfo(external_id, gfx::Rect(1, 1, 100, 100)); | 261 CreateDisplayInfo(external_id, gfx::Rect(1, 1, 100, 100)); |
| 266 std::vector<display::ManagedDisplayInfo> display_info_list; | 262 std::vector<display::ManagedDisplayInfo> display_info_list; |
| 267 | 263 |
| 268 display_manager->SetMultiDisplayMode(DisplayManager::MIRRORING); | 264 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); |
| 269 | 265 |
| 270 // software mirroring. | 266 // software mirroring. |
| 271 display_info_list.push_back(internal_display_info); | 267 display_info_list.push_back(internal_display_info); |
| 272 display_info_list.push_back(external_display_info); | 268 display_info_list.push_back(external_display_info); |
| 273 display_manager->OnNativeDisplaysChanged(display_info_list); | 269 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 274 const int64_t internal_display_id = | 270 const int64_t internal_display_id = |
| 275 test::DisplayManagerTestApi().SetFirstDisplayAsInternalDisplay(); | 271 test::DisplayManagerTestApi(display_manager()) |
| 272 .SetFirstDisplayAsInternalDisplay(); |
| 276 EXPECT_EQ(internal_id, internal_display_id); | 273 EXPECT_EQ(internal_id, internal_display_id); |
| 277 | 274 |
| 278 EXPECT_EQ(1U, display_manager->GetNumDisplays()); | 275 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 279 EXPECT_TRUE(display_manager->IsInMirrorMode()); | 276 EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
| 280 EXPECT_EQ(external_id, display_manager->mirroring_display_id()); | 277 EXPECT_EQ(external_id, display_manager()->mirroring_display_id()); |
| 281 | 278 |
| 282 // dock mode. | 279 // dock mode. |
| 283 display_info_list.clear(); | 280 display_info_list.clear(); |
| 284 display_info_list.push_back(external_display_info); | 281 display_info_list.push_back(external_display_info); |
| 285 display_manager->SetMultiDisplayMode(DisplayManager::MIRRORING); | 282 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); |
| 286 display_manager->OnNativeDisplaysChanged(display_info_list); | 283 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 287 EXPECT_EQ(1U, display_manager->GetNumDisplays()); | 284 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 288 EXPECT_FALSE(display_manager->IsInMirrorMode()); | 285 EXPECT_FALSE(display_manager()->IsInMirrorMode()); |
| 289 | 286 |
| 290 // back to software mirroring. | 287 // back to software mirroring. |
| 291 display_info_list.clear(); | 288 display_info_list.clear(); |
| 292 display_info_list.push_back(internal_display_info); | 289 display_info_list.push_back(internal_display_info); |
| 293 display_info_list.push_back(external_display_info); | 290 display_info_list.push_back(external_display_info); |
| 294 display_manager->SetMultiDisplayMode(DisplayManager::MIRRORING); | 291 display_manager()->SetMultiDisplayMode(DisplayManager::MIRRORING); |
| 295 display_manager->OnNativeDisplaysChanged(display_info_list); | 292 display_manager()->OnNativeDisplaysChanged(display_info_list); |
| 296 EXPECT_EQ(1U, display_manager->GetNumDisplays()); | 293 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); |
| 297 EXPECT_TRUE(display_manager->IsInMirrorMode()); | 294 EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
| 298 EXPECT_EQ(external_id, display_manager->mirroring_display_id()); | 295 EXPECT_EQ(external_id, display_manager()->mirroring_display_id()); |
| 299 } | 296 } |
| 300 | 297 |
| 301 TEST_F(MirrorOnBootTest, MAYBE_MirrorOnBoot) { | 298 TEST_F(MirrorOnBootTest, MAYBE_MirrorOnBoot) { |
| 302 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 299 EXPECT_TRUE(display_manager()->IsInMirrorMode()); |
| 303 EXPECT_TRUE(display_manager->IsInMirrorMode()); | |
| 304 RunAllPendingInMessageLoop(); | 300 RunAllPendingInMessageLoop(); |
| 305 test::MirrorWindowTestApi test_api; | 301 test::MirrorWindowTestApi test_api; |
| 306 EXPECT_TRUE(test_api.GetHost()); | 302 EXPECT_TRUE(test_api.GetHost()); |
| 307 } | 303 } |
| 308 | 304 |
| 309 } // namespace ash | 305 } // namespace ash |
| OLD | NEW |