blob: d6bf080c37f14ca645f5b6018e70f1eb4304d972 [file] [log] [blame]
[email protected]55ad8c12014-01-17 18:24:331// Copyright 2014 The Chromium Authors. All rights reserved.
[email protected]8d625fb2012-07-18 16:40:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]55ad8c12014-01-17 18:24:335#include "ash/screen_util.h"
[email protected]8d625fb2012-07-18 16:40:066
Ahmed Fakhry4f8e3722017-10-31 21:01:587#include "ash/public/cpp/config.h"
[email protected]8d625fb2012-07-18 16:40:068#include "ash/shell.h"
estadea23d6ceb2017-02-15 00:47:099#include "ash/test/ash_test_base.h"
[email protected]8d625fb2012-07-18 16:40:0610#include "ash/wm/window_util.h"
11#include "ui/aura/env.h"
[email protected]8d625fb2012-07-18 16:40:0612#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2613#include "ui/aura/window_event_dispatcher.h"
rjkroege72f8154f2016-10-29 00:49:0214#include "ui/display/manager/display_manager.h"
Ahmed Fakhry4f8e3722017-10-31 21:01:5815#include "ui/display/unified_desktop_utils.h"
[email protected]8d625fb2012-07-18 16:40:0616#include "ui/views/widget/widget.h"
17#include "ui/views/widget/widget_delegate.h"
yhanada698af192017-02-23 10:57:0718#include "ui/wm/core/coordinate_conversion.h"
[email protected]8d625fb2012-07-18 16:40:0619
20namespace ash {
[email protected]8d625fb2012-07-18 16:40:0621
estadea23d6ceb2017-02-15 00:47:0922using ScreenUtilTest = AshTestBase;
[email protected]8d625fb2012-07-18 16:40:0623
estadea23d6ceb2017-02-15 00:47:0924TEST_F(ScreenUtilTest, Bounds) {
[email protected]f634dd32012-07-23 22:49:0725 UpdateDisplay("600x600,500x500");
[email protected]a2e6af12013-01-07 21:40:3526 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
27 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0628 primary->Show();
[email protected]a2e6af12013-01-07 21:40:3529 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
30 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0631 secondary->Show();
32
jamescookcf8b648f2016-06-01 19:58:1733 // Maximized bounds. By default the shelf is 47px tall (ash::kShelfSize).
tdanderson0b7905b2016-06-22 21:53:0334 EXPECT_EQ(
estadea23d6ceb2017-02-15 00:47:0935 gfx::Rect(0, 0, 600, 552).ToString(),
tdanderson0b7905b2016-06-22 21:53:0336 ScreenUtil::GetMaximizedWindowBoundsInParent(primary->GetNativeView())
37 .ToString());
38 EXPECT_EQ(
estadea23d6ceb2017-02-15 00:47:0939 gfx::Rect(0, 0, 500, 452).ToString(),
tdanderson0b7905b2016-06-22 21:53:0340 ScreenUtil::GetMaximizedWindowBoundsInParent(secondary->GetNativeView())
41 .ToString());
[email protected]8d625fb2012-07-18 16:40:0642
[email protected]8d625fb2012-07-18 16:40:0643 // Display bounds
44 EXPECT_EQ("0,0 600x600",
jamescookb8dcef522016-06-25 14:42:5545 ScreenUtil::GetDisplayBoundsInParent(primary->GetNativeView())
46 .ToString());
[email protected]8d625fb2012-07-18 16:40:0647 EXPECT_EQ("0,0 500x500",
jamescookb8dcef522016-06-25 14:42:5548 ScreenUtil::GetDisplayBoundsInParent(secondary->GetNativeView())
49 .ToString());
[email protected]8d625fb2012-07-18 16:40:0650
51 // Work area bounds
tdanderson0b7905b2016-06-22 21:53:0352 EXPECT_EQ(
estadea23d6ceb2017-02-15 00:47:0953 gfx::Rect(0, 0, 600, 552).ToString(),
tdanderson0b7905b2016-06-22 21:53:0354 ScreenUtil::GetDisplayWorkAreaBoundsInParent(primary->GetNativeView())
55 .ToString());
56 EXPECT_EQ(
estadea23d6ceb2017-02-15 00:47:0957 gfx::Rect(0, 0, 500, 452).ToString(),
tdanderson0b7905b2016-06-22 21:53:0358 ScreenUtil::GetDisplayWorkAreaBoundsInParent(secondary->GetNativeView())
59 .ToString());
[email protected]8d625fb2012-07-18 16:40:0660}
[email protected]8d625fb2012-07-18 16:40:0661
[email protected]805155f2013-04-10 02:11:2062// Test verifies a stable handling of secondary screen widget changes
63// (crbug.com/226132).
estadea23d6ceb2017-02-15 00:47:0964TEST_F(ScreenUtilTest, StabilityTest) {
[email protected]805155f2013-04-10 02:11:2065 UpdateDisplay("600x600,500x500");
66 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
67 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
68 EXPECT_EQ(Shell::GetAllRootWindows()[1],
jamescookb8dcef522016-06-25 14:42:5569 secondary->GetNativeView()->GetRootWindow());
[email protected]805155f2013-04-10 02:11:2070 secondary->Show();
71 secondary->Maximize();
72 secondary->Show();
73 secondary->SetFullscreen(true);
74 secondary->Hide();
75 secondary->Close();
76}
77
estadea23d6ceb2017-02-15 00:47:0978TEST_F(ScreenUtilTest, ConvertRect) {
[email protected]f634dd32012-07-23 22:49:0779 UpdateDisplay("600x600,500x500");
[email protected]8d625fb2012-07-18 16:40:0680
[email protected]a2e6af12013-01-07 21:40:3581 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
82 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0683 primary->Show();
[email protected]a2e6af12013-01-07 21:40:3584 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
85 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0686 secondary->Show();
87
yhanada698af192017-02-23 10:57:0788 gfx::Rect r1(10, 10, 100, 100);
89 ::wm::ConvertRectFromScreen(primary->GetNativeView(), &r1);
90 EXPECT_EQ("0,0 100x100", r1.ToString());
[email protected]8d625fb2012-07-18 16:40:0691
yhanada698af192017-02-23 10:57:0792 gfx::Rect r2(620, 20, 100, 100);
93 ::wm::ConvertRectFromScreen(secondary->GetNativeView(), &r2);
94 EXPECT_EQ("10,10 100x100", r2.ToString());
95
96 gfx::Rect r3(30, 30, 100, 100);
97 ::wm::ConvertRectToScreen(primary->GetNativeView(), &r3);
98 EXPECT_EQ("40,40 100x100", r3.ToString());
99
100 gfx::Rect r4(40, 40, 100, 100);
101 ::wm::ConvertRectToScreen(secondary->GetNativeView(), &r4);
102 EXPECT_EQ("650,50 100x100", r4.ToString());
[email protected]8d625fb2012-07-18 16:40:06103}
104
estadea23d6ceb2017-02-15 00:47:09105TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) {
rjkroege72f8154f2016-10-29 00:49:02106 display_manager()->SetUnifiedDesktopEnabled(true);
oshima96f6a502015-05-02 08:43:32107
108 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
109 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
sky00f0b892017-05-05 17:06:24110 aura::Window* window = widget->GetNativeWindow();
oshima96f6a502015-05-02 08:43:32111
112 UpdateDisplay("500x400");
sky00f0b892017-05-05 17:06:24113 EXPECT_EQ("0,0 500x400",
114 ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32115
116 UpdateDisplay("500x400,600x400");
sky00f0b892017-05-05 17:06:24117 EXPECT_EQ("0,0 500x400",
118 ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32119
120 // Move to the 2nd physical display. Shelf's display still should be
121 // the first.
122 widget->SetBounds(gfx::Rect(800, 0, 100, 100));
123 ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString());
124
sky00f0b892017-05-05 17:06:24125 EXPECT_EQ("0,0 500x400",
126 ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32127
128 UpdateDisplay("600x500");
sky00f0b892017-05-05 17:06:24129 EXPECT_EQ("0,0 600x500",
130 ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32131}
132
Ahmed Fakhry4f8e3722017-10-31 21:01:58133TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktopGrid) {
134 // TODO: requires unified desktop mode. http://crbug.com/581462.
135 if (Shell::GetAshConfig() == Config::MASH)
136 return;
137
138 UpdateDisplay("500x400,400x600,300x600,200x300,600x200,350x400");
139 display_manager()->SetUnifiedDesktopEnabled(true);
140
141 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
142 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
143 aura::Window* window = widget->GetNativeWindow();
144
145 display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList();
146 ASSERT_EQ(6u, list.size());
147 // Create a 3 x 2 vertical layout matrix and set it.
148 // [500 x 400] [400 x 600]
149 // [300 x 600] [200 x 300]
150 // [600 x 200] [350 x 400]
151 display::UnifiedDesktopLayoutMatrix matrix;
152 matrix.resize(3u);
153 matrix[0].emplace_back(list[0]);
154 matrix[0].emplace_back(list[1]);
155 matrix[1].emplace_back(list[2]);
156 matrix[1].emplace_back(list[3]);
157 matrix[2].emplace_back(list[4]);
158 matrix[2].emplace_back(list[5]);
159 display_manager()->SetUnifiedDesktopMatrix(matrix);
160 display::Screen* screen = display::Screen::GetScreen();
161 EXPECT_EQ(gfx::Size(766, 1254), screen->GetPrimaryDisplay().size());
162
163 // Regardless of where the window is, the shelf is always in the top left
164 // display in the matrix.
165 EXPECT_EQ(gfx::Rect(0, 0, 499, 400),
166 ScreenUtil::GetDisplayBoundsWithShelf(window));
167
168 // Move to the bottom right display.
169 widget->SetBounds(gfx::Rect(620, 940, 100, 100));
170 EXPECT_EQ(gfx::Rect(0, 0, 499, 400),
171 ScreenUtil::GetDisplayBoundsWithShelf(window));
172}
173
[email protected]8d625fb2012-07-18 16:40:06174} // namespace ash