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

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

Powered by Google App Engine
This is Rietveld 408576698