Commit d08592b0 authored by sadrul@chromium.org's avatar sadrul@chromium.org

ash: Add some test coverage for WM swipe-gestures.

BUG=130409

Review URL: https://chromiumcodereview.appspot.com/10823218

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150496 0039d316-1c4b-4281-b951-d872f2087c98
parent 628f17e2
......@@ -17,8 +17,10 @@
#include "base/time.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_windows.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget_delegate.h"
namespace ash {
namespace test {
......@@ -94,6 +96,17 @@ class DummyBrightnessControlDelegate : public BrightnessControlDelegate,
DISALLOW_COPY_AND_ASSIGN(DummyBrightnessControlDelegate);
};
class ResizableWidgetDelegate : public views::WidgetDelegateView {
public:
ResizableWidgetDelegate() {}
virtual ~ResizableWidgetDelegate() {}
private:
virtual bool CanResize() const OVERRIDE { return true; }
DISALLOW_COPY_AND_ASSIGN(ResizableWidgetDelegate);
};
} // namespace
class SystemGestureEventFilterTest : public AshTestBase {
......@@ -430,5 +443,60 @@ TEST_F(SystemGestureEventFilterTest, LongPressAffordanceStateOnCaptureLoss) {
EXPECT_EQ(NULL, GetLongPressAffordanceView());
}
TEST_F(SystemGestureEventFilterTest, MultiFingerSwipeGestures) {
aura::RootWindow* root_window = Shell::GetPrimaryRootWindow();
views::Widget* toplevel = views::Widget::CreateWindowWithBounds(
new ResizableWidgetDelegate, gfx::Rect(0, 0, 100, 100));
toplevel->Show();
const int kSteps = 15;
const int kTouchPoints = 4;
gfx::Point points[kTouchPoints] = {
gfx::Point(10, 30),
gfx::Point(30, 20),
gfx::Point(50, 30),
gfx::Point(80, 50)
};
aura::test::EventGenerator generator(root_window,
toplevel->GetNativeWindow());
// Swipe down to minimize.
generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, 0, 150);
EXPECT_TRUE(wm::IsWindowMinimized(toplevel->GetNativeWindow()));
toplevel->Restore();
// Swipe up to maximize.
generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, 0, -150);
EXPECT_TRUE(wm::IsWindowMaximized(toplevel->GetNativeWindow()));
toplevel->Restore();
// Swipe right to snap.
gfx::Rect normal_bounds = toplevel->GetWindowBoundsInScreen();
generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, 150, 0);
gfx::Rect right_tile_bounds = toplevel->GetWindowBoundsInScreen();
EXPECT_NE(normal_bounds.ToString(), right_tile_bounds.ToString());
// Swipe left to snap.
gfx::Point left_points[kTouchPoints];
for (int i = 0; i < kTouchPoints; ++i) {
left_points[i] = points[i];
left_points[i].Offset(right_tile_bounds.x(), right_tile_bounds.y());
}
generator.GestureMultiFingerScroll(kTouchPoints, left_points, 15, kSteps,
-150, 0);
gfx::Rect left_tile_bounds = toplevel->GetWindowBoundsInScreen();
EXPECT_NE(normal_bounds.ToString(), left_tile_bounds.ToString());
EXPECT_NE(right_tile_bounds.ToString(), left_tile_bounds.ToString());
// Swipe right again.
generator.GestureMultiFingerScroll(kTouchPoints, points, 15, kSteps, 150, 0);
gfx::Rect current_bounds = toplevel->GetWindowBoundsInScreen();
EXPECT_NE(current_bounds.ToString(), left_tile_bounds.ToString());
EXPECT_EQ(current_bounds.ToString(), right_tile_bounds.ToString());
}
} // namespace test
} // namespace ash
......@@ -205,6 +205,45 @@ void EventGenerator::GestureScrollSequence(const gfx::Point& start,
Dispatch(release);
}
void EventGenerator::GestureMultiFingerScroll(int count,
const gfx::Point* start,
int event_separation_time_ms,
int steps,
int move_x,
int move_y) {
const int kMaxTouchPoints = 10;
gfx::Point points[kMaxTouchPoints];
CHECK_LE(count, kMaxTouchPoints);
CHECK_GT(steps, 0);
int delta_x = move_x / steps;
int delta_y = move_y / steps;
base::TimeDelta press_time = base::Time::NowFromSystemTime() - base::Time();
for (int i = 0; i < count; ++i) {
points[i] = start[i];
TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time);
Dispatch(press);
}
for (int step = 0; step < steps; ++step) {
base::TimeDelta move_time = press_time +
base::TimeDelta::FromMilliseconds(event_separation_time_ms * step);
for (int i = 0; i < count; ++i) {
points[i].Offset(delta_x, delta_y);
TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time);
Dispatch(move);
}
}
base::TimeDelta release_time = press_time +
base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps);
for (int i = 0; i < count; ++i) {
TouchEvent release(ui::ET_TOUCH_RELEASED, points[i], i, release_time);
Dispatch(release);
}
}
void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) {
DispatchKeyEvent(true, key_code, flags);
}
......
......@@ -138,6 +138,20 @@ class EventGenerator {
const base::TimeDelta& duration,
int steps);
// Generates press, move, release touch-events to generate a sequence of
// multi-finger scroll events. |count| specifies the number of touch-points
// that should generate the scroll events. |start| are the starting positions
// of all the touch points. |steps| and |event_separation_time_ms| are
// relevant when testing velocity/fling/swipe, otherwise these can be any
// non-zero value. |delta_x| and |delta_y| are the amount that each finger
// should be moved.
void GestureMultiFingerScroll(int count,
const gfx::Point* start,
int event_separation_time_ms,
int steps,
int move_x,
int move_y);
// Generates a key press event. On platforms except Windows and X11, a key
// event without native_event() is generated. Note that ui::EF_ flags should
// be passed as |flags|, not the native ones like 'ShiftMask' in <X11/X.h>.
......
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