blob: 70d9146c8b1e5451f6cfc5466c852d32327e7fb7 [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]f1853122012-06-27 16:21:2620#include "ui/aura/env.h"
21#include "ui/aura/root_window.h"
22#include "ui/aura/test/event_generator.h"
[email protected]dbf835d82012-09-11 18:23:0923#include "ui/aura/test/test_window_delegate.h"
24#include "ui/aura/test/test_windows.h"
[email protected]f1853122012-06-27 16:21:2625#include "ui/aura/window.h"
[email protected]dbf835d82012-09-11 18:23:0926#include "ui/aura/window_tracker.h"
[email protected]eff4c7f2013-08-13 01:45:5027#include "ui/keyboard/keyboard_switches.h"
[email protected]f1853122012-06-27 16:21:2628#include "ui/views/controls/menu/menu_controller.h"
29#include "ui/views/widget/widget.h"
30#include "ui/views/widget/widget_delegate.h"
31
[email protected]2ee2f5d2013-01-10 23:37:1632using aura::Window;
33using views::Widget;
34
[email protected]f1853122012-06-27 16:21:2635namespace ash {
36namespace {
37
38class TestDelegate : public views::WidgetDelegateView {
39 public:
40 explicit TestDelegate(bool system_modal) : system_modal_(system_modal) {}
41 virtual ~TestDelegate() {}
42
43 // Overridden from views::WidgetDelegate:
44 virtual views::View* GetContentsView() OVERRIDE {
45 return this;
46 }
47
48 virtual ui::ModalType GetModalType() const OVERRIDE {
49 return system_modal_ ? ui::MODAL_TYPE_SYSTEM : ui::MODAL_TYPE_NONE;
50 }
51
52 private:
53 bool system_modal_;
[email protected]0fbfa972013-10-02 19:23:3354
[email protected]f1853122012-06-27 16:21:2655 DISALLOW_COPY_AND_ASSIGN(TestDelegate);
56};
57
[email protected]792b9b12012-12-11 03:53:2758class DeleteOnBlurDelegate : public aura::test::TestWindowDelegate,
59 public aura::client::FocusChangeObserver {
[email protected]dbf835d82012-09-11 18:23:0960 public:
61 DeleteOnBlurDelegate() : window_(NULL) {}
62 virtual ~DeleteOnBlurDelegate() {}
63
[email protected]792b9b12012-12-11 03:53:2764 void SetWindow(aura::Window* window) {
65 window_ = window;
66 aura::client::SetFocusChangeObserver(window_, this);
67 }
[email protected]dbf835d82012-09-11 18:23:0968
[email protected]869f6352012-12-06 20:47:1769 private:
[email protected]dbf835d82012-09-11 18:23:0970 // aura::test::TestWindowDelegate overrides:
71 virtual bool CanFocus() OVERRIDE {
72 return true;
73 }
[email protected]dbf835d82012-09-11 18:23:0974
[email protected]792b9b12012-12-11 03:53:2775 // aura::client::FocusChangeObserver implementation:
76 virtual void OnWindowFocused(aura::Window* gained_focus,
77 aura::Window* lost_focus) OVERRIDE {
78 if (window_ == lost_focus)
79 delete window_;
[email protected]869f6352012-12-06 20:47:1780 }
81
[email protected]dbf835d82012-09-11 18:23:0982 aura::Window* window_;
83
84 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate);
85};
86
[email protected]eff4c7f2013-08-13 01:45:5087class ClickTestWindow : public views::WidgetDelegateView {
88 public:
89 ClickTestWindow() : mouse_presses_(0) {}
90 virtual ~ClickTestWindow() {}
91
92 // Overridden from views::WidgetDelegate:
93 virtual views::View* GetContentsView() OVERRIDE {
94 return this;
95 }
96
97 aura::Window* CreateTestWindowWithParent(aura::Window* parent) {
98 DCHECK(parent);
99 views::Widget* widget = Widget::CreateWindowWithParent(this, parent);
100 return widget->GetNativeView();
101 }
102
103 // Overridden from views::View:
104 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE {
105 mouse_presses_++;
106 return false;
107 }
108
109 int mouse_presses() const { return mouse_presses_; }
110
111 private:
112 int mouse_presses_;
113
114 DISALLOW_COPY_AND_ASSIGN(ClickTestWindow);
115};
116
[email protected]f1853122012-06-27 16:21:26117} // namespace
118
119namespace test {
[email protected]f1853122012-06-27 16:21:26120
[email protected]a2e6af12013-01-07 21:40:35121class RootWindowControllerTest : public test::AshTestBase {
122 public:
123 views::Widget* CreateTestWidget(const gfx::Rect& bounds) {
124 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
125 NULL, CurrentContext(), bounds);
126 widget->Show();
127 return widget;
128 }
129
130 views::Widget* CreateModalWidget(const gfx::Rect& bounds) {
131 views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds(
132 new TestDelegate(true), CurrentContext(), bounds);
133 widget->Show();
134 return widget;
135 }
136
137 views::Widget* CreateModalWidgetWithParent(const gfx::Rect& bounds,
138 gfx::NativeWindow parent) {
139 views::Widget* widget =
140 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
141 parent,
142 bounds);
143 widget->Show();
144 return widget;
145 }
146
147 aura::Window* GetModalContainer(aura::RootWindow* root_window) {
148 return Shell::GetContainer(
149 root_window,
150 ash::internal::kShellWindowId_SystemModalContainer);
151 }
152};
[email protected]f1853122012-06-27 16:21:26153
[email protected]e75642a2013-06-12 17:21:18154TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
155 if (!SupportsMultipleDisplays())
156 return;
[email protected]1c3f7002013-01-21 18:46:05157
[email protected]f634dd32012-07-23 22:49:07158 UpdateDisplay("600x600,500x500");
[email protected]f1853122012-06-27 16:21:26159 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
[email protected]431552c2012-10-23 00:38:33160 internal::RootWindowController* controller =
161 Shell::GetPrimaryRootWindowController();
[email protected]478c6c32013-03-09 02:50:58162 internal::ShelfLayoutManager* shelf_layout_manager =
163 controller->GetShelfLayoutManager();
164 shelf_layout_manager->SetAutoHideBehavior(
165 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
[email protected]f1853122012-06-27 16:21:26166
167 views::Widget* normal = CreateTestWidget(gfx::Rect(650, 10, 100, 100));
168 EXPECT_EQ(root_windows[1], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04169 EXPECT_EQ("650,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06170 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04171 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26172
173 views::Widget* maximized = CreateTestWidget(gfx::Rect(700, 10, 100, 100));
174 maximized->Maximize();
175 EXPECT_EQ(root_windows[1], maximized->GetNativeView()->GetRootWindow());
[email protected]f54effe2013-09-05 01:09:02176 EXPECT_EQ("600,0 500x453", maximized->GetWindowBoundsInScreen().ToString());
177 EXPECT_EQ("0,0 500x453",
[email protected]8c0ec432013-05-10 04:33:39178 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26179
180 views::Widget* minimized = CreateTestWidget(gfx::Rect(800, 10, 100, 100));
181 minimized->Minimize();
182 EXPECT_EQ(root_windows[1], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06183 EXPECT_EQ("800,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04184 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26185
186 views::Widget* fullscreen = CreateTestWidget(gfx::Rect(900, 10, 100, 100));
187 fullscreen->SetFullscreen(true);
188 EXPECT_EQ(root_windows[1], fullscreen->GetNativeView()->GetRootWindow());
[email protected]1a015382012-12-01 19:44:59189
[email protected]8d625fb2012-07-18 16:40:06190 EXPECT_EQ("600,0 500x500",
[email protected]e2f64d102012-07-19 19:17:04191 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06192 EXPECT_EQ("0,0 500x500",
[email protected]e2f64d102012-07-19 19:17:04193 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26194
[email protected]8f2f151412013-01-26 03:58:37195 views::Widget* unparented_control = new Widget;
196 Widget::InitParams params;
197 params.bounds = gfx::Rect(650, 10, 100, 100);
198 params.context = CurrentContext();
199 params.type = Widget::InitParams::TYPE_CONTROL;
200 unparented_control->Init(params);
201 EXPECT_EQ(root_windows[1],
202 unparented_control->GetNativeView()->GetRootWindow());
203 EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer,
204 unparented_control->GetNativeView()->parent()->id());
205
[email protected]95db9c12013-01-31 11:47:44206 aura::Window* panel = CreateTestWindowInShellWithDelegateAndType(
207 NULL, aura::client::WINDOW_TYPE_PANEL, 0, gfx::Rect(700, 100, 100, 100));
208 EXPECT_EQ(root_windows[1], panel->GetRootWindow());
209 EXPECT_EQ(internal::kShellWindowId_PanelContainer, panel->parent()->id());
210
[email protected]dbf835d82012-09-11 18:23:09211 // Make sure a window that will delete itself when losing focus
212 // will not crash.
213 aura::WindowTracker tracker;
214 DeleteOnBlurDelegate delete_on_blur_delegate;
[email protected]5ebe6102012-11-28 21:00:03215 aura::Window* d2 = CreateTestWindowInShellWithDelegate(
216 &delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100));
[email protected]792b9b12012-12-11 03:53:27217 delete_on_blur_delegate.SetWindow(d2);
[email protected]550543e2013-01-11 22:43:44218 aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2);
[email protected]dbf835d82012-09-11 18:23:09219 tracker.Add(d2);
220
[email protected]f634dd32012-07-23 22:49:07221 UpdateDisplay("600x600");
[email protected]f1853122012-06-27 16:21:26222
[email protected]dbf835d82012-09-11 18:23:09223 // d2 must have been deleted.
224 EXPECT_FALSE(tracker.Contains(d2));
225
[email protected]f1853122012-06-27 16:21:26226 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
[email protected]e2f64d102012-07-19 19:17:04227 EXPECT_EQ("50,10 100x100", normal->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06228 EXPECT_EQ("50,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04229 normal->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26230
[email protected]eefd51b22012-09-25 20:26:24231 // Maximized area on primary display has 3px (given as
[email protected]f1853122012-06-27 16:21:26232 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
[email protected]2a64b0a2013-07-23 23:15:54233
234 // First clear fullscreen status, since both fullscreen and maximized windows
235 // share the same desktop workspace, which cancels the shelf status.
236 fullscreen->SetFullscreen(false);
[email protected]f1853122012-06-27 16:21:26237 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
[email protected]7b675df612012-09-16 18:33:20238 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04239 maximized->GetWindowBoundsInScreen().ToString());
[email protected]7b675df612012-09-16 18:33:20240 EXPECT_EQ("0,0 600x597",
[email protected]e2f64d102012-07-19 19:17:04241 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]f1853122012-06-27 16:21:26242
[email protected]2a64b0a2013-07-23 23:15:54243 // Set fullscreen to true. In that case the 3px inset becomes invisible so
244 // the maximized window can also use the area fully.
245 fullscreen->SetFullscreen(true);
246 EXPECT_EQ(root_windows[0], maximized->GetNativeView()->GetRootWindow());
247 EXPECT_EQ("0,0 600x600",
248 maximized->GetWindowBoundsInScreen().ToString());
249 EXPECT_EQ("0,0 600x600",
250 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
251
[email protected]f1853122012-06-27 16:21:26252 EXPECT_EQ(root_windows[0], minimized->GetNativeView()->GetRootWindow());
[email protected]8d625fb2012-07-18 16:40:06253 EXPECT_EQ("200,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04254 minimized->GetWindowBoundsInScreen().ToString());
[email protected]f1853122012-06-27 16:21:26255
256 EXPECT_EQ(root_windows[0], fullscreen->GetNativeView()->GetRootWindow());
257 EXPECT_TRUE(fullscreen->IsFullscreen());
[email protected]8d625fb2012-07-18 16:40:06258 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04259 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06260 EXPECT_EQ("0,0 600x600",
[email protected]e2f64d102012-07-19 19:17:04261 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06262
263 // Test if the restore bounds are correctly updated.
[email protected]a41b4e12013-09-20 04:36:34264 wm::GetWindowState(maximized->GetNativeView())->Restore();
[email protected]e2f64d102012-07-19 19:17:04265 EXPECT_EQ("100,10 100x100", maximized->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06266 EXPECT_EQ("100,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04267 maximized->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8d625fb2012-07-18 16:40:06268
269 fullscreen->SetFullscreen(false);
270 EXPECT_EQ("300,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04271 fullscreen->GetWindowBoundsInScreen().ToString());
[email protected]8d625fb2012-07-18 16:40:06272 EXPECT_EQ("300,10 100x100",
[email protected]e2f64d102012-07-19 19:17:04273 fullscreen->GetNativeView()->GetBoundsInRootWindow().ToString());
[email protected]8f2f151412013-01-26 03:58:37274
275 // Test if the unparented widget has moved.
276 EXPECT_EQ(root_windows[0],
277 unparented_control->GetNativeView()->GetRootWindow());
278 EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer,
279 unparented_control->GetNativeView()->parent()->id());
[email protected]95db9c12013-01-31 11:47:44280
281 // Test if the panel has moved.
282 EXPECT_EQ(root_windows[0], panel->GetRootWindow());
283 EXPECT_EQ(internal::kShellWindowId_PanelContainer, panel->parent()->id());
[email protected]f1853122012-06-27 16:21:26284}
285
[email protected]e75642a2013-06-12 17:21:18286TEST_F(RootWindowControllerTest, MoveWindows_Modal) {
287 if (!SupportsMultipleDisplays())
288 return;
[email protected]1c3f7002013-01-21 18:46:05289
[email protected]f634dd32012-07-23 22:49:07290 UpdateDisplay("500x500,500x500");
[email protected]f1853122012-06-27 16:21:26291
292 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
293 // Emulate virtual screen coordinate system.
294 root_windows[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
295 root_windows[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
296
297 views::Widget* normal = CreateTestWidget(gfx::Rect(300, 10, 100, 100));
298 EXPECT_EQ(root_windows[0], normal->GetNativeView()->GetRootWindow());
299 EXPECT_TRUE(wm::IsActiveWindow(normal->GetNativeView()));
300
301 views::Widget* modal = CreateModalWidget(gfx::Rect(650, 10, 100, 100));
302 EXPECT_EQ(root_windows[1], modal->GetNativeView()->GetRootWindow());
303 EXPECT_TRUE(GetModalContainer(root_windows[1])->Contains(
304 modal->GetNativeView()));
305 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
306
307 aura::test::EventGenerator generator_1st(root_windows[0]);
308 generator_1st.ClickLeftButton();
309 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
310
[email protected]f634dd32012-07-23 22:49:07311 UpdateDisplay("500x500");
[email protected]f1853122012-06-27 16:21:26312 EXPECT_EQ(root_windows[0], modal->GetNativeView()->GetRootWindow());
313 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
314 generator_1st.ClickLeftButton();
315 EXPECT_TRUE(wm::IsActiveWindow(modal->GetNativeView()));
316}
317
[email protected]8674b312012-10-12 19:02:44318TEST_F(RootWindowControllerTest, ModalContainer) {
319 UpdateDisplay("600x600");
320 Shell* shell = Shell::GetInstance();
321 internal::RootWindowController* controller =
322 shell->GetPrimaryRootWindowController();
323 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29324 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]8674b312012-10-12 19:02:44325 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
326 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
327 controller->GetSystemModalLayoutManager(NULL));
328
[email protected]3b162e12012-11-09 11:52:35329 views::Widget* session_modal_widget =
330 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
331 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
332 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
333 controller->GetSystemModalLayoutManager(
334 session_modal_widget->GetNativeView()));
335
[email protected]fcb123d2013-04-17 15:58:49336 shell->session_state_delegate()->LockScreen();
[email protected]8674b312012-10-12 19:02:44337 EXPECT_EQ(user::LOGGED_IN_LOCKED,
[email protected]945f9cae2012-12-12 09:54:29338 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]8674b312012-10-12 19:02:44339 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
340 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
341 controller->GetSystemModalLayoutManager(NULL));
[email protected]3b162e12012-11-09 11:52:35342
343 aura::Window* lock_container =
344 Shell::GetContainer(controller->root_window(),
345 internal::kShellWindowId_LockScreenContainer);
346 views::Widget* lock_modal_widget =
347 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
348 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
349 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
350 controller->GetSystemModalLayoutManager(
351 lock_modal_widget->GetNativeView()));
352 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
353 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
354 controller->GetSystemModalLayoutManager(
355 session_modal_widget->GetNativeView()));
356
[email protected]fcb123d2013-04-17 15:58:49357 shell->session_state_delegate()->UnlockScreen();
[email protected]8674b312012-10-12 19:02:44358}
359
[email protected]1b219922012-11-13 21:16:43360TEST_F(RootWindowControllerTest, ModalContainerNotLoggedInLoggedIn) {
361 UpdateDisplay("600x600");
362 Shell* shell = Shell::GetInstance();
363
364 // Configure login screen environment.
365 SetUserLoggedIn(false);
366 EXPECT_EQ(user::LOGGED_IN_NONE,
[email protected]945f9cae2012-12-12 09:54:29367 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41368 EXPECT_EQ(0, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49369 EXPECT_FALSE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]1b219922012-11-13 21:16:43370
371 internal::RootWindowController* controller =
372 shell->GetPrimaryRootWindowController();
373 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
374 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
375 controller->GetSystemModalLayoutManager(NULL));
376
377 aura::Window* lock_container =
378 Shell::GetContainer(controller->root_window(),
379 internal::kShellWindowId_LockScreenContainer);
380 views::Widget* login_modal_widget =
381 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container);
382 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
383 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
384 controller->GetSystemModalLayoutManager(
385 login_modal_widget->GetNativeView()));
386 login_modal_widget->Close();
387
388 // Configure user session environment.
389 SetUserLoggedIn(true);
390 SetSessionStarted(true);
391 EXPECT_EQ(user::LOGGED_IN_USER,
[email protected]945f9cae2012-12-12 09:54:29392 shell->system_tray_delegate()->GetUserLoginStatus());
[email protected]c8d19f82013-05-18 09:09:41393 EXPECT_EQ(1, shell->session_state_delegate()->NumberOfLoggedInUsers());
[email protected]fcb123d2013-04-17 15:58:49394 EXPECT_TRUE(shell->session_state_delegate()->IsActiveUserSessionStarted());
[email protected]1b219922012-11-13 21:16:43395 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
396 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
397 controller->GetSystemModalLayoutManager(NULL));
398
399 views::Widget* session_modal_widget =
400 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
401 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
402 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
403 controller->GetSystemModalLayoutManager(
404 session_modal_widget->GetNativeView()));
405}
406
[email protected]a44afbbd2013-07-24 21:49:35407TEST_F(RootWindowControllerTest, ModalContainerBlockedSession) {
408 UpdateDisplay("600x600");
409 Shell* shell = Shell::GetInstance();
410 internal::RootWindowController* controller =
411 shell->GetPrimaryRootWindowController();
412 aura::Window* lock_container =
413 Shell::GetContainer(controller->root_window(),
414 internal::kShellWindowId_LockScreenContainer);
415 for (int block_reason = FIRST_BLOCK_REASON;
416 block_reason < NUMBER_OF_BLOCK_REASONS;
417 ++block_reason) {
418 views::Widget* session_modal_widget =
419 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
420 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
421 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
422 controller->GetSystemModalLayoutManager(
423 session_modal_widget->GetNativeView()));
424 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
425 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
426 controller->GetSystemModalLayoutManager(NULL));
427 session_modal_widget->Close();
428
429 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
430
431 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
432 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
433 controller->GetSystemModalLayoutManager(NULL));
434
435 views::Widget* lock_modal_widget =
436 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
437 lock_container);
438 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
439 internal::kShellWindowId_LockSystemModalContainer)->layout_manager(),
440 controller->GetSystemModalLayoutManager(
441 lock_modal_widget->GetNativeView()));
442
443 session_modal_widget =
444 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
445 EXPECT_EQ(Shell::GetContainer(controller->root_window(),
446 internal::kShellWindowId_SystemModalContainer)->layout_manager(),
447 controller->GetSystemModalLayoutManager(
448 session_modal_widget->GetNativeView()));
449 session_modal_widget->Close();
450
451 lock_modal_widget->Close();
452 UnblockUserSession();
453 }
454}
455
[email protected]e3bc88e2013-09-06 06:22:06456TEST_F(RootWindowControllerTest, GetTopmostFullscreenWindow) {
[email protected]2ee2f5d2013-01-10 23:37:16457 UpdateDisplay("600x600");
458 internal::RootWindowController* controller =
459 Shell::GetInstance()->GetPrimaryRootWindowController();
460
[email protected]700849f2013-04-30 17:49:20461 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16462 w1->Maximize();
[email protected]700849f2013-04-30 17:49:20463 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
464 w2->SetFullscreen(true);
465 // |w3| is a transient child of |w2|.
466 Widget* w3 = Widget::CreateWindowWithParentAndBounds(NULL,
467 w2->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
[email protected]2ee2f5d2013-01-10 23:37:16468
[email protected]e3bc88e2013-09-06 06:22:06469 // Test that GetTopmostFullscreenWindow() finds the fullscreen window when one
470 // of its transient children is active.
[email protected]700849f2013-04-30 17:49:20471 w3->Activate();
[email protected]e3bc88e2013-09-06 06:22:06472 EXPECT_EQ(w2->GetNativeWindow(), controller->GetTopmostFullscreenWindow());
[email protected]2ee2f5d2013-01-10 23:37:16473
[email protected]2a64b0a2013-07-23 23:15:54474 // Since there's only one desktop workspace, it always returns the same
475 // fullscreen window.
[email protected]700849f2013-04-30 17:49:20476 w1->Activate();
[email protected]e3bc88e2013-09-06 06:22:06477 EXPECT_EQ(w2->GetNativeWindow(), controller->GetTopmostFullscreenWindow());
478}
479
480TEST_F(RootWindowControllerTest, MultipleFullscreenWindows) {
481 UpdateDisplay("600x600");
482 internal::RootWindowController* controller =
483 Shell::GetInstance()->GetPrimaryRootWindowController();
484
485 Widget* w1 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
486 w1->Maximize();
487 Widget* w2 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
488 w2->SetFullscreen(true);
489 Widget* w3 = CreateTestWidget(gfx::Rect(0, 0, 100, 100));
490 w3->SetFullscreen(true);
491
492 // Test that GetTopmostFullscreenWindow() finds the active fullscreen window.
493 w2->Activate();
494 EXPECT_EQ(w2->GetNativeWindow(), controller->GetTopmostFullscreenWindow());
495 w3->Activate();
496 EXPECT_EQ(w3->GetNativeWindow(), controller->GetTopmostFullscreenWindow());
497
498 // If the active window is not fullscreen, it still returns the topmost
499 // fullscreen window, which is the last active one.
500 w1->Activate();
501 EXPECT_EQ(w3->GetNativeWindow(), controller->GetTopmostFullscreenWindow());
[email protected]2ee2f5d2013-01-10 23:37:16502}
503
[email protected]82ced2352013-07-19 20:49:06504// Test that user session window can't be focused if user session blocked by
505// some overlapping UI.
506TEST_F(RootWindowControllerTest, FocusBlockedWindow) {
507 UpdateDisplay("600x600");
508 internal::RootWindowController* controller =
509 Shell::GetInstance()->GetPrimaryRootWindowController();
510 aura::Window* lock_container =
511 Shell::GetContainer(controller->root_window(),
512 internal::kShellWindowId_LockScreenContainer);
513 aura::Window* lock_window = Widget::CreateWindowWithParentAndBounds(NULL,
514 lock_container, gfx::Rect(0, 0, 100, 100))->GetNativeView();
515 lock_window->Show();
516 aura::Window* session_window =
517 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
518 session_window->Show();
519
[email protected]a44afbbd2013-07-24 21:49:35520 for (int block_reason = FIRST_BLOCK_REASON;
521 block_reason < NUMBER_OF_BLOCK_REASONS;
522 ++block_reason) {
523 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
524 lock_window->Focus();
525 EXPECT_TRUE(lock_window->HasFocus());
526 session_window->Focus();
527 EXPECT_FALSE(session_window->HasFocus());
528 UnblockUserSession();
529 }
[email protected]82ced2352013-07-19 20:49:06530}
531
[email protected]0fbfa972013-10-02 19:23:33532// Tracks whether OnWindowDestroying() has been invoked.
533class DestroyedWindowObserver : public aura::WindowObserver {
534 public:
535 DestroyedWindowObserver() : destroyed_(false), window_(NULL) {}
536 virtual ~DestroyedWindowObserver() {
537 Shutdown();
538 }
539
540 void SetWindow(Window* window) {
541 window_ = window;
542 window->AddObserver(this);
543 }
544
545 bool destroyed() const { return destroyed_; }
546
547 // WindowObserver overrides:
548 virtual void OnWindowDestroying(Window* window) OVERRIDE {
549 destroyed_ = true;
550 Shutdown();
551 }
552
553 private:
554 void Shutdown() {
555 if (!window_)
556 return;
557 window_->RemoveObserver(this);
558 window_ = NULL;
559 }
560
561 bool destroyed_;
562 Window* window_;
563
564 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver);
565};
566
567// Verifies shutdown doesn't delete windows that are not owned by the parent.
568TEST_F(RootWindowControllerTest, DontDeleteWindowsNotOwnedByParent) {
569 DestroyedWindowObserver observer1;
570 aura::test::TestWindowDelegate delegate1;
571 aura::Window* window1 = new aura::Window(&delegate1);
572 window1->SetType(aura::client::WINDOW_TYPE_CONTROL);
573 window1->set_owned_by_parent(false);
574 observer1.SetWindow(window1);
575 window1->Init(ui::LAYER_NOT_DRAWN);
576 window1->SetDefaultParentByRootWindow(
577 Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
578
579 DestroyedWindowObserver observer2;
580 aura::Window* window2 = new aura::Window(NULL);
581 window2->set_owned_by_parent(false);
582 observer2.SetWindow(window2);
583 window2->Init(ui::LAYER_NOT_DRAWN);
584 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2);
585
586 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
587
588 ASSERT_FALSE(observer1.destroyed());
589 delete window1;
590
591 ASSERT_FALSE(observer2.destroyed());
592 delete window2;
593}
594
[email protected]cf6fea22013-08-07 14:24:01595typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest;
596
597// Make sure that an event handler exists for entire display area.
598TEST_F(NoSessionRootWindowControllerTest, Event) {
599 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
600 const gfx::Size size = root->bounds().size();
601 aura::Window* event_target = root->GetEventHandlerForPoint(gfx::Point(0, 0));
602 EXPECT_TRUE(event_target);
603 EXPECT_EQ(event_target,
604 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
605 EXPECT_EQ(event_target,
606 root->GetEventHandlerForPoint(gfx::Point(size.width() - 1, 0)));
607 EXPECT_EQ(event_target,
608 root->GetEventHandlerForPoint(gfx::Point(0, size.height() - 1)));
609 EXPECT_EQ(event_target,
610 root->GetEventHandlerForPoint(
611 gfx::Point(size.width() - 1, size.height() - 1)));
612}
613
[email protected]eff4c7f2013-08-13 01:45:50614class VirtualKeyboardRootWindowControllerTest : public test::AshTestBase {
615 public:
616 VirtualKeyboardRootWindowControllerTest() {};
617 virtual ~VirtualKeyboardRootWindowControllerTest() {};
618
619 virtual void SetUp() OVERRIDE {
620 CommandLine::ForCurrentProcess()->AppendSwitch(
621 keyboard::switches::kEnableVirtualKeyboard);
622 test::AshTestBase::SetUp();
623 }
624
625 private:
626 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest);
627};
628
[email protected]b6ba05d902013-10-04 21:38:45629// Test for http://crbug.com/297858. Virtual keyboard container should only show
630// on primary root window.
631TEST_F(VirtualKeyboardRootWindowControllerTest,
632 VirtualKeyboardOnPrimaryRootWindowOnly) {
633 if (!SupportsMultipleDisplays())
634 return;
635
636 UpdateDisplay("500x500,500x500");
637
638 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
639 aura::RootWindow* primary_root_window = Shell::GetPrimaryRootWindow();
640 aura::RootWindow* secondary_root_window =
641 root_windows[0] == primary_root_window ?
642 root_windows[1] : root_windows[0];
643
644 ASSERT_TRUE(Shell::GetContainer(
645 primary_root_window,
646 internal::kShellWindowId_VirtualKeyboardContainer));
647 ASSERT_FALSE(Shell::GetContainer(
648 secondary_root_window,
649 internal::kShellWindowId_VirtualKeyboardContainer));
650}
651
[email protected]eff4c7f2013-08-13 01:45:50652// Test for http://crbug.com/263599. Virtual keyboard should be able to receive
653// events at blocked user session.
654TEST_F(VirtualKeyboardRootWindowControllerTest,
655 ClickVirtualKeyboardInBlockedWindow) {
[email protected]b6ba05d902013-10-04 21:38:45656 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
[email protected]eff4c7f2013-08-13 01:45:50657 aura::Window* keyboard_container = Shell::GetContainer(root_window,
658 internal::kShellWindowId_VirtualKeyboardContainer);
659 ASSERT_TRUE(keyboard_container);
660 keyboard_container->Show();
661
662 ClickTestWindow* main_delegate = new ClickTestWindow();
663 scoped_ptr<aura::Window> keyboard_window(
664 main_delegate->CreateTestWindowWithParent(keyboard_container));
665 keyboard_container->layout_manager()->OnWindowResized();
666 keyboard_window->Show();
667 aura::test::EventGenerator event_generator(root_window,
668 keyboard_window.get());
669 event_generator.ClickLeftButton();
670 int expected_mouse_presses = 1;
671 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses());
672
673 for (int block_reason = FIRST_BLOCK_REASON;
674 block_reason < NUMBER_OF_BLOCK_REASONS;
675 ++block_reason) {
676 BlockUserSession(static_cast<UserSessionBlockReason>(block_reason));
677 event_generator.ClickLeftButton();
678 expected_mouse_presses++;
679 EXPECT_EQ(expected_mouse_presses, main_delegate->mouse_presses());
680 UnblockUserSession();
681 }
682}
683
[email protected]45c66672013-10-01 22:48:56684// Test for http://crbug.com/299787. RootWindowController should delete
685// the old container since the keyboard controller creates a new window in
686// GetWindowContainer().
687TEST_F(VirtualKeyboardRootWindowControllerTest,
688 DeleteOldContainerOnVirtualKeyboardInit) {
689 aura::RootWindow* root_window = ash::Shell::GetPrimaryRootWindow();
690 aura::Window* keyboard_container = Shell::GetContainer(root_window,
691 internal::kShellWindowId_VirtualKeyboardContainer);
692 ASSERT_TRUE(keyboard_container);
693 // Track the keyboard container window.
694 aura::WindowTracker tracker;
695 tracker.Add(keyboard_container);
696 // Mock a login state change to reinitialize the keyboard.
697 ash::Shell::GetInstance()->OnLoginStateChanged(user::LOGGED_IN_OWNER);
698 // keyboard_container should no longer be present.
699 EXPECT_FALSE(tracker.Contains(keyboard_container));
700}
701
[email protected]f1853122012-06-27 16:21:26702} // namespace test
703} // namespace ash