[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 5 | #include "ash/screen_util.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 6 | |
msw | 7626933 | 2016-08-06 02:25:48 | [diff] [blame] | 7 | #include "ash/common/wm/wm_screen_util.h" |
| 8 | #include "ash/common/wm_lookup.h" |
| 9 | #include "ash/common/wm_window.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 10 | #include "ash/shell.h" |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 11 | #include "ash/test/ash_md_test_base.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 12 | #include "ash/wm/window_util.h" |
| 13 | #include "ui/aura/env.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 14 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 15 | #include "ui/aura/window_event_dispatcher.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame^] | 16 | #include "ui/display/manager/display_manager.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 17 | #include "ui/views/widget/widget.h" |
| 18 | #include "ui/views/widget/widget_delegate.h" |
| 19 | |
| 20 | namespace ash { |
| 21 | namespace test { |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 22 | |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 23 | using ScreenUtilTest = AshMDTestBase; |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 24 | |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 25 | INSTANTIATE_TEST_CASE_P( |
| 26 | /* prefix intentionally left blank due to only one parameterization */, |
| 27 | ScreenUtilTest, |
| 28 | testing::Values(MaterialDesignController::NON_MATERIAL, |
| 29 | MaterialDesignController::MATERIAL_NORMAL, |
| 30 | MaterialDesignController::MATERIAL_EXPERIMENTAL)); |
| 31 | |
| 32 | TEST_P(ScreenUtilTest, Bounds) { |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 33 | if (!SupportsMultipleDisplays()) |
| 34 | return; |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 35 | const int height_offset = GetMdMaximizedWindowHeightOffset(); |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 36 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 37 | UpdateDisplay("600x600,500x500"); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 38 | views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 39 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 40 | primary->Show(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 41 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 42 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 43 | secondary->Show(); |
| 44 | |
jamescook | cf8b648f | 2016-06-01 19:58:17 | [diff] [blame] | 45 | // Maximized bounds. By default the shelf is 47px tall (ash::kShelfSize). |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 46 | EXPECT_EQ( |
| 47 | gfx::Rect(0, 0, 600, 553 + height_offset).ToString(), |
| 48 | ScreenUtil::GetMaximizedWindowBoundsInParent(primary->GetNativeView()) |
| 49 | .ToString()); |
| 50 | EXPECT_EQ( |
| 51 | gfx::Rect(0, 0, 500, 453 + height_offset).ToString(), |
| 52 | ScreenUtil::GetMaximizedWindowBoundsInParent(secondary->GetNativeView()) |
| 53 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 54 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 55 | // Display bounds |
| 56 | EXPECT_EQ("0,0 600x600", |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 57 | ScreenUtil::GetDisplayBoundsInParent(primary->GetNativeView()) |
| 58 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 59 | EXPECT_EQ("0,0 500x500", |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 60 | ScreenUtil::GetDisplayBoundsInParent(secondary->GetNativeView()) |
| 61 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 62 | |
| 63 | // Work area bounds |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 64 | EXPECT_EQ( |
| 65 | gfx::Rect(0, 0, 600, 553 + height_offset).ToString(), |
| 66 | ScreenUtil::GetDisplayWorkAreaBoundsInParent(primary->GetNativeView()) |
| 67 | .ToString()); |
| 68 | EXPECT_EQ( |
| 69 | gfx::Rect(0, 0, 500, 453 + height_offset).ToString(), |
| 70 | ScreenUtil::GetDisplayWorkAreaBoundsInParent(secondary->GetNativeView()) |
| 71 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 72 | } |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 73 | |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 74 | // Test verifies a stable handling of secondary screen widget changes |
| 75 | // (crbug.com/226132). |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 76 | TEST_P(ScreenUtilTest, StabilityTest) { |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 77 | if (!SupportsMultipleDisplays()) |
| 78 | return; |
| 79 | |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 80 | UpdateDisplay("600x600,500x500"); |
| 81 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 82 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 83 | EXPECT_EQ(Shell::GetAllRootWindows()[1], |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 84 | secondary->GetNativeView()->GetRootWindow()); |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 85 | secondary->Show(); |
| 86 | secondary->Maximize(); |
| 87 | secondary->Show(); |
| 88 | secondary->SetFullscreen(true); |
| 89 | secondary->Hide(); |
| 90 | secondary->Close(); |
| 91 | } |
| 92 | |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 93 | TEST_P(ScreenUtilTest, ConvertRect) { |
[email protected] | e75642a | 2013-06-12 17:21:18 | [diff] [blame] | 94 | if (!SupportsMultipleDisplays()) |
| 95 | return; |
| 96 | |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 97 | UpdateDisplay("600x600,500x500"); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 98 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 99 | views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 100 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 101 | primary->Show(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 102 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 103 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 104 | secondary->Show(); |
| 105 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 106 | EXPECT_EQ("0,0 100x100", |
| 107 | ScreenUtil::ConvertRectFromScreen(primary->GetNativeView(), |
| 108 | gfx::Rect(10, 10, 100, 100)) |
| 109 | .ToString()); |
| 110 | EXPECT_EQ("10,10 100x100", |
| 111 | ScreenUtil::ConvertRectFromScreen(secondary->GetNativeView(), |
| 112 | gfx::Rect(620, 20, 100, 100)) |
| 113 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 114 | |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 115 | EXPECT_EQ("40,40 100x100", |
| 116 | ScreenUtil::ConvertRectToScreen(primary->GetNativeView(), |
| 117 | gfx::Rect(30, 30, 100, 100)) |
| 118 | .ToString()); |
| 119 | EXPECT_EQ("650,50 100x100", |
| 120 | ScreenUtil::ConvertRectToScreen(secondary->GetNativeView(), |
| 121 | gfx::Rect(40, 40, 100, 100)) |
| 122 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 123 | } |
| 124 | |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 125 | TEST_P(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 126 | if (!SupportsMultipleDisplays()) |
| 127 | return; |
oshima | 628a617 | 2015-08-01 01:33:14 | [diff] [blame] | 128 | |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame^] | 129 | display_manager()->SetUnifiedDesktopEnabled(true); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 130 | |
| 131 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 132 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
msw | 7626933 | 2016-08-06 02:25:48 | [diff] [blame] | 133 | WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 134 | |
| 135 | UpdateDisplay("500x400"); |
msw | 7626933 | 2016-08-06 02:25:48 | [diff] [blame] | 136 | EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 137 | |
| 138 | UpdateDisplay("500x400,600x400"); |
msw | 7626933 | 2016-08-06 02:25:48 | [diff] [blame] | 139 | EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 140 | |
| 141 | // Move to the 2nd physical display. Shelf's display still should be |
| 142 | // the first. |
| 143 | widget->SetBounds(gfx::Rect(800, 0, 100, 100)); |
| 144 | ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); |
| 145 | |
msw | 7626933 | 2016-08-06 02:25:48 | [diff] [blame] | 146 | EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 147 | |
| 148 | UpdateDisplay("600x500"); |
msw | 7626933 | 2016-08-06 02:25:48 | [diff] [blame] | 149 | EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 152 | } // namespace test |
| 153 | } // namespace ash |