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