Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / ash / shelf / shelf_layout_manager_unittest.cc
blobab1d9a3964acc56792b0c8c0f552d4407d4b99b1
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/display/window_tree_host_manager.h"
12 #include "ash/focus_cycler.h"
13 #include "ash/root_window_controller.h"
14 #include "ash/session/session_state_delegate.h"
15 #include "ash/shelf/shelf.h"
16 #include "ash/shelf/shelf_layout_manager_observer.h"
17 #include "ash/shelf/shelf_view.h"
18 #include "ash/shelf/shelf_widget.h"
19 #include "ash/shell.h"
20 #include "ash/shell_window_ids.h"
21 #include "ash/system/status_area_widget.h"
22 #include "ash/system/tray/system_tray.h"
23 #include "ash/system/tray/system_tray_item.h"
24 #include "ash/test/ash_test_base.h"
25 #include "ash/test/display_manager_test_api.h"
26 #include "ash/test/shelf_test_api.h"
27 #include "ash/wm/window_state.h"
28 #include "ash/wm/window_util.h"
29 #include "base/command_line.h"
30 #include "base/strings/utf_string_conversions.h"
31 #include "ui/aura/client/aura_constants.h"
32 #include "ui/aura/client/window_tree_client.h"
33 #include "ui/aura/window.h"
34 #include "ui/aura/window_event_dispatcher.h"
35 #include "ui/compositor/layer.h"
36 #include "ui/compositor/layer_animator.h"
37 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
38 #include "ui/events/gesture_detection/gesture_configuration.h"
39 #include "ui/events/test/event_generator.h"
40 #include "ui/gfx/display.h"
41 #include "ui/gfx/screen.h"
42 #include "ui/views/controls/label.h"
43 #include "ui/views/layout/fill_layout.h"
44 #include "ui/views/view.h"
45 #include "ui/views/widget/widget.h"
47 #if defined(OS_WIN)
48 #include "base/win/windows_version.h"
49 #endif
51 namespace ash {
52 namespace {
54 void StepWidgetLayerAnimatorToEnd(views::Widget* widget) {
55 widget->GetNativeView()->layer()->GetAnimator()->Step(
56 base::TimeTicks::Now() + base::TimeDelta::FromSeconds(1));
59 ShelfWidget* GetShelfWidget() {
60 return Shell::GetPrimaryRootWindowController()->shelf();
63 ShelfLayoutManager* GetShelfLayoutManager() {
64 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager();
67 SystemTray* GetSystemTray() {
68 return Shell::GetPrimaryRootWindowController()->GetSystemTray();
71 // Class which waits till the shelf finishes animating to the target size and
72 // counts the number of animation steps.
73 class ShelfAnimationWaiter : views::WidgetObserver {
74 public:
75 explicit ShelfAnimationWaiter(const gfx::Rect& target_bounds)
76 : target_bounds_(target_bounds),
77 animation_steps_(0),
78 done_waiting_(false) {
79 GetShelfWidget()->AddObserver(this);
82 ~ShelfAnimationWaiter() override { GetShelfWidget()->RemoveObserver(this); }
84 // Wait till the shelf finishes animating to its expected bounds.
85 void WaitTillDoneAnimating() {
86 if (IsDoneAnimating())
87 done_waiting_ = true;
88 else
89 base::MessageLoop::current()->Run();
92 // Returns true if the animation has completed and it was valid.
93 bool WasValidAnimation() const {
94 return done_waiting_ && animation_steps_ > 0;
97 private:
98 // Returns true if shelf has finished animating to the target size.
99 bool IsDoneAnimating() const {
100 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
101 gfx::Rect current_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
102 int size = layout_manager->PrimaryAxisValue(current_bounds.height(),
103 current_bounds.width());
104 int desired_size = layout_manager->PrimaryAxisValue(target_bounds_.height(),
105 target_bounds_.width());
106 return (size == desired_size);
109 // views::WidgetObserver override.
110 void OnWidgetBoundsChanged(views::Widget* widget,
111 const gfx::Rect& new_bounds) override {
112 if (done_waiting_)
113 return;
115 ++animation_steps_;
116 if (IsDoneAnimating()) {
117 done_waiting_ = true;
118 base::MessageLoop::current()->Quit();
122 gfx::Rect target_bounds_;
123 int animation_steps_;
124 bool done_waiting_;
126 DISALLOW_COPY_AND_ASSIGN(ShelfAnimationWaiter);
129 class ShelfDragCallback {
130 public:
131 ShelfDragCallback(const gfx::Rect& not_visible, const gfx::Rect& visible)
132 : not_visible_bounds_(not_visible),
133 visible_bounds_(visible),
134 was_visible_on_drag_start_(false) {
135 EXPECT_EQ(not_visible_bounds_.bottom(), visible_bounds_.bottom());
138 virtual ~ShelfDragCallback() {
141 void ProcessScroll(ui::EventType type, const gfx::Vector2dF& delta) {
142 if (GetShelfLayoutManager()->visibility_state() == ash::SHELF_HIDDEN)
143 return;
145 if (type == ui::ET_GESTURE_SCROLL_BEGIN) {
146 scroll_ = gfx::Vector2dF();
147 was_visible_on_drag_start_ = GetShelfLayoutManager()->IsVisible();
148 return;
151 // The state of the shelf at the end of the gesture is tested separately.
152 if (type == ui::ET_GESTURE_SCROLL_END)
153 return;
155 if (type == ui::ET_GESTURE_SCROLL_UPDATE)
156 scroll_.Add(delta);
158 gfx::Rect shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
159 if (GetShelfLayoutManager()->IsHorizontalAlignment()) {
160 EXPECT_EQ(not_visible_bounds_.bottom(), shelf_bounds.bottom());
161 EXPECT_EQ(visible_bounds_.bottom(), shelf_bounds.bottom());
162 } else if (SHELF_ALIGNMENT_RIGHT ==
163 GetShelfLayoutManager()->GetAlignment()){
164 EXPECT_EQ(not_visible_bounds_.right(), shelf_bounds.right());
165 EXPECT_EQ(visible_bounds_.right(), shelf_bounds.right());
166 } else if (SHELF_ALIGNMENT_LEFT ==
167 GetShelfLayoutManager()->GetAlignment()) {
168 EXPECT_EQ(not_visible_bounds_.x(), shelf_bounds.x());
169 EXPECT_EQ(visible_bounds_.x(), shelf_bounds.x());
172 // if the shelf is being dimmed test dimmer bounds as well.
173 if (GetShelfWidget()->GetDimsShelf())
174 EXPECT_EQ(GetShelfWidget()->GetWindowBoundsInScreen(),
175 GetShelfWidget()->GetDimmerBoundsForTest());
177 // The shelf should never be smaller than the hidden state.
178 EXPECT_GE(shelf_bounds.height(), not_visible_bounds_.height());
179 float scroll_delta = GetShelfLayoutManager()->PrimaryAxisValue(
180 scroll_.y(),
181 scroll_.x());
182 bool increasing_drag =
183 GetShelfLayoutManager()->SelectValueForShelfAlignment(
184 scroll_delta < 0,
185 scroll_delta > 0,
186 scroll_delta < 0,
187 scroll_delta > 0);
188 int shelf_size = GetShelfLayoutManager()->PrimaryAxisValue(
189 shelf_bounds.height(),
190 shelf_bounds.width());
191 int visible_bounds_size = GetShelfLayoutManager()->PrimaryAxisValue(
192 visible_bounds_.height(),
193 visible_bounds_.width());
194 int not_visible_bounds_size = GetShelfLayoutManager()->PrimaryAxisValue(
195 not_visible_bounds_.height(),
196 not_visible_bounds_.width());
197 if (was_visible_on_drag_start_) {
198 if (increasing_drag) {
199 // If dragging inwards from the visible state, then the shelf should
200 // increase in size, but not more than the scroll delta.
201 EXPECT_LE(visible_bounds_size, shelf_size);
202 EXPECT_LE(std::abs(shelf_size - visible_bounds_size),
203 std::abs(scroll_delta));
204 } else {
205 if (shelf_size > not_visible_bounds_size) {
206 // If dragging outwards from the visible state, then the shelf
207 // should decrease in size, until it reaches the minimum size.
208 EXPECT_EQ(shelf_size, visible_bounds_size - std::abs(scroll_delta));
211 } else {
212 if (std::abs(scroll_delta) <
213 visible_bounds_size - not_visible_bounds_size) {
214 // Tests that the shelf sticks with the touch point during the drag
215 // until the shelf is completely visible.
216 EXPECT_EQ(shelf_size, not_visible_bounds_size + std::abs(scroll_delta));
217 } else {
218 // Tests that after the shelf is completely visible, the shelf starts
219 // resisting the drag.
220 EXPECT_LT(shelf_size, not_visible_bounds_size + std::abs(scroll_delta));
225 private:
226 const gfx::Rect not_visible_bounds_;
227 const gfx::Rect visible_bounds_;
228 gfx::Vector2dF scroll_;
229 bool was_visible_on_drag_start_;
231 DISALLOW_COPY_AND_ASSIGN(ShelfDragCallback);
234 class ShelfLayoutObserverTest : public ShelfLayoutManagerObserver {
235 public:
236 ShelfLayoutObserverTest()
237 : changed_auto_hide_state_(false) {
240 ~ShelfLayoutObserverTest() override {}
242 bool changed_auto_hide_state() const { return changed_auto_hide_state_; }
244 private:
245 void OnAutoHideStateChanged(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 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 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 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 views::View* CreateNotificationView(user::LoginStatus status) override {
288 notification_view_ = new views::View;
289 return notification_view_;
292 void DestroyTrayView() override { tray_view_ = NULL; }
294 void DestroyDefaultView() override { default_view_ = NULL; }
296 void DestroyDetailedView() override { detailed_view_ = NULL; }
298 void DestroyNotificationView() override { notification_view_ = NULL; }
300 void UpdateAfterLoginStatusChange(user::LoginStatus status) override {}
302 views::View* tray_view() const { return tray_view_; }
303 views::View* default_view() const { return default_view_; }
304 views::View* detailed_view() const { return detailed_view_; }
305 views::View* notification_view() const { return notification_view_; }
307 private:
308 views::View* tray_view_;
309 views::View* default_view_;
310 views::View* detailed_view_;
311 views::View* notification_view_;
313 DISALLOW_COPY_AND_ASSIGN(TestItem);
316 } // namespace
318 class ShelfLayoutManagerTest : public ash::test::AshTestBase {
319 public:
320 ShelfLayoutManagerTest() {}
322 void SetState(ShelfLayoutManager* shelf,
323 ShelfVisibilityState state) {
324 shelf->SetState(state);
327 void UpdateAutoHideStateNow() {
328 GetShelfLayoutManager()->UpdateAutoHideStateNow();
331 aura::Window* CreateTestWindow() {
332 aura::Window* window = new aura::Window(NULL);
333 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
334 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
335 window->Init(ui::LAYER_TEXTURED);
336 ParentWindowInPrimaryRootWindow(window);
337 return window;
340 aura::Window* CreateTestWindowInParent(aura::Window* root_window) {
341 aura::Window* window = new aura::Window(NULL);
342 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
343 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
344 window->Init(ui::LAYER_TEXTURED);
345 aura::client::ParentWindowWithContext(window, root_window, gfx::Rect());
346 return window;
349 views::Widget* CreateTestWidgetWithParams(
350 const views::Widget::InitParams& params) {
351 views::Widget* out = new views::Widget;
352 out->Init(params);
353 out->Show();
354 return out;
357 // Create a simple widget attached to the current context (will
358 // delete on TearDown).
359 views::Widget* CreateTestWidget() {
360 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
361 params.bounds = gfx::Rect(0, 0, 200, 200);
362 params.context = CurrentContext();
363 return CreateTestWidgetWithParams(params);
366 void RunGestureDragTests(gfx::Vector2d);
368 // Turn on the lock screen.
369 void LockScreen() {
370 Shell::GetInstance()->session_state_delegate()->LockScreen();
371 // The test session state delegate does not fire the lock state change.
372 Shell::GetInstance()->OnLockStateChanged(true);
375 // Turn off the lock screen.
376 void UnlockScreen() {
377 Shell::GetInstance()->session_state_delegate()->UnlockScreen();
378 // The test session state delegate does not fire the lock state change.
379 Shell::GetInstance()->OnLockStateChanged(false);
382 // Open the add user screen if |show| is true, otherwise end it.
383 void ShowAddUserScreen(bool show) {
384 SetUserAddingScreenRunning(show);
385 ShelfLayoutManager* manager = GetShelfWidget()->shelf_layout_manager();
386 manager->SessionStateChanged(
387 show ? SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY :
388 SessionStateDelegate::SESSION_STATE_ACTIVE);
391 private:
392 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest);
395 void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
396 ShelfLayoutManager* shelf = GetShelfLayoutManager();
397 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
398 views::Widget* widget = new views::Widget;
399 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
400 params.bounds = gfx::Rect(0, 0, 200, 200);
401 params.context = CurrentContext();
402 widget->Init(params);
403 widget->Show();
404 widget->Maximize();
406 // The time delta should be large enough to prevent accidental fling creation.
407 const base::TimeDelta kTimeDelta = base::TimeDelta::FromMilliseconds(100);
409 aura::Window* window = widget->GetNativeWindow();
410 shelf->LayoutShelf();
412 gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen();
413 gfx::Rect bounds_shelf = window->bounds();
414 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
416 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
417 shelf->LayoutShelf();
418 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
420 gfx::Rect bounds_noshelf = window->bounds();
421 gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen();
423 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
424 shelf->LayoutShelf();
426 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
427 const int kNumScrollSteps = 4;
428 ShelfDragCallback handler(shelf_hidden, shelf_shown);
430 // Swipe up on the shelf. This should not change any state.
431 gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
432 gfx::Point end = start + delta;
434 // Swipe down on the shelf to hide it.
435 generator.GestureScrollSequenceWithCallback(
436 start,
437 end,
438 kTimeDelta,
439 kNumScrollSteps,
440 base::Bind(&ShelfDragCallback::ProcessScroll,
441 base::Unretained(&handler)));
442 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
443 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
444 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
445 EXPECT_NE(bounds_shelf.ToString(), window->bounds().ToString());
446 EXPECT_NE(shelf_shown.ToString(),
447 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
449 // Swipe up to show the shelf.
450 generator.GestureScrollSequenceWithCallback(
451 end,
452 start,
453 kTimeDelta,
454 kNumScrollSteps,
455 base::Bind(&ShelfDragCallback::ProcessScroll,
456 base::Unretained(&handler)));
457 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
458 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
459 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
460 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
461 GetShelfWidget()->GetWindowBoundsInScreen());
462 EXPECT_EQ(shelf_shown.ToString(),
463 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
465 // Swipe up again. The shelf should hide.
466 end = start - delta;
467 generator.GestureScrollSequenceWithCallback(
468 start,
469 end,
470 kTimeDelta,
471 kNumScrollSteps,
472 base::Bind(&ShelfDragCallback::ProcessScroll,
473 base::Unretained(&handler)));
474 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
475 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
476 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
477 EXPECT_EQ(shelf_hidden.ToString(),
478 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
480 // Swipe up yet again to show it.
481 end = start + delta;
482 generator.GestureScrollSequenceWithCallback(
483 end,
484 start,
485 kTimeDelta,
486 kNumScrollSteps,
487 base::Bind(&ShelfDragCallback::ProcessScroll,
488 base::Unretained(&handler)));
490 // Swipe down very little. It shouldn't change any state.
491 if (GetShelfLayoutManager()->IsHorizontalAlignment())
492 end.set_y(start.y() + shelf_shown.height() * 3 / 10);
493 else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
494 end.set_x(start.x() - shelf_shown.width() * 3 / 10);
495 else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
496 end.set_x(start.x() + shelf_shown.width() * 3 / 10);
497 generator.GestureScrollSequence(start, end, kTimeDelta, 5);
498 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
499 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
500 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
501 EXPECT_EQ(shelf_shown.ToString(),
502 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
504 // Swipe down again to hide.
505 end = start + delta;
506 generator.GestureScrollSequenceWithCallback(
507 start,
508 end,
509 kTimeDelta,
510 kNumScrollSteps,
511 base::Bind(&ShelfDragCallback::ProcessScroll,
512 base::Unretained(&handler)));
513 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
514 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
515 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
516 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
517 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
518 EXPECT_EQ(shelf_hidden.ToString(),
519 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
521 // Swipe up in extended hit region to show it.
522 gfx::Point extended_start = start;
523 if (GetShelfLayoutManager()->IsHorizontalAlignment())
524 extended_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().y() -1);
525 else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
526 extended_start.set_x(
527 GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
528 else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
529 extended_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
530 end = extended_start - delta;
531 generator.GestureScrollSequenceWithCallback(
532 extended_start,
533 end,
534 kTimeDelta,
535 kNumScrollSteps,
536 base::Bind(&ShelfDragCallback::ProcessScroll,
537 base::Unretained(&handler)));
538 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
539 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
540 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
541 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
542 GetShelfWidget()->GetWindowBoundsInScreen());
543 EXPECT_EQ(shelf_shown.ToString(),
544 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
546 // Swipe down again to hide.
547 end = start + delta;
548 generator.GestureScrollSequenceWithCallback(
549 start,
550 end,
551 kTimeDelta,
552 kNumScrollSteps,
553 base::Bind(&ShelfDragCallback::ProcessScroll,
554 base::Unretained(&handler)));
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(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
559 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
560 EXPECT_EQ(shelf_hidden.ToString(),
561 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
563 // Swipe up outside the hit area. This should not change anything.
564 gfx::Point outside_start = gfx::Point(
565 (GetShelfWidget()->GetWindowBoundsInScreen().x() +
566 GetShelfWidget()->GetWindowBoundsInScreen().right())/2,
567 GetShelfWidget()->GetWindowBoundsInScreen().y() - 50);
568 end = outside_start + delta;
569 generator.GestureScrollSequence(
570 outside_start, end, kTimeDelta, kNumScrollSteps);
571 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
572 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
573 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
574 EXPECT_EQ(shelf_hidden.ToString(),
575 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
577 // Swipe up from below the shelf where a bezel would be, this should show the
578 // shelf.
579 gfx::Point below_start = start;
580 if (GetShelfLayoutManager()->IsHorizontalAlignment())
581 below_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() + 1);
582 else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
583 below_start.set_x(
584 GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
585 else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
586 below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
587 end = below_start - delta;
588 generator.GestureScrollSequence(
589 below_start, end, kTimeDelta, kNumScrollSteps);
590 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
591 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
592 EXPECT_EQ(bounds_shelf.ToString(), window->bounds().ToString());
593 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(),
594 GetShelfWidget()->GetWindowBoundsInScreen());
595 EXPECT_EQ(shelf_shown.ToString(),
596 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
598 // Swipe down again to hide.
599 end = start + delta;
600 generator.GestureScrollSequenceWithCallback(
601 start,
602 end,
603 kTimeDelta,
604 kNumScrollSteps,
605 base::Bind(&ShelfDragCallback::ProcessScroll,
606 base::Unretained(&handler)));
607 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
608 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
609 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
610 EXPECT_EQ(GetShelfWidget()->GetDimmerBoundsForTest(), gfx::Rect());
611 EXPECT_EQ(bounds_noshelf.ToString(), window->bounds().ToString());
612 EXPECT_EQ(shelf_hidden.ToString(),
613 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
615 // Put |widget| into fullscreen. Set the shelf to be auto hidden when |widget|
616 // is fullscreen. (eg browser immersive fullscreen).
617 widget->SetFullscreen(true);
618 wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(false);
619 shelf->UpdateVisibilityState();
621 gfx::Rect bounds_fullscreen = window->bounds();
622 EXPECT_TRUE(widget->IsFullscreen());
623 EXPECT_NE(bounds_noshelf.ToString(), bounds_fullscreen.ToString());
625 // Swipe up. This should show the shelf.
626 end = below_start - delta;
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_SHOWN, shelf->auto_hide_state());
636 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_NEVER, shelf->auto_hide_behavior());
637 EXPECT_EQ(shelf_shown.ToString(),
638 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
639 EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
641 // Swipe up again. This should hide the shelf.
642 generator.GestureScrollSequenceWithCallback(
643 below_start,
644 end,
645 kTimeDelta,
646 kNumScrollSteps,
647 base::Bind(&ShelfDragCallback::ProcessScroll,
648 base::Unretained(&handler)));
649 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
650 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
651 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
652 EXPECT_EQ(shelf_hidden.ToString(),
653 GetShelfWidget()->GetWindowBoundsInScreen().ToString());
654 EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
656 // Set the shelf to be hidden when |widget| is fullscreen. (eg tab fullscreen
657 // with or without immersive browser fullscreen).
658 wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(true);
659 shelf->UpdateVisibilityState();
660 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
661 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
663 // Swipe-up. This should not change anything.
664 end = start - delta;
665 generator.GestureScrollSequenceWithCallback(
666 below_start,
667 end,
668 kTimeDelta,
669 kNumScrollSteps,
670 base::Bind(&ShelfDragCallback::ProcessScroll,
671 base::Unretained(&handler)));
672 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
673 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
674 EXPECT_EQ(bounds_fullscreen.ToString(), window->bounds().ToString());
676 // Close actually, otherwise further event may be affected since widget
677 // is fullscreen status.
678 widget->Close();
679 RunAllPendingInMessageLoop();
681 // The shelf should be shown because there are no more visible windows.
682 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
683 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
684 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
686 // Swipe-up to hide. This should have no effect because there are no visible
687 // windows.
688 end = below_start - delta;
689 generator.GestureScrollSequenceWithCallback(
690 below_start,
691 end,
692 kTimeDelta,
693 kNumScrollSteps,
694 base::Bind(&ShelfDragCallback::ProcessScroll,
695 base::Unretained(&handler)));
696 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
697 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
698 EXPECT_EQ(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, shelf->auto_hide_behavior());
701 // Need to be implemented. http://crbug.com/111279.
702 #if defined(OS_WIN)
703 #define MAYBE_SetVisible DISABLED_SetVisible
704 #else
705 #define MAYBE_SetVisible SetVisible
706 #endif
707 // Makes sure SetVisible updates work area and widget appropriately.
708 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) {
709 ShelfWidget* shelf = GetShelfWidget();
710 ShelfLayoutManager* manager = shelf->shelf_layout_manager();
711 // Force an initial layout.
712 manager->LayoutShelf();
713 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
715 gfx::Rect status_bounds(
716 shelf->status_area_widget()->GetWindowBoundsInScreen());
717 gfx::Rect shelf_bounds(
718 shelf->GetWindowBoundsInScreen());
719 int shelf_height = manager->GetIdealBounds().height();
720 gfx::Screen* screen = Shell::GetScreen();
721 gfx::Display display = screen->GetDisplayNearestWindow(
722 Shell::GetPrimaryRootWindow());
723 ASSERT_NE(-1, display.id());
724 // Bottom inset should be the max of widget heights.
725 EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
727 // Hide the shelf.
728 SetState(manager, SHELF_HIDDEN);
729 // Run the animation to completion.
730 StepWidgetLayerAnimatorToEnd(shelf);
731 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget());
732 EXPECT_EQ(SHELF_HIDDEN, manager->visibility_state());
733 display = screen->GetDisplayNearestWindow(
734 Shell::GetPrimaryRootWindow());
736 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
738 // Make sure the bounds of the two widgets changed.
739 EXPECT_GE(shelf->GetNativeView()->bounds().y(),
740 screen->GetPrimaryDisplay().bounds().bottom());
741 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(),
742 screen->GetPrimaryDisplay().bounds().bottom());
744 // And show it again.
745 SetState(manager, SHELF_VISIBLE);
746 // Run the animation to completion.
747 StepWidgetLayerAnimatorToEnd(shelf);
748 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget());
749 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
750 display = screen->GetDisplayNearestWindow(
751 Shell::GetPrimaryRootWindow());
752 EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
754 // Make sure the bounds of the two widgets changed.
755 shelf_bounds = shelf->GetNativeView()->bounds();
756 EXPECT_LT(shelf_bounds.y(), screen->GetPrimaryDisplay().bounds().bottom());
757 status_bounds = shelf->status_area_widget()->GetNativeView()->bounds();
758 EXPECT_LT(status_bounds.y(),
759 screen->GetPrimaryDisplay().bounds().bottom());
762 // Makes sure shelf alignment is correct for lock screen.
763 TEST_F(ShelfLayoutManagerTest, SideAlignmentInteractionWithLockScreen) {
764 ShelfLayoutManager* manager = GetShelfWidget()->shelf_layout_manager();
765 manager->SetAlignment(SHELF_ALIGNMENT_LEFT);
766 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
767 LockScreen();
768 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, manager->GetAlignment());
769 UnlockScreen();
770 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
773 // Makes sure shelf alignment is correct for add user screen.
774 TEST_F(ShelfLayoutManagerTest, SideAlignmentInteractionWithAddUserScreen) {
775 ShelfLayoutManager* manager = GetShelfWidget()->shelf_layout_manager();
776 manager->SetAlignment(SHELF_ALIGNMENT_LEFT);
777 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
778 ShowAddUserScreen(true);
779 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, manager->GetAlignment());
780 ShowAddUserScreen(false);
781 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
784 // Makes sure shelf alignment is correct for login screen.
785 TEST_F(ShelfLayoutManagerTest, SideAlignmentInteractionWithLoginScreen) {
786 ShelfLayoutManager* manager = GetShelfWidget()->shelf_layout_manager();
787 ASSERT_EQ(SHELF_ALIGNMENT_BOTTOM, manager->GetAlignment());
788 SetUserLoggedIn(false);
789 SetSessionStarted(false);
791 // The test session state delegate does not fire state changes.
792 SetSessionStarting();
793 manager->SessionStateChanged(
794 Shell::GetInstance()->session_state_delegate()->GetSessionState());
796 // Login sets alignment preferences before the session completes startup.
797 manager->SetAlignment(SHELF_ALIGNMENT_LEFT);
798 SetUserLoggedIn(true);
799 SetSessionStarted(true);
801 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, manager->GetAlignment());
802 // Ensure that the shelf has been notified.
803 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetShelfWidget()->shelf()->alignment());
806 // Makes sure LayoutShelf invoked while animating cleans things up.
807 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
808 ShelfWidget* shelf = GetShelfWidget();
809 // Force an initial layout.
810 shelf->shelf_layout_manager()->LayoutShelf();
811 EXPECT_EQ(SHELF_VISIBLE, shelf->shelf_layout_manager()->visibility_state());
813 // Hide the shelf.
814 SetState(shelf->shelf_layout_manager(), SHELF_HIDDEN);
815 shelf->shelf_layout_manager()->LayoutShelf();
816 EXPECT_EQ(SHELF_HIDDEN, shelf->shelf_layout_manager()->visibility_state());
817 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow(
818 Shell::GetPrimaryRootWindow());
819 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
821 // Make sure the bounds of the two widgets changed.
822 EXPECT_GE(shelf->GetNativeView()->bounds().y(),
823 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
824 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(),
825 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom());
828 // Test that switching to a different visibility state does not restart the
829 // shelf show / hide animation if it is already running. (crbug.com/250918)
830 TEST_F(ShelfLayoutManagerTest, SetStateWhileAnimating) {
831 ShelfWidget* shelf = GetShelfWidget();
832 SetState(shelf->shelf_layout_manager(), SHELF_VISIBLE);
833 gfx::Rect initial_shelf_bounds = shelf->GetWindowBoundsInScreen();
834 gfx::Rect initial_status_bounds =
835 shelf->status_area_widget()->GetWindowBoundsInScreen();
837 ui::ScopedAnimationDurationScaleMode normal_animation_duration(
838 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
839 SetState(shelf->shelf_layout_manager(), SHELF_HIDDEN);
840 SetState(shelf->shelf_layout_manager(), SHELF_VISIBLE);
842 gfx::Rect current_shelf_bounds = shelf->GetWindowBoundsInScreen();
843 gfx::Rect current_status_bounds =
844 shelf->status_area_widget()->GetWindowBoundsInScreen();
846 const int small_change = initial_shelf_bounds.height() / 2;
847 EXPECT_LE(
848 std::abs(initial_shelf_bounds.height() - current_shelf_bounds.height()),
849 small_change);
850 EXPECT_LE(
851 std::abs(initial_status_bounds.height() - current_status_bounds.height()),
852 small_change);
855 // Makes sure the shelf is sized when the status area changes size.
856 TEST_F(ShelfLayoutManagerTest, ShelfUpdatedWhenStatusAreaChangesSize) {
857 Shelf* shelf = Shelf::ForPrimaryDisplay();
858 ASSERT_TRUE(shelf);
859 ShelfWidget* shelf_widget = GetShelfWidget();
860 ASSERT_TRUE(shelf_widget);
861 ASSERT_TRUE(shelf_widget->status_area_widget());
862 shelf_widget->status_area_widget()->SetBounds(
863 gfx::Rect(0, 0, 200, 200));
864 EXPECT_EQ(200, shelf_widget->GetContentsView()->width() -
865 test::ShelfTestAPI(shelf).shelf_view()->width());
869 #if defined(OS_WIN)
870 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
871 #define MAYBE_AutoHide DISABLED_AutoHide
872 #else
873 #define MAYBE_AutoHide AutoHide
874 #endif
876 // Various assertions around auto-hide.
877 TEST_F(ShelfLayoutManagerTest, MAYBE_AutoHide) {
878 aura::Window* root = Shell::GetPrimaryRootWindow();
879 ui::test::EventGenerator generator(root, root);
880 generator.MoveMouseTo(0, 0);
882 ShelfLayoutManager* shelf = GetShelfLayoutManager();
883 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
884 views::Widget* widget = new views::Widget;
885 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
886 params.bounds = gfx::Rect(0, 0, 200, 200);
887 params.context = CurrentContext();
888 // Widget is now owned by the parent window.
889 widget->Init(params);
890 widget->Maximize();
891 widget->Show();
892 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
893 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
895 // LayoutShelf() forces the animation to completion, at which point the
896 // shelf should go off the screen.
897 shelf->LayoutShelf();
898 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
899 GetShelfWidget()->GetWindowBoundsInScreen().y());
900 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
901 Shell::GetScreen()->GetDisplayNearestWindow(
902 root).work_area().bottom());
904 // Move the mouse to the bottom of the screen.
905 generator.MoveMouseTo(0, root->bounds().bottom() - 1);
907 // Shelf should be shown again (but it shouldn't have changed the work area).
908 SetState(shelf, SHELF_AUTO_HIDE);
909 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
910 shelf->LayoutShelf();
911 EXPECT_EQ(root->bounds().bottom() - shelf->GetIdealBounds().height(),
912 GetShelfWidget()->GetWindowBoundsInScreen().y());
913 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
914 Shell::GetScreen()->GetDisplayNearestWindow(
915 root).work_area().bottom());
917 // Move mouse back up.
918 generator.MoveMouseTo(0, 0);
919 SetState(shelf, SHELF_AUTO_HIDE);
920 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
921 shelf->LayoutShelf();
922 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
923 GetShelfWidget()->GetWindowBoundsInScreen().y());
925 // Drag mouse to bottom of screen.
926 generator.PressLeftButton();
927 generator.MoveMouseTo(0, root->bounds().bottom() - 1);
928 UpdateAutoHideStateNow();
929 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
931 generator.ReleaseLeftButton();
932 generator.MoveMouseTo(1, root->bounds().bottom() - 1);
933 UpdateAutoHideStateNow();
934 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
935 generator.PressLeftButton();
936 generator.MoveMouseTo(1, root->bounds().bottom() - 1);
937 UpdateAutoHideStateNow();
938 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
941 // Test the behavior of the shelf when it is auto hidden and it is on the
942 // boundary between the primary and the secondary display.
943 TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnScreenBoundary) {
944 if (!SupportsMultipleDisplays())
945 return;
947 UpdateDisplay("800x600,800x600");
948 DisplayLayout display_layout(DisplayLayout::RIGHT, 0);
949 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
950 display_layout);
951 // Put the primary monitor's shelf on the display boundary.
952 ShelfLayoutManager* shelf = GetShelfLayoutManager();
953 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
955 // Create a window because the shelf is always shown when no windows are
956 // visible.
957 CreateTestWidget();
959 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
960 ASSERT_EQ(root_windows[0],
961 GetShelfWidget()->GetNativeWindow()->GetRootWindow());
963 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
964 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
966 int right_edge = root_windows[0]->GetBoundsInScreen().right() - 1;
967 int y = root_windows[0]->GetBoundsInScreen().y();
969 // Start off the mouse nowhere near the shelf; the shelf should be hidden.
970 ui::test::EventGenerator& generator(GetEventGenerator());
971 generator.MoveMouseTo(right_edge - 50, y);
972 UpdateAutoHideStateNow();
973 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
975 // Moving the mouse over the light bar (but not to the edge of the screen)
976 // should show the shelf.
977 generator.MoveMouseTo(right_edge - 1, y);
978 UpdateAutoHideStateNow();
979 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
980 EXPECT_EQ(right_edge - 1, Shell::GetScreen()->GetCursorScreenPoint().x());
982 // Moving the mouse off the light bar should hide the shelf.
983 generator.MoveMouseTo(right_edge - 50, y);
984 UpdateAutoHideStateNow();
985 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
987 // Moving the mouse to the right edge of the screen crossing the light bar
988 // should show the shelf despite the mouse cursor getting warped to the
989 // secondary display.
990 generator.MoveMouseTo(right_edge - 1, y);
991 generator.MoveMouseTo(right_edge, y);
992 UpdateAutoHideStateNow();
993 EXPECT_NE(right_edge - 1, Shell::GetScreen()->GetCursorScreenPoint().x());
994 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
996 // Hide the shelf.
997 generator.MoveMouseTo(right_edge - 50, y);
998 UpdateAutoHideStateNow();
999 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1001 // Moving the mouse to the right edge of the screen crossing the light bar and
1002 // overshooting by a lot should keep the shelf hidden.
1003 generator.MoveMouseTo(right_edge - 1, y);
1004 generator.MoveMouseTo(right_edge + 50, y);
1005 UpdateAutoHideStateNow();
1006 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1008 // Moving the mouse to the right edge of the screen crossing the light bar and
1009 // overshooting a bit should show the shelf.
1010 generator.MoveMouseTo(right_edge - 1, y);
1011 generator.MoveMouseTo(right_edge + 2, y);
1012 UpdateAutoHideStateNow();
1013 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1015 // Keeping the mouse close to the left edge of the secondary display after the
1016 // shelf is shown should keep the shelf shown.
1017 generator.MoveMouseTo(right_edge + 2, y + 1);
1018 UpdateAutoHideStateNow();
1019 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1021 // Moving the mouse far from the left edge of the secondary display should
1022 // hide the shelf.
1023 generator.MoveMouseTo(right_edge + 50, y);
1024 UpdateAutoHideStateNow();
1025 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1027 // Moving to the left edge of the secondary display without first crossing
1028 // the primary display's right aligned shelf first should not show the shelf.
1029 generator.MoveMouseTo(right_edge + 2, y);
1030 UpdateAutoHideStateNow();
1031 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1034 // Assertions around the lock screen showing.
1035 TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
1036 if (!SupportsHostWindowResize())
1037 return;
1039 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1040 // it isn't over the shelf.
1041 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1042 gfx::Point());
1043 generator.MoveMouseTo(0, 0);
1045 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1046 shelf->SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
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);
1053 widget->Maximize();
1054 widget->Show();
1055 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1056 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1058 aura::Window* root = Shell::GetPrimaryRootWindow();
1059 // LayoutShelf() forces the animation to completion, at which point the
1060 // shelf should go off the screen.
1061 shelf->LayoutShelf();
1062 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideSize,
1063 GetShelfWidget()->GetWindowBoundsInScreen().y());
1065 aura::Window* lock_container = Shell::GetContainer(
1066 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer);
1068 views::Widget* lock_widget = new views::Widget;
1069 views::Widget::InitParams lock_params(
1070 views::Widget::InitParams::TYPE_WINDOW);
1071 lock_params.bounds = gfx::Rect(0, 0, 200, 200);
1072 params.context = CurrentContext();
1073 lock_params.parent = lock_container;
1074 // Widget is now owned by the parent window.
1075 lock_widget->Init(lock_params);
1076 lock_widget->Maximize();
1077 lock_widget->Show();
1079 // Lock the screen.
1080 LockScreen();
1081 // Showing a widget in the lock screen should force the shelf to be visibile.
1082 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1084 UnlockScreen();
1085 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1088 // Assertions around SetAutoHideBehavior.
1089 TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) {
1090 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1091 // it isn't over the shelf.
1092 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1093 gfx::Point());
1094 generator.MoveMouseTo(0, 0);
1096 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1097 views::Widget* widget = new views::Widget;
1098 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1099 params.bounds = gfx::Rect(0, 0, 200, 200);
1100 params.context = CurrentContext();
1101 // Widget is now owned by the parent window.
1102 widget->Init(params);
1103 widget->Show();
1104 aura::Window* window = widget->GetNativeWindow();
1105 gfx::Rect display_bounds(
1106 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
1108 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1109 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1111 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1112 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1114 widget->Maximize();
1115 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1116 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1117 window).work_area().bottom(),
1118 widget->GetWorkAreaBoundsInScreen().bottom());
1120 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1121 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1122 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1123 window).work_area().bottom(),
1124 widget->GetWorkAreaBoundsInScreen().bottom());
1126 ui::ScopedAnimationDurationScaleMode animation_duration(
1127 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
1129 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1130 ShelfWidget* shelf_widget = GetShelfWidget();
1131 EXPECT_TRUE(shelf_widget->status_area_widget()->IsVisible());
1132 StepWidgetLayerAnimatorToEnd(shelf_widget);
1133 StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget());
1134 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1135 EXPECT_EQ(Shell::GetScreen()->GetDisplayNearestWindow(
1136 window).work_area().bottom(),
1137 widget->GetWorkAreaBoundsInScreen().bottom());
1140 // Basic assertions around the dimming of the shelf.
1141 TEST_F(ShelfLayoutManagerTest, DimmingBehavior) {
1142 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1143 // it isn't over the shelf.
1144 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1145 gfx::Point());
1146 generator.MoveMouseTo(0, 0);
1148 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1149 shelf->shelf_widget()->DisableDimmingAnimationsForTest();
1151 views::Widget* widget = new views::Widget;
1152 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1153 params.bounds = gfx::Rect(0, 0, 200, 200);
1154 params.context = CurrentContext();
1155 // Widget is now owned by the parent window.
1156 widget->Init(params);
1157 widget->Show();
1158 aura::Window* window = widget->GetNativeWindow();
1159 gfx::Rect display_bounds(
1160 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
1162 gfx::Point off_shelf = display_bounds.CenterPoint();
1163 gfx::Point on_shelf =
1164 shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1166 // Test there is no dimming object active at this point.
1167 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1168 EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
1169 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1170 EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
1172 // After maximization, the shelf should be visible and the dimmer created.
1173 widget->Maximize();
1175 on_shelf = shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1176 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1178 // Moving the mouse off the shelf should dim the bar.
1179 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1180 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1182 // Adding touch events outside the shelf should still keep the shelf in
1183 // dimmed state.
1184 generator.PressTouch();
1185 generator.MoveTouch(off_shelf);
1186 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1187 // Move the touch into the shelf area should undim.
1188 generator.MoveTouch(on_shelf);
1189 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1190 generator.ReleaseTouch();
1191 // And a release dims again.
1192 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1194 // Moving the mouse on the shelf should undim the bar.
1195 generator.MoveMouseTo(on_shelf);
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.MoveTouch(on_shelf);
1207 generator.ReleaseTouch();
1209 // After restore, the dimming object should be deleted again.
1210 widget->Restore();
1211 EXPECT_EQ(-1, shelf->shelf_widget()->GetDimmingAlphaForTest());
1214 // Test that dimming works correctly with multiple displays.
1215 TEST_F(ShelfLayoutManagerTest, DimmingBehaviorDualDisplay) {
1216 if (!SupportsMultipleDisplays())
1217 return;
1219 // Create two displays.
1220 Shell* shell = Shell::GetInstance();
1221 UpdateDisplay("0+0-200x200,+200+0-100x100");
1222 EXPECT_EQ(2U, shell->display_manager()->GetNumDisplays());
1224 WindowTreeHostManager* window_tree_host_manager =
1225 shell->window_tree_host_manager();
1226 aura::Window::Windows root_windows =
1227 window_tree_host_manager->GetAllRootWindows();
1228 EXPECT_EQ(root_windows.size(), 2U);
1230 std::vector<ShelfWidget*> shelf_widgets;
1231 for (auto& root_window : root_windows) {
1232 ShelfLayoutManager* shelf =
1233 GetRootWindowController(root_window)->GetShelfLayoutManager();
1234 shelf_widgets.push_back(shelf->shelf_widget());
1236 // For disabling the dimming animation to work, the animation must be
1237 // disabled prior to creating the dimmer.
1238 shelf_widgets.back()->DisableDimmingAnimationsForTest();
1240 // Create a maximized window to create the dimmer.
1241 views::Widget* widget = new views::Widget;
1242 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1243 params.context = root_window;
1244 params.bounds = root_window->GetBoundsInScreen();
1245 params.show_state = ui::SHOW_STATE_MAXIMIZED;
1246 widget->Init(params);
1247 widget->Show();
1250 ui::test::EventGenerator& generator(GetEventGenerator());
1252 generator.MoveMouseTo(root_windows[0]->GetBoundsInScreen().CenterPoint());
1253 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest());
1254 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest());
1256 generator.MoveMouseTo(
1257 shelf_widgets[0]->GetWindowBoundsInScreen().CenterPoint());
1258 EXPECT_EQ(0, shelf_widgets[0]->GetDimmingAlphaForTest());
1259 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest());
1261 generator.MoveMouseTo(
1262 shelf_widgets[1]->GetWindowBoundsInScreen().CenterPoint());
1263 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest());
1264 EXPECT_EQ(0, shelf_widgets[1]->GetDimmingAlphaForTest());
1266 generator.MoveMouseTo(root_windows[1]->GetBoundsInScreen().CenterPoint());
1267 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest());
1268 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest());
1271 // Assertions around the dimming of the shelf in conjunction with menus.
1272 TEST_F(ShelfLayoutManagerTest, DimmingBehaviorWithMenus) {
1273 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1274 // it isn't over the shelf.
1275 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1276 gfx::Point());
1277 generator.MoveMouseTo(0, 0);
1279 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1280 shelf->shelf_widget()->DisableDimmingAnimationsForTest();
1282 views::Widget* widget = new views::Widget;
1283 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1284 params.bounds = gfx::Rect(0, 0, 200, 200);
1285 params.context = CurrentContext();
1286 // Widget is now owned by the parent window.
1287 widget->Init(params);
1288 widget->Show();
1289 aura::Window* window = widget->GetNativeWindow();
1290 gfx::Rect display_bounds(
1291 Shell::GetScreen()->GetDisplayNearestWindow(window).bounds());
1293 // After maximization, the shelf should be visible and the dimmer created.
1294 widget->Maximize();
1296 gfx::Point off_shelf = display_bounds.CenterPoint();
1297 gfx::Point on_shelf =
1298 shelf->shelf_widget()->GetWindowBoundsInScreen().CenterPoint();
1300 // Moving the mouse on the shelf should undim the bar.
1301 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1302 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1304 // Simulate a menu opening.
1305 shelf->shelf_widget()->ForceUndimming(true);
1307 // Moving the mouse off the shelf should not dim the bar.
1308 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1309 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1311 // No matter what the touch events do, the shelf should stay undimmed.
1312 generator.PressTouch();
1313 generator.MoveTouch(off_shelf);
1314 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1315 generator.MoveTouch(on_shelf);
1316 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1317 generator.MoveTouch(off_shelf);
1318 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1319 generator.ReleaseTouch();
1320 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1322 // "Closing the menu" should now turn off the menu since no event is inside
1323 // the shelf any longer.
1324 shelf->shelf_widget()->ForceUndimming(false);
1325 EXPECT_LT(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1327 // Moving the mouse again on the shelf which should undim the bar again.
1328 // This time we check that the bar stays undimmed when the mouse remains on
1329 // the bar and the "menu gets closed".
1330 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1331 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1332 shelf->shelf_widget()->ForceUndimming(true);
1333 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1334 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1335 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1336 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1337 shelf->shelf_widget()->ForceUndimming(true);
1338 EXPECT_EQ(0, shelf->shelf_widget()->GetDimmingAlphaForTest());
1341 // Verifies the shelf is visible when status/shelf is focused.
1342 TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrShelfFocused) {
1343 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1344 // it isn't over the shelf.
1345 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1346 gfx::Point());
1347 generator.MoveMouseTo(0, 0);
1349 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1350 views::Widget* widget = new views::Widget;
1351 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1352 params.bounds = gfx::Rect(0, 0, 200, 200);
1353 params.context = CurrentContext();
1354 // Widget is now owned by the parent window.
1355 widget->Init(params);
1356 widget->Show();
1357 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1358 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1359 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1361 // Focus the shelf. Have to go through the focus cycler as normal focus
1362 // requests to it do nothing.
1363 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
1364 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1366 widget->Activate();
1367 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1369 // Trying to activate the status should fail, since we only allow activating
1370 // it when the user is using the keyboard (i.e. through FocusCycler).
1371 GetShelfWidget()->status_area_widget()->Activate();
1372 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1374 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
1375 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1378 // Makes sure shelf will be visible when app list opens as shelf is in
1379 // SHELF_VISIBLE state,and toggling app list won't change shelf
1380 // visibility state.
1381 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) {
1382 Shell* shell = Shell::GetInstance();
1383 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1384 shelf->LayoutShelf();
1385 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1387 // Create a normal unmaximized windowm shelf should be visible.
1388 aura::Window* window = CreateTestWindow();
1389 window->SetBounds(gfx::Rect(0, 0, 100, 100));
1390 window->Show();
1391 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1392 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1394 // Show app list and the shelf stays visible.
1395 shell->ShowAppList(NULL);
1396 EXPECT_TRUE(shell->GetAppListTargetVisibility());
1397 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1399 // Hide app list and the shelf stays visible.
1400 shell->DismissAppList();
1401 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1402 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1405 // Makes sure shelf will be shown with SHELF_AUTO_HIDE_SHOWN state
1406 // when app list opens as shelf is in SHELF_AUTO_HIDE state, and
1407 // toggling app list won't change shelf visibility state.
1408 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) {
1409 Shell* shell = Shell::GetInstance();
1410 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1411 shelf->LayoutShelf();
1412 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1414 // Create a window and show it in maximized state.
1415 aura::Window* window = CreateTestWindow();
1416 window->SetBounds(gfx::Rect(0, 0, 100, 100));
1417 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1418 window->Show();
1419 wm::ActivateWindow(window);
1421 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1422 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1424 // Show app list.
1425 shell->ShowAppList(NULL);
1426 // The shelf's auto hide state won't be changed until the timer fires, so
1427 // calling shell->UpdateShelfVisibility() is kind of manually helping it to
1428 // update the state.
1429 shell->UpdateShelfVisibility();
1430 EXPECT_TRUE(shell->GetAppListTargetVisibility());
1431 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1432 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1434 // Hide app list.
1435 shell->DismissAppList();
1436 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1437 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1440 // Makes sure that when we have dual displays, with one or both shelves are set
1441 // to AutoHide, viewing the AppList on one of them doesn't unhide the other
1442 // hidden shelf.
1443 TEST_F(ShelfLayoutManagerTest, DualDisplayOpenAppListWithShelfAutoHideState) {
1444 if (!SupportsMultipleDisplays())
1445 return;
1447 // Create two displays.
1448 Shell* shell = Shell::GetInstance();
1449 DisplayManager* display_manager = shell->display_manager();
1450 EXPECT_EQ(1U, display_manager->GetNumDisplays());
1451 UpdateDisplay("0+0-200x200,+200+0-100x100");
1452 EXPECT_EQ(2U, display_manager->GetNumDisplays());
1454 WindowTreeHostManager* window_tree_host_manager =
1455 shell->window_tree_host_manager();
1456 aura::Window::Windows root_windows =
1457 window_tree_host_manager->GetAllRootWindows();
1458 EXPECT_EQ(root_windows.size(), 2U);
1460 // Get the shelves in both displays and set them to be 'AutoHide'.
1461 ShelfLayoutManager* shelf_1 =
1462 GetRootWindowController(root_windows[0])->GetShelfLayoutManager();
1463 ShelfLayoutManager* shelf_2 =
1464 GetRootWindowController(root_windows[1])->GetShelfLayoutManager();
1465 EXPECT_NE(shelf_1, shelf_2);
1466 EXPECT_NE(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1467 shelf_2->shelf_widget()->GetNativeWindow()->
1468 GetRootWindow());
1469 shelf_1->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1470 shelf_1->LayoutShelf();
1471 shelf_2->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1472 shelf_2->LayoutShelf();
1474 // Create a window in each display and show them in maximized state.
1475 aura::Window* window_1 =
1476 CreateTestWindowInParent(root_windows[0]);
1477 window_1->SetBounds(gfx::Rect(0, 0, 100, 100));
1478 window_1->SetProperty(aura::client::kShowStateKey,
1479 ui::SHOW_STATE_MAXIMIZED);
1480 window_1->Show();
1481 aura::Window* window_2 =
1482 CreateTestWindowInParent(root_windows[1]);
1483 window_2->SetBounds(gfx::Rect(201, 0, 100, 100));
1484 window_2->SetProperty(aura::client::kShowStateKey,
1485 ui::SHOW_STATE_MAXIMIZED);
1486 window_2->Show();
1488 EXPECT_EQ(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1489 window_1->GetRootWindow());
1490 EXPECT_EQ(shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1491 window_2->GetRootWindow());
1493 // Activate one window in one display and manually trigger the update of shelf
1494 // visibility.
1495 wm::ActivateWindow(window_1);
1496 shell->UpdateShelfVisibility();
1498 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1499 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->visibility_state());
1500 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->visibility_state());
1501 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->auto_hide_state());
1502 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->auto_hide_state());
1504 // Show app list.
1505 shell->ShowAppList(NULL);
1506 shell->UpdateShelfVisibility();
1508 // Only the shelf in the active display should be shown, the other is hidden.
1509 EXPECT_TRUE(shell->GetAppListTargetVisibility());
1510 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->visibility_state());
1511 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_1->auto_hide_state());
1512 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->visibility_state());
1513 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->auto_hide_state());
1515 // Hide app list, both shelves should be hidden.
1516 shell->DismissAppList();
1517 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1518 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->visibility_state());
1519 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->visibility_state());
1520 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->auto_hide_state());
1521 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->auto_hide_state());
1524 // Makes sure the shelf will be hidden when we have a fullscreen window, and it
1525 // will unhide when we open the app list.
1526 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfHiddenState) {
1527 Shell* shell = Shell::GetInstance();
1528 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1529 // For shelf to be visible, app list is not open in initial state.
1530 shelf->LayoutShelf();
1532 // Create a window and make it full screen.
1533 aura::Window* window = CreateTestWindow();
1534 window->SetBounds(gfx::Rect(0, 0, 100, 100));
1535 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
1536 window->Show();
1537 wm::ActivateWindow(window);
1539 // App list and shelf is not shown.
1540 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1541 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1543 // Show app list.
1544 shell->ShowAppList(NULL);
1545 EXPECT_TRUE(shell->GetAppListTargetVisibility());
1546 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1548 // Hide app list.
1549 shell->DismissAppList();
1550 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1551 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1554 // Tests the correct behavior of the shelf when there is a system modal window
1555 // open when we have a single display.
1556 TEST_F(ShelfLayoutManagerTest, ShelfWithSystemModalWindowSingleDisplay) {
1557 Shell* shell = Shell::GetInstance();
1558 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1559 shelf->LayoutShelf();
1560 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1562 aura::Window* window = CreateTestWindow();
1563 window->SetBounds(gfx::Rect(0, 0, 100, 100));
1564 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1565 window->Show();
1566 wm::ActivateWindow(window);
1568 // Enable system modal dialog, and make sure shelf is still hidden.
1569 shell->SimulateModalWindowOpenForTesting(true);
1570 EXPECT_TRUE(shell->IsSystemModalWindowOpen());
1571 EXPECT_FALSE(wm::CanActivateWindow(window));
1572 shell->UpdateShelfVisibility();
1573 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1574 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1577 // Tests the correct behavior of the shelf when there is a system modal window
1578 // open when we have dual display.
1579 TEST_F(ShelfLayoutManagerTest, ShelfWithSystemModalWindowDualDisplay) {
1580 if (!SupportsMultipleDisplays())
1581 return;
1583 // Create two displays.
1584 Shell* shell = Shell::GetInstance();
1585 DisplayManager* display_manager = shell->display_manager();
1586 UpdateDisplay("200x200,100x100");
1587 EXPECT_EQ(2U, display_manager->GetNumDisplays());
1589 WindowTreeHostManager* window_tree_host_manager =
1590 shell->window_tree_host_manager();
1591 aura::Window::Windows root_windows =
1592 window_tree_host_manager->GetAllRootWindows();
1593 EXPECT_EQ(2U, root_windows.size());
1595 // Get the shelves in both displays and set them to be 'AutoHide'.
1596 ShelfLayoutManager* shelf_1 =
1597 GetRootWindowController(root_windows[0])->GetShelfLayoutManager();
1598 ShelfLayoutManager* shelf_2 =
1599 GetRootWindowController(root_windows[1])->GetShelfLayoutManager();
1600 EXPECT_NE(shelf_1, shelf_2);
1601 EXPECT_NE(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1602 shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow());
1603 shelf_1->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1604 shelf_1->LayoutShelf();
1605 shelf_2->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1606 shelf_2->LayoutShelf();
1608 // Create a window in each display and show them in maximized state.
1609 aura::Window* window_1 = CreateTestWindowInParent(root_windows[0]);
1610 window_1->SetBounds(gfx::Rect(0, 0, 100, 100));
1611 window_1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1612 window_1->Show();
1613 aura::Window* window_2 = CreateTestWindowInParent(root_windows[1]);
1614 window_2->SetBounds(gfx::Rect(201, 0, 100, 100));
1615 window_2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1616 window_2->Show();
1618 EXPECT_EQ(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1619 window_1->GetRootWindow());
1620 EXPECT_EQ(shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1621 window_2->GetRootWindow());
1622 EXPECT_TRUE(window_1->IsVisible());
1623 EXPECT_TRUE(window_2->IsVisible());
1625 // Enable system modal dialog, and make sure both shelves are still hidden.
1626 shell->SimulateModalWindowOpenForTesting(true);
1627 EXPECT_TRUE(shell->IsSystemModalWindowOpen());
1628 EXPECT_FALSE(wm::CanActivateWindow(window_1));
1629 EXPECT_FALSE(wm::CanActivateWindow(window_2));
1630 shell->UpdateShelfVisibility();
1631 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->visibility_state());
1632 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->auto_hide_state());
1633 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->visibility_state());
1634 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->auto_hide_state());
1637 // Tests that the shelf is only hidden for a fullscreen window at the front and
1638 // toggles visibility when another window is activated.
1639 TEST_F(ShelfLayoutManagerTest, FullscreenWindowInFrontHidesShelf) {
1640 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1642 // Create a window and make it full screen.
1643 aura::Window* window1 = CreateTestWindow();
1644 window1->SetBounds(gfx::Rect(0, 0, 100, 100));
1645 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
1646 window1->Show();
1648 aura::Window* window2 = CreateTestWindow();
1649 window2->SetBounds(gfx::Rect(0, 0, 100, 100));
1650 window2->Show();
1652 wm::GetWindowState(window1)->Activate();
1653 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1655 wm::GetWindowState(window2)->Activate();
1656 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1658 wm::GetWindowState(window1)->Activate();
1659 EXPECT_EQ(SHELF_HIDDEN, shelf->visibility_state());
1662 // Test the behavior of the shelf when a window on one display is fullscreen
1663 // but the other display has the active window.
1664 TEST_F(ShelfLayoutManagerTest, FullscreenWindowOnSecondDisplay) {
1665 if (!SupportsMultipleDisplays())
1666 return;
1668 UpdateDisplay("800x600,800x600");
1669 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1670 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1671 Shell::RootWindowControllerList root_window_controllers =
1672 Shell::GetAllRootWindowControllers();
1674 // Create windows on either display.
1675 aura::Window* window1 = CreateTestWindow();
1676 window1->SetBoundsInScreen(
1677 gfx::Rect(0, 0, 100, 100),
1678 display_manager->GetDisplayAt(0));
1679 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
1680 window1->Show();
1682 aura::Window* window2 = CreateTestWindow();
1683 window2->SetBoundsInScreen(
1684 gfx::Rect(800, 0, 100, 100),
1685 display_manager->GetDisplayAt(1));
1686 window2->Show();
1688 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
1689 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
1691 wm::GetWindowState(window2)->Activate();
1692 EXPECT_EQ(SHELF_HIDDEN,
1693 root_window_controllers[0]->GetShelfLayoutManager()->visibility_state());
1694 EXPECT_EQ(SHELF_VISIBLE,
1695 root_window_controllers[1]->GetShelfLayoutManager()->visibility_state());
1699 #if defined(OS_WIN)
1700 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1701 #define MAYBE_SetAlignment DISABLED_SetAlignment
1702 #else
1703 #define MAYBE_SetAlignment SetAlignment
1704 #endif
1706 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT, TOP).
1707 TEST_F(ShelfLayoutManagerTest, MAYBE_SetAlignment) {
1708 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1709 // Force an initial layout.
1710 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1711 shelf->LayoutShelf();
1712 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1714 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
1715 gfx::Rect shelf_bounds(
1716 GetShelfWidget()->GetWindowBoundsInScreen());
1717 const gfx::Screen* screen = Shell::GetScreen();
1718 gfx::Display display =
1719 screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1720 ASSERT_NE(-1, display.id());
1721 EXPECT_EQ(shelf->GetIdealBounds().width(),
1722 display.GetWorkAreaInsets().left());
1723 EXPECT_GE(
1724 shelf_bounds.width(),
1725 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1726 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetSystemTray()->shelf_alignment());
1727 StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
1728 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen());
1729 EXPECT_GE(status_bounds.width(),
1730 status_area_widget->GetContentsView()->GetPreferredSize().width());
1731 EXPECT_EQ(shelf->GetIdealBounds().width(),
1732 display.GetWorkAreaInsets().left());
1733 EXPECT_EQ(0, display.GetWorkAreaInsets().top());
1734 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
1735 EXPECT_EQ(0, display.GetWorkAreaInsets().right());
1736 EXPECT_EQ(display.bounds().x(), shelf_bounds.x());
1737 EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
1738 EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
1739 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1740 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1741 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1742 display.GetWorkAreaInsets().left());
1743 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize, display.work_area().x());
1745 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1746 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
1747 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1748 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1749 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1750 ASSERT_NE(-1, display.id());
1751 EXPECT_EQ(shelf->GetIdealBounds().width(),
1752 display.GetWorkAreaInsets().right());
1753 EXPECT_GE(shelf_bounds.width(),
1754 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1755 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment());
1756 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
1757 EXPECT_GE(status_bounds.width(),
1758 status_area_widget->GetContentsView()->GetPreferredSize().width());
1759 EXPECT_EQ(shelf->GetIdealBounds().width(),
1760 display.GetWorkAreaInsets().right());
1761 EXPECT_EQ(0, display.GetWorkAreaInsets().top());
1762 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
1763 EXPECT_EQ(0, display.GetWorkAreaInsets().left());
1764 EXPECT_EQ(display.work_area().right(), shelf_bounds.x());
1765 EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
1766 EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
1767 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1768 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1769 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1770 display.GetWorkAreaInsets().right());
1771 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1772 display.bounds().right() - display.work_area().right());
1774 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1775 shelf->SetAlignment(SHELF_ALIGNMENT_TOP);
1776 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1777 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1778 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1779 ASSERT_NE(-1, display.id());
1780 EXPECT_EQ(shelf->GetIdealBounds().height(),
1781 display.GetWorkAreaInsets().top());
1782 EXPECT_GE(shelf_bounds.height(),
1783 GetShelfWidget()->GetContentsView()->GetPreferredSize().height());
1784 EXPECT_EQ(SHELF_ALIGNMENT_TOP, GetSystemTray()->shelf_alignment());
1785 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
1786 EXPECT_GE(status_bounds.height(),
1787 status_area_widget->GetContentsView()->GetPreferredSize().height());
1788 EXPECT_EQ(shelf->GetIdealBounds().height(),
1789 display.GetWorkAreaInsets().top());
1790 EXPECT_EQ(0, display.GetWorkAreaInsets().right());
1791 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
1792 EXPECT_EQ(0, display.GetWorkAreaInsets().left());
1793 EXPECT_EQ(display.work_area().y(), shelf_bounds.bottom());
1794 EXPECT_EQ(display.bounds().x(), shelf_bounds.x());
1795 EXPECT_EQ(display.bounds().width(), shelf_bounds.width());
1796 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1797 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1798 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1799 display.GetWorkAreaInsets().top());
1800 EXPECT_EQ(ShelfLayoutManager::kAutoHideSize,
1801 display.work_area().y() - display.bounds().y());
1804 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) {
1805 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1806 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1807 views::Widget* widget = new views::Widget;
1808 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1809 params.bounds = gfx::Rect(0, 0, 200, 200);
1810 params.context = CurrentContext();
1811 widget->Init(params);
1812 widget->Show();
1813 widget->Maximize();
1815 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
1817 aura::Window* window = widget->GetNativeWindow();
1818 shelf->LayoutShelf();
1820 gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen();
1821 gfx::Rect bounds_shelf = window->bounds();
1823 // Edge swipe when SHELF_VISIBLE should not change visibility state.
1824 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1825 generator.GestureEdgeSwipe();
1826 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
1828 // Edge swipe when AUTO_HIDE_HIDDEN should change to AUTO_HIDE_SHOWN.
1829 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1830 shelf->LayoutShelf();
1831 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1832 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1833 generator.GestureEdgeSwipe();
1834 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1835 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1837 widget->SetFullscreen(true);
1838 wm::GetWindowState(window)->set_hide_shelf_when_fullscreen(false);
1839 shelf->UpdateVisibilityState();
1841 // Edge swipe in fullscreen + AUTO_HIDE_HIDDEN should show the shelf and
1842 // remain fullscreen.
1843 EXPECT_TRUE(widget->IsFullscreen());
1844 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1845 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1846 generator.GestureEdgeSwipe();
1847 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
1848 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1849 EXPECT_TRUE(widget->IsFullscreen());
1852 // Tests that gesture edge swipe events are forwarded to the right shelf on the
1853 // right monitor (crbug.com/449851).
1854 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipeMultiMonitor) {
1855 if (!SupportsMultipleDisplays())
1856 return;
1858 // Create two displays.
1859 Shell* shell = Shell::GetInstance();
1860 DisplayManager* display_manager = shell->display_manager();
1861 UpdateDisplay("200x200,100x100");
1862 ASSERT_EQ(2U, display_manager->GetNumDisplays());
1864 auto root_window_controllers = Shell::GetAllRootWindowControllers();
1865 ASSERT_EQ(2U, root_window_controllers.size());
1866 ShelfLayoutManager* shelf_1 =
1867 root_window_controllers[0]->GetShelfLayoutManager();
1868 ShelfLayoutManager* shelf_2 =
1869 root_window_controllers[1]->GetShelfLayoutManager();
1871 // Create two maximized windows, one in each display.
1872 aura::Window* window_1 =
1873 CreateTestWindowInParent(root_window_controllers[0]->GetRootWindow());
1874 window_1->SetBounds(gfx::Rect(0, 0, 100, 100));
1875 window_1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1876 window_1->Show();
1877 aura::Window* window_2 =
1878 CreateTestWindowInParent(root_window_controllers[1]->GetRootWindow());
1879 window_2->SetBounds(gfx::Rect(201, 0, 100, 100));
1880 window_2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1881 window_2->Show();
1883 // Make sure both are set to auto-hide and both are hidden.
1884 shelf_1->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1885 shelf_2->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1886 shelf_1->LayoutShelf();
1887 shelf_2->LayoutShelf();
1888 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->visibility_state());
1889 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->visibility_state());
1890 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->auto_hide_state());
1891 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->auto_hide_state());
1893 ui::test::EventGenerator monitor_1_generator(
1894 root_window_controllers[0]->GetRootWindow());
1895 ui::test::EventGenerator monitor_2_generator(
1896 root_window_controllers[1]->GetRootWindow());
1898 // An edge swipe in one display should only affect the shelf in that display.
1899 monitor_1_generator.GestureEdgeSwipe();
1900 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->visibility_state());
1901 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->visibility_state());
1902 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_1->auto_hide_state());
1903 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->auto_hide_state());
1905 // Back to normal after an update.
1906 shell->UpdateShelfVisibility();
1907 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->visibility_state());
1908 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->visibility_state());
1909 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->auto_hide_state());
1910 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->auto_hide_state());
1912 monitor_2_generator.GestureEdgeSwipe();
1913 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->visibility_state());
1914 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->visibility_state());
1915 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->auto_hide_state());
1916 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_2->auto_hide_state());
1919 #if defined(OS_WIN)
1920 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1921 #define MAYBE_GestureDrag DISABLED_GestureDrag
1922 #else
1923 #define MAYBE_GestureDrag GestureDrag
1924 #endif
1926 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
1927 // Slop is an implementation detail of gesture recognition, and complicates
1928 // these tests. Ignore it.
1929 ui::GestureConfiguration::GetInstance()
1930 ->set_max_touch_move_in_pixels_for_click(0);
1931 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1933 SCOPED_TRACE("BOTTOM");
1934 RunGestureDragTests(gfx::Vector2d(0, 120));
1938 SCOPED_TRACE("LEFT");
1939 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
1940 RunGestureDragTests(gfx::Vector2d(-120, 0));
1944 SCOPED_TRACE("RIGHT");
1945 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
1946 RunGestureDragTests(gfx::Vector2d(120, 0));
1950 TEST_F(ShelfLayoutManagerTest, WindowVisibilityDisablesAutoHide) {
1951 if (!SupportsMultipleDisplays())
1952 return;
1954 UpdateDisplay("800x600,800x600");
1955 ShelfLayoutManager* shelf = GetShelfLayoutManager();
1956 shelf->LayoutShelf();
1957 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1959 // Create a visible window so auto-hide behavior is enforced
1960 views::Widget* dummy = CreateTestWidget();
1962 // Window visible => auto hide behaves normally.
1963 shelf->UpdateVisibilityState();
1964 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1966 // Window minimized => auto hide disabled.
1967 dummy->Minimize();
1968 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1970 // Window closed => auto hide disabled.
1971 dummy->CloseNow();
1972 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1974 // Multiple window test
1975 views::Widget* window1 = CreateTestWidget();
1976 views::Widget* window2 = CreateTestWidget();
1978 // both visible => normal autohide
1979 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1981 // either minimzed => normal autohide
1982 window2->Minimize();
1983 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1984 window2->Restore();
1985 window1->Minimize();
1986 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1988 // both minimized => disable auto hide
1989 window2->Minimize();
1990 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1992 // Test moving windows to/from other display.
1993 window2->Restore();
1994 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
1995 // Move to second display.
1996 window2->SetBounds(gfx::Rect(850, 50, 50, 50));
1997 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
1998 // Move back to primary display.
1999 window2->SetBounds(gfx::Rect(50, 50, 50, 50));
2000 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
2003 // Test that the shelf animates back to its normal position upon a user
2004 // completing a gesture drag.
2005 TEST_F(ShelfLayoutManagerTest, ShelfAnimatesWhenGestureComplete) {
2006 if (!SupportsHostWindowResize())
2007 return;
2009 // Test the shelf animates back to its original visible bounds when it is
2010 // dragged when there are no visible windows.
2011 ShelfLayoutManager* shelf = GetShelfLayoutManager();
2012 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2013 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
2014 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
2015 gfx::Rect visible_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
2017 // Enable animations so that we can make sure that they occur.
2018 ui::ScopedAnimationDurationScaleMode regular_animations(
2019 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
2021 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
2022 gfx::Rect shelf_bounds_in_screen =
2023 GetShelfWidget()->GetWindowBoundsInScreen();
2024 gfx::Point start(shelf_bounds_in_screen.CenterPoint());
2025 gfx::Point end(start.x(), shelf_bounds_in_screen.bottom());
2026 generator.GestureScrollSequence(start, end,
2027 base::TimeDelta::FromMilliseconds(10), 5);
2028 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
2029 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
2031 ShelfAnimationWaiter waiter(visible_bounds);
2032 // Wait till the animation completes and check that it occurred.
2033 waiter.WaitTillDoneAnimating();
2034 EXPECT_TRUE(waiter.WasValidAnimation());
2037 // Create a visible window so auto-hide behavior is enforced.
2038 CreateTestWidget();
2040 // Get the bounds of the shelf when it is hidden.
2041 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
2042 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
2043 gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
2046 // Enable the animations so that we can make sure they do occur.
2047 ui::ScopedAnimationDurationScaleMode regular_animations(
2048 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
2050 gfx::Point start =
2051 GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
2052 gfx::Point end(start.x(), start.y() - 100);
2053 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
2055 // Test that the shelf animates to the visible bounds after a swipe up on
2056 // the auto hidden shelf.
2057 generator.GestureScrollSequence(start, end,
2058 base::TimeDelta::FromMilliseconds(10), 1);
2059 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
2060 ShelfAnimationWaiter waiter1(visible_bounds);
2061 waiter1.WaitTillDoneAnimating();
2062 EXPECT_TRUE(waiter1.WasValidAnimation());
2064 // Test that the shelf animates to the auto hidden bounds after a swipe up
2065 // on the visible shelf.
2066 EXPECT_EQ(SHELF_VISIBLE, shelf->visibility_state());
2067 generator.GestureScrollSequence(start, end,
2068 base::TimeDelta::FromMilliseconds(10), 1);
2069 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
2070 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
2071 ShelfAnimationWaiter waiter2(auto_hidden_bounds);
2072 waiter2.WaitTillDoneAnimating();
2073 EXPECT_TRUE(waiter2.WasValidAnimation());
2077 TEST_F(ShelfLayoutManagerTest, ShelfFlickerOnTrayActivation) {
2078 ShelfLayoutManager* shelf = GetShelfLayoutManager();
2080 // Create a visible window so auto-hide behavior is enforced.
2081 CreateTestWidget();
2083 // Turn on auto-hide for the shelf.
2084 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2085 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
2086 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
2088 // Show the status menu. That should make the shelf visible again.
2089 Shell::GetInstance()->accelerator_controller()->PerformActionIfEnabled(
2090 SHOW_SYSTEM_TRAY_BUBBLE);
2091 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->visibility_state());
2092 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->auto_hide_state());
2093 EXPECT_TRUE(GetSystemTray()->HasSystemBubble());
2096 TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) {
2097 // Make sure the shelf is always visible.
2098 ShelfLayoutManager* shelf = GetShelfLayoutManager();
2099 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
2100 shelf->LayoutShelf();
2102 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
2103 params.bounds = gfx::Rect(0, 0, 200, 200);
2104 params.context = CurrentContext();
2105 views::Widget* widget_one = CreateTestWidgetWithParams(params);
2106 widget_one->Maximize();
2108 views::Widget* widget_two = CreateTestWidgetWithParams(params);
2109 widget_two->Maximize();
2110 widget_two->Activate();
2112 // Both windows are maximized. They should be of the same size.
2113 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
2114 widget_two->GetNativeWindow()->bounds().ToString());
2115 int area_when_shelf_shown =
2116 widget_one->GetNativeWindow()->bounds().size().GetArea();
2118 // Now hide the shelf.
2119 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2121 // Both windows should be resized according to the shelf status.
2122 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
2123 widget_two->GetNativeWindow()->bounds().ToString());
2124 // Resized to small.
2125 EXPECT_LT(area_when_shelf_shown,
2126 widget_one->GetNativeWindow()->bounds().size().GetArea());
2128 // Now show the shelf.
2129 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
2131 // Again both windows should be of the same size.
2132 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
2133 widget_two->GetNativeWindow()->bounds().ToString());
2134 EXPECT_EQ(area_when_shelf_shown,
2135 widget_one->GetNativeWindow()->bounds().size().GetArea());
2138 // Confirm that the shelf is dimmed only when content is maximized and
2139 // shelf is not autohidden.
2140 TEST_F(ShelfLayoutManagerTest, Dimming) {
2141 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
2142 scoped_ptr<aura::Window> w1(CreateTestWindow());
2143 w1->Show();
2144 wm::ActivateWindow(w1.get());
2146 // Normal window doesn't dim shelf.
2147 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
2148 ShelfWidget* shelf = GetShelfWidget();
2149 EXPECT_FALSE(shelf->GetDimsShelf());
2151 // Maximized window does.
2152 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
2153 EXPECT_TRUE(shelf->GetDimsShelf());
2155 // Change back to normal stops dimming.
2156 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
2157 EXPECT_FALSE(shelf->GetDimsShelf());
2159 // Changing back to maximized dims again.
2160 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
2161 EXPECT_TRUE(shelf->GetDimsShelf());
2163 // Changing shelf to autohide stops dimming.
2164 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2165 EXPECT_FALSE(shelf->GetDimsShelf());
2168 // Make sure that the shelf will not hide if the mouse is between a bubble and
2169 // the shelf.
2170 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) {
2171 ShelfLayoutManager* shelf = GetShelfLayoutManager();
2172 StatusAreaWidget* status_area_widget =
2173 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
2174 SystemTray* tray = GetSystemTray();
2176 // Create a visible window so auto-hide behavior is enforced.
2177 CreateTestWidget();
2179 shelf->LayoutShelf();
2180 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
2182 // Make two iterations - first without a message bubble which should make
2183 // the shelf disappear and then with a message bubble which should keep it
2184 // visible.
2185 for (int i = 0; i < 2; i++) {
2186 // Make sure the shelf is visible and position the mouse over it. Then
2187 // allow auto hide.
2188 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
2189 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2190 gfx::Point center =
2191 status_area_widget->GetWindowBoundsInScreen().CenterPoint();
2192 generator.MoveMouseTo(center.x(), center.y());
2193 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2194 EXPECT_TRUE(shelf->IsVisible());
2195 if (!i) {
2196 // In our first iteration we make sure there is no bubble.
2197 tray->CloseSystemBubble();
2198 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2199 } else {
2200 // In our second iteration we show a bubble.
2201 TestItem *item = new TestItem;
2202 tray->AddTrayItem(item);
2203 tray->ShowNotificationView(item);
2204 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2206 // Move the pointer over the edge of the shelf.
2207 generator.MoveMouseTo(
2208 center.x(), status_area_widget->GetWindowBoundsInScreen().y() - 8);
2209 shelf->UpdateVisibilityState();
2210 if (i) {
2211 EXPECT_TRUE(shelf->IsVisible());
2212 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2213 } else {
2214 EXPECT_FALSE(shelf->IsVisible());
2215 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2220 TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColor) {
2221 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
2223 scoped_ptr<aura::Window> w1(CreateTestWindow());
2224 w1->Show();
2225 wm::ActivateWindow(w1.get());
2226 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
2227 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
2228 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
2230 scoped_ptr<aura::Window> w2(CreateTestWindow());
2231 w2->Show();
2232 wm::ActivateWindow(w2.get());
2233 // Overlaps with shelf.
2234 w2->SetBounds(GetShelfLayoutManager()->GetIdealBounds());
2236 // Still background is 'maximized'.
2237 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
2239 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
2240 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
2241 w2->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MINIMIZED);
2242 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
2244 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
2245 EXPECT_EQ(SHELF_BACKGROUND_MAXIMIZED, GetShelfWidget()->GetBackgroundType());
2246 w1.reset();
2247 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget()->GetBackgroundType());
2250 // Verify that the shelf doesn't have the opaque background if it's auto-hide
2251 // status.
2252 TEST_F(ShelfLayoutManagerTest, ShelfBackgroundColorAutoHide) {
2253 EXPECT_EQ(SHELF_BACKGROUND_DEFAULT, GetShelfWidget ()->GetBackgroundType());
2255 GetShelfLayoutManager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2256 scoped_ptr<aura::Window> w1(CreateTestWindow());
2257 w1->Show();
2258 wm::ActivateWindow(w1.get());
2259 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
2260 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
2261 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
2264 #if defined(OS_CHROMEOS)
2265 #define MAYBE_StatusAreaHitBoxCoversEdge StatusAreaHitBoxCoversEdge
2266 #else
2267 #define MAYBE_StatusAreaHitBoxCoversEdge DISABLED_StatusAreaHitBoxCoversEdge
2268 #endif
2270 // Verify the hit bounds of the status area extend to the edge of the shelf.
2271 TEST_F(ShelfLayoutManagerTest, MAYBE_StatusAreaHitBoxCoversEdge) {
2272 UpdateDisplay("400x400");
2273 ShelfLayoutManager* shelf = GetShelfLayoutManager();
2274 StatusAreaWidget* status_area_widget =
2275 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
2276 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
2277 generator.MoveMouseTo(399,399);
2279 // Test bottom right pixel for bottom alignment.
2280 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2281 generator.ClickLeftButton();
2282 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2283 generator.ClickLeftButton();
2284 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2286 // Test bottom right pixel for right alignment.
2287 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
2288 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2289 generator.ClickLeftButton();
2290 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2291 generator.ClickLeftButton();
2292 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2294 // Test bottom left pixel for left alignment.
2295 generator.MoveMouseTo(0, 399);
2296 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
2297 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2298 generator.ClickLeftButton();
2299 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2300 generator.ClickLeftButton();
2301 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2304 // Tests that when the auto-hide behaviour is changed during an animation the
2305 // target bounds are updated to reflect the new state.
2306 TEST_F(ShelfLayoutManagerTest,
2307 ShelfAutoHideToggleDuringAnimationUpdatesBounds) {
2308 ShelfLayoutManager* shelf_manager = GetShelfLayoutManager();
2309 aura::Window* status_window = GetShelfWidget()->status_area_widget()->
2310 GetNativeView();
2311 gfx::Rect initial_bounds = status_window->bounds();
2313 ui::ScopedAnimationDurationScaleMode regular_animations(
2314 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
2315 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
2316 gfx::Rect hide_target_bounds = status_window->GetTargetBounds();
2317 EXPECT_GT(hide_target_bounds.y(), initial_bounds.y());
2319 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
2320 gfx::Rect reshow_target_bounds = status_window->GetTargetBounds();
2321 EXPECT_EQ(initial_bounds, reshow_target_bounds);
2324 // Tests that during shutdown, that window activation changes are properly
2325 // handled, and do not crash (crbug.com/458768)
2326 TEST_F(ShelfLayoutManagerTest, ShutdownHandlesWindowActivation) {
2327 ShelfLayoutManager* shelf_manager = GetShelfLayoutManager();
2328 ShelfWidget* shelf = GetShelfWidget();
2329 shelf_manager->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2331 aura::Window* window1 = CreateTestWindowInShellWithId(0);
2332 window1->SetBounds(gfx::Rect(0, 0, 100, 100));
2333 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
2334 window1->Show();
2335 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(0));
2336 window2->SetBounds(gfx::Rect(0, 0, 100, 100));
2337 window2->Show();
2338 wm::ActivateWindow(window1);
2340 shelf->ShutdownStatusAreaWidget();
2341 shelf_manager->PrepareForShutdown();
2343 // Deleting a focused maximized window will switch focus to |window2|. This
2344 // would normally cause the ShelfLayoutManager to update its state. However
2345 // during shutdown we want to handle this without crashing.
2346 delete window1;
2349 TEST_F(ShelfLayoutManagerTest, ShelfLayoutInUnifiedDesktop) {
2350 if (!SupportsMultipleDisplays())
2351 return;
2352 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true);
2354 UpdateDisplay("500x500, 500x500");
2356 StatusAreaWidget* status_area_widget =
2357 Shell::GetPrimaryRootWindowController()->shelf()->status_area_widget();
2358 EXPECT_TRUE(status_area_widget->IsVisible());
2359 // Shelf should be in the first display's area.
2360 // TODO: make this test more robust against changes in font, font size.
2361 EXPECT_EQ("353,453 147x47",
2362 status_area_widget->GetWindowBoundsInScreen().ToString());
2365 } // namespace ash