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/root_window_controller.h"
8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/wm/window_util.h"
13 #include "ui/aura/env.h"
14 #include "ui/aura/window.h"
15 #include "ui/aura/window_event_dispatcher.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_delegate.h"
22 typedef test::AshTestBase ScreenUtilTest
;
24 TEST_F(ScreenUtilTest
, Bounds
) {
25 if (!SupportsMultipleDisplays())
28 UpdateDisplay("600x600,500x500");
29 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
30 SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
32 views::Widget
* primary
= views::Widget::CreateWindowWithContextAndBounds(
33 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
35 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
36 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
40 EXPECT_EQ("0,0 600x597",
41 ScreenUtil::GetMaximizedWindowBoundsInParent(
42 primary
->GetNativeView()).ToString());
43 EXPECT_EQ("0,0 500x453",
44 ScreenUtil::GetMaximizedWindowBoundsInParent(
45 secondary
->GetNativeView()).ToString());
48 EXPECT_EQ("0,0 600x600",
49 ScreenUtil::GetDisplayBoundsInParent(
50 primary
->GetNativeView()).ToString());
51 EXPECT_EQ("0,0 500x500",
52 ScreenUtil::GetDisplayBoundsInParent(
53 secondary
->GetNativeView()).ToString());
56 EXPECT_EQ("0,0 600x597",
57 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
58 primary
->GetNativeView()).ToString());
59 EXPECT_EQ("0,0 500x453",
60 ScreenUtil::GetDisplayWorkAreaBoundsInParent(
61 secondary
->GetNativeView()).ToString());
64 // Test verifies a stable handling of secondary screen widget changes
65 // (crbug.com/226132).
66 TEST_F(ScreenUtilTest
, StabilityTest
) {
67 if (!SupportsMultipleDisplays())
70 UpdateDisplay("600x600,500x500");
71 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
72 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
73 EXPECT_EQ(Shell::GetAllRootWindows()[1],
74 secondary
->GetNativeView()->GetRootWindow());
76 secondary
->Maximize();
78 secondary
->SetFullscreen(true);
83 TEST_F(ScreenUtilTest
, ConvertRect
) {
84 if (!SupportsMultipleDisplays())
87 UpdateDisplay("600x600,500x500");
89 views::Widget
* primary
= views::Widget::CreateWindowWithContextAndBounds(
90 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
92 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
93 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
98 ScreenUtil::ConvertRectFromScreen(
99 primary
->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString());
102 ScreenUtil::ConvertRectFromScreen(
103 secondary
->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString());
107 ScreenUtil::ConvertRectToScreen(
108 primary
->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString());
111 ScreenUtil::ConvertRectToScreen(
112 secondary
->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString());