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/root_window.h"
23 #include "ui/aura/test/event_generator.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_tracker.h"
28 #include "ui/keyboard/keyboard_switches.h"
29 #include "ui/views/controls/menu/menu_controller.h"
30 #include "ui/views/widget/widget.h"
31 #include "ui/views/widget/widget_delegate.h"
39 class TestDelegate
: public views::WidgetDelegateView
{
41 explicit TestDelegate(bool system_modal
) : system_modal_(system_modal
) {}
42 virtual ~TestDelegate() {}
44 // Overridden from views::WidgetDelegate:
45 virtual views::View
* GetContentsView() OVERRIDE
{
49 virtual ui::ModalType
GetModalType() const OVERRIDE
{
50 return system_modal_
? ui::MODAL_TYPE_SYSTEM
: ui::MODAL_TYPE_NONE
;
56 DISALLOW_COPY_AND_ASSIGN(TestDelegate
);
59 class DeleteOnBlurDelegate
: public aura::test::TestWindowDelegate
,
60 public aura::client::FocusChangeObserver
{
62 DeleteOnBlurDelegate() : window_(NULL
) {}
63 virtual ~DeleteOnBlurDelegate() {}
65 void SetWindow(aura::Window
* window
) {
67 aura::client::SetFocusChangeObserver(window_
, this);
71 // aura::test::TestWindowDelegate overrides:
72 virtual bool CanFocus() OVERRIDE
{
76 // aura::client::FocusChangeObserver implementation:
77 virtual void OnWindowFocused(aura::Window
* gained_focus
,
78 aura::Window
* lost_focus
) OVERRIDE
{
79 if (window_
== lost_focus
)
83 aura::Window
* window_
;
85 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate
);
88 class ClickTestWindow
: public views::WidgetDelegateView
{
90 ClickTestWindow() : mouse_presses_(0) {}
91 virtual ~ClickTestWindow() {}
93 // Overridden from views::WidgetDelegate:
94 virtual views::View
* GetContentsView() OVERRIDE
{
98 aura::Window
* CreateTestWindowWithParent(aura::Window
* parent
) {
100 views::Widget
* widget
= Widget::CreateWindowWithParent(this, parent
);
101 return widget
->GetNativeView();
104 // Overridden from views::View:
105 virtual bool OnMousePressed(const ui::MouseEvent
& event
) OVERRIDE
{
110 int mouse_presses() const { return mouse_presses_
; }
115 DISALLOW_COPY_AND_ASSIGN(ClickTestWindow
);
122 class RootWindowControllerTest
: public test::AshTestBase
{
124 views::Widget
* CreateTestWidget(const gfx::Rect
& bounds
) {
125 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
126 NULL
, CurrentContext(), bounds
);
131 views::Widget
* CreateModalWidget(const gfx::Rect
& bounds
) {
132 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
133 new TestDelegate(true), CurrentContext(), bounds
);
138 views::Widget
* CreateModalWidgetWithParent(const gfx::Rect
& bounds
,
139 gfx::NativeWindow parent
) {
140 views::Widget
* widget
=
141 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
148 aura::Window
* GetModalContainer(aura::Window
* root_window
) {
149 return Shell::GetContainer(
151 ash::internal::kShellWindowId_SystemModalContainer
);
155 TEST_F(RootWindowControllerTest
, MoveWindows_Basic
) {
156 if (!SupportsMultipleDisplays())
159 UpdateDisplay("600x600,500x500");
160 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
161 internal::RootWindowController
* controller
=
162 Shell::GetPrimaryRootWindowController();
163 internal::ShelfLayoutManager
* shelf_layout_manager
=
164 controller
->GetShelfLayoutManager();
165 shelf_layout_manager
->SetAutoHideBehavior(
166 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
168 views::Widget
* normal
= CreateTestWidget(gfx::Rect(650, 10, 100, 100));
169 EXPECT_EQ(root_windows
[1], normal
->GetNativeView()->GetRootWindow());
170 EXPECT_EQ("650,10 100x100", normal
->GetWindowBoundsInScreen().ToString());
171 EXPECT_EQ("50,10 100x100",
172 normal
->GetNativeView()->GetBoundsInRootWindow().ToString());
174 views::Widget
* maximized
= CreateTestWidget(gfx::Rect(700, 10, 100, 100));
175 maximized
->Maximize();
176 EXPECT_EQ(root_windows
[1], maximized
->GetNativeView()->GetRootWindow());
177 EXPECT_EQ("600,0 500x453", maximized
->GetWindowBoundsInScreen().ToString());
178 EXPECT_EQ("0,0 500x453",
179 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
181 views::Widget
* minimized
= CreateTestWidget(gfx::Rect(800, 10, 100, 100));
182 minimized
->Minimize();
183 EXPECT_EQ(root_windows
[1], minimized
->GetNativeView()->GetRootWindow());
184 EXPECT_EQ("800,10 100x100",
185 minimized
->GetWindowBoundsInScreen().ToString());
187 views::Widget
* fullscreen
= CreateTestWidget(gfx::Rect(900, 10, 100, 100));
188 fullscreen
->SetFullscreen(true);
189 EXPECT_EQ(root_windows
[1], fullscreen
->GetNativeView()->GetRootWindow());
191 EXPECT_EQ("600,0 500x500",
192 fullscreen
->GetWindowBoundsInScreen().ToString());
193 EXPECT_EQ("0,0 500x500",
194 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
196 views::Widget
* unparented_control
= new Widget
;
197 Widget::InitParams params
;
198 params
.bounds
= gfx::Rect(650, 10, 100, 100);
199 params
.context
= CurrentContext();
200 params
.type
= Widget::InitParams::TYPE_CONTROL
;
201 unparented_control
->Init(params
);
202 EXPECT_EQ(root_windows
[1],
203 unparented_control
->GetNativeView()->GetRootWindow());
204 EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer
,
205 unparented_control
->GetNativeView()->parent()->id());
207 aura::Window
* panel
= CreateTestWindowInShellWithDelegateAndType(
208 NULL
, aura::client::WINDOW_TYPE_PANEL
, 0, gfx::Rect(700, 100, 100, 100));
209 EXPECT_EQ(root_windows
[1], panel
->GetRootWindow());
210 EXPECT_EQ(internal::kShellWindowId_PanelContainer
, panel
->parent()->id());
212 // Make sure a window that will delete itself when losing focus
214 aura::WindowTracker tracker
;
215 DeleteOnBlurDelegate delete_on_blur_delegate
;
216 aura::Window
* d2
= CreateTestWindowInShellWithDelegate(
217 &delete_on_blur_delegate
, 0, gfx::Rect(50, 50, 100, 100));
218 delete_on_blur_delegate
.SetWindow(d2
);
219 aura::client::GetFocusClient(root_windows
[0])->FocusWindow(d2
);
222 UpdateDisplay("600x600");
224 // d2 must have been deleted.
225 EXPECT_FALSE(tracker
.Contains(d2
));
227 EXPECT_EQ(root_windows
[0], normal
->GetNativeView()->GetRootWindow());
228 EXPECT_EQ("50,10 100x100", normal
->GetWindowBoundsInScreen().ToString());
229 EXPECT_EQ("50,10 100x100",
230 normal
->GetNativeView()->GetBoundsInRootWindow().ToString());
232 // Maximized area on primary display has 3px (given as
233 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
235 // First clear fullscreen status, since both fullscreen and maximized windows
236 // share the same desktop workspace, which cancels the shelf status.
237 fullscreen
->SetFullscreen(false);
238 EXPECT_EQ(root_windows
[0], maximized
->GetNativeView()->GetRootWindow());
239 EXPECT_EQ("0,0 600x597",
240 maximized
->GetWindowBoundsInScreen().ToString());
241 EXPECT_EQ("0,0 600x597",
242 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
244 // Set fullscreen to true. In that case the 3px inset becomes invisible so
245 // the maximized window can also use the area fully.
246 fullscreen
->SetFullscreen(true);
247 EXPECT_EQ(root_windows
[0], maximized
->GetNativeView()->GetRootWindow());
248 EXPECT_EQ("0,0 600x600",
249 maximized
->GetWindowBoundsInScreen().ToString());
250 EXPECT_EQ("0,0 600x600",
251 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
253 EXPECT_EQ(root_windows
[0], minimized
->GetNativeView()->GetRootWindow());
254 EXPECT_EQ("200,10 100x100",
255 minimized
->GetWindowBoundsInScreen().ToString());
257 EXPECT_EQ(root_windows
[0], fullscreen
->GetNativeView()->GetRootWindow());
258 EXPECT_TRUE(fullscreen
->IsFullscreen());
259 EXPECT_EQ("0,0 600x600",
260 fullscreen
->GetWindowBoundsInScreen().ToString());
261 EXPECT_EQ("0,0 600x600",
262 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
264 // Test if the restore bounds are correctly updated.
265 wm::GetWindowState(maximized
->GetNativeView())->Restore();
266 EXPECT_EQ("100,10 100x100", maximized
->GetWindowBoundsInScreen().ToString());
267 EXPECT_EQ("100,10 100x100",
268 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
270 fullscreen
->SetFullscreen(false);
271 EXPECT_EQ("300,10 100x100",
272 fullscreen
->GetWindowBoundsInScreen().ToString());
273 EXPECT_EQ("300,10 100x100",
274 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
276 // Test if the unparented widget has moved.
277 EXPECT_EQ(root_windows
[0],
278 unparented_control
->GetNativeView()->GetRootWindow());
279 EXPECT_EQ(internal::kShellWindowId_UnparentedControlContainer
,
280 unparented_control
->GetNativeView()->parent()->id());
282 // Test if the panel has moved.
283 EXPECT_EQ(root_windows
[0], panel
->GetRootWindow());
284 EXPECT_EQ(internal::kShellWindowId_PanelContainer
, panel
->parent()->id());
287 TEST_F(RootWindowControllerTest
, MoveWindows_Modal
) {
288 if (!SupportsMultipleDisplays())
291 UpdateDisplay("500x500,500x500");
293 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
294 // Emulate virtual screen coordinate system.
295 root_windows
[0]->SetBounds(gfx::Rect(0, 0, 500, 500));
296 root_windows
[1]->SetBounds(gfx::Rect(500, 0, 500, 500));
298 views::Widget
* normal
= CreateTestWidget(gfx::Rect(300, 10, 100, 100));
299 EXPECT_EQ(root_windows
[0], normal
->GetNativeView()->GetRootWindow());
300 EXPECT_TRUE(wm::IsActiveWindow(normal
->GetNativeView()));
302 views::Widget
* modal
= CreateModalWidget(gfx::Rect(650, 10, 100, 100));
303 EXPECT_EQ(root_windows
[1], modal
->GetNativeView()->GetRootWindow());
304 EXPECT_TRUE(GetModalContainer(root_windows
[1])->Contains(
305 modal
->GetNativeView()));
306 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
308 aura::test::EventGenerator
generator_1st(root_windows
[0]);
309 generator_1st
.ClickLeftButton();
310 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
312 UpdateDisplay("500x500");
313 EXPECT_EQ(root_windows
[0], modal
->GetNativeView()->GetRootWindow());
314 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
315 generator_1st
.ClickLeftButton();
316 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
319 TEST_F(RootWindowControllerTest
, ModalContainer
) {
320 UpdateDisplay("600x600");
321 Shell
* shell
= Shell::GetInstance();
322 internal::RootWindowController
* controller
=
323 shell
->GetPrimaryRootWindowController();
324 EXPECT_EQ(user::LOGGED_IN_USER
,
325 shell
->system_tray_delegate()->GetUserLoginStatus());
326 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
327 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
328 controller
->GetSystemModalLayoutManager(NULL
));
330 views::Widget
* session_modal_widget
=
331 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
332 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
333 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
334 controller
->GetSystemModalLayoutManager(
335 session_modal_widget
->GetNativeView()));
337 shell
->session_state_delegate()->LockScreen();
338 EXPECT_EQ(user::LOGGED_IN_LOCKED
,
339 shell
->system_tray_delegate()->GetUserLoginStatus());
340 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
341 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
342 controller
->GetSystemModalLayoutManager(NULL
));
344 aura::Window
* lock_container
=
345 Shell::GetContainer(controller
->root_window(),
346 internal::kShellWindowId_LockScreenContainer
);
347 views::Widget
* lock_modal_widget
=
348 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container
);
349 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
350 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
351 controller
->GetSystemModalLayoutManager(
352 lock_modal_widget
->GetNativeView()));
353 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
354 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
355 controller
->GetSystemModalLayoutManager(
356 session_modal_widget
->GetNativeView()));
358 shell
->session_state_delegate()->UnlockScreen();
361 TEST_F(RootWindowControllerTest
, ModalContainerNotLoggedInLoggedIn
) {
362 UpdateDisplay("600x600");
363 Shell
* shell
= Shell::GetInstance();
365 // Configure login screen environment.
366 SetUserLoggedIn(false);
367 EXPECT_EQ(user::LOGGED_IN_NONE
,
368 shell
->system_tray_delegate()->GetUserLoginStatus());
369 EXPECT_EQ(0, shell
->session_state_delegate()->NumberOfLoggedInUsers());
370 EXPECT_FALSE(shell
->session_state_delegate()->IsActiveUserSessionStarted());
372 internal::RootWindowController
* controller
=
373 shell
->GetPrimaryRootWindowController();
374 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
375 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
376 controller
->GetSystemModalLayoutManager(NULL
));
378 aura::Window
* lock_container
=
379 Shell::GetContainer(controller
->root_window(),
380 internal::kShellWindowId_LockScreenContainer
);
381 views::Widget
* login_modal_widget
=
382 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100), lock_container
);
383 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
384 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
385 controller
->GetSystemModalLayoutManager(
386 login_modal_widget
->GetNativeView()));
387 login_modal_widget
->Close();
389 // Configure user session environment.
390 SetUserLoggedIn(true);
391 SetSessionStarted(true);
392 EXPECT_EQ(user::LOGGED_IN_USER
,
393 shell
->system_tray_delegate()->GetUserLoginStatus());
394 EXPECT_EQ(1, shell
->session_state_delegate()->NumberOfLoggedInUsers());
395 EXPECT_TRUE(shell
->session_state_delegate()->IsActiveUserSessionStarted());
396 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
397 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
398 controller
->GetSystemModalLayoutManager(NULL
));
400 views::Widget
* session_modal_widget
=
401 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
402 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
403 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
404 controller
->GetSystemModalLayoutManager(
405 session_modal_widget
->GetNativeView()));
408 TEST_F(RootWindowControllerTest
, ModalContainerBlockedSession
) {
409 UpdateDisplay("600x600");
410 Shell
* shell
= Shell::GetInstance();
411 internal::RootWindowController
* controller
=
412 shell
->GetPrimaryRootWindowController();
413 aura::Window
* lock_container
=
414 Shell::GetContainer(controller
->root_window(),
415 internal::kShellWindowId_LockScreenContainer
);
416 for (int block_reason
= FIRST_BLOCK_REASON
;
417 block_reason
< NUMBER_OF_BLOCK_REASONS
;
419 views::Widget
* session_modal_widget
=
420 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
421 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
422 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
423 controller
->GetSystemModalLayoutManager(
424 session_modal_widget
->GetNativeView()));
425 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
426 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
427 controller
->GetSystemModalLayoutManager(NULL
));
428 session_modal_widget
->Close();
430 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
432 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
433 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
434 controller
->GetSystemModalLayoutManager(NULL
));
436 views::Widget
* lock_modal_widget
=
437 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
439 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
440 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
441 controller
->GetSystemModalLayoutManager(
442 lock_modal_widget
->GetNativeView()));
444 session_modal_widget
=
445 CreateModalWidget(gfx::Rect(300, 10, 100, 100));
446 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
447 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
448 controller
->GetSystemModalLayoutManager(
449 session_modal_widget
->GetNativeView()));
450 session_modal_widget
->Close();
452 lock_modal_widget
->Close();
453 UnblockUserSession();
457 TEST_F(RootWindowControllerTest
, GetWindowForFullscreenMode
) {
458 UpdateDisplay("600x600");
459 internal::RootWindowController
* controller
=
460 Shell::GetInstance()->GetPrimaryRootWindowController();
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 // |w3| is a transient child of |w2|.
467 Widget
* w3
= Widget::CreateWindowWithParentAndBounds(NULL
,
468 w2
->GetNativeWindow(), gfx::Rect(0, 0, 100, 100));
470 // Test that GetWindowForFullscreenMode() finds the fullscreen window when one
471 // of its transient children is active.
473 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetWindowForFullscreenMode());
475 // If the topmost window is not fullscreen, it returns NULL.
477 EXPECT_EQ(NULL
, controller
->GetWindowForFullscreenMode());
481 // Only w2 remains, if minimized GetWindowForFullscreenMode should return
484 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetWindowForFullscreenMode());
486 EXPECT_EQ(NULL
, controller
->GetWindowForFullscreenMode());
489 // Test that user session window can't be focused if user session blocked by
490 // some overlapping UI.
491 TEST_F(RootWindowControllerTest
, FocusBlockedWindow
) {
492 UpdateDisplay("600x600");
493 internal::RootWindowController
* controller
=
494 Shell::GetInstance()->GetPrimaryRootWindowController();
495 aura::Window
* lock_container
=
496 Shell::GetContainer(controller
->root_window(),
497 internal::kShellWindowId_LockScreenContainer
);
498 aura::Window
* lock_window
= Widget::CreateWindowWithParentAndBounds(NULL
,
499 lock_container
, gfx::Rect(0, 0, 100, 100))->GetNativeView();
501 aura::Window
* session_window
=
502 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
503 session_window
->Show();
505 for (int block_reason
= FIRST_BLOCK_REASON
;
506 block_reason
< NUMBER_OF_BLOCK_REASONS
;
508 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
509 lock_window
->Focus();
510 EXPECT_TRUE(lock_window
->HasFocus());
511 session_window
->Focus();
512 EXPECT_FALSE(session_window
->HasFocus());
513 UnblockUserSession();
517 // Tracks whether OnWindowDestroying() has been invoked.
518 class DestroyedWindowObserver
: public aura::WindowObserver
{
520 DestroyedWindowObserver() : destroyed_(false), window_(NULL
) {}
521 virtual ~DestroyedWindowObserver() {
525 void SetWindow(Window
* window
) {
527 window
->AddObserver(this);
530 bool destroyed() const { return destroyed_
; }
532 // WindowObserver overrides:
533 virtual void OnWindowDestroying(Window
* window
) OVERRIDE
{
542 window_
->RemoveObserver(this);
549 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver
);
552 // Verifies shutdown doesn't delete windows that are not owned by the parent.
553 TEST_F(RootWindowControllerTest
, DontDeleteWindowsNotOwnedByParent
) {
554 DestroyedWindowObserver observer1
;
555 aura::test::TestWindowDelegate delegate1
;
556 aura::Window
* window1
= new aura::Window(&delegate1
);
557 window1
->SetType(aura::client::WINDOW_TYPE_CONTROL
);
558 window1
->set_owned_by_parent(false);
559 observer1
.SetWindow(window1
);
560 window1
->Init(ui::LAYER_NOT_DRAWN
);
561 aura::client::ParentWindowWithContext(
562 window1
, Shell::GetInstance()->GetPrimaryRootWindow(), gfx::Rect());
564 DestroyedWindowObserver observer2
;
565 aura::Window
* window2
= new aura::Window(NULL
);
566 window2
->set_owned_by_parent(false);
567 observer2
.SetWindow(window2
);
568 window2
->Init(ui::LAYER_NOT_DRAWN
);
569 Shell::GetInstance()->GetPrimaryRootWindow()->AddChild(window2
);
571 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
573 ASSERT_FALSE(observer1
.destroyed());
576 ASSERT_FALSE(observer2
.destroyed());
580 typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest
;
582 // Make sure that an event handler exists for entire display area.
583 TEST_F(NoSessionRootWindowControllerTest
, Event
) {
584 aura::Window
* root
= Shell::GetPrimaryRootWindow();
585 const gfx::Size size
= root
->bounds().size();
586 aura::Window
* event_target
= root
->GetEventHandlerForPoint(gfx::Point(0, 0));
587 EXPECT_TRUE(event_target
);
588 EXPECT_EQ(event_target
,
589 root
->GetEventHandlerForPoint(gfx::Point(0, size
.height() - 1)));
590 EXPECT_EQ(event_target
,
591 root
->GetEventHandlerForPoint(gfx::Point(size
.width() - 1, 0)));
592 EXPECT_EQ(event_target
,
593 root
->GetEventHandlerForPoint(gfx::Point(0, size
.height() - 1)));
594 EXPECT_EQ(event_target
,
595 root
->GetEventHandlerForPoint(
596 gfx::Point(size
.width() - 1, size
.height() - 1)));
599 class VirtualKeyboardRootWindowControllerTest
: public test::AshTestBase
{
601 VirtualKeyboardRootWindowControllerTest() {};
602 virtual ~VirtualKeyboardRootWindowControllerTest() {};
604 virtual void SetUp() OVERRIDE
{
605 CommandLine::ForCurrentProcess()->AppendSwitch(
606 keyboard::switches::kEnableVirtualKeyboard
);
607 test::AshTestBase::SetUp();
608 Shell::GetPrimaryRootWindowController()->ActivateKeyboard(
609 Shell::GetInstance()->keyboard_controller());
613 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest
);
616 // Test for http://crbug.com/297858. Virtual keyboard container should only show
617 // on primary root window.
618 TEST_F(VirtualKeyboardRootWindowControllerTest
,
619 VirtualKeyboardOnPrimaryRootWindowOnly
) {
620 if (!SupportsMultipleDisplays())
623 UpdateDisplay("500x500,500x500");
625 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
626 aura::Window
* primary_root_window
= Shell::GetPrimaryRootWindow();
627 aura::Window
* secondary_root_window
=
628 root_windows
[0] == primary_root_window
?
629 root_windows
[1] : root_windows
[0];
631 ASSERT_TRUE(Shell::GetContainer(
633 internal::kShellWindowId_VirtualKeyboardContainer
));
634 ASSERT_FALSE(Shell::GetContainer(
635 secondary_root_window
,
636 internal::kShellWindowId_VirtualKeyboardContainer
));
639 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive
640 // events at blocked user session.
641 TEST_F(VirtualKeyboardRootWindowControllerTest
,
642 ClickVirtualKeyboardInBlockedWindow
) {
643 aura::Window
* root_window
= Shell::GetPrimaryRootWindow();
644 aura::Window
* keyboard_container
= Shell::GetContainer(root_window
,
645 internal::kShellWindowId_VirtualKeyboardContainer
);
646 ASSERT_TRUE(keyboard_container
);
647 keyboard_container
->Show();
649 ClickTestWindow
* main_delegate
= new ClickTestWindow();
650 scoped_ptr
<aura::Window
> keyboard_window(
651 main_delegate
->CreateTestWindowWithParent(keyboard_container
));
652 keyboard_container
->layout_manager()->OnWindowResized();
653 keyboard_window
->Show();
654 aura::test::EventGenerator
event_generator(root_window
,
655 keyboard_window
.get());
656 event_generator
.ClickLeftButton();
657 int expected_mouse_presses
= 1;
658 EXPECT_EQ(expected_mouse_presses
, main_delegate
->mouse_presses());
660 for (int block_reason
= FIRST_BLOCK_REASON
;
661 block_reason
< NUMBER_OF_BLOCK_REASONS
;
663 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
664 event_generator
.ClickLeftButton();
665 expected_mouse_presses
++;
666 EXPECT_EQ(expected_mouse_presses
, main_delegate
->mouse_presses());
667 UnblockUserSession();
671 // Test for http://crbug.com/299787. RootWindowController should delete
672 // the old container since the keyboard controller creates a new window in
673 // GetWindowContainer().
674 TEST_F(VirtualKeyboardRootWindowControllerTest
,
675 DeleteOldContainerOnVirtualKeyboardInit
) {
676 aura::Window
* root_window
= ash::Shell::GetPrimaryRootWindow();
677 aura::Window
* keyboard_container
= Shell::GetContainer(root_window
,
678 internal::kShellWindowId_VirtualKeyboardContainer
);
679 ASSERT_TRUE(keyboard_container
);
680 // Track the keyboard container window.
681 aura::WindowTracker tracker
;
682 tracker
.Add(keyboard_container
);
683 // Mock a login user profile change to reinitialize the keyboard.
684 ash::Shell::GetInstance()->OnLoginUserProfilePrepared();
685 // keyboard_container should no longer be present.
686 EXPECT_FALSE(tracker
.Contains(keyboard_container
));