blob: 095cabdc02462b1419b3dbe03965e94e6285a1b9 [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
oshima96f6a502015-05-02 08:43:327#include "ash/display/display_manager.h"
[email protected]8d625fb2012-07-18 16:40:068#include "ash/shell.h"
tdanderson0b7905b2016-06-22 21:53:039#include "ash/test/ash_md_test_base.h"
oshimabba2d992015-05-22 19:21:3910#include "ash/test/display_manager_test_api.h"
[email protected]8d625fb2012-07-18 16:40:0611#include "ash/wm/window_util.h"
12#include "ui/aura/env.h"
[email protected]8d625fb2012-07-18 16:40:0613#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2614#include "ui/aura/window_event_dispatcher.h"
[email protected]8d625fb2012-07-18 16:40:0615#include "ui/views/widget/widget.h"
16#include "ui/views/widget/widget_delegate.h"
17
18namespace ash {
19namespace test {
[email protected]8d625fb2012-07-18 16:40:0620
tdanderson0b7905b2016-06-22 21:53:0321using ScreenUtilTest = AshMDTestBase;
[email protected]8d625fb2012-07-18 16:40:0622
tdanderson0b7905b2016-06-22 21:53:0323INSTANTIATE_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
30TEST_P(ScreenUtilTest, Bounds) {
[email protected]e75642a2013-06-12 17:21:1831 if (!SupportsMultipleDisplays())
32 return;
tdanderson0b7905b2016-06-22 21:53:0333 const int height_offset = GetMdMaximizedWindowHeightOffset();
[email protected]e75642a2013-06-12 17:21:1834
[email protected]f634dd32012-07-23 22:49:0735 UpdateDisplay("600x600,500x500");
[email protected]a2e6af12013-01-07 21:40:3536 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
37 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0638 primary->Show();
[email protected]a2e6af12013-01-07 21:40:3539 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
40 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0641 secondary->Show();
42
jamescookcf8b648f2016-06-01 19:58:1743 // Maximized bounds. By default the shelf is 47px tall (ash::kShelfSize).
tdanderson0b7905b2016-06-22 21:53:0344 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]8d625fb2012-07-18 16:40:0652
[email protected]8d625fb2012-07-18 16:40:0653 // Display bounds
54 EXPECT_EQ("0,0 600x600",
jamescookb8dcef522016-06-25 14:42:5555 ScreenUtil::GetDisplayBoundsInParent(primary->GetNativeView())
56 .ToString());
[email protected]8d625fb2012-07-18 16:40:0657 EXPECT_EQ("0,0 500x500",
jamescookb8dcef522016-06-25 14:42:5558 ScreenUtil::GetDisplayBoundsInParent(secondary->GetNativeView())
59 .ToString());
[email protected]8d625fb2012-07-18 16:40:0660
61 // Work area bounds
tdanderson0b7905b2016-06-22 21:53:0362 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]8d625fb2012-07-18 16:40:0670}
[email protected]8d625fb2012-07-18 16:40:0671
[email protected]805155f2013-04-10 02:11:2072// Test verifies a stable handling of secondary screen widget changes
73// (crbug.com/226132).
tdanderson0b7905b2016-06-22 21:53:0374TEST_P(ScreenUtilTest, StabilityTest) {
[email protected]e75642a2013-06-12 17:21:1875 if (!SupportsMultipleDisplays())
76 return;
77
[email protected]805155f2013-04-10 02:11:2078 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],
jamescookb8dcef522016-06-25 14:42:5582 secondary->GetNativeView()->GetRootWindow());
[email protected]805155f2013-04-10 02:11:2083 secondary->Show();
84 secondary->Maximize();
85 secondary->Show();
86 secondary->SetFullscreen(true);
87 secondary->Hide();
88 secondary->Close();
89}
90
tdanderson0b7905b2016-06-22 21:53:0391TEST_P(ScreenUtilTest, ConvertRect) {
[email protected]e75642a2013-06-12 17:21:1892 if (!SupportsMultipleDisplays())
93 return;
94
[email protected]f634dd32012-07-23 22:49:0795 UpdateDisplay("600x600,500x500");
[email protected]8d625fb2012-07-18 16:40:0696
[email protected]a2e6af12013-01-07 21:40:3597 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
98 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0699 primary->Show();
[email protected]a2e6af12013-01-07 21:40:35100 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
101 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:06102 secondary->Show();
103
jamescookb8dcef522016-06-25 14:42:55104 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]8d625fb2012-07-18 16:40:06112
jamescookb8dcef522016-06-25 14:42:55113 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]8d625fb2012-07-18 16:40:06121}
122
tdanderson0b7905b2016-06-22 21:53:03123TEST_P(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) {
oshima96f6a502015-05-02 08:43:32124 if (!SupportsMultipleDisplays())
125 return;
126 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
oshima628a6172015-08-01 01:33:14127
128 display_manager->SetUnifiedDesktopEnabled(true);
oshima96f6a502015-05-02 08:43:32129
130 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
131 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
132
133 UpdateDisplay("500x400");
oshimac0c9eb72015-11-04 02:16:36134 EXPECT_EQ("0,0 500x400",
135 ScreenUtil::GetShelfDisplayBoundsInRoot(widget->GetNativeWindow())
136 .ToString());
oshima96f6a502015-05-02 08:43:32137
138 UpdateDisplay("500x400,600x400");
oshimac0c9eb72015-11-04 02:16:36139 EXPECT_EQ("0,0 500x400",
140 ScreenUtil::GetShelfDisplayBoundsInRoot(widget->GetNativeWindow())
141 .ToString());
oshima96f6a502015-05-02 08:43:32142
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
oshimac0c9eb72015-11-04 02:16:36148 EXPECT_EQ("0,0 500x400",
149 ScreenUtil::GetShelfDisplayBoundsInRoot(widget->GetNativeWindow())
150 .ToString());
oshima96f6a502015-05-02 08:43:32151
152 UpdateDisplay("600x500");
oshimac0c9eb72015-11-04 02:16:36153 EXPECT_EQ("0,0 600x500",
154 ScreenUtil::GetShelfDisplayBoundsInRoot(widget->GetNativeWindow())
155 .ToString());
oshima96f6a502015-05-02 08:43:32156}
157
[email protected]8d625fb2012-07-18 16:40:06158} // namespace test
159} // namespace ash