Commit 2817c9d4 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

Reland "splitview: Cleanup window selector unittests."

This is a reland of cc477ff2
Original change's description:
> splitview: Cleanup window selector unittests.
> 
> Move splitview window selector unittests to their own test class.
> 
> Bug: None
> Test: ash_unittests
> Change-Id: I8153c916a05ef9ab6011105ca670dfc0e73ee257
> Reviewed-on: https://chromium-review.googlesource.com/661327
> Reviewed-by: Xiaoqian Dai <xdai@chromium.org>
> Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
> Commit-Queue: Sammie Quon <sammiequon@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#501487}

Bug: None
Change-Id: If130112bdc3501d340b1c157e5b98d3af78fe5e8
Reviewed-on: https://chromium-review.googlesource.com/666039
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarXiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502879}
parent 83d0eb4f
...@@ -173,10 +173,6 @@ class WindowSelectorTest : public AshTestBase { ...@@ -173,10 +173,6 @@ class WindowSelectorTest : public AshTestBase {
return window_selector_controller()->window_selector_.get(); return window_selector_controller()->window_selector_.get();
} }
SplitViewController* split_view_controller() {
return Shell::Get()->split_view_controller();
}
void ToggleOverview() { window_selector_controller()->ToggleOverview(); } void ToggleOverview() { window_selector_controller()->ToggleOverview(); }
aura::Window* GetOverviewWindowForMinimizedState(int index, aura::Window* GetOverviewWindowForMinimizedState(int index,
...@@ -337,14 +333,6 @@ class WindowSelectorTest : public AshTestBase { ...@@ -337,14 +333,6 @@ class WindowSelectorTest : public AshTestBase {
return window_selector()->text_filter_widget_.get(); return window_selector()->text_filter_widget_.get();
} }
gfx::Rect GetSplitViewLeftWindowBounds(aura::Window* window) {
return split_view_controller()->GetLeftWindowBoundsInScreen(window);
}
gfx::Rect GetSplitViewRightWindowBounds(aura::Window* window) {
return split_view_controller()->GetRightWindowBoundsInScreen(window);
}
gfx::Rect GetGridBounds() { gfx::Rect GetGridBounds() {
if (window_selector()) if (window_selector())
return window_selector()->grid_list_[0]->bounds_; return window_selector()->grid_list_[0]->bounds_;
...@@ -1929,14 +1917,39 @@ TEST_F(WindowSelectorTest, OverviewWhileDragging) { ...@@ -1929,14 +1917,39 @@ TEST_F(WindowSelectorTest, OverviewWhileDragging) {
resizer->RevertDrag(); resizer->RevertDrag();
} }
class SplitViewWindowSelectorTest : public WindowSelectorTest {
public:
SplitViewWindowSelectorTest() = default;
~SplitViewWindowSelectorTest() override = default;
void SetUp() override {
WindowSelectorTest::SetUp();
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTabletSplitView);
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
}
SplitViewController* split_view_controller() {
return Shell::Get()->split_view_controller();
}
protected:
gfx::Rect GetSplitViewLeftWindowBounds(aura::Window* window) {
return split_view_controller()->GetLeftWindowBoundsInScreen(window);
}
gfx::Rect GetSplitViewRightWindowBounds(aura::Window* window) {
return split_view_controller()->GetRightWindowBoundsInScreen(window);
}
private:
DISALLOW_COPY_AND_ASSIGN(SplitViewWindowSelectorTest);
};
// Tests that dragging a overview window selector item to the edge of the screen // Tests that dragging a overview window selector item to the edge of the screen
// snaps the window. If two windows are snapped to left and right side of the // snaps the window. If two windows are snapped to left and right side of the
// screen, exit the overview mode. // screen, exit the overview mode.
TEST_F(WindowSelectorTest, DragOverviewWindowToSnap) { TEST_F(SplitViewWindowSelectorTest, DragOverviewWindowToSnap) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTabletSplitView);
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
const gfx::Rect bounds(0, 0, 400, 400); const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
...@@ -1944,7 +1957,7 @@ TEST_F(WindowSelectorTest, DragOverviewWindowToSnap) { ...@@ -1944,7 +1957,7 @@ TEST_F(WindowSelectorTest, DragOverviewWindowToSnap) {
ToggleOverview(); ToggleOverview();
EXPECT_TRUE(window_selector_controller()->IsSelecting()); EXPECT_TRUE(window_selector_controller()->IsSelecting());
EXPECT_EQ(split_view_controller()->IsSplitViewModeActive(), false); EXPECT_FALSE(split_view_controller()->IsSplitViewModeActive());
// Drag |window1| selector item to snap to left. // Drag |window1| selector item to snap to left.
const int grid_index = 0; const int grid_index = 0;
...@@ -1958,7 +1971,7 @@ TEST_F(WindowSelectorTest, DragOverviewWindowToSnap) { ...@@ -1958,7 +1971,7 @@ TEST_F(WindowSelectorTest, DragOverviewWindowToSnap) {
window_selector()->Drag(selector_item1, end_location1); window_selector()->Drag(selector_item1, end_location1);
window_selector()->CompleteDrag(selector_item1); window_selector()->CompleteDrag(selector_item1);
EXPECT_EQ(split_view_controller()->IsSplitViewModeActive(), true); EXPECT_TRUE(split_view_controller()->IsSplitViewModeActive());
EXPECT_EQ(split_view_controller()->state(), EXPECT_EQ(split_view_controller()->state(),
SplitViewController::LEFT_SNAPPED); SplitViewController::LEFT_SNAPPED);
EXPECT_EQ(split_view_controller()->left_window(), window1.get()); EXPECT_EQ(split_view_controller()->left_window(), window1.get());
...@@ -1999,13 +2012,8 @@ TEST_F(WindowSelectorTest, DragOverviewWindowToSnap) { ...@@ -1999,13 +2012,8 @@ TEST_F(WindowSelectorTest, DragOverviewWindowToSnap) {
// Verify the window grid size changes as expected when dragging items around in // Verify the window grid size changes as expected when dragging items around in
// overview mode when split view is enabled. // overview mode when split view is enabled.
TEST_F(WindowSelectorTest, WindowGridSizeWhileDraggingWithSplitView) { TEST_F(SplitViewWindowSelectorTest, WindowGridSizeWhileDraggingWithSplitView) {
// Enable split view, enter maximize mode, add some windows and enter overview // Add three windows and enter overview mode.
// mode.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTabletSplitView);
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
const gfx::Rect bounds(0, 0, 400, 400); const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
...@@ -2070,17 +2078,13 @@ TEST_F(WindowSelectorTest, WindowGridSizeWhileDraggingWithSplitView) { ...@@ -2070,17 +2078,13 @@ TEST_F(WindowSelectorTest, WindowGridSizeWhileDraggingWithSplitView) {
window_selector()->Drag(selector_item, center); window_selector()->Drag(selector_item, center);
EXPECT_EQ(GetSplitViewRightWindowBounds(window1.get()), GetGridBounds()); EXPECT_EQ(GetSplitViewRightWindowBounds(window1.get()), GetGridBounds());
// TODO(crbug.com/766725): There is a memory leak if we tear down while
// overview and splitview mode is active. Investigate.
ToggleOverview(); ToggleOverview();
} }
// Tests dragging a unsnappable window. // Tests dragging a unsnappable window.
TEST_F(WindowSelectorTest, DraggingNonSnapableAppWithSplitView) { TEST_F(SplitViewWindowSelectorTest, DraggingNonSnapableAppWithSplitView) {
// Enable split view, enter maximize mode, add a unsnappable window and enter
// overview mode.
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTabletSplitView);
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
const gfx::Rect bounds(0, 0, 400, 400); const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> unsnappable_window(CreateWindow(bounds)); std::unique_ptr<aura::Window> unsnappable_window(CreateWindow(bounds));
unsnappable_window->SetProperty(aura::client::kResizeBehaviorKey, unsnappable_window->SetProperty(aura::client::kResizeBehaviorKey,
...@@ -2111,17 +2115,12 @@ TEST_F(WindowSelectorTest, DraggingNonSnapableAppWithSplitView) { ...@@ -2111,17 +2115,12 @@ TEST_F(WindowSelectorTest, DraggingNonSnapableAppWithSplitView) {
window_selector()->Drag(selector_item, window_selector()->Drag(selector_item,
gfx::Point(root_window_bounds.right() / 2, 0)); gfx::Point(root_window_bounds.right() / 2, 0));
EXPECT_EQ(expected_grid_bounds, GetGridBounds()); EXPECT_EQ(expected_grid_bounds, GetGridBounds());
ToggleOverview();
} }
// Tests that if there is only one window in the MRU window list in the overview // Tests that if there is only one window in the MRU window list in the overview
// mode, snapping the window to one side of the screen will end the overview // mode, snapping the window to one side of the screen will end the overview
// mode since there is no more window left in the overview window grid. // mode since there is no more window left in the overview window grid.
TEST_F(WindowSelectorTest, EmptyWindowsListExitOverview) { TEST_F(SplitViewWindowSelectorTest, EmptyWindowsListExitOverview) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTabletSplitView);
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
const gfx::Rect bounds(0, 0, 400, 400); const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
...@@ -2147,11 +2146,7 @@ TEST_F(WindowSelectorTest, EmptyWindowsListExitOverview) { ...@@ -2147,11 +2146,7 @@ TEST_F(WindowSelectorTest, EmptyWindowsListExitOverview) {
} }
// Verify that the split view overview overlay is shown when expected. // Verify that the split view overview overlay is shown when expected.
TEST_F(WindowSelectorTest, SplitViewOverviewOverlayVisibility) { TEST_F(SplitViewWindowSelectorTest, SplitViewOverviewOverlayVisibility) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTabletSplitView);
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
const gfx::Rect bounds(0, 0, 400, 400); const gfx::Rect bounds(0, 0, 400, 400);
std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); std::unique_ptr<aura::Window> window1(CreateWindow(bounds));
std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); std::unique_ptr<aura::Window> window2(CreateWindow(bounds));
...@@ -2187,11 +2182,7 @@ TEST_F(WindowSelectorTest, SplitViewOverviewOverlayVisibility) { ...@@ -2187,11 +2182,7 @@ TEST_F(WindowSelectorTest, SplitViewOverviewOverlayVisibility) {
// Verify that the split view overview overlays widget reparents when starting a // Verify that the split view overview overlays widget reparents when starting a
// drag on a different display. // drag on a different display.
TEST_F(WindowSelectorTest, SplitViewOverviewOverlayWidgetReparenting) { TEST_F(SplitViewWindowSelectorTest, SplitViewOverviewOverlayWidgetReparenting) {
base::CommandLine::ForCurrentProcess()->AppendSwitch(
switches::kAshEnableTabletSplitView);
Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(true);
// Add two displays and one window on each display. // Add two displays and one window on each display.
UpdateDisplay("600x600,600x600"); UpdateDisplay("600x600,600x600");
auto root_windows = Shell::Get()->GetAllRootWindows(); auto root_windows = Shell::Get()->GetAllRootWindows();
......
...@@ -22,7 +22,7 @@ namespace ash { ...@@ -22,7 +22,7 @@ namespace ash {
class SplitViewControllerTest; class SplitViewControllerTest;
class SplitViewDivider; class SplitViewDivider;
class WindowSelectorTest; class SplitViewWindowSelectorTest;
// The controller for the split view. It snaps a window to left/right side of // The controller for the split view. It snaps a window to left/right side of
// the screen. It also observes the two snapped windows and decides when to exit // the screen. It also observes the two snapped windows and decides when to exit
...@@ -113,7 +113,7 @@ class ASH_EXPORT SplitViewController : public aura::WindowObserver, ...@@ -113,7 +113,7 @@ class ASH_EXPORT SplitViewController : public aura::WindowObserver,
private: private:
friend class SplitViewControllerTest; friend class SplitViewControllerTest;
friend class WindowSelectorTest; friend class SplitViewWindowSelectorTest;
// Starts/Stops observing |window|. // Starts/Stops observing |window|.
void StartObserving(aura::Window* window); void StartObserving(aura::Window* window);
......
...@@ -32,7 +32,7 @@ class ASH_EXPORT SplitViewOverviewOverlay { ...@@ -32,7 +32,7 @@ class ASH_EXPORT SplitViewOverviewOverlay {
bool visible() const; bool visible() const;
private: private:
FRIEND_TEST_ALL_PREFIXES(WindowSelectorTest, FRIEND_TEST_ALL_PREFIXES(SplitViewWindowSelectorTest,
SplitViewOverviewOverlayWidgetReparenting); SplitViewOverviewOverlayWidgetReparenting);
class SplitViewOverviewOverlayView; class SplitViewOverviewOverlayView;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment