| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/screen_util.h" | 5 #include "ash/screen_util.h" |
| 6 | 6 |
| 7 #include "ash/common/wm/wm_screen_util.h" | 7 #include "ash/common/wm/wm_screen_util.h" |
| 8 #include "ash/common/wm_lookup.h" | 8 #include "ash/common/wm_lookup.h" |
| 9 #include "ash/common/wm_window.h" | 9 #include "ash/common/wm_window.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 using ScreenUtilTest = AshMDTestBase; | 23 using ScreenUtilTest = AshMDTestBase; |
| 24 | 24 |
| 25 INSTANTIATE_TEST_CASE_P( | 25 INSTANTIATE_TEST_CASE_P( |
| 26 /* prefix intentionally left blank due to only one parameterization */, | 26 /* prefix intentionally left blank due to only one parameterization */, |
| 27 ScreenUtilTest, | 27 ScreenUtilTest, |
| 28 testing::Values(MaterialDesignController::NON_MATERIAL, | 28 testing::Values(MaterialDesignController::NON_MATERIAL, |
| 29 MaterialDesignController::MATERIAL_NORMAL, | 29 MaterialDesignController::MATERIAL_NORMAL, |
| 30 MaterialDesignController::MATERIAL_EXPERIMENTAL)); | 30 MaterialDesignController::MATERIAL_EXPERIMENTAL)); |
| 31 | 31 |
| 32 TEST_P(ScreenUtilTest, Bounds) { | 32 TEST_P(ScreenUtilTest, Bounds) { |
| 33 if (!SupportsMultipleDisplays()) | |
| 34 return; | |
| 35 const int height_offset = GetMdMaximizedWindowHeightOffset(); | 33 const int height_offset = GetMdMaximizedWindowHeightOffset(); |
| 36 | 34 |
| 37 UpdateDisplay("600x600,500x500"); | 35 UpdateDisplay("600x600,500x500"); |
| 38 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( | 36 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 39 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 37 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
| 40 primary->Show(); | 38 primary->Show(); |
| 41 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( | 39 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 42 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); | 40 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 43 secondary->Show(); | 41 secondary->Show(); |
| 44 | 42 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 67 .ToString()); | 65 .ToString()); |
| 68 EXPECT_EQ( | 66 EXPECT_EQ( |
| 69 gfx::Rect(0, 0, 500, 453 + height_offset).ToString(), | 67 gfx::Rect(0, 0, 500, 453 + height_offset).ToString(), |
| 70 ScreenUtil::GetDisplayWorkAreaBoundsInParent(secondary->GetNativeView()) | 68 ScreenUtil::GetDisplayWorkAreaBoundsInParent(secondary->GetNativeView()) |
| 71 .ToString()); | 69 .ToString()); |
| 72 } | 70 } |
| 73 | 71 |
| 74 // Test verifies a stable handling of secondary screen widget changes | 72 // Test verifies a stable handling of secondary screen widget changes |
| 75 // (crbug.com/226132). | 73 // (crbug.com/226132). |
| 76 TEST_P(ScreenUtilTest, StabilityTest) { | 74 TEST_P(ScreenUtilTest, StabilityTest) { |
| 77 if (!SupportsMultipleDisplays()) | |
| 78 return; | |
| 79 | |
| 80 UpdateDisplay("600x600,500x500"); | 75 UpdateDisplay("600x600,500x500"); |
| 81 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( | 76 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 82 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); | 77 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 83 EXPECT_EQ(Shell::GetAllRootWindows()[1], | 78 EXPECT_EQ(Shell::GetAllRootWindows()[1], |
| 84 secondary->GetNativeView()->GetRootWindow()); | 79 secondary->GetNativeView()->GetRootWindow()); |
| 85 secondary->Show(); | 80 secondary->Show(); |
| 86 secondary->Maximize(); | 81 secondary->Maximize(); |
| 87 secondary->Show(); | 82 secondary->Show(); |
| 88 secondary->SetFullscreen(true); | 83 secondary->SetFullscreen(true); |
| 89 secondary->Hide(); | 84 secondary->Hide(); |
| 90 secondary->Close(); | 85 secondary->Close(); |
| 91 } | 86 } |
| 92 | 87 |
| 93 TEST_P(ScreenUtilTest, ConvertRect) { | 88 TEST_P(ScreenUtilTest, ConvertRect) { |
| 94 if (!SupportsMultipleDisplays()) | |
| 95 return; | |
| 96 | |
| 97 UpdateDisplay("600x600,500x500"); | 89 UpdateDisplay("600x600,500x500"); |
| 98 | 90 |
| 99 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( | 91 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 100 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 92 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
| 101 primary->Show(); | 93 primary->Show(); |
| 102 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( | 94 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 103 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); | 95 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 104 secondary->Show(); | 96 secondary->Show(); |
| 105 | 97 |
| 106 EXPECT_EQ("0,0 100x100", | 98 EXPECT_EQ("0,0 100x100", |
| 107 ScreenUtil::ConvertRectFromScreen(primary->GetNativeView(), | 99 ScreenUtil::ConvertRectFromScreen(primary->GetNativeView(), |
| 108 gfx::Rect(10, 10, 100, 100)) | 100 gfx::Rect(10, 10, 100, 100)) |
| 109 .ToString()); | 101 .ToString()); |
| 110 EXPECT_EQ("10,10 100x100", | 102 EXPECT_EQ("10,10 100x100", |
| 111 ScreenUtil::ConvertRectFromScreen(secondary->GetNativeView(), | 103 ScreenUtil::ConvertRectFromScreen(secondary->GetNativeView(), |
| 112 gfx::Rect(620, 20, 100, 100)) | 104 gfx::Rect(620, 20, 100, 100)) |
| 113 .ToString()); | 105 .ToString()); |
| 114 | 106 |
| 115 EXPECT_EQ("40,40 100x100", | 107 EXPECT_EQ("40,40 100x100", |
| 116 ScreenUtil::ConvertRectToScreen(primary->GetNativeView(), | 108 ScreenUtil::ConvertRectToScreen(primary->GetNativeView(), |
| 117 gfx::Rect(30, 30, 100, 100)) | 109 gfx::Rect(30, 30, 100, 100)) |
| 118 .ToString()); | 110 .ToString()); |
| 119 EXPECT_EQ("650,50 100x100", | 111 EXPECT_EQ("650,50 100x100", |
| 120 ScreenUtil::ConvertRectToScreen(secondary->GetNativeView(), | 112 ScreenUtil::ConvertRectToScreen(secondary->GetNativeView(), |
| 121 gfx::Rect(40, 40, 100, 100)) | 113 gfx::Rect(40, 40, 100, 100)) |
| 122 .ToString()); | 114 .ToString()); |
| 123 } | 115 } |
| 124 | 116 |
| 125 TEST_P(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { | 117 TEST_P(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { |
| 126 if (!SupportsMultipleDisplays()) | |
| 127 return; | |
| 128 | |
| 129 display_manager()->SetUnifiedDesktopEnabled(true); | 118 display_manager()->SetUnifiedDesktopEnabled(true); |
| 130 | 119 |
| 131 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( | 120 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 132 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 121 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
| 133 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); | 122 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); |
| 134 | 123 |
| 135 UpdateDisplay("500x400"); | 124 UpdateDisplay("500x400"); |
| 136 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 125 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
| 137 | 126 |
| 138 UpdateDisplay("500x400,600x400"); | 127 UpdateDisplay("500x400,600x400"); |
| 139 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 128 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
| 140 | 129 |
| 141 // Move to the 2nd physical display. Shelf's display still should be | 130 // Move to the 2nd physical display. Shelf's display still should be |
| 142 // the first. | 131 // the first. |
| 143 widget->SetBounds(gfx::Rect(800, 0, 100, 100)); | 132 widget->SetBounds(gfx::Rect(800, 0, 100, 100)); |
| 144 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); | 133 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); |
| 145 | 134 |
| 146 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); | 135 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
| 147 | 136 |
| 148 UpdateDisplay("600x500"); | 137 UpdateDisplay("600x500"); |
| 149 EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString()); | 138 EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString()); |
| 150 } | 139 } |
| 151 | 140 |
| 152 } // namespace test | 141 } // namespace test |
| 153 } // namespace ash | 142 } // namespace ash |
| OLD | NEW |