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 fef9b75942451b118bd8b09072bbdac1984a75e7..3a4278abc52f825a4666b4430c282c60a157f542 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" |
@@ -68,6 +72,18 @@ void CancelDrag(DragDropController* controller, bool* canceled) { |
} |
} |
+// 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; |
+ |
+// A slow fling velocity that should not cause selctor items to close. |
+const int kSlowFlingVelocity = 2000; |
+ |
+// A fast fling velocity that should cause selector items to close. |
+const int kFastFlingVelocity = 5000; |
+ |
} // namespace |
class WindowSelectorTest : public test::AshTestBase { |
@@ -119,6 +135,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); |
@@ -256,6 +283,24 @@ class WindowSelectorTest : public test::AshTestBase { |
DISALLOW_COPY_AND_ASSIGN(WindowSelectorTest); |
}; |
+class WindowSelectorSwipeToCloseDisabledTest : public WindowSelectorTest { |
+ public: |
+ WindowSelectorSwipeToCloseDisabledTest() {} |
+ ~WindowSelectorSwipeToCloseDisabledTest() override {} |
+ |
+ // WindowSelectorTest: |
+ void SetUp() override; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(WindowSelectorSwipeToCloseDisabledTest); |
+}; |
+ |
+void WindowSelectorSwipeToCloseDisabledTest::SetUp() { |
+ base::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); |
@@ -1246,4 +1291,164 @@ TEST_F(WindowSelectorTest, CancelOverviewOnTap) { |
EXPECT_FALSE(IsSelecting()); |
} |
+// 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. |
flackr
2015/02/10 17:49:50
Probably worth mentioning why. Is a bare window mi
bruthig
2015/02/12 18:08:55
I've moved the comment to the CreateWindowWidget m
|
+ 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); |
flackr
2015/02/10 17:49:50
Should probably also verify the window moves with
bruthig
2015/02/12 18:08:55
Done.
|
+ |
+ 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 a slow velocity fling. |
+TEST_F(WindowSelectorTest, SlowVelocityFling) { |
+ // 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() - kShortDragDistance, start.y()); |
+ const base::TimeDelta kScrollDuration = |
+ event_generator.CalculateScrollDurationForFlingVelocity( |
+ start, end, kSlowFlingVelocity, 10); |
+ event_generator.GestureScrollSequence(start, end, kScrollDuration, 10); |
+ |
+ EXPECT_FALSE(widget->IsClosed()); |
+ |
+ RunAllPendingInMessageLoop(); |
+ EXPECT_TRUE(IsSelecting()); |
+} |
+ |
+// Test a fast velocity fling. |
+TEST_F(WindowSelectorTest, FastVelocityFling) { |
+ // 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() - kShortDragDistance, start.y()); |
+ const base::TimeDelta kScrollDuration = |
+ event_generator.CalculateScrollDurationForFlingVelocity( |
+ start, end, kFastFlingVelocity, 10); |
+ event_generator.GestureScrollSequence(start, end, kScrollDuration, 10); |
+ |
+ EXPECT_TRUE(widget->IsClosed()); |
+ |
+ RunAllPendingInMessageLoop(); |
+ EXPECT_FALSE(IsSelecting()); |
+} |
+ |
+// Test a fast velocity fling. |
+TEST_F(WindowSelectorTest, SlowVelocityFlingAtAFarDistance) { |
+ // 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() - kFarDragDistance, start.y()); |
+ const base::TimeDelta kScrollDuration = |
+ event_generator.CalculateScrollDurationForFlingVelocity( |
+ start, end, kSlowFlingVelocity, 10); |
+ event_generator.GestureScrollSequence(start, end, kScrollDuration, 10); |
+ |
+ EXPECT_TRUE(widget->IsClosed()); |
+ |
+ RunAllPendingInMessageLoop(); |
+ EXPECT_FALSE(IsSelecting()); |
+} |
+ |
} // namespace ash |