| Index: ash/wm/overview/window_selector_unittest.cc
|
| diff --git a/ash/wm/overview/window_selector_unittest.cc b/ash/wm/overview/window_selector_unittest.cc
|
| index cd25675f9a8fa53875c315de12bcadc79fff06b8..071991878b3833c95017046b8067306b2b460157 100644
|
| --- a/ash/wm/overview/window_selector_unittest.cc
|
| +++ b/ash/wm/overview/window_selector_unittest.cc
|
| @@ -3,8 +3,11 @@
|
| // found in the LICENSE file.
|
|
|
| #include <algorithm>
|
| +#include <map>
|
| +#include <vector>
|
|
|
| #include "ash/accessibility_delegate.h"
|
| +#include "ash/ash_switches.h"
|
| #include "ash/drag_drop/drag_drop_controller.h"
|
| #include "ash/root_window_controller.h"
|
| #include "ash/screen_util.h"
|
| @@ -28,6 +31,7 @@
|
| #include "ash/wm/window_util.h"
|
| #include "ash/wm/wm_event.h"
|
| #include "base/basictypes.h"
|
| +#include "base/command_line.h"
|
| #include "base/compiler_specific.h"
|
| #include "base/memory/scoped_vector.h"
|
| #include "base/run_loop.h"
|
| @@ -58,6 +62,12 @@ namespace {
|
| typedef std::vector<aura::Window*> WindowList;
|
| typedef std::map<const aura::Window*, int> WindowIndexMap;
|
|
|
| +// A short drag distance that will not cause an overview item to close.
|
| +const int kShortDragDistance = 10;
|
| +
|
| +// A far drag distance that will cause an overview item to close.
|
| +const int kFarDragDistance = 200;
|
| +
|
| class NonActivatableActivationDelegate
|
| : public aura::client::ActivationDelegate {
|
| public:
|
| @@ -133,6 +143,17 @@ class WindowSelectorTest : public test::AshTestBase {
|
| return widget;
|
| }
|
|
|
| + scoped_ptr<views::Widget> CreateWindowWidget(const gfx::Rect& bounds) {
|
| + scoped_ptr<views::Widget> widget(new views::Widget);
|
| + views::Widget::InitParams params;
|
| + params.bounds = bounds;
|
| + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
| + widget->Init(params);
|
| + widget->Show();
|
| + ParentWindowInPrimaryRootWindow(widget->GetNativeWindow());
|
| + return widget.Pass();
|
| + }
|
| +
|
| bool WindowsOverlapping(aura::Window* window1, aura::Window* window2) {
|
| gfx::RectF window1_bounds = GetTransformedTargetBounds(window1);
|
| gfx::RectF window2_bounds = GetTransformedTargetBounds(window2);
|
| @@ -270,6 +291,24 @@ class WindowSelectorTest : public test::AshTestBase {
|
| DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest);
|
| };
|
|
|
| +class WindowSelectorSwipeToCloseDisabledTest : public WindowSelectorTest {
|
| + public:
|
| + WindowSelectorSwipeToCloseDisabledTest() {}
|
| + virtual ~WindowSelectorSwipeToCloseDisabledTest() {}
|
| +
|
| + // WindowSelectorTest:
|
| + virtual void SetUp() override;
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(WindowSelectorSwipeToCloseDisabledTest);
|
| +};
|
| +
|
| +void WindowSelectorSwipeToCloseDisabledTest::SetUp() {
|
| + CommandLine::ForCurrentProcess()->AppendSwitch(
|
| + switches::kAshDisableSwipeToCloseInOverviewMode);
|
| + WindowSelectorTest::SetUp();
|
| +}
|
| +
|
| // Tests that an a11y alert is sent on entering overview mode.
|
| TEST_F(WindowSelectorTest, A11yAlertOnOverviewMode) {
|
| gfx::Rect bounds(0, 0, 400, 400);
|
| @@ -442,22 +481,15 @@ TEST_F(WindowSelectorTest, WindowDoesNotReceiveEvents) {
|
|
|
| // Tests that clicking on the close button effectively closes the window.
|
| TEST_F(WindowSelectorTest, CloseButton) {
|
| - scoped_ptr<aura::Window> window1(CreateWindow(gfx::Rect(200, 300, 250, 450)));
|
| -
|
| // We need a widget for the close button to work, a bare window will crash.
|
| - scoped_ptr<views::Widget> widget(new views::Widget);
|
| - views::Widget::InitParams params;
|
| - params.bounds = gfx::Rect(0, 0, 400, 400);
|
| - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
| - params.parent = window1->parent();
|
| - widget->Init(params);
|
| - widget->Show();
|
| + scoped_ptr<views::Widget> widget =
|
| + CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
|
| ToggleOverview();
|
|
|
| - aura::Window* window2 = widget->GetNativeWindow();
|
| - gfx::RectF bounds = GetTransformedBoundsInRootWindow(window2);
|
| + aura::Window* window = widget->GetNativeWindow();
|
| + gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
|
| gfx::Point point(bounds.top_right().x() - 1, bounds.top_right().y() - 1);
|
| - ui::test::EventGenerator event_generator(window2->GetRootWindow(), point);
|
| + ui::test::EventGenerator event_generator(window->GetRootWindow(), point);
|
|
|
| EXPECT_FALSE(widget->IsClosed());
|
| event_generator.ClickLeftButton();
|
| @@ -1430,4 +1462,228 @@ TEST_F(WindowSelectorTest, PanelSelectionOnSecondaryDisplay) {
|
| EXPECT_EQ(panel2.get(), GetFocusedWindow());
|
| }
|
|
|
| +// Verify swipe to close doesn't work when swipe to close is disabled.
|
| +TEST_F(WindowSelectorSwipeToCloseDisabledTest, WindowTapDragFarDistance) {
|
| + // We need a widget for the close button to work, a bare window will crash.
|
| + scoped_ptr<views::Widget> widget =
|
| + CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
|
| +
|
| + ToggleOverview();
|
| + ASSERT_TRUE(IsSelecting());
|
| +
|
| + aura::Window* window = widget->GetNativeWindow();
|
| + gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
|
| + ui::test::EventGenerator event_generator(window->GetRootWindow());
|
| +
|
| + ASSERT_FALSE(widget->IsClosed());
|
| +
|
| + gfx::Point start(bounds.CenterPoint());
|
| + gfx::Point end(start.x() - kFarDragDistance, start.y());
|
| + event_generator.GestureScrollSequence(
|
| + start, end, base::TimeDelta::FromMilliseconds(10), 5);
|
| +
|
| + EXPECT_FALSE(widget->IsClosed());
|
| +
|
| + RunAllPendingInMessageLoop();
|
| + EXPECT_TRUE(IsSelecting());
|
| +}
|
| +
|
| +// Test dragging a window a short distance.
|
| +TEST_F(WindowSelectorTest, WindowTapDragShortDistance) {
|
| + // We need a widget for the close button to work, a bare window will crash.
|
| + scoped_ptr<views::Widget> widget =
|
| + CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
|
| +
|
| + ToggleOverview();
|
| +
|
| + aura::Window* window = widget->GetNativeWindow();
|
| + gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
|
| + ui::test::EventGenerator event_generator(window->GetRootWindow());
|
| +
|
| + ASSERT_FALSE(widget->IsClosed());
|
| +
|
| + gfx::Point start(bounds.CenterPoint());
|
| + gfx::Point end(start.x() - kShortDragDistance, start.y());
|
| + event_generator.GestureScrollSequence(
|
| + start, end, base::TimeDelta::FromMilliseconds(10), 5);
|
| +
|
| + EXPECT_FALSE(widget->IsClosed());
|
| +
|
| + RunAllPendingInMessageLoop();
|
| + EXPECT_TRUE(IsSelecting());
|
| +}
|
| +
|
| +// Test dragging a window a far distance.
|
| +TEST_F(WindowSelectorTest, WindowTapDragFarDistance) {
|
| + // We need a widget for the close button to work, a bare window will crash.
|
| + scoped_ptr<views::Widget> widget =
|
| + CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
|
| +
|
| + ToggleOverview();
|
| + ASSERT_TRUE(IsSelecting());
|
| +
|
| + aura::Window* window = widget->GetNativeWindow();
|
| + gfx::Rect bounds = ToNearestRect(GetTransformedBoundsInRootWindow(window));
|
| + ui::test::EventGenerator event_generator(window->GetRootWindow());
|
| +
|
| + ASSERT_FALSE(widget->IsClosed());
|
| +
|
| + gfx::Point start(bounds.CenterPoint());
|
| + gfx::Point end(start.x() - kFarDragDistance, start.y());
|
| + event_generator.GestureScrollSequence(
|
| + start, end, base::TimeDelta::FromMilliseconds(10), 5);
|
| +
|
| + EXPECT_TRUE(widget->IsClosed());
|
| +
|
| + RunAllPendingInMessageLoop();
|
| + EXPECT_FALSE(IsSelecting());
|
| +}
|
| +
|
| +// Test dragging a window in a multi window SelectorItem a far distance.
|
| +TEST_F(WindowSelectorTest, MultiWindowTapDragFarDistance) {
|
| + scoped_ptr<views::Widget> widget1(
|
| + CreatePanelWindowWidget(gfx::Rect(0, 0, 300, 100)));
|
| + scoped_ptr<views::Widget> widget2(
|
| + CreatePanelWindowWidget(gfx::Rect(100, 0, 100, 100)));
|
| + aura::Window* window1 = widget1->GetNativeWindow();
|
| + wm::ActivateWindow(window1);
|
| + ToggleOverview();
|
| +
|
| + gfx::Rect bounds1 = ToNearestRect(GetTransformedBoundsInRootWindow(window1));
|
| + ui::test::EventGenerator event_generator1(window1->GetRootWindow());
|
| +
|
| + ASSERT_FALSE(widget1->IsClosed());
|
| + ASSERT_FALSE(widget2->IsClosed());
|
| +
|
| + gfx::Point start(bounds1.CenterPoint());
|
| + gfx::Point end(start.x() - kFarDragDistance, start.y());
|
| + event_generator1.GestureScrollSequence(
|
| + start, end, base::TimeDelta::FromMilliseconds(10), 5);
|
| +
|
| + EXPECT_TRUE(widget1->IsClosed());
|
| + EXPECT_FALSE(widget2->IsClosed());
|
| +
|
| + RunAllPendingInMessageLoop();
|
| + EXPECT_TRUE(IsSelecting());
|
| +}
|
| +
|
| +// Test dragging all windows in a multi window SelectorItem a short distance.
|
| +TEST_F(WindowSelectorTest, MultiWindowTapDragLabelShortDistance) {
|
| + scoped_ptr<views::Widget> widget1(
|
| + CreatePanelWindowWidget(gfx::Rect(0, 0, 300, 100)));
|
| + scoped_ptr<views::Widget> widget2(
|
| + CreatePanelWindowWidget(gfx::Rect(100, 0, 100, 100)));
|
| + aura::Window* window1 = widget1->GetNativeWindow();
|
| + wm::ActivateWindow(window1);
|
| + ToggleOverview();
|
| +
|
| + gfx::Rect bounds = GetWindowItemsForRoot(0).back()->target_bounds();
|
| + ui::test::EventGenerator event_generator1(window1->GetRootWindow());
|
| +
|
| + ASSERT_FALSE(widget1->IsClosed());
|
| + ASSERT_FALSE(widget2->IsClosed());
|
| +
|
| + gfx::Point start(bounds.CenterPoint().x(), bounds.y() + 3);
|
| + gfx::Point end(start.x() - kShortDragDistance, start.y());
|
| + event_generator1.GestureScrollSequence(
|
| + start, end, base::TimeDelta::FromMilliseconds(10), 5);
|
| +
|
| + EXPECT_FALSE(widget1->IsClosed());
|
| + EXPECT_FALSE(widget2->IsClosed());
|
| +
|
| + RunAllPendingInMessageLoop();
|
| +
|
| + RunAllPendingInMessageLoop();
|
| + EXPECT_TRUE(IsSelecting());
|
| +}
|
| +
|
| +// Test dragging all windows in a multi window SelectorItem a far distance.
|
| +TEST_F(WindowSelectorTest, MultiWindowTapDragLabelFarDistance) {
|
| + scoped_ptr<views::Widget> widget1(
|
| + CreatePanelWindowWidget(gfx::Rect(0, 0, 300, 100)));
|
| + scoped_ptr<views::Widget> widget2(
|
| + CreatePanelWindowWidget(gfx::Rect(100, 0, 100, 100)));
|
| + aura::Window* window1 = widget1->GetNativeWindow();
|
| + wm::ActivateWindow(window1);
|
| + ToggleOverview();
|
| +
|
| + gfx::Rect bounds = GetWindowItemsForRoot(0).back()->target_bounds();
|
| + ui::test::EventGenerator event_generator1(window1->GetRootWindow());
|
| +
|
| + ASSERT_FALSE(widget1->IsClosed());
|
| + ASSERT_FALSE(widget2->IsClosed());
|
| +
|
| + gfx::Point start(bounds.CenterPoint().x(), bounds.y() + 3);
|
| + gfx::Point end(start.x() - kFarDragDistance, start.y());
|
| + event_generator1.GestureScrollSequence(
|
| + start, end, base::TimeDelta::FromMilliseconds(10), 5);
|
| +
|
| + EXPECT_TRUE(widget1->IsClosed());
|
| + EXPECT_TRUE(widget2->IsClosed());
|
| +
|
| + RunAllPendingInMessageLoop();
|
| + EXPECT_FALSE(IsSelecting());
|
| +}
|
| +
|
| +// Test a low velocity fling.
|
| +TEST_F(WindowSelectorTest, LowVelocityFling) {
|
| + const float kFlingVelocity = 2000;
|
| + const int kSmallSwipeDistance = 25;
|
| +
|
| + // We need a widget for the close button to work, a bare window will crash.
|
| + scoped_ptr<views::Widget> widget =
|
| + CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
|
| +
|
| + ToggleOverview();
|
| +
|
| + aura::Window* window = widget->GetNativeWindow();
|
| + gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
|
| + ui::test::EventGenerator event_generator(window->GetRootWindow());
|
| +
|
| + ASSERT_FALSE(widget->IsClosed());
|
| +
|
| + gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y());
|
| + gfx::Point end(start.x() - kSmallSwipeDistance, start.y());
|
| + const base::TimeDelta kScrollDuration =
|
| + event_generator.CalculateScrollDurationForFlingVelocity(
|
| + start, end, kFlingVelocity, 10);
|
| + event_generator.GestureScrollSequence(start, end, kScrollDuration, 10);
|
| +
|
| + EXPECT_FALSE(widget->IsClosed());
|
| +
|
| + RunAllPendingInMessageLoop();
|
| + EXPECT_TRUE(IsSelecting());
|
| +}
|
| +
|
| +// Test a high velocity fling.
|
| +TEST_F(WindowSelectorTest, HighVelocityFling) {
|
| + const float kFlingVelocity = 10000;
|
| + const int kSmallSwipeDistance = 25;
|
| +
|
| + // We need a widget for the close button to work, a bare window will crash.
|
| + scoped_ptr<views::Widget> widget =
|
| + CreateWindowWidget(gfx::Rect(0, 0, 400, 400));
|
| +
|
| + ToggleOverview();
|
| + ASSERT_TRUE(IsSelecting());
|
| +
|
| + aura::Window* window = widget->GetNativeWindow();
|
| + gfx::RectF bounds = GetTransformedBoundsInRootWindow(window);
|
| + ui::test::EventGenerator event_generator(window->GetRootWindow());
|
| +
|
| + ASSERT_FALSE(widget->IsClosed());
|
| +
|
| + gfx::Point start(bounds.CenterPoint().x(), bounds.CenterPoint().y());
|
| + gfx::Point end(start.x() - kSmallSwipeDistance, start.y());
|
| + const base::TimeDelta kScrollDuration =
|
| + event_generator.CalculateScrollDurationForFlingVelocity(
|
| + start, end, kFlingVelocity, 10);
|
| + event_generator.GestureScrollSequence(start, end, kScrollDuration, 10);
|
| +
|
| + EXPECT_TRUE(widget->IsClosed());
|
| +
|
| + RunAllPendingInMessageLoop();
|
| + EXPECT_FALSE(IsSelecting());
|
| +}
|
| +
|
| } // namespace ash
|
|
|