blob: 67842f0f531d1e74d584bd21b986acf22f025d8b [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"
[email protected]dbf835d82012-09-11 18:23:0912#include "ui/aura/focus_manager.h"
[email protected]f1853122012-06-27 16:21:2613#include "ui/aura/root_window.h"
14#include "ui/aura/test/event_generator.h"
[email protected]dbf835d82012-09-11 18:23:0915#include "ui/aura/test/test_window_delegate.h"
16#include "ui/aura/test/test_windows.h"
[email protected]f1853122012-06-27 16:21:2617#include "ui/aura/window.h"
[email protected]dbf835d82012-09-11 18:23:0918#include "ui/aura/window_tracker.h"
[email protected]f1853122012-06-27 16:21:2619#include "ui/views/controls/menu/menu_controller.h"
20#include "ui/views/widget/widget.h"
21#include "ui/views/widget/widget_delegate.h"
22
23namespace ash {
24namespace {
25
26class TestDelegate : public views::WidgetDelegateView {
27 public:
28 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
29 virtual ~TestDelegate() {}
30
31 // Overridden from views::WidgetDelegate:
32 virtual views::View* GetContentsView() OVERRIDE {
33 return this;
34 }
35
36 virtual ui::ModalType GetModalType() const OVERRIDE {
37 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
38 }
39
40 private:
41 bool system_modal_;
42 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
43};
44
[email protected]dbf835d82012-09-11 18:23:0945class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate {
46 public:
47 DeleteOnBlurDelegate() : window_(NULL) {}
48 virtual ~DeleteOnBlurDelegate() {}
49
50 void set_window(aura::Window* window) { window_ = window; }
51
52 // aura::test::TestWindowDelegate overrides:
53 virtual bool CanFocus() OVERRIDE {
54 return true;
55 }
56 virtual void OnBlur() OVERRIDE {
57 delete window_;
58 }
59
60 private:
61 aura::Window* window_;
62
63 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
64};
65
[email protected]f1853122012-06-27 16:21:2666views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
67 views::Widget* widget =
68 views::Widget::CreateWindowWithBounds(NULL, bounds);
69 widget->Show();
70 return widget;
71}
72
73views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
74 views::Widget* widget =
75 views::Widget::CreateWindowWithBounds(new TestDelegate(true), bounds);
76 widget->Show();
77 return widget;
78}
79
80aura::Window* GetModalContainer(aura::RootWindow* root_window) {
81 return Shell::GetContainer(
82 root_window,
83 ash::internal::kShellWindowId_SystemModalContainer);
84}
85
86} // namespace
87
88namespace test {
[email protected]f1853122012-06-27 16:21:2689
[email protected]3e4351b2012-08-09 04:04:1690typedef test::AshTestBase RootWindowControllerTest;
[email protected]f1853122012-06-27 16:21:2691
92TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
[email protected]f634dd32012-07-23 22:49:0793 UpdateDisplay("600x600,500x500");
[email protected]f1853122012-06-27 16:21:2694 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]eefd51b22012-09-25 20:26:2495 ash::Shell::GetInstance()->SetShelfAutoHideBehavior(
96 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
[email protected]f1853122012-06-27 16:21:2697
98 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
99 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04100 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06101 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04102 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26103
104 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
105 maximized->Maximize();
106 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
107#if !defined(OS_WIN)
108 // TODO(oshima): Window reports smaller screen size. Investigate why.
[email protected]e2f64d102012-07-19 19:17:04109 EXPECT_EQ("600,0 500x500", maximized->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06110 EXPECT_EQ("0,0 500x500",
[email protected]e2f64d102012-07-19 19:17:04111 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26112#endif
113
114 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
115 minimized->Minimize();
116 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06117 EXPECT_EQ("800,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04118 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26119
120 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100));
121 fullscreen->SetFullscreen(true);
122 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
123#if !defined(OS_WIN)
124 // TODO(oshima): Window reports smaller screen size. Investigate why.
[email protected]8d625fb2012-07-18 16:40:06125 EXPECT_EQ("600,0 500x500",
[email protected]e2f64d102012-07-19 19:17:04126 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06127 EXPECT_EQ("0,0 500x500",
[email protected]e2f64d102012-07-19 19:17:04128 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26129#endif
130
[email protected]dbf835d82012-09-11 18:23:09131 // Make sure a window that will delete itself when losing focus
132 // will not crash.
133 aura::WindowTracker tracker;
134 DeleteOnBlurDelegate delete_on_blur_delegate;
135 aura::Window* d2 = aura::test::CreateTestWindowWithDelegate(
136 &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100), NULL);
137 delete_on_blur_delegate.set_window(d2);
138 root_windows[0]->GetFocusManager()->SetFocusedWindow(
139 d2, NULL);
140 tracker.Add(d2);
141
[email protected]f634dd32012-07-23 22:49:07142 UpdateDisplay("600x600");
[email protected]f1853122012-06-27 16:21:26143
[email protected]dbf835d82012-09-11 18:23:09144 // d2 must have been deleted.
145 EXPECT_FALSE(tracker.Contains(d2));
146
[email protected]f1853122012-06-27 16:21:26147 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04148 EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06149 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04150 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26151
[email protected]eefd51b22012-09-25 20:26:24152 // Maximized area on primary display has 3px (given as
[email protected]f1853122012-06-27 16:21:26153 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
154 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]7b675df612012-09-16 18:33:20155 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04156 maximized->GetWindowBoundsInScreen().ToString());
[email protected]7b675df612012-09-16 18:33:20157 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04158 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26159
160 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06161 EXPECT_EQ("200,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04162 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26163
164 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
165 EXPECT_TRUE(fullscreen->IsFullscreen());
[email protected]8d625fb2012-07-18 16:40:06166 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04167 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06168 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04169 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06170
171 // Test if the restore bounds are correctly updated.
172 wm::RestoreWindow(maximized->GetNativeView());
[email protected]e2f64d102012-07-19 19:17:04173 EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06174 EXPECT_EQ("100,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04175 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06176
177 fullscreen->SetFullscreen(false);
178 EXPECT_EQ("300,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04179 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06180 EXPECT_EQ("300,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04181 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26182}
183
184TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
[email protected]f634dd32012-07-23 22:49:07185 UpdateDisplay("500x500,500x500");
[email protected]f1853122012-06-27 16:21:26186
187 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
188 // Emulate virtual screen coordinate system.
189 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
190 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
191
192 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
193 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
194 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
195
196 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
197 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
198 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
199 modal->GetNativeView()));
200 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
201
202 aura::test::EventGenerator generator_1st(root_windows[0]);
203 generator_1st.ClickLeftButton();
204 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
205
[email protected]f634dd32012-07-23 22:49:07206 UpdateDisplay("500x500");
[email protected]f1853122012-06-27 16:21:26207 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
208 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
209 generator_1st.ClickLeftButton();
210 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
211}
212
213} // namespace test
214} // namespace ash