[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 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 7 | #include "ash/shell.h" |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 8 | #include "ash/test/ash_test_base.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 9 | #include "ash/wm/window_util.h" |
| 10 | #include "ui/aura/env.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 11 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 12 | #include "ui/aura/window_event_dispatcher.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 13 | #include "ui/display/manager/display_manager.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 14 | #include "ui/views/widget/widget.h" |
| 15 | #include "ui/views/widget/widget_delegate.h" |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 16 | #include "ui/wm/core/coordinate_conversion.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 17 | |
| 18 | namespace ash { |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 19 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 20 | using ScreenUtilTest = AshTestBase; |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 21 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 22 | TEST_F(ScreenUtilTest, Bounds) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 23 | UpdateDisplay("600x600,500x500"); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 24 | views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 25 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 26 | primary->Show(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 27 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 28 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 29 | secondary->Show(); |
| 30 | |
jamescook | cf8b648f | 2016-06-01 19:58:17 | [diff] [blame] | 31 | // Maximized bounds. By default the shelf is 47px tall (ash::kShelfSize). |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 32 | EXPECT_EQ( |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 33 | gfx::Rect(0, 0, 600, 552).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 34 | ScreenUtil::GetMaximizedWindowBoundsInParent(primary->GetNativeView()) |
| 35 | .ToString()); |
| 36 | EXPECT_EQ( |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 37 | gfx::Rect(0, 0, 500, 452).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 38 | ScreenUtil::GetMaximizedWindowBoundsInParent(secondary->GetNativeView()) |
| 39 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 40 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 41 | // Display bounds |
| 42 | EXPECT_EQ("0,0 600x600", |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 43 | ScreenUtil::GetDisplayBoundsInParent(primary->GetNativeView()) |
| 44 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 45 | EXPECT_EQ("0,0 500x500", |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 46 | ScreenUtil::GetDisplayBoundsInParent(secondary->GetNativeView()) |
| 47 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 48 | |
| 49 | // Work area bounds |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 50 | EXPECT_EQ( |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 51 | gfx::Rect(0, 0, 600, 552).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 52 | ScreenUtil::GetDisplayWorkAreaBoundsInParent(primary->GetNativeView()) |
| 53 | .ToString()); |
| 54 | EXPECT_EQ( |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 55 | gfx::Rect(0, 0, 500, 452).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 56 | ScreenUtil::GetDisplayWorkAreaBoundsInParent(secondary->GetNativeView()) |
| 57 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 58 | } |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 59 | |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 60 | // Test verifies a stable handling of secondary screen widget changes |
| 61 | // (crbug.com/226132). |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 62 | TEST_F(ScreenUtilTest, StabilityTest) { |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 63 | UpdateDisplay("600x600,500x500"); |
| 64 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 65 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 66 | EXPECT_EQ(Shell::GetAllRootWindows()[1], |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 67 | secondary->GetNativeView()->GetRootWindow()); |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 68 | secondary->Show(); |
| 69 | secondary->Maximize(); |
| 70 | secondary->Show(); |
| 71 | secondary->SetFullscreen(true); |
| 72 | secondary->Hide(); |
| 73 | secondary->Close(); |
| 74 | } |
| 75 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 76 | TEST_F(ScreenUtilTest, ConvertRect) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 77 | UpdateDisplay("600x600,500x500"); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 78 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 79 | views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 80 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 81 | primary->Show(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 82 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 83 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 84 | secondary->Show(); |
| 85 | |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 86 | gfx::Rect r1(10, 10, 100, 100); |
| 87 | ::wm::ConvertRectFromScreen(primary->GetNativeView(), &r1); |
| 88 | EXPECT_EQ("0,0 100x100", r1.ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 89 | |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 90 | gfx::Rect r2(620, 20, 100, 100); |
| 91 | ::wm::ConvertRectFromScreen(secondary->GetNativeView(), &r2); |
| 92 | EXPECT_EQ("10,10 100x100", r2.ToString()); |
| 93 | |
| 94 | gfx::Rect r3(30, 30, 100, 100); |
| 95 | ::wm::ConvertRectToScreen(primary->GetNativeView(), &r3); |
| 96 | EXPECT_EQ("40,40 100x100", r3.ToString()); |
| 97 | |
| 98 | gfx::Rect r4(40, 40, 100, 100); |
| 99 | ::wm::ConvertRectToScreen(secondary->GetNativeView(), &r4); |
| 100 | EXPECT_EQ("650,50 100x100", r4.ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 101 | } |
| 102 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 103 | TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 104 | display_manager()->SetUnifiedDesktopEnabled(true); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 105 | |
| 106 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 107 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 108 | aura::Window* window = widget->GetNativeWindow(); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 109 | |
| 110 | UpdateDisplay("500x400"); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 111 | EXPECT_EQ("0,0 500x400", |
| 112 | ScreenUtil::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 113 | |
| 114 | UpdateDisplay("500x400,600x400"); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 115 | EXPECT_EQ("0,0 500x400", |
| 116 | ScreenUtil::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 117 | |
| 118 | // Move to the 2nd physical display. Shelf's display still should be |
| 119 | // the first. |
| 120 | widget->SetBounds(gfx::Rect(800, 0, 100, 100)); |
| 121 | ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); |
| 122 | |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 123 | EXPECT_EQ("0,0 500x400", |
| 124 | ScreenUtil::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 125 | |
| 126 | UpdateDisplay("600x500"); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 127 | EXPECT_EQ("0,0 600x500", |
| 128 | ScreenUtil::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 129 | } |
| 130 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 131 | } // namespace ash |