| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "ash/display/multi_display_manager.h" | |
| 6 | |
| 7 #include "ash/display/display_controller.h" | |
| 8 #include "ash/screen_ash.h" | |
| 9 #include "ash/shell.h" | |
| 10 #include "ash/test/ash_test_base.h" | |
| 11 #include "base/format_macros.h" | |
| 12 #include "base/stringprintf.h" | |
| 13 #include "ui/aura/display_observer.h" | |
| 14 #include "ui/aura/env.h" | |
| 15 #include "ui/aura/root_window.h" | |
| 16 #include "ui/aura/window_observer.h" | |
| 17 #include "ui/gfx/display.h" | |
| 18 | |
| 19 namespace ash { | |
| 20 namespace internal { | |
| 21 | |
| 22 using std::vector; | |
| 23 using std::string; | |
| 24 | |
| 25 class MultiDisplayManagerTest : public test::AshTestBase, | |
| 26 public aura::DisplayObserver, | |
| 27 public aura::WindowObserver { | |
| 28 public: | |
| 29 MultiDisplayManagerTest() | |
| 30 : removed_count_(0U), | |
| 31 root_window_destroyed_(false) { | |
| 32 } | |
| 33 virtual ~MultiDisplayManagerTest() {} | |
| 34 | |
| 35 virtual void SetUp() OVERRIDE { | |
| 36 AshTestBase::SetUp(); | |
| 37 display_manager()->AddObserver(this); | |
| 38 Shell::GetPrimaryRootWindow()->AddObserver(this); | |
| 39 } | |
| 40 virtual void TearDown() OVERRIDE { | |
| 41 Shell::GetPrimaryRootWindow()->RemoveObserver(this); | |
| 42 display_manager()->RemoveObserver(this); | |
| 43 AshTestBase::TearDown(); | |
| 44 } | |
| 45 | |
| 46 MultiDisplayManager* display_manager() { | |
| 47 return static_cast<MultiDisplayManager*>( | |
| 48 aura::Env::GetInstance()->display_manager()); | |
| 49 } | |
| 50 const vector<gfx::Display>& changed() const { return changed_; } | |
| 51 const vector<gfx::Display>& added() const { return added_; } | |
| 52 | |
| 53 string GetCountSummary() const { | |
| 54 return StringPrintf("%"PRIuS" %"PRIuS" %"PRIuS, | |
| 55 changed_.size(), added_.size(), removed_count_); | |
| 56 } | |
| 57 | |
| 58 void reset() { | |
| 59 changed_.clear(); | |
| 60 added_.clear(); | |
| 61 removed_count_ = 0U; | |
| 62 root_window_destroyed_ = false; | |
| 63 } | |
| 64 | |
| 65 bool root_window_destroyed() const { | |
| 66 return root_window_destroyed_; | |
| 67 } | |
| 68 | |
| 69 const gfx::Display& FindDisplayForId(int64 id) { | |
| 70 return display_manager()->FindDisplayForId(id); | |
| 71 } | |
| 72 | |
| 73 // aura::DisplayObserver overrides: | |
| 74 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { | |
| 75 changed_.push_back(display); | |
| 76 } | |
| 77 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE { | |
| 78 added_.push_back(new_display); | |
| 79 } | |
| 80 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { | |
| 81 ++removed_count_; | |
| 82 } | |
| 83 | |
| 84 // aura::WindowObserver overrides: | |
| 85 virtual void OnWindowDestroying(aura::Window* window) { | |
| 86 ASSERT_EQ(Shell::GetPrimaryRootWindow(), window); | |
| 87 root_window_destroyed_ = true; | |
| 88 } | |
| 89 | |
| 90 private: | |
| 91 vector<gfx::Display> changed_; | |
| 92 vector<gfx::Display> added_; | |
| 93 size_t removed_count_; | |
| 94 bool root_window_destroyed_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(MultiDisplayManagerTest); | |
| 97 }; | |
| 98 | |
| 99 #if defined(OS_CHROMEOS) | |
| 100 // TODO(oshima): This fails with non extended desktop on windows. | |
| 101 // Reenable when extended desktop is enabled by default. | |
| 102 #define MAYBE_NativeDisplayTest NativeDisplayTest | |
| 103 #define MAYBE_EmulatorTest EmulatorTest | |
| 104 #define MAYBE_OverscanInsetsTest OverscanInsetsTest | |
| 105 #define MAYBE_ZeroOverscanInsets ZeroOverscanInsets | |
| 106 #else | |
| 107 #define MAYBE_NativeDisplayTest DISABLED_NativeDisplayTest | |
| 108 #define MAYBE_EmulatorTest DISABLED_EmulatorTest | |
| 109 #define MAYBE_OverscanInsetsTest DISABLED_OverscanInsetsTest | |
| 110 #define MAYBE_ZeroOverscanInsets DISABLED_ZeroOverscanInsets | |
| 111 #endif | |
| 112 | |
| 113 TEST_F(MultiDisplayManagerTest, MAYBE_NativeDisplayTest) { | |
| 114 aura::DisplayManager::set_use_fullscreen_host_window(true); | |
| 115 | |
| 116 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 117 | |
| 118 // Update primary and add seconary. | |
| 119 UpdateDisplay("100+0-500x500,0+501-400x400"); | |
| 120 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 121 EXPECT_EQ("0,0 500x500", | |
| 122 display_manager()->GetDisplayAt(0)->bounds().ToString()); | |
| 123 | |
| 124 EXPECT_EQ("1 1 0", GetCountSummary()); | |
| 125 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); | |
| 126 EXPECT_EQ(display_manager()->GetDisplayAt(1)->id(), added()[0].id()); | |
| 127 EXPECT_EQ("0,0 500x500", changed()[0].bounds().ToString()); | |
| 128 // Secondary display is on right. | |
| 129 EXPECT_EQ("500,0 400x400", added()[0].bounds().ToString()); | |
| 130 EXPECT_EQ("0,501 400x400", added()[0].bounds_in_pixel().ToString()); | |
| 131 reset(); | |
| 132 | |
| 133 // Delete secondary. | |
| 134 UpdateDisplay("100+0-500x500"); | |
| 135 EXPECT_EQ("0 0 1", GetCountSummary()); | |
| 136 reset(); | |
| 137 | |
| 138 // Change primary. | |
| 139 UpdateDisplay("0+0-1000x600"); | |
| 140 EXPECT_EQ("1 0 0", GetCountSummary()); | |
| 141 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); | |
| 142 EXPECT_EQ("0,0 1000x600", changed()[0].bounds().ToString()); | |
| 143 reset(); | |
| 144 | |
| 145 // Add secondary. | |
| 146 UpdateDisplay("0+0-1000x600,1001+0-600x400"); | |
| 147 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 148 EXPECT_EQ("0 1 0", GetCountSummary()); | |
| 149 EXPECT_EQ(display_manager()->GetDisplayAt(1)->id(), added()[0].id()); | |
| 150 // Secondary display is on right. | |
| 151 EXPECT_EQ("1000,0 600x400", added()[0].bounds().ToString()); | |
| 152 EXPECT_EQ("1001,0 600x400", added()[0].bounds_in_pixel().ToString()); | |
| 153 reset(); | |
| 154 | |
| 155 // Secondary removed, primary changed. | |
| 156 UpdateDisplay("0+0-800x300"); | |
| 157 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 158 EXPECT_EQ("1 0 1", GetCountSummary()); | |
| 159 EXPECT_EQ(display_manager()->GetDisplayAt(0)->id(), changed()[0].id()); | |
| 160 EXPECT_EQ("0,0 800x300", changed()[0].bounds().ToString()); | |
| 161 reset(); | |
| 162 | |
| 163 // # of display can go to zero when screen is off. | |
| 164 const vector<gfx::Display> empty; | |
| 165 display_manager()->OnNativeDisplaysChanged(empty); | |
| 166 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 167 EXPECT_EQ("0 0 0", GetCountSummary()); | |
| 168 EXPECT_FALSE(root_window_destroyed()); | |
| 169 // Display configuration stays the same | |
| 170 EXPECT_EQ("0,0 800x300", | |
| 171 display_manager()->GetDisplayAt(0)->bounds().ToString()); | |
| 172 reset(); | |
| 173 | |
| 174 // Connect to display again | |
| 175 UpdateDisplay("100+100-500x400"); | |
| 176 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 177 EXPECT_EQ("1 0 0", GetCountSummary()); | |
| 178 EXPECT_FALSE(root_window_destroyed()); | |
| 179 EXPECT_EQ("0,0 500x400", changed()[0].bounds().ToString()); | |
| 180 EXPECT_EQ("100,100 500x400", changed()[0].bounds_in_pixel().ToString()); | |
| 181 reset(); | |
| 182 | |
| 183 // Go back to zero and wake up with multiple displays. | |
| 184 display_manager()->OnNativeDisplaysChanged(empty); | |
| 185 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 186 EXPECT_FALSE(root_window_destroyed()); | |
| 187 reset(); | |
| 188 | |
| 189 // Add secondary. | |
| 190 UpdateDisplay("0+0-1000x600,1000+1000-600x400"); | |
| 191 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 192 EXPECT_EQ("0,0 1000x600", | |
| 193 display_manager()->GetDisplayAt(0)->bounds().ToString()); | |
| 194 // Secondary display is on right. | |
| 195 EXPECT_EQ("1000,0 600x400", | |
| 196 display_manager()->GetDisplayAt(1)->bounds().ToString()); | |
| 197 EXPECT_EQ("1000,1000 600x400", | |
| 198 display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); | |
| 199 reset(); | |
| 200 | |
| 201 aura::DisplayManager::set_use_fullscreen_host_window(false); | |
| 202 } | |
| 203 | |
| 204 // Test in emulation mode (use_fullscreen_host_window=false) | |
| 205 TEST_F(MultiDisplayManagerTest, MAYBE_EmulatorTest) { | |
| 206 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 207 | |
| 208 MultiDisplayManager::CycleDisplay(); | |
| 209 // Update primary and add seconary. | |
| 210 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 211 EXPECT_EQ("0 1 0", GetCountSummary()); | |
| 212 reset(); | |
| 213 | |
| 214 MultiDisplayManager::CycleDisplay(); | |
| 215 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 216 EXPECT_EQ("0 0 1", GetCountSummary()); | |
| 217 reset(); | |
| 218 | |
| 219 MultiDisplayManager::CycleDisplay(); | |
| 220 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 221 EXPECT_EQ("0 1 0", GetCountSummary()); | |
| 222 reset(); | |
| 223 } | |
| 224 | |
| 225 TEST_F(MultiDisplayManagerTest, MAYBE_OverscanInsetsTest) { | |
| 226 UpdateDisplay("0+0-500x500,0+501-400x400"); | |
| 227 reset(); | |
| 228 ASSERT_EQ(2u, display_manager()->GetNumDisplays()); | |
| 229 gfx::Display display1(*display_manager()->GetDisplayAt(0)); | |
| 230 gfx::Display display2(*display_manager()->GetDisplayAt(1)); | |
| 231 | |
| 232 display_manager()->SetOverscanInsets( | |
| 233 display2.id(), gfx::Insets(13, 12, 11, 10)); | |
| 234 std::vector<gfx::Display> changed_displays = changed(); | |
| 235 EXPECT_EQ(1u, changed_displays.size()); | |
| 236 EXPECT_EQ(display2.id(), changed_displays[0].id()); | |
| 237 EXPECT_EQ("0,0 500x500", | |
| 238 display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); | |
| 239 EXPECT_EQ("12,514 378x376", | |
| 240 display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); | |
| 241 | |
| 242 display_manager()->SetOverscanInsets( | |
| 243 display2.id(), gfx::Insets(10, 11, 12, 13)); | |
| 244 EXPECT_EQ("0,0 500x500", | |
| 245 display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); | |
| 246 EXPECT_EQ("11,511 376x378", | |
| 247 display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); | |
| 248 | |
| 249 // Recreate a new 2nd display. It won't apply the overscan inset because the | |
| 250 // new display has a different ID. | |
| 251 UpdateDisplay("0+0-500x500"); | |
| 252 UpdateDisplay("0+0-500x500,0+501-400x400"); | |
| 253 EXPECT_EQ("0,0 500x500", | |
| 254 display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); | |
| 255 EXPECT_EQ("0,501 400x400", | |
| 256 display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); | |
| 257 | |
| 258 // Recreate the displays with the same ID. It should apply the overscan | |
| 259 // inset. | |
| 260 UpdateDisplay("0+0-500x500"); | |
| 261 std::vector<gfx::Display> displays; | |
| 262 displays.push_back(display1); | |
| 263 displays.push_back(display2); | |
| 264 display_manager()->OnNativeDisplaysChanged(displays); | |
| 265 EXPECT_EQ("0,0 500x500", | |
| 266 display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); | |
| 267 EXPECT_EQ("11,511 376x378", | |
| 268 display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); | |
| 269 | |
| 270 // HiDPI but overscan display. The specified insets size should be doubled. | |
| 271 UpdateDisplay("0+0-500x500"); | |
| 272 UpdateDisplay("0+0-500x500,0+501-400x400*2"); | |
| 273 display_manager()->SetOverscanInsets( | |
| 274 display_manager()->GetDisplayAt(1)->id(), gfx::Insets(4, 5, 6, 7)); | |
| 275 EXPECT_EQ("0,0 500x500", | |
| 276 display_manager()->GetDisplayAt(0)->bounds_in_pixel().ToString()); | |
| 277 EXPECT_EQ("10,509 376x380", | |
| 278 display_manager()->GetDisplayAt(1)->bounds_in_pixel().ToString()); | |
| 279 EXPECT_EQ("188x190", display_manager()->GetDisplayAt(1)->size().ToString()); | |
| 280 } | |
| 281 | |
| 282 TEST_F(MultiDisplayManagerTest, MAYBE_ZeroOverscanInsets) { | |
| 283 // Make sure the display change events is emitted for overscan inset changes. | |
| 284 UpdateDisplay("0+0-500x500,0+501-400x400"); | |
| 285 ASSERT_EQ(2u, display_manager()->GetNumDisplays()); | |
| 286 int64 display2_id = display_manager()->GetDisplayAt(1)->id(); | |
| 287 | |
| 288 reset(); | |
| 289 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(0, 0, 0, 0)); | |
| 290 EXPECT_EQ(0u, changed().size()); | |
| 291 | |
| 292 reset(); | |
| 293 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(1, 0, 0, 0)); | |
| 294 EXPECT_EQ(1u, changed().size()); | |
| 295 EXPECT_EQ(display2_id, changed()[0].id()); | |
| 296 | |
| 297 reset(); | |
| 298 display_manager()->SetOverscanInsets(display2_id, gfx::Insets(0, 0, 0, 0)); | |
| 299 EXPECT_EQ(1u, changed().size()); | |
| 300 EXPECT_EQ(display2_id, changed()[0].id()); | |
| 301 } | |
| 302 | |
| 303 // TODO(oshima): Device scale factor is supported on chromeos only for now. | |
| 304 #if defined(OS_CHROMEOS) | |
| 305 #define MAYBE_TestDeviceScaleOnlyChange TestDeviceScaleOnlyChange | |
| 306 #define MAYBE_TestNativeDisplaysChanged TestNativeDisplaysChanged | |
| 307 #define MAYBE_NativeDisplaysChangedAfterPrimaryChange \ | |
| 308 NativeDisplaysChangedAfterPrimaryChange | |
| 309 #else | |
| 310 #define MAYBE_TestDeviceScaleOnlyChange DISABLED_TestDeviceScaleOnlyChange | |
| 311 #define MAYBE_TestNativeDisplaysChanged DISABLED_TestNativeDisplaysChanged | |
| 312 #define MAYBE_NativeDisplaysChangedAfterPrimaryChange \ | |
| 313 DISABLED_NativeDisplaysChangedAfterPrimaryChange | |
| 314 #endif | |
| 315 | |
| 316 TEST_F(MultiDisplayManagerTest, MAYBE_TestDeviceScaleOnlyChange) { | |
| 317 aura::DisplayManager::set_use_fullscreen_host_window(true); | |
| 318 UpdateDisplay("1000x600"); | |
| 319 EXPECT_EQ(1, | |
| 320 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); | |
| 321 EXPECT_EQ("1000x600", | |
| 322 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); | |
| 323 UpdateDisplay("1000x600*2"); | |
| 324 EXPECT_EQ(2, | |
| 325 Shell::GetPrimaryRootWindow()->compositor()->device_scale_factor()); | |
| 326 EXPECT_EQ("500x300", | |
| 327 Shell::GetPrimaryRootWindow()->bounds().size().ToString()); | |
| 328 aura::DisplayManager::set_use_fullscreen_host_window(false); | |
| 329 } | |
| 330 | |
| 331 TEST_F(MultiDisplayManagerTest, MAYBE_TestNativeDisplaysChanged) { | |
| 332 const int64 internal_display_id = | |
| 333 display_manager()->SetFirstDisplayAsInternalDisplayForTest(); | |
| 334 const gfx::Display native_display(internal_display_id, | |
| 335 gfx::Rect(0, 0, 500, 500)); | |
| 336 | |
| 337 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 338 std::string default_bounds = | |
| 339 display_manager()->GetDisplayAt(0)->bounds().ToString(); | |
| 340 | |
| 341 std::vector<gfx::Display> displays; | |
| 342 // Primary disconnected. | |
| 343 display_manager()->OnNativeDisplaysChanged(displays); | |
| 344 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 345 EXPECT_EQ(default_bounds, | |
| 346 display_manager()->GetDisplayAt(0)->bounds().ToString()); | |
| 347 | |
| 348 // External connected while primary was disconnected. | |
| 349 displays.push_back(gfx::Display(10, gfx::Rect(1, 1, 100, 100))); | |
| 350 display_manager()->OnNativeDisplaysChanged(displays); | |
| 351 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 352 EXPECT_EQ(default_bounds, | |
| 353 FindDisplayForId(internal_display_id).bounds().ToString()); | |
| 354 EXPECT_EQ("1,1 100x100", | |
| 355 FindDisplayForId(10).bounds_in_pixel().ToString()); | |
| 356 | |
| 357 // Primary connected, with different bounds. | |
| 358 displays.clear(); | |
| 359 displays.push_back(native_display); | |
| 360 displays.push_back(gfx::Display(10, gfx::Rect(1, 1, 100, 100))); | |
| 361 display_manager()->OnNativeDisplaysChanged(displays); | |
| 362 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 363 EXPECT_EQ("0,0 500x500", | |
| 364 FindDisplayForId(internal_display_id).bounds().ToString()); | |
| 365 EXPECT_EQ("1,1 100x100", | |
| 366 FindDisplayForId(10).bounds_in_pixel().ToString()); | |
| 367 | |
| 368 // Turn off primary. | |
| 369 displays.clear(); | |
| 370 displays.push_back(gfx::Display(10, gfx::Rect(1, 1, 100, 100))); | |
| 371 display_manager()->OnNativeDisplaysChanged(displays); | |
| 372 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 373 EXPECT_EQ("0,0 500x500", | |
| 374 FindDisplayForId(internal_display_id).bounds().ToString()); | |
| 375 EXPECT_EQ("1,1 100x100", | |
| 376 FindDisplayForId(10).bounds_in_pixel().ToString()); | |
| 377 | |
| 378 // Emulate suspend. | |
| 379 displays.clear(); | |
| 380 display_manager()->OnNativeDisplaysChanged(displays); | |
| 381 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 382 EXPECT_EQ("0,0 500x500", | |
| 383 FindDisplayForId(internal_display_id).bounds().ToString()); | |
| 384 EXPECT_EQ("1,1 100x100", | |
| 385 FindDisplayForId(10).bounds_in_pixel().ToString()); | |
| 386 | |
| 387 // External display has disconnected then resumed. | |
| 388 displays.push_back(native_display); | |
| 389 display_manager()->OnNativeDisplaysChanged(displays); | |
| 390 EXPECT_EQ(1U, display_manager()->GetNumDisplays()); | |
| 391 EXPECT_EQ("0,0 500x500", | |
| 392 FindDisplayForId(internal_display_id).bounds().ToString()); | |
| 393 } | |
| 394 | |
| 395 #if defined(OS_CHROMEOS) | |
| 396 #define MAYBE_EnsurePointerInDisplays EnsurePointerInDisplays | |
| 397 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft \ | |
| 398 EnsurePointerInDisplays_2ndOnLeft | |
| 399 #else | |
| 400 // TODO(oshima): Re-enable these tests on WinAura (http://crbug.com/158163). | |
| 401 #define MAYBE_EnsurePointerInDisplays DISABLED_EnsurePointerInDisplays | |
| 402 #define MAYBE_EnsurePointerInDisplays_2ndOnLeft \ | |
| 403 DISABLED_EnsurePointerInDisplays_2ndOnLeft | |
| 404 #endif | |
| 405 | |
| 406 TEST_F(MultiDisplayManagerTest, MAYBE_EnsurePointerInDisplays) { | |
| 407 UpdateDisplay("200x200,300x300"); | |
| 408 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
| 409 | |
| 410 aura::Env* env = aura::Env::GetInstance(); | |
| 411 | |
| 412 // Set the initial position. | |
| 413 root_windows[0]->MoveCursorTo(gfx::Point(350, 150)); | |
| 414 EXPECT_EQ("350,150", env->last_mouse_location().ToString()); | |
| 415 | |
| 416 // A mouse pointer will be inside 2nd display. | |
| 417 UpdateDisplay("300x300,200x200"); | |
| 418 EXPECT_EQ("350,150", env->last_mouse_location().ToString()); | |
| 419 | |
| 420 // A mouse pointer will be outside of displays and move to the | |
| 421 // center of 2nd display. | |
| 422 UpdateDisplay("300x300,100x100"); | |
| 423 EXPECT_EQ("350,50", env->last_mouse_location().ToString()); | |
| 424 | |
| 425 // 2nd display was disconnected, but the mouse pointer says in the | |
| 426 // 1st display. | |
| 427 UpdateDisplay("400x400"); | |
| 428 EXPECT_EQ("350,50", env->last_mouse_location().ToString()); | |
| 429 | |
| 430 // 1st display's resolution has changed, and the mouse pointer is | |
| 431 // now outside. Move the mouse pointer to the center of 1st display. | |
| 432 UpdateDisplay("300x300"); | |
| 433 EXPECT_EQ("150,150", env->last_mouse_location().ToString()); | |
| 434 | |
| 435 // Move the mouse pointer to the bottom of 1st display. | |
| 436 root_windows[0]->MoveCursorTo(gfx::Point(150, 290)); | |
| 437 EXPECT_EQ("150,290", env->last_mouse_location().ToString()); | |
| 438 | |
| 439 // The mouse pointer is outside and closest display is 1st one. | |
| 440 UpdateDisplay("300x280,200x200"); | |
| 441 EXPECT_EQ("150,140", env->last_mouse_location().ToString()); | |
| 442 } | |
| 443 | |
| 444 TEST_F(MultiDisplayManagerTest, MAYBE_EnsurePointerInDisplays_2ndOnLeft) { | |
| 445 UpdateDisplay("200x200,300x300"); | |
| 446 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | |
| 447 | |
| 448 // Set the 2nd display on the left. | |
| 449 DisplayController* display_controller = | |
| 450 Shell::GetInstance()->display_controller(); | |
| 451 DisplayLayout layout = display_controller->default_display_layout(); | |
| 452 layout.position = DisplayLayout::LEFT; | |
| 453 display_controller->SetDefaultDisplayLayout(layout); | |
| 454 | |
| 455 EXPECT_EQ("-300,0 300x300", | |
| 456 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); | |
| 457 | |
| 458 aura::Env* env = aura::Env::GetInstance(); | |
| 459 | |
| 460 // Set the initial position. | |
| 461 root_windows[0]->MoveCursorTo(gfx::Point(-150, 150)); | |
| 462 EXPECT_EQ("-150,150", env->last_mouse_location().ToString()); | |
| 463 | |
| 464 // A mouse pointer will be in 2nd display. | |
| 465 UpdateDisplay("300x300,200x200"); | |
| 466 EXPECT_EQ("-150,150", env->last_mouse_location().ToString()); | |
| 467 | |
| 468 // A mouse pointer will be outside of displays and move to the | |
| 469 // center of 2nd display. | |
| 470 UpdateDisplay("300x300,200x100"); | |
| 471 EXPECT_EQ("-100,50", env->last_mouse_location().ToString()); | |
| 472 | |
| 473 // 2nd display was disconnected. Mouse pointer should move to | |
| 474 // 1st display. | |
| 475 UpdateDisplay("300x300"); | |
| 476 EXPECT_EQ("150,150", env->last_mouse_location().ToString()); | |
| 477 } | |
| 478 | |
| 479 TEST_F(MultiDisplayManagerTest, MAYBE_NativeDisplaysChangedAfterPrimaryChange) { | |
| 480 const int64 internal_display_id = | |
| 481 display_manager()->SetFirstDisplayAsInternalDisplayForTest(); | |
| 482 const gfx::Display native_display(internal_display_id, | |
| 483 gfx::Rect(0, 0, 500, 500)); | |
| 484 const gfx::Display secondary_display(10, gfx::Rect(1, 1, 100, 100)); | |
| 485 | |
| 486 std::vector<gfx::Display> displays; | |
| 487 displays.push_back(native_display); | |
| 488 displays.push_back(secondary_display); | |
| 489 display_manager()->OnNativeDisplaysChanged(displays); | |
| 490 EXPECT_EQ(2U, display_manager()->GetNumDisplays()); | |
| 491 EXPECT_EQ("0,0 500x500", | |
| 492 FindDisplayForId(internal_display_id).bounds().ToString()); | |
| 493 EXPECT_EQ("500,0 100x100", FindDisplayForId(10).bounds().ToString()); | |
| 494 | |
| 495 ash::Shell::GetInstance()->display_controller()->SetPrimaryDisplay( | |
| 496 secondary_display); | |
| 497 EXPECT_EQ("-500,0 500x500", | |
| 498 FindDisplayForId(internal_display_id).bounds().ToString()); | |
| 499 EXPECT_EQ("0,0 100x100", FindDisplayForId(10).bounds().ToString()); | |
| 500 | |
| 501 // OnNativeDisplaysChanged may change the display bounds. Here makes sure | |
| 502 // nothing changed if the exactly same displays are specified. | |
| 503 display_manager()->OnNativeDisplaysChanged(displays); | |
| 504 EXPECT_EQ("-500,0 500x500", | |
| 505 FindDisplayForId(internal_display_id).bounds().ToString()); | |
| 506 EXPECT_EQ("0,0 100x100", FindDisplayForId(10).bounds().ToString()); | |
| 507 } | |
| 508 | |
| 509 } // namespace internal | |
| 510 } // namespace ash | |
| OLD | NEW |