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

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

Issue 2133333002: [ash-md] Allows docked windows to be selected in overview mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: [ash-md] Allows docked windows to be selected in overview mode (comments + tests) Created 4 years, 5 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 | « ash/common/wm/overview/window_selector.cc ('k') | 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 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/aura/wm_window_aura.h" 8 #include "ash/aura/wm_window_aura.h"
9 #include "ash/common/accessibility_delegate.h" 9 #include "ash/common/accessibility_delegate.h"
10 #include "ash/common/accessibility_types.h" 10 #include "ash/common/accessibility_types.h"
11 #include "ash/common/ash_switches.h" 11 #include "ash/common/ash_switches.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/shell_window_ids.h" 13 #include "ash/common/shell_window_ids.h"
14 #include "ash/common/wm/dock/docked_window_layout_manager.h"
14 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 15 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
15 #include "ash/common/wm/mru_window_tracker.h" 16 #include "ash/common/wm/mru_window_tracker.h"
16 #include "ash/common/wm/overview/scoped_transform_overview_window.h" 17 #include "ash/common/wm/overview/scoped_transform_overview_window.h"
17 #include "ash/common/wm/overview/window_grid.h" 18 #include "ash/common/wm/overview/window_grid.h"
18 #include "ash/common/wm/overview/window_selector.h" 19 #include "ash/common/wm/overview/window_selector.h"
19 #include "ash/common/wm/overview/window_selector_controller.h" 20 #include "ash/common/wm/overview/window_selector_controller.h"
20 #include "ash/common/wm/overview/window_selector_item.h" 21 #include "ash/common/wm/overview/window_selector_item.h"
21 #include "ash/common/wm/panels/panel_layout_manager.h" 22 #include "ash/common/wm/panels/panel_layout_manager.h"
22 #include "ash/common/wm/window_state.h" 23 #include "ash/common/wm/window_state.h"
23 #include "ash/common/wm/wm_event.h" 24 #include "ash/common/wm/wm_event.h"
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 EXPECT_FALSE(docked2->IsVisible()); 610 EXPECT_FALSE(docked2->IsVisible());
610 611
611 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, 612 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED,
612 wm::GetWindowState(docked1.get())->GetStateType()); 613 wm::GetWindowState(docked1.get())->GetStateType());
613 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, 614 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED,
614 wm::GetWindowState(docked2.get())->GetStateType()); 615 wm::GetWindowState(docked2.get())->GetStateType());
615 616
616 ToggleOverview(); 617 ToggleOverview();
617 618
618 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); 619 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get()));
619 // Docked windows stays the same. 620
620 EXPECT_EQ(docked_bounds.ToString(), docked1->GetBoundsInScreen().ToString()); 621 gfx::Rect container_bounds = docked1->parent()->bounds();
621 EXPECT_FALSE(docked2->IsVisible()); 622 ShelfWidget* shelf = Shell::GetPrimaryRootWindowController()->shelf_widget();
622 623 DockedWindowLayoutManager* manager =
624 DockedWindowLayoutManager::Get(WmWindowAura::Get(docked1.get()));
625
626 if (ash::MaterialDesignController::IsOverviewMaterial()) {
627 // Docked windows get shown and transformed.
628 EXPECT_TRUE(docked2->IsVisible());
629
630 // Docked area shrinks.
631 DockedWindowLayoutManager* manager =
632 DockedWindowLayoutManager::Get(WmWindowAura::Get(docked1.get()));
633 EXPECT_EQ(0, manager->docked_bounds().width());
634
635 // Work area takes the whole screen minus the shelf.
636 gfx::Rect work_area = display::Screen::GetScreen()
637 ->GetDisplayNearestWindow(docked1.get())
638 .work_area();
639 gfx::Size expected_work_area_bounds(container_bounds.size());
640 expected_work_area_bounds.Enlarge(
641 0, -shelf->GetWindowBoundsInScreen().height());
642 EXPECT_EQ(expected_work_area_bounds.ToString(),
643 work_area.size().ToString());
644 } else {
645 // Docked windows stays the same.
646 EXPECT_EQ(docked_bounds.ToString(),
647 docked1->GetBoundsInScreen().ToString());
648 EXPECT_FALSE(docked2->IsVisible());
649 }
623 // Docked window can still be activated, which will exit the overview mode. 650 // Docked window can still be activated, which will exit the overview mode.
624 ClickWindow(docked1.get()); 651 ClickWindow(docked1.get());
625 EXPECT_TRUE(wm::IsActiveWindow(docked1.get())); 652 EXPECT_TRUE(wm::IsActiveWindow(docked1.get()));
626 EXPECT_FALSE(window_selector_controller()->IsSelecting()); 653 EXPECT_FALSE(window_selector_controller()->IsSelecting());
654
655 // Docked area has a window in it.
656 EXPECT_GT(manager->docked_bounds().width(), 0);
657
658 // Work area takes the whole screen minus the shelf and the docked area.
659 gfx::Rect work_area = display::Screen::GetScreen()
660 ->GetDisplayNearestWindow(docked1.get())
661 .work_area();
662 gfx::Size expected_work_area_bounds(container_bounds.size());
663 expected_work_area_bounds.Enlarge(-manager->docked_bounds().width(),
664 -shelf->GetWindowBoundsInScreen().height());
665 EXPECT_EQ(expected_work_area_bounds.ToString(), work_area.size().ToString());
666 }
667
668 // Tests that selecting a docked window updates docked layout pushing another
669 // window to get docked-minimized.
670 TEST_P(WindowSelectorTest, ActivateDockedWindow) {
671 if (!ash::MaterialDesignController::IsOverviewMaterial())
672 return;
673
674 // aura::Window* root_window = Shell::GetPrimaryRootWindow();
675 gfx::Rect bounds(300, 0, 200, 200);
676 std::unique_ptr<views::Widget> widget1 = CreateWindowWidget(bounds);
677 std::unique_ptr<views::Widget> widget2 = CreateWindowWidget(bounds);
678
679 aura::test::TestWindowDelegate delegate;
680 delegate.set_minimum_size(gfx::Size(200, 500));
681 std::unique_ptr<aura::Window> docked_window1(
682 CreateTestWindowInShellWithDelegate(&delegate, -1, bounds));
683 std::unique_ptr<aura::Window> docked_window2(
684 CreateTestWindowInShellWithDelegate(&delegate, -1, bounds));
685 wm::WindowState* state1 = wm::GetWindowState(docked_window1.get());
686 wm::WindowState* state2 = wm::GetWindowState(docked_window2.get());
687
688 // Dock the second window first, then the first window.
689 wm::WMEvent dock_event(wm::WM_EVENT_DOCK);
690 state2->OnWMEvent(&dock_event);
691 state1->OnWMEvent(&dock_event);
692
693 // Both windows' restored bounds are same.
694 const gfx::Rect expected_bounds = docked_window1->bounds();
695 EXPECT_EQ(expected_bounds.ToString(), docked_window2->bounds().ToString());
696
697 // |docked_window1| is docked and visible.
698 EXPECT_TRUE(docked_window1->IsVisible());
699 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
700 // |docked_window2| is docked-minimized and hidden.
701 EXPECT_FALSE(docked_window2->IsVisible());
702 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state2->GetStateType());
703
704 ToggleOverview();
705
706 // Activate |docked_window2| leaving the overview.
707 const gfx::RectF rect =
708 GetTransformedBoundsInRootWindow(docked_window2.get());
709 gfx::Point point(rect.top_right().x() - 50, rect.top_right().y() + 10);
710 ui::test::EventGenerator event_generator(docked_window2->GetRootWindow(),
711 point);
712 event_generator.ClickLeftButton();
713
714 // Windows' bounds are still the same.
715 EXPECT_EQ(expected_bounds.ToString(), docked_window1->bounds().ToString());
716 EXPECT_EQ(expected_bounds.ToString(), docked_window2->bounds().ToString());
717
718 // |docked_window1| is docked-minimized and hidden.
719 EXPECT_FALSE(docked_window1->IsVisible());
720 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state1->GetStateType());
721 // |docked_window2| is docked and visible.
722 EXPECT_TRUE(docked_window2->IsVisible());
723 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state2->GetStateType());
724 }
725
726 // Tests that clicking on the close button closes the docked window.
727 TEST_P(WindowSelectorTest, CloseDockedWindow) {
728 if (!ash::MaterialDesignController::IsOverviewMaterial())
729 return;
730
731 // aura::Window* root_window = Shell::GetPrimaryRootWindow();
732 gfx::Rect bounds(300, 0, 200, 200);
733 std::unique_ptr<views::Widget> widget1 = CreateWindowWidget(bounds);
734 std::unique_ptr<views::Widget> widget2 = CreateWindowWidget(bounds);
735
736 aura::test::TestWindowDelegate delegate;
737 delegate.set_minimum_size(gfx::Size(200, 500));
738 std::unique_ptr<aura::Window> docked_window1(
739 CreateTestWindowInShellWithDelegate(&delegate, -1, bounds));
740 std::unique_ptr<views::Widget> docked2 = CreateWindowWidget(bounds);
741 aura::Window* docked_window2 = docked2->GetNativeWindow();
742 wm::WindowState* state1 = wm::GetWindowState(docked_window1.get());
743 wm::WindowState* state2 = wm::GetWindowState(docked_window2);
744
745 // Dock the first window first, then the second window.
746 wm::WMEvent dock_event(wm::WM_EVENT_DOCK);
747 state1->OnWMEvent(&dock_event);
748 state2->OnWMEvent(&dock_event);
749
750 const gfx::Rect expected_bounds1 = docked_window1->bounds();
751
752 // |docked_window1| is docked-minimized and hidden.
753 EXPECT_FALSE(docked_window1->IsVisible());
754 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state1->GetStateType());
755 // |docked_window2| is docked and visible.
756 EXPECT_TRUE(docked_window2->IsVisible());
757 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state2->GetStateType());
758
759 ToggleOverview();
760
761 // Close |docked_window2| (staying in overview).
762 const gfx::RectF rect = GetTransformedBoundsInRootWindow(docked_window2);
763 gfx::Point point(rect.top_right().x() - 5, rect.top_right().y() - 5);
764 ui::test::EventGenerator event_generator(docked_window2->GetRootWindow(),
765 point);
766 // Both windows are visible while in overview.
767 EXPECT_TRUE(docked_window1->IsVisible());
768 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
769 EXPECT_TRUE(docked_window2->IsVisible());
770 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state2->GetStateType());
771
772 event_generator.ClickLeftButton();
773 // |docked2| widget is closed.
774 EXPECT_TRUE(docked2->IsClosed());
775
776 // Exit overview.
777 ToggleOverview();
778
779 // Window bounds are still the same.
780 EXPECT_EQ(expected_bounds1.ToString(), docked_window1->bounds().ToString());
781
782 // |docked_window1| returns to docked-minimized and hidden state.
783 EXPECT_FALSE(docked_window1->IsVisible());
784 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state1->GetStateType());
785 }
786
787 // Tests that clicking on the close button closes the docked-minimized window.
788 TEST_P(WindowSelectorTest, CloseDockedMinimizedWindow) {
789 if (!ash::MaterialDesignController::IsOverviewMaterial())
790 return;
791
792 // aura::Window* root_window = Shell::GetPrimaryRootWindow();
793 gfx::Rect bounds(300, 0, 200, 200);
794 std::unique_ptr<views::Widget> widget1 = CreateWindowWidget(bounds);
795 std::unique_ptr<views::Widget> widget2 = CreateWindowWidget(bounds);
796
797 aura::test::TestWindowDelegate delegate;
798 delegate.set_minimum_size(gfx::Size(200, 500));
799 std::unique_ptr<aura::Window> docked_window1(
800 CreateTestWindowInShellWithDelegate(&delegate, -1, bounds));
801 std::unique_ptr<views::Widget> docked2 = CreateWindowWidget(bounds);
802 aura::Window* docked_window2 = docked2->GetNativeWindow();
803 wm::WindowState* state1 = wm::GetWindowState(docked_window1.get());
804 wm::WindowState* state2 = wm::GetWindowState(docked_window2);
805
806 // Dock the second window first, then the first window.
807 wm::WMEvent dock_event(wm::WM_EVENT_DOCK);
808 state2->OnWMEvent(&dock_event);
809 state1->OnWMEvent(&dock_event);
810
811 const gfx::Rect expected_bounds1 = docked_window1->bounds();
812
813 // |docked_window1| is docked and visible.
814 EXPECT_TRUE(docked_window1->IsVisible());
815 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
816 // |docked_window2| is docked-minimized and hidden.
817 EXPECT_FALSE(docked_window2->IsVisible());
818 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED_MINIMIZED, state2->GetStateType());
819
820 ToggleOverview();
821
822 // Close |docked_window2| (staying in overview).
823 const gfx::RectF rect = GetTransformedBoundsInRootWindow(docked_window2);
824 gfx::Point point(rect.top_right().x() - 5, rect.top_right().y() - 5);
825 ui::test::EventGenerator event_generator(docked_window2->GetRootWindow(),
826 point);
827 // Both windows are visible while in overview.
828 EXPECT_TRUE(docked_window1->IsVisible());
829 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
830 EXPECT_TRUE(docked_window2->IsVisible());
831 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state2->GetStateType());
832
833 event_generator.ClickLeftButton();
834 // |docked2| widget is closed.
835 EXPECT_TRUE(docked2->IsClosed());
836
837 // Exit overview.
838 ToggleOverview();
839
840 // Window bounds are still the same.
841 EXPECT_EQ(expected_bounds1.ToString(),
842 docked_window1->GetTargetBounds().ToString());
843
844 // |docked_window1| returns to docked and visible state.
845 EXPECT_TRUE(docked_window1->IsVisible());
846 EXPECT_EQ(wm::WINDOW_STATE_TYPE_DOCKED, state1->GetStateType());
627 } 847 }
628 848
629 // Tests selecting a window by tapping on it. 849 // Tests selecting a window by tapping on it.
630 TEST_P(WindowSelectorTest, BasicGesture) { 850 TEST_P(WindowSelectorTest, BasicGesture) {
631 gfx::Rect bounds(0, 0, 400, 400); 851 gfx::Rect bounds(0, 0, 400, 400);
632 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); 852 std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
633 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); 853 std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
634 wm::ActivateWindow(window1.get()); 854 wm::ActivateWindow(window1.get());
635 EXPECT_EQ(window1.get(), GetFocusedWindow()); 855 EXPECT_EQ(window1.get(), GetFocusedWindow());
636 ToggleOverview(); 856 ToggleOverview();
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 bounds.y()); 2065 bounds.y());
1846 EXPECT_LE(transformed_rect.bottom(), bounds.bottom()); 2066 EXPECT_LE(transformed_rect.bottom(), bounds.bottom());
1847 EXPECT_NEAR(transformed_rect.x() - bounds.x(), 2067 EXPECT_NEAR(transformed_rect.x() - bounds.x(),
1848 bounds.right() - transformed_rect.right(), 1); 2068 bounds.right() - transformed_rect.right(), 1);
1849 EXPECT_NEAR( 2069 EXPECT_NEAR(
1850 transformed_rect.y() + (int)(scale * inset) - header_height - bounds.y(), 2070 transformed_rect.y() + (int)(scale * inset) - header_height - bounds.y(),
1851 bounds.bottom() - transformed_rect.bottom(), 1); 2071 bounds.bottom() - transformed_rect.bottom(), 1);
1852 } 2072 }
1853 2073
1854 } // namespace ash 2074 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/overview/window_selector.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698