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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/display_info.h" | 8 #include "ash/display/display_info.h" |
9 #include "ash/display/display_layout_store.h" | 9 #include "ash/display/display_layout_store.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( | 720 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( |
721 gfx::Point(600, 100)).id()); | 721 gfx::Point(600, 100)).id()); |
722 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( | 722 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( |
723 gfx::Point(174, 225)).id()); | 723 gfx::Point(174, 225)).id()); |
724 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( | 724 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( |
725 gfx::Point(176, 225)).id()); | 725 gfx::Point(176, 225)).id()); |
726 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( | 726 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( |
727 gfx::Point(300, 400)).id()); | 727 gfx::Point(300, 400)).id()); |
728 } | 728 } |
729 | 729 |
| 730 TEST_F(DisplayControllerTest, SwapPrimaryForLegacyShelfLayout) { |
| 731 if (!SupportsMultipleDisplays()) |
| 732 return; |
| 733 |
| 734 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 735 ash::switches::kAshDisableAlternateShelfLayout); |
| 736 |
| 737 DisplayController* display_controller = |
| 738 Shell::GetInstance()->display_controller(); |
| 739 internal::DisplayManager* display_manager = |
| 740 Shell::GetInstance()->display_manager(); |
| 741 |
| 742 UpdateDisplay("200x200,300x300"); |
| 743 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
| 744 gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay(); |
| 745 |
| 746 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); |
| 747 display_manager->SetLayoutForCurrentDisplays(display_layout); |
| 748 |
| 749 EXPECT_NE(primary_display.id(), secondary_display.id()); |
| 750 aura::Window* primary_root = |
| 751 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
| 752 aura::Window* secondary_root = |
| 753 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
| 754 EXPECT_NE(primary_root, secondary_root); |
| 755 aura::Window* shelf_window = |
| 756 Shelf::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); |
| 757 EXPECT_TRUE(primary_root->Contains(shelf_window)); |
| 758 EXPECT_FALSE(secondary_root->Contains(shelf_window)); |
| 759 EXPECT_EQ(primary_display.id(), |
| 760 Shell::GetScreen()->GetDisplayNearestPoint( |
| 761 gfx::Point(-100, -100)).id()); |
| 762 EXPECT_EQ(primary_display.id(), |
| 763 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
| 764 |
| 765 EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString()); |
| 766 EXPECT_EQ("0,0 200x152", primary_display.work_area().ToString()); |
| 767 EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString()); |
| 768 EXPECT_EQ("200,0 300x252", secondary_display.work_area().ToString()); |
| 769 EXPECT_EQ("right, 50", |
| 770 display_manager->GetCurrentDisplayLayout().ToString()); |
| 771 |
| 772 // Switch primary and secondary |
| 773 display_controller->SetPrimaryDisplay(secondary_display); |
| 774 const DisplayLayout& inverted_layout = |
| 775 display_manager->GetCurrentDisplayLayout(); |
| 776 EXPECT_EQ("left, -50", inverted_layout.ToString()); |
| 777 |
| 778 EXPECT_EQ(secondary_display.id(), |
| 779 Shell::GetScreen()->GetPrimaryDisplay().id()); |
| 780 EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id()); |
| 781 EXPECT_EQ(primary_display.id(), |
| 782 Shell::GetScreen()->GetDisplayNearestPoint( |
| 783 gfx::Point(-100, -100)).id()); |
| 784 EXPECT_EQ(secondary_display.id(), |
| 785 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
| 786 |
| 787 EXPECT_EQ( |
| 788 primary_root, |
| 789 display_controller->GetRootWindowForDisplayId(secondary_display.id())); |
| 790 EXPECT_EQ( |
| 791 secondary_root, |
| 792 display_controller->GetRootWindowForDisplayId(primary_display.id())); |
| 793 EXPECT_TRUE(primary_root->Contains(shelf_window)); |
| 794 EXPECT_FALSE(secondary_root->Contains(shelf_window)); |
| 795 |
| 796 // Test if the bounds are correctly swapped. |
| 797 gfx::Display swapped_primary = Shell::GetScreen()->GetPrimaryDisplay(); |
| 798 gfx::Display swapped_secondary = ScreenUtil::GetSecondaryDisplay(); |
| 799 EXPECT_EQ("0,0 300x300", swapped_primary.bounds().ToString()); |
| 800 EXPECT_EQ("0,0 300x252", swapped_primary.work_area().ToString()); |
| 801 EXPECT_EQ("-200,-50 200x200", swapped_secondary.bounds().ToString()); |
| 802 |
| 803 EXPECT_EQ("-200,-50 200x152", swapped_secondary.work_area().ToString()); |
| 804 |
| 805 aura::WindowTracker tracker; |
| 806 tracker.Add(primary_root); |
| 807 tracker.Add(secondary_root); |
| 808 |
| 809 // Deleting 2nd display should move the primary to original primary display. |
| 810 UpdateDisplay("200x200"); |
| 811 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. |
| 812 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays()); |
| 813 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id()); |
| 814 EXPECT_EQ(primary_display.id(), |
| 815 Shell::GetScreen()->GetDisplayNearestPoint( |
| 816 gfx::Point(-100, -100)).id()); |
| 817 EXPECT_EQ(primary_display.id(), |
| 818 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
| 819 EXPECT_TRUE(tracker.Contains(primary_root)); |
| 820 EXPECT_FALSE(tracker.Contains(secondary_root)); |
| 821 EXPECT_TRUE(primary_root->Contains(shelf_window)); |
| 822 } |
| 823 |
730 TEST_F(DisplayControllerTest, SwapPrimaryById) { | 824 TEST_F(DisplayControllerTest, SwapPrimaryById) { |
731 if (!SupportsMultipleDisplays()) | 825 if (!SupportsMultipleDisplays()) |
732 return; | 826 return; |
733 | 827 |
734 DisplayController* display_controller = | 828 DisplayController* display_controller = |
735 Shell::GetInstance()->display_controller(); | 829 Shell::GetInstance()->display_controller(); |
736 internal::DisplayManager* display_manager = | 830 internal::DisplayManager* display_manager = |
737 Shell::GetInstance()->display_manager(); | 831 Shell::GetInstance()->display_manager(); |
738 | 832 |
739 UpdateDisplay("200x200,300x300"); | 833 UpdateDisplay("200x200,300x300"); |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetDispatcher()->host())); | 1328 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetDispatcher()->host())); |
1235 | 1329 |
1236 // Switching back to single display. | 1330 // Switching back to single display. |
1237 UpdateDisplay("300x400"); | 1331 UpdateDisplay("300x400"); |
1238 EXPECT_EQ("aura_root_0", GetXWindowName( | 1332 EXPECT_EQ("aura_root_0", GetXWindowName( |
1239 Shell::GetPrimaryRootWindow()->GetDispatcher()->host())); | 1333 Shell::GetPrimaryRootWindow()->GetDispatcher()->host())); |
1240 } | 1334 } |
1241 #endif | 1335 #endif |
1242 | 1336 |
1243 } // namespace ash | 1337 } // namespace ash |
OLD | NEW |