blob: 2f055274e0d8cc0e4b755389176d74ad3000a34b [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
[email protected]8d625fb2012-07-18 16:40:067#include "ash/shell.h"
estadea23d6ceb2017-02-15 00:47:098#include "ash/test/ash_test_base.h"
[email protected]8d625fb2012-07-18 16:40:069#include "ash/wm/window_util.h"
10#include "ui/aura/env.h"
[email protected]8d625fb2012-07-18 16:40:0611#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2612#include "ui/aura/window_event_dispatcher.h"
rjkroege72f8154f2016-10-29 00:49:0213#include "ui/display/manager/display_manager.h"
[email protected]8d625fb2012-07-18 16:40:0614#include "ui/views/widget/widget.h"
15#include "ui/views/widget/widget_delegate.h"
yhanada698af192017-02-23 10:57:0716#include "ui/wm/core/coordinate_conversion.h"
[email protected]8d625fb2012-07-18 16:40:0617
18namespace ash {
[email protected]8d625fb2012-07-18 16:40:0619
estadea23d6ceb2017-02-15 00:47:0920using ScreenUtilTest = AshTestBase;
[email protected]8d625fb2012-07-18 16:40:0621
estadea23d6ceb2017-02-15 00:47:0922TEST_F(ScreenUtilTest, Bounds) {
[email protected]f634dd32012-07-23 22:49:0723 UpdateDisplay("600x600,500x500");
[email protected]a2e6af12013-01-07 21:40:3524 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
25 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0626 primary->Show();
[email protected]a2e6af12013-01-07 21:40:3527 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
28 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0629 secondary->Show();
30
jamescookcf8b648f2016-06-01 19:58:1731 // Maximized bounds. By default the shelf is 47px tall (ash::kShelfSize).
tdanderson0b7905b2016-06-22 21:53:0332 EXPECT_EQ(
estadea23d6ceb2017-02-15 00:47:0933 gfx::Rect(0, 0, 600, 552).ToString(),
tdanderson0b7905b2016-06-22 21:53:0334 ScreenUtil::GetMaximizedWindowBoundsInParent(primary->GetNativeView())
35 .ToString());
36 EXPECT_EQ(
estadea23d6ceb2017-02-15 00:47:0937 gfx::Rect(0, 0, 500, 452).ToString(),
tdanderson0b7905b2016-06-22 21:53:0338 ScreenUtil::GetMaximizedWindowBoundsInParent(secondary->GetNativeView())
39 .ToString());
[email protected]8d625fb2012-07-18 16:40:0640
[email protected]8d625fb2012-07-18 16:40:0641 // Display bounds
42 EXPECT_EQ("0,0 600x600",
jamescookb8dcef522016-06-25 14:42:5543 ScreenUtil::GetDisplayBoundsInParent(primary->GetNativeView())
44 .ToString());
[email protected]8d625fb2012-07-18 16:40:0645 EXPECT_EQ("0,0 500x500",
jamescookb8dcef522016-06-25 14:42:5546 ScreenUtil::GetDisplayBoundsInParent(secondary->GetNativeView())
47 .ToString());
[email protected]8d625fb2012-07-18 16:40:0648
49 // Work area bounds
tdanderson0b7905b2016-06-22 21:53:0350 EXPECT_EQ(
estadea23d6ceb2017-02-15 00:47:0951 gfx::Rect(0, 0, 600, 552).ToString(),
tdanderson0b7905b2016-06-22 21:53:0352 ScreenUtil::GetDisplayWorkAreaBoundsInParent(primary->GetNativeView())
53 .ToString());
54 EXPECT_EQ(
estadea23d6ceb2017-02-15 00:47:0955 gfx::Rect(0, 0, 500, 452).ToString(),
tdanderson0b7905b2016-06-22 21:53:0356 ScreenUtil::GetDisplayWorkAreaBoundsInParent(secondary->GetNativeView())
57 .ToString());
[email protected]8d625fb2012-07-18 16:40:0658}
[email protected]8d625fb2012-07-18 16:40:0659
[email protected]805155f2013-04-10 02:11:2060// Test verifies a stable handling of secondary screen widget changes
61// (crbug.com/226132).
estadea23d6ceb2017-02-15 00:47:0962TEST_F(ScreenUtilTest, StabilityTest) {
[email protected]805155f2013-04-10 02:11:2063 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],
jamescookb8dcef522016-06-25 14:42:5567 secondary->GetNativeView()->GetRootWindow());
[email protected]805155f2013-04-10 02:11:2068 secondary->Show();
69 secondary->Maximize();
70 secondary->Show();
71 secondary->SetFullscreen(true);
72 secondary->Hide();
73 secondary->Close();
74}
75
estadea23d6ceb2017-02-15 00:47:0976TEST_F(ScreenUtilTest, ConvertRect) {
[email protected]f634dd32012-07-23 22:49:0777 UpdateDisplay("600x600,500x500");
[email protected]8d625fb2012-07-18 16:40:0678
[email protected]a2e6af12013-01-07 21:40:3579 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds(
80 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0681 primary->Show();
[email protected]a2e6af12013-01-07 21:40:3582 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds(
83 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100));
[email protected]8d625fb2012-07-18 16:40:0684 secondary->Show();
85
yhanada698af192017-02-23 10:57:0786 gfx::Rect r1(10, 10, 100, 100);
87 ::wm::ConvertRectFromScreen(primary->GetNativeView(), &r1);
88 EXPECT_EQ("0,0 100x100", r1.ToString());
[email protected]8d625fb2012-07-18 16:40:0689
yhanada698af192017-02-23 10:57:0790 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]8d625fb2012-07-18 16:40:06101}
102
estadea23d6ceb2017-02-15 00:47:09103TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) {
rjkroege72f8154f2016-10-29 00:49:02104 display_manager()->SetUnifiedDesktopEnabled(true);
oshima96f6a502015-05-02 08:43:32105
106 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
107 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100));
sky00f0b892017-05-05 17:06:24108 aura::Window* window = widget->GetNativeWindow();
oshima96f6a502015-05-02 08:43:32109
110 UpdateDisplay("500x400");
sky00f0b892017-05-05 17:06:24111 EXPECT_EQ("0,0 500x400",
112 ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32113
114 UpdateDisplay("500x400,600x400");
sky00f0b892017-05-05 17:06:24115 EXPECT_EQ("0,0 500x400",
116 ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32117
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
sky00f0b892017-05-05 17:06:24123 EXPECT_EQ("0,0 500x400",
124 ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32125
126 UpdateDisplay("600x500");
sky00f0b892017-05-05 17:06:24127 EXPECT_EQ("0,0 600x500",
128 ScreenUtil::GetDisplayBoundsWithShelf(window).ToString());
oshima96f6a502015-05-02 08:43:32129}
130
[email protected]8d625fb2012-07-18 16:40:06131} // namespace ash