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

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

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

Powered by Google App Engine
This is Rietveld 408576698