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