blob: 13c23631bddb76e10512eece077135475e7665e2 [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
msw76269332016-08-06 02:25:487#include "ash/common/wm/wm_screen_util.h"
8#include "ash/common/wm_lookup.h"
9#include "ash/common/wm_window.h"
[email protected]8d625fb2012-07-18 16:40:0610#include "ash/shell.h"
tdanderson0b7905b2016-06-22 21:53:0311#include "ash/test/ash_md_test_base.h"
[email protected]8d625fb2012-07-18 16:40:0612#include "ash/wm/window_util.h"
13#include "ui/aura/env.h"
[email protected]8d625fb2012-07-18 16:40:0614#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2615#include "ui/aura/window_event_dispatcher.h"
rjkroege72f8154f2016-10-29 00:49:0216#include "ui/display/manager/display_manager.h"
[email protected]8d625fb2012-07-18 16:40:0617#include "ui/views/widget/widget.h"
18#include "ui/views/widget/widget_delegate.h"
19
20namespace ash {
21namespace test {
[email protected]8d625fb2012-07-18 16:40:0622
tdanderson0b7905b2016-06-22 21:53:0323using ScreenUtilTest = AshMDTestBase;
[email protected]8d625fb2012-07-18 16:40:0624
tdanderson0b7905b2016-06-22 21:53:0325INSTANTIATE_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
32TEST_P(ScreenUtilTest, Bounds) {
[email protected]e75642a2013-06-12 17:21:1833 if (!SupportsMultipleDisplays())
34 return;
tdanderson0b7905b2016-06-22 21:53:0335 const int height_offset = GetMdMaximizedWindowHeightOffset();
[email protected]e75642a2013-06-12 17:21:1836
[email protected]f634dd32012-07-23 22:49:0737 UpdateDisplay("600x600,500x500");
[email protected]a2e6af12013-01-07 21:40:3538 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
39 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0640 primary->Show();
[email protected]a2e6af12013-01-07 21:40:3541 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
42 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0643 secondary->Show();
44
jamescookcf8b648f2016-06-01 19:58:1745 // Maximized bounds. By default the shelf is 47px tall (ash::kShelfSize).
tdanderson0b7905b2016-06-22 21:53:0346 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]8d625fb2012-07-18 16:40:0654
[email protected]8d625fb2012-07-18 16:40:0655 // Display bounds
56 EXPECT_EQ("0,0 600x600",
jamescookb8dcef522016-06-25 14:42:5557 ScreenUtil::GetDisplayBoundsInParent(primary->GetNativeView())
58 .ToString());
[email protected]8d625fb2012-07-18 16:40:0659 EXPECT_EQ("0,0 500x500",
jamescookb8dcef522016-06-25 14:42:5560 ScreenUtil::GetDisplayBoundsInParent(secondary->GetNativeView())
61 .ToString());
[email protected]8d625fb2012-07-18 16:40:0662
63 // Work area bounds
tdanderson0b7905b2016-06-22 21:53:0364 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]8d625fb2012-07-18 16:40:0672}
[email protected]8d625fb2012-07-18 16:40:0673
[email protected]805155f2013-04-10 02:11:2074// Test verifies a stable handling of secondary screen widget changes
75// (crbug.com/226132).
tdanderson0b7905b2016-06-22 21:53:0376TEST_P(ScreenUtilTest, StabilityTest) {
[email protected]e75642a2013-06-12 17:21:1877 if (!SupportsMultipleDisplays())
78 return;
79
[email protected]805155f2013-04-10 02:11:2080 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],
jamescookb8dcef522016-06-25 14:42:5584 secondary->GetNativeView()->GetRootWindow());
[email protected]805155f2013-04-10 02:11:2085 secondary->Show();
86 secondary->Maximize();
87 secondary->Show();
88 secondary->SetFullscreen(true);
89 secondary->Hide();
90 secondary->Close();
91}
92
tdanderson0b7905b2016-06-22 21:53:0393TEST_P(ScreenUtilTest, ConvertRect) {
[email protected]e75642a2013-06-12 17:21:1894 if (!SupportsMultipleDisplays())
95 return;
96
[email protected]f634dd32012-07-23 22:49:0797 UpdateDisplay("600x600,500x500");
[email protected]8d625fb2012-07-18 16:40:0698
[email protected]a2e6af12013-01-07 21:40:3599 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
100 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:06101 primary->Show();
[email protected]a2e6af12013-01-07 21:40:35102 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
103 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:06104 secondary->Show();
105
jamescookb8dcef522016-06-25 14:42:55106 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]8d625fb2012-07-18 16:40:06114
jamescookb8dcef522016-06-25 14:42:55115 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]8d625fb2012-07-18 16:40:06123}
124
tdanderson0b7905b2016-06-22 21:53:03125TEST_P(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) {
oshima96f6a502015-05-02 08:43:32126 if (!SupportsMultipleDisplays())
127 return;
oshima628a6172015-08-01 01:33:14128
rjkroege72f8154f2016-10-29 00:49:02129 display_manager()->SetUnifiedDesktopEnabled(true);
oshima96f6a502015-05-02 08:43:32130
131 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
132 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
msw76269332016-08-06 02:25:48133 WmWindow* window = WmLookup::Get()->GetWindowForWidget(widget);
oshima96f6a502015-05-02 08:43:32134
135 UpdateDisplay("500x400");
msw76269332016-08-06 02:25:48136 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32137
138 UpdateDisplay("500x400,600x400");
msw76269332016-08-06 02:25:48139 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32140
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
msw76269332016-08-06 02:25:48146 EXPECT_EQ("0,0 500x400", wm::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32147
148 UpdateDisplay("600x500");
msw76269332016-08-06 02:25:48149 EXPECT_EQ("0,0 600x500", wm::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32150}
151
[email protected]8d625fb2012-07-18 16:40:06152} // namespace test
153} // namespace ash