1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/screen_util.h"
7 #include "ash/display/display_manager.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h"
13 #include "ash/test/display_manager_test_api.h"
14 #include "ash/wm/window_util.h"
15 #include "ui/aura/env.h"
16 #include "ui/aura/window.h"
17 #include "ui/aura/window_event_dispatcher.h"
18 #include "ui/views/widget/widget.h"
19 #include "ui/views/widget/widget_delegate.h"
24 typedef test::AshTestBase ScreenUtilTest
;
26 TEST_F(ScreenUtilTest
, Bounds
) {
27 if (!SupportsMultipleDisplays())
30 UpdateDisplay("600x600,500x500");
31 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
32 SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
34 views::Widget
* primary
= views::Widget::CreateWindowWithContextAndBounds(
35 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
37 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
38 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
42 EXPECT_EQ("0,0 600x597",
43 ScreenUtil::GetMaximizedWindowBoundsInParent(
44 primary
->GetNativeView()).ToString());
45 EXPECT_EQ("0,0 500x453",
46 ScreenUtil::GetMaximizedWindowBoundsInParent(
47 secondary
->GetNativeView()).ToString());
50 EXPECT_EQ("0,0 600x600",
51 ScreenUtil::GetDisplayBoundsInParent(
52 primary
->GetNativeView()).ToString());
53 EXPECT_EQ("0,0 500x500",
54 ScreenUtil::GetDisplayBoundsInParent(
55 secondary
->GetNativeView()).ToString());
58 EXPECT_EQ("0,0 600x597",
59 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
60 primary
->GetNativeView()).ToString());
61 EXPECT_EQ("0,0 500x453",
62 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
63 secondary
->GetNativeView()).ToString());
66 // Test verifies a stable handling of secondary screen widget changes
67 // (crbug.com/226132).
68 TEST_F(ScreenUtilTest
, StabilityTest
) {
69 if (!SupportsMultipleDisplays())
72 UpdateDisplay("600x600,500x500");
73 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
74 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
75 EXPECT_EQ(Shell::GetAllRootWindows()[1],
76 secondary
->GetNativeView()->GetRootWindow());
78 secondary
->Maximize();
80 secondary
->SetFullscreen(true);
85 TEST_F(ScreenUtilTest
, ConvertRect
) {
86 if (!SupportsMultipleDisplays())
89 UpdateDisplay("600x600,500x500");
91 views::Widget
* primary
= views::Widget::CreateWindowWithContextAndBounds(
92 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
94 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
95 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
100 ScreenUtil::ConvertRectFromScreen(
101 primary
->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString());
104 ScreenUtil::ConvertRectFromScreen(
105 secondary
->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString());
109 ScreenUtil::ConvertRectToScreen(
110 primary
->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString());
113 ScreenUtil::ConvertRectToScreen(
114 secondary
->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString());
117 TEST_F(ScreenUtilTest
, ShelfDisplayBoundsInUnifiedDesktop
) {
118 if (!SupportsMultipleDisplays())
120 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
122 display_manager
->SetUnifiedDesktopEnabled(true);
124 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
125 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
127 UpdateDisplay("500x400");
128 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
129 widget
->GetNativeWindow()).ToString());
131 UpdateDisplay("500x400,600x400");
132 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
133 widget
->GetNativeWindow()).ToString());
135 // Move to the 2nd physical display. Shelf's display still should be
137 widget
->SetBounds(gfx::Rect(800, 0, 100, 100));
138 ASSERT_EQ("800,0 100x100", widget
->GetWindowBoundsInScreen().ToString());
140 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
141 widget
->GetNativeWindow()).ToString());
143 UpdateDisplay("600x500");
144 EXPECT_EQ("0,0 600x500", ScreenUtil::GetShelfDisplayBoundsInScreen(
145 widget
->GetNativeWindow()).ToString());