Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ash / shelf / shelf_layout_manager_unittest.cc
blob58c712adcdef7f19bb598abd1741efe4c7bac146
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/window.h"
31 #include "ui/aura/window_event_dispatcher.h"
32 #include "ui/compositor/layer.h"
33 #include "ui/compositor/layer_animator.h"
34 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
35 #include "ui/events/gestures/gesture_configuration.h"
36 #include "ui/events/test/event_generator.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"
44 #if defined(OS_WIN)
45 #include "base/win/windows_version.h"
46 #endif
48 namespace ash {
49 namespace {
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 {
71 public:
72 explicit ShelfAnimationWaiter(const gfx::Rect& target_bounds)
73 : target_bounds_(target_bounds),
74 animation_steps_(0),
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())
86 done_waiting_ = true;
87 else
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;
96 private:
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 {
111 if (done_waiting_)
112 return;
114 ++animation_steps_;
115 if (IsDoneAnimating()) {
116 done_waiting_ = true;
117 base::MessageLoop::current()->Quit();
121 gfx::Rect target_bounds_;
122 int animation_steps_;
123 bool done_waiting_;
125 DISALLOW_COPY_AND_ASSIGN(ShelfAnimationWaiter);
128 class ShelfDragCallback {
129 public:
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)
142 return;
144 if (type == ui::ET_GESTURE_SCROLL_BEGIN) {
145 scroll_ = gfx::Vector2dF();
146 was_visible_on_drag_start_ = GetShelfLayoutManager()->IsVisible();
147 return;
150 // The state of the shelf at the end of the gesture is tested separately.
151 if (type == ui::ET_GESTURE_SCROLL_END)
152 return;
154 if (type == ui::ET_GESTURE_SCROLL_UPDATE)
155 scroll_.Add(delta);
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(
179 scroll_.y(),
180 scroll_.x());
181 bool increasing_drag =
182 GetShelfLayoutManager()->SelectValueForShelfAlignment(
183 scroll_delta < 0,
184 scroll_delta > 0,
185 scroll_delta < 0,
186 scroll_delta > 0);
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));
203 } else {
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));
210 } else {
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));
216 } else {
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));
224 private:
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 {
234 public:
235 ShelfLayoutObserverTest()
236 : changed_auto_hide_state_(false) {
239 virtual ~ShelfLayoutObserverTest() {}
241 bool changed_auto_hide_state() const { return changed_auto_hide_state_; }
243 private:
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 {
256 public:
257 TestItem()
258 : SystemTrayItem(GetSystemTray()),
259 tray_view_(NULL),
260 default_view_(NULL),
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")));
269 return tray_view_;
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 {
294 tray_view_ = NULL;
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_; }
317 private:
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);
326 } // namespace
328 class ShelfLayoutManagerTest : public ash::test::AshTestBase {
329 public:
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);
347 return window;
350 views::Widget* CreateTestWidgetWithParams(
351 const views::Widget::InitParams& params) {
352 views::Widget* out = new views::Widget;
353 out->Init(params);
354 out->Show();
355 return out;
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);
376 private:
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);
388 widget->Show();
389 widget->Maximize();
391 // The time delta should be large enough to prevent accidental fling creation.
392 const base::TimeDelta kTimeDelta = base::TimeDelta::FromMilliseconds(100);
394 aura::Window* window = widget->GetNativeWindow();
395 shelf->LayoutShelf();
397 gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen();
398 gfx::Rect bounds_shelf = window->bounds();
399 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
401 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
402 shelf->LayoutShelf();
403 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
405 gfx::Rect bounds_noshelf = window->bounds();
406 gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen();
408 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
409 shelf->LayoutShelf();
411 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
412 const int kNumScrollSteps = 4;
413 ShelfDragCallback handler(shelf_hidden, shelf_shown);
415 // Swipe up on the shelf. This should not change any state.
416 gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
417 gfx::Point end = start + delta;
419 // Swipe down on the shelf to hide it.
420 generator.GestureScrollSequenceWithCallback(
421 start,
422 end,
423 kTimeDelta,
424 kNumScrollSteps,
425 base::Bind(&ShelfDragCallback::ProcessScroll,
426 base::Unretained(&handler)));
427 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
428 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
429 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
430 EXPECT_NE(bounds_shelf.ToString(), window->bounds().ToString());
431 EXPECT_NE(shelf_shown.ToString(),
432 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
434 // Swipe up to show the shelf.
435 generator.GestureScrollSequenceWithCallback(
436 end,
437 start,
438 kTimeDelta,
439 kNumScrollSteps,
440 base::Bind(&ShelfDragCallback::ProcessScroll,
441 base::Unretained(&handler)));
442 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
443 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
444 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
445 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
446 GetShelfWidget()->GetWindowBoundsInScreen());
447 EXPECT_EQ(shelf_shown.ToString(),
448 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
450 // Swipe up again. The shelf should hide.
451 end = start - delta;
452 generator.GestureScrollSequenceWithCallback(
453 start,
454 end,
455 kTimeDelta,
456 kNumScrollSteps,
457 base::Bind(&ShelfDragCallback::ProcessScroll,
458 base::Unretained(&handler)));
459 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
460 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
461 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
462 EXPECT_EQ(shelf_hidden.ToString(),
463 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
465 // Swipe up yet again to show it.
466 end = start + delta;
467 generator.GestureScrollSequenceWithCallback(
468 end,
469 start,
470 kTimeDelta,
471 kNumScrollSteps,
472 base::Bind(&ShelfDragCallback::ProcessScroll,
473 base::Unretained(&handler)));
475 // Swipe down very little. It shouldn't change any state.
476 if (GetShelfLayoutManager()->IsHorizontalAlignment())
477 end.set_y(start.y() + shelf_shown.height() * 3 / 10);
478 else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
479 end.set_x(start.x() - shelf_shown.width() * 3 / 10);
480 else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
481 end.set_x(start.x() + shelf_shown.width() * 3 / 10);
482 generator.GestureScrollSequence(start, end, kTimeDelta, 5);
483 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
484 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
485 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
486 EXPECT_EQ(shelf_shown.ToString(),
487 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
489 // Swipe down again to hide.
490 end = start + delta;
491 generator.GestureScrollSequenceWithCallback(
492 start,
493 end,
494 kTimeDelta,
495 kNumScrollSteps,
496 base::Bind(&ShelfDragCallback::ProcessScroll,
497 base::Unretained(&handler)));
498 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
499 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
500 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
501 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
502 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
503 EXPECT_EQ(shelf_hidden.ToString(),
504 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
506 // Swipe up in extended hit region to show it.
507 gfx::Point extended_start = start;
508 if (GetShelfLayoutManager()->IsHorizontalAlignment())
509 extended_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().y() -1);
510 else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
511 extended_start.set_x(
512 GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
513 else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
514 extended_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
515 end = extended_start - delta;
516 generator.GestureScrollSequenceWithCallback(
517 extended_start,
518 end,
519 kTimeDelta,
520 kNumScrollSteps,
521 base::Bind(&ShelfDragCallback::ProcessScroll,
522 base::Unretained(&handler)));
523 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
524 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
525 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
526 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
527 GetShelfWidget()->GetWindowBoundsInScreen());
528 EXPECT_EQ(shelf_shown.ToString(),
529 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
531 // Swipe down again to hide.
532 end = start + delta;
533 generator.GestureScrollSequenceWithCallback(
534 start,
535 end,
536 kTimeDelta,
537 kNumScrollSteps,
538 base::Bind(&ShelfDragCallback::ProcessScroll,
539 base::Unretained(&handler)));
540 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
541 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
542 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
543 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
544 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
545 EXPECT_EQ(shelf_hidden.ToString(),
546 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
548 // Swipe up outside the hit area. This should not change anything.
549 gfx::Point outside_start = gfx::Point(
550 (GetShelfWidget()->GetWindowBoundsInScreen().x() +
551 GetShelfWidget()->GetWindowBoundsInScreen().right())/2,
552 GetShelfWidget()->GetWindowBoundsInScreen().y() - 50);
553 end = outside_start + delta;
554 generator.GestureScrollSequence(
555 outside_start, end, kTimeDelta, kNumScrollSteps);
556 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
557 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
558 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
559 EXPECT_EQ(shelf_hidden.ToString(),
560 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
562 // Swipe up from below the shelf where a bezel would be, this should show the
563 // shelf.
564 gfx::Point below_start = start;
565 if (GetShelfLayoutManager()->IsHorizontalAlignment())
566 below_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() + 1);
567 else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
568 below_start.set_x(
569 GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
570 else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
571 below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
572 end = below_start - delta;
573 generator.GestureScrollSequence(
574 below_start, end, kTimeDelta, kNumScrollSteps);
575 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
576 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
577 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
578 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
579 GetShelfWidget()->GetWindowBoundsInScreen());
580 EXPECT_EQ(shelf_shown.ToString(),
581 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
583 // Swipe down again to hide.
584 end = start + delta;
585 generator.GestureScrollSequenceWithCallback(
586 start,
587 end,
588 kTimeDelta,
589 kNumScrollSteps,
590 base::Bind(&ShelfDragCallback::ProcessScroll,
591 base::Unretained(&handler)));
592 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
593 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
594 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
595 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
596 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
597 EXPECT_EQ(shelf_hidden.ToString(),
598 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
600 // Put |widget| into fullscreen. Set the shelf to be auto hidden when |widget|
601 // is fullscreen. (eg browser immersive fullscreen).
602 widget->SetFullscreen(true);
603 wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(false);
604 shelf->UpdateVisibilityState();
606 gfx::Rect bounds_fullscreen = window->bounds();
607 EXPECT_TRUE(widget->IsFullscreen());
608 EXPECT_NE(bounds_noshelf.ToString(), bounds_fullscreen.ToString());
610 // Swipe up. This should show the shelf.
611 end = below_start - delta;
612 generator.GestureScrollSequenceWithCallback(
613 below_start,
614 end,
615 kTimeDelta,
616 kNumScrollSteps,
617 base::Bind(&ShelfDragCallback::ProcessScroll,
618 base::Unretained(&handler)));
619 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
620 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
621 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
622 EXPECT_EQ(shelf_shown.ToString(),
623 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
624 EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
626 // Swipe up again. This should hide the shelf.
627 generator.GestureScrollSequenceWithCallback(
628 below_start,
629 end,
630 kTimeDelta,
631 kNumScrollSteps,
632 base::Bind(&ShelfDragCallback::ProcessScroll,
633 base::Unretained(&handler)));
634 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
635 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
636 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
637 EXPECT_EQ(shelf_hidden.ToString(),
638 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
639 EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
641 // Set the shelf to be hidden when |widget| is fullscreen. (eg tab fullscreen
642 // with or without immersive browser fullscreen).
643 wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(true);
644 shelf->UpdateVisibilityState();
645 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
646 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
648 // Swipe-up. This should not change anything.
649 end = start - delta;
650 generator.GestureScrollSequenceWithCallback(
651 below_start,
652 end,
653 kTimeDelta,
654 kNumScrollSteps,
655 base::Bind(&ShelfDragCallback::ProcessScroll,
656 base::Unretained(&handler)));
657 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
658 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
659 EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
661 // Close actually, otherwise further event may be affected since widget
662 // is fullscreen status.
663 widget->Close();
664 RunAllPendingInMessageLoop();
666 // The shelf should be shown because there are no more visible windows.
667 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
668 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
669 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
671 // Swipe-up to hide. This should have no effect because there are no visible
672 // windows.
673 end = below_start - delta;
674 generator.GestureScrollSequenceWithCallback(
675 below_start,
676 end,
677 kTimeDelta,
678 kNumScrollSteps,
679 base::Bind(&ShelfDragCallback::ProcessScroll,
680 base::Unretained(&handler)));
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());
686 // Need to be implemented. http://crbug.com/111279.
687 #if defined(OS_WIN)
688 #define MAYBE_SetVisible DISABLED_SetVisible
689 #else
690 #define MAYBE_SetVisible SetVisible
691 #endif
692 // Makes sure SetVisible updates work area and widget appropriately.
693 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) {
694 ShelfWidget* shelf = GetShelfWidget();
695 ShelfLayoutManager* manager = shelf->shelf_layout_manager();
696 // Force an initial layout.
697 manager->LayoutShelf();
698 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
700 gfx::Rect status_bounds(
701 shelf->status_area_widget()->GetWindowBoundsInScreen());
702 gfx::Rect shelf_bounds(
703 shelf->GetWindowBoundsInScreen());
704 int shelf_height = manager->GetIdealBounds().height();
705 gfx::Screen* screen = Shell::GetScreen();
706 gfx::Display display = screen->GetDisplayNearestWindow(
707 Shell::GetPrimaryRootWindow());
708 ASSERT_NE(-1, display.id());
709 // Bottom inset should be the max of widget heights.
710 EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
712 // Hide the shelf.
713 SetState(manager, SHELF_HIDDEN);
714 // Run the animation to completion.
715 StepWidgetLayerAnimatorToEnd(shelf);
716 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget());
717 EXPECT_EQ(SHELF_HIDDEN, manager->visibility_state());
718 display = screen->GetDisplayNearestWindow(
719 Shell::GetPrimaryRootWindow());
721 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
723 // Make sure the bounds of the two widgets changed.
724 EXPECT_GE(shelf->GetNativeView()->bounds().y(),
725 screen->GetPrimaryDisplay().bounds().bottom());
726 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(),
727 screen->GetPrimaryDisplay().bounds().bottom());
729 // And show it again.
730 SetState(manager, SHELF_VISIBLE);
731 // Run the animation to completion.
732 StepWidgetLayerAnimatorToEnd(shelf);
733 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget());
734 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
735 display = screen->GetDisplayNearestWindow(
736 Shell::GetPrimaryRootWindow());
737 EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
739 // Make sure the bounds of the two widgets changed.
740 shelf_bounds = shelf->GetNativeView()->bounds();
741 EXPECT_LT(shelf_bounds.y(), screen->GetPrimaryDisplay().bounds().bottom());
742 status_bounds = shelf->status_area_widget()->GetNativeView()->bounds();
743 EXPECT_LT(status_bounds.y(),
744 screen->GetPrimaryDisplay().bounds().bottom());
747 // Makes sure shelf alignment is correct for lock screen.
748 TEST_F(ShelfLayoutManagerTest, SideAlignmentInteractionWithLockScreen) {
749 ShelfLayoutManager* manager = GetShelfWidget()->shelf_layout_manager();
750 manager->SetAlignment(SHELF_ALIGNMENT_LEFT);
751 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
752 Shell::GetInstance()->session_state_delegate()->LockScreen();
753 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, manager->GetAlignment());
754 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
755 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
758 // Makes sure LayoutShelf invoked while animating cleans things up.
759 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
760 ShelfWidget* shelf = GetShelfWidget();
761 // Force an initial layout.
762 shelf->shelf_layout_manager()->LayoutShelf();
763 EXPECT_EQ(SHELF_VISIBLE, shelf->shelf_layout_manager()->visibility_state());
765 // Hide the shelf.
766 SetState(shelf->shelf_layout_manager(), SHELF_HIDDEN);
767 shelf->shelf_layout_manager()->LayoutShelf();
768 EXPECT_EQ(SHELF_HIDDEN, shelf->shelf_layout_manager()->visibility_state());
769 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow(
770 Shell::GetPrimaryRootWindow());
771 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
773 // Make sure the bounds of the two widgets changed.
774 EXPECT_GE(shelf->GetNativeView()->bounds().y(),
775 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
776 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(),
777 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
780 // Test that switching to a different visibility state does not restart the
781 // shelf show / hide animation if it is already running. (crbug.com/250918)
782 TEST_F(ShelfLayoutManagerTest, SetStateWhileAnimating) {
783 ShelfWidget* shelf = GetShelfWidget();
784 SetState(shelf->shelf_layout_manager(), SHELF_VISIBLE);
785 gfx::Rect initial_shelf_bounds = shelf->GetWindowBoundsInScreen();
786 gfx::Rect initial_status_bounds =
787 shelf->status_area_widget()->GetWindowBoundsInScreen();
789 ui::ScopedAnimationDurationScaleMode normal_animation_duration(
790 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
791 SetState(shelf->shelf_layout_manager(), SHELF_HIDDEN);
792 SetState(shelf->shelf_layout_manager(), SHELF_VISIBLE);
794 gfx::Rect current_shelf_bounds = shelf->GetWindowBoundsInScreen();
795 gfx::Rect current_status_bounds =
796 shelf->status_area_widget()->GetWindowBoundsInScreen();
798 const int small_change = initial_shelf_bounds.height() / 2;
799 EXPECT_LE(
800 std::abs(initial_shelf_bounds.height() - current_shelf_bounds.height()),
801 small_change);
802 EXPECT_LE(
803 std::abs(initial_status_bounds.height() - current_status_bounds.height()),
804 small_change);
807 // Makes sure the shelf is sized when the status area changes size.
808 TEST_F(ShelfLayoutManagerTest, ShelfUpdatedWhenStatusAreaChangesSize) {
809 Shelf* shelf = Shelf::ForPrimaryDisplay();
810 ASSERT_TRUE(shelf);
811 ShelfWidget* shelf_widget = GetShelfWidget();
812 ASSERT_TRUE(shelf_widget);
813 ASSERT_TRUE(shelf_widget->status_area_widget());
814 shelf_widget->status_area_widget()->SetBounds(
815 gfx::Rect(0, 0, 200, 200));
816 EXPECT_EQ(200, shelf_widget->GetContentsView()->width() -
817 test::ShelfTestAPI(shelf).shelf_view()->width());
821 #if defined(OS_WIN)
822 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
823 #define MAYBE_AutoHide DISABLED_AutoHide
824 #else
825 #define MAYBE_AutoHide AutoHide
826 #endif
828 // Various assertions around auto-hide.
829 TEST_F(ShelfLayoutManagerTest, MAYBE_AutoHide) {
830 aura::Window* root = Shell::GetPrimaryRootWindow();
831 ui::test::EventGenerator generator(root, root);
832 generator.MoveMouseTo(0, 0);
834 ShelfLayoutManager* shelf = GetShelfLayoutManager();
835 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
836 views::Widget* widget = new views::Widget;
837 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
838 params.bounds = gfx::Rect(0, 0, 200, 200);
839 params.context = CurrentContext();
840 // Widget is now owned by the parent window.
841 widget->Init(params);
842 widget->Maximize();
843 widget->Show();
844 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
845 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
847 // LayoutShelf() forces the animation to completion, at which point the
848 // shelf should go off the screen.
849 shelf->LayoutShelf();
850 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
851 GetShelfWidget()->GetWindowBoundsInScreen().y());
852 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
853 Shell::GetScreen()->GetDisplayNearestWindow(
854 root).work_area().bottom());
856 // Move the mouse to the bottom of the screen.
857 generator.MoveMouseTo(0, root->bounds().bottom() - 1);
859 // Shelf should be shown again (but it shouldn't have changed the work area).
860 SetState(shelf, SHELF_AUTO_HIDE);
861 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
862 shelf->LayoutShelf();
863 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(),
864 GetShelfWidget()->GetWindowBoundsInScreen().y());
865 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
866 Shell::GetScreen()->GetDisplayNearestWindow(
867 root).work_area().bottom());
869 // Move mouse back up.
870 generator.MoveMouseTo(0, 0);
871 SetState(shelf, SHELF_AUTO_HIDE);
872 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
873 shelf->LayoutShelf();
874 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
875 GetShelfWidget()->GetWindowBoundsInScreen().y());
877 // Drag mouse to bottom of screen.
878 generator.PressLeftButton();
879 generator.MoveMouseTo(0, root->bounds().bottom() - 1);
880 UpdateAutoHideStateNow();
881 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
883 generator.ReleaseLeftButton();
884 generator.MoveMouseTo(1, root->bounds().bottom() - 1);
885 UpdateAutoHideStateNow();
886 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
887 generator.PressLeftButton();
888 generator.MoveMouseTo(1, root->bounds().bottom() - 1);
889 UpdateAutoHideStateNow();
890 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
893 // Test the behavior of the shelf when it is auto hidden and it is on the
894 // boundary between the primary and the secondary display.
895 TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnScreenBoundary) {
896 if (!SupportsMultipleDisplays())
897 return;
899 UpdateDisplay("800x600,800x600");
900 DisplayLayout display_layout(DisplayLayout::RIGHT, 0);
901 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
902 display_layout);
903 // Put the primary monitor's shelf on the display boundary.
904 ShelfLayoutManager* shelf = GetShelfLayoutManager();
905 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
907 // Create a window because the shelf is always shown when no windows are
908 // visible.
909 CreateTestWidget();
911 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
912 ASSERT_EQ(root_windows[0],
913 GetShelfWidget()->GetNativeWindow()->GetRootWindow());
915 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
916 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
918 int right_edge = root_windows[0]->GetBoundsInScreen().right() - 1;
919 int y = root_windows[0]->GetBoundsInScreen().y();
921 // Start off the mouse nowhere near the shelf; the shelf should be hidden.
922 ui::test::EventGenerator& generator(GetEventGenerator());
923 generator.MoveMouseTo(right_edge - 50, y);
924 UpdateAutoHideStateNow();
925 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
927 // Moving the mouse over the light bar (but not to the edge of the screen)
928 // should show the shelf.
929 generator.MoveMouseTo(right_edge - 1, y);
930 UpdateAutoHideStateNow();
931 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
932 EXPECT_EQ(right_edge - 1, Shell::GetScreen()->GetCursorScreenPoint().x());
934 // Moving the mouse off the light bar should hide the shelf.
935 generator.MoveMouseTo(right_edge - 50, y);
936 UpdateAutoHideStateNow();
937 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
939 // Moving the mouse to the right edge of the screen crossing the light bar
940 // should show the shelf despite the mouse cursor getting warped to the
941 // secondary display.
942 generator.MoveMouseTo(right_edge - 1, y);
943 generator.MoveMouseTo(right_edge, y);
944 UpdateAutoHideStateNow();
945 EXPECT_NE(right_edge - 1, Shell::GetScreen()->GetCursorScreenPoint().x());
946 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
948 // Hide the shelf.
949 generator.MoveMouseTo(right_edge - 50, y);
950 UpdateAutoHideStateNow();
951 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
953 // Moving the mouse to the right edge of the screen crossing the light bar and
954 // overshooting by a lot should keep the shelf hidden.
955 generator.MoveMouseTo(right_edge - 1, y);
956 generator.MoveMouseTo(right_edge + 50, y);
957 UpdateAutoHideStateNow();
958 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
960 // Moving the mouse to the right edge of the screen crossing the light bar and
961 // overshooting a bit should show the shelf.
962 generator.MoveMouseTo(right_edge - 1, y);
963 generator.MoveMouseTo(right_edge + 2, y);
964 UpdateAutoHideStateNow();
965 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
967 // Keeping the mouse close to the left edge of the secondary display after the
968 // shelf is shown should keep the shelf shown.
969 generator.MoveMouseTo(right_edge + 2, y + 1);
970 UpdateAutoHideStateNow();
971 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
973 // Moving the mouse far from the left edge of the secondary display should
974 // hide the shelf.
975 generator.MoveMouseTo(right_edge + 50, y);
976 UpdateAutoHideStateNow();
977 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
979 // Moving to the left edge of the secondary display without first crossing
980 // the primary display's right aligned shelf first should not show the shelf.
981 generator.MoveMouseTo(right_edge + 2, y);
982 UpdateAutoHideStateNow();
983 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
986 // Assertions around the lock screen showing.
987 TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
988 // Since ShelfLayoutManager queries for mouse location, move the mouse so
989 // it isn't over the shelf.
990 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
991 gfx::Point());
992 generator.MoveMouseTo(0, 0);
994 ShelfLayoutManager* shelf = GetShelfLayoutManager();
995 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
996 views::Widget* widget = new views::Widget;
997 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
998 params.bounds = gfx::Rect(0, 0, 200, 200);
999 params.context = CurrentContext();
1000 // Widget is now owned by the parent window.
1001 widget->Init(params);
1002 widget->Maximize();
1003 widget->Show();
1004 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1005 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1007 aura::Window* root = Shell::GetPrimaryRootWindow();
1008 // LayoutShelf() forces the animation to completion, at which point the
1009 // shelf should go off the screen.
1010 shelf->LayoutShelf();
1011 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
1012 GetShelfWidget()->GetWindowBoundsInScreen().y());
1014 aura::Window* lock_container = Shell::GetContainer(
1015 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer);
1017 views::Widget* lock_widget = new views::Widget;
1018 views::Widget::InitParams lock_params(
1019 views::Widget::InitParams::TYPE_WINDOW);
1020 lock_params.bounds = gfx::Rect(0, 0, 200, 200);
1021 params.context = CurrentContext();
1022 lock_params.parent = lock_container;
1023 // Widget is now owned by the parent window.
1024 lock_widget->Init(lock_params);
1025 lock_widget->Maximize();
1026 lock_widget->Show();
1028 // Lock the screen.
1029 Shell::GetInstance()->session_state_delegate()->LockScreen();
1030 shelf->UpdateVisibilityState();
1031 // Showing a widget in the lock screen should force the shelf to be visibile.
1032 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1034 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
1035 shelf->UpdateVisibilityState();
1036 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1039 // Assertions around SetAutoHideBehavior.
1040 TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) {
1041 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1042 // it isn't over the shelf.
1043 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1044 gfx::Point());
1045 generator.MoveMouseTo(0, 0);
1047 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1048 views::Widget* widget = new views::Widget;
1049 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1050 params.bounds = gfx::Rect(0, 0, 200, 200);
1051 params.context = CurrentContext();
1052 // Widget is now owned by the parent window.
1053 widget->Init(params);
1054 widget->Show();
1055 aura::Window* window = widget->GetNativeWindow();
1056 gfx::Rect display_bounds(
1057 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
1059 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1060 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1062 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1063 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1065 widget->Maximize();
1066 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1067 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1068 window).work_area().bottom(),
1069 widget->GetWorkAreaBoundsInScreen().bottom());
1071 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1072 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1073 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1074 window).work_area().bottom(),
1075 widget->GetWorkAreaBoundsInScreen().bottom());
1077 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1078 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1079 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1080 window).work_area().bottom(),
1081 widget->GetWorkAreaBoundsInScreen().bottom());
1084 // Basic assertions around the dimming of the shelf.
1085 TEST_F(ShelfLayoutManagerTest, TestDimmingBehavior) {
1086 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1087 // it isn't over the shelf.
1088 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1089 gfx::Point());
1090 generator.MoveMouseTo(0, 0);
1092 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1093 shelf->shelf_widget()->DisableDimmingAnimationsForTest();
1095 views::Widget* widget = new views::Widget;
1096 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1097 params.bounds = gfx::Rect(0, 0, 200, 200);
1098 params.context = CurrentContext();
1099 // Widget is now owned by the parent window.
1100 widget->Init(params);
1101 widget->Show();
1102 aura::Window* window = widget->GetNativeWindow();
1103 gfx::Rect display_bounds(
1104 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
1106 gfx::Point off_shelf = display_bounds.CenterPoint();
1107 gfx::Point on_shelf =
1108 shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1110 // Test there is no dimming object active at this point.
1111 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1112 EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
1113 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1114 EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
1116 // After maximization, the shelf should be visible and the dimmer created.
1117 widget->Maximize();
1119 on_shelf = shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1120 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1122 // Moving the mouse off the shelf should dim the bar.
1123 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1124 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1126 // Adding touch events outside the shelf should still keep the shelf in
1127 // dimmed state.
1128 generator.PressTouch();
1129 generator.MoveTouch(off_shelf);
1130 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1131 // Move the touch into the shelf area should undim.
1132 generator.MoveTouch(on_shelf);
1133 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1134 generator.ReleaseTouch();
1135 // And a release dims again.
1136 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1138 // Moving the mouse on the shelf should undim the bar.
1139 generator.MoveMouseTo(on_shelf);
1140 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1142 // No matter what the touch events do, the shelf should stay undimmed.
1143 generator.PressTouch();
1144 generator.MoveTouch(off_shelf);
1145 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1146 generator.MoveTouch(on_shelf);
1147 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1148 generator.MoveTouch(off_shelf);
1149 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1150 generator.MoveTouch(on_shelf);
1151 generator.ReleaseTouch();
1153 // After restore, the dimming object should be deleted again.
1154 widget->Restore();
1155 EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
1158 // Assertions around the dimming of the shelf in conjunction with menus.
1159 TEST_F(ShelfLayoutManagerTest, TestDimmingBehaviorWithMenus) {
1160 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1161 // it isn't over the shelf.
1162 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1163 gfx::Point());
1164 generator.MoveMouseTo(0, 0);
1166 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1167 shelf->shelf_widget()->DisableDimmingAnimationsForTest();
1169 views::Widget* widget = new views::Widget;
1170 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1171 params.bounds = gfx::Rect(0, 0, 200, 200);
1172 params.context = CurrentContext();
1173 // Widget is now owned by the parent window.
1174 widget->Init(params);
1175 widget->Show();
1176 aura::Window* window = widget->GetNativeWindow();
1177 gfx::Rect display_bounds(
1178 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
1180 // After maximization, the shelf should be visible and the dimmer created.
1181 widget->Maximize();
1183 gfx::Point off_shelf = display_bounds.CenterPoint();
1184 gfx::Point on_shelf =
1185 shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1187 // Moving the mouse on the shelf should undim the bar.
1188 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1189 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1191 // Simulate a menu opening.
1192 shelf->shelf_widget()->ForceUndimming(true);
1194 // Moving the mouse off the shelf should not dim the bar.
1195 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1196 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1198 // No matter what the touch events do, the shelf should stay undimmed.
1199 generator.PressTouch();
1200 generator.MoveTouch(off_shelf);
1201 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1202 generator.MoveTouch(on_shelf);
1203 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1204 generator.MoveTouch(off_shelf);
1205 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1206 generator.ReleaseTouch();
1207 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1209 // "Closing the menu" should now turn off the menu since no event is inside
1210 // the shelf any longer.
1211 shelf->shelf_widget()->ForceUndimming(false);
1212 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1214 // Moving the mouse again on the shelf which should undim the bar again.
1215 // This time we check that the bar stays undimmed when the mouse remains on
1216 // the bar and the "menu gets closed".
1217 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1218 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1219 shelf->shelf_widget()->ForceUndimming(true);
1220 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1221 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1222 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1223 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1224 shelf->shelf_widget()->ForceUndimming(true);
1225 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1228 // Verifies the shelf is visible when status/shelf is focused.
1229 TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrShelfFocused) {
1230 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1231 // it isn't over the shelf.
1232 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1233 gfx::Point());
1234 generator.MoveMouseTo(0, 0);
1236 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1237 views::Widget* widget = new views::Widget;
1238 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1239 params.bounds = gfx::Rect(0, 0, 200, 200);
1240 params.context = CurrentContext();
1241 // Widget is now owned by the parent window.
1242 widget->Init(params);
1243 widget->Show();
1244 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1245 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1246 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1248 // Focus the shelf. Have to go through the focus cycler as normal focus
1249 // requests to it do nothing.
1250 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
1251 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1253 widget->Activate();
1254 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1256 // Trying to activate the status should fail, since we only allow activating
1257 // it when the user is using the keyboard (i.e. through FocusCycler).
1258 GetShelfWidget()->status_area_widget()->Activate();
1259 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1261 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
1262 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1265 // Makes sure shelf will be visible when app list opens as shelf is in
1266 // SHELF_VISIBLE state,and toggling app list won't change shelf
1267 // visibility state.
1268 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) {
1269 Shell* shell = Shell::GetInstance();
1270 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1271 shelf->LayoutShelf();
1272 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1274 // Create a normal unmaximized windowm shelf should be visible.
1275 aura::Window* window = CreateTestWindow();
1276 window->SetBounds(gfx::Rect(0, 0, 100, 100));
1277 window->Show();
1278 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1279 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1281 // Show app list and the shelf stays visible.
1282 shell->ShowAppList(NULL);
1283 EXPECT_TRUE(shell->GetAppListTargetVisibility());
1284 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1286 // Hide app list and the shelf stays visible.
1287 shell->DismissAppList();
1288 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1289 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1292 // Makes sure shelf will be shown with SHELF_AUTO_HIDE_SHOWN state
1293 // when app list opens as shelf is in SHELF_AUTO_HIDE state, and
1294 // toggling app list won't change shelf visibility state.
1295 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) {
1296 Shell* shell = Shell::GetInstance();
1297 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1298 shelf->LayoutShelf();
1299 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1301 // Create a window and show it in maximized state.
1302 aura::Window* window = CreateTestWindow();
1303 window->SetBounds(gfx::Rect(0, 0, 100, 100));
1304 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1305 window->Show();
1306 wm::ActivateWindow(window);
1308 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1309 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1311 // Show app list.
1312 shell->ShowAppList(NULL);
1313 // The shelf's auto hide state won't be changed until the timer fires, so
1314 // calling shell->UpdateShelfVisibility() is kind of manually helping it to
1315 // update the state.
1316 shell->UpdateShelfVisibility();
1317 EXPECT_TRUE(shell->GetAppListTargetVisibility());
1318 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1319 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1321 // Hide app list.
1322 shell->DismissAppList();
1323 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1324 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1327 // Makes sure shelf will be hidden when app list opens as shelf is in HIDDEN
1328 // state, and toggling app list won't change shelf visibility state.
1329 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfHiddenState) {
1330 Shell* shell = Shell::GetInstance();
1331 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1332 // For shelf to be visible, app list is not open in initial state.
1333 shelf->LayoutShelf();
1335 // Create a window and make it full screen.
1336 aura::Window* window = CreateTestWindow();
1337 window->SetBounds(gfx::Rect(0, 0, 100, 100));
1338 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
1339 window->Show();
1340 wm::ActivateWindow(window);
1342 // App list and shelf is not shown.
1343 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1344 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1346 // Show app list.
1347 shell->ShowAppList(NULL);
1348 EXPECT_TRUE(shell->GetAppListTargetVisibility());
1349 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1351 // Hide app list.
1352 shell->DismissAppList();
1353 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1354 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1357 // Tests that the shelf is only hidden for a fullscreen window at the front and
1358 // toggles visibility when another window is activated.
1359 TEST_F(ShelfLayoutManagerTest, FullscreenWindowInFrontHidesShelf) {
1360 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1362 // Create a window and make it full screen.
1363 aura::Window* window1 = CreateTestWindow();
1364 window1->SetBounds(gfx::Rect(0, 0, 100, 100));
1365 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
1366 window1->Show();
1368 aura::Window* window2 = CreateTestWindow();
1369 window2->SetBounds(gfx::Rect(0, 0, 100, 100));
1370 window2->Show();
1372 wm::GetWindowState(window1)->Activate();
1373 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1375 wm::GetWindowState(window2)->Activate();
1376 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1378 wm::GetWindowState(window1)->Activate();
1379 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1382 // Test the behavior of the shelf when a window on one display is fullscreen
1383 // but the other display has the active window.
1384 TEST_F(ShelfLayoutManagerTest, FullscreenWindowOnSecondDisplay) {
1385 if (!SupportsMultipleDisplays())
1386 return;
1388 UpdateDisplay("800x600,800x600");
1389 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1390 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1391 Shell::RootWindowControllerList root_window_controllers =
1392 Shell::GetAllRootWindowControllers();
1394 // Create windows on either display.
1395 aura::Window* window1 = CreateTestWindow();
1396 window1->SetBoundsInScreen(
1397 gfx::Rect(0, 0, 100, 100),
1398 display_manager->GetDisplayAt(0));
1399 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
1400 window1->Show();
1402 aura::Window* window2 = CreateTestWindow();
1403 window2->SetBoundsInScreen(
1404 gfx::Rect(800, 0, 100, 100),
1405 display_manager->GetDisplayAt(1));
1406 window2->Show();
1408 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
1409 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
1411 wm::GetWindowState(window2)->Activate();
1412 EXPECT_EQ(SHELF_HIDDEN,
1413 root_window_controllers[0]->GetShelfLayoutManager()->visibility_state());
1414 EXPECT_EQ(SHELF_VISIBLE,
1415 root_window_controllers[1]->GetShelfLayoutManager()->visibility_state());
1419 #if defined(OS_WIN)
1420 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1421 #define MAYBE_SetAlignment DISABLED_SetAlignment
1422 #else
1423 #define MAYBE_SetAlignment SetAlignment
1424 #endif
1426 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT, TOP).
1427 TEST_F(ShelfLayoutManagerTest, MAYBE_SetAlignment) {
1428 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1429 // Force an initial layout.
1430 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1431 shelf->LayoutShelf();
1432 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1434 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
1435 gfx::Rect shelf_bounds(
1436 GetShelfWidget()->GetWindowBoundsInScreen());
1437 const gfx::Screen* screen = Shell::GetScreen();
1438 gfx::Display display =
1439 screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1440 ASSERT_NE(-1, display.id());
1441 EXPECT_EQ(shelf->GetIdealBounds().width(),
1442 display.GetWorkAreaInsets().left());
1443 EXPECT_GE(
1444 shelf_bounds.width(),
1445 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1446 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetSystemTray()->shelf_alignment());
1447 StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
1448 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen());
1449 EXPECT_GE(status_bounds.width(),
1450 status_area_widget->GetContentsView()->GetPreferredSize().width());
1451 EXPECT_EQ(shelf->GetIdealBounds().width(),
1452 display.GetWorkAreaInsets().left());
1453 EXPECT_EQ(0, display.GetWorkAreaInsets().top());
1454 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
1455 EXPECT_EQ(0, display.GetWorkAreaInsets().right());
1456 EXPECT_EQ(display.bounds().x(), shelf_bounds.x());
1457 EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
1458 EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
1459 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1460 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1461 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1462 display.GetWorkAreaInsets().left());
1463 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x());
1465 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1466 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
1467 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1468 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1469 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1470 ASSERT_NE(-1, display.id());
1471 EXPECT_EQ(shelf->GetIdealBounds().width(),
1472 display.GetWorkAreaInsets().right());
1473 EXPECT_GE(shelf_bounds.width(),
1474 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1475 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment());
1476 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
1477 EXPECT_GE(status_bounds.width(),
1478 status_area_widget->GetContentsView()->GetPreferredSize().width());
1479 EXPECT_EQ(shelf->GetIdealBounds().width(),
1480 display.GetWorkAreaInsets().right());
1481 EXPECT_EQ(0, display.GetWorkAreaInsets().top());
1482 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
1483 EXPECT_EQ(0, display.GetWorkAreaInsets().left());
1484 EXPECT_EQ(display.work_area().right(), shelf_bounds.x());
1485 EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
1486 EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
1487 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1488 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1489 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1490 display.GetWorkAreaInsets().right());
1491 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1492 display.bounds().right() - display.work_area().right());
1494 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1495 shelf->SetAlignment(SHELF_ALIGNMENT_TOP);
1496 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1497 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1498 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1499 ASSERT_NE(-1, display.id());
1500 EXPECT_EQ(shelf->GetIdealBounds().height(),
1501 display.GetWorkAreaInsets().top());
1502 EXPECT_GE(shelf_bounds.height(),
1503 GetShelfWidget()->GetContentsView()->GetPreferredSize().height());
1504 EXPECT_EQ(SHELF_ALIGNMENT_TOP, GetSystemTray()->shelf_alignment());
1505 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
1506 EXPECT_GE(status_bounds.height(),
1507 status_area_widget->GetContentsView()->GetPreferredSize().height());
1508 EXPECT_EQ(shelf->GetIdealBounds().height(),
1509 display.GetWorkAreaInsets().top());
1510 EXPECT_EQ(0, display.GetWorkAreaInsets().right());
1511 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
1512 EXPECT_EQ(0, display.GetWorkAreaInsets().left());
1513 EXPECT_EQ(display.work_area().y(), shelf_bounds.bottom());
1514 EXPECT_EQ(display.bounds().x(), shelf_bounds.x());
1515 EXPECT_EQ(display.bounds().width(), shelf_bounds.width());
1516 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1517 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1518 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1519 display.GetWorkAreaInsets().top());
1520 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1521 display.work_area().y() - display.bounds().y());
1524 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) {
1525 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1526 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1527 views::Widget* widget = new views::Widget;
1528 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1529 params.bounds = gfx::Rect(0, 0, 200, 200);
1530 params.context = CurrentContext();
1531 widget->Init(params);
1532 widget->Show();
1533 widget->Maximize();
1535 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1537 aura::Window* window = widget->GetNativeWindow();
1538 shelf->LayoutShelf();
1540 gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen();
1541 gfx::Rect bounds_shelf = window->bounds();
1543 // Edge swipe when SHELF_VISIBLE should not change visibility state.
1544 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1545 generator.GestureEdgeSwipe();
1546 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1548 // Edge swipe when AUTO_HIDE_HIDDEN should change to AUTO_HIDE_SHOWN.
1549 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1550 shelf->LayoutShelf();
1551 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1552 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1553 generator.GestureEdgeSwipe();
1554 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1555 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1557 widget->SetFullscreen(true);
1558 wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(false);
1559 shelf->UpdateVisibilityState();
1561 // Edge swipe in fullscreen + AUTO_HIDE_HIDDEN should show the shelf and
1562 // remain fullscreen.
1563 EXPECT_TRUE(widget->IsFullscreen());
1564 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1565 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1566 generator.GestureEdgeSwipe();
1567 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1568 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1569 EXPECT_TRUE(widget->IsFullscreen());
1572 #if defined(OS_WIN)
1573 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1574 #define MAYBE_GestureDrag DISABLED_GestureDrag
1575 #else
1576 #define MAYBE_GestureDrag GestureDrag
1577 #endif
1579 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
1580 // Slop is an implementation detail of gesture recognition, and complicates
1581 // these tests. Ignore it.
1582 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
1583 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1585 SCOPED_TRACE("BOTTOM");
1586 RunGestureDragTests(gfx::Vector2d(0, 120));
1590 SCOPED_TRACE("LEFT");
1591 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
1592 RunGestureDragTests(gfx::Vector2d(-120, 0));
1596 SCOPED_TRACE("RIGHT");
1597 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
1598 RunGestureDragTests(gfx::Vector2d(120, 0));
1602 TEST_F(ShelfLayoutManagerTest, WindowVisibilityDisablesAutoHide) {
1603 if (!SupportsMultipleDisplays())
1604 return;
1606 UpdateDisplay("800x600,800x600");
1607 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1608 shelf->LayoutShelf();
1609 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1611 // Create a visible window so auto-hide behavior is enforced
1612 views::Widget* dummy = CreateTestWidget();
1614 // Window visible => auto hide behaves normally.
1615 shelf->UpdateVisibilityState();
1616 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1618 // Window minimized => auto hide disabled.
1619 dummy->Minimize();
1620 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1622 // Window closed => auto hide disabled.
1623 dummy->CloseNow();
1624 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1626 // Multiple window test
1627 views::Widget* window1 = CreateTestWidget();
1628 views::Widget* window2 = CreateTestWidget();
1630 // both visible => normal autohide
1631 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1633 // either minimzed => normal autohide
1634 window2->Minimize();
1635 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1636 window2->Restore();
1637 window1->Minimize();
1638 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1640 // both minimized => disable auto hide
1641 window2->Minimize();
1642 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1644 // Test moving windows to/from other display.
1645 window2->Restore();
1646 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1647 // Move to second display.
1648 window2->SetBounds(gfx::Rect(850, 50, 50, 50));
1649 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1650 // Move back to primary display.
1651 window2->SetBounds(gfx::Rect(50, 50, 50, 50));
1652 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1655 // Test that the shelf animates back to its normal position upon a user
1656 // completing a gesture drag.
1657 TEST_F(ShelfLayoutManagerTest, ShelfAnimatesWhenGestureComplete) {
1658 if (!SupportsHostWindowResize())
1659 return;
1661 // Test the shelf animates back to its original visible bounds when it is
1662 // dragged when there are no visible windows.
1663 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1664 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1665 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1666 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1667 gfx::Rect visible_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1669 // Enable animations so that we can make sure that they occur.
1670 ui::ScopedAnimationDurationScaleMode regular_animations(
1671 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
1673 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1674 gfx::Rect shelf_bounds_in_screen =
1675 GetShelfWidget()->GetWindowBoundsInScreen();
1676 gfx::Point start(shelf_bounds_in_screen.CenterPoint());
1677 gfx::Point end(start.x(), shelf_bounds_in_screen.bottom());
1678 generator.GestureScrollSequence(start, end,
1679 base::TimeDelta::FromMilliseconds(10), 5);
1680 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1681 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1683 ShelfAnimationWaiter waiter(visible_bounds);
1684 // Wait till the animation completes and check that it occurred.
1685 waiter.WaitTillDoneAnimating();
1686 EXPECT_TRUE(waiter.WasValidAnimation());
1689 // Create a visible window so auto-hide behavior is enforced.
1690 CreateTestWidget();
1692 // Get the bounds of the shelf when it is hidden.
1693 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1694 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1695 gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1698 // Enable the animations so that we can make sure they do occur.
1699 ui::ScopedAnimationDurationScaleMode regular_animations(
1700 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
1702 gfx::Point start =
1703 GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
1704 gfx::Point end(start.x(), start.y() - 100);
1705 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1707 // Test that the shelf animates to the visible bounds after a swipe up on
1708 // the auto hidden shelf.
1709 generator.GestureScrollSequence(start, end,
1710 base::TimeDelta::FromMilliseconds(10), 1);
1711 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1712 ShelfAnimationWaiter waiter1(visible_bounds);
1713 waiter1.WaitTillDoneAnimating();
1714 EXPECT_TRUE(waiter1.WasValidAnimation());
1716 // Test that the shelf animates to the auto hidden bounds after a swipe up
1717 // on the visible shelf.
1718 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1719 generator.GestureScrollSequence(start, end,
1720 base::TimeDelta::FromMilliseconds(10), 1);
1721 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1722 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1723 ShelfAnimationWaiter waiter2(auto_hidden_bounds);
1724 waiter2.WaitTillDoneAnimating();
1725 EXPECT_TRUE(waiter2.WasValidAnimation());
1729 TEST_F(ShelfLayoutManagerTest, GestureRevealsTrayBubble) {
1730 if (!SupportsHostWindowResize())
1731 return;
1733 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1734 shelf->LayoutShelf();
1736 // Create a visible window so auto-hide behavior is enforced.
1737 CreateTestWidget();
1739 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1740 SystemTray* tray = GetSystemTray();
1742 // First, make sure the shelf is visible.
1743 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1744 EXPECT_FALSE(tray->HasSystemBubble());
1746 // Now, drag up on the tray to show the bubble.
1747 gfx::Point start = GetShelfWidget()->status_area_widget()->
1748 GetWindowBoundsInScreen().CenterPoint();
1749 gfx::Point end(start.x(), start.y() - 100);
1750 generator.GestureScrollSequence(start, end,
1751 base::TimeDelta::FromMilliseconds(10), 1);
1752 EXPECT_TRUE(tray->HasSystemBubble());
1753 tray->CloseSystemBubble();
1754 RunAllPendingInMessageLoop();
1755 EXPECT_FALSE(tray->HasSystemBubble());
1757 // Drag again, but only a small amount, and slowly. The bubble should not be
1758 // visible.
1759 end.set_y(start.y() - 30);
1760 generator.GestureScrollSequence(start, end,
1761 base::TimeDelta::FromMilliseconds(500), 100);
1762 EXPECT_FALSE(tray->HasSystemBubble());
1764 // Now, hide the shelf.
1765 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1767 // Start a drag from the bezel, and drag up to show both the shelf and the
1768 // tray bubble.
1769 start.set_y(start.y() + 100);
1770 end.set_y(start.y() - 400);
1771 generator.GestureScrollSequence(start, end,
1772 base::TimeDelta::FromMilliseconds(10), 1);
1773 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1774 EXPECT_TRUE(tray->HasSystemBubble());
1777 TEST_F(ShelfLayoutManagerTest, ShelfFlickerOnTrayActivation) {
1778 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1780 // Create a visible window so auto-hide behavior is enforced.
1781 CreateTestWidget();
1783 // Turn on auto-hide for the shelf.
1784 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1785 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1786 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1788 // Show the status menu. That should make the shelf visible again.
1789 Shell::GetInstance()->accelerator_controller()->PerformAction(
1790 SHOW_SYSTEM_TRAY_BUBBLE, ui::Accelerator());
1791 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1792 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1793 EXPECT_TRUE(GetSystemTray()->HasSystemBubble());
1796 TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) {
1797 // Make sure the shelf is always visible.
1798 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1799 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1800 shelf->LayoutShelf();
1802 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1803 params.bounds = gfx::Rect(0, 0, 200, 200);
1804 params.context = CurrentContext();
1805 views::Widget* widget_one = CreateTestWidgetWithParams(params);
1806 widget_one->Maximize();
1808 views::Widget* widget_two = CreateTestWidgetWithParams(params);
1809 widget_two->Maximize();
1810 widget_two->Activate();
1812 // Both windows are maximized. They should be of the same size.
1813 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
1814 widget_two->GetNativeWindow()->bounds().ToString());
1815 int area_when_shelf_shown =
1816 widget_one->GetNativeWindow()->bounds().size().GetArea();
1818 // Now hide the shelf.
1819 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1821 // Both windows should be resized according to the shelf status.
1822 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
1823 widget_two->GetNativeWindow()->bounds().ToString());
1824 // Resized to small.
1825 EXPECT_LT(area_when_shelf_shown,
1826 widget_one->GetNativeWindow()->bounds().size().GetArea());
1828 // Now show the shelf.
1829 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1831 // Again both windows should be of the same size.
1832 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
1833 widget_two->GetNativeWindow()->bounds().ToString());
1834 EXPECT_EQ(area_when_shelf_shown,
1835 widget_one->GetNativeWindow()->bounds().size().GetArea());
1838 // Confirm that the shelf is dimmed only when content is maximized and
1839 // shelf is not autohidden.
1840 TEST_F(ShelfLayoutManagerTest, Dimming) {
1841 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1842 scoped_ptr<aura::Window> w1(CreateTestWindow());
1843 w1->Show();
1844 wm::ActivateWindow(w1.get());
1846 // Normal window doesn't dim shelf.
1847 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
1848 ShelfWidget* shelf = GetShelfWidget();
1849 EXPECT_FALSE(shelf->GetDimsShelf());
1851 // Maximized window does.
1852 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1853 EXPECT_TRUE(shelf->GetDimsShelf());
1855 // Change back to normal stops dimming.
1856 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
1857 EXPECT_FALSE(shelf->GetDimsShelf());
1859 // Changing back to maximized dims again.
1860 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1861 EXPECT_TRUE(shelf->GetDimsShelf());
1863 // Changing shelf to autohide stops dimming.
1864 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1865 EXPECT_FALSE(shelf->GetDimsShelf());
1868 // Make sure that the shelf will not hide if the mouse is between a bubble and
1869 // the shelf.
1870 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) {
1871 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1872 StatusAreaWidget* status_area_widget =
1873 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
1874 SystemTray* tray = GetSystemTray();
1876 // Create a visible window so auto-hide behavior is enforced.
1877 CreateTestWidget();
1879 shelf->LayoutShelf();
1880 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1882 // Make two iterations - first without a message bubble which should make
1883 // the shelf disappear and then with a message bubble which should keep it
1884 // visible.
1885 for (int i = 0; i < 2; i++) {
1886 // Make sure the shelf is visible and position the mouse over it. Then
1887 // allow auto hide.
1888 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1889 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1890 gfx::Point center =
1891 status_area_widget->GetWindowBoundsInScreen().CenterPoint();
1892 generator.MoveMouseTo(center.x(), center.y());
1893 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1894 EXPECT_TRUE(shelf->IsVisible());
1895 if (!i) {
1896 // In our first iteration we make sure there is no bubble.
1897 tray->CloseSystemBubble();
1898 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1899 } else {
1900 // In our second iteration we show a bubble.
1901 TestItem *item = new TestItem;
1902 tray->AddTrayItem(item);
1903 tray->ShowNotificationView(item);
1904 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
1906 // Move the pointer over the edge of the shelf.
1907 generator.MoveMouseTo(
1908 center.x(), status_area_widget->GetWindowBoundsInScreen().y() - 8);
1909 shelf->UpdateVisibilityState();
1910 if (i) {
1911 EXPECT_TRUE(shelf->IsVisible());
1912 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
1913 } else {
1914 EXPECT_FALSE(shelf->IsVisible());
1915 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1920 TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColor) {
1921 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
1923 scoped_ptr<aura::Window> w1(CreateTestWindow());
1924 w1->Show();
1925 wm::ActivateWindow(w1.get());
1926 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
1927 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1928 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
1930 scoped_ptr<aura::Window> w2(CreateTestWindow());
1931 w2->Show();
1932 wm::ActivateWindow(w2.get());
1933 // Overlaps with shelf.
1934 w2->SetBounds(GetShelfLayoutManager()->GetIdealBounds());
1936 // Still background is 'maximized'.
1937 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
1939 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
1940 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
1941 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
1942 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
1944 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1945 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
1946 w1.reset();
1947 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
1950 // Verify that the shelf doesn't have the opaque background if it's auto-hide
1951 // status.
1952 TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColorAutoHide) {
1953 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget ()->GetBackgroundType());
1955 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1956 scoped_ptr<aura::Window> w1(CreateTestWindow());
1957 w1->Show();
1958 wm::ActivateWindow(w1.get());
1959 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
1960 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1961 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
1964 #if defined(OS_CHROMEOS)
1965 #define MAYBE_StatusAreaHitBoxCoversEdge StatusAreaHitBoxCoversEdge
1966 #else
1967 #define MAYBE_StatusAreaHitBoxCoversEdge DISABLED_StatusAreaHitBoxCoversEdge
1968 #endif
1970 // Verify the hit bounds of the status area extend to the edge of the shelf.
1971 TEST_F(ShelfLayoutManagerTest, MAYBE_StatusAreaHitBoxCoversEdge) {
1972 UpdateDisplay("400x400");
1973 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1974 StatusAreaWidget* status_area_widget =
1975 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
1976 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1977 generator.MoveMouseTo(399,399);
1979 // Test bottom right pixel for bottom alignment.
1980 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1981 generator.ClickLeftButton();
1982 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
1983 generator.ClickLeftButton();
1984 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1986 // Test bottom right pixel for right alignment.
1987 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
1988 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1989 generator.ClickLeftButton();
1990 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
1991 generator.ClickLeftButton();
1992 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1994 // Test bottom left pixel for left alignment.
1995 generator.MoveMouseTo(0, 399);
1996 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
1997 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
1998 generator.ClickLeftButton();
1999 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2000 generator.ClickLeftButton();
2001 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2004 // Tests that when the auto-hide behaviour is changed during an animation the
2005 // target bounds are updated to reflect the new state.
2006 TEST_F(ShelfLayoutManagerTest,
2007 ShelfAutoHideToggleDuringAnimationUpdatesBounds) {
2008 ShelfLayoutManager* shelf_manager = GetShelfLayoutManager();
2009 aura::Window* status_window = GetShelfWidget()->status_area_widget()->
2010 GetNativeView();
2011 gfx::Rect initial_bounds = status_window->bounds();
2013 ui::ScopedAnimationDurationScaleMode regular_animations(
2014 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
2015 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
2016 gfx::Rect hide_target_bounds = status_window->GetTargetBounds();
2017 EXPECT_GT(hide_target_bounds.y(), initial_bounds.y());
2019 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
2020 gfx::Rect reshow_target_bounds = status_window->GetTargetBounds();
2021 EXPECT_EQ(initial_bounds, reshow_target_bounds);
2024 } // namespace ash