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_window_delegate.h"
24 #include "ui/aura/test/test_windows.h"
25 #include "ui/aura/window.h"
26 #include "ui/aura/window_event_dispatcher.h"
27 #include "ui/aura/window_tracker.h"
28 #include "ui/events/test/test_event_handler.h"
29 #include "ui/keyboard/keyboard_controller_proxy.h"
30 #include "ui/keyboard/keyboard_switches.h"
31 #include "ui/keyboard/keyboard_util.h"
32 #include "ui/views/controls/menu/menu_controller.h"
33 #include "ui/views/widget/widget.h"
34 #include "ui/views/widget/widget_delegate.h"
42 class TestDelegate
: public views::WidgetDelegateView
{
44 explicit TestDelegate(bool system_modal
) : system_modal_(system_modal
) {}
45 virtual ~TestDelegate() {}
47 // Overridden from views::WidgetDelegate:
48 virtual views::View
* GetContentsView() OVERRIDE
{
52 virtual ui::ModalType
GetModalType() const OVERRIDE
{
53 return system_modal_
? ui::MODAL_TYPE_SYSTEM
: ui::MODAL_TYPE_NONE
;
59 DISALLOW_COPY_AND_ASSIGN(TestDelegate
);
62 class DeleteOnBlurDelegate
: public aura::test::TestWindowDelegate
,
63 public aura::client::FocusChangeObserver
{
65 DeleteOnBlurDelegate() : window_(NULL
) {}
66 virtual ~DeleteOnBlurDelegate() {}
68 void SetWindow(aura::Window
* window
) {
70 aura::client::SetFocusChangeObserver(window_
, this);
74 // aura::test::TestWindowDelegate overrides:
75 virtual bool CanFocus() OVERRIDE
{
79 // aura::client::FocusChangeObserver implementation:
80 virtual void OnWindowFocused(aura::Window
* gained_focus
,
81 aura::Window
* lost_focus
) OVERRIDE
{
82 if (window_
== lost_focus
)
86 aura::Window
* window_
;
88 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate
);
95 class RootWindowControllerTest
: public test::AshTestBase
{
97 views::Widget
* CreateTestWidget(const gfx::Rect
& bounds
) {
98 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
99 NULL
, CurrentContext(), bounds
);
104 views::Widget
* CreateModalWidget(const gfx::Rect
& bounds
) {
105 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
106 new TestDelegate(true), CurrentContext(), bounds
);
111 views::Widget
* CreateModalWidgetWithParent(const gfx::Rect
& bounds
,
112 gfx::NativeWindow parent
) {
113 views::Widget
* widget
=
114 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
121 aura::Window
* GetModalContainer(aura::Window
* root_window
) {
122 return Shell::GetContainer(root_window
,
123 ash::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 RootWindowController
* controller
= Shell::GetPrimaryRootWindowController();
134 ShelfLayoutManager
* shelf_layout_manager
=
135 controller
->GetShelfLayoutManager();
136 shelf_layout_manager
->SetAutoHideBehavior(
137 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
139 views::Widget
* normal
= CreateTestWidget(gfx::Rect(650, 10, 100, 100));
140 EXPECT_EQ(root_windows
[1], normal
->GetNativeView()->GetRootWindow());
141 EXPECT_EQ("650,10 100x100", normal
->GetWindowBoundsInScreen().ToString());
142 EXPECT_EQ("50,10 100x100",
143 normal
->GetNativeView()->GetBoundsInRootWindow().ToString());
145 views::Widget
* maximized
= CreateTestWidget(gfx::Rect(700, 10, 100, 100));
146 maximized
->Maximize();
147 EXPECT_EQ(root_windows
[1], maximized
->GetNativeView()->GetRootWindow());
148 EXPECT_EQ("600,0 300x253", maximized
->GetWindowBoundsInScreen().ToString());
149 EXPECT_EQ("0,0 300x253",
150 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
152 views::Widget
* minimized
= CreateTestWidget(gfx::Rect(800, 10, 100, 100));
153 minimized
->Minimize();
154 EXPECT_EQ(root_windows
[1], minimized
->GetNativeView()->GetRootWindow());
155 EXPECT_EQ("800,10 100x100",
156 minimized
->GetWindowBoundsInScreen().ToString());
158 views::Widget
* fullscreen
= CreateTestWidget(gfx::Rect(850, 10, 100, 100));
159 fullscreen
->SetFullscreen(true);
160 EXPECT_EQ(root_windows
[1], fullscreen
->GetNativeView()->GetRootWindow());
162 EXPECT_EQ("600,0 300x300",
163 fullscreen
->GetWindowBoundsInScreen().ToString());
164 EXPECT_EQ("0,0 300x300",
165 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
167 views::Widget
* unparented_control
= new Widget
;
168 Widget::InitParams params
;
169 params
.bounds
= gfx::Rect(650, 10, 100, 100);
170 params
.context
= CurrentContext();
171 params
.type
= Widget::InitParams::TYPE_CONTROL
;
172 unparented_control
->Init(params
);
173 EXPECT_EQ(root_windows
[1],
174 unparented_control
->GetNativeView()->GetRootWindow());
175 EXPECT_EQ(kShellWindowId_UnparentedControlContainer
,
176 unparented_control
->GetNativeView()->parent()->id());
178 aura::Window
* panel
= CreateTestWindowInShellWithDelegateAndType(
179 NULL
, ui::wm::WINDOW_TYPE_PANEL
, 0, gfx::Rect(700, 100, 100, 100));
180 EXPECT_EQ(root_windows
[1], panel
->GetRootWindow());
181 EXPECT_EQ(kShellWindowId_PanelContainer
, panel
->parent()->id());
183 // Make sure a window that will delete itself when losing focus
185 aura::WindowTracker tracker
;
186 DeleteOnBlurDelegate delete_on_blur_delegate
;
187 aura::Window
* d2
= CreateTestWindowInShellWithDelegate(
188 &delete_on_blur_delegate
, 0, gfx::Rect(50, 50, 100, 100));
189 delete_on_blur_delegate
.SetWindow(d2
);
190 aura::client::GetFocusClient(root_windows
[0])->FocusWindow(d2
);
193 UpdateDisplay("600x600");
195 // d2 must have been deleted.
196 EXPECT_FALSE(tracker
.Contains(d2
));
198 EXPECT_EQ(root_windows
[0], normal
->GetNativeView()->GetRootWindow());
199 EXPECT_EQ("100,20 100x100", normal
->GetWindowBoundsInScreen().ToString());
200 EXPECT_EQ("100,20 100x100",
201 normal
->GetNativeView()->GetBoundsInRootWindow().ToString());
203 // Maximized area on primary display has 3px (given as
204 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
206 // First clear fullscreen status, since both fullscreen and maximized windows
207 // share the same desktop workspace, which cancels the shelf status.
208 fullscreen
->SetFullscreen(false);
209 EXPECT_EQ(root_windows
[0], maximized
->GetNativeView()->GetRootWindow());
210 EXPECT_EQ("0,0 600x597",
211 maximized
->GetWindowBoundsInScreen().ToString());
212 EXPECT_EQ("0,0 600x597",
213 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
215 // Set fullscreen to true. In that case the 3px inset becomes invisible so
216 // the maximized window can also use the area fully.
217 fullscreen
->SetFullscreen(true);
218 EXPECT_EQ(root_windows
[0], maximized
->GetNativeView()->GetRootWindow());
219 EXPECT_EQ("0,0 600x600",
220 maximized
->GetWindowBoundsInScreen().ToString());
221 EXPECT_EQ("0,0 600x600",
222 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
224 EXPECT_EQ(root_windows
[0], minimized
->GetNativeView()->GetRootWindow());
225 EXPECT_EQ("400,20 100x100",
226 minimized
->GetWindowBoundsInScreen().ToString());
228 EXPECT_EQ(root_windows
[0], fullscreen
->GetNativeView()->GetRootWindow());
229 EXPECT_TRUE(fullscreen
->IsFullscreen());
230 EXPECT_EQ("0,0 600x600",
231 fullscreen
->GetWindowBoundsInScreen().ToString());
232 EXPECT_EQ("0,0 600x600",
233 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
235 // Test if the restore bounds are correctly updated.
236 wm::GetWindowState(maximized
->GetNativeView())->Restore();
237 EXPECT_EQ("200,20 100x100", maximized
->GetWindowBoundsInScreen().ToString());
238 EXPECT_EQ("200,20 100x100",
239 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
241 fullscreen
->SetFullscreen(false);
242 EXPECT_EQ("500,20 100x100",
243 fullscreen
->GetWindowBoundsInScreen().ToString());
244 EXPECT_EQ("500,20 100x100",
245 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
247 // Test if the unparented widget has moved.
248 EXPECT_EQ(root_windows
[0],
249 unparented_control
->GetNativeView()->GetRootWindow());
250 EXPECT_EQ(kShellWindowId_UnparentedControlContainer
,
251 unparented_control
->GetNativeView()->parent()->id());
253 // Test if the panel has moved.
254 EXPECT_EQ(root_windows
[0], panel
->GetRootWindow());
255 EXPECT_EQ(kShellWindowId_PanelContainer
, panel
->parent()->id());
258 TEST_F(RootWindowControllerTest
, MoveWindows_Modal
) {
259 if (!SupportsMultipleDisplays())
262 UpdateDisplay("500x500,500x500");
264 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
265 // Emulate virtual screen coordinate system.
266 root_windows
[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
267 root_windows
[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
269 views::Widget
* normal
= CreateTestWidget(gfx::Rect(300, 10, 100, 100));
270 EXPECT_EQ(root_windows
[0], normal
->GetNativeView()->GetRootWindow());
271 EXPECT_TRUE(wm::IsActiveWindow(normal
->GetNativeView()));
273 views::Widget
* modal
= CreateModalWidget(gfx::Rect(650, 10, 100, 100));
274 EXPECT_EQ(root_windows
[1], modal
->GetNativeView()->GetRootWindow());
275 EXPECT_TRUE(GetModalContainer(root_windows
[1])->Contains(
276 modal
->GetNativeView()));
277 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
279 aura::test::EventGenerator
generator_1st(root_windows
[0]);
280 generator_1st
.ClickLeftButton();
281 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
283 UpdateDisplay("500x500");
284 EXPECT_EQ(root_windows
[0], modal
->GetNativeView()->GetRootWindow());
285 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
286 generator_1st
.ClickLeftButton();
287 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
290 TEST_F(RootWindowControllerTest
, ModalContainer
) {
291 UpdateDisplay("600x600");
292 Shell
* shell
= Shell::GetInstance();
293 RootWindowController
* controller
= shell
->GetPrimaryRootWindowController();
294 EXPECT_EQ(user::LOGGED_IN_USER
,
295 shell
->system_tray_delegate()->GetUserLoginStatus());
296 EXPECT_EQ(controller
->GetContainer(kShellWindowId_SystemModalContainer
)
298 controller
->GetSystemModalLayoutManager(NULL
));
300 views::Widget
* session_modal_widget
=
301 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
302 EXPECT_EQ(controller
->GetContainer(kShellWindowId_SystemModalContainer
)
304 controller
->GetSystemModalLayoutManager(
305 session_modal_widget
->GetNativeView()));
307 shell
->session_state_delegate()->LockScreen();
308 EXPECT_EQ(user::LOGGED_IN_LOCKED
,
309 shell
->system_tray_delegate()->GetUserLoginStatus());
310 EXPECT_EQ(controller
->GetContainer(kShellWindowId_LockSystemModalContainer
)
312 controller
->GetSystemModalLayoutManager(NULL
));
314 aura::Window
* lock_container
=
315 controller
->GetContainer(kShellWindowId_LockScreenContainer
);
316 views::Widget
* lock_modal_widget
=
317 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container
);
318 EXPECT_EQ(controller
->GetContainer(kShellWindowId_LockSystemModalContainer
)
320 controller
->GetSystemModalLayoutManager(
321 lock_modal_widget
->GetNativeView()));
322 EXPECT_EQ(controller
->GetContainer(kShellWindowId_SystemModalContainer
)
324 controller
->GetSystemModalLayoutManager(
325 session_modal_widget
->GetNativeView()));
327 shell
->session_state_delegate()->UnlockScreen();
330 TEST_F(RootWindowControllerTest
, ModalContainerNotLoggedInLoggedIn
) {
331 UpdateDisplay("600x600");
332 Shell
* shell
= Shell::GetInstance();
334 // Configure login screen environment.
335 SetUserLoggedIn(false);
336 EXPECT_EQ(user::LOGGED_IN_NONE
,
337 shell
->system_tray_delegate()->GetUserLoginStatus());
338 EXPECT_EQ(0, shell
->session_state_delegate()->NumberOfLoggedInUsers());
339 EXPECT_FALSE(shell
->session_state_delegate()->IsActiveUserSessionStarted());
341 RootWindowController
* controller
= shell
->GetPrimaryRootWindowController();
342 EXPECT_EQ(controller
->GetContainer(kShellWindowId_LockSystemModalContainer
)
344 controller
->GetSystemModalLayoutManager(NULL
));
346 aura::Window
* lock_container
=
347 controller
->GetContainer(kShellWindowId_LockScreenContainer
);
348 views::Widget
* login_modal_widget
=
349 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container
);
350 EXPECT_EQ(controller
->GetContainer(kShellWindowId_LockSystemModalContainer
)
352 controller
->GetSystemModalLayoutManager(
353 login_modal_widget
->GetNativeView()));
354 login_modal_widget
->Close();
356 // Configure user session environment.
357 SetUserLoggedIn(true);
358 SetSessionStarted(true);
359 EXPECT_EQ(user::LOGGED_IN_USER
,
360 shell
->system_tray_delegate()->GetUserLoginStatus());
361 EXPECT_EQ(1, shell
->session_state_delegate()->NumberOfLoggedInUsers());
362 EXPECT_TRUE(shell
->session_state_delegate()->IsActiveUserSessionStarted());
363 EXPECT_EQ(controller
->GetContainer(kShellWindowId_SystemModalContainer
)
365 controller
->GetSystemModalLayoutManager(NULL
));
367 views::Widget
* session_modal_widget
=
368 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
369 EXPECT_EQ(controller
->GetContainer(kShellWindowId_SystemModalContainer
)
371 controller
->GetSystemModalLayoutManager(
372 session_modal_widget
->GetNativeView()));
375 TEST_F(RootWindowControllerTest
, ModalContainerBlockedSession
) {
376 UpdateDisplay("600x600");
377 Shell
* shell
= Shell::GetInstance();
378 RootWindowController
* controller
= shell
->GetPrimaryRootWindowController();
379 aura::Window
* lock_container
=
380 controller
->GetContainer(kShellWindowId_LockScreenContainer
);
381 for (int block_reason
= FIRST_BLOCK_REASON
;
382 block_reason
< NUMBER_OF_BLOCK_REASONS
;
384 views::Widget
* session_modal_widget
=
385 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
386 EXPECT_EQ(controller
->GetContainer(kShellWindowId_SystemModalContainer
)
388 controller
->GetSystemModalLayoutManager(
389 session_modal_widget
->GetNativeView()));
390 EXPECT_EQ(controller
->GetContainer(kShellWindowId_SystemModalContainer
)
392 controller
->GetSystemModalLayoutManager(NULL
));
393 session_modal_widget
->Close();
395 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
397 EXPECT_EQ(controller
->GetContainer(kShellWindowId_LockSystemModalContainer
)
399 controller
->GetSystemModalLayoutManager(NULL
));
401 views::Widget
* lock_modal_widget
=
402 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
404 EXPECT_EQ(controller
->GetContainer(kShellWindowId_LockSystemModalContainer
)
406 controller
->GetSystemModalLayoutManager(
407 lock_modal_widget
->GetNativeView()));
409 session_modal_widget
=
410 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
411 EXPECT_EQ(controller
->GetContainer(kShellWindowId_SystemModalContainer
)
413 controller
->GetSystemModalLayoutManager(
414 session_modal_widget
->GetNativeView()));
415 session_modal_widget
->Close();
417 lock_modal_widget
->Close();
418 UnblockUserSession();
422 TEST_F(RootWindowControllerTest
, GetWindowForFullscreenMode
) {
423 UpdateDisplay("600x600");
424 RootWindowController
* controller
=
425 Shell::GetInstance()->GetPrimaryRootWindowController();
427 Widget
* w1
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
429 Widget
* w2
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
430 w2
->SetFullscreen(true);
431 // |w3| is a transient child of |w2|.
432 Widget
* w3
= Widget::CreateWindowWithParentAndBounds(NULL
,
433 w2
->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
435 // Test that GetWindowForFullscreenMode() finds the fullscreen window when one
436 // of its transient children is active.
438 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetWindowForFullscreenMode());
440 // If the topmost window is not fullscreen, it returns NULL.
442 EXPECT_EQ(NULL
, controller
->GetWindowForFullscreenMode());
446 // Only w2 remains, if minimized GetWindowForFullscreenMode should return
449 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetWindowForFullscreenMode());
451 EXPECT_EQ(NULL
, controller
->GetWindowForFullscreenMode());
454 TEST_F(RootWindowControllerTest
, MultipleDisplaysGetWindowForFullscreenMode
) {
455 if (!SupportsMultipleDisplays())
458 UpdateDisplay("600x600,600x600");
459 Shell::RootWindowControllerList controllers
=
460 Shell::GetInstance()->GetAllRootWindowControllers();
462 Widget
* w1
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
464 Widget
* w2
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
465 w2
->SetFullscreen(true);
466 Widget
* w3
= CreateTestWidget(gfx::Rect(600, 0, 100, 100));
468 EXPECT_EQ(w1
->GetNativeWindow()->GetRootWindow(),
469 controllers
[0]->GetRootWindow());
470 EXPECT_EQ(w2
->GetNativeWindow()->GetRootWindow(),
471 controllers
[0]->GetRootWindow());
472 EXPECT_EQ(w3
->GetNativeWindow()->GetRootWindow(),
473 controllers
[1]->GetRootWindow());
476 EXPECT_EQ(NULL
, controllers
[0]->GetWindowForFullscreenMode());
477 EXPECT_EQ(NULL
, controllers
[1]->GetWindowForFullscreenMode());
480 EXPECT_EQ(w2
->GetNativeWindow(),
481 controllers
[0]->GetWindowForFullscreenMode());
482 EXPECT_EQ(NULL
, controllers
[1]->GetWindowForFullscreenMode());
484 // Verify that the first root window controller remains in fullscreen mode
485 // when a window on the other display is activated.
487 EXPECT_EQ(w2
->GetNativeWindow(),
488 controllers
[0]->GetWindowForFullscreenMode());
489 EXPECT_EQ(NULL
, controllers
[1]->GetWindowForFullscreenMode());
492 // Test that user session window can't be focused if user session blocked by
493 // some overlapping UI.
494 TEST_F(RootWindowControllerTest
, FocusBlockedWindow
) {
495 UpdateDisplay("600x600");
496 RootWindowController
* controller
=
497 Shell::GetInstance()->GetPrimaryRootWindowController();
498 aura::Window
* lock_container
=
499 controller
->GetContainer(kShellWindowId_LockScreenContainer
);
500 aura::Window
* lock_window
= Widget::CreateWindowWithParentAndBounds(NULL
,
501 lock_container
, gfx::Rect(0, 0, 100, 100))->GetNativeView();
503 aura::Window
* session_window
=
504 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
505 session_window
->Show();
507 for (int block_reason
= FIRST_BLOCK_REASON
;
508 block_reason
< NUMBER_OF_BLOCK_REASONS
;
510 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
511 lock_window
->Focus();
512 EXPECT_TRUE(lock_window
->HasFocus());
513 session_window
->Focus();
514 EXPECT_FALSE(session_window
->HasFocus());
515 UnblockUserSession();
519 // Tracks whether OnWindowDestroying() has been invoked.
520 class DestroyedWindowObserver
: public aura::WindowObserver
{
522 DestroyedWindowObserver() : destroyed_(false), window_(NULL
) {}
523 virtual ~DestroyedWindowObserver() {
527 void SetWindow(Window
* window
) {
529 window
->AddObserver(this);
532 bool destroyed() const { return destroyed_
; }
534 // WindowObserver overrides:
535 virtual void OnWindowDestroying(Window
* window
) OVERRIDE
{
544 window_
->RemoveObserver(this);
551 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver
);
554 // Verifies shutdown doesn't delete windows that are not owned by the parent.
555 TEST_F(RootWindowControllerTest
, DontDeleteWindowsNotOwnedByParent
) {
556 DestroyedWindowObserver observer1
;
557 aura::test::TestWindowDelegate delegate1
;
558 aura::Window
* window1
= new aura::Window(&delegate1
);
559 window1
->SetType(ui::wm::WINDOW_TYPE_CONTROL
);
560 window1
->set_owned_by_parent(false);
561 observer1
.SetWindow(window1
);
562 window1
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
563 aura::client::ParentWindowWithContext(
564 window1
, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
566 DestroyedWindowObserver observer2
;
567 aura::Window
* window2
= new aura::Window(NULL
);
568 window2
->set_owned_by_parent(false);
569 observer2
.SetWindow(window2
);
570 window2
->Init(aura::WINDOW_LAYER_NOT_DRAWN
);
571 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2
);
573 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
575 ASSERT_FALSE(observer1
.destroyed());
578 ASSERT_FALSE(observer2
.destroyed());
582 typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest
;
584 // Make sure that an event handler exists for entire display area.
585 TEST_F(NoSessionRootWindowControllerTest
, Event
) {
586 aura::Window
* root
= Shell::GetPrimaryRootWindow();
587 const gfx::Size size
= root
->bounds().size();
588 aura::Window
* event_target
= root
->GetEventHandlerForPoint(gfx::Point(0, 0));
589 EXPECT_TRUE(event_target
);
590 EXPECT_EQ(event_target
,
591 root
->GetEventHandlerForPoint(gfx::Point(0, size
.height() - 1)));
592 EXPECT_EQ(event_target
,
593 root
->GetEventHandlerForPoint(gfx::Point(size
.width() - 1, 0)));
594 EXPECT_EQ(event_target
,
595 root
->GetEventHandlerForPoint(gfx::Point(0, size
.height() - 1)));
596 EXPECT_EQ(event_target
,
597 root
->GetEventHandlerForPoint(
598 gfx::Point(size
.width() - 1, size
.height() - 1)));
601 class VirtualKeyboardRootWindowControllerTest
: public RootWindowControllerTest
604 VirtualKeyboardRootWindowControllerTest() {};
605 virtual ~VirtualKeyboardRootWindowControllerTest() {};
607 virtual void SetUp() OVERRIDE
{
608 CommandLine::ForCurrentProcess()->AppendSwitch(
609 keyboard::switches::kEnableVirtualKeyboard
);
610 test::AshTestBase::SetUp();
611 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
612 keyboard::KeyboardController::GetInstance());
616 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest
);
619 // Test for http://crbug.com/297858. Virtual keyboard container should only show
620 // on primary root window.
621 TEST_F(VirtualKeyboardRootWindowControllerTest
,
622 VirtualKeyboardOnPrimaryRootWindowOnly
) {
623 if (!SupportsMultipleDisplays())
626 UpdateDisplay("500x500,500x500");
628 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
629 aura::Window
* primary_root_window
= Shell::GetPrimaryRootWindow();
630 aura::Window
* secondary_root_window
=
631 root_windows
[0] == primary_root_window
?
632 root_windows
[1] : root_windows
[0];
634 ASSERT_TRUE(Shell::GetContainer(primary_root_window
,
635 kShellWindowId_VirtualKeyboardContainer
));
636 ASSERT_FALSE(Shell::GetContainer(secondary_root_window
,
637 kShellWindowId_VirtualKeyboardContainer
));
640 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive
641 // events at blocked user session.
642 TEST_F(VirtualKeyboardRootWindowControllerTest
,
643 ClickVirtualKeyboardInBlockedWindow
) {
644 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
645 aura::Window
* keyboard_container
=
646 Shell::GetContainer(root_window
, kShellWindowId_VirtualKeyboardContainer
);
647 ASSERT_TRUE(keyboard_container
);
648 keyboard_container
->Show();
650 aura::Window
* keyboard_window
= keyboard::KeyboardController::GetInstance()->
651 proxy()->GetKeyboardWindow();
652 keyboard_container
->AddChild(keyboard_window
);
653 keyboard_window
->set_owned_by_parent(false);
654 keyboard_window
->SetBounds(gfx::Rect());
655 keyboard_window
->Show();
657 ui::test::TestEventHandler handler
;
658 root_window
->AddPreTargetHandler(&handler
);
660 aura::test::EventGenerator
event_generator(root_window
, keyboard_window
);
661 event_generator
.ClickLeftButton();
662 int expected_mouse_presses
= 1;
663 EXPECT_EQ(expected_mouse_presses
, handler
.num_mouse_events() / 2);
665 for (int block_reason
= FIRST_BLOCK_REASON
;
666 block_reason
< NUMBER_OF_BLOCK_REASONS
;
668 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
669 event_generator
.ClickLeftButton();
670 expected_mouse_presses
++;
671 EXPECT_EQ(expected_mouse_presses
, handler
.num_mouse_events() / 2);
672 UnblockUserSession();
674 root_window
->RemovePreTargetHandler(&handler
);
677 // Test for http://crbug.com/299787. RootWindowController should delete
678 // the old container since the keyboard controller creates a new window in
679 // GetWindowContainer().
680 TEST_F(VirtualKeyboardRootWindowControllerTest
,
681 DeleteOldContainerOnVirtualKeyboardInit
) {
682 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
683 aura::Window
* keyboard_container
=
684 Shell::GetContainer(root_window
, kShellWindowId_VirtualKeyboardContainer
);
685 ASSERT_TRUE(keyboard_container
);
686 // Track the keyboard container window.
687 aura::WindowTracker tracker
;
688 tracker
.Add(keyboard_container
);
689 // Mock a login user profile change to reinitialize the keyboard.
690 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
691 // keyboard_container should no longer be present.
692 EXPECT_FALSE(tracker
.Contains(keyboard_container
));
695 // Test for crbug.com/342524. After user login, the work space should restore to
697 TEST_F(VirtualKeyboardRootWindowControllerTest
, RestoreWorkspaceAfterLogin
) {
698 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
699 aura::Window
* keyboard_container
=
700 Shell::GetContainer(root_window
, kShellWindowId_VirtualKeyboardContainer
);
701 keyboard_container
->Show();
702 keyboard::KeyboardController
* controller
=
703 keyboard::KeyboardController::GetInstance();
704 aura::Window
* keyboard_window
= controller
->proxy()->GetKeyboardWindow();
705 keyboard_container
->AddChild(keyboard_window
);
706 keyboard_window
->set_owned_by_parent(false);
707 keyboard_window
->SetBounds(keyboard::KeyboardBoundsFromWindowBounds(
708 keyboard_container
->bounds(), 100));
709 keyboard_window
->Show();
711 gfx::Rect before
= ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
713 // Notify keyboard bounds changing.
714 controller
->NotifyKeyboardBoundsChanging(
715 controller
->proxy()->GetKeyboardWindow()->bounds());
717 gfx::Rect after
= ash::Shell::GetScreen()->GetPrimaryDisplay().work_area();
718 EXPECT_LT(after
, before
);
720 // Mock a login user profile change to reinitialize the keyboard.
721 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
722 EXPECT_EQ(ash::Shell::GetScreen()->GetPrimaryDisplay().work_area(), before
);
725 // Ensure that system modal dialogs do not block events targeted at the virtual
727 TEST_F(VirtualKeyboardRootWindowControllerTest
, ClickWithActiveModalDialog
) {
728 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
729 aura::Window
* keyboard_container
=
730 Shell::GetContainer(root_window
, kShellWindowId_VirtualKeyboardContainer
);
731 ASSERT_TRUE(keyboard_container
);
732 keyboard_container
->Show();
734 aura::Window
* keyboard_window
= keyboard::KeyboardController::GetInstance()->
735 proxy()->GetKeyboardWindow();
736 keyboard_container
->AddChild(keyboard_window
);
737 keyboard_window
->set_owned_by_parent(false);
738 keyboard_window
->SetBounds(keyboard::KeyboardBoundsFromWindowBounds(
739 keyboard_container
->bounds(), 100));
741 ui::test::TestEventHandler handler
;
742 root_window
->AddPreTargetHandler(&handler
);
743 aura::test::EventGenerator
root_window_event_generator(root_window
);
744 aura::test::EventGenerator
keyboard_event_generator(root_window
,
747 views::Widget
* modal_widget
=
748 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
750 // Verify that mouse events to the root window are block with a visble modal
752 root_window_event_generator
.ClickLeftButton();
753 EXPECT_EQ(0, handler
.num_mouse_events());
755 // Verify that event dispatch to the virtual keyboard is unblocked.
756 keyboard_event_generator
.ClickLeftButton();
757 EXPECT_EQ(1, handler
.num_mouse_events() / 2);
759 modal_widget
->Close();
761 // Verify that mouse events are now unblocked to the root window.
762 root_window_event_generator
.ClickLeftButton();
763 EXPECT_EQ(2, handler
.num_mouse_events() / 2);
764 root_window
->RemovePreTargetHandler(&handler
);