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

Side by Side Diff: ash/wm/overview/window_selector_unittest.cc

Issue 2700523004: Remove docked windows entirely in M59. (Closed)
Patch Set: Yet another Rebase ... Created 3 years, 10 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "ash/common/accessibility_delegate.h" 8 #include "ash/common/accessibility_delegate.h"
9 #include "ash/common/accessibility_types.h" 9 #include "ash/common/accessibility_types.h"
10 #include "ash/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
11 #include "ash/common/shelf/shelf_widget.h" 11 #include "ash/common/shelf/shelf_widget.h"
12 #include "ash/common/shelf/wm_shelf.h" 12 #include "ash/common/shelf/wm_shelf.h"
13 #include "ash/common/system/tray/system_tray.h" 13 #include "ash/common/system/tray/system_tray.h"
14 #include "ash/common/test/test_shelf_delegate.h" 14 #include "ash/common/test/test_shelf_delegate.h"
15 #include "ash/common/wm/dock/docked_window_layout_manager.h"
16 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 15 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
17 #include "ash/common/wm/mru_window_tracker.h" 16 #include "ash/common/wm/mru_window_tracker.h"
18 #include "ash/common/wm/overview/scoped_transform_overview_window.h" 17 #include "ash/common/wm/overview/scoped_transform_overview_window.h"
19 #include "ash/common/wm/overview/window_grid.h" 18 #include "ash/common/wm/overview/window_grid.h"
20 #include "ash/common/wm/overview/window_selector.h" 19 #include "ash/common/wm/overview/window_selector.h"
21 #include "ash/common/wm/overview/window_selector_controller.h" 20 #include "ash/common/wm/overview/window_selector_controller.h"
22 #include "ash/common/wm/overview/window_selector_item.h" 21 #include "ash/common/wm/overview/window_selector_item.h"
23 #include "ash/common/wm/panels/panel_layout_manager.h" 22 #include "ash/common/wm/panels/panel_layout_manager.h"
24 #include "ash/common/wm/window_state.h" 23 #include "ash/common/wm/window_state.h"
25 #include "ash/common/wm/wm_event.h" 24 #include "ash/common/wm/wm_event.h"
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview2 = 541 const std::vector<std::unique_ptr<WindowSelectorItem>>& overview2 =
543 GetWindowItemsForRoot(0); 542 GetWindowItemsForRoot(0);
544 543
545 // The order should be MRU. 544 // The order should be MRU.
546 EXPECT_EQ(2, overview2[0]->GetWindow()->GetShellWindowId()); 545 EXPECT_EQ(2, overview2[0]->GetWindow()->GetShellWindowId());
547 EXPECT_EQ(1, overview2[1]->GetWindow()->GetShellWindowId()); 546 EXPECT_EQ(1, overview2[1]->GetWindow()->GetShellWindowId());
548 EXPECT_EQ(3, overview2[2]->GetWindow()->GetShellWindowId()); 547 EXPECT_EQ(3, overview2[2]->GetWindow()->GetShellWindowId());
549 ToggleOverview(); 548 ToggleOverview();
550 } 549 }
551 550
552 // Test class used for tests that need docked windows enabled.
553 class EnabledDockedWindowsWindowSelectorTest : public WindowSelectorTest {
554 public:
555 EnabledDockedWindowsWindowSelectorTest() = default;
556 ~EnabledDockedWindowsWindowSelectorTest() override = default;
557
558 void SetUp() override {
559 base::CommandLine::ForCurrentProcess()->AppendSwitch(
560 ash::switches::kAshEnableDockedWindows);
561 WindowSelectorTest::SetUp();
562 }
563
564 private:
565 DISALLOW_COPY_AND_ASSIGN(EnabledDockedWindowsWindowSelectorTest);
566 };
567
568 // Tests entering overview mode with docked windows
569 TEST_F(EnabledDockedWindowsWindowSelectorTest, BasicWithDocked) {
570 // aura::Window* root_window = Shell::GetPrimaryRootWindow();
571 gfx::Rect bounds(300, 0, 200, 200);
572 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
573 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
574 std::unique_ptr<aura::Window> docked1(CreateWindow(bounds));
575 std::unique_ptr<aura::Window> docked2(CreateWindow(bounds));
576
577 wm::WMEvent dock_event(wm::WM_EVENT_DOCK);
578 wm::GetWindowState(docked1.get())->OnWMEvent(&dock_event);
579
580 wm::WindowState* docked_state2 = wm::GetWindowState(docked2.get());
581 docked_state2->OnWMEvent(&dock_event);
582 wm::WMEvent minimize_event(wm::WM_EVENT_MINIMIZE);
583 docked_state2->OnWMEvent(&minimize_event);
584
585 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get()));
586 gfx::Rect docked_bounds = docked1->GetBoundsInScreen();
587
588 EXPECT_NE(bounds.ToString(), docked_bounds.ToString());
589 EXPECT_FALSE(WindowsOverlapping(window1.get(), docked1.get()));
590 EXPECT_FALSE(WindowsOverlapping(window1.get(), docked2.get()));
591 EXPECT_FALSE(docked2->IsVisible());
592
593 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED,
594 wm::GetWindowState(docked1.get())->GetStateType());
595 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED,
596 wm::GetWindowState(docked2.get())->GetStateType());
597
598 ToggleOverview();
599
600 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get()));
601
602 gfx::Rect container_bounds = docked1->parent()->bounds();
603 ShelfWidget* shelf = GetPrimaryShelf()->shelf_widget();
604 DockedWindowLayoutManager* manager =
605 DockedWindowLayoutManager::Get(WmWindow::Get(docked1.get()));
606
607 // Minimized docked windows stays invisible.
608 EXPECT_FALSE(docked2->IsVisible());
609 EXPECT_TRUE(GetOverviewWindowForMinimizedState(0, docked2.get()));
610
611 // Docked area shrinks.
612 EXPECT_EQ(0, manager->docked_bounds().width());
613
614 // Work area takes the whole screen minus the shelf.
615 gfx::Rect work_area = display::Screen::GetScreen()
616 ->GetDisplayNearestWindow(docked1.get())
617 .work_area();
618 gfx::Size expected_work_area_bounds(container_bounds.size());
619 expected_work_area_bounds.Enlarge(0,
620 -shelf->GetWindowBoundsInScreen().height());
621 EXPECT_EQ(expected_work_area_bounds.ToString(), work_area.size().ToString());
622
623 // Docked window can still be activated, which will exit the overview mode.
624 ClickWindow(docked1.get());
625 EXPECT_TRUE(wm::IsActiveWindow(docked1.get()));
626 EXPECT_FALSE(window_selector_controller()->IsSelecting());
627
628 // Docked area has a window in it.
629 EXPECT_GT(manager->docked_bounds().width(), 0);
630
631 // Work area takes the whole screen minus the shelf and the docked area.
632 work_area = display::Screen::GetScreen()
633 ->GetDisplayNearestWindow(docked1.get())
634 .work_area();
635 expected_work_area_bounds = container_bounds.size();
636 expected_work_area_bounds.Enlarge(-manager->docked_bounds().width(),
637 -shelf->GetWindowBoundsInScreen().height());
638 EXPECT_EQ(expected_work_area_bounds.ToString(), work_area.size().ToString());
639 }
640
641 // Tests that selecting a docked window updates docked layout pushing another
642 // window to get docked-minimized.
643 TEST_F(EnabledDockedWindowsWindowSelectorTest, ActivateDockedWindow) {
644 // aura::Window* root_window = Shell::GetPrimaryRootWindow();
645 gfx::Rect bounds(300, 0, 200, 200);
646 std::unique_ptr<views::Widget> widget1 = CreateWindowWidget(bounds);
647 std::unique_ptr<views::Widget> widget2 = CreateWindowWidget(bounds);
648
649 aura::test::TestWindowDelegate delegate;
650 delegate.set_minimum_size(gfx::Size(200, 500));
651 std::unique_ptr<aura::Window> docked_window1(
652 CreateTestWindowInShellWithDelegate(&delegate, -1, bounds));
653 docked_window1->SetProperty(aura::client::kTopViewInset, kHeaderHeight);
654 std::unique_ptr<aura::Window> docked_window2(
655 CreateTestWindowInShellWithDelegate(&delegate, -1, bounds));
656 docked_window2->SetProperty(aura::client::kTopViewInset, kHeaderHeight);
657 wm::WindowState* state1 = wm::GetWindowState(docked_window1.get());
658 wm::WindowState* state2 = wm::GetWindowState(docked_window2.get());
659
660 // Dock the second window first, then the first window.
661 wm::WMEvent dock_event(wm::WM_EVENT_DOCK);
662 state2->OnWMEvent(&dock_event);
663 state1->OnWMEvent(&dock_event);
664
665 // Both windows' restored bounds are same.
666 const gfx::Rect expected_bounds = docked_window1->bounds();
667 EXPECT_EQ(expected_bounds.ToString(), docked_window2->bounds().ToString());
668
669 // |docked_window1| is docked and visible.
670 EXPECT_TRUE(docked_window1->IsVisible());
671 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
672 // |docked_window2| is docked-minimized and hidden.
673 EXPECT_FALSE(docked_window2->IsVisible());
674 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state2->GetStateType());
675
676 ToggleOverview();
677
678 // Minimized should stay minimized.
679 EXPECT_FALSE(docked_window2->IsVisible());
680 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state2->GetStateType());
681
682 aura::Window* window_for_minimized_docked_window2 =
683 GetOverviewWindowForMinimizedState(0, docked_window2.get());
684 ASSERT_TRUE(window_for_minimized_docked_window2);
685
686 // Activate |docked_window2| leaving the overview.
687 const gfx::Rect rect =
688 GetTransformedBoundsInRootWindow(window_for_minimized_docked_window2);
689 gfx::Point point(rect.top_right().x() - 50, rect.top_right().y() + 50);
690 ui::test::EventGenerator event_generator(docked_window2->GetRootWindow(),
691 point);
692 event_generator.ClickLeftButton();
693
694 EXPECT_FALSE(IsSelecting());
695
696 // Windows' bounds are still the same.
697 EXPECT_EQ(expected_bounds.ToString(), docked_window1->bounds().ToString());
698 EXPECT_EQ(expected_bounds.ToString(), docked_window2->bounds().ToString());
699
700 // |docked_window1| is docked-minimized and hidden.
701 EXPECT_FALSE(docked_window1->IsVisible());
702 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state1->GetStateType());
703 // |docked_window2| is docked and visible.
704 EXPECT_TRUE(docked_window2->IsVisible());
705 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state2->GetStateType());
706 }
707
708 // Tests that clicking on the close button closes the docked window.
709 TEST_F(EnabledDockedWindowsWindowSelectorTest, CloseDockedWindow) {
710 // aura::Window* root_window = Shell::GetPrimaryRootWindow();
711 gfx::Rect bounds(300, 0, 200, 200);
712 std::unique_ptr<views::Widget> widget1 = CreateWindowWidget(bounds);
713 std::unique_ptr<views::Widget> widget2 = CreateWindowWidget(bounds);
714
715 aura::test::TestWindowDelegate delegate;
716 delegate.set_minimum_size(gfx::Size(200, 500));
717 std::unique_ptr<aura::Window> docked_window1(
718 CreateTestWindowInShellWithDelegate(&delegate, -1, bounds));
719 docked_window1->SetProperty(aura::client::kTopViewInset, kHeaderHeight);
720 std::unique_ptr<views::Widget> docked2 = CreateWindowWidget(bounds);
721 aura::Window* docked_window2 = docked2->GetNativeWindow();
722 wm::WindowState* state1 = wm::GetWindowState(docked_window1.get());
723 wm::WindowState* state2 = wm::GetWindowState(docked_window2);
724
725 // Dock the first window first, then the second window.
726 wm::WMEvent dock_event(wm::WM_EVENT_DOCK);
727 state1->OnWMEvent(&dock_event);
728 state2->OnWMEvent(&dock_event);
729
730 const gfx::Rect expected_bounds1 = docked_window1->bounds();
731
732 // |docked_window1| is docked-minimized and hidden.
733 EXPECT_FALSE(docked_window1->IsVisible());
734 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state1->GetStateType());
735 // |docked_window2| is docked and visible.
736 EXPECT_TRUE(docked_window2->IsVisible());
737 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state2->GetStateType());
738
739 ToggleOverview();
740
741 // Close |docked_window2| (staying in overview).
742 const gfx::Rect rect = GetTransformedBoundsInRootWindow(docked_window2);
743 gfx::Point point(rect.top_right().x() - 5, rect.top_right().y() + 5);
744 ui::test::EventGenerator event_generator(docked_window2->GetRootWindow(),
745 point);
746
747 // Minimized window stays invisible and in the minimized state while in
748 // overview.
749 EXPECT_FALSE(docked_window1->IsVisible());
750 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state1->GetStateType());
751 EXPECT_TRUE(docked_window2->IsVisible());
752 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state2->GetStateType());
753
754 EXPECT_TRUE(GetOverviewWindowForMinimizedState(0, docked_window1.get()));
755
756 event_generator.ClickLeftButton();
757 // |docked2| widget is closed.
758 EXPECT_TRUE(docked2->IsClosed());
759
760 // Exit overview.
761 ToggleOverview();
762
763 // Window bounds are still the same.
764 EXPECT_EQ(expected_bounds1.ToString(), docked_window1->bounds().ToString());
765
766 // |docked_window1| returns to docked-minimized and hidden state.
767 EXPECT_FALSE(docked_window1->IsVisible());
768 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state1->GetStateType());
769 }
770
771 // Tests that clicking on the close button closes the docked-minimized window.
772 TEST_F(EnabledDockedWindowsWindowSelectorTest, CloseDockedMinimizedWindow) {
773 // aura::Window* root_window = Shell::GetPrimaryRootWindow();
774 gfx::Rect bounds(300, 0, 200, 200);
775 std::unique_ptr<views::Widget> widget1 = CreateWindowWidget(bounds);
776 std::unique_ptr<views::Widget> widget2 = CreateWindowWidget(bounds);
777
778 aura::test::TestWindowDelegate delegate;
779 delegate.set_minimum_size(gfx::Size(200, 500));
780 std::unique_ptr<aura::Window> docked_window1(
781 CreateTestWindowInShellWithDelegate(&delegate, -1, bounds));
782 docked_window1->SetProperty(aura::client::kTopViewInset, kHeaderHeight);
783 std::unique_ptr<views::Widget> docked2 = CreateWindowWidget(bounds);
784 aura::Window* docked_window2 = docked2->GetNativeWindow();
785 wm::WindowState* state1 = wm::GetWindowState(docked_window1.get());
786 wm::WindowState* state2 = wm::GetWindowState(docked_window2);
787
788 // Dock the second window first, then the first window.
789 wm::WMEvent dock_event(wm::WM_EVENT_DOCK);
790 state2->OnWMEvent(&dock_event);
791 state1->OnWMEvent(&dock_event);
792
793 const gfx::Rect expected_bounds1 = docked_window1->bounds();
794
795 // |docked_window1| is docked and visible.
796 EXPECT_TRUE(docked_window1->IsVisible());
797 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
798 // |docked_window2| is docked-minimized and hidden.
799 EXPECT_FALSE(docked_window2->IsVisible());
800 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state2->GetStateType());
801
802 ToggleOverview();
803
804 // Both windows are visible while in overview.
805 EXPECT_TRUE(docked_window1->IsVisible());
806 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
807 EXPECT_FALSE(docked_window2->IsVisible());
808 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state2->GetStateType());
809
810 // Close |docked_window2| (staying in overview).
811 aura::Window* window_for_minimized_docked_window2 =
812 GetOverviewWindowForMinimizedState(0, docked_window2);
813 ASSERT_TRUE(window_for_minimized_docked_window2);
814 const gfx::Rect rect =
815 GetTransformedBoundsInRootWindow(window_for_minimized_docked_window2);
816 gfx::Point point(rect.top_right().x() - 10, rect.top_right().y() - 10);
817 ui::test::EventGenerator event_generator(docked_window2->GetRootWindow(),
818 point);
819 event_generator.ClickLeftButton();
820 // |docked2| widget is closed.
821 EXPECT_TRUE(docked2->IsClosed());
822
823 // Exit overview.
824 ToggleOverview();
825
826 // Window bounds are still the same.
827 EXPECT_EQ(expected_bounds1.ToString(),
828 docked_window1->GetTargetBounds().ToString());
829
830 // |docked_window1| returns to docked and visible state.
831 EXPECT_TRUE(docked_window1->IsVisible());
832 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
833 }
834
835 // Tests selecting a window by tapping on it. 551 // Tests selecting a window by tapping on it.
836 TEST_F(WindowSelectorTest, BasicGesture) { 552 TEST_F(WindowSelectorTest, BasicGesture) {
837 gfx::Rect bounds(0, 0, 400, 400); 553 gfx::Rect bounds(0, 0, 400, 400);
838 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); 554 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
839 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); 555 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
840 wm::ActivateWindow(window1.get()); 556 wm::ActivateWindow(window1.get());
841 EXPECT_EQ(window1.get(), GetFocusedWindow()); 557 EXPECT_EQ(window1.get(), GetFocusedWindow());
842 ToggleOverview(); 558 ToggleOverview();
843 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); 559 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow());
844 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 560 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after
2126 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); 1842 aura::client::WINDOW_MOVE_SOURCE_MOUSE));
2127 ASSERT_TRUE(resizer.get()); 1843 ASSERT_TRUE(resizer.get());
2128 gfx::Point location = resizer->GetInitialLocation(); 1844 gfx::Point location = resizer->GetInitialLocation();
2129 location.Offset(20, 20); 1845 location.Offset(20, 20);
2130 resizer->Drag(location, 0); 1846 resizer->Drag(location, 0);
2131 ToggleOverview(); 1847 ToggleOverview();
2132 resizer->RevertDrag(); 1848 resizer->RevertDrag();
2133 } 1849 }
2134 1850
2135 } // namespace ash 1851 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698