| 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 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( | 783 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( |
| 784 gfx::Point(600, 100)).id()); | 784 gfx::Point(600, 100)).id()); |
| 785 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( | 785 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( |
| 786 gfx::Point(174, 225)).id()); | 786 gfx::Point(174, 225)).id()); |
| 787 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( | 787 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( |
| 788 gfx::Point(176, 225)).id()); | 788 gfx::Point(176, 225)).id()); |
| 789 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( | 789 EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint( |
| 790 gfx::Point(300, 400)).id()); | 790 gfx::Point(300, 400)).id()); |
| 791 } | 791 } |
| 792 | 792 |
| 793 TEST_F(DisplayControllerTest, SwapPrimaryForLegacyShelfLayout) { | |
| 794 if (!SupportsMultipleDisplays()) | |
| 795 return; | |
| 796 | |
| 797 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 798 switches::kAshDisableAlternateShelfLayout); | |
| 799 | |
| 800 DisplayController* display_controller = | |
| 801 Shell::GetInstance()->display_controller(); | |
| 802 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 803 | |
| 804 UpdateDisplay("200x200,300x300"); | |
| 805 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | |
| 806 gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay(); | |
| 807 | |
| 808 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); | |
| 809 display_manager->SetLayoutForCurrentDisplays(display_layout); | |
| 810 | |
| 811 EXPECT_NE(primary_display.id(), secondary_display.id()); | |
| 812 aura::Window* primary_root = | |
| 813 display_controller->GetRootWindowForDisplayId(primary_display.id()); | |
| 814 aura::Window* secondary_root = | |
| 815 display_controller->GetRootWindowForDisplayId(secondary_display.id()); | |
| 816 EXPECT_NE(primary_root, secondary_root); | |
| 817 aura::Window* shelf_window = | |
| 818 Shelf::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); | |
| 819 EXPECT_TRUE(primary_root->Contains(shelf_window)); | |
| 820 EXPECT_FALSE(secondary_root->Contains(shelf_window)); | |
| 821 EXPECT_EQ(primary_display.id(), | |
| 822 Shell::GetScreen()->GetDisplayNearestPoint( | |
| 823 gfx::Point(-100, -100)).id()); | |
| 824 EXPECT_EQ(primary_display.id(), | |
| 825 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); | |
| 826 | |
| 827 EXPECT_EQ("0,0 200x200", primary_display.bounds().ToString()); | |
| 828 EXPECT_EQ("0,0 200x152", primary_display.work_area().ToString()); | |
| 829 EXPECT_EQ("200,0 300x300", secondary_display.bounds().ToString()); | |
| 830 EXPECT_EQ("200,0 300x252", secondary_display.work_area().ToString()); | |
| 831 EXPECT_EQ("right, 50", | |
| 832 display_manager->GetCurrentDisplayLayout().ToString()); | |
| 833 | |
| 834 // Switch primary and secondary | |
| 835 display_controller->SetPrimaryDisplay(secondary_display); | |
| 836 const DisplayLayout& inverted_layout = | |
| 837 display_manager->GetCurrentDisplayLayout(); | |
| 838 EXPECT_EQ("left, -50", inverted_layout.ToString()); | |
| 839 | |
| 840 EXPECT_EQ(secondary_display.id(), | |
| 841 Shell::GetScreen()->GetPrimaryDisplay().id()); | |
| 842 EXPECT_EQ(primary_display.id(), ScreenUtil::GetSecondaryDisplay().id()); | |
| 843 EXPECT_EQ(primary_display.id(), | |
| 844 Shell::GetScreen()->GetDisplayNearestPoint( | |
| 845 gfx::Point(-100, -100)).id()); | |
| 846 EXPECT_EQ(secondary_display.id(), | |
| 847 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); | |
| 848 | |
| 849 EXPECT_EQ( | |
| 850 primary_root, | |
| 851 display_controller->GetRootWindowForDisplayId(secondary_display.id())); | |
| 852 EXPECT_EQ( | |
| 853 secondary_root, | |
| 854 display_controller->GetRootWindowForDisplayId(primary_display.id())); | |
| 855 EXPECT_TRUE(primary_root->Contains(shelf_window)); | |
| 856 EXPECT_FALSE(secondary_root->Contains(shelf_window)); | |
| 857 | |
| 858 // Test if the bounds are correctly swapped. | |
| 859 gfx::Display swapped_primary = Shell::GetScreen()->GetPrimaryDisplay(); | |
| 860 gfx::Display swapped_secondary = ScreenUtil::GetSecondaryDisplay(); | |
| 861 EXPECT_EQ("0,0 300x300", swapped_primary.bounds().ToString()); | |
| 862 EXPECT_EQ("0,0 300x252", swapped_primary.work_area().ToString()); | |
| 863 EXPECT_EQ("-200,-50 200x200", swapped_secondary.bounds().ToString()); | |
| 864 | |
| 865 EXPECT_EQ("-200,-50 200x152", swapped_secondary.work_area().ToString()); | |
| 866 | |
| 867 aura::WindowTracker tracker; | |
| 868 tracker.Add(primary_root); | |
| 869 tracker.Add(secondary_root); | |
| 870 | |
| 871 // Deleting 2nd display should move the primary to original primary display. | |
| 872 UpdateDisplay("200x200"); | |
| 873 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. | |
| 874 EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays()); | |
| 875 EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetPrimaryDisplay().id()); | |
| 876 EXPECT_EQ(primary_display.id(), | |
| 877 Shell::GetScreen()->GetDisplayNearestPoint( | |
| 878 gfx::Point(-100, -100)).id()); | |
| 879 EXPECT_EQ(primary_display.id(), | |
| 880 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); | |
| 881 EXPECT_TRUE(tracker.Contains(primary_root)); | |
| 882 EXPECT_FALSE(tracker.Contains(secondary_root)); | |
| 883 EXPECT_TRUE(primary_root->Contains(shelf_window)); | |
| 884 } | |
| 885 | |
| 886 TEST_F(DisplayControllerTest, SwapPrimaryById) { | 793 TEST_F(DisplayControllerTest, SwapPrimaryById) { |
| 887 if (!SupportsMultipleDisplays()) | 794 if (!SupportsMultipleDisplays()) |
| 888 return; | 795 return; |
| 889 | 796 |
| 890 DisplayController* display_controller = | 797 DisplayController* display_controller = |
| 891 Shell::GetInstance()->display_controller(); | 798 Shell::GetInstance()->display_controller(); |
| 892 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 799 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 893 | 800 |
| 894 UpdateDisplay("200x200,300x300"); | 801 UpdateDisplay("200x200,300x300"); |
| 895 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 802 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
| (...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); | 1293 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); |
| 1387 | 1294 |
| 1388 // Switching back to single display. | 1295 // Switching back to single display. |
| 1389 UpdateDisplay("300x400"); | 1296 UpdateDisplay("300x400"); |
| 1390 EXPECT_EQ("aura_root_0", GetXWindowName( | 1297 EXPECT_EQ("aura_root_0", GetXWindowName( |
| 1391 Shell::GetPrimaryRootWindow()->GetHost())); | 1298 Shell::GetPrimaryRootWindow()->GetHost())); |
| 1392 } | 1299 } |
| 1393 #endif | 1300 #endif |
| 1394 | 1301 |
| 1395 } // namespace ash | 1302 } // namespace ash |
| OLD | NEW |