1 // Copyright (c) 2012 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_ash.h"
7 #include "ash/display/display_controller.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/root_window.h"
16 #include "ui/aura/window.h"
17 #include "ui/views/widget/widget.h"
18 #include "ui/views/widget/widget_delegate.h"
23 typedef test::AshTestBase ScreenAshTest
;
25 TEST_F(ScreenAshTest
, Bounds
) {
26 UpdateDisplay("600x600,500x500");
27 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()->
28 SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
30 views::Widget
* primary
= views::Widget::CreateWindowWithContextAndBounds(
31 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
33 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
34 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
38 EXPECT_EQ("0,0 600x597",
39 ScreenAsh::GetMaximizedWindowBoundsInParent(
40 primary
->GetNativeView()).ToString());
41 if (Shell::IsLauncherPerDisplayEnabled()) {
42 EXPECT_EQ("0,0 500x452",
43 ScreenAsh::GetMaximizedWindowBoundsInParent(
44 secondary
->GetNativeView()).ToString());
46 EXPECT_EQ("0,0 500x500",
47 ScreenAsh::GetMaximizedWindowBoundsInParent(
48 secondary
->GetNativeView()).ToString());
52 EXPECT_EQ("0,0 600x600",
53 ScreenAsh::GetDisplayBoundsInParent(
54 primary
->GetNativeView()).ToString());
55 EXPECT_EQ("0,0 500x500",
56 ScreenAsh::GetDisplayBoundsInParent(
57 secondary
->GetNativeView()).ToString());
60 EXPECT_EQ("0,0 600x597",
61 ScreenAsh::GetDisplayWorkAreaBoundsInParent(
62 primary
->GetNativeView()).ToString());
63 if (Shell::IsLauncherPerDisplayEnabled()) {
64 EXPECT_EQ("0,0 500x452",
65 ScreenAsh::GetDisplayWorkAreaBoundsInParent(
66 secondary
->GetNativeView()).ToString());
68 EXPECT_EQ("0,0 500x500",
69 ScreenAsh::GetDisplayWorkAreaBoundsInParent(
70 secondary
->GetNativeView()).ToString());
74 // Test verifies a stable handling of secondary screen widget changes
75 // (crbug.com/226132).
76 TEST_F(ScreenAshTest
, StabilityTest
) {
77 UpdateDisplay("600x600,500x500");
78 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
79 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
80 EXPECT_EQ(Shell::GetAllRootWindows()[1],
81 secondary
->GetNativeView()->GetRootWindow());
83 secondary
->Maximize();
85 secondary
->SetFullscreen(true);
90 TEST_F(ScreenAshTest
, ConvertRect
) {
91 UpdateDisplay("600x600,500x500");
93 views::Widget
* primary
= views::Widget::CreateWindowWithContextAndBounds(
94 NULL
, CurrentContext(), gfx::Rect(10, 10, 100, 100));
96 views::Widget
* secondary
= views::Widget::CreateWindowWithContextAndBounds(
97 NULL
, CurrentContext(), gfx::Rect(610, 10, 100, 100));
102 ScreenAsh::ConvertRectFromScreen(
103 primary
->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString());
106 ScreenAsh::ConvertRectFromScreen(
107 secondary
->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString());
111 ScreenAsh::ConvertRectToScreen(
112 primary
->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString());
115 ScreenAsh::ConvertRectToScreen(
116 secondary
->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString());