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/root_window_controller.h"
7 #include "ash/session_state_delegate.h"
8 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shell_window_ids.h"
11 #include "ash/system/tray/system_tray_delegate.h"
12 #include "ash/test/ash_test_base.h"
13 #include "ash/wm/system_modal_container_layout_manager.h"
14 #include "ash/wm/window_properties.h"
15 #include "ash/wm/window_state.h"
16 #include "ash/wm/window_util.h"
17 #include "base/command_line.h"
18 #include "ui/aura/client/focus_change_observer.h"
19 #include "ui/aura/client/focus_client.h"
20 #include "ui/aura/client/window_tree_client.h"
21 #include "ui/aura/env.h"
22 #include "ui/aura/test/event_generator.h"
23 #include "ui/aura/test/test_event_handler.h"
24 #include "ui/aura/test/test_window_delegate.h"
25 #include "ui/aura/test/test_windows.h"
26 #include "ui/aura/window.h"
27 #include "ui/aura/window_event_dispatcher.h"
28 #include "ui/aura/window_tracker.h"
29 #include "ui/keyboard/keyboard_controller_proxy.h"
30 #include "ui/keyboard/keyboard_switches.h"
31 #include "ui/views/controls/menu/menu_controller.h"
32 #include "ui/views/widget/widget.h"
33 #include "ui/views/widget/widget_delegate.h"
41 class TestDelegate
: public views::WidgetDelegateView
{
43 explicit TestDelegate(bool system_modal
) : system_modal_(system_modal
) {}
44 virtual ~TestDelegate() {}
46 // Overridden from views::WidgetDelegate:
47 virtual views::View
* GetContentsView() OVERRIDE
{
51 virtual ui::ModalType
GetModalType() const OVERRIDE
{
52 return system_modal_
? ui::MODAL_TYPE_SYSTEM
: ui::MODAL_TYPE_NONE
;
58 DISALLOW_COPY_AND_ASSIGN(TestDelegate
);
61 class DeleteOnBlurDelegate
: public aura::test::TestWindowDelegate
,
62 public aura::client::FocusChangeObserver
{
64 DeleteOnBlurDelegate() : window_(NULL
) {}
65 virtual ~DeleteOnBlurDelegate() {}
67 void SetWindow(aura::Window
* window
) {
69 aura::client::SetFocusChangeObserver(window_
, this);
73 // aura::test::TestWindowDelegate overrides:
74 virtual bool CanFocus() OVERRIDE
{
78 // aura::client::FocusChangeObserver implementation:
79 virtual void OnWindowFocused(aura::Window
* gained_focus
,
80 aura::Window
* lost_focus
) OVERRIDE
{
81 if (window_
== lost_focus
)
85 aura::Window
* window_
;
87 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate
);
94 class RootWindowControllerTest
: public test::AshTestBase
{
96 views::Widget
* CreateTestWidget(const gfx::Rect
& bounds
) {
97 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
98 NULL
, CurrentContext(), bounds
);
103 views::Widget
* CreateModalWidget(const gfx::Rect
& bounds
) {
104 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
105 new TestDelegate(true), CurrentContext(), bounds
);
110 views::Widget
* CreateModalWidgetWithParent(const gfx::Rect
& bounds
,
111 gfx::NativeWindow parent
) {
112 views::Widget
* widget
=
113 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
120 aura::Window
* GetModalContainer(aura::Window
* root_window
) {
121 return Shell::GetContainer(
123 ash::internal::kShellWindowId_SystemModalContainer
);
127 TEST_F(RootWindowControllerTest
, MoveWindows_Basic
) {
128 if (!SupportsMultipleDisplays())
130 // Windows origin should be doubled when moved to the 1st display.
131 UpdateDisplay("600x600,300x300");
132 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
133 internal::RootWindowController
* controller
=
134 Shell::GetPrimaryRootWindowController();
135 internal::ShelfLayoutManager
* shelf_layout_manager
=
136 controller
->GetShelfLayoutManager();
137 shelf_layout_manager
->SetAutoHideBehavior(
138 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
140 views::Widget
* normal
= CreateTestWidget(gfx::Rect(650, 10, 100, 100));
141 EXPECT_EQ(root_windows
[1], normal
->GetNativeView()->GetRootWindow());
142 EXPECT_EQ("650,10 100x100", normal
->GetWindowBoundsInScreen().ToString());
143 EXPECT_EQ("50,10 100x100",
144 normal
->GetNativeView()->GetBoundsInRootWindow().ToString());
146 views::Widget
* maximized
= CreateTestWidget(gfx::Rect(700, 10, 100, 100));
147 maximized
->Maximize();
148 EXPECT_EQ(root_windows
[1], maximized
->GetNativeView()->GetRootWindow());
149 EXPECT_EQ("600,0 300x253", maximized
->GetWindowBoundsInScreen().ToString());
150 EXPECT_EQ("0,0 300x253",
151 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
153 views::Widget
* minimized
= CreateTestWidget(gfx::Rect(800, 10, 100, 100));
154 minimized
->Minimize();
155 EXPECT_EQ(root_windows
[1], minimized
->GetNativeView()->GetRootWindow());
156 EXPECT_EQ("800,10 100x100",
157 minimized
->GetWindowBoundsInScreen().ToString());
159 views::Widget
* fullscreen
= CreateTestWidget(gfx::Rect(850, 10, 100, 100));
160 fullscreen
->SetFullscreen(true);
161 EXPECT_EQ(root_windows
[1], fullscreen
->GetNativeView()->GetRootWindow());
163 EXPECT_EQ("600,0 300x300",
164 fullscreen
->GetWindowBoundsInScreen().ToString());
165 EXPECT_EQ("0,0 300x300",
166 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
168 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());
179 aura::Window
* panel
= CreateTestWindowInShellWithDelegateAndType(
180 NULL
, ui::wm::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());
184 // Make sure a window that will delete itself when losing focus
186 aura::WindowTracker tracker
;
187 DeleteOnBlurDelegate delete_on_blur_delegate
;
188 aura::Window
* d2
= CreateTestWindowInShellWithDelegate(
189 &delete_on_blur_delegate
, 0, gfx::Rect(50, 50, 100, 100));
190 delete_on_blur_delegate
.SetWindow(d2
);
191 aura::client::GetFocusClient(root_windows
[0])->FocusWindow(d2
);
194 UpdateDisplay("600x600");
196 // d2 must have been deleted.
197 EXPECT_FALSE(tracker
.Contains(d2
));
199 EXPECT_EQ(root_windows
[0], normal
->GetNativeView()->GetRootWindow());
200 EXPECT_EQ("100,20 100x100", normal
->GetWindowBoundsInScreen().ToString());
201 EXPECT_EQ("100,20 100x100",
202 normal
->GetNativeView()->GetBoundsInRootWindow().ToString());
204 // Maximized area on primary display has 3px (given as
205 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
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);
210 EXPECT_EQ(root_windows
[0], maximized
->GetNativeView()->GetRootWindow());
211 EXPECT_EQ("0,0 600x597",
212 maximized
->GetWindowBoundsInScreen().ToString());
213 EXPECT_EQ("0,0 600x597",
214 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
216 // 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());
225 EXPECT_EQ(root_windows
[0], minimized
->GetNativeView()->GetRootWindow());
226 EXPECT_EQ("400,20 100x100",
227 minimized
->GetWindowBoundsInScreen().ToString());
229 EXPECT_EQ(root_windows
[0], fullscreen
->GetNativeView()->GetRootWindow());
230 EXPECT_TRUE(fullscreen
->IsFullscreen());
231 EXPECT_EQ("0,0 600x600",
232 fullscreen
->GetWindowBoundsInScreen().ToString());
233 EXPECT_EQ("0,0 600x600",
234 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
236 // Test if the restore bounds are correctly updated.
237 wm::GetWindowState(maximized
->GetNativeView())->Restore();
238 EXPECT_EQ("200,20 100x100", maximized
->GetWindowBoundsInScreen().ToString());
239 EXPECT_EQ("200,20 100x100",
240 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
242 fullscreen
->SetFullscreen(false);
243 EXPECT_EQ("500,20 100x100",
244 fullscreen
->GetWindowBoundsInScreen().ToString());
245 EXPECT_EQ("500,20 100x100",
246 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
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());
254 // Test if the panel has moved.
255 EXPECT_EQ(root_windows
[0], panel
->GetRootWindow());
256 EXPECT_EQ(internal::kShellWindowId_PanelContainer
, panel
->parent()->id());
259 TEST_F(RootWindowControllerTest
, MoveWindows_Modal
) {
260 if (!SupportsMultipleDisplays())
263 UpdateDisplay("500x500,500x500");
265 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
266 // 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));
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()));
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()));
280 aura::test::EventGenerator
generator_1st(root_windows
[0]);
281 generator_1st
.ClickLeftButton();
282 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
284 UpdateDisplay("500x500");
285 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()));
291 TEST_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
,
297 shell
->system_tray_delegate()->GetUserLoginStatus());
298 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
299 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
300 controller
->GetSystemModalLayoutManager(NULL
));
302 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()));
309 shell
->session_state_delegate()->LockScreen();
310 EXPECT_EQ(user::LOGGED_IN_LOCKED
,
311 shell
->system_tray_delegate()->GetUserLoginStatus());
312 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
313 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
314 controller
->GetSystemModalLayoutManager(NULL
));
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()));
330 shell
->session_state_delegate()->UnlockScreen();
333 TEST_F(RootWindowControllerTest
, ModalContainerNotLoggedInLoggedIn
) {
334 UpdateDisplay("600x600");
335 Shell
* shell
= Shell::GetInstance();
337 // Configure login screen environment.
338 SetUserLoggedIn(false);
339 EXPECT_EQ(user::LOGGED_IN_NONE
,
340 shell
->system_tray_delegate()->GetUserLoginStatus());
341 EXPECT_EQ(0, shell
->session_state_delegate()->NumberOfLoggedInUsers());
342 EXPECT_FALSE(shell
->session_state_delegate()->IsActiveUserSessionStarted());
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
));
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();
361 // Configure user session environment.
362 SetUserLoggedIn(true);
363 SetSessionStarted(true);
364 EXPECT_EQ(user::LOGGED_IN_USER
,
365 shell
->system_tray_delegate()->GetUserLoginStatus());
366 EXPECT_EQ(1, shell
->session_state_delegate()->NumberOfLoggedInUsers());
367 EXPECT_TRUE(shell
->session_state_delegate()->IsActiveUserSessionStarted());
368 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
369 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
370 controller
->GetSystemModalLayoutManager(NULL
));
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()));
380 TEST_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
;
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();
402 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
404 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
405 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
406 controller
->GetSystemModalLayoutManager(NULL
));
408 views::Widget
* lock_modal_widget
=
409 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
411 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
412 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
413 controller
->GetSystemModalLayoutManager(
414 lock_modal_widget
->GetNativeView()));
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();
424 lock_modal_widget
->Close();
425 UnblockUserSession();
429 TEST_F(RootWindowControllerTest
, GetWindowForFullscreenMode
) {
430 UpdateDisplay("600x600");
431 internal::RootWindowController
* controller
=
432 Shell::GetInstance()->GetPrimaryRootWindowController();
434 Widget
* w1
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
436 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));
442 // Test that GetWindowForFullscreenMode() finds the fullscreen window when one
443 // of its transient children is active.
445 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetWindowForFullscreenMode());
447 // If the topmost window is not fullscreen, it returns NULL.
449 EXPECT_EQ(NULL
, controller
->GetWindowForFullscreenMode());
453 // Only w2 remains, if minimized GetWindowForFullscreenMode should return
456 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetWindowForFullscreenMode());
458 EXPECT_EQ(NULL
, controller
->GetWindowForFullscreenMode());
461 TEST_F(RootWindowControllerTest
, MultipleDisplaysGetWindowForFullscreenMode
) {
462 if (!SupportsMultipleDisplays())
465 UpdateDisplay("600x600,600x600");
466 Shell::RootWindowControllerList controllers
=
467 Shell::GetInstance()->GetAllRootWindowControllers();
469 Widget
* w1
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
471 Widget
* w2
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
472 w2
->SetFullscreen(true);
473 Widget
* w3
= CreateTestWidget(gfx::Rect(600, 0, 100, 100));
475 EXPECT_EQ(w1
->GetNativeWindow()->GetRootWindow(),
476 controllers
[0]->root_window());
477 EXPECT_EQ(w2
->GetNativeWindow()->GetRootWindow(),
478 controllers
[0]->root_window());
479 EXPECT_EQ(w3
->GetNativeWindow()->GetRootWindow(),
480 controllers
[1]->root_window());
483 EXPECT_EQ(NULL
, controllers
[0]->GetWindowForFullscreenMode());
484 EXPECT_EQ(NULL
, controllers
[1]->GetWindowForFullscreenMode());
487 EXPECT_EQ(w2
->GetNativeWindow(),
488 controllers
[0]->GetWindowForFullscreenMode());
489 EXPECT_EQ(NULL
, controllers
[1]->GetWindowForFullscreenMode());
491 // Verify that the first root window controller remains in fullscreen mode
492 // when a window on the other display is activated.
494 EXPECT_EQ(w2
->GetNativeWindow(),
495 controllers
[0]->GetWindowForFullscreenMode());
496 EXPECT_EQ(NULL
, controllers
[1]->GetWindowForFullscreenMode());
499 // Test that user session window can't be focused if user session blocked by
500 // some overlapping UI.
501 TEST_F(RootWindowControllerTest
, FocusBlockedWindow
) {
502 UpdateDisplay("600x600");
503 internal::RootWindowController
* controller
=
504 Shell::GetInstance()->GetPrimaryRootWindowController();
505 aura::Window
* lock_container
=
506 Shell::GetContainer(controller
->root_window(),
507 internal::kShellWindowId_LockScreenContainer
);
508 aura::Window
* lock_window
= Widget::CreateWindowWithParentAndBounds(NULL
,
509 lock_container
, gfx::Rect(0, 0, 100, 100))->GetNativeView();
511 aura::Window
* session_window
=
512 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
513 session_window
->Show();
515 for (int block_reason
= FIRST_BLOCK_REASON
;
516 block_reason
< NUMBER_OF_BLOCK_REASONS
;
518 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
519 lock_window
->Focus();
520 EXPECT_TRUE(lock_window
->HasFocus());
521 session_window
->Focus();
522 EXPECT_FALSE(session_window
->HasFocus());
523 UnblockUserSession();
527 // Tracks whether OnWindowDestroying() has been invoked.
528 class DestroyedWindowObserver
: public aura::WindowObserver
{
530 DestroyedWindowObserver() : destroyed_(false), window_(NULL
) {}
531 virtual ~DestroyedWindowObserver() {
535 void SetWindow(Window
* window
) {
537 window
->AddObserver(this);
540 bool destroyed() const { return destroyed_
; }
542 // WindowObserver overrides:
543 virtual void OnWindowDestroying(Window
* window
) OVERRIDE
{
552 window_
->RemoveObserver(this);
559 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver
);
562 // Verifies shutdown doesn't delete windows that are not owned by the parent.
563 TEST_F(RootWindowControllerTest
, DontDeleteWindowsNotOwnedByParent
) {
564 DestroyedWindowObserver observer1
;
565 aura::test::TestWindowDelegate delegate1
;
566 aura::Window
* window1
= new aura::Window(&delegate1
);
567 window1
->SetType(ui::wm::WINDOW_TYPE_CONTROL
);
568 window1
->set_owned_by_parent(false);
569 observer1
.SetWindow(window1
);
570 window1
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
571 aura::client::ParentWindowWithContext(
572 window1
, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
574 DestroyedWindowObserver observer2
;
575 aura::Window
* window2
= new aura::Window(NULL
);
576 window2
->set_owned_by_parent(false);
577 observer2
.SetWindow(window2
);
578 window2
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
579 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2
);
581 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
583 ASSERT_FALSE(observer1
.destroyed());
586 ASSERT_FALSE(observer2
.destroyed());
590 typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest
;
592 // Make sure that an event handler exists for entire display area.
593 TEST_F(NoSessionRootWindowControllerTest
, Event
) {
594 aura::Window
* root
= Shell::GetPrimaryRootWindow();
595 const gfx::Size size
= root
->bounds().size();
596 aura::Window
* event_target
= root
->GetEventHandlerForPoint(gfx::Point(0, 0));
597 EXPECT_TRUE(event_target
);
598 EXPECT_EQ(event_target
,
599 root
->GetEventHandlerForPoint(gfx::Point(0, size
.height() - 1)));
600 EXPECT_EQ(event_target
,
601 root
->GetEventHandlerForPoint(gfx::Point(size
.width() - 1, 0)));
602 EXPECT_EQ(event_target
,
603 root
->GetEventHandlerForPoint(gfx::Point(0, size
.height() - 1)));
604 EXPECT_EQ(event_target
,
605 root
->GetEventHandlerForPoint(
606 gfx::Point(size
.width() - 1, size
.height() - 1)));
609 class VirtualKeyboardRootWindowControllerTest
: public test::AshTestBase
{
611 VirtualKeyboardRootWindowControllerTest() {};
612 virtual ~VirtualKeyboardRootWindowControllerTest() {};
614 virtual void SetUp() OVERRIDE
{
615 CommandLine::ForCurrentProcess()->AppendSwitch(
616 keyboard::switches::kEnableVirtualKeyboard
);
617 test::AshTestBase::SetUp();
618 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
619 Shell::GetInstance()->keyboard_controller());
623 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest
);
626 // Test for http://crbug.com/297858. Virtual keyboard container should only show
627 // on primary root window.
628 TEST_F(VirtualKeyboardRootWindowControllerTest
,
629 VirtualKeyboardOnPrimaryRootWindowOnly
) {
630 if (!SupportsMultipleDisplays())
633 UpdateDisplay("500x500,500x500");
635 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
636 aura::Window
* primary_root_window
= Shell::GetPrimaryRootWindow();
637 aura::Window
* secondary_root_window
=
638 root_windows
[0] == primary_root_window
?
639 root_windows
[1] : root_windows
[0];
641 ASSERT_TRUE(Shell::GetContainer(
643 internal::kShellWindowId_VirtualKeyboardContainer
));
644 ASSERT_FALSE(Shell::GetContainer(
645 secondary_root_window
,
646 internal::kShellWindowId_VirtualKeyboardContainer
));
649 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive
650 // events at blocked user session.
651 TEST_F(VirtualKeyboardRootWindowControllerTest
,
652 ClickVirtualKeyboardInBlockedWindow
) {
653 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
654 aura::Window
* keyboard_container
= Shell::GetContainer(root_window
,
655 internal::kShellWindowId_VirtualKeyboardContainer
);
656 ASSERT_TRUE(keyboard_container
);
657 keyboard_container
->Show();
659 aura::Window
* keyboard_window
= Shell::GetInstance()->keyboard_controller()->
660 proxy()->GetKeyboardWindow();
661 keyboard_container
->AddChild(keyboard_window
);
662 keyboard_window
->set_owned_by_parent(false);
663 keyboard_window
->SetBounds(gfx::Rect());
664 keyboard_window
->Show();
666 aura::test::TestEventHandler
* handler
= new aura::test::TestEventHandler
;
667 root_window
->SetEventFilter(handler
);
669 aura::test::EventGenerator
event_generator(root_window
, keyboard_window
);
670 event_generator
.ClickLeftButton();
671 int expected_mouse_presses
= 1;
672 EXPECT_EQ(expected_mouse_presses
, handler
->num_mouse_events() / 2);
674 for (int block_reason
= FIRST_BLOCK_REASON
;
675 block_reason
< NUMBER_OF_BLOCK_REASONS
;
677 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
678 event_generator
.ClickLeftButton();
679 expected_mouse_presses
++;
680 EXPECT_EQ(expected_mouse_presses
, handler
->num_mouse_events() / 2);
681 UnblockUserSession();
685 // Test for http://crbug.com/299787. RootWindowController should delete
686 // the old container since the keyboard controller creates a new window in
687 // GetWindowContainer().
688 TEST_F(VirtualKeyboardRootWindowControllerTest
,
689 DeleteOldContainerOnVirtualKeyboardInit
) {
690 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
691 aura::Window
* keyboard_container
= Shell::GetContainer(root_window
,
692 internal::kShellWindowId_VirtualKeyboardContainer
);
693 ASSERT_TRUE(keyboard_container
);
694 // Track the keyboard container window.
695 aura::WindowTracker tracker
;
696 tracker
.Add(keyboard_container
);
697 // Mock a login user profile change to reinitialize the keyboard.
698 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
699 // keyboard_container should no longer be present.
700 EXPECT_FALSE(tracker
.Contains(keyboard_container
));
703 // Test for crbug.com/342524. After user login, the work space should restore to
705 TEST_F(VirtualKeyboardRootWindowControllerTest
, RestoreWorkspaceAfterLogin
) {
706 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
707 aura::Window
* keyboard_container
= Shell::GetContainer(root_window
,
708 internal::kShellWindowId_VirtualKeyboardContainer
);
709 keyboard_container
->Show();
710 keyboard::KeyboardController
* controller
=
711 Shell::GetInstance()->keyboard_controller();
712 aura::Window
* keyboard_window
= controller
->proxy()->GetKeyboardWindow();
713 keyboard_container
->AddChild(keyboard_window
);
714 keyboard_window
->set_owned_by_parent(false);
715 keyboard_window
->Show();
717 gfx::Rect before
= ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
719 // Notify keyboard bounds changing.
720 controller
->NotifyKeyboardBoundsChanging(
721 controller
->proxy()->GetKeyboardWindow()->bounds());
723 gfx::Rect after
= ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
724 EXPECT_LT(after
, before
);
726 // Mock a login user profile change to reinitialize the keyboard.
727 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
728 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(), before
);