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_manager.h"
11 #include "ash/focus_cycler.h"
12 #include "ash/root_window_controller.h"
13 #include "ash/session/session_state_delegate.h"
14 #include "ash/shelf/shelf.h"
15 #include "ash/shelf/shelf_layout_manager_observer.h"
16 #include "ash/shelf/shelf_view.h"
17 #include "ash/shelf/shelf_widget.h"
18 #include "ash/shell.h"
19 #include "ash/shell_window_ids.h"
20 #include "ash/system/status_area_widget.h"
21 #include "ash/system/tray/system_tray.h"
22 #include "ash/system/tray/system_tray_item.h"
23 #include "ash/test/ash_test_base.h"
24 #include "ash/test/shelf_test_api.h"
25 #include "ash/wm/window_state.h"
26 #include "ash/wm/window_util.h"
27 #include "base/command_line.h"
28 #include "base/strings/utf_string_conversions.h"
29 #include "ui/aura/client/aura_constants.h"
30 #include "ui/aura/test/event_generator.h"
31 #include "ui/aura/window.h"
32 #include "ui/aura/window_event_dispatcher.h"
33 #include "ui/compositor/layer.h"
34 #include "ui/compositor/layer_animator.h"
35 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
36 #include "ui/events/gestures/gesture_configuration.h"
37 #include "ui/gfx/display.h"
38 #include "ui/gfx/screen.h"
39 #include "ui/views/controls/label.h"
40 #include "ui/views/layout/fill_layout.h"
41 #include "ui/views/view.h"
42 #include "ui/views/widget/widget.h"
45 #include "base/win/windows_version.h"
51 void StepWidgetLayerAnimatorToEnd(views::Widget
* widget
) {
52 widget
->GetNativeView()->layer()->GetAnimator()->Step(
53 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
56 ShelfWidget
* GetShelfWidget() {
57 return Shell::GetPrimaryRootWindowController()->shelf();
60 ShelfLayoutManager
* GetShelfLayoutManager() {
61 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
64 SystemTray
* GetSystemTray() {
65 return Shell::GetPrimaryRootWindowController()->GetSystemTray();
68 // Class which waits till the shelf finishes animating to the target size and
69 // counts the number of animation steps.
70 class ShelfAnimationWaiter
: views::WidgetObserver
{
72 explicit ShelfAnimationWaiter(const gfx::Rect
& target_bounds
)
73 : target_bounds_(target_bounds
),
75 done_waiting_(false) {
76 GetShelfWidget()->AddObserver(this);
79 virtual ~ShelfAnimationWaiter() {
80 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 virtual 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 virtual ~ShelfLayoutObserverTest() {}
241 bool changed_auto_hide_state() const { return changed_auto_hide_state_
; }
244 virtual void OnAutoHideStateChanged(
245 ShelfAutoHideState new_state
) OVERRIDE
{
246 changed_auto_hide_state_
= true;
249 bool changed_auto_hide_state_
;
251 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutObserverTest
);
254 // Trivial item implementation that tracks its views for testing.
255 class TestItem
: public SystemTrayItem
{
258 : SystemTrayItem(GetSystemTray()),
261 detailed_view_(NULL
),
262 notification_view_(NULL
) {}
264 virtual views::View
* CreateTrayView(user::LoginStatus status
) OVERRIDE
{
265 tray_view_
= new views::View
;
266 // Add a label so it has non-zero width.
267 tray_view_
->SetLayoutManager(new views::FillLayout
);
268 tray_view_
->AddChildView(new views::Label(base::UTF8ToUTF16("Tray")));
272 virtual views::View
* CreateDefaultView(user::LoginStatus status
) OVERRIDE
{
273 default_view_
= new views::View
;
274 default_view_
->SetLayoutManager(new views::FillLayout
);
275 default_view_
->AddChildView(new views::Label(base::UTF8ToUTF16("Default")));
276 return default_view_
;
279 virtual views::View
* CreateDetailedView(user::LoginStatus status
) OVERRIDE
{
280 detailed_view_
= new views::View
;
281 detailed_view_
->SetLayoutManager(new views::FillLayout
);
282 detailed_view_
->AddChildView(
283 new views::Label(base::UTF8ToUTF16("Detailed")));
284 return detailed_view_
;
287 virtual views::View
* CreateNotificationView(
288 user::LoginStatus status
) OVERRIDE
{
289 notification_view_
= new views::View
;
290 return notification_view_
;
293 virtual void DestroyTrayView() OVERRIDE
{
297 virtual void DestroyDefaultView() OVERRIDE
{
298 default_view_
= NULL
;
301 virtual void DestroyDetailedView() OVERRIDE
{
302 detailed_view_
= NULL
;
305 virtual void DestroyNotificationView() OVERRIDE
{
306 notification_view_
= NULL
;
309 virtual void UpdateAfterLoginStatusChange(
310 user::LoginStatus status
) OVERRIDE
{}
312 views::View
* tray_view() const { return tray_view_
; }
313 views::View
* default_view() const { return default_view_
; }
314 views::View
* detailed_view() const { return detailed_view_
; }
315 views::View
* notification_view() const { return notification_view_
; }
318 views::View
* tray_view_
;
319 views::View
* default_view_
;
320 views::View
* detailed_view_
;
321 views::View
* notification_view_
;
323 DISALLOW_COPY_AND_ASSIGN(TestItem
);
328 class ShelfLayoutManagerTest
: public ash::test::AshTestBase
{
330 ShelfLayoutManagerTest() {}
332 void SetState(ShelfLayoutManager
* shelf
,
333 ShelfVisibilityState state
) {
334 shelf
->SetState(state
);
337 void UpdateAutoHideStateNow() {
338 GetShelfLayoutManager()->UpdateAutoHideStateNow();
341 aura::Window
* CreateTestWindow() {
342 aura::Window
* window
= new aura::Window(NULL
);
343 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
344 window
->SetType(ui::wm::WINDOW_TYPE_NORMAL
);
345 window
->Init(aura::WINDOW_LAYER_TEXTURED
);
346 ParentWindowInPrimaryRootWindow(window
);
350 views::Widget
* CreateTestWidgetWithParams(
351 const views::Widget::InitParams
& params
) {
352 views::Widget
* out
= new views::Widget
;
358 // Create a simple widget attached to the current context (will
359 // delete on TearDown).
360 views::Widget
* CreateTestWidget() {
361 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
362 params
.bounds
= gfx::Rect(0, 0, 200, 200);
363 params
.context
= CurrentContext();
364 return CreateTestWidgetWithParams(params
);
367 // Overridden from AshTestBase:
368 virtual void SetUp() OVERRIDE
{
369 CommandLine::ForCurrentProcess()->AppendSwitch(
370 ash::switches::kAshEnableTrayDragging
);
371 test::AshTestBase::SetUp();
374 void RunGestureDragTests(gfx::Vector2d
);
377 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest
);
380 void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta
) {
381 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
382 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
383 views::Widget
* widget
= new views::Widget
;
384 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
385 params
.bounds
= gfx::Rect(0, 0, 200, 200);
386 params
.context
= CurrentContext();
387 widget
->Init(params
);
391 const base::TimeDelta kTimeDelta
= base::TimeDelta::FromMilliseconds(40);
393 aura::Window
* window
= widget
->GetNativeWindow();
394 shelf
->LayoutShelf();
396 gfx::Rect shelf_shown
= GetShelfWidget()->GetWindowBoundsInScreen();
397 gfx::Rect bounds_shelf
= window
->bounds();
398 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
400 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
401 shelf
->LayoutShelf();
402 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
404 gfx::Rect bounds_noshelf
= window
->bounds();
405 gfx::Rect shelf_hidden
= GetShelfWidget()->GetWindowBoundsInScreen();
407 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
408 shelf
->LayoutShelf();
410 aura::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
411 const int kNumScrollSteps
= 4;
412 ShelfDragCallback
handler(shelf_hidden
, shelf_shown
);
414 // Swipe up on the shelf. This should not change any state.
415 gfx::Point start
= GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
416 gfx::Point end
= start
+ delta
;
418 // Swipe down on the shelf to hide it.
419 generator
.GestureScrollSequenceWithCallback(
424 base::Bind(&ShelfDragCallback::ProcessScroll
,
425 base::Unretained(&handler
)));
426 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
427 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
428 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
429 EXPECT_NE(bounds_shelf
.ToString(), window
->bounds().ToString());
430 EXPECT_NE(shelf_shown
.ToString(),
431 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
433 // Swipe up to show the shelf.
434 generator
.GestureScrollSequenceWithCallback(
439 base::Bind(&ShelfDragCallback::ProcessScroll
,
440 base::Unretained(&handler
)));
441 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
442 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
443 EXPECT_EQ(bounds_shelf
.ToString(), window
->bounds().ToString());
444 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
445 GetShelfWidget()->GetWindowBoundsInScreen());
446 EXPECT_EQ(shelf_shown
.ToString(),
447 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
449 // Swipe up again. The shelf should hide.
451 generator
.GestureScrollSequenceWithCallback(
456 base::Bind(&ShelfDragCallback::ProcessScroll
,
457 base::Unretained(&handler
)));
458 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
459 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
460 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
461 EXPECT_EQ(shelf_hidden
.ToString(),
462 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
464 // Swipe up yet again to show it.
466 generator
.GestureScrollSequenceWithCallback(
471 base::Bind(&ShelfDragCallback::ProcessScroll
,
472 base::Unretained(&handler
)));
474 // Swipe down very little. It shouldn't change any state.
475 if (GetShelfLayoutManager()->IsHorizontalAlignment())
476 end
.set_y(start
.y() + shelf_shown
.height() * 3 / 10);
477 else if (SHELF_ALIGNMENT_LEFT
== GetShelfLayoutManager()->GetAlignment())
478 end
.set_x(start
.x() - shelf_shown
.width() * 3 / 10);
479 else if (SHELF_ALIGNMENT_RIGHT
== GetShelfLayoutManager()->GetAlignment())
480 end
.set_x(start
.x() + shelf_shown
.width() * 3 / 10);
481 generator
.GestureScrollSequence(start
, end
, kTimeDelta
, 5);
482 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
483 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
484 EXPECT_EQ(bounds_shelf
.ToString(), window
->bounds().ToString());
485 EXPECT_EQ(shelf_shown
.ToString(),
486 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
488 // Swipe down again to hide.
490 generator
.GestureScrollSequenceWithCallback(
495 base::Bind(&ShelfDragCallback::ProcessScroll
,
496 base::Unretained(&handler
)));
497 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
498 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
499 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
500 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
501 EXPECT_EQ(bounds_noshelf
.ToString(), window
->bounds().ToString());
502 EXPECT_EQ(shelf_hidden
.ToString(),
503 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
505 // Swipe up in extended hit region to show it.
506 gfx::Point extended_start
= start
;
507 if (GetShelfLayoutManager()->IsHorizontalAlignment())
508 extended_start
.set_y(GetShelfWidget()->GetWindowBoundsInScreen().y() -1);
509 else if (SHELF_ALIGNMENT_LEFT
== GetShelfLayoutManager()->GetAlignment())
510 extended_start
.set_x(
511 GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
512 else if (SHELF_ALIGNMENT_RIGHT
== GetShelfLayoutManager()->GetAlignment())
513 extended_start
.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
514 end
= extended_start
- delta
;
515 generator
.GestureScrollSequenceWithCallback(
520 base::Bind(&ShelfDragCallback::ProcessScroll
,
521 base::Unretained(&handler
)));
522 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
523 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
524 EXPECT_EQ(bounds_shelf
.ToString(), window
->bounds().ToString());
525 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
526 GetShelfWidget()->GetWindowBoundsInScreen());
527 EXPECT_EQ(shelf_shown
.ToString(),
528 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
530 // Swipe down again to hide.
532 generator
.GestureScrollSequenceWithCallback(
537 base::Bind(&ShelfDragCallback::ProcessScroll
,
538 base::Unretained(&handler
)));
539 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
540 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
541 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
542 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
543 EXPECT_EQ(bounds_noshelf
.ToString(), window
->bounds().ToString());
544 EXPECT_EQ(shelf_hidden
.ToString(),
545 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
547 // Swipe up outside the hit area. This should not change anything.
548 gfx::Point outside_start
= gfx::Point(
549 (GetShelfWidget()->GetWindowBoundsInScreen().x() +
550 GetShelfWidget()->GetWindowBoundsInScreen().right())/2,
551 GetShelfWidget()->GetWindowBoundsInScreen().y() - 50);
552 end
= outside_start
+ delta
;
553 generator
.GestureScrollSequence(
554 outside_start
, end
, kTimeDelta
, kNumScrollSteps
);
555 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
556 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
557 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
558 EXPECT_EQ(shelf_hidden
.ToString(),
559 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
561 // Swipe up from below the shelf where a bezel would be, this should show the
563 gfx::Point below_start
= start
;
564 if (GetShelfLayoutManager()->IsHorizontalAlignment())
565 below_start
.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() + 1);
566 else if (SHELF_ALIGNMENT_LEFT
== GetShelfLayoutManager()->GetAlignment())
568 GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
569 else if (SHELF_ALIGNMENT_RIGHT
== GetShelfLayoutManager()->GetAlignment())
570 below_start
.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
571 end
= below_start
- delta
;
572 generator
.GestureScrollSequence(
573 below_start
, end
, kTimeDelta
, kNumScrollSteps
);
574 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
575 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
576 EXPECT_EQ(bounds_shelf
.ToString(), window
->bounds().ToString());
577 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
578 GetShelfWidget()->GetWindowBoundsInScreen());
579 EXPECT_EQ(shelf_shown
.ToString(),
580 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
582 // Swipe down again to hide.
584 generator
.GestureScrollSequenceWithCallback(
589 base::Bind(&ShelfDragCallback::ProcessScroll
,
590 base::Unretained(&handler
)));
591 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
592 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
593 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
594 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
595 EXPECT_EQ(bounds_noshelf
.ToString(), window
->bounds().ToString());
596 EXPECT_EQ(shelf_hidden
.ToString(),
597 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
599 // Put |widget| into fullscreen. Set the shelf to be auto hidden when |widget|
600 // is fullscreen. (eg browser immersive fullscreen).
601 widget
->SetFullscreen(true);
602 wm::GetWindowState(window
)->set_hide_shelf_when_fullscreen(false);
603 shelf
->UpdateVisibilityState();
605 gfx::Rect bounds_fullscreen
= window
->bounds();
606 EXPECT_TRUE(widget
->IsFullscreen());
607 EXPECT_NE(bounds_noshelf
.ToString(), bounds_fullscreen
.ToString());
609 // Swipe up. This should show the shelf.
610 end
= below_start
- delta
;
611 generator
.GestureScrollSequenceWithCallback(
616 base::Bind(&ShelfDragCallback::ProcessScroll
,
617 base::Unretained(&handler
)));
618 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
619 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
620 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());
621 EXPECT_EQ(shelf_shown
.ToString(),
622 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
623 EXPECT_EQ(bounds_fullscreen
.ToString(), window
->bounds().ToString());
625 // Swipe up again. This should hide the shelf.
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_HIDDEN
, shelf
->auto_hide_state());
635 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
636 EXPECT_EQ(shelf_hidden
.ToString(),
637 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
638 EXPECT_EQ(bounds_fullscreen
.ToString(), window
->bounds().ToString());
640 // Set the shelf to be hidden when |widget| is fullscreen. (eg tab fullscreen
641 // with or without immersive browser fullscreen).
642 wm::GetWindowState(window
)->set_hide_shelf_when_fullscreen(true);
643 shelf
->UpdateVisibilityState();
644 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
645 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
647 // Swipe-up. This should not change anything.
649 generator
.GestureScrollSequenceWithCallback(
654 base::Bind(&ShelfDragCallback::ProcessScroll
,
655 base::Unretained(&handler
)));
656 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
657 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
658 EXPECT_EQ(bounds_fullscreen
.ToString(), window
->bounds().ToString());
660 // Close actually, otherwise further event may be affected since widget
661 // is fullscreen status.
663 RunAllPendingInMessageLoop();
665 // The shelf should be shown because there are no more visible windows.
666 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
667 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
668 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
670 // Swipe-up to hide. This should have no effect because there are no visible
672 end
= below_start
- delta
;
673 generator
.GestureScrollSequenceWithCallback(
678 base::Bind(&ShelfDragCallback::ProcessScroll
,
679 base::Unretained(&handler
)));
680 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
681 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
682 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
, shelf
->auto_hide_behavior());
685 // Need to be implemented. http://crbug.com/111279.
687 #define MAYBE_SetVisible DISABLED_SetVisible
689 #define MAYBE_SetVisible SetVisible
691 // Makes sure SetVisible updates work area and widget appropriately.
692 TEST_F(ShelfLayoutManagerTest
, MAYBE_SetVisible
) {
693 ShelfWidget
* shelf
= GetShelfWidget();
694 ShelfLayoutManager
* manager
= shelf
->shelf_layout_manager();
695 // Force an initial layout.
696 manager
->LayoutShelf();
697 EXPECT_EQ(SHELF_VISIBLE
, manager
->visibility_state());
699 gfx::Rect
status_bounds(
700 shelf
->status_area_widget()->GetWindowBoundsInScreen());
701 gfx::Rect
shelf_bounds(
702 shelf
->GetWindowBoundsInScreen());
703 int shelf_height
= manager
->GetIdealBounds().height();
704 gfx::Screen
* screen
= Shell::GetScreen();
705 gfx::Display display
= screen
->GetDisplayNearestWindow(
706 Shell::GetPrimaryRootWindow());
707 ASSERT_NE(-1, display
.id());
708 // Bottom inset should be the max of widget heights.
709 EXPECT_EQ(shelf_height
, display
.GetWorkAreaInsets().bottom());
712 SetState(manager
, SHELF_HIDDEN
);
713 // Run the animation to completion.
714 StepWidgetLayerAnimatorToEnd(shelf
);
715 StepWidgetLayerAnimatorToEnd(shelf
->status_area_widget());
716 EXPECT_EQ(SHELF_HIDDEN
, manager
->visibility_state());
717 display
= screen
->GetDisplayNearestWindow(
718 Shell::GetPrimaryRootWindow());
720 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
722 // Make sure the bounds of the two widgets changed.
723 EXPECT_GE(shelf
->GetNativeView()->bounds().y(),
724 screen
->GetPrimaryDisplay().bounds().bottom());
725 EXPECT_GE(shelf
->status_area_widget()->GetNativeView()->bounds().y(),
726 screen
->GetPrimaryDisplay().bounds().bottom());
728 // And show it again.
729 SetState(manager
, SHELF_VISIBLE
);
730 // Run the animation to completion.
731 StepWidgetLayerAnimatorToEnd(shelf
);
732 StepWidgetLayerAnimatorToEnd(shelf
->status_area_widget());
733 EXPECT_EQ(SHELF_VISIBLE
, manager
->visibility_state());
734 display
= screen
->GetDisplayNearestWindow(
735 Shell::GetPrimaryRootWindow());
736 EXPECT_EQ(shelf_height
, display
.GetWorkAreaInsets().bottom());
738 // Make sure the bounds of the two widgets changed.
739 shelf_bounds
= shelf
->GetNativeView()->bounds();
740 EXPECT_LT(shelf_bounds
.y(), screen
->GetPrimaryDisplay().bounds().bottom());
741 status_bounds
= shelf
->status_area_widget()->GetNativeView()->bounds();
742 EXPECT_LT(status_bounds
.y(),
743 screen
->GetPrimaryDisplay().bounds().bottom());
746 // Makes sure shelf alignment is correct for lock screen.
747 TEST_F(ShelfLayoutManagerTest
, SideAlignmentInteractionWithLockScreen
) {
748 ShelfLayoutManager
* manager
= GetShelfWidget()->shelf_layout_manager();
749 manager
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
750 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, manager
->GetAlignment());
751 Shell::GetInstance()->session_state_delegate()->LockScreen();
752 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM
, manager
->GetAlignment());
753 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
754 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, manager
->GetAlignment());
757 // Makes sure LayoutShelf invoked while animating cleans things up.
758 TEST_F(ShelfLayoutManagerTest
, LayoutShelfWhileAnimating
) {
759 ShelfWidget
* shelf
= GetShelfWidget();
760 // Force an initial layout.
761 shelf
->shelf_layout_manager()->LayoutShelf();
762 EXPECT_EQ(SHELF_VISIBLE
, shelf
->shelf_layout_manager()->visibility_state());
765 SetState(shelf
->shelf_layout_manager(), SHELF_HIDDEN
);
766 shelf
->shelf_layout_manager()->LayoutShelf();
767 EXPECT_EQ(SHELF_HIDDEN
, shelf
->shelf_layout_manager()->visibility_state());
768 gfx::Display display
= Shell::GetScreen()->GetDisplayNearestWindow(
769 Shell::GetPrimaryRootWindow());
770 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
772 // Make sure the bounds of the two widgets changed.
773 EXPECT_GE(shelf
->GetNativeView()->bounds().y(),
774 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
775 EXPECT_GE(shelf
->status_area_widget()->GetNativeView()->bounds().y(),
776 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
779 // Test that switching to a different visibility state does not restart the
780 // shelf show / hide animation if it is already running. (crbug.com/250918)
781 TEST_F(ShelfLayoutManagerTest
, SetStateWhileAnimating
) {
782 ShelfWidget
* shelf
= GetShelfWidget();
783 SetState(shelf
->shelf_layout_manager(), SHELF_VISIBLE
);
784 gfx::Rect initial_shelf_bounds
= shelf
->GetWindowBoundsInScreen();
785 gfx::Rect initial_status_bounds
=
786 shelf
->status_area_widget()->GetWindowBoundsInScreen();
788 ui::ScopedAnimationDurationScaleMode
normal_animation_duration(
789 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION
);
790 SetState(shelf
->shelf_layout_manager(), SHELF_HIDDEN
);
791 SetState(shelf
->shelf_layout_manager(), SHELF_VISIBLE
);
793 gfx::Rect current_shelf_bounds
= shelf
->GetWindowBoundsInScreen();
794 gfx::Rect current_status_bounds
=
795 shelf
->status_area_widget()->GetWindowBoundsInScreen();
797 const int small_change
= initial_shelf_bounds
.height() / 2;
799 std::abs(initial_shelf_bounds
.height() - current_shelf_bounds
.height()),
802 std::abs(initial_status_bounds
.height() - current_status_bounds
.height()),
806 // Makes sure the shelf is sized when the status area changes size.
807 TEST_F(ShelfLayoutManagerTest
, ShelfUpdatedWhenStatusAreaChangesSize
) {
808 Shelf
* shelf
= Shelf::ForPrimaryDisplay();
810 ShelfWidget
* shelf_widget
= GetShelfWidget();
811 ASSERT_TRUE(shelf_widget
);
812 ASSERT_TRUE(shelf_widget
->status_area_widget());
813 shelf_widget
->status_area_widget()->SetBounds(
814 gfx::Rect(0, 0, 200, 200));
815 EXPECT_EQ(200, shelf_widget
->GetContentsView()->width() -
816 test::ShelfTestAPI(shelf
).shelf_view()->width());
821 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
822 #define MAYBE_AutoHide DISABLED_AutoHide
824 #define MAYBE_AutoHide AutoHide
827 // Various assertions around auto-hide.
828 TEST_F(ShelfLayoutManagerTest
, MAYBE_AutoHide
) {
829 aura::Window
* root
= Shell::GetPrimaryRootWindow();
830 aura::test::EventGenerator
generator(root
, root
);
831 generator
.MoveMouseTo(0, 0);
833 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
834 shelf
->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
835 views::Widget
* widget
= new views::Widget
;
836 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
837 params
.bounds
= gfx::Rect(0, 0, 200, 200);
838 params
.context
= CurrentContext();
839 // Widget is now owned by the parent window.
840 widget
->Init(params
);
843 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
844 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
846 // LayoutShelf() forces the animation to completion, at which point the
847 // shelf should go off the screen.
848 shelf
->LayoutShelf();
849 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
850 GetShelfWidget()->GetWindowBoundsInScreen().y());
851 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
852 Shell::GetScreen()->GetDisplayNearestWindow(
853 root
).work_area().bottom());
855 // Move the mouse to the bottom of the screen.
856 generator
.MoveMouseTo(0, root
->bounds().bottom() - 1);
858 // Shelf should be shown again (but it shouldn't have changed the work area).
859 SetState(shelf
, SHELF_AUTO_HIDE
);
860 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
861 shelf
->LayoutShelf();
862 EXPECT_EQ(root
->bounds().bottom() - shelf
->GetIdealBounds().height(),
863 GetShelfWidget()->GetWindowBoundsInScreen().y());
864 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
865 Shell::GetScreen()->GetDisplayNearestWindow(
866 root
).work_area().bottom());
868 // Move mouse back up.
869 generator
.MoveMouseTo(0, 0);
870 SetState(shelf
, SHELF_AUTO_HIDE
);
871 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
872 shelf
->LayoutShelf();
873 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
874 GetShelfWidget()->GetWindowBoundsInScreen().y());
876 // Drag mouse to bottom of screen.
877 generator
.PressLeftButton();
878 generator
.MoveMouseTo(0, root
->bounds().bottom() - 1);
879 UpdateAutoHideStateNow();
880 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
882 generator
.ReleaseLeftButton();
883 generator
.MoveMouseTo(1, root
->bounds().bottom() - 1);
884 UpdateAutoHideStateNow();
885 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
886 generator
.PressLeftButton();
887 generator
.MoveMouseTo(1, root
->bounds().bottom() - 1);
888 UpdateAutoHideStateNow();
889 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
892 // Test the behavior of the shelf when it is auto hidden and it is on the
893 // boundary between the primary and the secondary display.
894 TEST_F(ShelfLayoutManagerTest
, AutoHideShelfOnScreenBoundary
) {
895 if (!SupportsMultipleDisplays())
898 UpdateDisplay("800x600,800x600");
899 DisplayLayout
display_layout(DisplayLayout::RIGHT
, 0);
900 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
902 // Put the primary monitor's shelf on the display boundary.
903 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
904 shelf
->SetAlignment(SHELF_ALIGNMENT_RIGHT
);
906 // Create a window because the shelf is always shown when no windows are
910 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
911 ASSERT_EQ(root_windows
[0],
912 GetShelfWidget()->GetNativeWindow()->GetRootWindow());
914 shelf
->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
915 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
917 int right_edge
= root_windows
[0]->GetBoundsInScreen().right() - 1;
918 int y
= root_windows
[0]->GetBoundsInScreen().y();
920 // Start off the mouse nowhere near the shelf; the shelf should be hidden.
921 aura::test::EventGenerator
& generator(GetEventGenerator());
922 generator
.MoveMouseTo(right_edge
- 50, y
);
923 UpdateAutoHideStateNow();
924 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
926 // Moving the mouse over the light bar (but not to the edge of the screen)
927 // should show the shelf.
928 generator
.MoveMouseTo(right_edge
- 1, y
);
929 UpdateAutoHideStateNow();
930 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
931 EXPECT_EQ(right_edge
- 1, Shell::GetScreen()->GetCursorScreenPoint().x());
933 // Moving the mouse off the light bar should hide the shelf.
934 generator
.MoveMouseTo(right_edge
- 50, y
);
935 UpdateAutoHideStateNow();
936 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
938 // Moving the mouse to the right edge of the screen crossing the light bar
939 // should show the shelf despite the mouse cursor getting warped to the
940 // secondary display.
941 generator
.MoveMouseTo(right_edge
- 1, y
);
942 generator
.MoveMouseTo(right_edge
, y
);
943 UpdateAutoHideStateNow();
944 EXPECT_NE(right_edge
- 1, Shell::GetScreen()->GetCursorScreenPoint().x());
945 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
948 generator
.MoveMouseTo(right_edge
- 50, y
);
949 UpdateAutoHideStateNow();
950 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
952 // Moving the mouse to the right edge of the screen crossing the light bar and
953 // overshooting by a lot should keep the shelf hidden.
954 generator
.MoveMouseTo(right_edge
- 1, y
);
955 generator
.MoveMouseTo(right_edge
+ 50, y
);
956 UpdateAutoHideStateNow();
957 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
959 // Moving the mouse to the right edge of the screen crossing the light bar and
960 // overshooting a bit should show the shelf.
961 generator
.MoveMouseTo(right_edge
- 1, y
);
962 generator
.MoveMouseTo(right_edge
+ 2, y
);
963 UpdateAutoHideStateNow();
964 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
966 // Keeping the mouse close to the left edge of the secondary display after the
967 // shelf is shown should keep the shelf shown.
968 generator
.MoveMouseTo(right_edge
+ 2, y
+ 1);
969 UpdateAutoHideStateNow();
970 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
972 // Moving the mouse far from the left edge of the secondary display should
974 generator
.MoveMouseTo(right_edge
+ 50, y
);
975 UpdateAutoHideStateNow();
976 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
978 // Moving to the left edge of the secondary display without first crossing
979 // the primary display's right aligned shelf first should not show the shelf.
980 generator
.MoveMouseTo(right_edge
+ 2, y
);
981 UpdateAutoHideStateNow();
982 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
985 // Assertions around the lock screen showing.
986 TEST_F(ShelfLayoutManagerTest
, VisibleWhenLockScreenShowing
) {
987 // Since ShelfLayoutManager queries for mouse location, move the mouse so
988 // it isn't over the shelf.
989 aura::test::EventGenerator
generator(
990 Shell::GetPrimaryRootWindow(), gfx::Point());
991 generator
.MoveMouseTo(0, 0);
993 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
994 shelf
->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
995 views::Widget
* widget
= new views::Widget
;
996 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
997 params
.bounds
= gfx::Rect(0, 0, 200, 200);
998 params
.context
= CurrentContext();
999 // Widget is now owned by the parent window.
1000 widget
->Init(params
);
1003 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1004 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1006 aura::Window
* root
= Shell::GetPrimaryRootWindow();
1007 // LayoutShelf() forces the animation to completion, at which point the
1008 // shelf should go off the screen.
1009 shelf
->LayoutShelf();
1010 EXPECT_EQ(root
->bounds().bottom() - ShelfLayoutManager::kAutoHideSize
,
1011 GetShelfWidget()->GetWindowBoundsInScreen().y());
1013 aura::Window
* lock_container
= Shell::GetContainer(
1014 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer
);
1016 views::Widget
* lock_widget
= new views::Widget
;
1017 views::Widget::InitParams
lock_params(
1018 views::Widget::InitParams::TYPE_WINDOW
);
1019 lock_params
.bounds
= gfx::Rect(0, 0, 200, 200);
1020 params
.context
= CurrentContext();
1021 lock_params
.parent
= lock_container
;
1022 // Widget is now owned by the parent window.
1023 lock_widget
->Init(lock_params
);
1024 lock_widget
->Maximize();
1025 lock_widget
->Show();
1028 Shell::GetInstance()->session_state_delegate()->LockScreen();
1029 shelf
->UpdateVisibilityState();
1030 // Showing a widget in the lock screen should force the shelf to be visibile.
1031 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1033 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
1034 shelf
->UpdateVisibilityState();
1035 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1038 // Assertions around SetAutoHideBehavior.
1039 TEST_F(ShelfLayoutManagerTest
, SetAutoHideBehavior
) {
1040 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1041 // it isn't over the shelf.
1042 aura::test::EventGenerator
generator(
1043 Shell::GetPrimaryRootWindow(), gfx::Point());
1044 generator
.MoveMouseTo(0, 0);
1046 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1047 views::Widget
* widget
= new views::Widget
;
1048 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1049 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1050 params
.context
= CurrentContext();
1051 // Widget is now owned by the parent window.
1052 widget
->Init(params
);
1054 aura::Window
* window
= widget
->GetNativeWindow();
1055 gfx::Rect
display_bounds(
1056 Shell::GetScreen()->GetDisplayNearestWindow(window
).bounds());
1058 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1059 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1061 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1062 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1065 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1066 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1067 window
).work_area().bottom(),
1068 widget
->GetWorkAreaBoundsInScreen().bottom());
1070 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1071 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1072 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1073 window
).work_area().bottom(),
1074 widget
->GetWorkAreaBoundsInScreen().bottom());
1076 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1077 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1078 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1079 window
).work_area().bottom(),
1080 widget
->GetWorkAreaBoundsInScreen().bottom());
1083 // Basic assertions around the dimming of the shelf.
1084 TEST_F(ShelfLayoutManagerTest
, TestDimmingBehavior
) {
1085 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1086 // it isn't over the shelf.
1087 aura::test::EventGenerator
generator(
1088 Shell::GetPrimaryRootWindow(), gfx::Point());
1089 generator
.MoveMouseTo(0, 0);
1091 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1092 shelf
->shelf_widget()->DisableDimmingAnimationsForTest();
1094 views::Widget
* widget
= new views::Widget
;
1095 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1096 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1097 params
.context
= CurrentContext();
1098 // Widget is now owned by the parent window.
1099 widget
->Init(params
);
1101 aura::Window
* window
= widget
->GetNativeWindow();
1102 gfx::Rect
display_bounds(
1103 Shell::GetScreen()->GetDisplayNearestWindow(window
).bounds());
1105 gfx::Point off_shelf
= display_bounds
.CenterPoint();
1106 gfx::Point on_shelf
=
1107 shelf
->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1109 // Test there is no dimming object active at this point.
1110 generator
.MoveMouseTo(on_shelf
.x(), on_shelf
.y());
1111 EXPECT_EQ(-1, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1112 generator
.MoveMouseTo(off_shelf
.x(), off_shelf
.y());
1113 EXPECT_EQ(-1, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1115 // After maximization, the shelf should be visible and the dimmer created.
1118 on_shelf
= shelf
->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1119 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1121 // Moving the mouse off the shelf should dim the bar.
1122 generator
.MoveMouseTo(off_shelf
.x(), off_shelf
.y());
1123 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1125 // Adding touch events outside the shelf should still keep the shelf in
1127 generator
.PressTouch();
1128 generator
.MoveTouch(off_shelf
);
1129 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1130 // Move the touch into the shelf area should undim.
1131 generator
.MoveTouch(on_shelf
);
1132 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1133 generator
.ReleaseTouch();
1134 // And a release dims again.
1135 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1137 // Moving the mouse on the shelf should undim the bar.
1138 generator
.MoveMouseTo(on_shelf
);
1139 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1141 // No matter what the touch events do, the shelf should stay undimmed.
1142 generator
.PressTouch();
1143 generator
.MoveTouch(off_shelf
);
1144 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1145 generator
.MoveTouch(on_shelf
);
1146 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1147 generator
.MoveTouch(off_shelf
);
1148 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1149 generator
.MoveTouch(on_shelf
);
1150 generator
.ReleaseTouch();
1152 // After restore, the dimming object should be deleted again.
1154 EXPECT_EQ(-1, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1157 // Assertions around the dimming of the shelf in conjunction with menus.
1158 TEST_F(ShelfLayoutManagerTest
, TestDimmingBehaviorWithMenus
) {
1159 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1160 // it isn't over the shelf.
1161 aura::test::EventGenerator
generator(
1162 Shell::GetPrimaryRootWindow(), gfx::Point());
1163 generator
.MoveMouseTo(0, 0);
1165 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1166 shelf
->shelf_widget()->DisableDimmingAnimationsForTest();
1168 views::Widget
* widget
= new views::Widget
;
1169 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1170 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1171 params
.context
= CurrentContext();
1172 // Widget is now owned by the parent window.
1173 widget
->Init(params
);
1175 aura::Window
* window
= widget
->GetNativeWindow();
1176 gfx::Rect
display_bounds(
1177 Shell::GetScreen()->GetDisplayNearestWindow(window
).bounds());
1179 // After maximization, the shelf should be visible and the dimmer created.
1182 gfx::Point off_shelf
= display_bounds
.CenterPoint();
1183 gfx::Point on_shelf
=
1184 shelf
->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1186 // Moving the mouse on the shelf should undim the bar.
1187 generator
.MoveMouseTo(on_shelf
.x(), on_shelf
.y());
1188 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1190 // Simulate a menu opening.
1191 shelf
->shelf_widget()->ForceUndimming(true);
1193 // Moving the mouse off the shelf should not dim the bar.
1194 generator
.MoveMouseTo(off_shelf
.x(), off_shelf
.y());
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
.ReleaseTouch();
1206 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1208 // "Closing the menu" should now turn off the menu since no event is inside
1209 // the shelf any longer.
1210 shelf
->shelf_widget()->ForceUndimming(false);
1211 EXPECT_LT(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1213 // Moving the mouse again on the shelf which should undim the bar again.
1214 // This time we check that the bar stays undimmed when the mouse remains on
1215 // the bar and the "menu gets closed".
1216 generator
.MoveMouseTo(on_shelf
.x(), on_shelf
.y());
1217 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1218 shelf
->shelf_widget()->ForceUndimming(true);
1219 generator
.MoveMouseTo(off_shelf
.x(), off_shelf
.y());
1220 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1221 generator
.MoveMouseTo(on_shelf
.x(), on_shelf
.y());
1222 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1223 shelf
->shelf_widget()->ForceUndimming(true);
1224 EXPECT_EQ(0, shelf
->shelf_widget()->GetDimmingAlphaForTest());
1227 // Verifies the shelf is visible when status/shelf is focused.
1228 TEST_F(ShelfLayoutManagerTest
, VisibleWhenStatusOrShelfFocused
) {
1229 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1230 // it isn't over the shelf.
1231 aura::test::EventGenerator
generator(
1232 Shell::GetPrimaryRootWindow(), gfx::Point());
1233 generator
.MoveMouseTo(0, 0);
1235 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1236 views::Widget
* widget
= new views::Widget
;
1237 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1238 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1239 params
.context
= CurrentContext();
1240 // Widget is now owned by the parent window.
1241 widget
->Init(params
);
1243 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1244 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1245 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1247 // Focus the shelf. Have to go through the focus cycler as normal focus
1248 // requests to it do nothing.
1249 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD
);
1250 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1253 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1255 // Trying to activate the status should fail, since we only allow activating
1256 // it when the user is using the keyboard (i.e. through FocusCycler).
1257 GetShelfWidget()->status_area_widget()->Activate();
1258 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1260 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD
);
1261 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1264 // Makes sure shelf will be visible when app list opens as shelf is in
1265 // SHELF_VISIBLE state,and toggling app list won't change shelf
1266 // visibility state.
1267 TEST_F(ShelfLayoutManagerTest
, OpenAppListWithShelfVisibleState
) {
1268 Shell
* shell
= Shell::GetInstance();
1269 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1270 shelf
->LayoutShelf();
1271 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1273 // Create a normal unmaximized windowm shelf should be visible.
1274 aura::Window
* window
= CreateTestWindow();
1275 window
->SetBounds(gfx::Rect(0, 0, 100, 100));
1277 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1278 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1280 // Toggle app list to show, and the shelf stays visible.
1281 shell
->ToggleAppList(NULL
);
1282 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
1283 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1285 // Toggle app list to hide, and the shelf stays visible.
1286 shell
->ToggleAppList(NULL
);
1287 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1288 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1291 // Makes sure shelf will be shown with SHELF_AUTO_HIDE_SHOWN state
1292 // when app list opens as shelf is in SHELF_AUTO_HIDE state, and
1293 // toggling app list won't change shelf visibility state.
1294 TEST_F(ShelfLayoutManagerTest
, OpenAppListWithShelfAutoHideState
) {
1295 Shell
* shell
= Shell::GetInstance();
1296 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1297 shelf
->LayoutShelf();
1298 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1300 // Create a window and show it in maximized state.
1301 aura::Window
* window
= CreateTestWindow();
1302 window
->SetBounds(gfx::Rect(0, 0, 100, 100));
1303 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1305 wm::ActivateWindow(window
);
1307 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1308 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1310 // Toggle app list to show.
1311 shell
->ToggleAppList(NULL
);
1312 // The shelf's auto hide state won't be changed until the timer fires, so
1313 // calling shell->UpdateShelfVisibility() is kind of manually helping it to
1314 // update the state.
1315 shell
->UpdateShelfVisibility();
1316 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
1317 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1318 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1320 // Toggle app list to hide.
1321 shell
->ToggleAppList(NULL
);
1322 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1323 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1326 // Makes sure shelf will be hidden when app list opens as shelf is in HIDDEN
1327 // state, and toggling app list won't change shelf visibility state.
1328 TEST_F(ShelfLayoutManagerTest
, OpenAppListWithShelfHiddenState
) {
1329 Shell
* shell
= Shell::GetInstance();
1330 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1331 // For shelf to be visible, app list is not open in initial state.
1332 shelf
->LayoutShelf();
1334 // Create a window and make it full screen.
1335 aura::Window
* window
= CreateTestWindow();
1336 window
->SetBounds(gfx::Rect(0, 0, 100, 100));
1337 window
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
1339 wm::ActivateWindow(window
);
1341 // App list and shelf is not shown.
1342 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1343 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1345 // Toggle app list to show.
1346 shell
->ToggleAppList(NULL
);
1347 EXPECT_TRUE(shell
->GetAppListTargetVisibility());
1348 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1350 // Toggle app list to hide.
1351 shell
->ToggleAppList(NULL
);
1352 EXPECT_FALSE(shell
->GetAppListTargetVisibility());
1353 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1356 // Tests that the shelf is only hidden for a fullscreen window at the front and
1357 // toggles visibility when another window is activated.
1358 TEST_F(ShelfLayoutManagerTest
, FullscreenWindowInFrontHidesShelf
) {
1359 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1361 // Create a window and make it full screen.
1362 aura::Window
* window1
= CreateTestWindow();
1363 window1
->SetBounds(gfx::Rect(0, 0, 100, 100));
1364 window1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
1367 aura::Window
* window2
= CreateTestWindow();
1368 window2
->SetBounds(gfx::Rect(0, 0, 100, 100));
1371 wm::GetWindowState(window1
)->Activate();
1372 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1374 wm::GetWindowState(window2
)->Activate();
1375 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1377 wm::GetWindowState(window1
)->Activate();
1378 EXPECT_EQ(SHELF_HIDDEN
, shelf
->visibility_state());
1381 // Test the behavior of the shelf when a window on one display is fullscreen
1382 // but the other display has the active window.
1383 TEST_F(ShelfLayoutManagerTest
, FullscreenWindowOnSecondDisplay
) {
1384 if (!SupportsMultipleDisplays())
1387 UpdateDisplay("800x600,800x600");
1388 DisplayManager
* display_manager
= Shell::GetInstance()->display_manager();
1389 aura::Window::Windows root_windows
= Shell::GetAllRootWindows();
1390 Shell::RootWindowControllerList root_window_controllers
=
1391 Shell::GetAllRootWindowControllers();
1393 // Create windows on either display.
1394 aura::Window
* window1
= CreateTestWindow();
1395 window1
->SetBoundsInScreen(
1396 gfx::Rect(0, 0, 100, 100),
1397 display_manager
->GetDisplayAt(0));
1398 window1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_FULLSCREEN
);
1401 aura::Window
* window2
= CreateTestWindow();
1402 window2
->SetBoundsInScreen(
1403 gfx::Rect(800, 0, 100, 100),
1404 display_manager
->GetDisplayAt(1));
1407 EXPECT_EQ(root_windows
[0], window1
->GetRootWindow());
1408 EXPECT_EQ(root_windows
[1], window2
->GetRootWindow());
1410 wm::GetWindowState(window2
)->Activate();
1411 EXPECT_EQ(SHELF_HIDDEN
,
1412 root_window_controllers
[0]->GetShelfLayoutManager()->visibility_state());
1413 EXPECT_EQ(SHELF_VISIBLE
,
1414 root_window_controllers
[1]->GetShelfLayoutManager()->visibility_state());
1419 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1420 #define MAYBE_SetAlignment DISABLED_SetAlignment
1422 #define MAYBE_SetAlignment SetAlignment
1425 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT, TOP).
1426 TEST_F(ShelfLayoutManagerTest
, MAYBE_SetAlignment
) {
1427 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1428 // Force an initial layout.
1429 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1430 shelf
->LayoutShelf();
1431 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1433 shelf
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
1434 gfx::Rect
shelf_bounds(
1435 GetShelfWidget()->GetWindowBoundsInScreen());
1436 const gfx::Screen
* screen
= Shell::GetScreen();
1437 gfx::Display display
=
1438 screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1439 ASSERT_NE(-1, display
.id());
1440 EXPECT_EQ(shelf
->GetIdealBounds().width(),
1441 display
.GetWorkAreaInsets().left());
1443 shelf_bounds
.width(),
1444 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1445 EXPECT_EQ(SHELF_ALIGNMENT_LEFT
, GetSystemTray()->shelf_alignment());
1446 StatusAreaWidget
* status_area_widget
= GetShelfWidget()->status_area_widget();
1447 gfx::Rect
status_bounds(status_area_widget
->GetWindowBoundsInScreen());
1448 EXPECT_GE(status_bounds
.width(),
1449 status_area_widget
->GetContentsView()->GetPreferredSize().width());
1450 EXPECT_EQ(shelf
->GetIdealBounds().width(),
1451 display
.GetWorkAreaInsets().left());
1452 EXPECT_EQ(0, display
.GetWorkAreaInsets().top());
1453 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
1454 EXPECT_EQ(0, display
.GetWorkAreaInsets().right());
1455 EXPECT_EQ(display
.bounds().x(), shelf_bounds
.x());
1456 EXPECT_EQ(display
.bounds().y(), shelf_bounds
.y());
1457 EXPECT_EQ(display
.bounds().height(), shelf_bounds
.height());
1458 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1459 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1460 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1461 display
.GetWorkAreaInsets().left());
1462 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
, display
.work_area().x());
1464 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1465 shelf
->SetAlignment(SHELF_ALIGNMENT_RIGHT
);
1466 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1467 shelf_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
1468 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1469 ASSERT_NE(-1, display
.id());
1470 EXPECT_EQ(shelf
->GetIdealBounds().width(),
1471 display
.GetWorkAreaInsets().right());
1472 EXPECT_GE(shelf_bounds
.width(),
1473 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1474 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT
, GetSystemTray()->shelf_alignment());
1475 status_bounds
= gfx::Rect(status_area_widget
->GetWindowBoundsInScreen());
1476 EXPECT_GE(status_bounds
.width(),
1477 status_area_widget
->GetContentsView()->GetPreferredSize().width());
1478 EXPECT_EQ(shelf
->GetIdealBounds().width(),
1479 display
.GetWorkAreaInsets().right());
1480 EXPECT_EQ(0, display
.GetWorkAreaInsets().top());
1481 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
1482 EXPECT_EQ(0, display
.GetWorkAreaInsets().left());
1483 EXPECT_EQ(display
.work_area().right(), shelf_bounds
.x());
1484 EXPECT_EQ(display
.bounds().y(), shelf_bounds
.y());
1485 EXPECT_EQ(display
.bounds().height(), shelf_bounds
.height());
1486 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1487 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1488 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1489 display
.GetWorkAreaInsets().right());
1490 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1491 display
.bounds().right() - display
.work_area().right());
1493 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1494 shelf
->SetAlignment(SHELF_ALIGNMENT_TOP
);
1495 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1496 shelf_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
1497 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1498 ASSERT_NE(-1, display
.id());
1499 EXPECT_EQ(shelf
->GetIdealBounds().height(),
1500 display
.GetWorkAreaInsets().top());
1501 EXPECT_GE(shelf_bounds
.height(),
1502 GetShelfWidget()->GetContentsView()->GetPreferredSize().height());
1503 EXPECT_EQ(SHELF_ALIGNMENT_TOP
, GetSystemTray()->shelf_alignment());
1504 status_bounds
= gfx::Rect(status_area_widget
->GetWindowBoundsInScreen());
1505 EXPECT_GE(status_bounds
.height(),
1506 status_area_widget
->GetContentsView()->GetPreferredSize().height());
1507 EXPECT_EQ(shelf
->GetIdealBounds().height(),
1508 display
.GetWorkAreaInsets().top());
1509 EXPECT_EQ(0, display
.GetWorkAreaInsets().right());
1510 EXPECT_EQ(0, display
.GetWorkAreaInsets().bottom());
1511 EXPECT_EQ(0, display
.GetWorkAreaInsets().left());
1512 EXPECT_EQ(display
.work_area().y(), shelf_bounds
.bottom());
1513 EXPECT_EQ(display
.bounds().x(), shelf_bounds
.x());
1514 EXPECT_EQ(display
.bounds().width(), shelf_bounds
.width());
1515 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1516 display
= screen
->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1517 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1518 display
.GetWorkAreaInsets().top());
1519 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize
,
1520 display
.work_area().y() - display
.bounds().y());
1523 TEST_F(ShelfLayoutManagerTest
, GestureEdgeSwipe
) {
1524 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1525 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1526 views::Widget
* widget
= new views::Widget
;
1527 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1528 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1529 params
.context
= CurrentContext();
1530 widget
->Init(params
);
1534 aura::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1536 aura::Window
* window
= widget
->GetNativeWindow();
1537 shelf
->LayoutShelf();
1539 gfx::Rect shelf_shown
= GetShelfWidget()->GetWindowBoundsInScreen();
1540 gfx::Rect bounds_shelf
= window
->bounds();
1542 // Edge swipe when SHELF_VISIBLE should not change visibility state.
1543 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1544 generator
.GestureEdgeSwipe();
1545 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1547 // Edge swipe when AUTO_HIDE_HIDDEN should change to AUTO_HIDE_SHOWN.
1548 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1549 shelf
->LayoutShelf();
1550 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1551 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1552 generator
.GestureEdgeSwipe();
1553 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1554 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1556 widget
->SetFullscreen(true);
1557 wm::GetWindowState(window
)->set_hide_shelf_when_fullscreen(false);
1558 shelf
->UpdateVisibilityState();
1560 // Edge swipe in fullscreen + AUTO_HIDE_HIDDEN should show the shelf and
1561 // remain fullscreen.
1562 EXPECT_TRUE(widget
->IsFullscreen());
1563 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1564 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1565 generator
.GestureEdgeSwipe();
1566 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1567 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1568 EXPECT_TRUE(widget
->IsFullscreen());
1571 // Test that starting the maximize mode does still allow the shelf to be made
1572 // visible when an (immersive mode) full screen app is running.
1573 TEST_F(ShelfLayoutManagerTest
, GestureEdgeSwipeInMaximizeMode
) {
1574 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1575 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1576 views::Widget
* widget
= new views::Widget
;
1577 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1578 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1579 params
.context
= CurrentContext();
1580 widget
->Init(params
);
1582 aura::Window
* window
= widget
->GetNativeWindow();
1583 wm::GetWindowState(window
)->set_hide_shelf_when_fullscreen(false);
1584 widget
->SetFullscreen(true);
1586 aura::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1588 // The maximize mode gets started.
1589 shelf
->OnMaximizeModeStarted();
1590 shelf
->LayoutShelf();
1591 shelf
->UpdateVisibilityState();
1593 // Edge swipe in fullscreen + AUTO_HIDE_HIDDEN should show the shelf and
1594 // remain fullscreen.
1595 EXPECT_TRUE(widget
->IsFullscreen());
1596 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1597 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1598 generator
.GestureEdgeSwipe();
1599 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1600 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1601 EXPECT_TRUE(widget
->IsFullscreen());
1605 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1606 #define MAYBE_GestureDrag DISABLED_GestureDrag
1608 #define MAYBE_GestureDrag GestureDrag
1611 TEST_F(ShelfLayoutManagerTest
, MAYBE_GestureDrag
) {
1612 // Slop is an implementation detail of gesture recognition, and complicates
1613 // these tests. Ignore it.
1614 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
1615 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1617 SCOPED_TRACE("BOTTOM");
1618 RunGestureDragTests(gfx::Vector2d(0, 120));
1622 SCOPED_TRACE("LEFT");
1623 shelf
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
1624 RunGestureDragTests(gfx::Vector2d(-120, 0));
1628 SCOPED_TRACE("RIGHT");
1629 shelf
->SetAlignment(SHELF_ALIGNMENT_RIGHT
);
1630 RunGestureDragTests(gfx::Vector2d(120, 0));
1634 TEST_F(ShelfLayoutManagerTest
, WindowVisibilityDisablesAutoHide
) {
1635 if (!SupportsMultipleDisplays())
1638 UpdateDisplay("800x600,800x600");
1639 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1640 shelf
->LayoutShelf();
1641 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1643 // Create a visible window so auto-hide behavior is enforced
1644 views::Widget
* dummy
= CreateTestWidget();
1646 // Window visible => auto hide behaves normally.
1647 shelf
->UpdateVisibilityState();
1648 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1650 // Window minimized => auto hide disabled.
1652 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1654 // Window closed => auto hide disabled.
1656 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1658 // Multiple window test
1659 views::Widget
* window1
= CreateTestWidget();
1660 views::Widget
* window2
= CreateTestWidget();
1662 // both visible => normal autohide
1663 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1665 // either minimzed => normal autohide
1666 window2
->Minimize();
1667 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1669 window1
->Minimize();
1670 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1672 // both minimized => disable auto hide
1673 window2
->Minimize();
1674 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1676 // Test moving windows to/from other display.
1678 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1679 // Move to second display.
1680 window2
->SetBounds(gfx::Rect(850, 50, 50, 50));
1681 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1682 // Move back to primary display.
1683 window2
->SetBounds(gfx::Rect(50, 50, 50, 50));
1684 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1687 // Test that the shelf animates back to its normal position upon a user
1688 // completing a gesture drag.
1689 TEST_F(ShelfLayoutManagerTest
, ShelfAnimatesWhenGestureComplete
) {
1690 if (!SupportsHostWindowResize())
1693 // Test the shelf animates back to its original visible bounds when it is
1694 // dragged when there are no visible windows.
1695 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1696 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1697 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1698 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1699 gfx::Rect visible_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
1701 // Enable animations so that we can make sure that they occur.
1702 ui::ScopedAnimationDurationScaleMode
regular_animations(
1703 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION
);
1705 aura::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1706 gfx::Rect shelf_bounds_in_screen
=
1707 GetShelfWidget()->GetWindowBoundsInScreen();
1708 gfx::Point
start(shelf_bounds_in_screen
.CenterPoint());
1709 gfx::Point
end(start
.x(), shelf_bounds_in_screen
.bottom());
1710 generator
.GestureScrollSequence(start
, end
,
1711 base::TimeDelta::FromMilliseconds(10), 5);
1712 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1713 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1715 ShelfAnimationWaiter
waiter(visible_bounds
);
1716 // Wait till the animation completes and check that it occurred.
1717 waiter
.WaitTillDoneAnimating();
1718 EXPECT_TRUE(waiter
.WasValidAnimation());
1721 // Create a visible window so auto-hide behavior is enforced.
1724 // Get the bounds of the shelf when it is hidden.
1725 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1726 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1727 gfx::Rect auto_hidden_bounds
= GetShelfWidget()->GetWindowBoundsInScreen();
1730 // Enable the animations so that we can make sure they do occur.
1731 ui::ScopedAnimationDurationScaleMode
regular_animations(
1732 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION
);
1735 GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
1736 gfx::Point
end(start
.x(), start
.y() - 100);
1737 aura::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1739 // Test that the shelf animates to the visible bounds after a swipe up on
1740 // the auto hidden shelf.
1741 generator
.GestureScrollSequence(start
, end
,
1742 base::TimeDelta::FromMilliseconds(10), 1);
1743 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1744 ShelfAnimationWaiter
waiter1(visible_bounds
);
1745 waiter1
.WaitTillDoneAnimating();
1746 EXPECT_TRUE(waiter1
.WasValidAnimation());
1748 // Test that the shelf animates to the auto hidden bounds after a swipe up
1749 // on the visible shelf.
1750 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1751 generator
.GestureScrollSequence(start
, end
,
1752 base::TimeDelta::FromMilliseconds(10), 1);
1753 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1754 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1755 ShelfAnimationWaiter
waiter2(auto_hidden_bounds
);
1756 waiter2
.WaitTillDoneAnimating();
1757 EXPECT_TRUE(waiter2
.WasValidAnimation());
1761 TEST_F(ShelfLayoutManagerTest
, GestureRevealsTrayBubble
) {
1762 if (!SupportsHostWindowResize())
1765 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1766 shelf
->LayoutShelf();
1768 // Create a visible window so auto-hide behavior is enforced.
1771 aura::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1772 SystemTray
* tray
= GetSystemTray();
1774 // First, make sure the shelf is visible.
1775 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1776 EXPECT_FALSE(tray
->HasSystemBubble());
1778 // Now, drag up on the tray to show the bubble.
1779 gfx::Point start
= GetShelfWidget()->status_area_widget()->
1780 GetWindowBoundsInScreen().CenterPoint();
1781 gfx::Point
end(start
.x(), start
.y() - 100);
1782 generator
.GestureScrollSequence(start
, end
,
1783 base::TimeDelta::FromMilliseconds(10), 1);
1784 EXPECT_TRUE(tray
->HasSystemBubble());
1785 tray
->CloseSystemBubble();
1786 RunAllPendingInMessageLoop();
1787 EXPECT_FALSE(tray
->HasSystemBubble());
1789 // Drag again, but only a small amount, and slowly. The bubble should not be
1791 end
.set_y(start
.y() - 30);
1792 generator
.GestureScrollSequence(start
, end
,
1793 base::TimeDelta::FromMilliseconds(500), 100);
1794 EXPECT_FALSE(tray
->HasSystemBubble());
1796 // Now, hide the shelf.
1797 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1799 // Start a drag from the bezel, and drag up to show both the shelf and the
1801 start
.set_y(start
.y() + 100);
1802 end
.set_y(start
.y() - 400);
1803 generator
.GestureScrollSequence(start
, end
,
1804 base::TimeDelta::FromMilliseconds(10), 1);
1805 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
1806 EXPECT_TRUE(tray
->HasSystemBubble());
1809 TEST_F(ShelfLayoutManagerTest
, ShelfFlickerOnTrayActivation
) {
1810 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1812 // Create a visible window so auto-hide behavior is enforced.
1815 // Turn on auto-hide for the shelf.
1816 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1817 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1818 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
1820 // Show the status menu. That should make the shelf visible again.
1821 Shell::GetInstance()->accelerator_controller()->PerformAction(
1822 SHOW_SYSTEM_TRAY_BUBBLE
, ui::Accelerator());
1823 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
1824 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN
, shelf
->auto_hide_state());
1825 EXPECT_TRUE(GetSystemTray()->HasSystemBubble());
1828 TEST_F(ShelfLayoutManagerTest
, WorkAreaChangeWorkspace
) {
1829 // Make sure the shelf is always visible.
1830 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1831 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1832 shelf
->LayoutShelf();
1834 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
1835 params
.bounds
= gfx::Rect(0, 0, 200, 200);
1836 params
.context
= CurrentContext();
1837 views::Widget
* widget_one
= CreateTestWidgetWithParams(params
);
1838 widget_one
->Maximize();
1840 views::Widget
* widget_two
= CreateTestWidgetWithParams(params
);
1841 widget_two
->Maximize();
1842 widget_two
->Activate();
1844 // Both windows are maximized. They should be of the same size.
1845 EXPECT_EQ(widget_one
->GetNativeWindow()->bounds().ToString(),
1846 widget_two
->GetNativeWindow()->bounds().ToString());
1847 int area_when_shelf_shown
=
1848 widget_one
->GetNativeWindow()->bounds().size().GetArea();
1850 // Now hide the shelf.
1851 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1853 // Both windows should be resized according to the shelf status.
1854 EXPECT_EQ(widget_one
->GetNativeWindow()->bounds().ToString(),
1855 widget_two
->GetNativeWindow()->bounds().ToString());
1856 // Resized to small.
1857 EXPECT_LT(area_when_shelf_shown
,
1858 widget_one
->GetNativeWindow()->bounds().size().GetArea());
1860 // Now show the shelf.
1861 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1863 // Again both windows should be of the same size.
1864 EXPECT_EQ(widget_one
->GetNativeWindow()->bounds().ToString(),
1865 widget_two
->GetNativeWindow()->bounds().ToString());
1866 EXPECT_EQ(area_when_shelf_shown
,
1867 widget_one
->GetNativeWindow()->bounds().size().GetArea());
1870 // Confirm that the shelf is dimmed only when content is maximized and
1871 // shelf is not autohidden.
1872 TEST_F(ShelfLayoutManagerTest
, Dimming
) {
1873 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1874 scoped_ptr
<aura::Window
> w1(CreateTestWindow());
1876 wm::ActivateWindow(w1
.get());
1878 // Normal window doesn't dim shelf.
1879 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
1880 ShelfWidget
* shelf
= GetShelfWidget();
1881 EXPECT_FALSE(shelf
->GetDimsShelf());
1883 // Maximized window does.
1884 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1885 EXPECT_TRUE(shelf
->GetDimsShelf());
1887 // Change back to normal stops dimming.
1888 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_NORMAL
);
1889 EXPECT_FALSE(shelf
->GetDimsShelf());
1891 // Changing back to maximized dims again.
1892 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1893 EXPECT_TRUE(shelf
->GetDimsShelf());
1895 // Changing shelf to autohide stops dimming.
1896 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1897 EXPECT_FALSE(shelf
->GetDimsShelf());
1900 // Make sure that the shelf will not hide if the mouse is between a bubble and
1902 TEST_F(ShelfLayoutManagerTest
, BubbleEnlargesShelfMouseHitArea
) {
1903 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
1904 StatusAreaWidget
* status_area_widget
=
1905 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
1906 SystemTray
* tray
= GetSystemTray();
1908 // Create a visible window so auto-hide behavior is enforced.
1911 shelf
->LayoutShelf();
1912 aura::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
1914 // Make two iterations - first without a message bubble which should make
1915 // the shelf disappear and then with a message bubble which should keep it
1917 for (int i
= 0; i
< 2; i
++) {
1918 // Make sure the shelf is visible and position the mouse over it. Then
1920 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
);
1921 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
1923 status_area_widget
->GetWindowBoundsInScreen().CenterPoint();
1924 generator
.MoveMouseTo(center
.x(), center
.y());
1925 shelf
->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1926 EXPECT_TRUE(shelf
->IsVisible());
1928 // In our first iteration we make sure there is no bubble.
1929 tray
->CloseSystemBubble();
1930 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
1932 // In our second iteration we show a bubble.
1933 TestItem
*item
= new TestItem
;
1934 tray
->AddTrayItem(item
);
1935 tray
->ShowNotificationView(item
);
1936 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
1938 // Move the pointer over the edge of the shelf.
1939 generator
.MoveMouseTo(
1940 center
.x(), status_area_widget
->GetWindowBoundsInScreen().y() - 8);
1941 shelf
->UpdateVisibilityState();
1943 EXPECT_TRUE(shelf
->IsVisible());
1944 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
1946 EXPECT_FALSE(shelf
->IsVisible());
1947 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
1952 TEST_F(ShelfLayoutManagerTest
, ShelfBackgroundColor
) {
1953 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget()->GetBackgroundType());
1955 scoped_ptr
<aura::Window
> w1(CreateTestWindow());
1957 wm::ActivateWindow(w1
.get());
1958 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget()->GetBackgroundType());
1959 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1960 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED
, GetShelfWidget()->GetBackgroundType());
1962 scoped_ptr
<aura::Window
> w2(CreateTestWindow());
1964 wm::ActivateWindow(w2
.get());
1965 // Overlaps with shelf.
1966 w2
->SetBounds(GetShelfLayoutManager()->GetIdealBounds());
1968 // Still background is 'maximized'.
1969 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED
, GetShelfWidget()->GetBackgroundType());
1971 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
1972 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP
, GetShelfWidget()->GetBackgroundType());
1973 w2
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MINIMIZED
);
1974 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget()->GetBackgroundType());
1976 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1977 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED
, GetShelfWidget()->GetBackgroundType());
1979 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget()->GetBackgroundType());
1982 // Verify that the shelf doesn't have the opaque background if it's auto-hide
1984 TEST_F(ShelfLayoutManagerTest
, ShelfBackgroundColorAutoHide
) {
1985 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT
, GetShelfWidget ()->GetBackgroundType());
1987 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
1988 scoped_ptr
<aura::Window
> w1(CreateTestWindow());
1990 wm::ActivateWindow(w1
.get());
1991 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP
, GetShelfWidget()->GetBackgroundType());
1992 w1
->SetProperty(aura::client::kShowStateKey
, ui::SHOW_STATE_MAXIMIZED
);
1993 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP
, GetShelfWidget()->GetBackgroundType());
1996 #if defined(OS_CHROMEOS)
1997 #define MAYBE_StatusAreaHitBoxCoversEdge StatusAreaHitBoxCoversEdge
1999 #define MAYBE_StatusAreaHitBoxCoversEdge DISABLED_StatusAreaHitBoxCoversEdge
2002 // Verify the hit bounds of the status area extend to the edge of the shelf.
2003 TEST_F(ShelfLayoutManagerTest
, MAYBE_StatusAreaHitBoxCoversEdge
) {
2004 UpdateDisplay("400x400");
2005 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
2006 StatusAreaWidget
* status_area_widget
=
2007 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
2008 aura::test::EventGenerator
generator(Shell::GetPrimaryRootWindow());
2009 generator
.MoveMouseTo(399,399);
2011 // Test bottom right pixel for bottom alignment.
2012 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2013 generator
.ClickLeftButton();
2014 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
2015 generator
.ClickLeftButton();
2016 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2018 // Test bottom right pixel for right alignment.
2019 shelf
->SetAlignment(SHELF_ALIGNMENT_RIGHT
);
2020 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2021 generator
.ClickLeftButton();
2022 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
2023 generator
.ClickLeftButton();
2024 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2026 // Test bottom left pixel for left alignment.
2027 generator
.MoveMouseTo(0, 399);
2028 shelf
->SetAlignment(SHELF_ALIGNMENT_LEFT
);
2029 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2030 generator
.ClickLeftButton();
2031 EXPECT_TRUE(status_area_widget
->IsMessageBubbleShown());
2032 generator
.ClickLeftButton();
2033 EXPECT_FALSE(status_area_widget
->IsMessageBubbleShown());
2036 // Tests that entering maximize mode resets auto-hide behaviour to be off by
2038 TEST_F(ShelfLayoutManagerTest
, MaximizeModeResetsAutohide
) {
2039 ShelfLayoutManager
* shelf
= GetShelfLayoutManager();
2040 shelf
->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
);
2041 views::Widget
* widget
= new views::Widget
;
2042 views::Widget::InitParams
params(views::Widget::InitParams::TYPE_WINDOW
);
2043 params
.bounds
= gfx::Rect(0, 0, 200, 200);
2044 params
.context
= CurrentContext();
2045 // Widget is now owned by the parent window.
2046 widget
->Init(params
);
2049 EXPECT_EQ(SHELF_AUTO_HIDE
, shelf
->visibility_state());
2050 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN
, shelf
->auto_hide_state());
2052 shelf
->OnMaximizeModeStarted();
2053 // LayoutShelf() forces the animation to completion
2054 shelf
->LayoutShelf();
2055 EXPECT_EQ(SHELF_VISIBLE
, shelf
->visibility_state());
2056 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
, shelf
->auto_hide_behavior());