blob: 7524b295f2bbea8b6cab56e0e5386f20f33dc044 [file] [log] [blame]
[email protected]f1853122012-06-27 16:21:261// 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.
4
[email protected]2e236a52012-06-27 22:21:475#include "ash/display/display_controller.h"
6#include "ash/display/multi_display_manager.h"
[email protected]f1853122012-06-27 16:21:267#include "ash/shell.h"
8#include "ash/shell_window_ids.h"
9#include "ash/test/ash_test_base.h"
10#include "ash/wm/window_util.h"
11#include "ui/aura/env.h"
12#include "ui/aura/root_window.h"
13#include "ui/aura/test/event_generator.h"
14#include "ui/aura/window.h"
15#include "ui/views/controls/menu/menu_controller.h"
16#include "ui/views/widget/widget.h"
17#include "ui/views/widget/widget_delegate.h"
18
19namespace ash {
20namespace {
21
22class TestDelegate : public views::WidgetDelegateView {
23 public:
24 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
25 virtual ~TestDelegate() {}
26
27 // Overridden from views::WidgetDelegate:
28 virtual views::View* GetContentsView() OVERRIDE {
29 return this;
30 }
31
32 virtual ui::ModalType GetModalType() const OVERRIDE {
33 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
34 }
35
36 private:
37 bool system_modal_;
38 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
39};
40
41views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
42 views::Widget* widget =
43 views::Widget::CreateWindowWithBounds(NULL, bounds);
44 widget->Show();
45 return widget;
46}
47
48views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
49 views::Widget* widget =
50 views::Widget::CreateWindowWithBounds(new TestDelegate(true), bounds);
51 widget->Show();
52 return widget;
53}
54
55aura::Window* GetModalContainer(aura::RootWindow* root_window) {
56 return Shell::GetContainer(
57 root_window,
58 ash::internal::kShellWindowId_SystemModalContainer);
59}
60
61} // namespace
62
63namespace test {
64class RootWindowControllerTest : public test::AshTestBase {
65 public:
66 RootWindowControllerTest() {}
67 virtual ~RootWindowControllerTest() {}
68
69 virtual void SetUp() OVERRIDE {
[email protected]2e236a52012-06-27 22:21:4770 internal::DisplayController::SetExtendedDesktopEnabled(true);
71 internal::DisplayController::SetVirtualScreenCoordinatesEnabled(true);
[email protected]f1853122012-06-27 16:21:2672 AshTestBase::SetUp();
73 }
74
75 virtual void TearDown() OVERRIDE {
76 AshTestBase::TearDown();
[email protected]2e236a52012-06-27 22:21:4777 internal::DisplayController::SetExtendedDesktopEnabled(false);
78 internal::DisplayController::SetVirtualScreenCoordinatesEnabled(false);
[email protected]f1853122012-06-27 16:21:2679 }
80
81 private:
82 DISALLOW_COPY_AND_ASSIGN(RootWindowControllerTest);
83};
84
85TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
[email protected]2e236a52012-06-27 22:21:4786 UpdateDisplay("0+0-600x600,600+0-500x500");
[email protected]f1853122012-06-27 16:21:2687 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]f1853122012-06-27 16:21:2688
89 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
90 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:0691 EXPECT_EQ("650,10 100x100", normal->GetWindowScreenBounds().ToString());
92 EXPECT_EQ("50,10 100x100",
93 normal->GetNativeView()->GetRootWindowBounds().ToString());
[email protected]f1853122012-06-27 16:21:2694
95 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
96 maximized->Maximize();
97 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
98#if !defined(OS_WIN)
99 // TODO(oshima): Window reports smaller screen size. Investigate why.
[email protected]8d625fb2012-07-18 16:40:06100 EXPECT_EQ("600,0 500x500", maximized->GetWindowScreenBounds().ToString());
101 EXPECT_EQ("0,0 500x500",
102 maximized->GetNativeView()->GetRootWindowBounds().ToString());
[email protected]f1853122012-06-27 16:21:26103#endif
104
105 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
106 minimized->Minimize();
107 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06108 EXPECT_EQ("800,10 100x100",
109 minimized->GetWindowScreenBounds().ToString());
[email protected]f1853122012-06-27 16:21:26110
111 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100));
112 fullscreen->SetFullscreen(true);
113 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
114#if !defined(OS_WIN)
115 // TODO(oshima): Window reports smaller screen size. Investigate why.
[email protected]8d625fb2012-07-18 16:40:06116 EXPECT_EQ("600,0 500x500",
117 fullscreen->GetWindowScreenBounds().ToString());
118 EXPECT_EQ("0,0 500x500",
119 fullscreen->GetNativeView()->GetRootWindowBounds().ToString());
[email protected]f1853122012-06-27 16:21:26120#endif
121
[email protected]2e236a52012-06-27 22:21:47122 UpdateDisplay("0+0-600x600");
[email protected]f1853122012-06-27 16:21:26123
124 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06125 EXPECT_EQ("50,10 100x100", normal->GetWindowScreenBounds().ToString());
126 EXPECT_EQ("50,10 100x100",
127 normal->GetNativeView()->GetRootWindowBounds().ToString());
[email protected]f1853122012-06-27 16:21:26128
[email protected]2e236a52012-06-27 22:21:47129 // Maximized area on primary display has 2px (given as
[email protected]f1853122012-06-27 16:21:26130 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
131 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06132 EXPECT_EQ("0,0 600x598",
133 maximized->GetWindowScreenBounds().ToString());
134 EXPECT_EQ("0,0 600x598",
135 maximized->GetNativeView()->GetRootWindowBounds().ToString());
[email protected]f1853122012-06-27 16:21:26136
137 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06138 EXPECT_EQ("200,10 100x100",
139 minimized->GetWindowScreenBounds().ToString());
[email protected]f1853122012-06-27 16:21:26140
141 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
142 EXPECT_TRUE(fullscreen->IsFullscreen());
[email protected]8d625fb2012-07-18 16:40:06143 EXPECT_EQ("0,0 600x600",
144 fullscreen->GetWindowScreenBounds().ToString());
145 EXPECT_EQ("0,0 600x600",
146 fullscreen->GetNativeView()->GetRootWindowBounds().ToString());
147
148 // Test if the restore bounds are correctly updated.
149 wm::RestoreWindow(maximized->GetNativeView());
150 EXPECT_EQ("100,10 100x100", maximized->GetWindowScreenBounds().ToString());
151 EXPECT_EQ("100,10 100x100",
152 maximized->GetNativeView()->GetRootWindowBounds().ToString());
153
154 fullscreen->SetFullscreen(false);
155 EXPECT_EQ("300,10 100x100",
156 fullscreen->GetWindowScreenBounds().ToString());
157 EXPECT_EQ("300,10 100x100",
158 fullscreen->GetNativeView()->GetRootWindowBounds().ToString());
[email protected]f1853122012-06-27 16:21:26159}
160
161TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
[email protected]2e236a52012-06-27 22:21:47162 UpdateDisplay("0+0-500x500,500+0-500x500");
[email protected]f1853122012-06-27 16:21:26163
164 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
165 // Emulate virtual screen coordinate system.
166 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
167 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
168
169 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
170 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
171 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
172
173 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
174 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
175 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
176 modal->GetNativeView()));
177 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
178
179 aura::test::EventGenerator generator_1st(root_windows[0]);
180 generator_1st.ClickLeftButton();
181 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
182
[email protected]2e236a52012-06-27 22:21:47183 UpdateDisplay("0+0-500x500");
[email protected]f1853122012-06-27 16:21:26184 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
185 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
186 generator_1st.ClickLeftButton();
187 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
188}
189
190} // namespace test
191} // namespace ash