Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: ash/shelf/shelf_layout_manager_unittest.cc

Issue 2199023002: mash: Paritally migrate ShelfLayoutManagerTest to ash common types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add Windows workaround and comment for StatusAreaHitBoxCoversEdge. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/shelf/shelf_layout_manager.h" 5 #include "ash/shelf/shelf_layout_manager.h"
6 6
7 #include "ash/aura/wm_window_aura.h" 7 #include "ash/aura/wm_window_aura.h"
8 #include "ash/common/accelerators/accelerator_controller.h" 8 #include "ash/common/accelerators/accelerator_controller.h"
9 #include "ash/common/accelerators/accelerator_table.h" 9 #include "ash/common/accelerators/accelerator_table.h"
10 #include "ash/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
11 #include "ash/common/focus_cycler.h" 11 #include "ash/common/focus_cycler.h"
12 #include "ash/common/material_design/material_design_controller.h" 12 #include "ash/common/material_design/material_design_controller.h"
13 #include "ash/common/session/session_state_delegate.h" 13 #include "ash/common/session/session_state_delegate.h"
14 #include "ash/common/shelf/shelf_constants.h" 14 #include "ash/common/shelf/shelf_constants.h"
15 #include "ash/common/shell_window_ids.h" 15 #include "ash/common/shell_window_ids.h"
16 #include "ash/common/system/status_area_widget.h" 16 #include "ash/common/system/status_area_widget.h"
17 #include "ash/common/system/tray/system_tray.h" 17 #include "ash/common/system/tray/system_tray.h"
18 #include "ash/common/system/tray/system_tray_item.h" 18 #include "ash/common/system/tray/system_tray_item.h"
19 #include "ash/common/wm/window_state.h" 19 #include "ash/common/wm/window_state.h"
20 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
21 #include "ash/display/display_manager.h" 21 #include "ash/display/display_manager.h"
22 #include "ash/display/window_tree_host_manager.h"
23 #include "ash/root_window_controller.h" 22 #include "ash/root_window_controller.h"
24 #include "ash/shelf/shelf.h" 23 #include "ash/shelf/shelf.h"
25 #include "ash/shelf/shelf_layout_manager_observer.h" 24 #include "ash/shelf/shelf_layout_manager_observer.h"
26 #include "ash/shelf/shelf_view.h" 25 #include "ash/shelf/shelf_view.h"
27 #include "ash/shelf/shelf_widget.h" 26 #include "ash/shelf/shelf_widget.h"
28 #include "ash/shell.h" 27 #include "ash/shell.h"
29 #include "ash/test/ash_test_base.h" 28 #include "ash/test/ash_test_base.h"
30 #include "ash/test/display_manager_test_api.h" 29 #include "ash/test/display_manager_test_api.h"
31 #include "ash/test/shelf_test_api.h" 30 #include "ash/test/shelf_test_api.h"
32 #include "ash/test/test_system_tray_item.h" 31 #include "ash/test/test_system_tray_item.h"
(...skipping 29 matching lines...) Expand all
62 61
63 Shelf* GetShelf() { 62 Shelf* GetShelf() {
64 return Shelf::ForPrimaryDisplay(); 63 return Shelf::ForPrimaryDisplay();
65 } 64 }
66 65
67 ShelfWidget* GetShelfWidget() { 66 ShelfWidget* GetShelfWidget() {
68 return GetShelf()->shelf_widget(); 67 return GetShelf()->shelf_widget();
69 } 68 }
70 69
71 ShelfLayoutManager* GetShelfLayoutManager() { 70 ShelfLayoutManager* GetShelfLayoutManager() {
72 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); 71 return GetShelfWidget()->shelf_layout_manager();
73 }
74
75 SystemTray* GetSystemTray() {
76 return Shell::GetPrimaryRootWindowController()->GetSystemTray();
77 } 72 }
78 73
79 // Class which waits till the shelf finishes animating to the target size and 74 // Class which waits till the shelf finishes animating to the target size and
80 // counts the number of animation steps. 75 // counts the number of animation steps.
81 class ShelfAnimationWaiter : views::WidgetObserver { 76 class ShelfAnimationWaiter : views::WidgetObserver {
82 public: 77 public:
83 explicit ShelfAnimationWaiter(const gfx::Rect& target_bounds) 78 explicit ShelfAnimationWaiter(const gfx::Rect& target_bounds)
84 : target_bounds_(target_bounds), 79 : target_bounds_(target_bounds),
85 animation_steps_(0), 80 animation_steps_(0),
86 done_waiting_(false) { 81 done_waiting_(false) {
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 290 }
296 291
297 views::Widget* CreateTestWidgetWithParams( 292 views::Widget* CreateTestWidgetWithParams(
298 const views::Widget::InitParams& params) { 293 const views::Widget::InitParams& params) {
299 views::Widget* out = new views::Widget; 294 views::Widget* out = new views::Widget;
300 out->Init(params); 295 out->Init(params);
301 out->Show(); 296 out->Show();
302 return out; 297 return out;
303 } 298 }
304 299
305 // Create a simple widget attached to the current context (will 300 // Create a simple widget in the current context (will delete on TearDown).
306 // delete on TearDown).
307 views::Widget* CreateTestWidget() { 301 views::Widget* CreateTestWidget() {
308 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 302 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
309 params.bounds = gfx::Rect(0, 0, 200, 200); 303 params.bounds = gfx::Rect(0, 0, 200, 200);
310 params.context = CurrentContext(); 304 params.context = CurrentContext();
311 return CreateTestWidgetWithParams(params); 305 return CreateTestWidgetWithParams(params);
312 } 306 }
313 307
314 void RunGestureDragTests(gfx::Vector2d); 308 void RunGestureDragTests(gfx::Vector2d);
315 309
316 // Turn on the lock screen. 310 // Turn on the lock screen.
(...skipping 10 matching lines...) Expand all
327 Shell::GetInstance()->OnLockStateChanged(false); 321 Shell::GetInstance()->OnLockStateChanged(false);
328 } 322 }
329 323
330 private: 324 private:
331 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest); 325 DISALLOW_COPY_AND_ASSIGN(ShelfLayoutManagerTest);
332 }; 326 };
333 327
334 void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) { 328 void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
335 Shelf* shelf = GetShelf(); 329 Shelf* shelf = GetShelf();
336 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 330 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
337 views::Widget* widget = new views::Widget; 331
338 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 332 views::Widget* widget = CreateTestWidget();
339 params.bounds = gfx::Rect(0, 0, 200, 200);
340 params.context = CurrentContext();
341 widget->Init(params);
342 widget->Show();
343 widget->Maximize(); 333 widget->Maximize();
344 334
345 // The time delta should be large enough to prevent accidental fling creation. 335 // The time delta should be large enough to prevent accidental fling creation.
346 const base::TimeDelta kTimeDelta = base::TimeDelta::FromMilliseconds(100); 336 const base::TimeDelta kTimeDelta = base::TimeDelta::FromMilliseconds(100);
347 337
348 aura::Window* window = widget->GetNativeWindow(); 338 aura::Window* window = widget->GetNativeWindow();
349 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 339 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
350 layout_manager->LayoutShelf(); 340 layout_manager->LayoutShelf();
351 341
352 gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen(); 342 gfx::Rect shelf_shown = GetShelfWidget()->GetWindowBoundsInScreen();
353 gfx::Rect bounds_shelf = window->bounds(); 343 gfx::Rect bounds_shelf = window->bounds();
354 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 344 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
355 345
356 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 346 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
357 layout_manager->LayoutShelf(); 347 layout_manager->LayoutShelf();
358 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 348 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
359 349
360 gfx::Rect bounds_noshelf = window->bounds(); 350 gfx::Rect bounds_noshelf = window->bounds();
361 gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen(); 351 gfx::Rect shelf_hidden = GetShelfWidget()->GetWindowBoundsInScreen();
362 352
363 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 353 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
364 layout_manager->LayoutShelf(); 354 layout_manager->LayoutShelf();
365 355
366 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 356 ui::test::EventGenerator& generator(GetEventGenerator());
367 const int kNumScrollSteps = 4; 357 const int kNumScrollSteps = 4;
368 ShelfDragCallback handler(shelf_hidden, shelf_shown); 358 ShelfDragCallback handler(shelf_hidden, shelf_shown);
369 359
370 // Swipe up on the shelf. This should not change any state. 360 // Swipe up on the shelf. This should not change any state.
371 gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint(); 361 gfx::Point start = GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
372 gfx::Point end = start + delta; 362 gfx::Point end = start + delta;
373 363
374 // Swipe down on the shelf to hide it. 364 // Swipe down on the shelf to hide it.
375 generator.GestureScrollSequenceWithCallback( 365 generator.GestureScrollSequenceWithCallback(
376 start, end, kTimeDelta, kNumScrollSteps, 366 start, end, kTimeDelta, kNumScrollSteps,
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 ShelfWidget* shelf_widget = GetShelfWidget(); 609 ShelfWidget* shelf_widget = GetShelfWidget();
620 ShelfLayoutManager* manager = shelf_widget->shelf_layout_manager(); 610 ShelfLayoutManager* manager = shelf_widget->shelf_layout_manager();
621 // Force an initial layout. 611 // Force an initial layout.
622 manager->LayoutShelf(); 612 manager->LayoutShelf();
623 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state()); 613 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
624 614
625 gfx::Rect status_bounds( 615 gfx::Rect status_bounds(
626 shelf_widget->status_area_widget()->GetWindowBoundsInScreen()); 616 shelf_widget->status_area_widget()->GetWindowBoundsInScreen());
627 gfx::Rect shelf_bounds(shelf_widget->GetWindowBoundsInScreen()); 617 gfx::Rect shelf_bounds(shelf_widget->GetWindowBoundsInScreen());
628 int shelf_height = manager->GetIdealBounds().height(); 618 int shelf_height = manager->GetIdealBounds().height();
629 display::Screen* screen = display::Screen::GetScreen(); 619 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
630 display::Display display =
631 screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
632 ASSERT_NE(-1, display.id()); 620 ASSERT_NE(-1, display.id());
633 // Bottom inset should be the max of widget heights. 621 // Bottom inset should be the max of widget heights.
634 EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom()); 622 EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
635 623
636 // Hide the shelf. 624 // Hide the shelf.
637 SetState(manager, SHELF_HIDDEN); 625 SetState(manager, SHELF_HIDDEN);
638 // Run the animation to completion. 626 // Run the animation to completion.
639 StepWidgetLayerAnimatorToEnd(shelf_widget); 627 StepWidgetLayerAnimatorToEnd(shelf_widget);
640 StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget()); 628 StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget());
641 EXPECT_EQ(SHELF_HIDDEN, manager->visibility_state()); 629 EXPECT_EQ(SHELF_HIDDEN, manager->visibility_state());
642 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 630 display = display::Screen::GetScreen()->GetPrimaryDisplay();
643
644 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); 631 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
645 632
646 // Make sure the bounds of the two widgets changed. 633 // Make sure the bounds of the two widgets changed.
647 EXPECT_GE(shelf_widget->GetNativeView()->bounds().y(), 634 EXPECT_GE(shelf_widget->GetNativeView()->bounds().y(),
648 screen->GetPrimaryDisplay().bounds().bottom()); 635 display.bounds().bottom());
649 EXPECT_GE(shelf_widget->status_area_widget()->GetNativeView()->bounds().y(), 636 EXPECT_GE(shelf_widget->status_area_widget()->GetNativeView()->bounds().y(),
650 screen->GetPrimaryDisplay().bounds().bottom()); 637 display.bounds().bottom());
651 638
652 // And show it again. 639 // And show it again.
653 SetState(manager, SHELF_VISIBLE); 640 SetState(manager, SHELF_VISIBLE);
654 // Run the animation to completion. 641 // Run the animation to completion.
655 StepWidgetLayerAnimatorToEnd(shelf_widget); 642 StepWidgetLayerAnimatorToEnd(shelf_widget);
656 StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget()); 643 StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget());
657 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state()); 644 EXPECT_EQ(SHELF_VISIBLE, manager->visibility_state());
658 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 645 display = display::Screen::GetScreen()->GetPrimaryDisplay();
659 EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom()); 646 EXPECT_EQ(shelf_height, display.GetWorkAreaInsets().bottom());
660 647
661 // Make sure the bounds of the two widgets changed. 648 // Make sure the bounds of the two widgets changed.
662 shelf_bounds = shelf_widget->GetNativeView()->bounds(); 649 shelf_bounds = shelf_widget->GetNativeView()->bounds();
663 EXPECT_LT(shelf_bounds.y(), screen->GetPrimaryDisplay().bounds().bottom()); 650 EXPECT_LT(shelf_bounds.y(), display.bounds().bottom());
664 status_bounds = shelf_widget->status_area_widget()->GetNativeView()->bounds(); 651 status_bounds = shelf_widget->status_area_widget()->GetNativeView()->bounds();
665 EXPECT_LT(status_bounds.y(), screen->GetPrimaryDisplay().bounds().bottom()); 652 EXPECT_LT(status_bounds.y(), display.bounds().bottom());
666 } 653 }
667 654
668 // Makes sure LayoutShelf invoked while animating cleans things up. 655 // Makes sure LayoutShelf invoked while animating cleans things up.
669 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { 656 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) {
670 Shelf* shelf = GetShelf(); 657 Shelf* shelf = GetShelf();
671 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 658 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
672 // Force an initial layout. 659 // Force an initial layout.
673 layout_manager->LayoutShelf(); 660 layout_manager->LayoutShelf();
674 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 661 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
675 662
676 // Hide the shelf. 663 // Hide the shelf.
677 SetState(layout_manager, SHELF_HIDDEN); 664 SetState(layout_manager, SHELF_HIDDEN);
678 layout_manager->LayoutShelf(); 665 layout_manager->LayoutShelf();
679 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); 666 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
680 display::Display display = 667 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
681 display::Screen::GetScreen()->GetDisplayNearestWindow(
682 Shell::GetPrimaryRootWindow());
683 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); 668 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
684 669
685 // Make sure the bounds of the two widgets changed. 670 // Make sure the bounds of the two widgets changed.
686 ShelfWidget* shelf_widget = GetShelfWidget(); 671 ShelfWidget* shelf_widget = GetShelfWidget();
687 EXPECT_GE( 672 EXPECT_GE(shelf_widget->GetNativeView()->bounds().y(),
688 shelf_widget->GetNativeView()->bounds().y(), 673 display.bounds().bottom());
689 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().bottom()); 674 EXPECT_GE(shelf_widget->status_area_widget()->GetNativeView()->bounds().y(),
690 EXPECT_GE( 675 display.bounds().bottom());
691 shelf_widget->status_area_widget()->GetNativeView()->bounds().y(),
692 display::Screen::GetScreen()->GetPrimaryDisplay().bounds().bottom());
693 } 676 }
694 677
695 // Test that switching to a different visibility state does not restart the 678 // Test that switching to a different visibility state does not restart the
696 // shelf show / hide animation if it is already running. (crbug.com/250918) 679 // shelf show / hide animation if it is already running. (crbug.com/250918)
697 TEST_F(ShelfLayoutManagerTest, SetStateWhileAnimating) { 680 TEST_F(ShelfLayoutManagerTest, SetStateWhileAnimating) {
698 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 681 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
699 SetState(layout_manager, SHELF_VISIBLE); 682 SetState(layout_manager, SHELF_VISIBLE);
700 ShelfWidget* shelf_widget = GetShelfWidget(); 683 ShelfWidget* shelf_widget = GetShelfWidget();
701 gfx::Rect initial_shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); 684 gfx::Rect initial_shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
702 gfx::Rect initial_status_bounds = 685 gfx::Rect initial_status_bounds =
(...skipping 22 matching lines...) Expand all
725 Shelf* shelf = GetShelf(); 708 Shelf* shelf = GetShelf();
726 ASSERT_TRUE(shelf); 709 ASSERT_TRUE(shelf);
727 ShelfWidget* shelf_widget = GetShelfWidget(); 710 ShelfWidget* shelf_widget = GetShelfWidget();
728 ASSERT_TRUE(shelf_widget); 711 ASSERT_TRUE(shelf_widget);
729 ASSERT_TRUE(shelf_widget->status_area_widget()); 712 ASSERT_TRUE(shelf_widget->status_area_widget());
730 shelf_widget->status_area_widget()->SetBounds(gfx::Rect(0, 0, 200, 200)); 713 shelf_widget->status_area_widget()->SetBounds(gfx::Rect(0, 0, 200, 200));
731 EXPECT_EQ(200, shelf_widget->GetContentsView()->width() - 714 EXPECT_EQ(200, shelf_widget->GetContentsView()->width() -
732 test::ShelfTestAPI(shelf).shelf_view()->width()); 715 test::ShelfTestAPI(shelf).shelf_view()->width());
733 } 716 }
734 717
735 #if defined(OS_WIN)
736 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
737 #define MAYBE_AutoHide DISABLED_AutoHide
738 #else
739 #define MAYBE_AutoHide AutoHide
740 #endif
741
742 // Various assertions around auto-hide. 718 // Various assertions around auto-hide.
743 TEST_F(ShelfLayoutManagerTest, MAYBE_AutoHide) { 719 TEST_F(ShelfLayoutManagerTest, AutoHide) {
744 aura::Window* root = Shell::GetPrimaryRootWindow(); 720 ui::test::EventGenerator& generator(GetEventGenerator());
745 ui::test::EventGenerator generator(root, root);
746 generator.MoveMouseTo(0, 0);
747 721
748 Shelf* shelf = GetShelf(); 722 Shelf* shelf = GetShelf();
749 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 723 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
750 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 724 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
751 views::Widget* widget = new views::Widget; 725 views::Widget* widget = CreateTestWidget();
752 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
753 params.bounds = gfx::Rect(0, 0, 200, 200);
754 params.context = CurrentContext();
755 // Widget is now owned by the parent window.
756 widget->Init(params);
757 widget->Maximize(); 726 widget->Maximize();
758 widget->Show();
759 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 727 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
760 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 728 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
761 729
762 // LayoutShelf() forces the animation to completion, at which point the 730 // LayoutShelf() forces the animation to completion, at which point the
763 // shelf should go off the screen. 731 // shelf should go off the screen.
764 layout_manager->LayoutShelf(); 732 layout_manager->LayoutShelf();
765 int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE); 733 const int shelf_insets = GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE);
766 734
767 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, 735 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
736 const int display_bottom = display.bounds().bottom();
737 EXPECT_EQ(display_bottom - kShelfAutoHideSize,
768 GetShelfWidget()->GetWindowBoundsInScreen().y()); 738 GetShelfWidget()->GetWindowBoundsInScreen().y());
769 EXPECT_EQ(root->bounds().bottom() - shelf_insets, 739 EXPECT_EQ(display_bottom - shelf_insets, display.work_area().bottom());
770 display::Screen::GetScreen()
771 ->GetDisplayNearestWindow(root)
772 .work_area()
773 .bottom());
774 740
775 // Move the mouse to the bottom of the screen. 741 // Move the mouse to the bottom of the screen.
776 generator.MoveMouseTo(0, root->bounds().bottom() - 1); 742 generator.MoveMouseTo(0, display_bottom - 1);
777 743
778 // Shelf should be shown again (but it shouldn't have changed the work area). 744 // Shelf should be shown again (but it shouldn't have changed the work area).
779 SetState(layout_manager, SHELF_AUTO_HIDE); 745 SetState(layout_manager, SHELF_AUTO_HIDE);
780 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 746 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
781 layout_manager->LayoutShelf(); 747 layout_manager->LayoutShelf();
782 EXPECT_EQ(root->bounds().bottom() - layout_manager->GetIdealBounds().height(), 748 EXPECT_EQ(display_bottom - layout_manager->GetIdealBounds().height(),
783 GetShelfWidget()->GetWindowBoundsInScreen().y()); 749 GetShelfWidget()->GetWindowBoundsInScreen().y());
784 EXPECT_EQ(root->bounds().bottom() - shelf_insets, 750 EXPECT_EQ(display_bottom - shelf_insets, display.work_area().bottom());
785 display::Screen::GetScreen()
786 ->GetDisplayNearestWindow(root)
787 .work_area()
788 .bottom());
789 751
790 // Move mouse back up. 752 // Move mouse back up.
791 generator.MoveMouseTo(0, 0); 753 generator.MoveMouseTo(0, 0);
792 SetState(layout_manager, SHELF_AUTO_HIDE); 754 SetState(layout_manager, SHELF_AUTO_HIDE);
793 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 755 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
794 layout_manager->LayoutShelf(); 756 layout_manager->LayoutShelf();
795 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, 757 EXPECT_EQ(display_bottom - kShelfAutoHideSize,
796 GetShelfWidget()->GetWindowBoundsInScreen().y()); 758 GetShelfWidget()->GetWindowBoundsInScreen().y());
797 759
798 // Drag mouse to bottom of screen. 760 // Drag mouse to bottom of screen.
799 generator.PressLeftButton(); 761 generator.PressLeftButton();
800 generator.MoveMouseTo(0, root->bounds().bottom() - 1); 762 generator.MoveMouseTo(0, display_bottom - 1);
801 UpdateAutoHideStateNow(); 763 UpdateAutoHideStateNow();
802 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 764 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
803 765
804 generator.ReleaseLeftButton(); 766 generator.ReleaseLeftButton();
805 generator.MoveMouseTo(1, root->bounds().bottom() - 1); 767 generator.MoveMouseTo(1, display_bottom - 1);
806 UpdateAutoHideStateNow(); 768 UpdateAutoHideStateNow();
807 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 769 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
808 generator.PressLeftButton(); 770 generator.PressLeftButton();
809 generator.MoveMouseTo(1, root->bounds().bottom() - 1); 771 generator.MoveMouseTo(1, display_bottom - 1);
810 UpdateAutoHideStateNow(); 772 UpdateAutoHideStateNow();
811 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 773 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
812 } 774 }
813 775
814 // Test the behavior of the shelf when it is auto hidden and it is on the 776 // Test the behavior of the shelf when it is auto hidden and it is on the
815 // boundary between the primary and the secondary display. 777 // boundary between the primary and the secondary display.
816 TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnScreenBoundary) { 778 TEST_F(ShelfLayoutManagerTest, AutoHideShelfOnScreenBoundary) {
817 if (!SupportsMultipleDisplays()) 779 if (!SupportsMultipleDisplays())
818 return; 780 return;
819 781
820 UpdateDisplay("800x600,800x600"); 782 UpdateDisplay("800x600,800x600");
821 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( 783 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays(
822 test::CreateDisplayLayout(display::DisplayPlacement::RIGHT, 0)); 784 test::CreateDisplayLayout(display::DisplayPlacement::RIGHT, 0));
823 // Put the primary monitor's shelf on the display boundary. 785 // Put the primary monitor's shelf on the display boundary.
824 Shelf* shelf = GetShelf(); 786 Shelf* shelf = GetShelf();
825 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); 787 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
826 788
827 // Create a window because the shelf is always shown when no windows are 789 // Create a window because the shelf is always shown when no windows are
828 // visible. 790 // visible.
829 CreateTestWidget(); 791 CreateTestWidget();
830 792
831 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
832 ASSERT_EQ(root_windows[0],
833 GetShelfWidget()->GetNativeWindow()->GetRootWindow());
834
835 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 793 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
836 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 794 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
837 795
838 int right_edge = root_windows[0]->GetBoundsInScreen().right() - 1; 796 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
839 int y = root_windows[0]->GetBoundsInScreen().y(); 797 const int right_edge = display.bounds().right() - 1;
798 const int y = display.bounds().y();
840 799
841 // Start off the mouse nowhere near the shelf; the shelf should be hidden. 800 // Start off the mouse nowhere near the shelf; the shelf should be hidden.
842 ui::test::EventGenerator& generator(GetEventGenerator()); 801 ui::test::EventGenerator& generator(GetEventGenerator());
843 generator.MoveMouseTo(right_edge - 50, y); 802 generator.MoveMouseTo(right_edge - 50, y);
844 UpdateAutoHideStateNow(); 803 UpdateAutoHideStateNow();
845 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 804 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
846 805
847 // Moving the mouse over the light bar (but not to the edge of the screen) 806 // Moving the mouse over the light bar (but not to the edge of the screen)
848 // should show the shelf. 807 // should show the shelf.
849 generator.MoveMouseTo(right_edge - 1, y); 808 generator.MoveMouseTo(right_edge - 1, y);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 859
901 // Moving to the left edge of the secondary display without first crossing 860 // Moving to the left edge of the secondary display without first crossing
902 // the primary display's right aligned shelf first should not show the shelf. 861 // the primary display's right aligned shelf first should not show the shelf.
903 generator.MoveMouseTo(right_edge + 2, y); 862 generator.MoveMouseTo(right_edge + 2, y);
904 UpdateAutoHideStateNow(); 863 UpdateAutoHideStateNow();
905 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 864 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
906 } 865 }
907 866
908 // Assertions around the lock screen showing. 867 // Assertions around the lock screen showing.
909 TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) { 868 TEST_F(ShelfLayoutManagerTest, VisibleWhenLockScreenShowing) {
910 if (!SupportsHostWindowResize())
911 return;
912
913 // Since ShelfLayoutManager queries for mouse location, move the mouse so
914 // it isn't over the shelf.
915 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
916 gfx::Point());
917 generator.MoveMouseTo(0, 0);
918
919 Shelf* shelf = GetShelf(); 869 Shelf* shelf = GetShelf();
920 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 870 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
921 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 871 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
922 views::Widget* widget = new views::Widget; 872 views::Widget* widget = CreateTestWidget();
923 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
924 params.bounds = gfx::Rect(0, 0, 200, 200);
925 params.context = CurrentContext();
926 // Widget is now owned by the parent window.
927 widget->Init(params);
928 widget->Maximize(); 873 widget->Maximize();
929 widget->Show();
930 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 874 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
931 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 875 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
932 876
933 aura::Window* root = Shell::GetPrimaryRootWindow();
934 // LayoutShelf() forces the animation to completion, at which point the 877 // LayoutShelf() forces the animation to completion, at which point the
935 // shelf should go off the screen. 878 // shelf should go off the screen.
936 layout_manager->LayoutShelf(); 879 layout_manager->LayoutShelf();
937 EXPECT_EQ(root->bounds().bottom() - kShelfAutoHideSize, 880 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
881 EXPECT_EQ(display.bounds().bottom() - kShelfAutoHideSize,
938 GetShelfWidget()->GetWindowBoundsInScreen().y()); 882 GetShelfWidget()->GetWindowBoundsInScreen().y());
939 883
940 aura::Window* lock_container = Shell::GetContainer( 884 std::unique_ptr<views::Widget> lock_widget(AshTestBase::CreateTestWidget(
941 Shell::GetPrimaryRootWindow(), kShellWindowId_LockScreenContainer); 885 nullptr, kShellWindowId_LockScreenContainer, gfx::Rect(200, 200)));
942
943 views::Widget* lock_widget = new views::Widget;
944 views::Widget::InitParams lock_params(views::Widget::InitParams::TYPE_WINDOW);
945 lock_params.bounds = gfx::Rect(0, 0, 200, 200);
946 params.context = CurrentContext();
947 lock_params.parent = lock_container;
948 // Widget is now owned by the parent window.
949 lock_widget->Init(lock_params);
950 lock_widget->Maximize(); 886 lock_widget->Maximize();
951 lock_widget->Show();
952 887
953 // Lock the screen. 888 // Lock the screen.
954 LockScreen(); 889 LockScreen();
955 // Showing a widget in the lock screen should force the shelf to be visibile. 890 // Showing a widget in the lock screen should force the shelf to be visibile.
956 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 891 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
957 892
958 UnlockScreen(); 893 UnlockScreen();
959 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 894 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
960 } 895 }
961 896
962 // Assertions around SetAutoHideBehavior. 897 // Assertions around SetAutoHideBehavior.
963 TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) { 898 TEST_F(ShelfLayoutManagerTest, SetAutoHideBehavior) {
964 // Since ShelfLayoutManager queries for mouse location, move the mouse so
965 // it isn't over the shelf.
966 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
967 gfx::Point());
968 generator.MoveMouseTo(0, 0);
969
970 Shelf* shelf = GetShelf(); 899 Shelf* shelf = GetShelf();
971 views::Widget* widget = new views::Widget; 900 views::Widget* widget = CreateTestWidget();
972 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
973 params.bounds = gfx::Rect(0, 0, 200, 200);
974 params.context = CurrentContext();
975 // Widget is now owned by the parent window.
976 widget->Init(params);
977 widget->Show();
978 aura::Window* window = widget->GetNativeWindow();
979 901
980 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 902 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
981 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 903 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
982 904
983 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 905 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
984 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 906 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
985 907
986 widget->Maximize(); 908 widget->Maximize();
987 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 909 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
988 EXPECT_EQ(display::Screen::GetScreen() 910 display::Screen* screen = display::Screen::GetScreen();
989 ->GetDisplayNearestWindow(window) 911 EXPECT_EQ(screen->GetPrimaryDisplay().work_area().bottom(),
990 .work_area()
991 .bottom(),
992 widget->GetWorkAreaBoundsInScreen().bottom()); 912 widget->GetWorkAreaBoundsInScreen().bottom());
993 913
994 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 914 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
995 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 915 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
996 EXPECT_EQ(display::Screen::GetScreen() 916 EXPECT_EQ(screen->GetPrimaryDisplay().work_area().bottom(),
997 ->GetDisplayNearestWindow(window)
998 .work_area()
999 .bottom(),
1000 widget->GetWorkAreaBoundsInScreen().bottom()); 917 widget->GetWorkAreaBoundsInScreen().bottom());
1001 918
1002 ui::ScopedAnimationDurationScaleMode animation_duration( 919 ui::ScopedAnimationDurationScaleMode animation_duration(
1003 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 920 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
1004 921
1005 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 922 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1006 ShelfWidget* shelf_widget = GetShelfWidget(); 923 ShelfWidget* shelf_widget = GetShelfWidget();
1007 EXPECT_TRUE(shelf_widget->status_area_widget()->IsVisible()); 924 EXPECT_TRUE(shelf_widget->status_area_widget()->IsVisible());
1008 StepWidgetLayerAnimatorToEnd(shelf_widget); 925 StepWidgetLayerAnimatorToEnd(shelf_widget);
1009 StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget()); 926 StepWidgetLayerAnimatorToEnd(shelf_widget->status_area_widget());
1010 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 927 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
1011 EXPECT_EQ(display::Screen::GetScreen() 928 EXPECT_EQ(screen->GetPrimaryDisplay().work_area().bottom(),
1012 ->GetDisplayNearestWindow(window)
1013 .work_area()
1014 .bottom(),
1015 widget->GetWorkAreaBoundsInScreen().bottom()); 929 widget->GetWorkAreaBoundsInScreen().bottom());
1016 } 930 }
1017 931
1018 // Basic assertions around the dimming of the shelf. 932 // Basic assertions around the dimming of the shelf.
1019 TEST_F(ShelfLayoutManagerTest, DimmingBehavior) { 933 TEST_F(ShelfLayoutManagerTest, DimmingBehavior) {
1020 // Since ShelfLayoutManager queries for mouse location, move the mouse so 934 ui::test::EventGenerator& generator(GetEventGenerator());
1021 // it isn't over the shelf.
1022 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1023 gfx::Point());
1024 generator.MoveMouseTo(0, 0);
1025 935
1026 ShelfWidget* shelf_widget = GetShelfWidget(); 936 ShelfWidget* shelf_widget = GetShelfWidget();
1027 shelf_widget->DisableDimmingAnimationsForTest(); 937 shelf_widget->DisableDimmingAnimationsForTest();
1028 938 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
1029 views::Widget* widget = new views::Widget; 939 gfx::Point off_shelf = display.bounds().CenterPoint();
1030 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1031 params.bounds = gfx::Rect(0, 0, 200, 200);
1032 params.context = CurrentContext();
1033 // Widget is now owned by the parent window.
1034 widget->Init(params);
1035 widget->Show();
1036 aura::Window* window = widget->GetNativeWindow();
1037 gfx::Rect display_bounds(
1038 display::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds());
1039
1040 gfx::Point off_shelf = display_bounds.CenterPoint();
1041 gfx::Point on_shelf = shelf_widget->GetWindowBoundsInScreen().CenterPoint(); 940 gfx::Point on_shelf = shelf_widget->GetWindowBoundsInScreen().CenterPoint();
941 views::Widget* widget = CreateTestWidget();
1042 942
1043 // Test there is no dimming object active at this point. 943 // Test there is no dimming object active at this point.
1044 generator.MoveMouseTo(on_shelf.x(), on_shelf.y()); 944 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1045 EXPECT_EQ(-1, shelf_widget->GetDimmingAlphaForTest()); 945 EXPECT_EQ(-1, shelf_widget->GetDimmingAlphaForTest());
1046 generator.MoveMouseTo(off_shelf.x(), off_shelf.y()); 946 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1047 EXPECT_EQ(-1, shelf_widget->GetDimmingAlphaForTest()); 947 EXPECT_EQ(-1, shelf_widget->GetDimmingAlphaForTest());
1048 948
1049 // After maximization, the shelf should be visible and the dimmer created. 949 // After maximization, the shelf should be visible and the dimmer created.
1050 widget->Maximize(); 950 widget->Maximize();
1051 951
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 widget->Restore(); 987 widget->Restore();
1088 EXPECT_EQ(-1, shelf_widget->GetDimmingAlphaForTest()); 988 EXPECT_EQ(-1, shelf_widget->GetDimmingAlphaForTest());
1089 } 989 }
1090 990
1091 // Test that dimming works correctly with multiple displays. 991 // Test that dimming works correctly with multiple displays.
1092 TEST_F(ShelfLayoutManagerTest, DimmingBehaviorDualDisplay) { 992 TEST_F(ShelfLayoutManagerTest, DimmingBehaviorDualDisplay) {
1093 if (!SupportsMultipleDisplays()) 993 if (!SupportsMultipleDisplays())
1094 return; 994 return;
1095 995
1096 // Create two displays. 996 // Create two displays.
1097 Shell* shell = Shell::GetInstance();
1098 UpdateDisplay("0+0-200x200,+200+0-100x100"); 997 UpdateDisplay("0+0-200x200,+200+0-100x100");
1099 EXPECT_EQ(2U, shell->display_manager()->GetNumDisplays()); 998 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1100
1101 WindowTreeHostManager* window_tree_host_manager =
1102 shell->window_tree_host_manager();
1103 aura::Window::Windows root_windows =
1104 window_tree_host_manager->GetAllRootWindows();
1105 EXPECT_EQ(root_windows.size(), 2U); 999 EXPECT_EQ(root_windows.size(), 2U);
1106 1000
1107 std::vector<ShelfWidget*> shelf_widgets; 1001 std::vector<ShelfWidget*> shelf_widgets;
1108 for (auto* root_window : root_windows) { 1002 for (auto* root_window : root_windows) {
1109 ShelfLayoutManager* shelf = 1003 ShelfLayoutManager* shelf =
1110 GetRootWindowController(root_window)->GetShelfLayoutManager(); 1004 GetRootWindowController(root_window)->GetShelfLayoutManager();
1111 shelf_widgets.push_back(shelf->shelf_widget()); 1005 shelf_widgets.push_back(shelf->shelf_widget());
1112 1006
1113 // For disabling the dimming animation to work, the animation must be 1007 // For disabling the dimming animation to work, the animation must be
1114 // disabled prior to creating the dimmer. 1008 // disabled prior to creating the dimmer.
1115 shelf_widgets.back()->DisableDimmingAnimationsForTest(); 1009 shelf_widgets.back()->DisableDimmingAnimationsForTest();
1116 1010
1117 // Create a maximized window to create the dimmer. 1011 // Create a maximized window to create the dimmer.
1118 views::Widget* widget = new views::Widget; 1012 views::Widget::InitParams params;
1119 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1120 params.context = root_window; 1013 params.context = root_window;
1121 params.bounds = root_window->GetBoundsInScreen(); 1014 params.bounds = root_window->GetBoundsInScreen();
1122 params.show_state = ui::SHOW_STATE_MAXIMIZED; 1015 params.show_state = ui::SHOW_STATE_MAXIMIZED;
1123 widget->Init(params); 1016 CreateTestWidgetWithParams(params);
1124 widget->Show();
1125 } 1017 }
1126 1018
1127 ui::test::EventGenerator& generator(GetEventGenerator()); 1019 ui::test::EventGenerator& generator(GetEventGenerator());
1128 1020
1129 generator.MoveMouseTo(root_windows[0]->GetBoundsInScreen().CenterPoint()); 1021 generator.MoveMouseTo(root_windows[0]->GetBoundsInScreen().CenterPoint());
1130 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest()); 1022 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest());
1131 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest()); 1023 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest());
1132 1024
1133 generator.MoveMouseTo( 1025 generator.MoveMouseTo(
1134 shelf_widgets[0]->GetWindowBoundsInScreen().CenterPoint()); 1026 shelf_widgets[0]->GetWindowBoundsInScreen().CenterPoint());
1135 EXPECT_EQ(0, shelf_widgets[0]->GetDimmingAlphaForTest()); 1027 EXPECT_EQ(0, shelf_widgets[0]->GetDimmingAlphaForTest());
1136 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest()); 1028 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest());
1137 1029
1138 generator.MoveMouseTo( 1030 generator.MoveMouseTo(
1139 shelf_widgets[1]->GetWindowBoundsInScreen().CenterPoint()); 1031 shelf_widgets[1]->GetWindowBoundsInScreen().CenterPoint());
1140 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest()); 1032 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest());
1141 EXPECT_EQ(0, shelf_widgets[1]->GetDimmingAlphaForTest()); 1033 EXPECT_EQ(0, shelf_widgets[1]->GetDimmingAlphaForTest());
1142 1034
1143 generator.MoveMouseTo(root_windows[1]->GetBoundsInScreen().CenterPoint()); 1035 generator.MoveMouseTo(root_windows[1]->GetBoundsInScreen().CenterPoint());
1144 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest()); 1036 EXPECT_LT(0, shelf_widgets[0]->GetDimmingAlphaForTest());
1145 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest()); 1037 EXPECT_LT(0, shelf_widgets[1]->GetDimmingAlphaForTest());
1146 } 1038 }
1147 1039
1148 // Assertions around the dimming of the shelf in conjunction with menus. 1040 // Assertions around the dimming of the shelf in conjunction with menus.
1149 TEST_F(ShelfLayoutManagerTest, DimmingBehaviorWithMenus) { 1041 TEST_F(ShelfLayoutManagerTest, DimmingBehaviorWithMenus) {
1150 // Since ShelfLayoutManager queries for mouse location, move the mouse so 1042 ui::test::EventGenerator& generator(GetEventGenerator());
1151 // it isn't over the shelf.
1152 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1153 gfx::Point());
1154 generator.MoveMouseTo(0, 0); 1043 generator.MoveMouseTo(0, 0);
1155 1044
1156 ShelfWidget* shelf_widget = GetShelfWidget(); 1045 ShelfWidget* shelf_widget = GetShelfWidget();
1157 shelf_widget->DisableDimmingAnimationsForTest(); 1046 shelf_widget->DisableDimmingAnimationsForTest();
1158 1047
1159 views::Widget* widget = new views::Widget;
1160 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1161 params.bounds = gfx::Rect(0, 0, 200, 200);
1162 params.context = CurrentContext();
1163 // Widget is now owned by the parent window.
1164 widget->Init(params);
1165 widget->Show();
1166 aura::Window* window = widget->GetNativeWindow();
1167 gfx::Rect display_bounds(
1168 display::Screen::GetScreen()->GetDisplayNearestWindow(window).bounds());
1169
1170 // After maximization, the shelf should be visible and the dimmer created. 1048 // After maximization, the shelf should be visible and the dimmer created.
1049 views::Widget* widget = CreateTestWidget();
1171 widget->Maximize(); 1050 widget->Maximize();
1172 1051
1173 gfx::Point off_shelf = display_bounds.CenterPoint(); 1052 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
1053 gfx::Point off_shelf = display.bounds().CenterPoint();
1174 gfx::Point on_shelf = shelf_widget->GetWindowBoundsInScreen().CenterPoint(); 1054 gfx::Point on_shelf = shelf_widget->GetWindowBoundsInScreen().CenterPoint();
1175 1055
1176 // Moving the mouse on the shelf should undim the bar. 1056 // Moving the mouse on the shelf should undim the bar.
1177 generator.MoveMouseTo(on_shelf.x(), on_shelf.y()); 1057 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1178 EXPECT_EQ(0, shelf_widget->GetDimmingAlphaForTest()); 1058 EXPECT_EQ(0, shelf_widget->GetDimmingAlphaForTest());
1179 1059
1180 // Simulate a menu opening. 1060 // Simulate a menu opening.
1181 shelf_widget->ForceUndimming(true); 1061 shelf_widget->ForceUndimming(true);
1182 1062
1183 // Moving the mouse off the shelf should not dim the bar. 1063 // Moving the mouse off the shelf should not dim the bar.
(...skipping 25 matching lines...) Expand all
1209 generator.MoveMouseTo(off_shelf.x(), off_shelf.y()); 1089 generator.MoveMouseTo(off_shelf.x(), off_shelf.y());
1210 EXPECT_EQ(0, shelf_widget->GetDimmingAlphaForTest()); 1090 EXPECT_EQ(0, shelf_widget->GetDimmingAlphaForTest());
1211 generator.MoveMouseTo(on_shelf.x(), on_shelf.y()); 1091 generator.MoveMouseTo(on_shelf.x(), on_shelf.y());
1212 EXPECT_EQ(0, shelf_widget->GetDimmingAlphaForTest()); 1092 EXPECT_EQ(0, shelf_widget->GetDimmingAlphaForTest());
1213 shelf_widget->ForceUndimming(true); 1093 shelf_widget->ForceUndimming(true);
1214 EXPECT_EQ(0, shelf_widget->GetDimmingAlphaForTest()); 1094 EXPECT_EQ(0, shelf_widget->GetDimmingAlphaForTest());
1215 } 1095 }
1216 1096
1217 // Verifies the shelf is visible when status/shelf is focused. 1097 // Verifies the shelf is visible when status/shelf is focused.
1218 TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrShelfFocused) { 1098 TEST_F(ShelfLayoutManagerTest, VisibleWhenStatusOrShelfFocused) {
1219 // Since ShelfLayoutManager queries for mouse location, move the mouse so
1220 // it isn't over the shelf.
1221 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
1222 gfx::Point());
1223 generator.MoveMouseTo(0, 0);
1224
1225 Shelf* shelf = GetShelf(); 1099 Shelf* shelf = GetShelf();
1226 views::Widget* widget = new views::Widget; 1100 views::Widget* widget = CreateTestWidget();
1227 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1228 params.bounds = gfx::Rect(0, 0, 200, 200);
1229 params.context = CurrentContext();
1230 // Widget is now owned by the parent window.
1231 widget->Init(params);
1232 widget->Show();
1233 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1101 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1234 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 1102 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
1235 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 1103 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
1236 1104
1237 // Focus the shelf. Have to go through the focus cycler as normal focus 1105 // Focus the shelf. Have to go through the focus cycler as normal focus
1238 // requests to it do nothing. 1106 // requests to it do nothing.
1239 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); 1107 GetShelfWidget()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD);
1240 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 1108 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
1241 1109
1242 widget->Activate(); 1110 widget->Activate();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 } 1183 }
1316 1184
1317 // Makes sure that when we have dual displays, with one or both shelves are set 1185 // Makes sure that when we have dual displays, with one or both shelves are set
1318 // to AutoHide, viewing the AppList on one of them doesn't unhide the other 1186 // to AutoHide, viewing the AppList on one of them doesn't unhide the other
1319 // hidden shelf. 1187 // hidden shelf.
1320 TEST_F(ShelfLayoutManagerTest, DualDisplayOpenAppListWithShelfAutoHideState) { 1188 TEST_F(ShelfLayoutManagerTest, DualDisplayOpenAppListWithShelfAutoHideState) {
1321 if (!SupportsMultipleDisplays()) 1189 if (!SupportsMultipleDisplays())
1322 return; 1190 return;
1323 1191
1324 // Create two displays. 1192 // Create two displays.
1325 Shell* shell = Shell::GetInstance();
1326 DisplayManager* display_manager = shell->display_manager();
1327 EXPECT_EQ(1U, display_manager->GetNumDisplays());
1328 UpdateDisplay("0+0-200x200,+200+0-100x100"); 1193 UpdateDisplay("0+0-200x200,+200+0-100x100");
1329 EXPECT_EQ(2U, display_manager->GetNumDisplays()); 1194 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1330
1331 WindowTreeHostManager* window_tree_host_manager =
1332 shell->window_tree_host_manager();
1333 aura::Window::Windows root_windows =
1334 window_tree_host_manager->GetAllRootWindows();
1335 EXPECT_EQ(root_windows.size(), 2U); 1195 EXPECT_EQ(root_windows.size(), 2U);
1336 1196
1337 // Get the shelves in both displays and set them to be 'AutoHide'. 1197 // Get the shelves in both displays and set them to be 'AutoHide'.
1338 Shelf* shelf_1 = GetRootWindowController(root_windows[0])->GetShelf(); 1198 Shelf* shelf_1 = GetRootWindowController(root_windows[0])->GetShelf();
1339 Shelf* shelf_2 = GetRootWindowController(root_windows[1])->GetShelf(); 1199 Shelf* shelf_2 = GetRootWindowController(root_windows[1])->GetShelf();
1340 EXPECT_NE(shelf_1, shelf_2); 1200 EXPECT_NE(shelf_1, shelf_2);
1341 EXPECT_NE(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(), 1201 EXPECT_NE(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1342 shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow()); 1202 shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow());
1343 shelf_1->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1203 shelf_1->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1344 shelf_1->shelf_layout_manager()->LayoutShelf(); 1204 shelf_1->shelf_layout_manager()->LayoutShelf();
(...skipping 11 matching lines...) Expand all
1356 window_2->Show(); 1216 window_2->Show();
1357 1217
1358 EXPECT_EQ(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(), 1218 EXPECT_EQ(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1359 window_1->GetRootWindow()); 1219 window_1->GetRootWindow());
1360 EXPECT_EQ(shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow(), 1220 EXPECT_EQ(shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1361 window_2->GetRootWindow()); 1221 window_2->GetRootWindow());
1362 1222
1363 // Activate one window in one display and manually trigger the update of shelf 1223 // Activate one window in one display and manually trigger the update of shelf
1364 // visibility. 1224 // visibility.
1365 wm::ActivateWindow(window_1); 1225 wm::ActivateWindow(window_1);
1366 shell->UpdateShelfVisibility(); 1226 Shell::GetInstance()->UpdateShelfVisibility();
1367 1227
1368 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); 1228 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility());
1369 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState()); 1229 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
1370 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState()); 1230 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
1371 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState()); 1231 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState());
1372 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState()); 1232 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
1373 1233
1374 // Show app list. 1234 // Show app list.
1375 WmShell::Get()->ShowAppList(); 1235 WmShell::Get()->ShowAppList();
1376 shell->UpdateShelfVisibility(); 1236 Shell::GetInstance()->UpdateShelfVisibility();
1377 1237
1378 // Only the shelf in the active display should be shown, the other is hidden. 1238 // Only the shelf in the active display should be shown, the other is hidden.
1379 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); 1239 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility());
1380 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState()); 1240 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
1381 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_1->GetAutoHideState()); 1241 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_1->GetAutoHideState());
1382 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState()); 1242 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
1383 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState()); 1243 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
1384 1244
1385 // Hide app list, both shelves should be hidden. 1245 // Hide app list, both shelves should be hidden.
1386 WmShell::Get()->DismissAppList(); 1246 WmShell::Get()->DismissAppList();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 1278
1419 // Hide app list. 1279 // Hide app list.
1420 shell->DismissAppList(); 1280 shell->DismissAppList();
1421 EXPECT_FALSE(shell->GetAppListTargetVisibility()); 1281 EXPECT_FALSE(shell->GetAppListTargetVisibility());
1422 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); 1282 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
1423 } 1283 }
1424 1284
1425 // Tests the correct behavior of the shelf when there is a system modal window 1285 // Tests the correct behavior of the shelf when there is a system modal window
1426 // open when we have a single display. 1286 // open when we have a single display.
1427 TEST_F(ShelfLayoutManagerTest, ShelfWithSystemModalWindowSingleDisplay) { 1287 TEST_F(ShelfLayoutManagerTest, ShelfWithSystemModalWindowSingleDisplay) {
1428 Shell* shell = Shell::GetInstance();
1429 Shelf* shelf = GetShelf(); 1288 Shelf* shelf = GetShelf();
1430 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 1289 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
1431 layout_manager->LayoutShelf(); 1290 layout_manager->LayoutShelf();
1432 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1291 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1433 1292
1434 aura::Window* window = CreateTestWindow(); 1293 aura::Window* window = CreateTestWindow();
1435 window->SetBounds(gfx::Rect(0, 0, 100, 100)); 1294 window->SetBounds(gfx::Rect(0, 0, 100, 100));
1436 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1295 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
1437 window->Show(); 1296 window->Show();
1438 wm::ActivateWindow(window); 1297 wm::ActivateWindow(window);
1439 1298
1440 // Enable system modal dialog, and make sure shelf is still hidden. 1299 // Enable system modal dialog, and make sure shelf is still hidden.
1441 WmShell* wm_shell = WmShell::Get(); 1300 WmShell* wm_shell = WmShell::Get();
1442 wm_shell->SimulateModalWindowOpenForTesting(true); 1301 wm_shell->SimulateModalWindowOpenForTesting(true);
1443 EXPECT_TRUE(wm_shell->IsSystemModalWindowOpen()); 1302 EXPECT_TRUE(wm_shell->IsSystemModalWindowOpen());
1444 EXPECT_FALSE(wm::CanActivateWindow(window)); 1303 EXPECT_FALSE(wm::CanActivateWindow(window));
1445 shell->UpdateShelfVisibility(); 1304 Shell::GetInstance()->UpdateShelfVisibility();
1446 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 1305 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
1447 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 1306 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
1448 } 1307 }
1449 1308
1450 // Tests the correct behavior of the shelf when there is a system modal window 1309 // Tests the correct behavior of the shelf when there is a system modal window
1451 // open when we have dual display. 1310 // open when we have dual display.
1452 TEST_F(ShelfLayoutManagerTest, ShelfWithSystemModalWindowDualDisplay) { 1311 TEST_F(ShelfLayoutManagerTest, ShelfWithSystemModalWindowDualDisplay) {
1453 if (!SupportsMultipleDisplays()) 1312 if (!SupportsMultipleDisplays())
1454 return; 1313 return;
1455 1314
1456 // Create two displays. 1315 // Create two displays.
1457 Shell* shell = Shell::GetInstance();
1458 DisplayManager* display_manager = shell->display_manager();
1459 UpdateDisplay("200x200,100x100"); 1316 UpdateDisplay("200x200,100x100");
1460 EXPECT_EQ(2U, display_manager->GetNumDisplays()); 1317 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1461
1462 WindowTreeHostManager* window_tree_host_manager =
1463 shell->window_tree_host_manager();
1464 aura::Window::Windows root_windows =
1465 window_tree_host_manager->GetAllRootWindows();
1466 EXPECT_EQ(2U, root_windows.size()); 1318 EXPECT_EQ(2U, root_windows.size());
1467 1319
1468 // Get the shelves in both displays and set them to be 'AutoHide'. 1320 // Get the shelves in both displays and set them to be 'AutoHide'.
1469 Shelf* shelf_1 = GetRootWindowController(root_windows[0])->GetShelf(); 1321 Shelf* shelf_1 = GetRootWindowController(root_windows[0])->GetShelf();
1470 Shelf* shelf_2 = GetRootWindowController(root_windows[1])->GetShelf(); 1322 Shelf* shelf_2 = GetRootWindowController(root_windows[1])->GetShelf();
1471 EXPECT_NE(shelf_1, shelf_2); 1323 EXPECT_NE(shelf_1, shelf_2);
1472 EXPECT_NE(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(), 1324 EXPECT_NE(shelf_1->shelf_widget()->GetNativeWindow()->GetRootWindow(),
1473 shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow()); 1325 shelf_2->shelf_widget()->GetNativeWindow()->GetRootWindow());
1474 shelf_1->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1326 shelf_1->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1475 shelf_1->shelf_layout_manager()->LayoutShelf(); 1327 shelf_1->shelf_layout_manager()->LayoutShelf();
(...skipping 16 matching lines...) Expand all
1492 window_2->GetRootWindow()); 1344 window_2->GetRootWindow());
1493 EXPECT_TRUE(window_1->IsVisible()); 1345 EXPECT_TRUE(window_1->IsVisible());
1494 EXPECT_TRUE(window_2->IsVisible()); 1346 EXPECT_TRUE(window_2->IsVisible());
1495 1347
1496 // Enable system modal dialog, and make sure both shelves are still hidden. 1348 // Enable system modal dialog, and make sure both shelves are still hidden.
1497 WmShell* wm_shell = WmShell::Get(); 1349 WmShell* wm_shell = WmShell::Get();
1498 wm_shell->SimulateModalWindowOpenForTesting(true); 1350 wm_shell->SimulateModalWindowOpenForTesting(true);
1499 EXPECT_TRUE(wm_shell->IsSystemModalWindowOpen()); 1351 EXPECT_TRUE(wm_shell->IsSystemModalWindowOpen());
1500 EXPECT_FALSE(wm::CanActivateWindow(window_1)); 1352 EXPECT_FALSE(wm::CanActivateWindow(window_1));
1501 EXPECT_FALSE(wm::CanActivateWindow(window_2)); 1353 EXPECT_FALSE(wm::CanActivateWindow(window_2));
1502 shell->UpdateShelfVisibility(); 1354 Shell::GetInstance()->UpdateShelfVisibility();
1503 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState()); 1355 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
1504 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState()); 1356 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState());
1505 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState()); 1357 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
1506 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState()); 1358 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
1507 } 1359 }
1508 1360
1509 // Tests that the shelf is only hidden for a fullscreen window at the front and 1361 // Tests that the shelf is only hidden for a fullscreen window at the front and
1510 // toggles visibility when another window is activated. 1362 // toggles visibility when another window is activated.
1511 TEST_F(ShelfLayoutManagerTest, FullscreenWindowInFrontHidesShelf) { 1363 TEST_F(ShelfLayoutManagerTest, FullscreenWindowInFrontHidesShelf) {
1512 Shelf* shelf = GetShelf(); 1364 Shelf* shelf = GetShelf();
(...skipping 18 matching lines...) Expand all
1531 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); 1383 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
1532 } 1384 }
1533 1385
1534 // Test the behavior of the shelf when a window on one display is fullscreen 1386 // Test the behavior of the shelf when a window on one display is fullscreen
1535 // but the other display has the active window. 1387 // but the other display has the active window.
1536 TEST_F(ShelfLayoutManagerTest, FullscreenWindowOnSecondDisplay) { 1388 TEST_F(ShelfLayoutManagerTest, FullscreenWindowOnSecondDisplay) {
1537 if (!SupportsMultipleDisplays()) 1389 if (!SupportsMultipleDisplays())
1538 return; 1390 return;
1539 1391
1540 UpdateDisplay("800x600,800x600"); 1392 UpdateDisplay("800x600,800x600");
1541 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
1542 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 1393 aura::Window::Windows root_windows = Shell::GetAllRootWindows();
1543 Shell::RootWindowControllerList root_window_controllers = 1394 Shell::RootWindowControllerList root_window_controllers =
1544 Shell::GetAllRootWindowControllers(); 1395 Shell::GetAllRootWindowControllers();
1545 1396
1546 // Create windows on either display. 1397 // Create windows on either display.
1547 aura::Window* window1 = CreateTestWindow(); 1398 aura::Window* window1 = CreateTestWindow();
1548 window1->SetBoundsInScreen(gfx::Rect(0, 0, 100, 100), 1399 window1->SetBoundsInScreen(gfx::Rect(0, 0, 100, 100),
1549 display_manager->GetDisplayAt(0)); 1400 display::Screen::GetScreen()->GetAllDisplays()[0]);
1550 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 1401 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
1551 window1->Show(); 1402 window1->Show();
1552 1403
1553 aura::Window* window2 = CreateTestWindow(); 1404 aura::Window* window2 = CreateTestWindow();
1554 window2->SetBoundsInScreen(gfx::Rect(800, 0, 100, 100), 1405 window2->SetBoundsInScreen(gfx::Rect(800, 0, 100, 100),
1555 display_manager->GetDisplayAt(1)); 1406 display::Screen::GetScreen()->GetAllDisplays()[1]);
1556 window2->Show(); 1407 window2->Show();
1557 1408
1558 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); 1409 EXPECT_EQ(root_windows[0], window1->GetRootWindow());
1559 EXPECT_EQ(root_windows[1], window2->GetRootWindow()); 1410 EXPECT_EQ(root_windows[1], window2->GetRootWindow());
1560 1411
1561 wm::GetWindowState(window2)->Activate(); 1412 wm::GetWindowState(window2)->Activate();
1562 EXPECT_EQ( 1413 EXPECT_EQ(
1563 SHELF_HIDDEN, 1414 SHELF_HIDDEN,
1564 root_window_controllers[0]->GetShelfLayoutManager()->visibility_state()); 1415 root_window_controllers[0]->GetShelfLayoutManager()->visibility_state());
1565 EXPECT_EQ( 1416 EXPECT_EQ(
(...skipping 11 matching lines...) Expand all
1577 1428
1578 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 1429 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
1579 1430
1580 wm::PinWindow(window1); 1431 wm::PinWindow(window1);
1581 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); 1432 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
1582 1433
1583 WmWindowAura::Get(window1)->GetWindowState()->Restore(); 1434 WmWindowAura::Get(window1)->GetWindowState()->Restore();
1584 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 1435 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
1585 } 1436 }
1586 1437
1587 #if defined(OS_WIN)
1588 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1589 #define MAYBE_SetAlignment DISABLED_SetAlignment
1590 #else
1591 #define MAYBE_SetAlignment SetAlignment
1592 #endif
1593
1594 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT). 1438 // Tests SHELF_ALIGNMENT_(LEFT, RIGHT).
1595 TEST_F(ShelfLayoutManagerTest, MAYBE_SetAlignment) { 1439 TEST_F(ShelfLayoutManagerTest, SetAlignment) {
1596 Shelf* shelf = GetShelf(); 1440 Shelf* shelf = GetShelf();
1597 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 1441 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
1598 // Force an initial layout. 1442 // Force an initial layout.
1599 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1443 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1600 layout_manager->LayoutShelf(); 1444 layout_manager->LayoutShelf();
1601 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 1445 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
1602 1446
1603 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 1447 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
1604 gfx::Rect shelf_bounds(GetShelfWidget()->GetWindowBoundsInScreen()); 1448 gfx::Rect shelf_bounds(GetShelfWidget()->GetWindowBoundsInScreen());
1605 const display::Screen* screen = display::Screen::GetScreen(); 1449 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
1606 display::Display display =
1607 screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1608 ASSERT_NE(-1, display.id()); 1450 ASSERT_NE(-1, display.id());
1609 EXPECT_EQ(layout_manager->GetIdealBounds().width(), 1451 EXPECT_EQ(layout_manager->GetIdealBounds().width(),
1610 display.GetWorkAreaInsets().left()); 1452 display.GetWorkAreaInsets().left());
1611 EXPECT_GE(shelf_bounds.width(), 1453 EXPECT_GE(shelf_bounds.width(),
1612 GetShelfWidget()->GetContentsView()->GetPreferredSize().width()); 1454 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1613 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetSystemTray()->shelf_alignment()); 1455 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, GetPrimarySystemTray()->shelf_alignment());
1614 StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget(); 1456 StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
1615 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen()); 1457 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen());
1616 EXPECT_GE(status_bounds.width(), 1458 EXPECT_GE(status_bounds.width(),
1617 status_area_widget->GetContentsView()->GetPreferredSize().width()); 1459 status_area_widget->GetContentsView()->GetPreferredSize().width());
1618 EXPECT_EQ(layout_manager->GetIdealBounds().width(), 1460 EXPECT_EQ(layout_manager->GetIdealBounds().width(),
1619 display.GetWorkAreaInsets().left()); 1461 display.GetWorkAreaInsets().left());
1620 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); 1462 EXPECT_EQ(0, display.GetWorkAreaInsets().top());
1621 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); 1463 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
1622 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); 1464 EXPECT_EQ(0, display.GetWorkAreaInsets().right());
1623 EXPECT_EQ(display.bounds().x(), shelf_bounds.x()); 1465 EXPECT_EQ(display.bounds().x(), shelf_bounds.x());
1624 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); 1466 EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
1625 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); 1467 EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
1626 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1468 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1627 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 1469 display = display::Screen::GetScreen()->GetPrimaryDisplay();
1628 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE), 1470 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE),
1629 display.GetWorkAreaInsets().left()); 1471 display.GetWorkAreaInsets().left());
1630 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE), 1472 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE),
1631 display.work_area().x()); 1473 display.work_area().x());
1632 1474
1633 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1475 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1634 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); 1476 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT);
1635 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow());
1636 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); 1477 shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1637 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 1478 display = display::Screen::GetScreen()->GetPrimaryDisplay();
1638 ASSERT_NE(-1, display.id()); 1479 ASSERT_NE(-1, display.id());
1639 EXPECT_EQ(layout_manager->GetIdealBounds().width(), 1480 EXPECT_EQ(layout_manager->GetIdealBounds().width(),
1640 display.GetWorkAreaInsets().right()); 1481 display.GetWorkAreaInsets().right());
1641 EXPECT_GE(shelf_bounds.width(), 1482 EXPECT_GE(shelf_bounds.width(),
1642 GetShelfWidget()->GetContentsView()->GetPreferredSize().width()); 1483 GetShelfWidget()->GetContentsView()->GetPreferredSize().width());
1643 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetSystemTray()->shelf_alignment()); 1484 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, GetPrimarySystemTray()->shelf_alignment());
1644 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); 1485 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen());
1645 EXPECT_GE(status_bounds.width(), 1486 EXPECT_GE(status_bounds.width(),
1646 status_area_widget->GetContentsView()->GetPreferredSize().width()); 1487 status_area_widget->GetContentsView()->GetPreferredSize().width());
1647 EXPECT_EQ(layout_manager->GetIdealBounds().width(), 1488 EXPECT_EQ(layout_manager->GetIdealBounds().width(),
1648 display.GetWorkAreaInsets().right()); 1489 display.GetWorkAreaInsets().right());
1649 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); 1490 EXPECT_EQ(0, display.GetWorkAreaInsets().top());
1650 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); 1491 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom());
1651 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); 1492 EXPECT_EQ(0, display.GetWorkAreaInsets().left());
1652 EXPECT_EQ(display.work_area().right(), shelf_bounds.x()); 1493 EXPECT_EQ(display.work_area().right(), shelf_bounds.x());
1653 EXPECT_EQ(display.bounds().y(), shelf_bounds.y()); 1494 EXPECT_EQ(display.bounds().y(), shelf_bounds.y());
1654 EXPECT_EQ(display.bounds().height(), shelf_bounds.height()); 1495 EXPECT_EQ(display.bounds().height(), shelf_bounds.height());
1655 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1496 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1656 display = screen->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); 1497 display = display::Screen::GetScreen()->GetPrimaryDisplay();
1657 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE), 1498 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE),
1658 display.GetWorkAreaInsets().right()); 1499 display.GetWorkAreaInsets().right());
1659 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE), 1500 EXPECT_EQ(GetShelfConstant(SHELF_INSETS_FOR_AUTO_HIDE),
1660 display.bounds().right() - display.work_area().right()); 1501 display.bounds().right() - display.work_area().right());
1661 } 1502 }
1662 1503
1663 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) { 1504 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipe) {
1664 Shelf* shelf = GetShelf(); 1505 Shelf* shelf = GetShelf();
1665 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 1506 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
1666 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1507 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1667 views::Widget* widget = new views::Widget; 1508 views::Widget* widget = CreateTestWidget();
1668 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
1669 params.bounds = gfx::Rect(0, 0, 200, 200);
1670 params.context = CurrentContext();
1671 widget->Init(params);
1672 widget->Show();
1673 widget->Maximize(); 1509 widget->Maximize();
1674 1510
1675 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1511 ui::test::EventGenerator& generator(GetEventGenerator());
1676 1512
1677 aura::Window* window = widget->GetNativeWindow(); 1513 aura::Window* window = widget->GetNativeWindow();
1678 layout_manager->LayoutShelf(); 1514 layout_manager->LayoutShelf();
1679 1515
1680 // Edge swipe when SHELF_VISIBLE should not change visibility state. 1516 // Edge swipe when SHELF_VISIBLE should not change visibility state.
1681 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 1517 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
1682 generator.GestureEdgeSwipe(); 1518 generator.GestureEdgeSwipe();
1683 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 1519 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
1684 1520
1685 // Edge swipe when AUTO_HIDE_HIDDEN should change to AUTO_HIDE_SHOWN. 1521 // Edge swipe when AUTO_HIDE_HIDDEN should change to AUTO_HIDE_SHOWN.
(...skipping 20 matching lines...) Expand all
1706 EXPECT_TRUE(widget->IsFullscreen()); 1542 EXPECT_TRUE(widget->IsFullscreen());
1707 } 1543 }
1708 1544
1709 // Tests that gesture edge swipe events are forwarded to the right shelf on the 1545 // Tests that gesture edge swipe events are forwarded to the right shelf on the
1710 // right monitor (crbug.com/449851). 1546 // right monitor (crbug.com/449851).
1711 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipeMultiMonitor) { 1547 TEST_F(ShelfLayoutManagerTest, GestureEdgeSwipeMultiMonitor) {
1712 if (!SupportsMultipleDisplays()) 1548 if (!SupportsMultipleDisplays())
1713 return; 1549 return;
1714 1550
1715 // Create two displays. 1551 // Create two displays.
1716 Shell* shell = Shell::GetInstance();
1717 DisplayManager* display_manager = shell->display_manager();
1718 UpdateDisplay("200x200,100x100"); 1552 UpdateDisplay("200x200,100x100");
1719 ASSERT_EQ(2U, display_manager->GetNumDisplays());
1720
1721 auto root_window_controllers = Shell::GetAllRootWindowControllers(); 1553 auto root_window_controllers = Shell::GetAllRootWindowControllers();
1722 ASSERT_EQ(2U, root_window_controllers.size()); 1554 ASSERT_EQ(2U, root_window_controllers.size());
1723 Shelf* shelf_1 = root_window_controllers[0]->GetShelf(); 1555 Shelf* shelf_1 = root_window_controllers[0]->GetShelf();
1724 Shelf* shelf_2 = root_window_controllers[1]->GetShelf(); 1556 Shelf* shelf_2 = root_window_controllers[1]->GetShelf();
1725 1557
1726 // Create two maximized windows, one in each display. 1558 // Create two maximized windows, one in each display.
1727 aura::Window* window_1 = 1559 aura::Window* window_1 =
1728 CreateTestWindowInParent(root_window_controllers[0]->GetRootWindow()); 1560 CreateTestWindowInParent(root_window_controllers[0]->GetRootWindow());
1729 window_1->SetBounds(gfx::Rect(0, 0, 100, 100)); 1561 window_1->SetBounds(gfx::Rect(0, 0, 100, 100));
1730 window_1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1562 window_1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
(...skipping 20 matching lines...) Expand all
1751 root_window_controllers[1]->GetRootWindow()); 1583 root_window_controllers[1]->GetRootWindow());
1752 1584
1753 // An edge swipe in one display should only affect the shelf in that display. 1585 // An edge swipe in one display should only affect the shelf in that display.
1754 monitor_1_generator.GestureEdgeSwipe(); 1586 monitor_1_generator.GestureEdgeSwipe();
1755 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState()); 1587 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
1756 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState()); 1588 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
1757 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_1->GetAutoHideState()); 1589 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_1->GetAutoHideState());
1758 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState()); 1590 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
1759 1591
1760 // Back to normal after an update. 1592 // Back to normal after an update.
1761 shell->UpdateShelfVisibility(); 1593 Shell::GetInstance()->UpdateShelfVisibility();
1762 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState()); 1594 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
1763 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState()); 1595 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
1764 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState()); 1596 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState());
1765 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState()); 1597 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_2->GetAutoHideState());
1766 1598
1767 monitor_2_generator.GestureEdgeSwipe(); 1599 monitor_2_generator.GestureEdgeSwipe();
1768 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState()); 1600 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_1->GetVisibilityState());
1769 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState()); 1601 EXPECT_EQ(SHELF_AUTO_HIDE, shelf_2->GetVisibilityState());
1770 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState()); 1602 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf_1->GetAutoHideState());
1771 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_2->GetAutoHideState()); 1603 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf_2->GetAutoHideState());
1772 } 1604 }
1773 1605
1774 #if defined(OS_WIN) 1606 TEST_F(ShelfLayoutManagerTest, GestureDrag) {
1775 // RootWindow and Display can't resize on Windows Ash. http://crbug.com/165962
1776 #define MAYBE_GestureDrag DISABLED_GestureDrag
1777 #else
1778 #define MAYBE_GestureDrag GestureDrag
1779 #endif
1780
1781 TEST_F(ShelfLayoutManagerTest, MAYBE_GestureDrag) {
1782 // Slop is an implementation detail of gesture recognition, and complicates 1607 // Slop is an implementation detail of gesture recognition, and complicates
1783 // these tests. Ignore it. 1608 // these tests. Ignore it.
1784 ui::GestureConfiguration::GetInstance() 1609 ui::GestureConfiguration::GetInstance()
1785 ->set_max_touch_move_in_pixels_for_click(0); 1610 ->set_max_touch_move_in_pixels_for_click(0);
1786 Shelf* shelf = GetShelf(); 1611 Shelf* shelf = GetShelf();
1787 { 1612 {
1788 SCOPED_TRACE("BOTTOM"); 1613 SCOPED_TRACE("BOTTOM");
1789 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); 1614 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
1790 RunGestureDragTests(gfx::Vector2d(0, 120)); 1615 RunGestureDragTests(gfx::Vector2d(0, 120));
1791 } 1616 }
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1853 window2->SetBounds(gfx::Rect(850, 50, 50, 50)); 1678 window2->SetBounds(gfx::Rect(850, 50, 50, 50));
1854 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 1679 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
1855 // Move back to primary display. 1680 // Move back to primary display.
1856 window2->SetBounds(gfx::Rect(50, 50, 50, 50)); 1681 window2->SetBounds(gfx::Rect(50, 50, 50, 50));
1857 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 1682 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
1858 } 1683 }
1859 1684
1860 // Test that the shelf animates back to its normal position upon a user 1685 // Test that the shelf animates back to its normal position upon a user
1861 // completing a gesture drag. 1686 // completing a gesture drag.
1862 TEST_F(ShelfLayoutManagerTest, ShelfAnimatesWhenGestureComplete) { 1687 TEST_F(ShelfLayoutManagerTest, ShelfAnimatesWhenGestureComplete) {
1863 if (!SupportsHostWindowResize())
James Cook 2016/08/02 16:34:18 It's great you cleaned up unnecessary stuff like t
msw 2016/08/02 18:12:29 Acknowledged.
1864 return;
1865
1866 // Test the shelf animates back to its original visible bounds when it is 1688 // Test the shelf animates back to its original visible bounds when it is
1867 // dragged when there are no visible windows. 1689 // dragged when there are no visible windows.
1868 Shelf* shelf = GetShelf(); 1690 Shelf* shelf = GetShelf();
1869 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1691 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1870 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 1692 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
1871 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 1693 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
1872 gfx::Rect visible_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); 1694 gfx::Rect visible_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1873 { 1695 {
1874 // Enable animations so that we can make sure that they occur. 1696 // Enable animations so that we can make sure that they occur.
1875 ui::ScopedAnimationDurationScaleMode regular_animations( 1697 ui::ScopedAnimationDurationScaleMode regular_animations(
1876 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); 1698 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
1877 1699
1878 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1700 ui::test::EventGenerator& generator(GetEventGenerator());
1879 gfx::Rect shelf_bounds_in_screen = 1701 gfx::Rect shelf_bounds_in_screen =
1880 GetShelfWidget()->GetWindowBoundsInScreen(); 1702 GetShelfWidget()->GetWindowBoundsInScreen();
1881 gfx::Point start(shelf_bounds_in_screen.CenterPoint()); 1703 gfx::Point start(shelf_bounds_in_screen.CenterPoint());
1882 gfx::Point end(start.x(), shelf_bounds_in_screen.bottom()); 1704 gfx::Point end(start.x(), shelf_bounds_in_screen.bottom());
1883 generator.GestureScrollSequence(start, end, 1705 generator.GestureScrollSequence(start, end,
1884 base::TimeDelta::FromMilliseconds(10), 5); 1706 base::TimeDelta::FromMilliseconds(10), 5);
1885 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 1707 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
1886 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 1708 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
1887 1709
1888 ShelfAnimationWaiter waiter(visible_bounds); 1710 ShelfAnimationWaiter waiter(visible_bounds);
(...skipping 11 matching lines...) Expand all
1900 gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen(); 1722 gfx::Rect auto_hidden_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
1901 1723
1902 { 1724 {
1903 // Enable the animations so that we can make sure they do occur. 1725 // Enable the animations so that we can make sure they do occur.
1904 ui::ScopedAnimationDurationScaleMode regular_animations( 1726 ui::ScopedAnimationDurationScaleMode regular_animations(
1905 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); 1727 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
1906 1728
1907 gfx::Point start = 1729 gfx::Point start =
1908 GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint(); 1730 GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
1909 gfx::Point end(start.x(), start.y() - 100); 1731 gfx::Point end(start.x(), start.y() - 100);
1910 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1732 ui::test::EventGenerator& generator(GetEventGenerator());
1911 1733
1912 // Test that the shelf animates to the visible bounds after a swipe up on 1734 // Test that the shelf animates to the visible bounds after a swipe up on
1913 // the auto hidden shelf. 1735 // the auto hidden shelf.
1914 generator.GestureScrollSequence(start, end, 1736 generator.GestureScrollSequence(start, end,
1915 base::TimeDelta::FromMilliseconds(10), 1); 1737 base::TimeDelta::FromMilliseconds(10), 1);
1916 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 1738 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
1917 ShelfAnimationWaiter waiter1(visible_bounds); 1739 ShelfAnimationWaiter waiter1(visible_bounds);
1918 waiter1.WaitTillDoneAnimating(); 1740 waiter1.WaitTillDoneAnimating();
1919 EXPECT_TRUE(waiter1.WasValidAnimation()); 1741 EXPECT_TRUE(waiter1.WasValidAnimation());
1920 1742
(...skipping 19 matching lines...) Expand all
1940 // Turn on auto-hide for the shelf. 1762 // Turn on auto-hide for the shelf.
1941 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1763 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
1942 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 1764 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
1943 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 1765 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
1944 1766
1945 // Show the status menu. That should make the shelf visible again. 1767 // Show the status menu. That should make the shelf visible again.
1946 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled( 1768 WmShell::Get()->accelerator_controller()->PerformActionIfEnabled(
1947 SHOW_SYSTEM_TRAY_BUBBLE); 1769 SHOW_SYSTEM_TRAY_BUBBLE);
1948 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState()); 1770 EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
1949 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState()); 1771 EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
1950 EXPECT_TRUE(GetSystemTray()->HasSystemBubble()); 1772 EXPECT_TRUE(GetPrimarySystemTray()->HasSystemBubble());
1951 } 1773 }
1952 1774
1953 TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) { 1775 TEST_F(ShelfLayoutManagerTest, WorkAreaChangeWorkspace) {
1954 // Make sure the shelf is always visible. 1776 // Make sure the shelf is always visible.
1955 Shelf* shelf = GetShelf(); 1777 Shelf* shelf = GetShelf();
1956 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 1778 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
1957 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1779 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
1958 layout_manager->LayoutShelf(); 1780 layout_manager->LayoutShelf();
1959 1781
1960 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 1782 views::Widget* widget_one = CreateTestWidget();
1961 params.bounds = gfx::Rect(0, 0, 200, 200);
1962 params.context = CurrentContext();
1963 views::Widget* widget_one = CreateTestWidgetWithParams(params);
1964 widget_one->Maximize(); 1783 widget_one->Maximize();
1965 1784
1966 views::Widget* widget_two = CreateTestWidgetWithParams(params); 1785 views::Widget* widget_two = CreateTestWidget();
1967 widget_two->Maximize(); 1786 widget_two->Maximize();
1968 widget_two->Activate(); 1787 widget_two->Activate();
1969 1788
1970 // Both windows are maximized. They should be of the same size. 1789 // Both windows are maximized. They should be of the same size.
1971 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(), 1790 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(),
1972 widget_two->GetNativeWindow()->bounds().ToString()); 1791 widget_two->GetNativeWindow()->bounds().ToString());
1973 int area_when_shelf_shown = 1792 int area_when_shelf_shown =
1974 widget_one->GetNativeWindow()->bounds().size().GetArea(); 1793 widget_one->GetNativeWindow()->bounds().size().GetArea();
1975 1794
1976 // Now hide the shelf. 1795 // Now hide the shelf.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 EXPECT_FALSE(shelf_widget->GetDimsShelf()); 1843 EXPECT_FALSE(shelf_widget->GetDimsShelf());
2025 } 1844 }
2026 1845
2027 // Make sure that the shelf will not hide if the mouse is between a bubble and 1846 // Make sure that the shelf will not hide if the mouse is between a bubble and
2028 // the shelf. 1847 // the shelf.
2029 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) { 1848 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) {
2030 Shelf* shelf = GetShelf(); 1849 Shelf* shelf = GetShelf();
2031 ShelfLayoutManager* layout_manager = GetShelfLayoutManager(); 1850 ShelfLayoutManager* layout_manager = GetShelfLayoutManager();
2032 StatusAreaWidget* status_area_widget = 1851 StatusAreaWidget* status_area_widget =
2033 shelf->shelf_widget()->status_area_widget(); 1852 shelf->shelf_widget()->status_area_widget();
2034 SystemTray* tray = GetSystemTray(); 1853 SystemTray* tray = GetPrimarySystemTray();
2035 1854
2036 // Create a visible window so auto-hide behavior is enforced. 1855 // Create a visible window so auto-hide behavior is enforced.
2037 CreateTestWidget(); 1856 CreateTestWidget();
2038 1857
2039 layout_manager->LayoutShelf(); 1858 layout_manager->LayoutShelf();
2040 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 1859 ui::test::EventGenerator& generator(GetEventGenerator());
2041 1860
2042 // Make two iterations - first without a message bubble which should make 1861 // Make two iterations - first without a message bubble which should make
2043 // the shelf disappear and then with a message bubble which should keep it 1862 // the shelf disappear and then with a message bubble which should keep it
2044 // visible. 1863 // visible.
2045 for (int i = 0; i < 2; i++) { 1864 for (int i = 0; i < 2; i++) {
2046 // Make sure the shelf is visible and position the mouse over it. Then 1865 // Make sure the shelf is visible and position the mouse over it. Then
2047 // allow auto hide. 1866 // allow auto hide.
2048 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 1867 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
2049 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); 1868 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2050 gfx::Point center = 1869 gfx::Point center =
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 1933
2115 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 1934 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2116 std::unique_ptr<aura::Window> w1(CreateTestWindow()); 1935 std::unique_ptr<aura::Window> w1(CreateTestWindow());
2117 w1->Show(); 1936 w1->Show();
2118 wm::ActivateWindow(w1.get()); 1937 wm::ActivateWindow(w1.get());
2119 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType()); 1938 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
2120 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 1939 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
2121 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType()); 1940 EXPECT_EQ(SHELF_BACKGROUND_OVERLAP, GetShelfWidget()->GetBackgroundType());
2122 } 1941 }
2123 1942
2124 #if defined(OS_CHROMEOS)
2125 #define MAYBE_StatusAreaHitBoxCoversEdge StatusAreaHitBoxCoversEdge
2126 #else
2127 #define MAYBE_StatusAreaHitBoxCoversEdge DISABLED_StatusAreaHitBoxCoversEdge
2128 #endif
2129
2130 // Verify the hit bounds of the status area extend to the edge of the shelf. 1943 // Verify the hit bounds of the status area extend to the edge of the shelf.
2131 TEST_F(ShelfLayoutManagerTest, MAYBE_StatusAreaHitBoxCoversEdge) { 1944 TEST_F(ShelfLayoutManagerTest, StatusAreaHitBoxCoversEdge) {
2132 UpdateDisplay("400x400"); 1945 StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
2133 Shelf* shelf = GetShelf(); 1946 ui::test::EventGenerator& generator(GetEventGenerator());
2134 StatusAreaWidget* status_area_widget = Shell::GetPrimaryRootWindowController() 1947 display::Display display = display::Screen::GetScreen()->GetPrimaryDisplay();
2135 ->shelf_widget() 1948 gfx::Rect inset_display_bounds = display.bounds();
2136 ->status_area_widget(); 1949 inset_display_bounds.Inset(1, 1);
2137 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
2138 generator.MoveMouseTo(399, 399);
2139 1950
2140 // Test bottom right pixel for bottom alignment. 1951 // Test bottom right pixel for bottom alignment.
1952 GetShelf()->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
1953 generator.MoveMouseTo(inset_display_bounds.bottom_right());
1954 #if defined(OS_WIN)
1955 // The bottom right pixel doesn't work on Windows; see crbug.com/633434
1956 generator.MoveMouseTo(
1957 status_area_widget->GetWindowBoundsInScreen().CenterPoint());
1958 #endif
James Cook 2016/08/02 16:34:18 If possible I would just #if !defined(OS_WIN) the
msw 2016/08/02 18:12:29 Done.
2141 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); 1959 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2142 generator.ClickLeftButton(); 1960 generator.ClickLeftButton();
2143 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown()); 1961 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2144 generator.ClickLeftButton(); 1962 generator.ClickLeftButton();
2145 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); 1963 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2146 1964
2147 // Test bottom right pixel for right alignment. 1965 // Test bottom right pixel for right alignment.
2148 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); 1966 GetShelf()->SetAlignment(SHELF_ALIGNMENT_RIGHT);
1967 generator.MoveMouseTo(inset_display_bounds.bottom_right());
1968 #if defined(OS_WIN)
1969 // The bottom right pixel doesn't work on Windows; see crbug.com/633434
1970 generator.MoveMouseTo(
1971 status_area_widget->GetWindowBoundsInScreen().CenterPoint());
1972 #endif
2149 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); 1973 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2150 generator.ClickLeftButton(); 1974 generator.ClickLeftButton();
2151 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown()); 1975 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2152 generator.ClickLeftButton(); 1976 generator.ClickLeftButton();
2153 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); 1977 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2154 1978
2155 // Test bottom left pixel for left alignment. 1979 // Test bottom left pixel for left alignment.
2156 generator.MoveMouseTo(0, 399); 1980 generator.MoveMouseTo(inset_display_bounds.bottom_left());
James Cook 2016/08/02 16:34:18 Doesn't this check 1, 398 instead of 0, 399? (We'v
msw 2016/08/02 18:12:29 Done. Thanks for catching that!
2157 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 1981 GetShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT);
2158 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); 1982 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2159 generator.ClickLeftButton(); 1983 generator.ClickLeftButton();
2160 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown()); 1984 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown());
2161 generator.ClickLeftButton(); 1985 generator.ClickLeftButton();
2162 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); 1986 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown());
2163 } 1987 }
2164 1988
2165 // Tests that when the auto-hide behaviour is changed during an animation the 1989 // Tests that when the auto-hide behaviour is changed during an animation the
2166 // target bounds are updated to reflect the new state. 1990 // target bounds are updated to reflect the new state.
2167 TEST_F(ShelfLayoutManagerTest, 1991 TEST_F(ShelfLayoutManagerTest,
2168 ShelfAutoHideToggleDuringAnimationUpdatesBounds) { 1992 ShelfAutoHideToggleDuringAnimationUpdatesBounds) {
2169 Shelf* shelf = GetShelf();
2170 aura::Window* status_window = 1993 aura::Window* status_window =
2171 GetShelfWidget()->status_area_widget()->GetNativeView(); 1994 GetShelfWidget()->status_area_widget()->GetNativeView();
2172 gfx::Rect initial_bounds = status_window->bounds(); 1995 gfx::Rect initial_bounds = status_window->bounds();
2173 1996
2174 ui::ScopedAnimationDurationScaleMode regular_animations( 1997 ui::ScopedAnimationDurationScaleMode regular_animations(
2175 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION); 1998 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION);
2176 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 1999 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
2177 gfx::Rect hide_target_bounds = status_window->GetTargetBounds(); 2000 gfx::Rect hide_target_bounds = status_window->GetTargetBounds();
2178 EXPECT_GT(hide_target_bounds.y(), initial_bounds.y()); 2001 EXPECT_GT(hide_target_bounds.y(), initial_bounds.y());
2179 2002
2180 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); 2003 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER);
2181 gfx::Rect reshow_target_bounds = status_window->GetTargetBounds(); 2004 gfx::Rect reshow_target_bounds = status_window->GetTargetBounds();
2182 EXPECT_EQ(initial_bounds, reshow_target_bounds); 2005 EXPECT_EQ(initial_bounds, reshow_target_bounds);
2183 } 2006 }
2184 2007
2185 // Tests that during shutdown, that window activation changes are properly 2008 // Tests that during shutdown, that window activation changes are properly
2186 // handled, and do not crash (crbug.com/458768) 2009 // handled, and do not crash (crbug.com/458768)
2187 TEST_F(ShelfLayoutManagerTest, ShutdownHandlesWindowActivation) { 2010 TEST_F(ShelfLayoutManagerTest, ShutdownHandlesWindowActivation) {
2188 Shelf* shelf = GetShelf(); 2011 GetShelf()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2189 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
2190 2012
2191 aura::Window* window1 = CreateTestWindowInShellWithId(0); 2013 aura::Window* window1 = CreateTestWindowInShellWithId(0);
2192 window1->SetBounds(gfx::Rect(0, 0, 100, 100)); 2014 window1->SetBounds(gfx::Rect(0, 0, 100, 100));
2193 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 2015 window1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
2194 window1->Show(); 2016 window1->Show();
2195 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(0)); 2017 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(0));
2196 window2->SetBounds(gfx::Rect(0, 0, 100, 100)); 2018 window2->SetBounds(gfx::Rect(0, 0, 100, 100));
2197 window2->Show(); 2019 window2->Show();
2198 wm::ActivateWindow(window1); 2020 wm::ActivateWindow(window1);
2199 2021
2200 GetShelfWidget()->Shutdown(); 2022 GetShelfWidget()->Shutdown();
2201 2023
2202 // Deleting a focused maximized window will switch focus to |window2|. This 2024 // Deleting a focused maximized window will switch focus to |window2|. This
2203 // would normally cause the ShelfLayoutManager to update its state. However 2025 // would normally cause the ShelfLayoutManager to update its state. However
2204 // during shutdown we want to handle this without crashing. 2026 // during shutdown we want to handle this without crashing.
2205 delete window1; 2027 delete window1;
2206 } 2028 }
2207 2029
2208 TEST_F(ShelfLayoutManagerTest, ShelfLayoutInUnifiedDesktop) { 2030 TEST_F(ShelfLayoutManagerTest, ShelfLayoutInUnifiedDesktop) {
2209 if (!SupportsMultipleDisplays()) 2031 if (!SupportsMultipleDisplays())
2210 return; 2032 return;
2033
2211 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true); 2034 Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(true);
2212
2213 UpdateDisplay("500x400, 500x400"); 2035 UpdateDisplay("500x400, 500x400");
2214 2036
2215 StatusAreaWidget* status_area_widget = Shell::GetPrimaryRootWindowController() 2037 StatusAreaWidget* status_area_widget = GetShelfWidget()->status_area_widget();
2216 ->shelf_widget()
2217 ->status_area_widget();
2218 EXPECT_TRUE(status_area_widget->IsVisible()); 2038 EXPECT_TRUE(status_area_widget->IsVisible());
2219 // Shelf should be in the first display's area. 2039 // Shelf should be in the first display's area.
2220 gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen()); 2040 gfx::Rect status_area_bounds(status_area_widget->GetWindowBoundsInScreen());
2221 EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds)); 2041 EXPECT_TRUE(gfx::Rect(0, 0, 500, 400).Contains(status_area_bounds));
2222 EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right()); 2042 EXPECT_EQ(gfx::Point(500, 400), status_area_bounds.bottom_right());
2223 } 2043 }
2224 2044
2225 } // namespace ash 2045 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698