Commit 5e47fa79 authored by Qiang Xu's avatar Qiang Xu Committed by Commit Bot

cros: add multi window resizer test for two snapped windows

changes:
Add test coverage for multi window resizer dragging to change bounds of
two snapped windows. Also in file cleanup.

Bug: 783589
Test: covered by tests.
Change-Id: I1ce5e5d4aa762c55a5a5933be452ce3fb4c7b1fa
Reviewed-on: https://chromium-review.googlesource.com/799810Reviewed-by: default avatarRobert Flack <flackr@chromium.org>
Commit-Queue: Qiang(Joe) Xu <warx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520691}
parent 1144ea86
......@@ -9,7 +9,9 @@
#include "ash/shell.h"
#include "ash/shell_test_api.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h"
#include "ash/wm/workspace/workspace_event_handler_test_helper.h"
#include "ash/wm/workspace_controller.h"
#include "ash/wm/workspace_controller_test_api.h"
......@@ -48,7 +50,7 @@ class TestWidgetDelegate : public views::WidgetDelegateView {
class MultiWindowResizeControllerTest : public AshTestBase {
public:
MultiWindowResizeControllerTest() : resize_controller_(NULL) {}
MultiWindowResizeControllerTest() = default;
~MultiWindowResizeControllerTest() override = default;
void SetUp() override {
......@@ -88,7 +90,7 @@ class MultiWindowResizeControllerTest : public AshTestBase {
return resize_controller_->resize_widget_.get();
}
MultiWindowResizeController* resize_controller_;
MultiWindowResizeController* resize_controller_ = nullptr;
private:
DISALLOW_COPY_AND_ASSIGN(MultiWindowResizeControllerTest);
......@@ -104,7 +106,7 @@ TEST_F(MultiWindowResizeControllerTest, BasicTests) {
std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
&delegate2, -2, gfx::Rect(100, 0, 100, 100)));
delegate2.set_window_component(HTRIGHT);
ui::test::EventGenerator generator(w1->GetRootWindow());
ui::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(w1->bounds().CenterPoint());
EXPECT_TRUE(HasPendingShow());
EXPECT_TRUE(IsShowing());
......@@ -205,7 +207,7 @@ TEST_F(MultiWindowResizeControllerTest, DeleteWindow) {
std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
&delegate2, -2, gfx::Rect(100, 0, 100, 100)));
delegate2.set_window_component(HTRIGHT);
ui::test::EventGenerator generator(w1->GetRootWindow());
ui::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(w1->bounds().CenterPoint());
EXPECT_TRUE(HasPendingShow());
EXPECT_TRUE(IsShowing());
......@@ -228,7 +230,7 @@ TEST_F(MultiWindowResizeControllerTest, DeleteWindow) {
// Delete w2.
w2.reset();
EXPECT_TRUE(resize_widget() == NULL);
EXPECT_FALSE(resize_widget());
EXPECT_FALSE(HasPendingShow());
EXPECT_FALSE(IsShowing());
EXPECT_FALSE(HasTarget(w1.get()));
......@@ -244,7 +246,7 @@ TEST_F(MultiWindowResizeControllerTest, Drag) {
std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
&delegate2, -2, gfx::Rect(100, 0, 100, 100)));
delegate2.set_window_component(HTRIGHT);
ui::test::EventGenerator generator(w1->GetRootWindow());
ui::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(w1->bounds().CenterPoint());
EXPECT_TRUE(HasPendingShow());
EXPECT_TRUE(IsShowing());
......@@ -269,8 +271,8 @@ TEST_F(MultiWindowResizeControllerTest, Drag) {
EXPECT_TRUE(resize_widget());
EXPECT_FALSE(HasPendingShow());
EXPECT_TRUE(IsShowing());
EXPECT_EQ("0,0 110x100", w1->bounds().ToString());
EXPECT_EQ("110,0 100x100", w2->bounds().ToString());
EXPECT_EQ(gfx::Rect(0, 0, 110, 100), w1->bounds());
EXPECT_EQ(gfx::Rect(110, 0, 100, 100), w2->bounds());
}
// Makes sure three windows are picked up.
......@@ -288,7 +290,7 @@ TEST_F(MultiWindowResizeControllerTest, Three) {
&delegate3, -3, gfx::Rect(200, 0, 100, 100)));
delegate3.set_window_component(HTRIGHT);
ui::test::EventGenerator generator(w1->GetRootWindow());
ui::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(w1->bounds().CenterPoint());
EXPECT_TRUE(HasPendingShow());
EXPECT_TRUE(IsShowing());
......@@ -324,7 +326,7 @@ TEST_F(MultiWindowResizeControllerTest, ClickOutside) {
&delegate2, -2, gfx::Rect(100, 0, 100, 100)));
delegate2.set_window_component(HTLEFT);
ui::test::EventGenerator& generator(GetEventGenerator());
ui::test::EventGenerator& generator = GetEventGenerator();
gfx::Point w1_center_in_screen = w1->GetBoundsInScreen().CenterPoint();
generator.MoveMouseTo(w1_center_in_screen);
EXPECT_TRUE(HasPendingShow());
......@@ -348,4 +350,55 @@ TEST_F(MultiWindowResizeControllerTest, ClickOutside) {
EXPECT_FALSE(IsShowing());
}
// Tests dragging to resize two snapped windows.
TEST_F(MultiWindowResizeControllerTest, TwoSnappedWindows) {
UpdateDisplay("400x300");
// Create two snapped windows, one left snapped, one right snapped.
aura::test::TestWindowDelegate delegate1;
std::unique_ptr<aura::Window> w1(CreateTestWindowInShellWithDelegate(
&delegate1, -1, gfx::Rect(100, 100, 100, 100)));
delegate1.set_window_component(HTRIGHT);
wm::WindowState* w1_state = wm::GetWindowState(w1.get());
const wm::WMEvent snap_left(wm::WM_EVENT_SNAP_LEFT);
w1_state->OnWMEvent(&snap_left);
EXPECT_EQ(mojom::WindowStateType::LEFT_SNAPPED, w1_state->GetStateType());
aura::test::TestWindowDelegate delegate2;
std::unique_ptr<aura::Window> w2(CreateTestWindowInShellWithDelegate(
&delegate2, -2, gfx::Rect(100, 100, 100, 100)));
delegate2.set_window_component(HTRIGHT);
wm::WindowState* w2_state = wm::GetWindowState(w2.get());
const wm::WMEvent snap_right(wm::WM_EVENT_SNAP_RIGHT);
w2_state->OnWMEvent(&snap_right);
EXPECT_EQ(mojom::WindowStateType::RIGHT_SNAPPED, w2_state->GetStateType());
ui::test::EventGenerator& generator = GetEventGenerator();
generator.MoveMouseTo(w1->bounds().CenterPoint());
EXPECT_TRUE(HasPendingShow());
EXPECT_TRUE(IsShowing());
// Force a show now.
ShowNow();
EXPECT_FALSE(HasPendingShow());
EXPECT_TRUE(IsShowing());
// Move the mouse over the resize widget.
ASSERT_TRUE(resize_widget());
gfx::Rect bounds(resize_widget()->GetWindowBoundsInScreen());
gfx::Point resize_widget_center = bounds.CenterPoint();
generator.MoveMouseTo(resize_widget_center);
EXPECT_FALSE(HasPendingShow());
EXPECT_TRUE(IsShowing());
// Move the resize widget.
generator.PressLeftButton();
generator.MoveMouseTo(resize_widget_center.x() + 100,
resize_widget_center.y());
generator.ReleaseLeftButton();
// Check snapped states and bounds.
EXPECT_EQ(mojom::WindowStateType::LEFT_SNAPPED, w1_state->GetStateType());
EXPECT_EQ(gfx::Rect(0, 0, 300, 252), w1->bounds());
EXPECT_EQ(mojom::WindowStateType::RIGHT_SNAPPED, w2_state->GetStateType());
EXPECT_EQ(gfx::Rect(300, 0, 100, 252), w2->bounds());
}
} // namespace ash
......@@ -101,6 +101,7 @@
-MultiWindowResizeControllerTest.Drag
-MultiWindowResizeControllerTest.IsOverWindows
-MultiWindowResizeControllerTest.Three
-MultiWindowResizeControllerTest.TwoSnappedWindows
-NativeCursorManagerAshTest.FractionalScale
-NativeCursorManagerAshTest.LockCursor
-NativeCursorManagerAshTest.SetCursor
......
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