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/env.h"
21 #include "ui/aura/root_window.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_tracker.h"
27 #include "ui/keyboard/keyboard_switches.h"
28 #include "ui/views/controls/menu/menu_controller.h"
29 #include "ui/views/widget/widget.h"
30 #include "ui/views/widget/widget_delegate.h"
38 class TestDelegate
: public views::WidgetDelegateView
{
40 explicit TestDelegate(bool system_modal
) : system_modal_(system_modal
) {}
41 virtual ~TestDelegate() {}
43 // Overridden from views::WidgetDelegate:
44 virtual views::View
* GetContentsView() OVERRIDE
{
48 virtual ui::ModalType
GetModalType() const OVERRIDE
{
49 return system_modal_
? ui::MODAL_TYPE_SYSTEM
: ui::MODAL_TYPE_NONE
;
55 DISALLOW_COPY_AND_ASSIGN(TestDelegate
);
58 class DeleteOnBlurDelegate
: public aura::test::TestWindowDelegate
,
59 public aura::client::FocusChangeObserver
{
61 DeleteOnBlurDelegate() : window_(NULL
) {}
62 virtual ~DeleteOnBlurDelegate() {}
64 void SetWindow(aura::Window
* window
) {
66 aura::client::SetFocusChangeObserver(window_
, this);
70 // aura::test::TestWindowDelegate overrides:
71 virtual bool CanFocus() OVERRIDE
{
75 // aura::client::FocusChangeObserver implementation:
76 virtual void OnWindowFocused(aura::Window
* gained_focus
,
77 aura::Window
* lost_focus
) OVERRIDE
{
78 if (window_
== lost_focus
)
82 aura::Window
* window_
;
84 DISALLOW_COPY_AND_ASSIGN(DeleteOnBlurDelegate
);
87 class ClickTestWindow
: public views::WidgetDelegateView
{
89 ClickTestWindow() : mouse_presses_(0) {}
90 virtual ~ClickTestWindow() {}
92 // Overridden from views::WidgetDelegate:
93 virtual views::View
* GetContentsView() OVERRIDE
{
97 aura::Window
* CreateTestWindowWithParent(aura::Window
* parent
) {
99 views::Widget
* widget
= Widget::CreateWindowWithParent(this, parent
);
100 return widget
->GetNativeView();
103 // Overridden from views::View:
104 virtual bool OnMousePressed(const ui::MouseEvent
& event
) OVERRIDE
{
109 int mouse_presses() const { return mouse_presses_
; }
114 DISALLOW_COPY_AND_ASSIGN(ClickTestWindow
);
121 class RootWindowControllerTest
: public test::AshTestBase
{
123 views::Widget
* CreateTestWidget(const gfx::Rect
& bounds
) {
124 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
125 NULL
, CurrentContext(), bounds
);
130 views::Widget
* CreateModalWidget(const gfx::Rect
& bounds
) {
131 views::Widget
* widget
= views::Widget::CreateWindowWithContextAndBounds(
132 new TestDelegate(true), CurrentContext(), bounds
);
137 views::Widget
* CreateModalWidgetWithParent(const gfx::Rect
& bounds
,
138 gfx::NativeWindow parent
) {
139 views::Widget
* widget
=
140 views::Widget::CreateWindowWithParentAndBounds(new TestDelegate(true),
147 aura::Window
* GetModalContainer(aura::RootWindow
* root_window
) {
148 return Shell::GetContainer(
150 ash::internal::kShellWindowId_SystemModalContainer
);
154 TEST_F(RootWindowControllerTest
, MoveWindows_Basic
) {
155 if (!SupportsMultipleDisplays())
158 UpdateDisplay("600x600,500x500");
159 Shell::RootWindowList root_windows
= Shell::GetAllRootWindows();
160 internal::RootWindowController
* controller
=
161 Shell::GetPrimaryRootWindowController();
162 internal::ShelfLayoutManager
* shelf_layout_manager
=
163 controller
->GetShelfLayoutManager();
164 shelf_layout_manager
->SetAutoHideBehavior(
165 ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
167 views::Widget
* normal
= CreateTestWidget(gfx::Rect(650, 10, 100, 100));
168 EXPECT_EQ(root_windows
[1], normal
->GetNativeView()->GetRootWindow());
169 EXPECT_EQ("650,10 100x100", normal
->GetWindowBoundsInScreen().ToString());
170 EXPECT_EQ("50,10 100x100",
171 normal
->GetNativeView()->GetBoundsInRootWindow().ToString());
173 views::Widget
* maximized
= CreateTestWidget(gfx::Rect(700, 10, 100, 100));
174 maximized
->Maximize();
175 EXPECT_EQ(root_windows
[1], maximized
->GetNativeView()->GetRootWindow());
176 EXPECT_EQ("600,0 500x453", maximized
->GetWindowBoundsInScreen().ToString());
177 EXPECT_EQ("0,0 500x453",
178 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
180 views::Widget
* minimized
= CreateTestWidget(gfx::Rect(800, 10, 100, 100));
181 minimized
->Minimize();
182 EXPECT_EQ(root_windows
[1], minimized
->GetNativeView()->GetRootWindow());
183 EXPECT_EQ("800,10 100x100",
184 minimized
->GetWindowBoundsInScreen().ToString());
186 views::Widget
* fullscreen
= CreateTestWidget(gfx::Rect(900, 10, 100, 100));
187 fullscreen
->SetFullscreen(true);
188 EXPECT_EQ(root_windows
[1], fullscreen
->GetNativeView()->GetRootWindow());
190 EXPECT_EQ("600,0 500x500",
191 fullscreen
->GetWindowBoundsInScreen().ToString());
192 EXPECT_EQ("0,0 500x500",
193 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
195 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());
206 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());
211 // Make sure a window that will delete itself when losing focus
213 aura::WindowTracker tracker
;
214 DeleteOnBlurDelegate delete_on_blur_delegate
;
215 aura::Window
* d2
= CreateTestWindowInShellWithDelegate(
216 &delete_on_blur_delegate
, 0, gfx::Rect(50, 50, 100, 100));
217 delete_on_blur_delegate
.SetWindow(d2
);
218 aura::client::GetFocusClient(root_windows
[0])->FocusWindow(d2
);
221 UpdateDisplay("600x600");
223 // d2 must have been deleted.
224 EXPECT_FALSE(tracker
.Contains(d2
));
226 EXPECT_EQ(root_windows
[0], normal
->GetNativeView()->GetRootWindow());
227 EXPECT_EQ("50,10 100x100", normal
->GetWindowBoundsInScreen().ToString());
228 EXPECT_EQ("50,10 100x100",
229 normal
->GetNativeView()->GetBoundsInRootWindow().ToString());
231 // Maximized area on primary display has 3px (given as
232 // kAutoHideSize in shelf_layout_manager.cc) inset at the bottom.
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);
237 EXPECT_EQ(root_windows
[0], maximized
->GetNativeView()->GetRootWindow());
238 EXPECT_EQ("0,0 600x597",
239 maximized
->GetWindowBoundsInScreen().ToString());
240 EXPECT_EQ("0,0 600x597",
241 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
243 // 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());
252 EXPECT_EQ(root_windows
[0], minimized
->GetNativeView()->GetRootWindow());
253 EXPECT_EQ("200,10 100x100",
254 minimized
->GetWindowBoundsInScreen().ToString());
256 EXPECT_EQ(root_windows
[0], fullscreen
->GetNativeView()->GetRootWindow());
257 EXPECT_TRUE(fullscreen
->IsFullscreen());
258 EXPECT_EQ("0,0 600x600",
259 fullscreen
->GetWindowBoundsInScreen().ToString());
260 EXPECT_EQ("0,0 600x600",
261 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
263 // Test if the restore bounds are correctly updated.
264 wm::GetWindowState(maximized
->GetNativeView())->Restore();
265 EXPECT_EQ("100,10 100x100", maximized
->GetWindowBoundsInScreen().ToString());
266 EXPECT_EQ("100,10 100x100",
267 maximized
->GetNativeView()->GetBoundsInRootWindow().ToString());
269 fullscreen
->SetFullscreen(false);
270 EXPECT_EQ("300,10 100x100",
271 fullscreen
->GetWindowBoundsInScreen().ToString());
272 EXPECT_EQ("300,10 100x100",
273 fullscreen
->GetNativeView()->GetBoundsInRootWindow().ToString());
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());
281 // Test if the panel has moved.
282 EXPECT_EQ(root_windows
[0], panel
->GetRootWindow());
283 EXPECT_EQ(internal::kShellWindowId_PanelContainer
, panel
->parent()->id());
286 TEST_F(RootWindowControllerTest
, MoveWindows_Modal
) {
287 if (!SupportsMultipleDisplays())
290 UpdateDisplay("500x500,500x500");
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));
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()));
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()));
307 aura::test::EventGenerator
generator_1st(root_windows
[0]);
308 generator_1st
.ClickLeftButton();
309 EXPECT_TRUE(wm::IsActiveWindow(modal
->GetNativeView()));
311 UpdateDisplay("500x500");
312 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()));
318 TEST_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
,
324 shell
->system_tray_delegate()->GetUserLoginStatus());
325 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
326 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
327 controller
->GetSystemModalLayoutManager(NULL
));
329 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()));
336 shell
->session_state_delegate()->LockScreen();
337 EXPECT_EQ(user::LOGGED_IN_LOCKED
,
338 shell
->system_tray_delegate()->GetUserLoginStatus());
339 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
340 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
341 controller
->GetSystemModalLayoutManager(NULL
));
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()));
357 shell
->session_state_delegate()->UnlockScreen();
360 TEST_F(RootWindowControllerTest
, ModalContainerNotLoggedInLoggedIn
) {
361 UpdateDisplay("600x600");
362 Shell
* shell
= Shell::GetInstance();
364 // Configure login screen environment.
365 SetUserLoggedIn(false);
366 EXPECT_EQ(user::LOGGED_IN_NONE
,
367 shell
->system_tray_delegate()->GetUserLoginStatus());
368 EXPECT_EQ(0, shell
->session_state_delegate()->NumberOfLoggedInUsers());
369 EXPECT_FALSE(shell
->session_state_delegate()->IsActiveUserSessionStarted());
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
));
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();
388 // Configure user session environment.
389 SetUserLoggedIn(true);
390 SetSessionStarted(true);
391 EXPECT_EQ(user::LOGGED_IN_USER
,
392 shell
->system_tray_delegate()->GetUserLoginStatus());
393 EXPECT_EQ(1, shell
->session_state_delegate()->NumberOfLoggedInUsers());
394 EXPECT_TRUE(shell
->session_state_delegate()->IsActiveUserSessionStarted());
395 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
396 internal::kShellWindowId_SystemModalContainer
)->layout_manager(),
397 controller
->GetSystemModalLayoutManager(NULL
));
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()));
407 TEST_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
;
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();
429 BlockUserSession(static_cast<UserSessionBlockReason
>(block_reason
));
431 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
432 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
433 controller
->GetSystemModalLayoutManager(NULL
));
435 views::Widget
* lock_modal_widget
=
436 CreateModalWidgetWithParent(gfx::Rect(300, 10, 100, 100),
438 EXPECT_EQ(Shell::GetContainer(controller
->root_window(),
439 internal::kShellWindowId_LockSystemModalContainer
)->layout_manager(),
440 controller
->GetSystemModalLayoutManager(
441 lock_modal_widget
->GetNativeView()));
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();
451 lock_modal_widget
->Close();
452 UnblockUserSession();
456 TEST_F(RootWindowControllerTest
, GetTopmostFullscreenWindow
) {
457 UpdateDisplay("600x600");
458 internal::RootWindowController
* controller
=
459 Shell::GetInstance()->GetPrimaryRootWindowController();
461 Widget
* w1
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
463 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));
469 // Test that GetTopmostFullscreenWindow() finds the fullscreen window when one
470 // of its transient children is active.
472 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetTopmostFullscreenWindow());
474 // Since there's only one desktop workspace, it always returns the same
475 // fullscreen window.
477 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetTopmostFullscreenWindow());
480 TEST_F(RootWindowControllerTest
, MultipleFullscreenWindows
) {
481 UpdateDisplay("600x600");
482 internal::RootWindowController
* controller
=
483 Shell::GetInstance()->GetPrimaryRootWindowController();
485 Widget
* w1
= CreateTestWidget(gfx::Rect(0, 0, 100, 100));
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);
492 // Test that GetTopmostFullscreenWindow() finds the active fullscreen window.
494 EXPECT_EQ(w2
->GetNativeWindow(), controller
->GetTopmostFullscreenWindow());
496 EXPECT_EQ(w3
->GetNativeWindow(), controller
->GetTopmostFullscreenWindow());
498 // If the active window is not fullscreen, it still returns the topmost
499 // fullscreen window, which is the last active one.
501 EXPECT_EQ(w3
->GetNativeWindow(), controller
->GetTopmostFullscreenWindow());
504 // Test that user session window can't be focused if user session blocked by
505 // some overlapping UI.
506 TEST_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();
516 aura::Window
* session_window
=
517 CreateTestWidget(gfx::Rect(0, 0, 100, 100))->GetNativeView();
518 session_window
->Show();
520 for (int block_reason
= FIRST_BLOCK_REASON
;
521 block_reason
< NUMBER_OF_BLOCK_REASONS
;
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();
532 // Tracks whether OnWindowDestroying() has been invoked.
533 class DestroyedWindowObserver
: public aura::WindowObserver
{
535 DestroyedWindowObserver() : destroyed_(false), window_(NULL
) {}
536 virtual ~DestroyedWindowObserver() {
540 void SetWindow(Window
* window
) {
542 window
->AddObserver(this);
545 bool destroyed() const { return destroyed_
; }
547 // WindowObserver overrides:
548 virtual void OnWindowDestroying(Window
* window
) OVERRIDE
{
557 window_
->RemoveObserver(this);
564 DISALLOW_COPY_AND_ASSIGN(DestroyedWindowObserver
);
567 // Verifies shutdown doesn't delete windows that are not owned by the parent.
568 TEST_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());
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
);
586 Shell::GetInstance()->GetPrimaryRootWindowController()->CloseChildWindows();
588 ASSERT_FALSE(observer1
.destroyed());
591 ASSERT_FALSE(observer2
.destroyed());
595 typedef test::NoSessionAshTestBase NoSessionRootWindowControllerTest
;
597 // Make sure that an event handler exists for entire display area.
598 TEST_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)));
614 class VirtualKeyboardRootWindowControllerTest
: public test::AshTestBase
{
616 VirtualKeyboardRootWindowControllerTest() {};
617 virtual ~VirtualKeyboardRootWindowControllerTest() {};
619 virtual void SetUp() OVERRIDE
{
620 CommandLine::ForCurrentProcess()->AppendSwitch(
621 keyboard::switches::kEnableVirtualKeyboard
);
622 test::AshTestBase::SetUp();
626 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardRootWindowControllerTest
);
629 // Test for http://crbug.com/297858. Virtual keyboard container should only show
630 // on primary root window.
631 TEST_F(VirtualKeyboardRootWindowControllerTest
,
632 VirtualKeyboardOnPrimaryRootWindowOnly
) {
633 if (!SupportsMultipleDisplays())
636 UpdateDisplay("500x500,500x500");
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];
644 ASSERT_TRUE(Shell::GetContainer(
646 internal::kShellWindowId_VirtualKeyboardContainer
));
647 ASSERT_FALSE(Shell::GetContainer(
648 secondary_root_window
,
649 internal::kShellWindowId_VirtualKeyboardContainer
));
652 // Test for http://crbug.com/263599. Virtual keyboard should be able to receive
653 // events at blocked user session.
654 TEST_F(VirtualKeyboardRootWindowControllerTest
,
655 ClickVirtualKeyboardInBlockedWindow
) {
656 aura::RootWindow
* root_window
= Shell::GetPrimaryRootWindow();
657 aura::Window
* keyboard_container
= Shell::GetContainer(root_window
,
658 internal::kShellWindowId_VirtualKeyboardContainer
);
659 ASSERT_TRUE(keyboard_container
);
660 keyboard_container
->Show();
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());
673 for (int block_reason
= FIRST_BLOCK_REASON
;
674 block_reason
< NUMBER_OF_BLOCK_REASONS
;
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();
684 // Test for http://crbug.com/299787. RootWindowController should delete
685 // the old container since the keyboard controller creates a new window in
686 // GetWindowContainer().
687 TEST_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
));