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 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 ScreenAsh::GetMaximizedWindowBoundsInParent(
43 primary
->GetNativeView()).ToString());
44 EXPECT_EQ("0,0 500x452",
45 ScreenAsh::GetMaximizedWindowBoundsInParent(
46 secondary
->GetNativeView()).ToString());
49 EXPECT_EQ("0,0 600x600",
50 ScreenAsh::GetDisplayBoundsInParent(
51 primary
->GetNativeView()).ToString());
52 EXPECT_EQ("0,0 500x500",
53 ScreenAsh::GetDisplayBoundsInParent(
54 secondary
->GetNativeView()).ToString());
57 EXPECT_EQ("0,0 600x597",
58 ScreenAsh::GetDisplayWorkAreaBoundsInParent(
59 primary
->GetNativeView()).ToString());
60 EXPECT_EQ("0,0 500x452",
61 ScreenAsh::GetDisplayWorkAreaBoundsInParent(
62 secondary
->GetNativeView()).ToString());
65 // Test verifies a stable handling of secondary screen widget changes
66 // (crbug.com/226132).
67 TEST_F(ScreenAshTest
, 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(ScreenAshTest
, 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 ScreenAsh::ConvertRectFromScreen(
100 primary
->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString());
103 ScreenAsh::ConvertRectFromScreen(
104 secondary
->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString());
108 ScreenAsh::ConvertRectToScreen(
109 primary
->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString());
112 ScreenAsh::ConvertRectToScreen(
113 secondary
->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString());