OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include "ash/display/display_info.h" | 7 #include "ash/display/display_info.h" |
8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
9 #include "ash/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 return result; | 115 return result; |
116 } | 116 } |
117 | 117 |
118 private: | 118 private: |
119 gfx::Point mouse_location_; | 119 gfx::Point mouse_location_; |
120 aura::RootWindow* target_root_; | 120 aura::RootWindow* target_root_; |
121 | 121 |
122 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); | 122 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); |
123 }; | 123 }; |
124 | 124 |
| 125 gfx::Display::Rotation GetStoredRotation(int64 id) { |
| 126 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); |
| 127 } |
| 128 |
| 129 float GetStoredUIScale(int64 id) { |
| 130 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); |
| 131 } |
| 132 |
125 } // namespace | 133 } // namespace |
126 | 134 |
127 typedef test::AshTestBase DisplayControllerTest; | 135 typedef test::AshTestBase DisplayControllerTest; |
128 | 136 |
129 TEST_F(DisplayControllerShutdownTest, Shutdown) { | 137 TEST_F(DisplayControllerShutdownTest, Shutdown) { |
130 UpdateDisplay("444x333, 200x200"); | 138 UpdateDisplay("444x333, 200x200"); |
131 } | 139 } |
132 | 140 |
133 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { | 141 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { |
134 TestObserver observer; | 142 TestObserver observer; |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); | 460 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
453 EXPECT_TRUE(tracker.Contains(primary_root)); | 461 EXPECT_TRUE(tracker.Contains(primary_root)); |
454 EXPECT_FALSE(tracker.Contains(secondary_root)); | 462 EXPECT_FALSE(tracker.Contains(secondary_root)); |
455 EXPECT_TRUE(primary_root->Contains(launcher_window)); | 463 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
456 | 464 |
457 internal::DisplayManager* display_manager = | 465 internal::DisplayManager* display_manager = |
458 Shell::GetInstance()->display_manager(); | 466 Shell::GetInstance()->display_manager(); |
459 // Adding 2nd display with the same ID. The 2nd display should become primary | 467 // Adding 2nd display with the same ID. The 2nd display should become primary |
460 // since secondary id is still stored as desirable_primary_id. | 468 // since secondary id is still stored as desirable_primary_id. |
461 std::vector<internal::DisplayInfo> display_info_list; | 469 std::vector<internal::DisplayInfo> display_info_list; |
462 display_info_list.push_back(display_manager->GetDisplayInfo(primary_display)); | |
463 display_info_list.push_back( | 470 display_info_list.push_back( |
464 display_manager->GetDisplayInfo(secondary_display)); | 471 display_manager->GetDisplayInfo(primary_display.id())); |
| 472 display_info_list.push_back( |
| 473 display_manager->GetDisplayInfo(secondary_display.id())); |
465 display_manager->OnNativeDisplaysChanged(display_info_list); | 474 display_manager->OnNativeDisplaysChanged(display_info_list); |
466 | 475 |
467 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 476 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
468 EXPECT_EQ(secondary_display.id(), | 477 EXPECT_EQ(secondary_display.id(), |
469 Shell::GetScreen()->GetPrimaryDisplay().id()); | 478 Shell::GetScreen()->GetPrimaryDisplay().id()); |
470 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); | 479 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); |
471 EXPECT_EQ( | 480 EXPECT_EQ( |
472 primary_root, | 481 primary_root, |
473 display_controller->GetRootWindowForDisplayId(secondary_display.id())); | 482 display_controller->GetRootWindowForDisplayId(secondary_display.id())); |
474 EXPECT_NE( | 483 EXPECT_NE( |
475 primary_root, | 484 primary_root, |
476 display_controller->GetRootWindowForDisplayId(primary_display.id())); | 485 display_controller->GetRootWindowForDisplayId(primary_display.id())); |
477 EXPECT_TRUE(primary_root->Contains(launcher_window)); | 486 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
478 | 487 |
479 // Deleting 2nd display and adding 2nd display with a different ID. The 2nd | 488 // Deleting 2nd display and adding 2nd display with a different ID. The 2nd |
480 // display shouldn't become primary. | 489 // display shouldn't become primary. |
481 UpdateDisplay("200x200"); | 490 UpdateDisplay("200x200"); |
482 internal::DisplayInfo third_display_info( | 491 internal::DisplayInfo third_display_info( |
483 secondary_display.id() + 1, std::string(), false); | 492 secondary_display.id() + 1, std::string(), false); |
484 third_display_info.SetBounds(secondary_display.bounds()); | 493 third_display_info.SetBounds(secondary_display.bounds()); |
485 ASSERT_NE(primary_display.id(), third_display_info.id()); | 494 ASSERT_NE(primary_display.id(), third_display_info.id()); |
486 | 495 |
487 const internal::DisplayInfo& primary_display_info = | 496 const internal::DisplayInfo& primary_display_info = |
488 display_manager->GetDisplayInfo(primary_display); | 497 display_manager->GetDisplayInfo(primary_display.id()); |
489 std::vector<internal::DisplayInfo> display_info_list2; | 498 std::vector<internal::DisplayInfo> display_info_list2; |
490 display_info_list2.push_back(primary_display_info); | 499 display_info_list2.push_back(primary_display_info); |
491 display_info_list2.push_back(third_display_info); | 500 display_info_list2.push_back(third_display_info); |
492 display_manager->OnNativeDisplaysChanged(display_info_list2); | 501 display_manager->OnNativeDisplaysChanged(display_info_list2); |
493 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 502 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
494 EXPECT_EQ(primary_display.id(), | 503 EXPECT_EQ(primary_display.id(), |
495 Shell::GetScreen()->GetPrimaryDisplay().id()); | 504 Shell::GetScreen()->GetPrimaryDisplay().id()); |
496 EXPECT_EQ(third_display_info.id(), ScreenAsh::GetSecondaryDisplay().id()); | 505 EXPECT_EQ(third_display_info.id(), ScreenAsh::GetSecondaryDisplay().id()); |
497 EXPECT_EQ( | 506 EXPECT_EQ( |
498 primary_root, | 507 primary_root, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 int64 display2_id = ScreenAsh::GetSecondaryDisplay().id(); | 666 int64 display2_id = ScreenAsh::GetSecondaryDisplay().id(); |
658 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 667 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
659 aura::test::EventGenerator generator1(root_windows[0]); | 668 aura::test::EventGenerator generator1(root_windows[0]); |
660 | 669 |
661 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); | 670 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
662 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); | 671 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
663 EXPECT_EQ("120,0 150x200", | 672 EXPECT_EQ("120,0 150x200", |
664 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); | 673 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
665 generator1.MoveMouseTo(50, 40); | 674 generator1.MoveMouseTo(50, 40); |
666 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); | 675 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); |
| 676 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); |
| 677 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); |
667 | 678 |
668 display_manager->SetDisplayRotation(display1.id(), | 679 display_manager->SetDisplayRotation(display1.id(), |
669 gfx::Display::ROTATE_90); | 680 gfx::Display::ROTATE_90); |
670 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); | 681 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
671 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); | 682 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
672 EXPECT_EQ("200,0 150x200", | 683 EXPECT_EQ("200,0 150x200", |
673 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); | 684 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
674 generator1.MoveMouseTo(50, 40); | 685 generator1.MoveMouseTo(50, 40); |
675 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); | 686 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); |
| 687 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); |
| 688 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); |
676 | 689 |
677 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); | 690 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); |
678 display_controller->SetLayoutForCurrentDisplays(display_layout); | 691 display_controller->SetLayoutForCurrentDisplays(display_layout); |
679 EXPECT_EQ("50,120 150x200", | 692 EXPECT_EQ("50,120 150x200", |
680 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); | 693 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
681 | 694 |
682 display_manager->SetDisplayRotation(display2_id, | 695 display_manager->SetDisplayRotation(display2_id, |
683 gfx::Display::ROTATE_270); | 696 gfx::Display::ROTATE_270); |
684 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); | 697 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
685 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); | 698 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
686 EXPECT_EQ("50,120 200x150", | 699 EXPECT_EQ("50,120 200x150", |
687 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); | 700 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 701 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); |
| 702 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); |
688 | 703 |
689 aura::test::EventGenerator generator2(root_windows[1]); | 704 aura::test::EventGenerator generator2(root_windows[1]); |
690 generator2.MoveMouseTo(50, 40); | 705 generator2.MoveMouseTo(50, 40); |
691 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); | 706 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); |
692 display_manager->SetDisplayRotation(display1.id(), | 707 display_manager->SetDisplayRotation(display1.id(), |
693 gfx::Display::ROTATE_180); | 708 gfx::Display::ROTATE_180); |
694 | 709 |
695 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); | 710 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
696 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); | 711 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
697 // Dislay must share at least 100, so the x's offset becomes 20. | 712 // Dislay must share at least 100, so the x's offset becomes 20. |
698 EXPECT_EQ("20,200 200x150", | 713 EXPECT_EQ("20,200 200x150", |
699 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); | 714 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 715 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); |
| 716 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); |
700 | 717 |
701 generator1.MoveMouseTo(50, 40); | 718 generator1.MoveMouseTo(50, 40); |
702 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); | 719 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); |
703 | 720 |
704 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 721 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
705 } | 722 } |
706 | 723 |
707 #if defined(OS_WIN) | 724 #if defined(OS_WIN) |
708 // On Win8 bots, the host window can't be resized and | 725 // On Win8 bots, the host window can't be resized and |
709 // SetTransform updates the window using the orignal host window | 726 // SetTransform updates the window using the orignal host window |
710 // size. | 727 // size. |
711 #define MAYBE_ScaleRootWindow DISABLED_ScaleRootWindow | 728 #define MAYBE_ScaleRootWindow DISABLED_ScaleRootWindow |
712 #else | 729 #else |
713 #define MAYBE_ScaleRootWindow ScaleRootWindow | 730 #define MAYBE_ScaleRootWindow ScaleRootWindow |
714 #endif | 731 #endif |
715 | 732 |
716 TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) { | 733 TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) { |
717 TestEventHandler event_handler; | 734 TestEventHandler event_handler; |
718 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 735 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
719 | 736 |
720 UpdateDisplay("600x400*2@1.5"); | 737 UpdateDisplay("600x400*2@1.5,500x300"); |
721 | 738 |
722 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); | 739 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
| 740 gfx::Display display2 = ScreenAsh::GetSecondaryDisplay(); |
723 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 741 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
724 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); | 742 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); |
725 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); | 743 EXPECT_EQ("0,0 450x300", root_windows[0]->bounds().ToString()); |
| 744 EXPECT_EQ("450,0 500x300", display2.bounds().ToString()); |
| 745 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); |
| 746 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); |
726 | 747 |
727 aura::test::EventGenerator generator(root_windows[0]); | 748 aura::test::EventGenerator generator(root_windows[0]); |
728 generator.MoveMouseTo(599, 200); | 749 generator.MoveMouseTo(599, 200); |
729 EXPECT_EQ("449,150", event_handler.GetLocationAndReset()); | 750 EXPECT_EQ("449,150", event_handler.GetLocationAndReset()); |
730 | 751 |
| 752 internal::DisplayManager* display_manager = |
| 753 Shell::GetInstance()->display_manager(); |
| 754 display_manager->SetDisplayUIScale(display1.id(), 1.25); |
| 755 display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
| 756 display2 = ScreenAsh::GetSecondaryDisplay(); |
| 757 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); |
| 758 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); |
| 759 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); |
| 760 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); |
| 761 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); |
| 762 |
731 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 763 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
732 } | 764 } |
733 | 765 |
734 } // namespace test | 766 } // namespace test |
735 } // namespace ash | 767 } // namespace ash |
OLD | NEW |