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

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

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

Powered by Google App Engine
This is Rietveld 408576698