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/shelf/shelf_layout_manager.h"
7 #include "ash/accelerators/accelerator_controller.h"
8 #include "ash/accelerators/accelerator_table.h"
9 #include "ash/ash_switches.h"
10 #include "ash/display/display_controller.h"
11 #include "ash/display/display_manager.h"
12 #include "ash/focus_cycler.h"
13 #include "ash/root_window_controller.h"
14 #include "ash/session/session_state_delegate.h"
15 #include "ash/shelf/shelf.h"
16 #include "ash/shelf/shelf_layout_manager_observer.h"
17 #include "ash/shelf/shelf_view.h"
18 #include "ash/shelf/shelf_widget.h"
19 #include "ash/shell.h"
20 #include "ash/shell_window_ids.h"
21 #include "ash/system/status_area_widget.h"
22 #include "ash/system/tray/system_tray.h"
23 #include "ash/system/tray/system_tray_item.h"
24 #include "ash/test/ash_test_base.h"
25 #include "ash/test/shelf_test_api.h"
26 #include "ash/wm/window_state.h"
27 #include "ash/wm/window_util.h"
28 #include "base/command_line.h"
29 #include "base/strings/utf_string_conversions.h"
30 #include "ui/aura/client/aura_constants.h"
31 #include "ui/aura/client/window_tree_client.h"
32 #include "ui/aura/window.h"
33 #include "ui/aura/window_event_dispatcher.h"
34 #include "ui/compositor/layer.h"
35 #include "ui/compositor/layer_animator.h"
36 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
37 #include "ui/events/gesture_detection/gesture_configuration.h"
38 #include "ui/events/test/event_generator.h"
39 #include "ui/gfx/display.h"
40 #include "ui/gfx/screen.h"
41 #include "ui/views/controls/label.h"
42 #include "ui/views/layout/fill_layout.h"
43 #include "ui/views/view.h"
44 #include "ui/views/widget/widget.h"
47 #include "base/win/windows_version.h"
53 void StepWidgetLayerAnimatorToEnd(views::Widget
* widget
) {
54 widget
->GetNativeView()->layer()->GetAnimator()->Step(
55 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
58 ShelfWidget
* GetShelfWidget() {
59 return Shell::GetPrimaryRootWindowController()->shelf();
62 ShelfLayoutManager
* GetShelfLayoutManager() {
63 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
66 SystemTray
* GetSystemTray() {
67 return Shell::GetPrimaryRootWindowController()->GetSystemTray();
70 // Class which waits till the shelf finishes animating to the target size and
71 // counts the number of animation steps.
72 class ShelfAnimationWaiter
: views::WidgetObserver
{
74 explicit ShelfAnimationWaiter(const gfx::Rect
& target_bounds
)
75 : target_bounds_(target_bounds
),
77 done_waiting_(false) {
78 GetShelfWidget()->AddObserver(this);
81 ~ShelfAnimationWaiter() override
{ GetShelfWidget()->RemoveObserver(this); }
83 // Wait till the shelf finishes animating to its expected bounds.
84 void WaitTillDoneAnimating() {
85 if (IsDoneAnimating())
88 base::MessageLoop::current()->Run();
91 // Returns true if the animation has completed and it was valid.
92 bool WasValidAnimation() const {
93 return done_waiting_
&& animation_steps_
> 0;
97 // Returns true if shelf has finished animating to the target size.
98 bool IsDoneAnimating() const {
99 ShelfLayoutManager
* layout_manager
= GetShelfLayoutManager();
100 gfx::Rect current_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
101 int size
= layout_manager
->PrimaryAxisValue(current_bounds
.height(),
102 current_bounds
.width());
103 int desired_size
= layout_manager
->PrimaryAxisValue(target_bounds_
.height(),
104 target_bounds_
.width());
105 return (size
== desired_size
);
108 // views::WidgetObserver override.
109 void OnWidgetBoundsChanged(views::Widget
* widget
,
110 const gfx::Rect
& new_bounds
) override
{
115 if (IsDoneAnimating()) {
116 done_waiting_
= true;
117 base::MessageLoop::current()->Quit();
121 gfx::Rect target_bounds_
;
122 int animation_steps_
;
125 DISALLOW_COPY_AND_ASSIGN(ShelfAnimationWaiter
);
128 class ShelfDragCallback
{
130 ShelfDragCallback(const gfx::Rect
& not_visible
, const gfx::Rect
& visible
)
131 : not_visible_bounds_(not_visible
),
132 visible_bounds_(visible
),
133 was_visible_on_drag_start_(false) {
134 EXPECT_EQ(not_visible_bounds_
.bottom(), visible_bounds_
.bottom());
137 virtual ~ShelfDragCallback() {
140 void ProcessScroll(ui::EventType type
, const gfx::Vector2dF
& delta
) {
141 if (GetShelfLayoutManager()->visibility_state() == ash::SHELF_HIDDEN
)
144 if (type
== ui::ET_GESTURE_SCROLL_BEGIN
) {
145 scroll_
= gfx::Vector2dF();
146 was_visible_on_drag_start_
= GetShelfLayoutManager()->IsVisible();
150 // The state of the shelf at the end of the gesture is tested separately.
151 if (type
== ui::ET_GESTURE_SCROLL_END
)
154 if (type
== ui::ET_GESTURE_SCROLL_UPDATE
)
157 gfx::Rect shelf_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
158 if (GetShelfLayoutManager()->IsHorizontalAlignment()) {
159 EXPECT_EQ(not_visible_bounds_
.bottom(), shelf_bounds
.bottom());
160 EXPECT_EQ(visible_bounds_
.bottom(), shelf_bounds
.bottom());
161 } else if (SHELF_ALIGNMENT_RIGHT
==
162 GetShelfLayoutManager()->GetAlignment()){
163 EXPECT_EQ(not_visible_bounds_
.right(), shelf_bounds
.right());
164 EXPECT_EQ(visible_bounds_
.right(), shelf_bounds
.right());
165 } else if (SHELF_ALIGNMENT_LEFT
==
166 GetShelfLayoutManager()->GetAlignment()) {
167 EXPECT_EQ(not_visible_bounds_
.x(), shelf_bounds
.x());
168 EXPECT_EQ(visible_bounds_
.x(), shelf_bounds
.x());
171 // if the shelf is being dimmed test dimmer bounds as well.
172 if (GetShelfWidget()->GetDimsShelf())
173 EXPECT_EQ(GetShelfWidget()->GetWindowBoundsInScreen(),
174 GetShelfWidget()->GetDimmerBoundsForTest());
176 // The shelf should never be smaller than the hidden state.
177 EXPECT_GE(shelf_bounds
.height(), not_visible_bounds_
.height());
178 float scroll_delta
= GetShelfLayoutManager()->PrimaryAxisValue(
181 bool increasing_drag
=
182 GetShelfLayoutManager()->SelectValueForShelfAlignment(
187 int shelf_size
= GetShelfLayoutManager()->PrimaryAxisValue(
188 shelf_bounds
.height(),
189 shelf_bounds
.width());
190 int visible_bounds_size
= GetShelfLayoutManager()->PrimaryAxisValue(
191 visible_bounds_
.height(),
192 visible_bounds_
.width());
193 int not_visible_bounds_size
= GetShelfLayoutManager()->PrimaryAxisValue(
194 not_visible_bounds_
.height(),
195 not_visible_bounds_
.width());
196 if (was_visible_on_drag_start_
) {
197 if (increasing_drag
) {
198 // If dragging inwards from the visible state, then the shelf should
199 // increase in size, but not more than the scroll delta.
200 EXPECT_LE(visible_bounds_size
, shelf_size
);
201 EXPECT_LE(std::abs(shelf_size
- visible_bounds_size
),
202 std::abs(scroll_delta
));
204 if (shelf_size
> not_visible_bounds_size
) {
205 // If dragging outwards from the visible state, then the shelf
206 // should decrease in size, until it reaches the minimum size.
207 EXPECT_EQ(shelf_size
, visible_bounds_size
- std::abs(scroll_delta
));
211 if (std::abs(scroll_delta
) <
212 visible_bounds_size
- not_visible_bounds_size
) {
213 // Tests that the shelf sticks with the touch point during the drag
214 // until the shelf is completely visible.
215 EXPECT_EQ(shelf_size
, not_visible_bounds_size
+ std::abs(scroll_delta
));
217 // Tests that after the shelf is completely visible, the shelf starts
218 // resisting the drag.
219 EXPECT_LT(shelf_size
, not_visible_bounds_size
+ std::abs(scroll_delta
));
225 const gfx::Rect not_visible_bounds_
;
226 const gfx::Rect visible_bounds_
;
227 gfx::Vector2dF scroll_
;
228 bool was_visible_on_drag_start_
;
230 DISALLOW_COPY_AND_ASSIGN(ShelfDragCallback
);
233 class ShelfLayoutObserverTest
: public ShelfLayoutManagerObserver
{
235 ShelfLayoutObserverTest()
236 : changed_auto_hide_state_(false) {
239 ~ShelfLayoutObserverTest() override
{}
241 bool changed_auto_hide_state() const { return changed_auto_hide_state_
; }
244 void OnAutoHideStateChanged(ShelfAutoHideState new_state
) override
{
245 changed_auto_hide_state_
= true;
248 bool changed_auto_hide_state_
;
250 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutObserverTest
);
253 // Trivial item implementation that tracks its views for testing.
254 class TestItem
: public SystemTrayItem
{
257 : SystemTrayItem(GetSystemTray()),
260 detailed_view_(NULL
),
261 notification_view_(NULL
) {}
263 views::View
* CreateTrayView(user::LoginStatus status
) override
{
264 tray_view_
= new views::View
;
265 // Add a label so it has non-zero width.
266 tray_view_
->SetLayoutManager(new views::FillLayout
);
267 tray_view_
->AddChildView(new views::Label(base::UTF8ToUTF16("Tray")));
271 views::View
* CreateDefaultView(user::LoginStatus status
) override
{
272 default_view_
= new views::View
;
273 default_view_
->SetLayoutManager(new views::FillLayout
);
274 default_view_
->AddChildView(new views::Label(base::UTF8ToUTF16("Default")));
275 return default_view_
;
278 views::View
* CreateDetailedView(user::LoginStatus status
) override
{
279 detailed_view_
= new views::View
;
280 detailed_view_
->SetLayoutManager(new views::FillLayout
);
281 detailed_view_
->AddChildView(
282 new views::Label(base::UTF8ToUTF16("Detailed")));
283 return detailed_view_
;
286 views::View
* CreateNotificationView(user::LoginStatus status
) override
{
287 notification_view_
= new views::View
;
288 return notification_view_
;
291 void DestroyTrayView() override
{ tray_view_
= NULL
; }
293 void DestroyDefaultView() override
{ default_view_
= NULL
; }
295 void DestroyDetailedView() override
{ detailed_view_
= NULL
; }
297 void DestroyNotificationView() override
{ notification_view_
= NULL
; }
299 void UpdateAfterLoginStatusChange(user::LoginStatus status
) override
{}
301 views::View
* tray_view() const { return tray_view_
; }
302 views::View
* default_view() const { return default_view_
; }
303 views::View
* detailed_view() const { return detailed_view_
; }
304 views::View
* notification_view() const { return notification_view_
; }
307 views::View
* tray_view_
;
308 views::View
* default_view_
;
309 views::View
* detailed_view_
;
310 views::View
* notification_view_
;
312 DISALLOW_COPY_AND_ASSIGN(TestItem
);
317 class ShelfLayoutManagerTest
: public ash::test::AshTestBase
{
319 ShelfLayoutManagerTest() {}
321 void SetState(ShelfLayoutManager
* shelf
,
322 ShelfVisibilityState state
) {
323 shelf
->SetState(state
);
326 void UpdateAutoHideStateNow() {
327 GetShelfLayoutManager()->UpdateAutoHideStateNow();
330 aura::Window
* CreateTestWindow() {
331 aura::Window
* window
= new aura::Window(NULL
);
332 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
333 window
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
334 window
->Init(ui::LAYER_TEXTURED
);
335 ParentWindowInPrimaryRootWindow(window
);
339 aura::Window
* CreateTestWindowInParent(aura::Window
* root_window
) {
340 aura::Window
* window
= new aura::Window(NULL
);
341 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
342 window
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
343 window
->Init(ui::LAYER_TEXTURED
);
344 aura::client::ParentWindowWithContext(window
, root_window
, gfx::Rect());
348 views::Widget
* CreateTestWidgetWithParams(
349 const views::Widget::InitParams
& params
) {
350 views::Widget
* out
= new views::Widget
;
356 // Create a simple widget attached to the current context (will
357 // delete on TearDown).
358 views::Widget
* CreateTestWidget() {
359 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
360 params
.bounds
= gfx::Rect(0, 0, 200, 200);
361 params
.context
= CurrentContext();
362 return CreateTestWidgetWithParams(params
);
365 void RunGestureDragTests(gfx::Vector2d
);
367 // Turn on the lock screen.
369 Shell::GetInstance()->session_state_delegate()->LockScreen();
370 // The test session state delegate does not fire the lock state change.
371 Shell::GetInstance()->OnLockStateChanged(true);
374 // Turn off the lock screen.
375 void UnlockScreen() {
376 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
377 // The test session state delegate does not fire the lock state change.
378 Shell::GetInstance()->OnLockStateChanged(false);
381 // Open the add user screen if |show| is true, otherwise end it.
382 void ShowAddUserScreen(bool show
) {
383 SetUserAddingScreenRunning(show
);
384 ShelfLayoutManager
* manager
= GetShelfWidget()->shelf_layout_manager();
385 manager
->SessionStateChanged(
386 show
? SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY
:
387 SessionStateDelegate::SESSION_STATE_ACTIVE
);
391 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest
);
394 void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta
) {
395 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
396 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
397 views::Widget
* widget
= new views::Widget
;
398 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
399 params
.bounds
= gfx::Rect(0, 0, 200, 200);
400 params
.context
= CurrentContext();
401 widget
->Init(params
);
405 // The time delta should be large enough to prevent accidental fling creation.
406 const base::TimeDelta kTimeDelta
= base::TimeDelta::FromMilliseconds(100);
408 aura::Window
* window
= widget
->GetNativeWindow();
409 shelf
->LayoutShelf();
411 gfx::Rect shelf_shown
= GetShelfWidget()->GetWindowBoundsInScreen();
412 gfx::Rect bounds_shelf
= window
->bounds();
413 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
415 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
416 shelf
->LayoutShelf();
417 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
419 gfx::Rect bounds_noshelf
= window
->bounds();
420 gfx::Rect shelf_hidden
= GetShelfWidget()->GetWindowBoundsInScreen();
422 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
423 shelf
->LayoutShelf();
425 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
426 const int kNumScrollSteps
= 4;
427 ShelfDragCallback
handler(shelf_hidden
, shelf_shown
);
429 // Swipe up on the shelf. This should not change any state.
430 gfx::Point start
= GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
431 gfx::Point end
= start
+ delta
;
433 // Swipe down on the shelf to hide it.
434 generator
.GestureScrollSequenceWithCallback(
439 base::Bind(&ShelfDragCallback::ProcessScroll
,
440 base::Unretained(&handler
)));
441 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
442 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
443 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
444 EXPECT_NE(bounds_shelf
.ToString(), window
->bounds().ToString());
445 EXPECT_NE(shelf_shown
.ToString(),
446 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
448 // Swipe up to show the shelf.
449 generator
.GestureScrollSequenceWithCallback(
454 base::Bind(&ShelfDragCallback::ProcessScroll
,
455 base::Unretained(&handler
)));
456 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
457 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
458 EXPECT_EQ(bounds_shelf
.ToString(), window
->bounds().ToString());
459 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
460 GetShelfWidget()->GetWindowBoundsInScreen());
461 EXPECT_EQ(shelf_shown
.ToString(),
462 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
464 // Swipe up again. The shelf should hide.
466 generator
.GestureScrollSequenceWithCallback(
471 base::Bind(&ShelfDragCallback::ProcessScroll
,
472 base::Unretained(&handler
)));
473 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
474 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
475 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
476 EXPECT_EQ(shelf_hidden
.ToString(),
477 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
479 // Swipe up yet again to show it.
481 generator
.GestureScrollSequenceWithCallback(
486 base::Bind(&ShelfDragCallback::ProcessScroll
,
487 base::Unretained(&handler
)));
489 // Swipe down very little. It shouldn't change any state.
490 if (GetShelfLayoutManager()->IsHorizontalAlignment())
491 end
.set_y(start
.y() + shelf_shown
.height() * 3 / 10);
492 else if (SHELF_ALIGNMENT_LEFT
== GetShelfLayoutManager()->GetAlignment())
493 end
.set_x(start
.x() - shelf_shown
.width() * 3 / 10);
494 else if (SHELF_ALIGNMENT_RIGHT
== GetShelfLayoutManager()->GetAlignment())
495 end
.set_x(start
.x() + shelf_shown
.width() * 3 / 10);
496 generator
.GestureScrollSequence(start
, end
, kTimeDelta
, 5);
497 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
498 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
499 EXPECT_EQ(bounds_shelf
.ToString(), window
->bounds().ToString());
500 EXPECT_EQ(shelf_shown
.ToString(),
501 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
503 // Swipe down again to hide.
505 generator
.GestureScrollSequenceWithCallback(
510 base::Bind(&ShelfDragCallback::ProcessScroll
,
511 base::Unretained(&handler
)));
512 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
513 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
514 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
515 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
516 EXPECT_EQ(bounds_noshelf
.ToString(), window
->bounds().ToString());
517 EXPECT_EQ(shelf_hidden
.ToString(),
518 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
520 // Swipe up in extended hit region to show it.
521 gfx::Point extended_start
= start
;
522 if (GetShelfLayoutManager()->IsHorizontalAlignment())
523 extended_start
.set_y(GetShelfWidget()->GetWindowBoundsInScreen().y() -1);
524 else if (SHELF_ALIGNMENT_LEFT
== GetShelfLayoutManager()->GetAlignment())
525 extended_start
.set_x(
526 GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
527 else if (SHELF_ALIGNMENT_RIGHT
== GetShelfLayoutManager()->GetAlignment())
528 extended_start
.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
529 end
= extended_start
- delta
;
530 generator
.GestureScrollSequenceWithCallback(
535 base::Bind(&ShelfDragCallback::ProcessScroll
,
536 base::Unretained(&handler
)));
537 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
538 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
539 EXPECT_EQ(bounds_shelf
.ToString(), window
->bounds().ToString());
540 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
541 GetShelfWidget()->GetWindowBoundsInScreen());
542 EXPECT_EQ(shelf_shown
.ToString(),
543 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
545 // Swipe down again to hide.
547 generator
.GestureScrollSequenceWithCallback(
552 base::Bind(&ShelfDragCallback::ProcessScroll
,
553 base::Unretained(&handler
)));
554 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
555 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
556 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
557 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
558 EXPECT_EQ(bounds_noshelf
.ToString(), window
->bounds().ToString());
559 EXPECT_EQ(shelf_hidden
.ToString(),
560 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
562 // Swipe up outside the hit area. This should not change anything.
563 gfx::Point outside_start
= gfx::Point(
564 (GetShelfWidget()->GetWindowBoundsInScreen().x() +
565 GetShelfWidget()->GetWindowBoundsInScreen().right())/2,
566 GetShelfWidget()->GetWindowBoundsInScreen().y() - 50);
567 end
= outside_start
+ delta
;
568 generator
.GestureScrollSequence(
569 outside_start
, end
, kTimeDelta
, kNumScrollSteps
);
570 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
571 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
572 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
573 EXPECT_EQ(shelf_hidden
.ToString(),
574 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
576 // Swipe up from below the shelf where a bezel would be, this should show the
578 gfx::Point below_start
= start
;
579 if (GetShelfLayoutManager()->IsHorizontalAlignment())
580 below_start
.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() + 1);
581 else if (SHELF_ALIGNMENT_LEFT
== GetShelfLayoutManager()->GetAlignment())
583 GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
584 else if (SHELF_ALIGNMENT_RIGHT
== GetShelfLayoutManager()->GetAlignment())
585 below_start
.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
586 end
= below_start
- delta
;
587 generator
.GestureScrollSequence(
588 below_start
, end
, kTimeDelta
, kNumScrollSteps
);
589 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
590 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
591 EXPECT_EQ(bounds_shelf
.ToString(), window
->bounds().ToString());
592 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
593 GetShelfWidget()->GetWindowBoundsInScreen());
594 EXPECT_EQ(shelf_shown
.ToString(),
595 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
597 // Swipe down again to hide.
599 generator
.GestureScrollSequenceWithCallback(
604 base::Bind(&ShelfDragCallback::ProcessScroll
,
605 base::Unretained(&handler
)));
606 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
607 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
608 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
609 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
610 EXPECT_EQ(bounds_noshelf
.ToString(), window
->bounds().ToString());
611 EXPECT_EQ(shelf_hidden
.ToString(),
612 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
614 // Put |widget| into fullscreen. Set the shelf to be auto hidden when |widget|
615 // is fullscreen. (eg browser immersive fullscreen).
616 widget
->SetFullscreen(true);
617 wm::GetWindowState(window
)->set_hide_shelf_when_fullscreen(false);
618 shelf
->UpdateVisibilityState();
620 gfx::Rect bounds_fullscreen
= window
->bounds();
621 EXPECT_TRUE(widget
->IsFullscreen());
622 EXPECT_NE(bounds_noshelf
.ToString(), bounds_fullscreen
.ToString());
624 // Swipe up. This should show the shelf.
625 end
= below_start
- delta
;
626 generator
.GestureScrollSequenceWithCallback(
631 base::Bind(&ShelfDragCallback::ProcessScroll
,
632 base::Unretained(&handler
)));
633 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
634 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
635 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
636 EXPECT_EQ(shelf_shown
.ToString(),
637 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
638 EXPECT_EQ(bounds_fullscreen
.ToString(), window
->bounds().ToString());
640 // Swipe up again. This should hide the shelf.
641 generator
.GestureScrollSequenceWithCallback(
646 base::Bind(&ShelfDragCallback::ProcessScroll
,
647 base::Unretained(&handler
)));
648 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
649 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
650 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
651 EXPECT_EQ(shelf_hidden
.ToString(),
652 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
653 EXPECT_EQ(bounds_fullscreen
.ToString(), window
->bounds().ToString());
655 // Set the shelf to be hidden when |widget| is fullscreen. (eg tab fullscreen
656 // with or without immersive browser fullscreen).
657 wm::GetWindowState(window
)->set_hide_shelf_when_fullscreen(true);
658 shelf
->UpdateVisibilityState();
659 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
660 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
662 // Swipe-up. This should not change anything.
664 generator
.GestureScrollSequenceWithCallback(
669 base::Bind(&ShelfDragCallback::ProcessScroll
,
670 base::Unretained(&handler
)));
671 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
672 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
673 EXPECT_EQ(bounds_fullscreen
.ToString(), window
->bounds().ToString());
675 // Close actually, otherwise further event may be affected since widget
676 // is fullscreen status.
678 RunAllPendingInMessageLoop();
680 // The shelf should be shown because there are no more visible windows.
681 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
682 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
683 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
685 // Swipe-up to hide. This should have no effect because there are no visible
687 end
= below_start
- delta
;
688 generator
.GestureScrollSequenceWithCallback(
693 base::Bind(&ShelfDragCallback::ProcessScroll
,
694 base::Unretained(&handler
)));
695 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
696 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
697 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
700 // Need to be implemented. http://crbug.com/111279.
702 #define MAYBE_SetVisible DISABLED_SetVisible
704 #define MAYBE_SetVisible SetVisible
706 // Makes sure SetVisible updates work area and widget appropriately.
707 TEST_F(ShelfLayoutManagerTest
, MAYBE_SetVisible
) {
708 ShelfWidget
* shelf
= GetShelfWidget();
709 ShelfLayoutManager
* manager
= shelf
->shelf_layout_manager();
710 // Force an initial layout.
711 manager
->LayoutShelf();
712 EXPECT_EQ(SHELF_VISIBLE
, manager
->visibility_state());
714 gfx::Rect
status_bounds(
715 shelf
->status_area_widget()->GetWindowBoundsInScreen());
716 gfx::Rect
shelf_bounds(
717 shelf
->GetWindowBoundsInScreen());
718 int shelf_height
= manager
->GetIdealBounds().height();
719 gfx::Screen
* screen
= Shell::GetScreen();
720 gfx::Display display
= screen
->GetDisplayNearestWindow(
721 Shell::GetPrimaryRootWindow());
722 ASSERT_NE(-1, display
.id());
723 // Bottom inset should be the max of widget heights.
724 EXPECT_EQ(shelf_height
, display
.GetWorkAreaInsets().bottom());
727 SetState(manager
, SHELF_HIDDEN
);
728 // Run the animation to completion.
729 StepWidgetLayerAnimatorToEnd(shelf
);
730 StepWidgetLayerAnimatorToEnd(shelf
->status_area_widget());
731 EXPECT_EQ(SHELF_HIDDEN
, manager
->visibility_state());
732 display
= screen
->GetDisplayNearestWindow(
733 Shell::GetPrimaryRootWindow());
735 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
737 // Make sure the bounds of the two widgets changed.
738 EXPECT_GE(shelf
->GetNativeView()->bounds().y(),
739 screen
->GetPrimaryDisplay().bounds().bottom());
740 EXPECT_GE(shelf
->status_area_widget()->GetNativeView()->bounds().y(),
741 screen
->GetPrimaryDisplay().bounds().bottom());
743 // And show it again.
744 SetState(manager
, SHELF_VISIBLE
);
745 // Run the animation to completion.
746 StepWidgetLayerAnimatorToEnd(shelf
);
747 StepWidgetLayerAnimatorToEnd(shelf
->status_area_widget());
748 EXPECT_EQ(SHELF_VISIBLE
, manager
->visibility_state());
749 display
= screen
->GetDisplayNearestWindow(
750 Shell::GetPrimaryRootWindow());
751 EXPECT_EQ(shelf_height
, display
.GetWorkAreaInsets().bottom());
753 // Make sure the bounds of the two widgets changed.
754 shelf_bounds
= shelf
->GetNativeView()->bounds();
755 EXPECT_LT(shelf_bounds
.y(), screen
->GetPrimaryDisplay().bounds().bottom());
756 status_bounds
= shelf
->status_area_widget()->GetNativeView()->bounds();
757 EXPECT_LT(status_bounds
.y(),
758 screen
->GetPrimaryDisplay().bounds().bottom());
761 // Makes sure shelf alignment is correct for lock screen.
762 TEST_F(ShelfLayoutManagerTest
, SideAlignmentInteractionWithLockScreen
) {
763 ShelfLayoutManager
* manager
= GetShelfWidget()->shelf_layout_manager();
764 manager
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
765 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, manager
->GetAlignment());
767 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM
, manager
->GetAlignment());
769 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, manager
->GetAlignment());
772 // Makes sure shelf alignment is correct for add user screen.
773 TEST_F(ShelfLayoutManagerTest
, SideAlignmentInteractionWithAddUserScreen
) {
774 ShelfLayoutManager
* manager
= GetShelfWidget()->shelf_layout_manager();
775 manager
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
776 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, manager
->GetAlignment());
777 ShowAddUserScreen(true);
778 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM
, manager
->GetAlignment());
779 ShowAddUserScreen(false);
780 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, manager
->GetAlignment());
783 // Makes sure shelf alignment is correct for login screen.
784 TEST_F(ShelfLayoutManagerTest
, SideAlignmentInteractionWithLoginScreen
) {
785 ShelfLayoutManager
* manager
= GetShelfWidget()->shelf_layout_manager();
786 ASSERT_EQ(SHELF_ALIGNMENT_BOTTOM
, manager
->GetAlignment());
787 SetUserLoggedIn(false);
788 SetSessionStarted(false);
790 // The test session state delegate does not fire state changes.
791 SetSessionStarting();
792 manager
->SessionStateChanged(
793 Shell::GetInstance()->session_state_delegate()->GetSessionState());
795 // Login sets alignment preferences before the session completes startup.
796 manager
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
797 SetUserLoggedIn(true);
798 SetSessionStarted(true);
800 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, manager
->GetAlignment());
801 // Ensure that the shelf has been notified.
802 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, GetShelfWidget()->shelf()->alignment());
805 // Makes sure LayoutShelf invoked while animating cleans things up.
806 TEST_F(ShelfLayoutManagerTest
, LayoutShelfWhileAnimating
) {
807 ShelfWidget
* shelf
= GetShelfWidget();
808 // Force an initial layout.
809 shelf
->shelf_layout_manager()->LayoutShelf();
810 EXPECT_EQ(SHELF_VISIBLE
, shelf
->shelf_layout_manager()->visibility_state());
813 SetState(shelf
->shelf_layout_manager(), SHELF_HIDDEN
);
814 shelf
->shelf_layout_manager()->LayoutShelf();
815 EXPECT_EQ(SHELF_HIDDEN
, shelf
->shelf_layout_manager()->visibility_state());
816 gfx::Display display
= Shell::GetScreen()->GetDisplayNearestWindow(
817 Shell::GetPrimaryRootWindow());
818 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
820 // Make sure the bounds of the two widgets changed.
821 EXPECT_GE(shelf
->GetNativeView()->bounds().y(),
822 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
823 EXPECT_GE(shelf
->status_area_widget()->GetNativeView()->bounds().y(),
824 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
827 // Test that switching to a different visibility state does not restart the
828 // shelf show / hide animation if it is already running. (crbug.com/250918)
829 TEST_F(ShelfLayoutManagerTest
, SetStateWhileAnimating
) {
830 ShelfWidget
* shelf
= GetShelfWidget();
831 SetState(shelf
->shelf_layout_manager(), SHELF_VISIBLE
);
832 gfx::Rect initial_shelf_bounds
= shelf
->GetWindowBoundsInScreen();
833 gfx::Rect initial_status_bounds
=
834 shelf
->status_area_widget()->GetWindowBoundsInScreen();
836 ui::ScopedAnimationDurationScaleMode
normal_animation_duration(
837 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION
);
838 SetState(shelf
->shelf_layout_manager(), SHELF_HIDDEN
);
839 SetState(shelf
->shelf_layout_manager(), SHELF_VISIBLE
);
841 gfx::Rect current_shelf_bounds
= shelf
->GetWindowBoundsInScreen();
842 gfx::Rect current_status_bounds
=
843 shelf
->status_area_widget()->GetWindowBoundsInScreen();
845 const int small_change
= initial_shelf_bounds
.height() / 2;
847 std::abs(initial_shelf_bounds
.height() - current_shelf_bounds
.height()),
850 std::abs(initial_status_bounds
.height() - current_status_bounds
.height()),
854 // Makes sure the shelf is sized when the status area changes size.
855 TEST_F(ShelfLayoutManagerTest
, ShelfUpdatedWhenStatusAreaChangesSize
) {
856 Shelf
* shelf
= Shelf::ForPrimaryDisplay();
858 ShelfWidget
* shelf_widget
= GetShelfWidget();
859 ASSERT_TRUE(shelf_widget
);
860 ASSERT_TRUE(shelf_widget
->status_area_widget());
861 shelf_widget
->status_area_widget()->SetBounds(
862 gfx::Rect(0, 0, 200, 200));
863 EXPECT_EQ(200, shelf_widget
->GetContentsView()->width() -
864 test::ShelfTestAPI(shelf
).shelf_view()->width());
869 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
870 #define MAYBE_AutoHide DISABLED_AutoHide
872 #define MAYBE_AutoHide AutoHide
875 // Various assertions around auto-hide.
876 TEST_F(ShelfLayoutManagerTest
, MAYBE_AutoHide
) {
877 aura::Window
* root
= Shell::GetPrimaryRootWindow();
878 ui::test::EventGenerator
generator(root
, root
);
879 generator
.MoveMouseTo(0, 0);
881 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
882 shelf
->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
883 views::Widget
* widget
= new views::Widget
;
884 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
885 params
.bounds
= gfx::Rect(0, 0, 200, 200);
886 params
.context
= CurrentContext();
887 // Widget is now owned by the parent window.
888 widget
->Init(params
);
891 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
892 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
894 // LayoutShelf() forces the animation to completion, at which point the
895 // shelf should go off the screen.
896 shelf
->LayoutShelf();
897 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
898 GetShelfWidget()->GetWindowBoundsInScreen().y());
899 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
900 Shell::GetScreen()->GetDisplayNearestWindow(
901 root
).work_area().bottom());
903 // Move the mouse to the bottom of the screen.
904 generator
.MoveMouseTo(0, root
->bounds().bottom() - 1);
906 // Shelf should be shown again (but it shouldn't have changed the work area).
907 SetState(shelf
, SHELF_AUTO_HIDE
);
908 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
909 shelf
->LayoutShelf();
910 EXPECT_EQ(root
->bounds().bottom() - shelf
->GetIdealBounds().height(),
911 GetShelfWidget()->GetWindowBoundsInScreen().y());
912 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
913 Shell::GetScreen()->GetDisplayNearestWindow(
914 root
).work_area().bottom());
916 // Move mouse back up.
917 generator
.MoveMouseTo(0, 0);
918 SetState(shelf
, SHELF_AUTO_HIDE
);
919 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
920 shelf
->LayoutShelf();
921 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
922 GetShelfWidget()->GetWindowBoundsInScreen().y());
924 // Drag mouse to bottom of screen.
925 generator
.PressLeftButton();
926 generator
.MoveMouseTo(0, root
->bounds().bottom() - 1);
927 UpdateAutoHideStateNow();
928 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
930 generator
.ReleaseLeftButton();
931 generator
.MoveMouseTo(1, root
->bounds().bottom() - 1);
932 UpdateAutoHideStateNow();
933 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
934 generator
.PressLeftButton();
935 generator
.MoveMouseTo(1, root
->bounds().bottom() - 1);
936 UpdateAutoHideStateNow();
937 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
940 // Test the behavior of the shelf when it is auto hidden and it is on the
941 // boundary between the primary and the secondary display.
942 TEST_F(ShelfLayoutManagerTest
, AutoHideShelfOnScreenBoundary
) {
943 if (!SupportsMultipleDisplays())
946 UpdateDisplay("800x600,800x600");
947 DisplayLayout
display_layout(DisplayLayout::RIGHT
, 0);
948 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
950 // Put the primary monitor's shelf on the display boundary.
951 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
952 shelf
->SetAlignment(SHELF_ALIGNMENT_RIGHT
);
954 // Create a window because the shelf is always shown when no windows are
958 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
959 ASSERT_EQ(root_windows
[0],
960 GetShelfWidget()->GetNativeWindow()->GetRootWindow());
962 shelf
->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
963 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
965 int right_edge
= root_windows
[0]->GetBoundsInScreen().right() - 1;
966 int y
= root_windows
[0]->GetBoundsInScreen().y();
968 // Start off the mouse nowhere near the shelf; the shelf should be hidden.
969 ui::test::EventGenerator
& generator(GetEventGenerator());
970 generator
.MoveMouseTo(right_edge
- 50, y
);
971 UpdateAutoHideStateNow();
972 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
974 // Moving the mouse over the light bar (but not to the edge of the screen)
975 // should show the shelf.
976 generator
.MoveMouseTo(right_edge
- 1, y
);
977 UpdateAutoHideStateNow();
978 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
979 EXPECT_EQ(right_edge
- 1, Shell::GetScreen()->GetCursorScreenPoint().x());
981 // Moving the mouse off the light bar should hide the shelf.
982 generator
.MoveMouseTo(right_edge
- 50, y
);
983 UpdateAutoHideStateNow();
984 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
986 // Moving the mouse to the right edge of the screen crossing the light bar
987 // should show the shelf despite the mouse cursor getting warped to the
988 // secondary display.
989 generator
.MoveMouseTo(right_edge
- 1, y
);
990 generator
.MoveMouseTo(right_edge
, y
);
991 UpdateAutoHideStateNow();
992 EXPECT_NE(right_edge
- 1, Shell::GetScreen()->GetCursorScreenPoint().x());
993 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
996 generator
.MoveMouseTo(right_edge
- 50, y
);
997 UpdateAutoHideStateNow();
998 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1000 // Moving the mouse to the right edge of the screen crossing the light bar and
1001 // overshooting by a lot should keep the shelf hidden.
1002 generator
.MoveMouseTo(right_edge
- 1, y
);
1003 generator
.MoveMouseTo(right_edge
+ 50, y
);
1004 UpdateAutoHideStateNow();
1005 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1007 // Moving the mouse to the right edge of the screen crossing the light bar and
1008 // overshooting a bit should show the shelf.
1009 generator
.MoveMouseTo(right_edge
- 1, y
);
1010 generator
.MoveMouseTo(right_edge
+ 2, y
);
1011 UpdateAutoHideStateNow();
1012 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1014 // Keeping the mouse close to the left edge of the secondary display after the
1015 // shelf is shown should keep the shelf shown.
1016 generator
.MoveMouseTo(right_edge
+ 2, y
+ 1);
1017 UpdateAutoHideStateNow();
1018 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1020 // Moving the mouse far from the left edge of the secondary display should
1022 generator
.MoveMouseTo(right_edge
+ 50, y
);
1023 UpdateAutoHideStateNow();
1024 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1026 // Moving to the left edge of the secondary display without first crossing
1027 // the primary display's right aligned shelf first should not show the shelf.
1028 generator
.MoveMouseTo(right_edge
+ 2, y
);
1029 UpdateAutoHideStateNow();
1030 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1033 // Assertions around the lock screen showing.
1034 TEST_F(ShelfLayoutManagerTest
, VisibleWhenLockScreenShowing
) {
1035 if (!SupportsHostWindowResize())
1038 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1039 // it isn't over the shelf.
1040 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1042 generator
.MoveMouseTo(0, 0);
1044 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1045 shelf
->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1046 views::Widget
* widget
= new views::Widget
;
1047 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1048 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1049 params
.context
= CurrentContext();
1050 // Widget is now owned by the parent window.
1051 widget
->Init(params
);
1054 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1055 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1057 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1058 // LayoutShelf() forces the animation to completion, at which point the
1059 // shelf should go off the screen.
1060 shelf
->LayoutShelf();
1061 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
1062 GetShelfWidget()->GetWindowBoundsInScreen().y());
1064 aura::Window
* lock_container
= Shell::GetContainer(
1065 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer
);
1067 views::Widget
* lock_widget
= new views::Widget
;
1068 views::Widget::InitParams
lock_params(
1069 views::Widget::InitParams::TYPE_WINDOW
);
1070 lock_params
.bounds
= gfx::Rect(0, 0, 200, 200);
1071 params
.context
= CurrentContext();
1072 lock_params
.parent
= lock_container
;
1073 // Widget is now owned by the parent window.
1074 lock_widget
->Init(lock_params
);
1075 lock_widget
->Maximize();
1076 lock_widget
->Show();
1080 // Showing a widget in the lock screen should force the shelf to be visibile.
1081 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1084 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1087 // Assertions around SetAutoHideBehavior.
1088 TEST_F(ShelfLayoutManagerTest
, SetAutoHideBehavior
) {
1089 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1090 // it isn't over the shelf.
1091 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1093 generator
.MoveMouseTo(0, 0);
1095 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1096 views::Widget
* widget
= new views::Widget
;
1097 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1098 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1099 params
.context
= CurrentContext();
1100 // Widget is now owned by the parent window.
1101 widget
->Init(params
);
1103 aura::Window
* window
= widget
->GetNativeWindow();
1104 gfx::Rect
display_bounds(
1105 Shell::GetScreen()->GetDisplayNearestWindow(window
).bounds());
1107 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1108 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1110 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1111 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1114 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1115 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1116 window
).work_area().bottom(),
1117 widget
->GetWorkAreaBoundsInScreen().bottom());
1119 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1120 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1121 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1122 window
).work_area().bottom(),
1123 widget
->GetWorkAreaBoundsInScreen().bottom());
1125 ui::ScopedAnimationDurationScaleMode
animation_duration(
1126 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION
);
1128 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1129 ShelfWidget
* shelf_widget
= GetShelfWidget();
1130 EXPECT_TRUE(shelf_widget
->status_area_widget()->IsVisible());
1131 StepWidgetLayerAnimatorToEnd(shelf_widget
);
1132 StepWidgetLayerAnimatorToEnd(shelf_widget
->status_area_widget());
1133 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1134 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1135 window
).work_area().bottom(),
1136 widget
->GetWorkAreaBoundsInScreen().bottom());
1139 // Basic assertions around the dimming of the shelf.
1140 TEST_F(ShelfLayoutManagerTest
, DimmingBehavior
) {
1141 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1142 // it isn't over the shelf.
1143 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1145 generator
.MoveMouseTo(0, 0);
1147 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1148 shelf
->shelf_widget()->DisableDimmingAnimationsForTest();
1150 views::Widget
* widget
= new views::Widget
;
1151 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1152 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1153 params
.context
= CurrentContext();
1154 // Widget is now owned by the parent window.
1155 widget
->Init(params
);
1157 aura::Window
* window
= widget
->GetNativeWindow();
1158 gfx::Rect
display_bounds(
1159 Shell::GetScreen()->GetDisplayNearestWindow(window
).bounds());
1161 gfx::Point off_shelf
= display_bounds
.CenterPoint();
1162 gfx::Point on_shelf
=
1163 shelf
->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1165 // Test there is no dimming object active at this point.
1166 generator
.MoveMouseTo(on_shelf
.x(), on_shelf
.y());
1167 EXPECT_EQ(-1, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1168 generator
.MoveMouseTo(off_shelf
.x(), off_shelf
.y());
1169 EXPECT_EQ(-1, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1171 // After maximization, the shelf should be visible and the dimmer created.
1174 on_shelf
= shelf
->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1175 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1177 // Moving the mouse off the shelf should dim the bar.
1178 generator
.MoveMouseTo(off_shelf
.x(), off_shelf
.y());
1179 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1181 // Adding touch events outside the shelf should still keep the shelf in
1183 generator
.PressTouch();
1184 generator
.MoveTouch(off_shelf
);
1185 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1186 // Move the touch into the shelf area should undim.
1187 generator
.MoveTouch(on_shelf
);
1188 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1189 generator
.ReleaseTouch();
1190 // And a release dims again.
1191 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1193 // Moving the mouse on the shelf should undim the bar.
1194 generator
.MoveMouseTo(on_shelf
);
1195 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1197 // No matter what the touch events do, the shelf should stay undimmed.
1198 generator
.PressTouch();
1199 generator
.MoveTouch(off_shelf
);
1200 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1201 generator
.MoveTouch(on_shelf
);
1202 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1203 generator
.MoveTouch(off_shelf
);
1204 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1205 generator
.MoveTouch(on_shelf
);
1206 generator
.ReleaseTouch();
1208 // After restore, the dimming object should be deleted again.
1210 EXPECT_EQ(-1, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1213 // Test that dimming works correctly with multiple displays.
1214 TEST_F(ShelfLayoutManagerTest
, DimmingBehaviorDualDisplay
) {
1215 if (!SupportsMultipleDisplays())
1218 // Create two displays.
1219 Shell
* shell
= Shell::GetInstance();
1220 UpdateDisplay("0+0-200x200,+200+0-100x100");
1221 EXPECT_EQ(2U, shell
->display_manager()->GetNumDisplays());
1223 DisplayController
* display_controller
= shell
->display_controller();
1224 aura::Window::Windows root_windows
= display_controller
->GetAllRootWindows();
1225 EXPECT_EQ(root_windows
.size(), 2U);
1227 std::vector
<ShelfWidget
*> shelf_widgets
;
1228 for (auto& root_window
: root_windows
) {
1229 ShelfLayoutManager
* shelf
=
1230 GetRootWindowController(root_window
)->GetShelfLayoutManager();
1231 shelf_widgets
.push_back(shelf
->shelf_widget());
1233 // For disabling the dimming animation to work, the animation must be
1234 // disabled prior to creating the dimmer.
1235 shelf_widgets
.back()->DisableDimmingAnimationsForTest();
1237 // Create a maximized window to create the dimmer.
1238 views::Widget
* widget
= new views::Widget
;
1239 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1240 params
.context
= root_window
;
1241 params
.bounds
= root_window
->GetBoundsInScreen();
1242 params
.show_state
= ui::SHOW_STATE_MAXIMIZED
;
1243 widget
->Init(params
);
1247 ui::test::EventGenerator
& generator(GetEventGenerator());
1249 generator
.MoveMouseTo(root_windows
[0]->GetBoundsInScreen().CenterPoint());
1250 EXPECT_LT(0, shelf_widgets
[0]->GetDimmingAlphaForTest());
1251 EXPECT_LT(0, shelf_widgets
[1]->GetDimmingAlphaForTest());
1253 generator
.MoveMouseTo(
1254 shelf_widgets
[0]->GetWindowBoundsInScreen().CenterPoint());
1255 EXPECT_EQ(0, shelf_widgets
[0]->GetDimmingAlphaForTest());
1256 EXPECT_LT(0, shelf_widgets
[1]->GetDimmingAlphaForTest());
1258 generator
.MoveMouseTo(
1259 shelf_widgets
[1]->GetWindowBoundsInScreen().CenterPoint());
1260 EXPECT_LT(0, shelf_widgets
[0]->GetDimmingAlphaForTest());
1261 EXPECT_EQ(0, shelf_widgets
[1]->GetDimmingAlphaForTest());
1263 generator
.MoveMouseTo(root_windows
[1]->GetBoundsInScreen().CenterPoint());
1264 EXPECT_LT(0, shelf_widgets
[0]->GetDimmingAlphaForTest());
1265 EXPECT_LT(0, shelf_widgets
[1]->GetDimmingAlphaForTest());
1268 // Assertions around the dimming of the shelf in conjunction with menus.
1269 TEST_F(ShelfLayoutManagerTest
, DimmingBehaviorWithMenus
) {
1270 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1271 // it isn't over the shelf.
1272 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1274 generator
.MoveMouseTo(0, 0);
1276 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1277 shelf
->shelf_widget()->DisableDimmingAnimationsForTest();
1279 views::Widget
* widget
= new views::Widget
;
1280 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1281 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1282 params
.context
= CurrentContext();
1283 // Widget is now owned by the parent window.
1284 widget
->Init(params
);
1286 aura::Window
* window
= widget
->GetNativeWindow();
1287 gfx::Rect
display_bounds(
1288 Shell::GetScreen()->GetDisplayNearestWindow(window
).bounds());
1290 // After maximization, the shelf should be visible and the dimmer created.
1293 gfx::Point off_shelf
= display_bounds
.CenterPoint();
1294 gfx::Point on_shelf
=
1295 shelf
->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1297 // Moving the mouse on the shelf should undim the bar.
1298 generator
.MoveMouseTo(on_shelf
.x(), on_shelf
.y());
1299 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1301 // Simulate a menu opening.
1302 shelf
->shelf_widget()->ForceUndimming(true);
1304 // Moving the mouse off the shelf should not dim the bar.
1305 generator
.MoveMouseTo(off_shelf
.x(), off_shelf
.y());
1306 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1308 // No matter what the touch events do, the shelf should stay undimmed.
1309 generator
.PressTouch();
1310 generator
.MoveTouch(off_shelf
);
1311 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1312 generator
.MoveTouch(on_shelf
);
1313 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1314 generator
.MoveTouch(off_shelf
);
1315 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1316 generator
.ReleaseTouch();
1317 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1319 // "Closing the menu" should now turn off the menu since no event is inside
1320 // the shelf any longer.
1321 shelf
->shelf_widget()->ForceUndimming(false);
1322 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1324 // Moving the mouse again on the shelf which should undim the bar again.
1325 // This time we check that the bar stays undimmed when the mouse remains on
1326 // the bar and the "menu gets closed".
1327 generator
.MoveMouseTo(on_shelf
.x(), on_shelf
.y());
1328 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1329 shelf
->shelf_widget()->ForceUndimming(true);
1330 generator
.MoveMouseTo(off_shelf
.x(), off_shelf
.y());
1331 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1332 generator
.MoveMouseTo(on_shelf
.x(), on_shelf
.y());
1333 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1334 shelf
->shelf_widget()->ForceUndimming(true);
1335 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1338 // Verifies the shelf is visible when status/shelf is focused.
1339 TEST_F(ShelfLayoutManagerTest
, VisibleWhenStatusOrShelfFocused
) {
1340 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1341 // it isn't over the shelf.
1342 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow(),
1344 generator
.MoveMouseTo(0, 0);
1346 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1347 views::Widget
* widget
= new views::Widget
;
1348 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1349 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1350 params
.context
= CurrentContext();
1351 // Widget is now owned by the parent window.
1352 widget
->Init(params
);
1354 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1355 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1356 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1358 // Focus the shelf. Have to go through the focus cycler as normal focus
1359 // requests to it do nothing.
1360 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD
);
1361 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1364 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1366 // Trying to activate the status should fail, since we only allow activating
1367 // it when the user is using the keyboard (i.e. through FocusCycler).
1368 GetShelfWidget()->status_area_widget()->Activate();
1369 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1371 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD
);
1372 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1375 // Makes sure shelf will be visible when app list opens as shelf is in
1376 // SHELF_VISIBLE state,and toggling app list won't change shelf
1377 // visibility state.
1378 TEST_F(ShelfLayoutManagerTest
, OpenAppListWithShelfVisibleState
) {
1379 Shell
* shell
= Shell::GetInstance();
1380 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1381 shelf
->LayoutShelf();
1382 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1384 // Create a normal unmaximized windowm shelf should be visible.
1385 aura::Window
* window
= CreateTestWindow();
1386 window
->SetBounds(gfx::Rect(0, 0, 100, 100));
1388 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1389 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1391 // Show app list and the shelf stays visible.
1392 shell
->ShowAppList(NULL
);
1393 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
1394 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1396 // Hide app list and the shelf stays visible.
1397 shell
->DismissAppList();
1398 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1399 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1402 // Makes sure shelf will be shown with SHELF_AUTO_HIDE_SHOWN state
1403 // when app list opens as shelf is in SHELF_AUTO_HIDE state, and
1404 // toggling app list won't change shelf visibility state.
1405 TEST_F(ShelfLayoutManagerTest
, OpenAppListWithShelfAutoHideState
) {
1406 Shell
* shell
= Shell::GetInstance();
1407 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1408 shelf
->LayoutShelf();
1409 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1411 // Create a window and show it in maximized state.
1412 aura::Window
* window
= CreateTestWindow();
1413 window
->SetBounds(gfx::Rect(0, 0, 100, 100));
1414 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1416 wm::ActivateWindow(window
);
1418 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1419 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1422 shell
->ShowAppList(NULL
);
1423 // The shelf's auto hide state won't be changed until the timer fires, so
1424 // calling shell->UpdateShelfVisibility() is kind of manually helping it to
1425 // update the state.
1426 shell
->UpdateShelfVisibility();
1427 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
1428 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1429 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1432 shell
->DismissAppList();
1433 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1434 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1437 // Makes sure that when we have dual displays, with one or both shelves are set
1438 // to AutoHide, viewing the AppList on one of them doesn't unhide the other
1440 TEST_F(ShelfLayoutManagerTest
, DualDisplayOpenAppListWithShelfAutoHideState
) {
1441 if (!SupportsMultipleDisplays())
1444 // Create two displays.
1445 Shell
* shell
= Shell::GetInstance();
1446 DisplayManager
* display_manager
= shell
->display_manager();
1447 EXPECT_EQ(1U, display_manager
->GetNumDisplays());
1448 UpdateDisplay("0+0-200x200,+200+0-100x100");
1449 EXPECT_EQ(2U, display_manager
->GetNumDisplays());
1451 DisplayController
* display_controller
= shell
->display_controller();
1452 aura::Window::Windows root_windows
= display_controller
->GetAllRootWindows();
1453 EXPECT_EQ(root_windows
.size(), 2U);
1455 // Get the shelves in both displays and set them to be 'AutoHide'.
1456 ShelfLayoutManager
* shelf_1
=
1457 GetRootWindowController(root_windows
[0])->GetShelfLayoutManager();
1458 ShelfLayoutManager
* shelf_2
=
1459 GetRootWindowController(root_windows
[1])->GetShelfLayoutManager();
1460 EXPECT_NE(shelf_1
, shelf_2
);
1461 EXPECT_NE(shelf_1
->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1462 shelf_2
->shelf_widget()->GetNativeWindow()->
1464 shelf_1
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1465 shelf_1
->LayoutShelf();
1466 shelf_2
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1467 shelf_2
->LayoutShelf();
1469 // Create a window in each display and show them in maximized state.
1470 aura::Window
* window_1
=
1471 CreateTestWindowInParent(root_windows
[0]);
1472 window_1
->SetBounds(gfx::Rect(0, 0, 100, 100));
1473 window_1
->SetProperty(aura::client::kShowStateKey
,
1474 ui::SHOW_STATE_MAXIMIZED
);
1476 aura::Window
* window_2
=
1477 CreateTestWindowInParent(root_windows
[1]);
1478 window_2
->SetBounds(gfx::Rect(201, 0, 100, 100));
1479 window_2
->SetProperty(aura::client::kShowStateKey
,
1480 ui::SHOW_STATE_MAXIMIZED
);
1483 EXPECT_EQ(shelf_1
->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1484 window_1
->GetRootWindow());
1485 EXPECT_EQ(shelf_2
->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1486 window_2
->GetRootWindow());
1488 // Activate one window in one display and manually trigger the update of shelf
1490 wm::ActivateWindow(window_1
);
1491 shell
->UpdateShelfVisibility();
1493 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1494 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_1
->visibility_state());
1495 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_2
->visibility_state());
1496 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_1
->auto_hide_state());
1497 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_2
->auto_hide_state());
1500 shell
->ShowAppList(NULL
);
1501 shell
->UpdateShelfVisibility();
1503 // Only the shelf in the active display should be shown, the other is hidden.
1504 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
1505 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_1
->visibility_state());
1506 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf_1
->auto_hide_state());
1507 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_2
->visibility_state());
1508 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_2
->auto_hide_state());
1510 // Hide app list, both shelves should be hidden.
1511 shell
->DismissAppList();
1512 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1513 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_1
->visibility_state());
1514 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_2
->visibility_state());
1515 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_1
->auto_hide_state());
1516 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_2
->auto_hide_state());
1519 // Makes sure the shelf will be hidden when we have a fullscreen window, and it
1520 // will unhide when we open the app list.
1521 TEST_F(ShelfLayoutManagerTest
, OpenAppListWithShelfHiddenState
) {
1522 Shell
* shell
= Shell::GetInstance();
1523 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1524 // For shelf to be visible, app list is not open in initial state.
1525 shelf
->LayoutShelf();
1527 // Create a window and make it full screen.
1528 aura::Window
* window
= CreateTestWindow();
1529 window
->SetBounds(gfx::Rect(0, 0, 100, 100));
1530 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
1532 wm::ActivateWindow(window
);
1534 // App list and shelf is not shown.
1535 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1536 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1539 shell
->ShowAppList(NULL
);
1540 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
1541 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1544 shell
->DismissAppList();
1545 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1546 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1549 // Tests the correct behavior of the shelf when there is a system modal window
1550 // open when we have a single display.
1551 TEST_F(ShelfLayoutManagerTest
, ShelfWithSystemModalWindowSingleDisplay
) {
1552 Shell
* shell
= Shell::GetInstance();
1553 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1554 shelf
->LayoutShelf();
1555 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1557 aura::Window
* window
= CreateTestWindow();
1558 window
->SetBounds(gfx::Rect(0, 0, 100, 100));
1559 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1561 wm::ActivateWindow(window
);
1563 // Enable system modal dialog, and make sure shelf is still hidden.
1564 shell
->SimulateModalWindowOpenForTesting(true);
1565 EXPECT_TRUE(shell
->IsSystemModalWindowOpen());
1566 EXPECT_FALSE(wm::CanActivateWindow(window
));
1567 shell
->UpdateShelfVisibility();
1568 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1569 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1572 // Tests the correct behavior of the shelf when there is a system modal window
1573 // open when we have dual display.
1574 TEST_F(ShelfLayoutManagerTest
, ShelfWithSystemModalWindowDualDisplay
) {
1575 if (!SupportsMultipleDisplays())
1578 // Create two displays.
1579 Shell
* shell
= Shell::GetInstance();
1580 DisplayManager
* display_manager
= shell
->display_manager();
1581 UpdateDisplay("200x200,100x100");
1582 EXPECT_EQ(2U, display_manager
->GetNumDisplays());
1584 DisplayController
* display_controller
= shell
->display_controller();
1585 aura::Window::Windows root_windows
= display_controller
->GetAllRootWindows();
1586 EXPECT_EQ(2U, root_windows
.size());
1588 // Get the shelves in both displays and set them to be 'AutoHide'.
1589 ShelfLayoutManager
* shelf_1
=
1590 GetRootWindowController(root_windows
[0])->GetShelfLayoutManager();
1591 ShelfLayoutManager
* shelf_2
=
1592 GetRootWindowController(root_windows
[1])->GetShelfLayoutManager();
1593 EXPECT_NE(shelf_1
, shelf_2
);
1594 EXPECT_NE(shelf_1
->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1595 shelf_2
->shelf_widget()->GetNativeWindow()->GetRootWindow());
1596 shelf_1
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1597 shelf_1
->LayoutShelf();
1598 shelf_2
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1599 shelf_2
->LayoutShelf();
1601 // Create a window in each display and show them in maximized state.
1602 aura::Window
* window_1
= CreateTestWindowInParent(root_windows
[0]);
1603 window_1
->SetBounds(gfx::Rect(0, 0, 100, 100));
1604 window_1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1606 aura::Window
* window_2
= CreateTestWindowInParent(root_windows
[1]);
1607 window_2
->SetBounds(gfx::Rect(201, 0, 100, 100));
1608 window_2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1611 EXPECT_EQ(shelf_1
->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1612 window_1
->GetRootWindow());
1613 EXPECT_EQ(shelf_2
->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1614 window_2
->GetRootWindow());
1615 EXPECT_TRUE(window_1
->IsVisible());
1616 EXPECT_TRUE(window_2
->IsVisible());
1618 // Enable system modal dialog, and make sure both shelves are still hidden.
1619 shell
->SimulateModalWindowOpenForTesting(true);
1620 EXPECT_TRUE(shell
->IsSystemModalWindowOpen());
1621 EXPECT_FALSE(wm::CanActivateWindow(window_1
));
1622 EXPECT_FALSE(wm::CanActivateWindow(window_2
));
1623 shell
->UpdateShelfVisibility();
1624 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_1
->visibility_state());
1625 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_1
->auto_hide_state());
1626 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_2
->visibility_state());
1627 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_2
->auto_hide_state());
1630 // Tests that the shelf is only hidden for a fullscreen window at the front and
1631 // toggles visibility when another window is activated.
1632 TEST_F(ShelfLayoutManagerTest
, FullscreenWindowInFrontHidesShelf
) {
1633 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1635 // Create a window and make it full screen.
1636 aura::Window
* window1
= CreateTestWindow();
1637 window1
->SetBounds(gfx::Rect(0, 0, 100, 100));
1638 window1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
1641 aura::Window
* window2
= CreateTestWindow();
1642 window2
->SetBounds(gfx::Rect(0, 0, 100, 100));
1645 wm::GetWindowState(window1
)->Activate();
1646 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1648 wm::GetWindowState(window2
)->Activate();
1649 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1651 wm::GetWindowState(window1
)->Activate();
1652 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1655 // Test the behavior of the shelf when a window on one display is fullscreen
1656 // but the other display has the active window.
1657 TEST_F(ShelfLayoutManagerTest
, FullscreenWindowOnSecondDisplay
) {
1658 if (!SupportsMultipleDisplays())
1661 UpdateDisplay("800x600,800x600");
1662 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1663 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1664 Shell::RootWindowControllerList root_window_controllers
=
1665 Shell::GetAllRootWindowControllers();
1667 // Create windows on either display.
1668 aura::Window
* window1
= CreateTestWindow();
1669 window1
->SetBoundsInScreen(
1670 gfx::Rect(0, 0, 100, 100),
1671 display_manager
->GetDisplayAt(0));
1672 window1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
1675 aura::Window
* window2
= CreateTestWindow();
1676 window2
->SetBoundsInScreen(
1677 gfx::Rect(800, 0, 100, 100),
1678 display_manager
->GetDisplayAt(1));
1681 EXPECT_EQ(root_windows
[0], window1
->GetRootWindow());
1682 EXPECT_EQ(root_windows
[1], window2
->GetRootWindow());
1684 wm::GetWindowState(window2
)->Activate();
1685 EXPECT_EQ(SHELF_HIDDEN
,
1686 root_window_controllers
[0]->GetShelfLayoutManager()->visibility_state());
1687 EXPECT_EQ(SHELF_VISIBLE
,
1688 root_window_controllers
[1]->GetShelfLayoutManager()->visibility_state());
1693 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1694 #define MAYBE_SetAlignment DISABLED_SetAlignment
1696 #define MAYBE_SetAlignment SetAlignment
1699 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT, TOP).
1700 TEST_F(ShelfLayoutManagerTest
, MAYBE_SetAlignment
) {
1701 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1702 // Force an initial layout.
1703 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1704 shelf
->LayoutShelf();
1705 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1707 shelf
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
1708 gfx::Rect
shelf_bounds(
1709 GetShelfWidget()->GetWindowBoundsInScreen());
1710 const gfx::Screen
* screen
= Shell::GetScreen();
1711 gfx::Display display
=
1712 screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1713 ASSERT_NE(-1, display
.id());
1714 EXPECT_EQ(shelf
->GetIdealBounds().width(),
1715 display
.GetWorkAreaInsets().left());
1717 shelf_bounds
.width(),
1718 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1719 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, GetSystemTray()->shelf_alignment());
1720 StatusAreaWidget
* status_area_widget
= GetShelfWidget()->status_area_widget();
1721 gfx::Rect
status_bounds(status_area_widget
->GetWindowBoundsInScreen());
1722 EXPECT_GE(status_bounds
.width(),
1723 status_area_widget
->GetContentsView()->GetPreferredSize().width());
1724 EXPECT_EQ(shelf
->GetIdealBounds().width(),
1725 display
.GetWorkAreaInsets().left());
1726 EXPECT_EQ(0, display
.GetWorkAreaInsets().top());
1727 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
1728 EXPECT_EQ(0, display
.GetWorkAreaInsets().right());
1729 EXPECT_EQ(display
.bounds().x(), shelf_bounds
.x());
1730 EXPECT_EQ(display
.bounds().y(), shelf_bounds
.y());
1731 EXPECT_EQ(display
.bounds().height(), shelf_bounds
.height());
1732 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1733 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1734 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1735 display
.GetWorkAreaInsets().left());
1736 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
, display
.work_area().x());
1738 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1739 shelf
->SetAlignment(SHELF_ALIGNMENT_RIGHT
);
1740 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1741 shelf_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
1742 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1743 ASSERT_NE(-1, display
.id());
1744 EXPECT_EQ(shelf
->GetIdealBounds().width(),
1745 display
.GetWorkAreaInsets().right());
1746 EXPECT_GE(shelf_bounds
.width(),
1747 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1748 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT
, GetSystemTray()->shelf_alignment());
1749 status_bounds
= gfx::Rect(status_area_widget
->GetWindowBoundsInScreen());
1750 EXPECT_GE(status_bounds
.width(),
1751 status_area_widget
->GetContentsView()->GetPreferredSize().width());
1752 EXPECT_EQ(shelf
->GetIdealBounds().width(),
1753 display
.GetWorkAreaInsets().right());
1754 EXPECT_EQ(0, display
.GetWorkAreaInsets().top());
1755 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
1756 EXPECT_EQ(0, display
.GetWorkAreaInsets().left());
1757 EXPECT_EQ(display
.work_area().right(), shelf_bounds
.x());
1758 EXPECT_EQ(display
.bounds().y(), shelf_bounds
.y());
1759 EXPECT_EQ(display
.bounds().height(), shelf_bounds
.height());
1760 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1761 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1762 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1763 display
.GetWorkAreaInsets().right());
1764 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1765 display
.bounds().right() - display
.work_area().right());
1767 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1768 shelf
->SetAlignment(SHELF_ALIGNMENT_TOP
);
1769 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1770 shelf_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
1771 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1772 ASSERT_NE(-1, display
.id());
1773 EXPECT_EQ(shelf
->GetIdealBounds().height(),
1774 display
.GetWorkAreaInsets().top());
1775 EXPECT_GE(shelf_bounds
.height(),
1776 GetShelfWidget()->GetContentsView()->GetPreferredSize().height());
1777 EXPECT_EQ(SHELF_ALIGNMENT_TOP
, GetSystemTray()->shelf_alignment());
1778 status_bounds
= gfx::Rect(status_area_widget
->GetWindowBoundsInScreen());
1779 EXPECT_GE(status_bounds
.height(),
1780 status_area_widget
->GetContentsView()->GetPreferredSize().height());
1781 EXPECT_EQ(shelf
->GetIdealBounds().height(),
1782 display
.GetWorkAreaInsets().top());
1783 EXPECT_EQ(0, display
.GetWorkAreaInsets().right());
1784 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
1785 EXPECT_EQ(0, display
.GetWorkAreaInsets().left());
1786 EXPECT_EQ(display
.work_area().y(), shelf_bounds
.bottom());
1787 EXPECT_EQ(display
.bounds().x(), shelf_bounds
.x());
1788 EXPECT_EQ(display
.bounds().width(), shelf_bounds
.width());
1789 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1790 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1791 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1792 display
.GetWorkAreaInsets().top());
1793 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1794 display
.work_area().y() - display
.bounds().y());
1797 TEST_F(ShelfLayoutManagerTest
, GestureEdgeSwipe
) {
1798 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1799 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1800 views::Widget
* widget
= new views::Widget
;
1801 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1802 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1803 params
.context
= CurrentContext();
1804 widget
->Init(params
);
1808 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1810 aura::Window
* window
= widget
->GetNativeWindow();
1811 shelf
->LayoutShelf();
1813 gfx::Rect shelf_shown
= GetShelfWidget()->GetWindowBoundsInScreen();
1814 gfx::Rect bounds_shelf
= window
->bounds();
1816 // Edge swipe when SHELF_VISIBLE should not change visibility state.
1817 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1818 generator
.GestureEdgeSwipe();
1819 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1821 // Edge swipe when AUTO_HIDE_HIDDEN should change to AUTO_HIDE_SHOWN.
1822 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1823 shelf
->LayoutShelf();
1824 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1825 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1826 generator
.GestureEdgeSwipe();
1827 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1828 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1830 widget
->SetFullscreen(true);
1831 wm::GetWindowState(window
)->set_hide_shelf_when_fullscreen(false);
1832 shelf
->UpdateVisibilityState();
1834 // Edge swipe in fullscreen + AUTO_HIDE_HIDDEN should show the shelf and
1835 // remain fullscreen.
1836 EXPECT_TRUE(widget
->IsFullscreen());
1837 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1838 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1839 generator
.GestureEdgeSwipe();
1840 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1841 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1842 EXPECT_TRUE(widget
->IsFullscreen());
1845 // Tests that gesture edge swipe events are forwarded to the right shelf on the
1846 // right monitor (crbug.com/449851).
1847 TEST_F(ShelfLayoutManagerTest
, GestureEdgeSwipeMultiMonitor
) {
1848 if (!SupportsMultipleDisplays())
1851 // Create two displays.
1852 Shell
* shell
= Shell::GetInstance();
1853 DisplayManager
* display_manager
= shell
->display_manager();
1854 UpdateDisplay("200x200,100x100");
1855 ASSERT_EQ(2U, display_manager
->GetNumDisplays());
1857 auto root_window_controllers
= Shell::GetAllRootWindowControllers();
1858 ASSERT_EQ(2U, root_window_controllers
.size());
1859 ShelfLayoutManager
* shelf_1
=
1860 root_window_controllers
[0]->GetShelfLayoutManager();
1861 ShelfLayoutManager
* shelf_2
=
1862 root_window_controllers
[1]->GetShelfLayoutManager();
1864 // Create two maximized windows, one in each display.
1865 aura::Window
* window_1
=
1866 CreateTestWindowInParent(root_window_controllers
[0]->GetRootWindow());
1867 window_1
->SetBounds(gfx::Rect(0, 0, 100, 100));
1868 window_1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1870 aura::Window
* window_2
=
1871 CreateTestWindowInParent(root_window_controllers
[1]->GetRootWindow());
1872 window_2
->SetBounds(gfx::Rect(201, 0, 100, 100));
1873 window_2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1876 // Make sure both are set to auto-hide and both are hidden.
1877 shelf_1
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1878 shelf_2
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1879 shelf_1
->LayoutShelf();
1880 shelf_2
->LayoutShelf();
1881 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_1
->visibility_state());
1882 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_2
->visibility_state());
1883 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_1
->auto_hide_state());
1884 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_2
->auto_hide_state());
1886 ui::test::EventGenerator
monitor_1_generator(
1887 root_window_controllers
[0]->GetRootWindow());
1888 ui::test::EventGenerator
monitor_2_generator(
1889 root_window_controllers
[1]->GetRootWindow());
1891 // An edge swipe in one display should only affect the shelf in that display.
1892 monitor_1_generator
.GestureEdgeSwipe();
1893 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_1
->visibility_state());
1894 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_2
->visibility_state());
1895 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf_1
->auto_hide_state());
1896 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_2
->auto_hide_state());
1898 // Back to normal after an update.
1899 shell
->UpdateShelfVisibility();
1900 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_1
->visibility_state());
1901 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_2
->visibility_state());
1902 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_1
->auto_hide_state());
1903 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_2
->auto_hide_state());
1905 monitor_2_generator
.GestureEdgeSwipe();
1906 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_1
->visibility_state());
1907 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf_2
->visibility_state());
1908 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf_1
->auto_hide_state());
1909 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf_2
->auto_hide_state());
1913 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1914 #define MAYBE_GestureDrag DISABLED_GestureDrag
1916 #define MAYBE_GestureDrag GestureDrag
1919 TEST_F(ShelfLayoutManagerTest
, MAYBE_GestureDrag
) {
1920 // Slop is an implementation detail of gesture recognition, and complicates
1921 // these tests. Ignore it.
1922 ui::GestureConfiguration::GetInstance()
1923 ->set_max_touch_move_in_pixels_for_click(0);
1924 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1926 SCOPED_TRACE("BOTTOM");
1927 RunGestureDragTests(gfx::Vector2d(0, 120));
1931 SCOPED_TRACE("LEFT");
1932 shelf
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
1933 RunGestureDragTests(gfx::Vector2d(-120, 0));
1937 SCOPED_TRACE("RIGHT");
1938 shelf
->SetAlignment(SHELF_ALIGNMENT_RIGHT
);
1939 RunGestureDragTests(gfx::Vector2d(120, 0));
1943 TEST_F(ShelfLayoutManagerTest
, WindowVisibilityDisablesAutoHide
) {
1944 if (!SupportsMultipleDisplays())
1947 UpdateDisplay("800x600,800x600");
1948 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1949 shelf
->LayoutShelf();
1950 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1952 // Create a visible window so auto-hide behavior is enforced
1953 views::Widget
* dummy
= CreateTestWidget();
1955 // Window visible => auto hide behaves normally.
1956 shelf
->UpdateVisibilityState();
1957 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1959 // Window minimized => auto hide disabled.
1961 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1963 // Window closed => auto hide disabled.
1965 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1967 // Multiple window test
1968 views::Widget
* window1
= CreateTestWidget();
1969 views::Widget
* window2
= CreateTestWidget();
1971 // both visible => normal autohide
1972 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1974 // either minimzed => normal autohide
1975 window2
->Minimize();
1976 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1978 window1
->Minimize();
1979 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1981 // both minimized => disable auto hide
1982 window2
->Minimize();
1983 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1985 // Test moving windows to/from other display.
1987 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1988 // Move to second display.
1989 window2
->SetBounds(gfx::Rect(850, 50, 50, 50));
1990 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1991 // Move back to primary display.
1992 window2
->SetBounds(gfx::Rect(50, 50, 50, 50));
1993 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1996 // Test that the shelf animates back to its normal position upon a user
1997 // completing a gesture drag.
1998 TEST_F(ShelfLayoutManagerTest
, ShelfAnimatesWhenGestureComplete
) {
1999 if (!SupportsHostWindowResize())
2002 // Test the shelf animates back to its original visible bounds when it is
2003 // dragged when there are no visible windows.
2004 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
2005 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
2006 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
2007 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
2008 gfx::Rect visible_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
2010 // Enable animations so that we can make sure that they occur.
2011 ui::ScopedAnimationDurationScaleMode
regular_animations(
2012 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION
);
2014 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
2015 gfx::Rect shelf_bounds_in_screen
=
2016 GetShelfWidget()->GetWindowBoundsInScreen();
2017 gfx::Point
start(shelf_bounds_in_screen
.CenterPoint());
2018 gfx::Point
end(start
.x(), shelf_bounds_in_screen
.bottom());
2019 generator
.GestureScrollSequence(start
, end
,
2020 base::TimeDelta::FromMilliseconds(10), 5);
2021 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
2022 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
2024 ShelfAnimationWaiter
waiter(visible_bounds
);
2025 // Wait till the animation completes and check that it occurred.
2026 waiter
.WaitTillDoneAnimating();
2027 EXPECT_TRUE(waiter
.WasValidAnimation());
2030 // Create a visible window so auto-hide behavior is enforced.
2033 // Get the bounds of the shelf when it is hidden.
2034 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
2035 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
2036 gfx::Rect auto_hidden_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
2039 // Enable the animations so that we can make sure they do occur.
2040 ui::ScopedAnimationDurationScaleMode
regular_animations(
2041 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION
);
2044 GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
2045 gfx::Point
end(start
.x(), start
.y() - 100);
2046 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
2048 // Test that the shelf animates to the visible bounds after a swipe up on
2049 // the auto hidden shelf.
2050 generator
.GestureScrollSequence(start
, end
,
2051 base::TimeDelta::FromMilliseconds(10), 1);
2052 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
2053 ShelfAnimationWaiter
waiter1(visible_bounds
);
2054 waiter1
.WaitTillDoneAnimating();
2055 EXPECT_TRUE(waiter1
.WasValidAnimation());
2057 // Test that the shelf animates to the auto hidden bounds after a swipe up
2058 // on the visible shelf.
2059 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
2060 generator
.GestureScrollSequence(start
, end
,
2061 base::TimeDelta::FromMilliseconds(10), 1);
2062 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
2063 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
2064 ShelfAnimationWaiter
waiter2(auto_hidden_bounds
);
2065 waiter2
.WaitTillDoneAnimating();
2066 EXPECT_TRUE(waiter2
.WasValidAnimation());
2070 TEST_F(ShelfLayoutManagerTest
, ShelfFlickerOnTrayActivation
) {
2071 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
2073 // Create a visible window so auto-hide behavior is enforced.
2076 // Turn on auto-hide for the shelf.
2077 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
2078 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
2079 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
2081 // Show the status menu. That should make the shelf visible again.
2082 Shell::GetInstance()->accelerator_controller()->PerformActionIfEnabled(
2083 SHOW_SYSTEM_TRAY_BUBBLE
);
2084 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
2085 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
2086 EXPECT_TRUE(GetSystemTray()->HasSystemBubble());
2089 TEST_F(ShelfLayoutManagerTest
, WorkAreaChangeWorkspace
) {
2090 // Make sure the shelf is always visible.
2091 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
2092 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
2093 shelf
->LayoutShelf();
2095 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
2096 params
.bounds
= gfx::Rect(0, 0, 200, 200);
2097 params
.context
= CurrentContext();
2098 views::Widget
* widget_one
= CreateTestWidgetWithParams(params
);
2099 widget_one
->Maximize();
2101 views::Widget
* widget_two
= CreateTestWidgetWithParams(params
);
2102 widget_two
->Maximize();
2103 widget_two
->Activate();
2105 // Both windows are maximized. They should be of the same size.
2106 EXPECT_EQ(widget_one
->GetNativeWindow()->bounds().ToString(),
2107 widget_two
->GetNativeWindow()->bounds().ToString());
2108 int area_when_shelf_shown
=
2109 widget_one
->GetNativeWindow()->bounds().size().GetArea();
2111 // Now hide the shelf.
2112 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
2114 // Both windows should be resized according to the shelf status.
2115 EXPECT_EQ(widget_one
->GetNativeWindow()->bounds().ToString(),
2116 widget_two
->GetNativeWindow()->bounds().ToString());
2117 // Resized to small.
2118 EXPECT_LT(area_when_shelf_shown
,
2119 widget_one
->GetNativeWindow()->bounds().size().GetArea());
2121 // Now show the shelf.
2122 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
2124 // Again both windows should be of the same size.
2125 EXPECT_EQ(widget_one
->GetNativeWindow()->bounds().ToString(),
2126 widget_two
->GetNativeWindow()->bounds().ToString());
2127 EXPECT_EQ(area_when_shelf_shown
,
2128 widget_one
->GetNativeWindow()->bounds().size().GetArea());
2131 // Confirm that the shelf is dimmed only when content is maximized and
2132 // shelf is not autohidden.
2133 TEST_F(ShelfLayoutManagerTest
, Dimming
) {
2134 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
2135 scoped_ptr
<aura::Window
> w1(CreateTestWindow());
2137 wm::ActivateWindow(w1
.get());
2139 // Normal window doesn't dim shelf.
2140 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
2141 ShelfWidget
* shelf
= GetShelfWidget();
2142 EXPECT_FALSE(shelf
->GetDimsShelf());
2144 // Maximized window does.
2145 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
2146 EXPECT_TRUE(shelf
->GetDimsShelf());
2148 // Change back to normal stops dimming.
2149 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
2150 EXPECT_FALSE(shelf
->GetDimsShelf());
2152 // Changing back to maximized dims again.
2153 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
2154 EXPECT_TRUE(shelf
->GetDimsShelf());
2156 // Changing shelf to autohide stops dimming.
2157 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
2158 EXPECT_FALSE(shelf
->GetDimsShelf());
2161 // Make sure that the shelf will not hide if the mouse is between a bubble and
2163 TEST_F(ShelfLayoutManagerTest
, BubbleEnlargesShelfMouseHitArea
) {
2164 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
2165 StatusAreaWidget
* status_area_widget
=
2166 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
2167 SystemTray
* tray
= GetSystemTray();
2169 // Create a visible window so auto-hide behavior is enforced.
2172 shelf
->LayoutShelf();
2173 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
2175 // Make two iterations - first without a message bubble which should make
2176 // the shelf disappear and then with a message bubble which should keep it
2178 for (int i
= 0; i
< 2; i
++) {
2179 // Make sure the shelf is visible and position the mouse over it. Then
2181 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
2182 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2184 status_area_widget
->GetWindowBoundsInScreen().CenterPoint();
2185 generator
.MoveMouseTo(center
.x(), center
.y());
2186 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
2187 EXPECT_TRUE(shelf
->IsVisible());
2189 // In our first iteration we make sure there is no bubble.
2190 tray
->CloseSystemBubble();
2191 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2193 // In our second iteration we show a bubble.
2194 TestItem
*item
= new TestItem
;
2195 tray
->AddTrayItem(item
);
2196 tray
->ShowNotificationView(item
);
2197 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
2199 // Move the pointer over the edge of the shelf.
2200 generator
.MoveMouseTo(
2201 center
.x(), status_area_widget
->GetWindowBoundsInScreen().y() - 8);
2202 shelf
->UpdateVisibilityState();
2204 EXPECT_TRUE(shelf
->IsVisible());
2205 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
2207 EXPECT_FALSE(shelf
->IsVisible());
2208 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2213 TEST_F(ShelfLayoutManagerTest
, ShelfBackgroundColor
) {
2214 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget()->GetBackgroundType());
2216 scoped_ptr
<aura::Window
> w1(CreateTestWindow());
2218 wm::ActivateWindow(w1
.get());
2219 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget()->GetBackgroundType());
2220 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
2221 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED
, GetShelfWidget()->GetBackgroundType());
2223 scoped_ptr
<aura::Window
> w2(CreateTestWindow());
2225 wm::ActivateWindow(w2
.get());
2226 // Overlaps with shelf.
2227 w2
->SetBounds(GetShelfLayoutManager()->GetIdealBounds());
2229 // Still background is 'maximized'.
2230 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED
, GetShelfWidget()->GetBackgroundType());
2232 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
2233 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP
, GetShelfWidget()->GetBackgroundType());
2234 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
2235 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget()->GetBackgroundType());
2237 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
2238 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED
, GetShelfWidget()->GetBackgroundType());
2240 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget()->GetBackgroundType());
2243 // Verify that the shelf doesn't have the opaque background if it's auto-hide
2245 TEST_F(ShelfLayoutManagerTest
, ShelfBackgroundColorAutoHide
) {
2246 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget ()->GetBackgroundType());
2248 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
2249 scoped_ptr
<aura::Window
> w1(CreateTestWindow());
2251 wm::ActivateWindow(w1
.get());
2252 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP
, GetShelfWidget()->GetBackgroundType());
2253 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
2254 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP
, GetShelfWidget()->GetBackgroundType());
2257 #if defined(OS_CHROMEOS)
2258 #define MAYBE_StatusAreaHitBoxCoversEdge StatusAreaHitBoxCoversEdge
2260 #define MAYBE_StatusAreaHitBoxCoversEdge DISABLED_StatusAreaHitBoxCoversEdge
2263 // Verify the hit bounds of the status area extend to the edge of the shelf.
2264 TEST_F(ShelfLayoutManagerTest
, MAYBE_StatusAreaHitBoxCoversEdge
) {
2265 UpdateDisplay("400x400");
2266 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
2267 StatusAreaWidget
* status_area_widget
=
2268 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
2269 ui::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
2270 generator
.MoveMouseTo(399,399);
2272 // Test bottom right pixel for bottom alignment.
2273 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2274 generator
.ClickLeftButton();
2275 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
2276 generator
.ClickLeftButton();
2277 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2279 // Test bottom right pixel for right alignment.
2280 shelf
->SetAlignment(SHELF_ALIGNMENT_RIGHT
);
2281 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2282 generator
.ClickLeftButton();
2283 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
2284 generator
.ClickLeftButton();
2285 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2287 // Test bottom left pixel for left alignment.
2288 generator
.MoveMouseTo(0, 399);
2289 shelf
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
2290 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2291 generator
.ClickLeftButton();
2292 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
2293 generator
.ClickLeftButton();
2294 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2297 // Tests that when the auto-hide behaviour is changed during an animation the
2298 // target bounds are updated to reflect the new state.
2299 TEST_F(ShelfLayoutManagerTest
,
2300 ShelfAutoHideToggleDuringAnimationUpdatesBounds
) {
2301 ShelfLayoutManager
* shelf_manager
= GetShelfLayoutManager();
2302 aura::Window
* status_window
= GetShelfWidget()->status_area_widget()->
2304 gfx::Rect initial_bounds
= status_window
->bounds();
2306 ui::ScopedAnimationDurationScaleMode
regular_animations(
2307 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION
);
2308 shelf_manager
->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN
);
2309 gfx::Rect hide_target_bounds
= status_window
->GetTargetBounds();
2310 EXPECT_GT(hide_target_bounds
.y(), initial_bounds
.y());
2312 shelf_manager
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
2313 gfx::Rect reshow_target_bounds
= status_window
->GetTargetBounds();
2314 EXPECT_EQ(initial_bounds
, reshow_target_bounds
);
2317 // Tests that during shutdown, that window activation changes are properly
2318 // handled, and do not crash (crbug.com/458768)
2319 TEST_F(ShelfLayoutManagerTest
, ShutdownHandlesWindowActivation
) {
2320 ShelfLayoutManager
* shelf_manager
= GetShelfLayoutManager();
2321 ShelfWidget
* shelf
= GetShelfWidget();
2322 shelf_manager
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
2324 aura::Window
* window1
= CreateTestWindowInShellWithId(0);
2325 window1
->SetBounds(gfx::Rect(0, 0, 100, 100));
2326 window1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
2328 scoped_ptr
<aura::Window
> window2(CreateTestWindowInShellWithId(0));
2329 window2
->SetBounds(gfx::Rect(0, 0, 100, 100));
2331 wm::ActivateWindow(window1
);
2333 shelf
->ShutdownStatusAreaWidget();
2334 shelf_manager
->PrepareForShutdown();
2336 // Deleting a focused maximized window will switch focus to |window2|. This
2337 // would normally cause the ShelfLayoutManager to update its state. However
2338 // during shutdown we want to handle this without crashing.
2342 TEST_F(ShelfLayoutManagerTest
, ShelfLayoutInUnifiedDesktop
) {
2343 if (!SupportsMultipleDisplays())
2346 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
2347 display_manager
->SetDefaultMultiDisplayMode(DisplayManager::UNIFIED
);
2348 display_manager
->SetMultiDisplayMode(DisplayManager::UNIFIED
);
2349 UpdateDisplay("500x500, 500x500");
2351 StatusAreaWidget
* status_area_widget
=
2352 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
2353 EXPECT_TRUE(status_area_widget
->IsVisible());
2354 // Shelf should be in the first display's area.
2355 EXPECT_EQ("348,453 152x47",
2356 status_area_widget
->GetWindowBoundsInScreen().ToString());