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/wm/window_util.h"
14 #include "ui/aura/env.h"
15 #include "ui/aura/window.h"
16 #include "ui/aura/window_event_dispatcher.h"
17 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_delegate.h"
23 typedef test::AshTestBase ScreenUtilTest
;
25 TEST_F(ScreenUtilTest
, Bounds
) {
26 if (!SupportsMultipleDisplays())
29 UpdateDisplay("600x600,500x500");
30 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
31 SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
33 views::Widget
* primary
= views::Widget::CreateWindowWithContextAndBounds(
34 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
36 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
37 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
41 EXPECT_EQ("0,0 600x597",
42 ScreenUtil::GetMaximizedWindowBoundsInParent(
43 primary
->GetNativeView()).ToString());
44 EXPECT_EQ("0,0 500x453",
45 ScreenUtil::GetMaximizedWindowBoundsInParent(
46 secondary
->GetNativeView()).ToString());
49 EXPECT_EQ("0,0 600x600",
50 ScreenUtil::GetDisplayBoundsInParent(
51 primary
->GetNativeView()).ToString());
52 EXPECT_EQ("0,0 500x500",
53 ScreenUtil::GetDisplayBoundsInParent(
54 secondary
->GetNativeView()).ToString());
57 EXPECT_EQ("0,0 600x597",
58 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
59 primary
->GetNativeView()).ToString());
60 EXPECT_EQ("0,0 500x453",
61 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
62 secondary
->GetNativeView()).ToString());
65 // Test verifies a stable handling of secondary screen widget changes
66 // (crbug.com/226132).
67 TEST_F(ScreenUtilTest
, StabilityTest
) {
68 if (!SupportsMultipleDisplays())
71 UpdateDisplay("600x600,500x500");
72 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
73 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
74 EXPECT_EQ(Shell::GetAllRootWindows()[1],
75 secondary
->GetNativeView()->GetRootWindow());
77 secondary
->Maximize();
79 secondary
->SetFullscreen(true);
84 TEST_F(ScreenUtilTest
, ConvertRect
) {
85 if (!SupportsMultipleDisplays())
88 UpdateDisplay("600x600,500x500");
90 views::Widget
* primary
= views::Widget::CreateWindowWithContextAndBounds(
91 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
93 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
94 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
99 ScreenUtil::ConvertRectFromScreen(
100 primary
->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString());
103 ScreenUtil::ConvertRectFromScreen(
104 secondary
->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString());
108 ScreenUtil::ConvertRectToScreen(
109 primary
->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString());
112 ScreenUtil::ConvertRectToScreen(
113 secondary
->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString());
116 TEST_F(ScreenUtilTest
, ShelfDisplayBoundsInUnifiedDesktop
) {
117 if (!SupportsMultipleDisplays())
119 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
120 display_manager
->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED
);
121 display_manager
->SetMultiDisplayMode(DisplayManager::UNIFIED
);
123 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
124 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
126 UpdateDisplay("500x400");
127 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
128 widget
->GetNativeWindow()).ToString());
130 UpdateDisplay("500x400,600x400");
131 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
132 widget
->GetNativeWindow()).ToString());
134 // Move to the 2nd physical display. Shelf's display still should be
136 widget
->SetBounds(gfx::Rect(800, 0, 100, 100));
137 ASSERT_EQ("800,0 100x100", widget
->GetWindowBoundsInScreen().ToString());
139 EXPECT_EQ("0,0 500x400", ScreenUtil::GetShelfDisplayBoundsInScreen(
140 widget
->GetNativeWindow()).ToString());
142 UpdateDisplay("600x500");
143 EXPECT_EQ("0,0 600x500", ScreenUtil::GetShelfDisplayBoundsInScreen(
144 widget
->GetNativeWindow()).ToString());