display_controller_unittest.cc revision 3551c9c881056c480085172ff9840cab31610854
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/display_controller.h" 6 7#include "ash/display/display_info.h" 8#include "ash/display/display_layout_store.h" 9#include "ash/display/display_manager.h" 10#include "ash/launcher/launcher.h" 11#include "ash/screen_ash.h" 12#include "ash/shelf/shelf_widget.h" 13#include "ash/shell.h" 14#include "ash/test/ash_test_base.h" 15#include "ash/test/cursor_manager_test_api.h" 16#include "ui/aura/env.h" 17#include "ui/aura/root_window.h" 18#include "ui/aura/test/event_generator.h" 19#include "ui/aura/window_tracker.h" 20#include "ui/base/events/event_handler.h" 21#include "ui/gfx/display.h" 22#include "ui/gfx/screen.h" 23#include "ui/views/widget/widget.h" 24 25#if defined(USE_X11) 26#include "ui/base/x/x11_util.h" 27#include <X11/Xlib.h> 28#undef RootWindow 29#endif 30 31namespace ash { 32namespace { 33 34const char kDesktopBackgroundView[] = "DesktopBackgroundView"; 35 36class TestObserver : public DisplayController::Observer, 37 public gfx::DisplayObserver { 38 public: 39 TestObserver() 40 : changing_count_(0), 41 changed_count_(0), 42 bounds_changed_count_(0), 43 changed_display_id_(0) { 44 Shell::GetInstance()->display_controller()->AddObserver(this); 45 Shell::GetScreen()->AddObserver(this); 46 } 47 48 virtual ~TestObserver() { 49 Shell::GetInstance()->display_controller()->RemoveObserver(this); 50 Shell::GetScreen()->RemoveObserver(this); 51 } 52 53 // Overridden from DisplayController::Observer 54 virtual void OnDisplayConfigurationChanging() OVERRIDE { 55 ++changing_count_; 56 } 57 virtual void OnDisplayConfigurationChanged() OVERRIDE { 58 ++changed_count_; 59 } 60 61 // Overrideen from gfx::DisplayObserver 62 virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { 63 changed_display_id_ = display.id(); 64 bounds_changed_count_ ++; 65 } 66 virtual void OnDisplayAdded(const gfx::Display& new_display) OVERRIDE { 67 } 68 virtual void OnDisplayRemoved(const gfx::Display& old_display) OVERRIDE { 69 } 70 71 int CountAndReset() { 72 EXPECT_EQ(changing_count_, changed_count_); 73 int count = changing_count_; 74 changing_count_ = changed_count_ = 0; 75 return count; 76 } 77 78 int64 GetBoundsChangedCountAndReset() { 79 int count = bounds_changed_count_; 80 bounds_changed_count_ = 0; 81 return count; 82 } 83 84 int64 GetChangedDisplayIdAndReset() { 85 int64 id = changed_display_id_; 86 changed_display_id_ = 0; 87 return id; 88 } 89 90 private: 91 int changing_count_; 92 int changed_count_; 93 94 int bounds_changed_count_; 95 int64 changed_display_id_; 96 97 DISALLOW_COPY_AND_ASSIGN(TestObserver); 98}; 99 100gfx::Display GetPrimaryDisplay() { 101 return Shell::GetScreen()->GetDisplayNearestWindow( 102 Shell::GetAllRootWindows()[0]); 103} 104 105gfx::Display GetSecondaryDisplay() { 106 return Shell::GetScreen()->GetDisplayNearestWindow( 107 Shell::GetAllRootWindows()[1]); 108} 109 110void SetSecondaryDisplayLayoutAndOffset(DisplayLayout::Position position, 111 int offset) { 112 DisplayLayout layout(position, offset); 113 ASSERT_GT(Shell::GetScreen()->GetNumDisplays(), 1); 114 Shell::GetInstance()->display_controller()-> 115 SetLayoutForCurrentDisplays(layout); 116} 117 118void SetSecondaryDisplayLayout(DisplayLayout::Position position) { 119 SetSecondaryDisplayLayoutAndOffset(position, 0); 120} 121 122void SetDefaultDisplayLayout(DisplayLayout::Position position) { 123 Shell::GetInstance()->display_manager()->layout_store()-> 124 SetDefaultDisplayLayout(DisplayLayout(position, 0)); 125} 126 127class DisplayControllerShutdownTest : public test::AshTestBase { 128 public: 129 virtual void TearDown() OVERRIDE { 130 test::AshTestBase::TearDown(); 131 if (!SupportsMultipleDisplays()) 132 return; 133 134 // Make sure that primary display is accessible after shutdown. 135 gfx::Display primary = Shell::GetScreen()->GetPrimaryDisplay(); 136 EXPECT_EQ("0,0 444x333", primary.bounds().ToString()); 137 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 138 } 139}; 140 141class TestEventHandler : public ui::EventHandler { 142 public: 143 TestEventHandler() : target_root_(NULL), 144 touch_radius_x_(0.0), 145 touch_radius_y_(0.0), 146 scroll_x_offset_(0.0), 147 scroll_y_offset_(0.0), 148 scroll_x_offset_ordinal_(0.0), 149 scroll_y_offset_ordinal_(0.0) {} 150 virtual ~TestEventHandler() {} 151 152 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 153 if (event->flags() & ui::EF_IS_SYNTHESIZED && 154 event->type() != ui::ET_MOUSE_EXITED && 155 event->type() != ui::ET_MOUSE_ENTERED) { 156 return; 157 } 158 aura::Window* target = static_cast<aura::Window*>(event->target()); 159 mouse_location_ = event->root_location(); 160 target_root_ = target->GetRootWindow(); 161 event->StopPropagation(); 162 } 163 164 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 165 aura::Window* target = static_cast<aura::Window*>(event->target()); 166 // Only record when the target is the background which covers 167 // entire root window. 168 if (target->name() != kDesktopBackgroundView) 169 return; 170 touch_radius_x_ = event->radius_x(); 171 touch_radius_y_ = event->radius_y(); 172 event->StopPropagation(); 173 } 174 175 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE { 176 aura::Window* target = static_cast<aura::Window*>(event->target()); 177 // Only record when the target is the background which covers 178 // entire root window. 179 if (target->name() != kDesktopBackgroundView) 180 return; 181 182 if (event->type() == ui::ET_SCROLL) { 183 scroll_x_offset_ = event->x_offset(); 184 scroll_y_offset_ = event->y_offset(); 185 scroll_x_offset_ordinal_ = event->x_offset_ordinal(); 186 scroll_y_offset_ordinal_ = event->y_offset_ordinal(); 187 } 188 event->StopPropagation(); 189 } 190 191 std::string GetLocationAndReset() { 192 std::string result = mouse_location_.ToString(); 193 mouse_location_.SetPoint(0, 0); 194 target_root_ = NULL; 195 return result; 196 } 197 198 float touch_radius_x() { return touch_radius_x_; } 199 float touch_radius_y() { return touch_radius_y_; } 200 float scroll_x_offset() { return scroll_x_offset_; } 201 float scroll_y_offset() { return scroll_y_offset_; } 202 float scroll_x_offset_ordinal() { return scroll_x_offset_ordinal_; } 203 float scroll_y_offset_ordinal() { return scroll_y_offset_ordinal_; } 204 205 private: 206 gfx::Point mouse_location_; 207 aura::RootWindow* target_root_; 208 209 float touch_radius_x_; 210 float touch_radius_y_; 211 float scroll_x_offset_; 212 float scroll_y_offset_; 213 float scroll_x_offset_ordinal_; 214 float scroll_y_offset_ordinal_; 215 216 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 217}; 218 219gfx::Display::Rotation GetStoredRotation(int64 id) { 220 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); 221} 222 223float GetStoredUIScale(int64 id) { 224 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); 225} 226 227#if defined(USE_X11) 228void GetPrimaryAndSeconary(aura::RootWindow** primary, 229 aura::RootWindow** secondary) { 230 *primary = Shell::GetPrimaryRootWindow(); 231 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 232 *secondary = root_windows[0] == *primary ? root_windows[1] : root_windows[0]; 233} 234 235std::string GetXWindowName(aura::RootWindow* window) { 236 char* name = NULL; 237 XFetchName(ui::GetXDisplay(), window->GetAcceleratedWidget(), &name); 238 std::string ret(name); 239 XFree(name); 240 return ret; 241} 242#endif 243 244} // namespace 245 246typedef test::AshTestBase DisplayControllerTest; 247 248TEST_F(DisplayControllerShutdownTest, Shutdown) { 249 if (!SupportsMultipleDisplays()) 250 return; 251 252 UpdateDisplay("444x333, 200x200"); 253} 254 255TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { 256 if (!SupportsMultipleDisplays()) 257 return; 258 259 TestObserver observer; 260 UpdateDisplay("500x500,400x400"); 261 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 262 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 263 gfx::Insets insets(5, 5, 5, 5); 264 int64 secondary_display_id = ScreenAsh::GetSecondaryDisplay().id(); 265 Shell::GetInstance()->display_manager()->UpdateWorkAreaOfDisplay( 266 secondary_display_id, insets); 267 268 // Default layout is RIGHT. 269 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 270 EXPECT_EQ("500,0 400x400", GetSecondaryDisplay().bounds().ToString()); 271 EXPECT_EQ("505,5 390x390", GetSecondaryDisplay().work_area().ToString()); 272 273 // Layout the secondary display to the bottom of the primary. 274 SetSecondaryDisplayLayout(DisplayLayout::BOTTOM); 275 EXPECT_EQ(1, observer.CountAndReset()); 276 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 277 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 278 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 279 EXPECT_EQ("0,500 400x400", GetSecondaryDisplay().bounds().ToString()); 280 EXPECT_EQ("5,505 390x390", GetSecondaryDisplay().work_area().ToString()); 281 282 // Layout the secondary display to the left of the primary. 283 SetSecondaryDisplayLayout(DisplayLayout::LEFT); 284 EXPECT_EQ(1, observer.CountAndReset()); 285 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 286 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 287 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 288 EXPECT_EQ("-400,0 400x400", GetSecondaryDisplay().bounds().ToString()); 289 EXPECT_EQ("-395,5 390x390", GetSecondaryDisplay().work_area().ToString()); 290 291 // Layout the secondary display to the top of the primary. 292 SetSecondaryDisplayLayout(DisplayLayout::TOP); 293 EXPECT_EQ(1, observer.CountAndReset()); 294 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 295 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 296 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 297 EXPECT_EQ("0,-400 400x400", GetSecondaryDisplay().bounds().ToString()); 298 EXPECT_EQ("5,-395 390x390", GetSecondaryDisplay().work_area().ToString()); 299 300 // Layout to the right with an offset. 301 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 300); 302 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 303 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 304 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 305 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 306 EXPECT_EQ("500,300 400x400", GetSecondaryDisplay().bounds().ToString()); 307 308 // Keep the minimum 100. 309 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, 490); 310 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 311 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 312 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 313 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 314 EXPECT_EQ("500,400 400x400", GetSecondaryDisplay().bounds().ToString()); 315 316 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::RIGHT, -400); 317 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 318 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 319 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 320 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 321 EXPECT_EQ("500,-300 400x400", GetSecondaryDisplay().bounds().ToString()); 322 323 // Layout to the bottom with an offset. 324 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -200); 325 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 326 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 327 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 328 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 329 EXPECT_EQ("-200,500 400x400", GetSecondaryDisplay().bounds().ToString()); 330 331 // Keep the minimum 100. 332 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, 490); 333 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 334 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 335 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 336 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 337 EXPECT_EQ("400,500 400x400", GetSecondaryDisplay().bounds().ToString()); 338 339 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); 340 EXPECT_EQ(secondary_display_id, observer.GetChangedDisplayIdAndReset()); 341 EXPECT_EQ(1, observer.GetBoundsChangedCountAndReset()); 342 EXPECT_EQ(1, observer.CountAndReset()); // resize and add 343 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 344 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); 345 346 // Setting the same layout shouldn't invoke observers. 347 SetSecondaryDisplayLayoutAndOffset(DisplayLayout::BOTTOM, -400); 348 EXPECT_EQ(0, observer.GetChangedDisplayIdAndReset()); 349 EXPECT_EQ(0, observer.GetBoundsChangedCountAndReset()); 350 EXPECT_EQ(0, observer.CountAndReset()); // resize and add 351 EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString()); 352 EXPECT_EQ("-300,500 400x400", GetSecondaryDisplay().bounds().ToString()); 353} 354 355TEST_F(DisplayControllerTest, BoundsUpdated) { 356 if (!SupportsMultipleDisplays()) 357 return; 358 359 TestObserver observer; 360 SetDefaultDisplayLayout(DisplayLayout::BOTTOM); 361 UpdateDisplay("200x200,300x300"); // layout, resize and add. 362 EXPECT_EQ(1, observer.CountAndReset()); 363 364 internal::DisplayManager* display_manager = 365 Shell::GetInstance()->display_manager(); 366 gfx::Insets insets(5, 5, 5, 5); 367 display_manager->UpdateWorkAreaOfDisplay( 368 ScreenAsh::GetSecondaryDisplay().id(), insets); 369 370 EXPECT_EQ("0,0 200x200", GetPrimaryDisplay().bounds().ToString()); 371 EXPECT_EQ("0,200 300x300", GetSecondaryDisplay().bounds().ToString()); 372 EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString()); 373 374 UpdateDisplay("400x400,200x200"); 375 EXPECT_EQ(1, observer.CountAndReset()); // two resizes 376 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); 377 EXPECT_EQ("0,400 200x200", GetSecondaryDisplay().bounds().ToString()); 378 379 UpdateDisplay("400x400,300x300"); 380 EXPECT_EQ(1, observer.CountAndReset()); 381 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); 382 EXPECT_EQ("0,400 300x300", GetSecondaryDisplay().bounds().ToString()); 383 384 UpdateDisplay("400x400"); 385 EXPECT_EQ(1, observer.CountAndReset()); 386 EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString()); 387 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays()); 388 389 UpdateDisplay("400x500*2,300x300"); 390 EXPECT_EQ(1, observer.CountAndReset()); 391 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 392 EXPECT_EQ("0,0 200x250", GetPrimaryDisplay().bounds().ToString()); 393 EXPECT_EQ("0,250 300x300", GetSecondaryDisplay().bounds().ToString()); 394 395 // No change 396 UpdateDisplay("400x500*2,300x300"); 397 EXPECT_EQ(0, observer.CountAndReset()); 398 399 // Rotation 400 int64 primary_id = GetPrimaryDisplay().id(); 401 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); 402 EXPECT_EQ(1, observer.CountAndReset()); 403 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); 404 EXPECT_EQ(0, observer.CountAndReset()); 405 406 // UI scale is eanbled only on internal display. 407 int64 secondary_id = GetSecondaryDisplay().id(); 408 gfx::Display::SetInternalDisplayId(secondary_id); 409 display_manager->SetDisplayUIScale(secondary_id, 1.125f); 410 EXPECT_EQ(1, observer.CountAndReset()); 411 display_manager->SetDisplayUIScale(secondary_id, 1.125f); 412 EXPECT_EQ(0, observer.CountAndReset()); 413 display_manager->SetDisplayUIScale(primary_id, 1.125f); 414 EXPECT_EQ(0, observer.CountAndReset()); 415 display_manager->SetDisplayUIScale(primary_id, 1.125f); 416 EXPECT_EQ(0, observer.CountAndReset()); 417} 418 419TEST_F(DisplayControllerTest, InvertLayout) { 420 EXPECT_EQ("left, 0", 421 DisplayLayout(DisplayLayout::RIGHT, 0).Invert().ToString()); 422 EXPECT_EQ("left, -100", 423 DisplayLayout(DisplayLayout::RIGHT, 100).Invert().ToString()); 424 EXPECT_EQ("left, 50", 425 DisplayLayout(DisplayLayout::RIGHT, -50).Invert().ToString()); 426 427 EXPECT_EQ("right, 0", 428 DisplayLayout(DisplayLayout::LEFT, 0).Invert().ToString()); 429 EXPECT_EQ("right, -90", 430 DisplayLayout(DisplayLayout::LEFT, 90).Invert().ToString()); 431 EXPECT_EQ("right, 60", 432 DisplayLayout(DisplayLayout::LEFT, -60).Invert().ToString()); 433 434 EXPECT_EQ("bottom, 0", 435 DisplayLayout(DisplayLayout::TOP, 0).Invert().ToString()); 436 EXPECT_EQ("bottom, -80", 437 DisplayLayout(DisplayLayout::TOP, 80).Invert().ToString()); 438 EXPECT_EQ("bottom, 70", 439 DisplayLayout(DisplayLayout::TOP, -70).Invert().ToString()); 440 441 EXPECT_EQ("top, 0", 442 DisplayLayout(DisplayLayout::BOTTOM, 0).Invert().ToString()); 443 EXPECT_EQ("top, -70", 444 DisplayLayout(DisplayLayout::BOTTOM, 70).Invert().ToString()); 445 EXPECT_EQ("top, 80", 446 DisplayLayout(DisplayLayout::BOTTOM, -80).Invert().ToString()); 447} 448 449TEST_F(DisplayControllerTest, SwapPrimary) { 450 if (!SupportsMultipleDisplays()) 451 return; 452 453 DisplayController* display_controller = 454 Shell::GetInstance()->display_controller(); 455 internal::DisplayManager* display_manager = 456 Shell::GetInstance()->display_manager(); 457 458 UpdateDisplay("200x200,300x300"); 459 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); 460 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); 461 462 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); 463 display_controller->SetLayoutForCurrentDisplays(display_layout); 464 465 EXPECT_NE(primary_display.id(), secondary_display.id()); 466 aura::RootWindow* primary_root = 467 display_controller->GetRootWindowForDisplayId(primary_display.id()); 468 aura::RootWindow* secondary_root = 469 display_controller->GetRootWindowForDisplayId(secondary_display.id()); 470 EXPECT_NE(primary_root, secondary_root); 471 aura::Window* launcher_window = 472 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); 473 EXPECT_TRUE(primary_root->Contains(launcher_window)); 474 EXPECT_FALSE(secondary_root->Contains(launcher_window)); 475 EXPECT_EQ(primary_display.id(), 476 Shell::GetScreen()->GetDisplayNearestPoint( 477 gfx::Point(-100, -100)).id()); 478 EXPECT_EQ(primary_display.id(), 479 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); 480 481 EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString()); 482 EXPECT_EQ("0,0 200x152", primary_display.work_area().ToString()); 483 EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString()); 484 EXPECT_EQ("200,0 300x252", secondary_display.work_area().ToString()); 485 EXPECT_EQ("right, 50", 486 display_manager->GetCurrentDisplayLayout().ToString()); 487 488 // Switch primary and secondary 489 display_controller->SetPrimaryDisplay(secondary_display); 490 const DisplayLayout& inverted_layout = 491 display_manager->GetCurrentDisplayLayout(); 492 EXPECT_EQ("left, -50", inverted_layout.ToString()); 493 494 EXPECT_EQ(secondary_display.id(), 495 Shell::GetScreen()->GetPrimaryDisplay().id()); 496 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); 497 EXPECT_EQ(secondary_display.id(), 498 Shell::GetScreen()->GetDisplayNearestPoint( 499 gfx::Point(-100, -100)).id()); 500 EXPECT_EQ(secondary_display.id(), 501 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); 502 503 EXPECT_EQ( 504 primary_root, 505 display_controller->GetRootWindowForDisplayId(secondary_display.id())); 506 EXPECT_EQ( 507 secondary_root, 508 display_controller->GetRootWindowForDisplayId(primary_display.id())); 509 EXPECT_TRUE(primary_root->Contains(launcher_window)); 510 EXPECT_FALSE(secondary_root->Contains(launcher_window)); 511 512 // Test if the bounds are correctly swapped. 513 gfx::Display swapped_primary = Shell::GetScreen()->GetPrimaryDisplay(); 514 gfx::Display swapped_secondary = ScreenAsh::GetSecondaryDisplay(); 515 EXPECT_EQ("0,0 300x300", swapped_primary.bounds().ToString()); 516 EXPECT_EQ("0,0 300x252", swapped_primary.work_area().ToString()); 517 EXPECT_EQ("-200,-50 200x200", swapped_secondary.bounds().ToString()); 518 519 EXPECT_EQ("-200,-50 200x152", swapped_secondary.work_area().ToString()); 520 521 aura::WindowTracker tracker; 522 tracker.Add(primary_root); 523 tracker.Add(secondary_root); 524 525 // Deleting 2nd display should move the primary to original primary display. 526 UpdateDisplay("200x200"); 527 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. 528 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays()); 529 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id()); 530 EXPECT_EQ(primary_display.id(), 531 Shell::GetScreen()->GetDisplayNearestPoint( 532 gfx::Point(-100, -100)).id()); 533 EXPECT_EQ(primary_display.id(), 534 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); 535 EXPECT_TRUE(tracker.Contains(primary_root)); 536 EXPECT_FALSE(tracker.Contains(secondary_root)); 537 EXPECT_TRUE(primary_root->Contains(launcher_window)); 538} 539 540TEST_F(DisplayControllerTest, SwapPrimaryById) { 541 if (!SupportsMultipleDisplays()) 542 return; 543 544 DisplayController* display_controller = 545 Shell::GetInstance()->display_controller(); 546 internal::DisplayManager* display_manager = 547 Shell::GetInstance()->display_manager(); 548 549 UpdateDisplay("200x200,300x300"); 550 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); 551 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); 552 553 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); 554 display_controller->SetLayoutForCurrentDisplays(display_layout); 555 556 EXPECT_NE(primary_display.id(), secondary_display.id()); 557 aura::RootWindow* primary_root = 558 display_controller->GetRootWindowForDisplayId(primary_display.id()); 559 aura::RootWindow* secondary_root = 560 display_controller->GetRootWindowForDisplayId(secondary_display.id()); 561 aura::Window* launcher_window = 562 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); 563 EXPECT_TRUE(primary_root->Contains(launcher_window)); 564 EXPECT_FALSE(secondary_root->Contains(launcher_window)); 565 EXPECT_NE(primary_root, secondary_root); 566 EXPECT_EQ(primary_display.id(), 567 Shell::GetScreen()->GetDisplayNearestPoint( 568 gfx::Point(-100, -100)).id()); 569 EXPECT_EQ(primary_display.id(), 570 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); 571 572 // Switch primary and secondary by display ID. 573 TestObserver observer; 574 display_controller->SetPrimaryDisplayId(secondary_display.id()); 575 EXPECT_EQ(secondary_display.id(), 576 Shell::GetScreen()->GetPrimaryDisplay().id()); 577 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); 578 EXPECT_LT(0, observer.CountAndReset()); 579 580 EXPECT_EQ( 581 primary_root, 582 display_controller->GetRootWindowForDisplayId(secondary_display.id())); 583 EXPECT_EQ( 584 secondary_root, 585 display_controller->GetRootWindowForDisplayId(primary_display.id())); 586 EXPECT_TRUE(primary_root->Contains(launcher_window)); 587 EXPECT_FALSE(secondary_root->Contains(launcher_window)); 588 589 const DisplayLayout& inverted_layout = 590 display_manager->GetCurrentDisplayLayout(); 591 592 EXPECT_EQ("left, -50", inverted_layout.ToString()); 593 594 // Calling the same ID don't do anything. 595 display_controller->SetPrimaryDisplayId(secondary_display.id()); 596 EXPECT_EQ(0, observer.CountAndReset()); 597 598 aura::WindowTracker tracker; 599 tracker.Add(primary_root); 600 tracker.Add(secondary_root); 601 602 // Deleting 2nd display should move the primary to original primary display. 603 UpdateDisplay("200x200"); 604 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. 605 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays()); 606 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id()); 607 EXPECT_EQ(primary_display.id(), 608 Shell::GetScreen()->GetDisplayNearestPoint( 609 gfx::Point(-100, -100)).id()); 610 EXPECT_EQ(primary_display.id(), 611 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); 612 EXPECT_TRUE(tracker.Contains(primary_root)); 613 EXPECT_FALSE(tracker.Contains(secondary_root)); 614 EXPECT_TRUE(primary_root->Contains(launcher_window)); 615 616 // Adding 2nd display with the same ID. The 2nd display should become primary 617 // since secondary id is still stored as desirable_primary_id. 618 std::vector<internal::DisplayInfo> display_info_list; 619 display_info_list.push_back( 620 display_manager->GetDisplayInfo(primary_display.id())); 621 display_info_list.push_back( 622 display_manager->GetDisplayInfo(secondary_display.id())); 623 display_manager->OnNativeDisplaysChanged(display_info_list); 624 625 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 626 EXPECT_EQ(secondary_display.id(), 627 Shell::GetScreen()->GetPrimaryDisplay().id()); 628 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); 629 EXPECT_EQ( 630 primary_root, 631 display_controller->GetRootWindowForDisplayId(secondary_display.id())); 632 EXPECT_NE( 633 primary_root, 634 display_controller->GetRootWindowForDisplayId(primary_display.id())); 635 EXPECT_TRUE(primary_root->Contains(launcher_window)); 636 637 // Deleting 2nd display and adding 2nd display with a different ID. The 2nd 638 // display shouldn't become primary. 639 UpdateDisplay("200x200"); 640 internal::DisplayInfo third_display_info( 641 secondary_display.id() + 1, std::string(), false); 642 third_display_info.SetBounds(secondary_display.bounds()); 643 ASSERT_NE(primary_display.id(), third_display_info.id()); 644 645 const internal::DisplayInfo& primary_display_info = 646 display_manager->GetDisplayInfo(primary_display.id()); 647 std::vector<internal::DisplayInfo> display_info_list2; 648 display_info_list2.push_back(primary_display_info); 649 display_info_list2.push_back(third_display_info); 650 display_manager->OnNativeDisplaysChanged(display_info_list2); 651 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 652 EXPECT_EQ(primary_display.id(), 653 Shell::GetScreen()->GetPrimaryDisplay().id()); 654 EXPECT_EQ(third_display_info.id(), ScreenAsh::GetSecondaryDisplay().id()); 655 EXPECT_EQ( 656 primary_root, 657 display_controller->GetRootWindowForDisplayId(primary_display.id())); 658 EXPECT_NE( 659 primary_root, 660 display_controller->GetRootWindowForDisplayId(third_display_info.id())); 661 EXPECT_TRUE(primary_root->Contains(launcher_window)); 662} 663 664TEST_F(DisplayControllerTest, CursorDeviceScaleFactorSwapPrimary) { 665 if (!SupportsMultipleDisplays()) 666 return; 667 668 DisplayController* display_controller = 669 Shell::GetInstance()->display_controller(); 670 671 UpdateDisplay("200x200,200x200*2"); 672 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); 673 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); 674 675 aura::RootWindow* primary_root = 676 display_controller->GetRootWindowForDisplayId(primary_display.id()); 677 aura::RootWindow* secondary_root = 678 display_controller->GetRootWindowForDisplayId(secondary_display.id()); 679 EXPECT_NE(primary_root, secondary_root); 680 681 test::CursorManagerTestApi test_api(Shell::GetInstance()->cursor_manager()); 682 683 EXPECT_EQ(1.0f, 684 primary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); 685 primary_root->MoveCursorTo(gfx::Point(50, 50)); 686 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); 687 EXPECT_EQ(2.0f, 688 secondary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); 689 secondary_root->MoveCursorTo(gfx::Point(50, 50)); 690 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); 691 692 // Switch primary and secondary 693 display_controller->SetPrimaryDisplay(secondary_display); 694 695 // Cursor's device scale factor should be updated accroding to the swap of 696 // primary and secondary. 697 EXPECT_EQ(1.0f, 698 secondary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); 699 secondary_root->MoveCursorTo(gfx::Point(50, 50)); 700 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); 701 primary_root->MoveCursorTo(gfx::Point(50, 50)); 702 EXPECT_EQ(2.0f, 703 primary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); 704 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); 705 706 // Deleting 2nd display. 707 UpdateDisplay("200x200"); 708 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. 709 710 // Cursor's device scale factor should be updated even without moving cursor. 711 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); 712 713 primary_root->MoveCursorTo(gfx::Point(50, 50)); 714 EXPECT_EQ(1.0f, 715 primary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); 716 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); 717} 718 719#if defined(OS_WIN) 720// TODO(scottmg): RootWindow doesn't get resized on Windows 721// Ash. http://crbug.com/247916. 722#define MAYBE_UpdateDisplayWithHostOrigin DISABLED_UpdateDisplayWithHostOrigin 723#else 724#define MAYBE_UpdateDisplayWithHostOrigin UpdateDisplayWithHostOrigin 725#endif 726 727TEST_F(DisplayControllerTest, MAYBE_UpdateDisplayWithHostOrigin) { 728 UpdateDisplay("100x200,300x400"); 729 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 730 Shell::RootWindowList root_windows = 731 Shell::GetInstance()->GetAllRootWindows(); 732 ASSERT_EQ(2U, root_windows.size()); 733 EXPECT_EQ("1,1", root_windows[0]->GetHostOrigin().ToString()); 734 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); 735 // UpdateDisplay set the origin if it's not set. 736 EXPECT_NE("1,1", root_windows[1]->GetHostOrigin().ToString()); 737 EXPECT_EQ("300x400", root_windows[1]->GetHostSize().ToString()); 738 739 UpdateDisplay("100x200,200+300-300x400"); 740 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 741 EXPECT_EQ("0,0", root_windows[0]->GetHostOrigin().ToString()); 742 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); 743 EXPECT_EQ("200,300", root_windows[1]->GetHostOrigin().ToString()); 744 EXPECT_EQ("300x400", root_windows[1]->GetHostSize().ToString()); 745 746 UpdateDisplay("400+500-200x300,300x400"); 747 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 748 EXPECT_EQ("400,500", root_windows[0]->GetHostOrigin().ToString()); 749 EXPECT_EQ("200x300", root_windows[0]->GetHostSize().ToString()); 750 EXPECT_EQ("0,0", root_windows[1]->GetHostOrigin().ToString()); 751 EXPECT_EQ("300x400", root_windows[1]->GetHostSize().ToString()); 752 753 UpdateDisplay("100+200-100x200,300+500-200x300"); 754 ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays()); 755 EXPECT_EQ("100,200", root_windows[0]->GetHostOrigin().ToString()); 756 EXPECT_EQ("100x200", root_windows[0]->GetHostSize().ToString()); 757 EXPECT_EQ("300,500", root_windows[1]->GetHostOrigin().ToString()); 758 EXPECT_EQ("200x300", root_windows[1]->GetHostSize().ToString()); 759} 760 761TEST_F(DisplayControllerTest, OverscanInsets) { 762 if (!SupportsMultipleDisplays()) 763 return; 764 765 DisplayController* display_controller = 766 Shell::GetInstance()->display_controller(); 767 TestEventHandler event_handler; 768 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 769 770 UpdateDisplay("120x200,300x400*2"); 771 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); 772 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 773 774 display_controller->SetOverscanInsets(display1.id(), 775 gfx::Insets(10, 15, 20, 25)); 776 EXPECT_EQ("0,0 80x170", root_windows[0]->bounds().ToString()); 777 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 778 EXPECT_EQ("80,0 150x200", 779 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); 780 781 aura::test::EventGenerator generator(root_windows[0]); 782 generator.MoveMouseToInHost(20, 25); 783 EXPECT_EQ("5,15", event_handler.GetLocationAndReset()); 784 785 display_controller->SetOverscanInsets(display1.id(), gfx::Insets()); 786 EXPECT_EQ("0,0 120x200", root_windows[0]->bounds().ToString()); 787 EXPECT_EQ("120,0 150x200", 788 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); 789 790 generator.MoveMouseToInHost(30, 20); 791 EXPECT_EQ("30,20", event_handler.GetLocationAndReset()); 792 793 // Make sure the root window transformer uses correct scale 794 // factor when swapping display. Test crbug.com/253690. 795 UpdateDisplay("400x300*2,600x400/o"); 796 root_windows = Shell::GetAllRootWindows(); 797 gfx::Point point; 798 Shell::GetAllRootWindows()[1]->GetRootTransform().TransformPoint(point); 799 EXPECT_EQ("15,10", point.ToString()); 800 801 display_controller->SwapPrimaryDisplay(); 802 point.SetPoint(0, 0); 803 Shell::GetAllRootWindows()[1]->GetRootTransform().TransformPoint(point); 804 EXPECT_EQ("15,10", point.ToString()); 805 806 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 807} 808 809TEST_F(DisplayControllerTest, Rotate) { 810 if (!SupportsMultipleDisplays()) 811 return; 812 813 DisplayController* display_controller = 814 Shell::GetInstance()->display_controller(); 815 internal::DisplayManager* display_manager = 816 Shell::GetInstance()->display_manager(); 817 TestEventHandler event_handler; 818 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 819 820 UpdateDisplay("120x200,300x400*2"); 821 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); 822 int64 display2_id = ScreenAsh::GetSecondaryDisplay().id(); 823 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 824 aura::test::EventGenerator generator1(root_windows[0]); 825 826 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 827 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 828 EXPECT_EQ("120,0 150x200", 829 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); 830 generator1.MoveMouseToInHost(50, 40); 831 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); 832 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); 833 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); 834 835 display_manager->SetDisplayRotation(display1.id(), 836 gfx::Display::ROTATE_90); 837 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 838 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); 839 EXPECT_EQ("200,0 150x200", 840 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); 841 generator1.MoveMouseToInHost(50, 40); 842 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); 843 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); 844 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); 845 846 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); 847 display_controller->SetLayoutForCurrentDisplays(display_layout); 848 EXPECT_EQ("50,120 150x200", 849 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); 850 851 display_manager->SetDisplayRotation(display2_id, 852 gfx::Display::ROTATE_270); 853 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); 854 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 855 EXPECT_EQ("50,120 200x150", 856 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); 857 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); 858 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); 859 860#if !defined(OS_WIN) 861 aura::test::EventGenerator generator2(root_windows[1]); 862 generator2.MoveMouseToInHost(50, 40); 863 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); 864 display_manager->SetDisplayRotation(display1.id(), 865 gfx::Display::ROTATE_180); 866 867 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); 868 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); 869 // Dislay must share at least 100, so the x's offset becomes 20. 870 EXPECT_EQ("20,200 200x150", 871 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); 872 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); 873 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); 874 875 generator1.MoveMouseToInHost(50, 40); 876 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); 877#endif 878 879 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 880} 881 882TEST_F(DisplayControllerTest, ScaleRootWindow) { 883 if (!SupportsMultipleDisplays()) 884 return; 885 886 TestEventHandler event_handler; 887 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 888 889 UpdateDisplay("600x400*2@1.5,500x300"); 890 891 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); 892 gfx::Display::SetInternalDisplayId(display1.id()); 893 894 gfx::Display display2 = ScreenAsh::GetSecondaryDisplay(); 895 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 896 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); 897 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); 898 EXPECT_EQ("450,0 500x300", display2.bounds().ToString()); 899 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); 900 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 901 902 aura::test::EventGenerator generator(root_windows[0]); 903 generator.MoveMouseToInHost(599, 200); 904 EXPECT_EQ("449,150", event_handler.GetLocationAndReset()); 905 906 internal::DisplayManager* display_manager = 907 Shell::GetInstance()->display_manager(); 908 display_manager->SetDisplayUIScale(display1.id(), 1.25f); 909 display1 = Shell::GetScreen()->GetPrimaryDisplay(); 910 display2 = ScreenAsh::GetSecondaryDisplay(); 911 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); 912 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); 913 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); 914 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); 915 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); 916 917 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 918} 919 920TEST_F(DisplayControllerTest, TouchScale) { 921 if (!SupportsMultipleDisplays()) 922 return; 923 924 TestEventHandler event_handler; 925 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 926 927 UpdateDisplay("200x200*2"); 928 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay(); 929 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 930 aura::RootWindow* root_window = root_windows[0]; 931 aura::test::EventGenerator generator(root_window); 932 933 generator.PressMoveAndReleaseTouchTo(50, 50); 934 // Default test touches have radius_x/y = 1.0, with device scale 935 // factor = 2, the scaled radius_x/y should be 0.5. 936 EXPECT_EQ(0.5, event_handler.touch_radius_x()); 937 EXPECT_EQ(0.5, event_handler.touch_radius_y()); 938 939 generator.ScrollSequence(gfx::Point(0,0), 940 base::TimeDelta::FromMilliseconds(100), 941 10.0, 1.0, 5, 1); 942 943 // With device scale factor = 2, ordinal_offset * 2 = offset. 944 EXPECT_EQ(event_handler.scroll_x_offset(), 945 event_handler.scroll_x_offset_ordinal() * 2); 946 EXPECT_EQ(event_handler.scroll_y_offset(), 947 event_handler.scroll_y_offset_ordinal() * 2); 948 949 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 950} 951 952TEST_F(DisplayControllerTest, ConvertHostToRootCoords) { 953 if (!SupportsMultipleDisplays()) 954 return; 955 956 TestEventHandler event_handler; 957 Shell::GetInstance()->AddPreTargetHandler(&event_handler); 958 959 UpdateDisplay("600x400*2/r@1.5"); 960 961 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); 962 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); 963 EXPECT_EQ("0,0 300x450", display1.bounds().ToString()); 964 EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString()); 965 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); 966 967 aura::test::EventGenerator generator(root_windows[0]); 968 generator.MoveMouseToInHost(0, 0); 969 EXPECT_EQ("0,449", event_handler.GetLocationAndReset()); 970 generator.MoveMouseToInHost(599, 0); 971 EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); 972 generator.MoveMouseToInHost(599, 399); 973 EXPECT_EQ("299,0", event_handler.GetLocationAndReset()); 974 generator.MoveMouseToInHost(0, 399); 975 EXPECT_EQ("299,449", event_handler.GetLocationAndReset()); 976 977 UpdateDisplay("600x400*2/u@1.5"); 978 display1 = Shell::GetScreen()->GetPrimaryDisplay(); 979 root_windows = Shell::GetAllRootWindows(); 980 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); 981 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); 982 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); 983 984 generator.MoveMouseToInHost(0, 0); 985 EXPECT_EQ("449,299", event_handler.GetLocationAndReset()); 986 generator.MoveMouseToInHost(599, 0); 987 EXPECT_EQ("0,299", event_handler.GetLocationAndReset()); 988 generator.MoveMouseToInHost(599, 399); 989 EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); 990 generator.MoveMouseToInHost(0, 399); 991 EXPECT_EQ("449,0", event_handler.GetLocationAndReset()); 992 993 UpdateDisplay("600x400*2/l@1.5"); 994 display1 = Shell::GetScreen()->GetPrimaryDisplay(); 995 root_windows = Shell::GetAllRootWindows(); 996 EXPECT_EQ("0,0 300x450", display1.bounds().ToString()); 997 EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString()); 998 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); 999 1000 generator.MoveMouseToInHost(0, 0); 1001 EXPECT_EQ("299,0", event_handler.GetLocationAndReset()); 1002 generator.MoveMouseToInHost(599, 0); 1003 EXPECT_EQ("299,449", event_handler.GetLocationAndReset()); 1004 generator.MoveMouseToInHost(599, 399); 1005 EXPECT_EQ("0,449", event_handler.GetLocationAndReset()); 1006 generator.MoveMouseToInHost(0, 399); 1007 EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); 1008 1009 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); 1010} 1011 1012#if defined(USE_X11) 1013TEST_F(DisplayControllerTest, XWidowNameForRootWindow) { 1014 EXPECT_EQ("aura_root_0", GetXWindowName(Shell::GetPrimaryRootWindow())); 1015 1016 // Multiple display. 1017 UpdateDisplay("200x200,300x300"); 1018 aura::RootWindow* primary, *secondary; 1019 GetPrimaryAndSeconary(&primary, &secondary); 1020 EXPECT_EQ("aura_root_0", GetXWindowName(primary)); 1021 EXPECT_EQ("aura_root_x", GetXWindowName(secondary)); 1022 1023 // Swap primary. 1024 primary = secondary = NULL; 1025 Shell::GetInstance()->display_controller()->SwapPrimaryDisplay(); 1026 GetPrimaryAndSeconary(&primary, &secondary); 1027 EXPECT_EQ("aura_root_0", GetXWindowName(primary)); 1028 EXPECT_EQ("aura_root_x", GetXWindowName(secondary)); 1029 1030 // Switching back to single display. 1031 UpdateDisplay("300x400"); 1032 EXPECT_EQ("aura_root_0", GetXWindowName(Shell::GetPrimaryRootWindow())); 1033} 1034#endif 1035 1036} // namespace ash 1037