blob: 237a513a451ffbfa0d96fd141bfade232ed2234c [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]8674b312012-10-12 19:02:445#include "ash/root_window_controller.h"
6
[email protected]fcb123d2013-04-17 15:58:497#include "ash/session_state_delegate.h"
[email protected]478c6c32013-03-09 02:50:588#include "ash/shelf/shelf_layout_manager.h"
[email protected]f1853122012-06-27 16:21:269#include "ash/shell.h"
10#include "ash/shell_window_ids.h"
[email protected]8674b312012-10-12 19:02:4411#include "ash/system/tray/system_tray_delegate.h"
[email protected]f1853122012-06-27 16:21:2612#include "ash/test/ash_test_base.h"
[email protected]8674b312012-10-12 19:02:4413#include "ash/wm/system_modal_container_layout_manager.h"
[email protected]2ee2f5d2013-01-10 23:37:1614#include "ash/wm/window_properties.h"
[email protected]a41b4e12013-09-20 04:36:3415#include "ash/wm/window_state.h"
[email protected]f1853122012-06-27 16:21:2616#include "ash/wm/window_util.h"
[email protected]eff4c7f2013-08-13 01:45:5017#include "base/command_line.h"
[email protected]792b9b12012-12-11 03:53:2718#include "ui/aura/client/focus_change_observer.h"
[email protected]8cfb6722012-11-28 03:28:4619#include "ui/aura/client/focus_client.h"
[email protected]e3225e02013-10-23 20:44:3720#include "ui/aura/client/window_tree_client.h"
[email protected]f1853122012-06-27 16:21:2621#include "ui/aura/env.h"
22#include "ui/aura/root_window.h"
23#include "ui/aura/test/event_generator.h"
[email protected]647b4842013-12-12 14:24:2424#include "ui/aura/test/test_event_handler.h"
[email protected]dbf835d82012-09-11 18:23:0925#include "ui/aura/test/test_window_delegate.h"
26#include "ui/aura/test/test_windows.h"
[email protected]f1853122012-06-27 16:21:2627#include "ui/aura/window.h"
[email protected]dbf835d82012-09-11 18:23:0928#include "ui/aura/window_tracker.h"
[email protected]647b4842013-12-12 14:24:2429#include "ui/keyboard/keyboard_controller_proxy.h"
[email protected]eff4c7f2013-08-13 01:45:5030#include "ui/keyboard/keyboard_switches.h"
[email protected]f1853122012-06-27 16:21:2631#include "ui/views/controls/menu/menu_controller.h"
32#include "ui/views/widget/widget.h"
33#include "ui/views/widget/widget_delegate.h"
34
[email protected]2ee2f5d2013-01-10 23:37:1635using aura::Window;
36using views::Widget;
37
[email protected]f1853122012-06-27 16:21:2638namespace ash {
39namespace {
40
41class TestDelegate : public views::WidgetDelegateView {
42 public:
43 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
44 virtual ~TestDelegate() {}
45
46 // Overridden from views::WidgetDelegate:
47 virtual views::View* GetContentsView() OVERRIDE {
48 return this;
49 }
50
51 virtual ui::ModalType GetModalType() const OVERRIDE {
52 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
53 }
54
55 private:
56 bool system_modal_;
[email protected]0fbfa972013-10-02 19:23:3357
[email protected]f1853122012-06-27 16:21:2658 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
59};
60
[email protected]792b9b12012-12-11 03:53:2761class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate,
62 public aura::client::FocusChangeObserver {
[email protected]dbf835d82012-09-11 18:23:0963 public:
64 DeleteOnBlurDelegate() : window_(NULL) {}
65 virtual ~DeleteOnBlurDelegate() {}
66
[email protected]792b9b12012-12-11 03:53:2767 void SetWindow(aura::Window* window) {
68 window_ = window;
69 aura::client::SetFocusChangeObserver(window_, this);
70 }
[email protected]dbf835d82012-09-11 18:23:0971
[email protected]869f6352012-12-06 20:47:1772 private:
[email protected]dbf835d82012-09-11 18:23:0973 // aura::test::TestWindowDelegate overrides:
74 virtual bool CanFocus() OVERRIDE {
75 return true;
76 }
[email protected]dbf835d82012-09-11 18:23:0977
[email protected]792b9b12012-12-11 03:53:2778 // aura::client::FocusChangeObserver implementation:
79 virtual void OnWindowFocused(aura::Window* gained_focus,
80 aura::Window* lost_focus) OVERRIDE {
81 if (window_ == lost_focus)
82 delete window_;
[email protected]869f6352012-12-06 20:47:1783 }
84
[email protected]dbf835d82012-09-11 18:23:0985 aura::Window* window_;
86
87 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
88};
89
[email protected]f1853122012-06-27 16:21:2690} // namespace
91
92namespace test {
[email protected]f1853122012-06-27 16:21:2693
[email protected]a2e6af12013-01-07 21:40:3594class RootWindowControllerTest : public test::AshTestBase {
95 public:
96 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
97 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
98 NULL, CurrentContext(), bounds);
99 widget->Show();
100 return widget;
101 }
102
103 views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
104 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
105 new TestDelegate(true), CurrentContext(), bounds);
106 widget->Show();
107 return widget;
108 }
109
110 views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds,
111 gfx::NativeWindow parent) {
112 views::Widget* widget =
113 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
114 parent,
115 bounds);
116 widget->Show();
117 return widget;
118 }
119
[email protected]c9390bd2013-11-08 20:33:13120 aura::Window* GetModalContainer(aura::Window* root_window) {
[email protected]a2e6af12013-01-07 21:40:35121 return Shell::GetContainer(
122 root_window,
123 ash::internal::kShellWindowId_SystemModalContainer);
124 }
125};
[email protected]f1853122012-06-27 16:21:26126
[email protected]e75642a2013-06-12 17:21:18127TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
128 if (!SupportsMultipleDisplays())
129 return;
[email protected]1c3f7002013-01-21 18:46:05130
[email protected]f634dd32012-07-23 22:49:07131 UpdateDisplay("600x600,500x500");
[email protected]c9390bd2013-11-08 20:33:13132 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]431552c2012-10-23 00:38:33133 internal::RootWindowController* controller =
134 Shell::GetPrimaryRootWindowController();
[email protected]478c6c32013-03-09 02:50:58135 internal::ShelfLayoutManager* shelf_layout_manager =
136 controller->GetShelfLayoutManager();
137 shelf_layout_manager->SetAutoHideBehavior(
138 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
[email protected]f1853122012-06-27 16:21:26139
140 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
141 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04142 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06143 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04144 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26145
146 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
147 maximized->Maximize();
148 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
[email protected]f54effe2013-09-05 01:09:02149 EXPECT_EQ("600,0 500x453", maximized->GetWindowBoundsInScreen().ToString());
150 EXPECT_EQ("0,0 500x453",
[email protected]8c0ec432013-05-10 04:33:39151 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26152
153 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
154 minimized->Minimize();
155 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06156 EXPECT_EQ("800,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04157 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26158
159 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100));
160 fullscreen->SetFullscreen(true);
161 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
[email protected]1a015382012-12-01 19:44:59162
[email protected]8d625fb2012-07-18 16:40:06163 EXPECT_EQ("600,0 500x500",
[email protected]e2f64d102012-07-19 19:17:04164 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06165 EXPECT_EQ("0,0 500x500",
[email protected]e2f64d102012-07-19 19:17:04166 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26167
[email protected]8f2f151412013-01-26 03:58:37168 views::Widget* unparented_control = new Widget;
169 Widget::InitParams params;
170 params.bounds = gfx::Rect(650, 10, 100, 100);
171 params.context = CurrentContext();
172 params.type = Widget::InitParams::TYPE_CONTROL;
173 unparented_control->Init(params);
174 EXPECT_EQ(root_windows[1],
175 unparented_control->GetNativeView()->GetRootWindow());
176 EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer,
177 unparented_control->GetNativeView()->parent()->id());
178
[email protected]95db9c12013-01-31 11:47:44179 aura::Window* panel = CreateTestWindowInShellWithDelegateAndType(
180 NULL, aura::client::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100));
181 EXPECT_EQ(root_windows[1], panel->GetRootWindow());
182 EXPECT_EQ(internal::kShellWindowId_PanelContainer, panel->parent()->id());
183
[email protected]dbf835d82012-09-11 18:23:09184 // Make sure a window that will delete itself when losing focus
185 // will not crash.
186 aura::WindowTracker tracker;
187 DeleteOnBlurDelegate delete_on_blur_delegate;
[email protected]5ebe6102012-11-28 21:00:03188 aura::Window* d2 = CreateTestWindowInShellWithDelegate(
189 &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100));
[email protected]792b9b12012-12-11 03:53:27190 delete_on_blur_delegate.SetWindow(d2);
[email protected]550543e2013-01-11 22:43:44191 aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2);
[email protected]dbf835d82012-09-11 18:23:09192 tracker.Add(d2);
193
[email protected]f634dd32012-07-23 22:49:07194 UpdateDisplay("600x600");
[email protected]f1853122012-06-27 16:21:26195
[email protected]dbf835d82012-09-11 18:23:09196 // d2 must have been deleted.
197 EXPECT_FALSE(tracker.Contains(d2));
198
[email protected]f1853122012-06-27 16:21:26199 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04200 EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06201 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04202 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26203
[email protected]eefd51b22012-09-25 20:26:24204 // Maximized area on primary display has 3px (given as
[email protected]f1853122012-06-27 16:21:26205 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
[email protected]2a64b0a2013-07-23 23:15:54206
207 // First clear fullscreen status, since both fullscreen and maximized windows
208 // share the same desktop workspace, which cancels the shelf status.
209 fullscreen->SetFullscreen(false);
[email protected]f1853122012-06-27 16:21:26210 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]7b675df612012-09-16 18:33:20211 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04212 maximized->GetWindowBoundsInScreen().ToString());
[email protected]7b675df612012-09-16 18:33:20213 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04214 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26215
[email protected]2a64b0a2013-07-23 23:15:54216 // Set fullscreen to true. In that case the 3px inset becomes invisible so
217 // the maximized window can also use the area fully.
218 fullscreen->SetFullscreen(true);
219 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
220 EXPECT_EQ("0,0 600x600",
221 maximized->GetWindowBoundsInScreen().ToString());
222 EXPECT_EQ("0,0 600x600",
223 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
224
[email protected]f1853122012-06-27 16:21:26225 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06226 EXPECT_EQ("200,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04227 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26228
229 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
230 EXPECT_TRUE(fullscreen->IsFullscreen());
[email protected]8d625fb2012-07-18 16:40:06231 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04232 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06233 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04234 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06235
236 // Test if the restore bounds are correctly updated.
[email protected]a41b4e12013-09-20 04:36:34237 wm::GetWindowState(maximized->GetNativeView())->Restore();
[email protected]e2f64d102012-07-19 19:17:04238 EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06239 EXPECT_EQ("100,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04240 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06241
242 fullscreen->SetFullscreen(false);
243 EXPECT_EQ("300,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04244 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06245 EXPECT_EQ("300,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04246 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8f2f151412013-01-26 03:58:37247
248 // Test if the unparented widget has moved.
249 EXPECT_EQ(root_windows[0],
250 unparented_control->GetNativeView()->GetRootWindow());
251 EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer,
252 unparented_control->GetNativeView()->parent()->id());
[email protected]95db9c12013-01-31 11:47:44253
254 // Test if the panel has moved.
255 EXPECT_EQ(root_windows[0], panel->GetRootWindow());
256 EXPECT_EQ(internal::kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]f1853122012-06-27 16:21:26257}
258
[email protected]e75642a2013-06-12 17:21:18259TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
260 if (!SupportsMultipleDisplays())
261 return;
[email protected]1c3f7002013-01-21 18:46:05262
[email protected]f634dd32012-07-23 22:49:07263 UpdateDisplay("500x500,500x500");
[email protected]f1853122012-06-27 16:21:26264
[email protected]c9390bd2013-11-08 20:33:13265 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]f1853122012-06-27 16:21:26266 // Emulate virtual screen coordinate system.
267 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
268 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
269
270 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
271 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
272 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
273
274 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
275 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
276 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
277 modal->GetNativeView()));
278 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
279
280 aura::test::EventGenerator generator_1st(root_windows[0]);
281 generator_1st.ClickLeftButton();
282 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
283
[email protected]f634dd32012-07-23 22:49:07284 UpdateDisplay("500x500");
[email protected]f1853122012-06-27 16:21:26285 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
286 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
287 generator_1st.ClickLeftButton();
288 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
289}
290
[email protected]8674b312012-10-12 19:02:44291TEST_F(RootWindowControllerTest, ModalContainer) {
292 UpdateDisplay("600x600");
293 Shell* shell = Shell::GetInstance();
294 internal::RootWindowController* controller =
295 shell->GetPrimaryRootWindowController();
296 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29297 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]8674b312012-10-12 19:02:44298 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
299 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
300 controller->GetSystemModalLayoutManager(NULL));
301
[email protected]3b162e12012-11-09 11:52:35302 views::Widget* session_modal_widget =
303 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
304 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
305 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
306 controller->GetSystemModalLayoutManager(
307 session_modal_widget->GetNativeView()));
308
[email protected]fcb123d2013-04-17 15:58:49309 shell->session_state_delegate()->LockScreen();
[email protected]8674b312012-10-12 19:02:44310 EXPECT_EQ(user::LOGGED_IN_LOCKED,
[email protected]945f9cae2012-12-12 09:54:29311 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]8674b312012-10-12 19:02:44312 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
313 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
314 controller->GetSystemModalLayoutManager(NULL));
[email protected]3b162e12012-11-09 11:52:35315
316 aura::Window* lock_container =
317 Shell::GetContainer(controller->root_window(),
318 internal::kShellWindowId_LockScreenContainer);
319 views::Widget* lock_modal_widget =
320 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
321 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
322 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
323 controller->GetSystemModalLayoutManager(
324 lock_modal_widget->GetNativeView()));
325 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
326 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
327 controller->GetSystemModalLayoutManager(
328 session_modal_widget->GetNativeView()));
329
[email protected]fcb123d2013-04-17 15:58:49330 shell->session_state_delegate()->UnlockScreen();
[email protected]8674b312012-10-12 19:02:44331}
332
[email protected]1b219922012-11-13 21:16:43333TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
334 UpdateDisplay("600x600");
335 Shell* shell = Shell::GetInstance();
336
337 // Configure login screen environment.
338 SetUserLoggedIn(false);
339 EXPECT_EQ(user::LOGGED_IN_NONE,
[email protected]945f9cae2012-12-12 09:54:29340 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41341 EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49342 EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]1b219922012-11-13 21:16:43343
344 internal::RootWindowController* controller =
345 shell->GetPrimaryRootWindowController();
346 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
347 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
348 controller->GetSystemModalLayoutManager(NULL));
349
350 aura::Window* lock_container =
351 Shell::GetContainer(controller->root_window(),
352 internal::kShellWindowId_LockScreenContainer);
353 views::Widget* login_modal_widget =
354 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
355 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
356 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
357 controller->GetSystemModalLayoutManager(
358 login_modal_widget->GetNativeView()));
359 login_modal_widget->Close();
360
361 // Configure user session environment.
362 SetUserLoggedIn(true);
363 SetSessionStarted(true);
364 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29365 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41366 EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49367 EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]1b219922012-11-13 21:16:43368 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
369 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
370 controller->GetSystemModalLayoutManager(NULL));
371
372 views::Widget* session_modal_widget =
373 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
374 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
375 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
376 controller->GetSystemModalLayoutManager(
377 session_modal_widget->GetNativeView()));
378}
379
[email protected]a44afbbd2013-07-24 21:49:35380TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) {
381 UpdateDisplay("600x600");
382 Shell* shell = Shell::GetInstance();
383 internal::RootWindowController* controller =
384 shell->GetPrimaryRootWindowController();
385 aura::Window* lock_container =
386 Shell::GetContainer(controller->root_window(),
387 internal::kShellWindowId_LockScreenContainer);
388 for (int block_reason = FIRST_BLOCK_REASON;
389 block_reason < NUMBER_OF_BLOCK_REASONS;
390 ++block_reason) {
391 views::Widget* session_modal_widget =
392 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
393 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
394 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
395 controller->GetSystemModalLayoutManager(
396 session_modal_widget->GetNativeView()));
397 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
398 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
399 controller->GetSystemModalLayoutManager(NULL));
400 session_modal_widget->Close();
401
402 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
403
404 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
405 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
406 controller->GetSystemModalLayoutManager(NULL));
407
408 views::Widget* lock_modal_widget =
409 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
410 lock_container);
411 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
412 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
413 controller->GetSystemModalLayoutManager(
414 lock_modal_widget->GetNativeView()));
415
416 session_modal_widget =
417 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
418 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
419 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
420 controller->GetSystemModalLayoutManager(
421 session_modal_widget->GetNativeView()));
422 session_modal_widget->Close();
423
424 lock_modal_widget->Close();
425 UnblockUserSession();
426 }
427}
428
[email protected]2c9171d22013-12-10 21:55:10429TEST_F(RootWindowControllerTest, GetWindowForFullscreenMode) {
[email protected]2ee2f5d2013-01-10 23:37:16430 UpdateDisplay("600x600");
431 internal::RootWindowController* controller =
432 Shell::GetInstance()->GetPrimaryRootWindowController();
433
[email protected]700849f2013-04-30 17:49:20434 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16435 w1->Maximize();
[email protected]700849f2013-04-30 17:49:20436 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
437 w2->SetFullscreen(true);
438 // |w3| is a transient child of |w2|.
439 Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL,
440 w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16441
[email protected]2c9171d22013-12-10 21:55:10442 // Test that GetWindowForFullscreenMode() finds the fullscreen window when one
[email protected]e3bc88e2013-09-06 06:22:06443 // of its transient children is active.
[email protected]700849f2013-04-30 17:49:20444 w3->Activate();
[email protected]2c9171d22013-12-10 21:55:10445 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16446
[email protected]2c9171d22013-12-10 21:55:10447 // If the topmost window is not fullscreen, it returns NULL.
[email protected]700849f2013-04-30 17:49:20448 w1->Activate();
[email protected]2c9171d22013-12-10 21:55:10449 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
450 w1->Close();
451 w3->Close();
[email protected]e3bc88e2013-09-06 06:22:06452
[email protected]2c9171d22013-12-10 21:55:10453 // Only w2 remains, if minimized GetWindowForFullscreenMode should return
454 // NULL.
[email protected]e3bc88e2013-09-06 06:22:06455 w2->Activate();
[email protected]2c9171d22013-12-10 21:55:10456 EXPECT_EQ(w2->GetNativeWindow(), controller->GetWindowForFullscreenMode());
457 w2->Minimize();
458 EXPECT_EQ(NULL, controller->GetWindowForFullscreenMode());
[email protected]2ee2f5d2013-01-10 23:37:16459}
460
[email protected]82ced2352013-07-19 20:49:06461// Test that user session window can't be focused if user session blocked by
462// some overlapping UI.
463TEST_F(RootWindowControllerTest, FocusBlockedWindow) {
464 UpdateDisplay("600x600");
465 internal::RootWindowController* controller =
466 Shell::GetInstance()->GetPrimaryRootWindowController();
467 aura::Window* lock_container =
468 Shell::GetContainer(controller->root_window(),
469 internal::kShellWindowId_LockScreenContainer);
470 aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL,
471 lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView();
472 lock_window->Show();
473 aura::Window* session_window =
474 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
475 session_window->Show();
476
[email protected]a44afbbd2013-07-24 21:49:35477 for (int block_reason = FIRST_BLOCK_REASON;
478 block_reason < NUMBER_OF_BLOCK_REASONS;
479 ++block_reason) {
480 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
481 lock_window->Focus();
482 EXPECT_TRUE(lock_window->HasFocus());
483 session_window->Focus();
484 EXPECT_FALSE(session_window->HasFocus());
485 UnblockUserSession();
486 }
[email protected]82ced2352013-07-19 20:49:06487}
488
[email protected]0fbfa972013-10-02 19:23:33489// Tracks whether OnWindowDestroying() has been invoked.
490class DestroyedWindowObserver : public aura::WindowObserver {
491 public:
492 DestroyedWindowObserver() : destroyed_(false), window_(NULL) {}
493 virtual ~DestroyedWindowObserver() {
494 Shutdown();
495 }
496
497 void SetWindow(Window* window) {
498 window_ = window;
499 window->AddObserver(this);
500 }
501
502 bool destroyed() const { return destroyed_; }
503
504 // WindowObserver overrides:
505 virtual void OnWindowDestroying(Window* window) OVERRIDE {
506 destroyed_ = true;
507 Shutdown();
508 }
509
510 private:
511 void Shutdown() {
512 if (!window_)
513 return;
514 window_->RemoveObserver(this);
515 window_ = NULL;
516 }
517
518 bool destroyed_;
519 Window* window_;
520
521 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver);
522};
523
524// Verifies shutdown doesn't delete windows that are not owned by the parent.
525TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) {
526 DestroyedWindowObserver observer1;
527 aura::test::TestWindowDelegate delegate1;
528 aura::Window* window1 = new aura::Window(&delegate1);
529 window1->SetType(aura::client::WINDOW_TYPE_CONTROL);
530 window1->set_owned_by_parent(false);
531 observer1.SetWindow(window1);
532 window1->Init(ui::LAYER_NOT_DRAWN);
[email protected]e3225e02013-10-23 20:44:37533 aura::client::ParentWindowWithContext(
534 window1, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
[email protected]0fbfa972013-10-02 19:23:33535
536 DestroyedWindowObserver observer2;
537 aura::Window* window2 = new aura::Window(NULL);
538 window2->set_owned_by_parent(false);
539 observer2.SetWindow(window2);
540 window2->Init(ui::LAYER_NOT_DRAWN);
541 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2);
542
543 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
544
545 ASSERT_FALSE(observer1.destroyed());
546 delete window1;
547
548 ASSERT_FALSE(observer2.destroyed());
549 delete window2;
550}
551
[email protected]cf6fea22013-08-07 14:24:01552typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest;
553
554// Make sure that an event handler exists for entire display area.
555TEST_F(NoSessionRootWindowControllerTest, Event) {
[email protected]bf9cdb362013-10-25 19:22:45556 aura::Window* root = Shell::GetPrimaryRootWindow();
[email protected]cf6fea22013-08-07 14:24:01557 const gfx::Size size = root->bounds().size();
558 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0));
559 EXPECT_TRUE(event_target);
560 EXPECT_EQ(event_target,
561 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
562 EXPECT_EQ(event_target,
563 root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0)));
564 EXPECT_EQ(event_target,
565 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
566 EXPECT_EQ(event_target,
567 root->GetEventHandlerForPoint(
568 gfx::Point(size.width() - 1, size.height() - 1)));
569}
570
[email protected]eff4c7f2013-08-13 01:45:50571class VirtualKeyboardRootWindowControllerTest : public test::AshTestBase {
572 public:
573 VirtualKeyboardRootWindowControllerTest() {};
574 virtual ~VirtualKeyboardRootWindowControllerTest() {};
575
576 virtual void SetUp() OVERRIDE {
577 CommandLine::ForCurrentProcess()->AppendSwitch(
578 keyboard::switches::kEnableVirtualKeyboard);
579 test::AshTestBase::SetUp();
[email protected]24ca45d2013-10-25 03:37:44580 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
581 Shell::GetInstance()->keyboard_controller());
[email protected]eff4c7f2013-08-13 01:45:50582 }
583
584 private:
585 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest);
586};
587
[email protected]b6ba05d902013-10-04 21:38:45588// Test for http://crbug.com/297858. Virtual keyboard container should only show
589// on primary root window.
590TEST_F(VirtualKeyboardRootWindowControllerTest,
591 VirtualKeyboardOnPrimaryRootWindowOnly) {
592 if (!SupportsMultipleDisplays())
593 return;
594
595 UpdateDisplay("500x500,500x500");
596
[email protected]c9390bd2013-11-08 20:33:13597 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
[email protected]bf9cdb362013-10-25 19:22:45598 aura::Window* primary_root_window = Shell::GetPrimaryRootWindow();
599 aura::Window* secondary_root_window =
[email protected]b6ba05d902013-10-04 21:38:45600 root_windows[0] == primary_root_window ?
601 root_windows[1] : root_windows[0];
602
603 ASSERT_TRUE(Shell::GetContainer(
604 primary_root_window,
605 internal::kShellWindowId_VirtualKeyboardContainer));
606 ASSERT_FALSE(Shell::GetContainer(
607 secondary_root_window,
608 internal::kShellWindowId_VirtualKeyboardContainer));
609}
610
[email protected]eff4c7f2013-08-13 01:45:50611// Test for http://crbug.com/263599. Virtual keyboard should be able to receive
612// events at blocked user session.
613TEST_F(VirtualKeyboardRootWindowControllerTest,
614 ClickVirtualKeyboardInBlockedWindow) {
[email protected]bf9cdb362013-10-25 19:22:45615 aura::Window* root_window = Shell::GetPrimaryRootWindow();
[email protected]eff4c7f2013-08-13 01:45:50616 aura::Window* keyboard_container = Shell::GetContainer(root_window,
617 internal::kShellWindowId_VirtualKeyboardContainer);
618 ASSERT_TRUE(keyboard_container);
619 keyboard_container->Show();
620
[email protected]647b4842013-12-12 14:24:24621 aura::Window* keyboard_window = Shell::GetInstance()->keyboard_controller()->
622 proxy()->GetKeyboardWindow();
623 keyboard_container->AddChild(keyboard_window);
624 keyboard_window->SetBounds(gfx::Rect());
[email protected]eff4c7f2013-08-13 01:45:50625 keyboard_window->Show();
[email protected]647b4842013-12-12 14:24:24626
627 aura::test::TestEventHandler* handler = new aura::test::TestEventHandler;
628 root_window->SetEventFilter(handler);
629
630 aura::test::EventGenerator event_generator(root_window, keyboard_window);
[email protected]eff4c7f2013-08-13 01:45:50631 event_generator.ClickLeftButton();
632 int expected_mouse_presses = 1;
[email protected]647b4842013-12-12 14:24:24633 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50634
635 for (int block_reason = FIRST_BLOCK_REASON;
636 block_reason < NUMBER_OF_BLOCK_REASONS;
637 ++block_reason) {
638 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
639 event_generator.ClickLeftButton();
640 expected_mouse_presses++;
[email protected]647b4842013-12-12 14:24:24641 EXPECT_EQ(expected_mouse_presses, handler->num_mouse_events() / 2);
[email protected]eff4c7f2013-08-13 01:45:50642 UnblockUserSession();
643 }
644}
645
[email protected]45c66672013-10-01 22:48:56646// Test for http://crbug.com/299787. RootWindowController should delete
647// the old container since the keyboard controller creates a new window in
648// GetWindowContainer().
649TEST_F(VirtualKeyboardRootWindowControllerTest,
650 DeleteOldContainerOnVirtualKeyboardInit) {
[email protected]bf9cdb362013-10-25 19:22:45651 aura::Window* root_window = ash::Shell::GetPrimaryRootWindow();
[email protected]45c66672013-10-01 22:48:56652 aura::Window* keyboard_container = Shell::GetContainer(root_window,
653 internal::kShellWindowId_VirtualKeyboardContainer);
654 ASSERT_TRUE(keyboard_container);
655 // Track the keyboard container window.
656 aura::WindowTracker tracker;
657 tracker.Add(keyboard_container);
[email protected]51f438112013-11-18 19:32:50658 // Mock a login user profile change to reinitialize the keyboard.
659 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
[email protected]45c66672013-10-01 22:48:56660 // keyboard_container should no longer be present.
661 EXPECT_FALSE(tracker.Contains(keyboard_container));
662}
663
[email protected]f1853122012-06-27 16:21:26664} // namespace test
665} // namespace ash