#include "ui/events/event.h"
#include "ui/events/event_switches.h"
#include "ui/events/event_utils.h"
-#include "ui/events/gestures/gesture_configuration.h"
+#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/gestures/gesture_recognizer_impl.h"
-#include "ui/events/gestures/gesture_sequence.h"
#include "ui/events/gestures/gesture_types.h"
#include "ui/events/test/event_generator.h"
#include "ui/events/test/events_test_utils.h"
flags_(0),
wait_until_event_(ui::ET_UNKNOWN) {}
- virtual ~GestureEventConsumeDelegate() {}
+ ~GestureEventConsumeDelegate() override {}
void Reset() {
events_.clear();
run_loop_->Run();
}
- virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
+ void OnGestureEvent(ui::GestureEvent* gesture) override {
events_.push_back(gesture->type());
bounding_box_ = gesture->details().bounding_box();
flags_ = gesture->flags();
dispatcher_(dispatcher),
queue_events_(true) {
}
- virtual ~QueueTouchEventDelegate() {
+ ~QueueTouchEventDelegate() override {
while(!queue_.empty()) {
delete queue_.front();
queue_.pop();
}
}
- virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
+ void OnTouchEvent(ui::TouchEvent* event) override {
if (queue_events_) {
queue_.push(new ui::TouchEvent(*event, window_, window_));
event->StopPropagation();
bool mouse_release() const { return mouse_release_; }
bool double_click() const { return double_click_; }
- virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
+ void OnMouseEvent(ui::MouseEvent* event) override {
switch (event->type()) {
case ui::ET_MOUSE_PRESSED:
double_click_ = event->flags() & ui::EF_IS_DOUBLE_CLICK;
DISALLOW_COPY_AND_ASSIGN(GestureEventSynthDelegate);
};
-class TestOneShotGestureSequenceTimer
- : public base::OneShotTimer<ui::GestureSequence> {
- public:
- TestOneShotGestureSequenceTimer() {}
-
- void ForceTimeout() {
- if (IsRunning()) {
- user_task().Run();
- Stop();
- }
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TestOneShotGestureSequenceTimer);
-};
-
-class TimerTestGestureSequence : public ui::GestureSequence {
- public:
- explicit TimerTestGestureSequence(ui::GestureSequenceDelegate* delegate)
- : ui::GestureSequence(delegate) {
- }
-
- void ForceTimeout() {
- static_cast<TestOneShotGestureSequenceTimer*>(
- GetLongPressTimer())->ForceTimeout();
- }
-
- bool IsTimerRunning() {
- return GetLongPressTimer()->IsRunning();
- }
-
- virtual base::OneShotTimer<ui::GestureSequence>* CreateTimer() OVERRIDE {
- return new TestOneShotGestureSequenceTimer();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TimerTestGestureSequence);
-};
-
-class TestGestureRecognizer : public ui::GestureRecognizerImpl {
- public:
- TestGestureRecognizer() : GestureRecognizerImpl() {
- }
-
- ui::GestureSequence* GetGestureSequenceForTesting(Window* window) {
- return GetGestureSequenceForConsumer(window);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TestGestureRecognizer);
-};
-
-class TimerTestGestureRecognizer : public TestGestureRecognizer {
- public:
- TimerTestGestureRecognizer() : TestGestureRecognizer() {
- }
-
- virtual ui::GestureSequence* CreateSequence(
- ui::GestureSequenceDelegate* delegate) OVERRIDE {
- return new TimerTestGestureSequence(delegate);
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TimerTestGestureRecognizer);
-};
-
-base::TimeDelta GetTime() {
- return ui::EventTimeForNow();
-}
-
class ScopedGestureRecognizerSetter {
public:
// Takes ownership of |new_gr|.
int time_step,
int num_steps,
GestureEventConsumeDelegate* delegate) {
- int x = x_start;
- int y = y_start;
+ float x = x_start;
+ float y = y_start;
for (int i = 0; i < num_steps; i++) {
x += dx;
// An event handler to keep track of events.
class TestEventHandler : public ui::EventHandler {
public:
- TestEventHandler() : touch_released_count_(0),
- touch_pressed_count_(0),
- touch_moved_count_(0),
- touch_cancelled_count_(0) {
- }
+ TestEventHandler()
+ : touch_released_count_(0),
+ touch_pressed_count_(0),
+ touch_moved_count_(0) {}
- virtual ~TestEventHandler() {}
+ ~TestEventHandler() override {}
- virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
+ void OnTouchEvent(ui::TouchEvent* event) override {
switch (event->type()) {
case ui::ET_TOUCH_RELEASED:
touch_released_count_++;
touch_moved_count_++;
break;
case ui::ET_TOUCH_CANCELLED:
- touch_cancelled_count_++;
+ cancelled_touch_points_.push_back(event->location());
break;
default:
break;
touch_released_count_ = 0;
touch_pressed_count_ = 0;
touch_moved_count_ = 0;
- touch_cancelled_count_ = 0;
+ cancelled_touch_points_.clear();
}
int touch_released_count() const { return touch_released_count_; }
int touch_pressed_count() const { return touch_pressed_count_; }
int touch_moved_count() const { return touch_moved_count_; }
- int touch_cancelled_count() const { return touch_cancelled_count_; }
+ int touch_cancelled_count() const {
+ return static_cast<int>(cancelled_touch_points_.size());
+ }
+ const std::vector<gfx::PointF>& cancelled_touch_points() const {
+ return cancelled_touch_points_;
+ }
private:
int touch_released_count_;
int touch_pressed_count_;
int touch_moved_count_;
- int touch_cancelled_count_;
+ std::vector<gfx::PointF> cancelled_touch_points_;
DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
};
class RemoveOnTouchCancelHandler : public TestEventHandler {
public:
RemoveOnTouchCancelHandler() {}
- virtual ~RemoveOnTouchCancelHandler() {}
+ ~RemoveOnTouchCancelHandler() override {}
private:
// ui::EventHandler:
- virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
+ void OnTouchEvent(ui::TouchEvent* event) override {
TestEventHandler::OnTouchEvent(event);
if (event->type() == ui::ET_TOUCH_CANCELLED) {
Window* target = static_cast<Window*>(event->target());
DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler);
};
+void DelayByLongPressTimeout() {
+ ui::GestureProvider::Config config;
+ base::RunLoop run_loop;
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ run_loop.QuitClosure(),
+ config.gesture_detector_config.longpress_timeout * 2);
+ run_loop.Run();
+}
+
+void DelayByShowPressTimeout() {
+ ui::GestureProvider::Config config;
+ base::RunLoop run_loop;
+ base::MessageLoop::current()->PostDelayedTask(
+ FROM_HERE,
+ run_loop.QuitClosure(),
+ config.gesture_detector_config.showpress_timeout * 2);
+ run_loop.Run();
+}
+
} // namespace
class GestureRecognizerTest : public AuraTestBase,
public:
GestureRecognizerTest() {}
- bool UsingUnifiedGR() {
- return GetParam();
+ void SetUp() override {
+ AuraTestBase::SetUp();
+ ui::GestureConfiguration::GetInstance()->set_show_press_delay_in_ms(2);
+ ui::GestureConfiguration::GetInstance()->set_long_press_time_in_ms(3);
}
- virtual void SetUp() OVERRIDE {
- // TODO(tdresser): Once unified GR has landed, only run these tests once.
- CommandLine::ForCurrentProcess()->AppendSwitchASCII(
- switches::kUnifiedGestureDetector,
- UsingUnifiedGR() ? switches::kUnifiedGestureDetectorEnabled
- : switches::kUnifiedGestureDetectorDisabled);
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest);
+};
+
+class GestureRecognizerWithSwitchTest : public GestureRecognizerTest {
+ public:
+ GestureRecognizerWithSwitchTest() {}
- AuraTestBase::SetUp();
- ui::GestureConfiguration::set_min_touch_down_duration_in_seconds_for_click(
- 0.001);
- ui::GestureConfiguration::set_show_press_delay_in_ms(2);
- ui::GestureConfiguration::set_long_press_time_in_seconds(0.003);
+ void SetUp() override {
+ GestureRecognizerTest::SetUp();
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kCompensateForUnstablePinchZoom);
+ ui::GestureConfiguration::GetInstance()->set_min_pinch_update_span_delta(5);
}
- DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest);
+ private:
+ DISALLOW_COPY_AND_ASSIGN(GestureRecognizerWithSwitchTest);
};
// Check that appropriate touch events generate tap gesture events.
-TEST_P(GestureRecognizerTest, GestureEventTap) {
+TEST_F(GestureRecognizerTest, GestureEventTap) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
// Check that appropriate touch events generate tap gesture events
// when information about the touch radii are provided.
-TEST_P(GestureRecognizerTest, GestureEventTapRegion) {
- // TODO(tdresser): enable this test with unified GR once we resolve the
- // bounding box differences. See crbug.com/366641.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, GestureEventTapRegion) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
EXPECT_EQ(1, delegate->tap_count());
gfx::Point actual_point(delegate->tap_location());
- EXPECT_EQ(25, delegate->bounding_box().width());
- EXPECT_EQ(24, delegate->bounding_box().height());
- EXPECT_EQ(48, actual_point.x());
+ EXPECT_EQ(16, delegate->bounding_box().width());
+ EXPECT_EQ(16, delegate->bounding_box().height());
+ EXPECT_EQ(49, actual_point.x());
EXPECT_EQ(204, actual_point.y());
}
EXPECT_EQ(1, delegate->tap_count());
gfx::Point actual_point(delegate->tap_location());
- EXPECT_EQ(33, delegate->bounding_box().width());
- EXPECT_EQ(32, delegate->bounding_box().height());
- EXPECT_EQ(397, actual_point.x());
+ EXPECT_EQ(18, delegate->bounding_box().width());
+ EXPECT_EQ(18, delegate->bounding_box().height());
+ EXPECT_EQ(401, actual_point.x());
EXPECT_EQ(149, actual_point.y());
}
}
// Check that appropriate touch events generate scroll gesture events.
-TEST_P(GestureRecognizerTest, GestureEventScroll) {
+TEST_F(GestureRecognizerTest, GestureEventScroll) {
// We'll start by moving the touch point by (10.5, 10.5). We want 5 dips of
// that distance to be consumed by the slop, so we set the slop radius to
// sqrt(5 * 5 + 5 * 5).
- ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
- sqrt(static_cast<double>(5 * 5 + 5 * 5)));
+ ui::GestureConfiguration::GetInstance()
+ ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5));
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
}
// Check that predicted scroll update positions are correct.
-TEST_P(GestureRecognizerTest, GestureEventScrollPrediction) {
- const double prediction_interval = 0.03;
- ui::GestureConfiguration::set_scroll_prediction_seconds(prediction_interval);
- // We'll start by moving the touch point by (5, 5). We want all of that
+TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) {
+ // We'll start by moving the touch point by (5, 5). We want all of that
// distance to be consumed by the slop, so we set the slop radius to
// sqrt(5 * 5 + 5 * 5).
- ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
- sqrt(static_cast<double>(5 * 5 + 5 * 5)));
+ ui::GestureConfiguration::GetInstance()
+ ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5));
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
}
// Check that the bounding box during a scroll event is correct.
-TEST_P(GestureRecognizerTest, GestureEventScrollBoundingBox) {
+TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) {
TimedEvents tes;
- for (int radius = 1; radius <= 10; ++radius) {
- ui::GestureConfiguration::set_default_radius(radius);
+ for (float radius = 1; radius <= 10; ++radius) {
+ ui::GestureConfiguration::GetInstance()->set_default_radius(radius);
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, bounds, root_window()));
- const int kPositionX = 101;
- const int kPositionY = 201;
+ const float kPositionX = 101;
+ const float kPositionY = 201;
delegate->Reset();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
- gfx::Point(kPositionX, kPositionY),
+ gfx::PointF(kPositionX, kPositionY),
kTouchId,
tes.Now());
DispatchEventUsingWindowDispatcher(&press);
- EXPECT_EQ(gfx::Rect(kPositionX - radius,
- kPositionY - radius,
- radius * 2,
- radius * 2).ToString(),
- delegate->bounding_box().ToString());
+ EXPECT_EQ(gfx::RectF(kPositionX - radius,
+ kPositionY - radius,
+ radius * 2,
+ radius * 2),
+ delegate->bounding_box());
const int kScrollAmount = 50;
tes.SendScrollEvents(event_processor(), kPositionX, kPositionY,
- 1, 1, kTouchId, 1, kScrollAmount, delegate.get());
+ 1, 1, kTouchId, 1, kScrollAmount, delegate.get());
EXPECT_EQ(gfx::Point(1, 1).ToString(),
delegate->scroll_begin_position().ToString());
- EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius,
- kPositionY + kScrollAmount - radius,
- radius * 2,
- radius * 2).ToString(),
- delegate->bounding_box().ToString());
+ EXPECT_EQ(gfx::RectF(kPositionX + kScrollAmount - radius,
+ kPositionY + kScrollAmount - radius,
+ radius * 2,
+ radius * 2),
+ delegate->bounding_box());
// Release the touch. This should end the scroll.
delegate->Reset();
ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
- gfx::Point(kPositionX + kScrollAmount,
- kPositionY + kScrollAmount),
+ gfx::PointF(kPositionX + kScrollAmount,
+ kPositionY + kScrollAmount),
kTouchId, press.time_stamp() +
base::TimeDelta::FromMilliseconds(50));
DispatchEventUsingWindowDispatcher(&release);
- EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius,
- kPositionY + kScrollAmount - radius,
- radius * 2,
- radius * 2).ToString(),
- delegate->bounding_box().ToString());
+ EXPECT_EQ(gfx::RectF(kPositionX + kScrollAmount - radius,
+ kPositionY + kScrollAmount - radius,
+ radius * 2,
+ radius * 2),
+ delegate->bounding_box());
}
- ui::GestureConfiguration::set_default_radius(0);
+ ui::GestureConfiguration::GetInstance()->set_default_radius(0);
}
// Check Scroll End Events report correct velocities
// if the user was on a horizontal rail
-TEST_P(GestureRecognizerTest, GestureEventHorizontalRailFling) {
+TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
EXPECT_FLOAT_EQ(20, delegate->scroll_x());
// Get a high x velocity, while still staying on the rail
- tes.SendScrollEvents(event_processor(), 1, 1,
- 100, 10, kTouchId, 1,
- ui::GestureConfiguration::points_buffered_for_velocity(),
- delegate.get());
+ const int kScrollAmount = 8;
+ tes.SendScrollEvents(event_processor(),
+ 1,
+ 1,
+ 100,
+ 10,
+ kTouchId,
+ 1,
+ kScrollAmount,
+ delegate.get());
delegate->Reset();
ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
// Check Scroll End Events report correct velocities
// if the user was on a vertical rail
-TEST_P(GestureRecognizerTest, GestureEventVerticalRailFling) {
+TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
EXPECT_EQ(0, delegate->scroll_velocity_x());
// Get a high y velocity, while still staying on the rail
- tes.SendScrollEvents(event_processor(), 1, 6,
- 10, 100, kTouchId, 1,
- ui::GestureConfiguration::points_buffered_for_velocity(),
+ const int kScrollAmount = 8;
+ tes.SendScrollEvents(event_processor(),
+ 1,
+ 6,
+ 10,
+ 100,
+ kTouchId,
+ 1,
+ kScrollAmount,
delegate.get());
EXPECT_EQ(0, delegate->scroll_velocity_x());
// Check Scroll End Events report non-zero velocities if the user is not on a
// rail
-TEST_P(GestureRecognizerTest, GestureEventNonRailFling) {
- ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(0);
+TEST_F(GestureRecognizerTest, GestureEventNonRailFling) {
+ ui::GestureConfiguration::GetInstance()
+ ->set_max_touch_move_in_pixels_for_click(0);
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
EXPECT_EQ(50, delegate->scroll_y());
EXPECT_EQ(50, delegate->scroll_x());
- tes.SendScrollEvents(event_processor(), 1, 1,
- 10, 100, kTouchId, 1,
- ui::GestureConfiguration::points_buffered_for_velocity(),
+ const int kScrollAmount = 8;
+ tes.SendScrollEvents(event_processor(),
+ 1,
+ 1,
+ 10,
+ 100,
+ kTouchId,
+ 1,
+ kScrollAmount,
delegate.get());
delegate->Reset();
}
// Check that appropriate touch events generate long press events
-TEST_P(GestureRecognizerTest, GestureEventLongPress) {
- ui::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click(
- 0.0025);
-
+TEST_F(GestureRecognizerTest, GestureEventLongPress) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
delegate->Reset();
- TimerTestGestureRecognizer* gesture_recognizer =
- new TimerTestGestureRecognizer();
-
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED,
gfx::Point(101, 201),
kTouchId,
EXPECT_FALSE(delegate->tap());
}
-// Check that scrolling cancels a long press
-TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
+// Check that scrolling prevents a long press.
+TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
delegate->Reset();
- TimerTestGestureRecognizer* gesture_recognizer =
- new TimerTestGestureRecognizer();
- TimerTestGestureSequence* gesture_sequence =
- static_cast<TimerTestGestureSequence*>(
- gesture_recognizer->GetGestureSequenceForTesting(window.get()));
-
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
kTouchId, tes.Now());
DispatchEventUsingWindowDispatcher(&press1);
// Scroll around, to cancel the long press
tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
- // Wait until the timer runs out
- gesture_sequence->ForceTimeout();
+
+ // Wait until a long press event would have fired, if it hadn't been
+ // cancelled.
+ DelayByLongPressTimeout();
+
EXPECT_FALSE(delegate->long_press());
EXPECT_TRUE(delegate->tap_cancel());
}
// Check that appropriate touch events generate long tap events
-TEST_P(GestureRecognizerTest, GestureEventLongTap) {
- ui::GestureConfiguration::set_max_touch_down_duration_in_seconds_for_click(
- 0.0025);
+TEST_F(GestureRecognizerTest, GestureEventLongTap) {
+ ui::GestureConfiguration::GetInstance()
+ ->set_max_touch_down_duration_for_click_in_ms(3);
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
delegate->Reset();
- TimerTestGestureRecognizer* gesture_recognizer =
- new TimerTestGestureRecognizer();
-
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED,
gfx::Point(101, 201),
kTouchId,
}
// Check that second tap cancels a long press
-TEST_P(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
+TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, bounds, root_window()));
- TimerTestGestureRecognizer* gesture_recognizer =
- new TimerTestGestureRecognizer();
- TimerTestGestureSequence* gesture_sequence =
- static_cast<TimerTestGestureSequence*>(
- gesture_recognizer->GetGestureSequenceForTesting(window.get()));
-
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
delegate->Reset();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
kTouchId1, tes.Now());
EXPECT_TRUE(delegate->begin());
// Wait until the timer runs out
- gesture_sequence->ForceTimeout();
+ DelayByLongPressTimeout();
// No long press occurred
EXPECT_FALSE(delegate->long_press());
// Check that horizontal scroll gestures cause scrolls on horizontal rails.
// Also tests that horizontal rails can be broken.
-TEST_P(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
+TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
// Send enough information that a velocity can be calculated for the gesture,
// and we can break the rail
- tes.SendScrollEvents(event_processor(), 1, 1,
- 6, 100, kTouchId, 1,
- ui::GestureConfiguration::points_buffered_for_velocity(),
+ const int kScrollAmount = 8;
+ tes.SendScrollEvents(event_processor(),
+ 1,
+ 1,
+ 6,
+ 100,
+ kTouchId,
+ 1,
+ kScrollAmount,
delegate.get());
tes.SendScrollEvent(event_processor(), 5, 0, kTouchId, delegate.get());
// Check that vertical scroll gestures cause scrolls on vertical rails.
// Also tests that vertical rails can be broken.
-TEST_P(GestureRecognizerTest, GestureEventVerticalRailScroll) {
+TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
// Send enough information that a velocity can be calculated for the gesture,
// and we can break the rail
- tes.SendScrollEvents(event_processor(), 1, 6,
- 100, 1, kTouchId, 1,
- ui::GestureConfiguration::points_buffered_for_velocity(),
+ const int kScrollAmount = 8;
+ tes.SendScrollEvents(event_processor(),
+ 1,
+ 6,
+ 100,
+ 1,
+ kTouchId,
+ 1,
+ kScrollAmount,
delegate.get());
tes.SendScrollEvent(event_processor(), 0, 5, kTouchId, delegate.get());
EXPECT_EQ(5, delegate->scroll_y());
}
-TEST_P(GestureRecognizerTest, GestureTapFollowedByScroll) {
+TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) {
// We'll start by moving the touch point by (5, 5). We want all of that
// distance to be consumed by the slop, so we set the slop radius to
// sqrt(5 * 5 + 5 * 5).
- ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(
- sqrt(static_cast<double>(5 * 5 + 5 * 5)));
+ ui::GestureConfiguration::GetInstance()
+ ->set_max_touch_move_in_pixels_for_click(sqrt(5.f * 5 + 5 * 5));
// First, tap. Then, do a scroll using the same touch-id.
scoped_ptr<GestureEventConsumeDelegate> delegate(
EXPECT_TRUE(delegate->fling());
}
-TEST_P(GestureRecognizerTest, AsynchronousGestureRecognition) {
+TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
scoped_ptr<QueueTouchEventDelegate> queued_delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
+ TimedEvents tes;
const int kWindowWidth = 123;
const int kWindowHeight = 45;
const int kTouchId1 = 6;
// Touch down on the window. This should not generate any gesture event.
queued_delegate->Reset();
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
- kTouchId1, GetTime());
+ ui::TouchEvent press(
+ ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now());
DispatchEventUsingWindowDispatcher(&press);
EXPECT_FALSE(queued_delegate->tap());
EXPECT_FALSE(queued_delegate->tap_down());
// Introduce some delay before the touch is released so that it is recognized
// as a tap. However, this still should not create any gesture events.
queued_delegate->Reset();
- ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
- kTouchId1, press.time_stamp() +
- base::TimeDelta::FromMilliseconds(50));
+ ui::TouchEvent release(
+ ui::ET_TOUCH_RELEASED,
+ gfx::Point(101, 201),
+ kTouchId1,
+ press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
DispatchEventUsingWindowDispatcher(&release);
EXPECT_FALSE(queued_delegate->tap());
EXPECT_FALSE(queued_delegate->tap_down());
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), root_window()));
delegate->Reset();
- ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20),
- kTouchId2, GetTime());
+ ui::TouchEvent press2(
+ ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&press2);
EXPECT_FALSE(delegate->tap());
EXPECT_TRUE(delegate->tap_down());
EXPECT_FALSE(delegate->scroll_update());
EXPECT_FALSE(delegate->scroll_end());
- ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20),
- kTouchId2, GetTime());
+ ui::TouchEvent release2(
+ ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&release2);
// Process the first queued event.
// Start all over. Press on the first window, then press again on the second
// window. The second press should still go to the first window.
queued_delegate->Reset();
- ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
- kTouchId1, GetTime());
+ ui::TouchEvent press3(
+ ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now());
DispatchEventUsingWindowDispatcher(&press3);
EXPECT_FALSE(queued_delegate->tap());
EXPECT_FALSE(queued_delegate->tap_down());
queued_delegate->Reset();
delegate->Reset();
- ui::TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(103, 203),
- kTouchId2, GetTime());
+ ui::TouchEvent press4(
+ ui::ET_TOUCH_PRESSED, gfx::Point(103, 203), kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&press4);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
// should generate both SCROLL_BEGIN and PINCH_BEGIN gestures.
queued_delegate->Reset();
delegate->Reset();
- int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
- ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(203 + x_move, 303),
- kTouchId2, GetTime());
+ ui::TouchEvent move(
+ ui::ET_TOUCH_MOVED,
+ gfx::PointF(203 +
+ ui::GestureConfiguration::GetInstance()
+ ->max_touch_move_in_pixels_for_click(),
+ 303),
+ kTouchId2,
+ tes.Now());
DispatchEventUsingWindowDispatcher(&move);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->tap_down());
EXPECT_FALSE(queued_delegate->begin());
EXPECT_FALSE(queued_delegate->end());
EXPECT_TRUE(queued_delegate->scroll_begin());
- // TODO(tdresser): uncomment once we've switched to the unified GR.
- // EXPECT_TRUE(queued_delegate->scroll_update());
+
+ EXPECT_TRUE(queued_delegate->scroll_update());
EXPECT_FALSE(queued_delegate->scroll_end());
EXPECT_TRUE(queued_delegate->pinch_begin());
EXPECT_FALSE(queued_delegate->pinch_update());
}
// Check that appropriate touch events generate pinch gesture events.
-TEST_P(GestureRecognizerTest, GestureEventPinchFromScroll) {
- // Disabled for unified GR due to differences in when pinch begin is sent. The
- // Aura GR sends it earlier than is necessary.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&press2);
- EXPECT_2_EVENTS(delegate->events(),
- ui::ET_GESTURE_BEGIN,
- ui::ET_GESTURE_PINCH_BEGIN);
+ EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_BEGIN);
EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(),
delegate->bounding_box().ToString());
kTouchId1, tes.Now());
DispatchEventUsingWindowDispatcher(&move3);
EXPECT_2_EVENTS(delegate->events(),
- ui::ET_GESTURE_PINCH_UPDATE,
- ui::ET_GESTURE_SCROLL_UPDATE);
+ ui::ET_GESTURE_SCROLL_UPDATE,
+ ui::ET_GESTURE_PINCH_BEGIN);
EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(),
delegate->bounding_box().ToString());
kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&move4);
EXPECT_2_EVENTS(delegate->events(),
- ui::ET_GESTURE_PINCH_UPDATE,
- ui::ET_GESTURE_SCROLL_UPDATE);
+ ui::ET_GESTURE_SCROLL_UPDATE,
+ ui::ET_GESTURE_PINCH_UPDATE);
EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(),
delegate->bounding_box().ToString());
EXPECT_TRUE(delegate->bounding_box().IsEmpty());
}
-TEST_P(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) {
+TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
EXPECT_TRUE(delegate->pinch_update());
}
-TEST_P(GestureRecognizerTest, GestureEventPinchFromTap) {
- // Disabled under unified gesture recognizer due to behavior differences in
- // scroll and bounding box behavior.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201),
kTouchId1, tes.Now());
DispatchEventUsingWindowDispatcher(&move3);
- EXPECT_2_EVENTS(delegate->events(),
+ EXPECT_3_EVENTS(delegate->events(),
ui::ET_GESTURE_SCROLL_BEGIN,
+ ui::ET_GESTURE_SCROLL_UPDATE,
ui::ET_GESTURE_PINCH_BEGIN);
EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(),
delegate->bounding_box().ToString());
kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&move4);
EXPECT_2_EVENTS(delegate->events(),
- ui::ET_GESTURE_PINCH_UPDATE,
- ui::ET_GESTURE_SCROLL_UPDATE);
+ ui::ET_GESTURE_SCROLL_UPDATE,
+ ui::ET_GESTURE_PINCH_UPDATE);
EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(),
delegate->bounding_box().ToString());
EXPECT_TRUE(delegate->bounding_box().IsEmpty());
}
-TEST_P(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
+TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
// Check that a touch is locked to the window of the closest current touch
// within max_separation_for_gesture_touches_in_pixels
-TEST_P(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) {
+TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) {
ui::GestureRecognizer* gesture_recognizer = new ui::GestureRecognizerImpl();
TimedEvents tes;
ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
scoped_ptr<GestureEventConsumeDelegate*[]> delegates(
new GestureEventConsumeDelegate*[kNumWindows]);
- ui::GestureConfiguration::
- set_max_separation_for_gesture_touches_in_pixels(499);
+ ui::GestureConfiguration::GetInstance()
+ ->set_max_separation_for_gesture_touches_in_pixels(499);
scoped_ptr<gfx::Rect[]> window_bounds(new gfx::Rect[kNumWindows]);
window_bounds[0] = gfx::Rect(0, 0, 1, 1);
// Check that a touch's target will not be effected by a touch on a different
// screen.
-TEST_P(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) {
+TEST_F(GestureRecognizerTest, GestureEventTouchLockIgnoresOtherScreens) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
gfx::Rect bounds(0, 0, 10, 10);
// Check that touch events outside the root window are still handled
// by the root window's gesture sequence.
-TEST_P(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
- // TODO(tdresser): write a version of this test for the unified GR.
- if (UsingUnifiedGR())
- return;
-
- TestGestureRecognizer* gesture_recognizer =
- new TestGestureRecognizer();
+TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
TimedEvents tes;
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
scoped_ptr<aura::Window> window(CreateTestWindowWithBounds(
gfx::Rect(-100, -100, 2000, 2000), root_window()));
- ui::GestureSequence* window_gesture_sequence =
- gesture_recognizer->GetGestureSequenceForTesting(window.get());
-
- ui::GestureSequence* root_window_gesture_sequence =
- gesture_recognizer->GetGestureSequenceForTesting(root_window());
-
gfx::Point pos1(-10, -10);
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, tes.Now());
DispatchEventUsingWindowDispatcher(&press1);
// As these presses were outside the root window, they should be
// associated with the root window.
- EXPECT_EQ(0, window_gesture_sequence->point_count());
- EXPECT_EQ(2, root_window_gesture_sequence->point_count());
+ EXPECT_EQ(root_window(),
+ static_cast<aura::Window*>(
+ ui::GestureRecognizer::Get()->GetTouchLockedTarget(press1)));
+ EXPECT_EQ(root_window(),
+ static_cast<aura::Window*>(
+ ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2)));
}
-TEST_P(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) {
+TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
EXPECT_TRUE(delegate->tap_cancel());
}
-TEST_P(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) {
- // Disabled for unified GR due to differences in when pinch begin is sent. The
- // Aura GR sends it earlier than is necessary.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
// Ack the press event.
delegate->ReceivedAck();
- EXPECT_TRUE(delegate->tap_down());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN);
delegate->Reset();
// Ack the move event.
delegate->ReceivedAck();
- EXPECT_TRUE(delegate->tap_cancel());
- EXPECT_TRUE(delegate->scroll_begin());
+ EXPECT_3_EVENTS(delegate->events(),
+ ui::ET_GESTURE_TAP_CANCEL,
+ ui::ET_GESTURE_SCROLL_BEGIN,
+ ui::ET_GESTURE_SCROLL_UPDATE);
delegate->Reset();
// Ack the release event. Although the release event has been processed, it
// should still generate a scroll-end event.
delegate->ReceivedAckPreventDefaulted();
- EXPECT_TRUE(delegate->scroll_end());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_SCROLL_END, ui::ET_GESTURE_END);
}
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(15, 25), kTouchId1,
tes.LeapForward(50));
ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 25), kTouchId2,
tes.Now());
- ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(45, 85), kTouchId2,
+ ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(145, 85), kTouchId2,
tes.LeapForward(1000));
- ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(45, 85), kTouchId2,
+ ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(145, 85), kTouchId2,
tes.LeapForward(14));
// Do a pinch.
// Ack the press and move events.
delegate->Reset();
delegate->ReceivedAck();
- EXPECT_TRUE(delegate->begin());
- EXPECT_TRUE(delegate->tap_down());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN);
delegate->Reset();
delegate->ReceivedAck();
- EXPECT_TRUE(delegate->scroll_begin());
+ EXPECT_3_EVENTS(delegate->events(),
+ ui::ET_GESTURE_TAP_CANCEL,
+ ui::ET_GESTURE_SCROLL_BEGIN,
+ ui::ET_GESTURE_SCROLL_UPDATE);
delegate->Reset();
delegate->ReceivedAck();
- EXPECT_TRUE(delegate->begin());
- EXPECT_TRUE(delegate->pinch_begin());
+ EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_BEGIN);
delegate->Reset();
delegate->ReceivedAck();
- EXPECT_TRUE(delegate->pinch_update());
+ EXPECT_2_EVENTS(delegate->events(),
+ ui::ET_GESTURE_SCROLL_UPDATE,
+ ui::ET_GESTURE_PINCH_BEGIN);
// Ack the first release. Although the release is processed, it should still
// generate a pinch-end event.
delegate->Reset();
delegate->ReceivedAckPreventDefaulted();
- EXPECT_TRUE(delegate->pinch_end());
- EXPECT_TRUE(delegate->end());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_PINCH_END, ui::ET_GESTURE_END);
delegate->Reset();
delegate->ReceivedAckPreventDefaulted();
- EXPECT_TRUE(delegate->scroll_end());
- EXPECT_TRUE(delegate->end());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_SCROLL_END, ui::ET_GESTURE_END);
}
-TEST_P(GestureRecognizerTest, GestureEndLocation) {
+TEST_F(GestureRecognizerTest, GestureEndLocation) {
GestureEventConsumeDelegate delegate;
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
&delegate, -1234, gfx::Rect(10, 10, 300, 300), root_window()));
delegate.gesture_end_location().ToString());
}
-TEST_P(GestureRecognizerTest, CaptureSendsGestureEnd) {
+TEST_F(GestureRecognizerTest, CaptureSendsGestureEnd) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
- TestGestureRecognizer* gesture_recognizer =
- new TestGestureRecognizer();
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window()));
ui::test::EventGenerator generator(root_window());
// Check that previous touch actions that are completely finished (either
// released or cancelled), do not receive extra synthetic cancels upon change of
// capture.
-TEST_P(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) {
+TEST_F(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
scoped_ptr<TestEventHandler> handler(new TestEventHandler);
}
// Tests that a press with the same touch id as an existing touch is ignored.
-TEST_P(GestureRecognizerTest, PressDoesNotCrash) {
+TEST_F(GestureRecognizerTest, PressDoesNotCrash) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
- TestGestureRecognizer* gesture_recognizer =
- new TestGestureRecognizer();
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
TimedEvents tes;
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
EXPECT_FALSE(delegate->scroll_begin());
}
-TEST_P(GestureRecognizerTest, TwoFingerTap) {
- // TODO(tdresser): enable this test with unified GR once two finger tap is
- // supported. See crbug.com/354396.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, TwoFingerTap) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
kTouchId1, tes.Now());
DispatchEventUsingWindowDispatcher(&press1);
- EXPECT_FALSE(delegate->tap());
- EXPECT_TRUE(delegate->tap_down());
- EXPECT_FALSE(delegate->tap_cancel());
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
- EXPECT_FALSE(delegate->long_press());
- EXPECT_FALSE(delegate->two_finger_tap());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN);
delegate->Reset();
ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&press2);
- EXPECT_FALSE(delegate->tap());
- EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
- EXPECT_TRUE(delegate->tap_cancel());
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
- EXPECT_FALSE(delegate->long_press());
- EXPECT_FALSE(delegate->two_finger_tap());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_TAP_CANCEL, ui::ET_GESTURE_BEGIN);
// Little bit of touch move should not affect our state.
delegate->Reset();
ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(131, 202),
kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&move2);
- EXPECT_FALSE(delegate->tap());
- EXPECT_FALSE(delegate->tap_down());
- EXPECT_FALSE(delegate->tap_cancel());
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
- EXPECT_FALSE(delegate->long_press());
- EXPECT_FALSE(delegate->two_finger_tap());
+ EXPECT_2_EVENTS(delegate->events(),
+ ui::ET_GESTURE_SCROLL_BEGIN,
+ ui::ET_GESTURE_SCROLL_UPDATE);
// Make sure there is enough delay before the touch is released so that it is
// recognized as a tap.
kTouchId1, tes.LeapForward(50));
DispatchEventUsingWindowDispatcher(&release1);
- EXPECT_FALSE(delegate->tap());
- EXPECT_FALSE(delegate->tap_down());
- EXPECT_FALSE(delegate->tap_cancel());
- EXPECT_TRUE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
- EXPECT_TRUE(delegate->two_finger_tap());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_TWO_FINGER_TAP, ui::ET_GESTURE_END);
// Lift second finger.
// Make sure there is enough delay before the touch is released so that it is
kTouchId2, tes.LeapForward(50));
DispatchEventUsingWindowDispatcher(&release2);
- EXPECT_FALSE(delegate->tap());
- EXPECT_FALSE(delegate->tap_down());
- EXPECT_FALSE(delegate->tap_cancel());
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
- EXPECT_TRUE(delegate->fling());
- EXPECT_FALSE(delegate->two_finger_tap());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_SCROLL_END, ui::ET_GESTURE_END);
}
-TEST_P(GestureRecognizerTest, TwoFingerTapExpired) {
+TEST_F(GestureRecognizerTest, TwoFingerTapExpired) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
EXPECT_FALSE(delegate->two_finger_tap());
}
-TEST_P(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
+TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
}
}
-TEST_P(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) {
- // Disabled for unified GR due to differences in when pinch begin is sent. The
- // Aura GR sends it earlier than is necessary.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&press2);
- EXPECT_TRUE(delegate->pinch_begin());
+ EXPECT_FALSE(delegate->pinch_begin());
// Make sure there is enough delay before the touch is released so that it
// is recognized as a tap.
DispatchEventUsingWindowDispatcher(&release);
EXPECT_FALSE(delegate->two_finger_tap());
- EXPECT_TRUE(delegate->pinch_end());
+ EXPECT_FALSE(delegate->pinch_end());
}
-TEST_P(GestureRecognizerTest, MultiFingerSwipe) {
+TEST_F(GestureRecognizerTest, MultiFingerSwipe) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
}
}
-TEST_P(GestureRecognizerTest, TwoFingerTapCancelled) {
+TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
}
}
-TEST_P(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) {
- // Disabled for unified GR due to differences in when scroll update is
- // sent. The Aura GR will never send a ScrollUpdate with a ScrollBegin, but
- // the unified GR will.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 523;
EXPECT_FALSE(delegate->tap_cancel());
// Pinch & Scroll only when there is enough movement.
EXPECT_TRUE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
+ EXPECT_TRUE(delegate->scroll_update());
EXPECT_FALSE(delegate->scroll_end());
EXPECT_FALSE(delegate->long_press());
EXPECT_FALSE(delegate->two_finger_tap());
// Verifies if a window is the target of multiple touch-ids and we hide the
// window everything is cleaned up correctly.
-TEST_P(GestureRecognizerTest, FlushAllOnHide) {
+TEST_F(GestureRecognizerTest, FlushAllOnHide) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
gfx::Rect bounds(0, 0, 200, 200);
ui::GestureRecognizer::Get()->GetTouchLockedTarget(press2));
}
-TEST_P(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) {
- // TODO(tdresser): write a version of this test for the unified GR.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
const int kTouchId = 2;
delegate->set_window(window.get());
TimedEvents tes;
- TimerTestGestureRecognizer* gesture_recognizer =
- new TimerTestGestureRecognizer();
- TimerTestGestureSequence* gesture_sequence =
- static_cast<TimerTestGestureSequence*>(
- gesture_recognizer->GetGestureSequenceForTesting(window.get()));
-
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
delegate->Reset();
ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
kTouchId, tes.Now());
delegate->Reset();
delegate->ReceivedAck();
EXPECT_TRUE(delegate->tap_down());
- EXPECT_TRUE(gesture_sequence->IsTimerRunning());
+
+ // Wait long enough that long press would have fired if the touchmove hadn't
+ // prevented it.
+ DelayByLongPressTimeout();
delegate->Reset();
delegate->ReceivedAckPreventDefaulted();
- EXPECT_FALSE(gesture_sequence->IsTimerRunning());
- gesture_sequence->ForceTimeout();
EXPECT_FALSE(delegate->long_press());
}
class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate {
public:
ConsumesTouchMovesDelegate() : consume_touch_move_(true) {}
- virtual ~ConsumesTouchMovesDelegate() {}
+ ~ConsumesTouchMovesDelegate() override {}
void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; }
private:
- virtual void OnTouchEvent(ui::TouchEvent* touch) OVERRIDE {
+ void OnTouchEvent(ui::TouchEvent* touch) override {
if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED)
touch->SetHandled();
else
// Same as GestureEventScroll, but tests that the behavior is the same
// even if all the touch-move events are consumed.
-TEST_P(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) {
+TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) {
scoped_ptr<ConsumesTouchMovesDelegate> delegate(
new ConsumesTouchMovesDelegate());
const int kWindowWidth = 123;
EXPECT_FALSE(delegate->scroll_update());
EXPECT_FALSE(delegate->scroll_end());
- // With the unified gesture detector, consuming the first touch move event
- // won't prevent all future scrolling.
- if (UsingUnifiedGR())
- EXPECT_TRUE(delegate->scroll_begin());
- else
- EXPECT_FALSE(delegate->scroll_begin());
+ EXPECT_TRUE(delegate->scroll_begin());
// Release the touch back at the start point. This should end without causing
// a tap.
EXPECT_FALSE(delegate->scroll_begin());
EXPECT_FALSE(delegate->scroll_update());
- if (UsingUnifiedGR())
- EXPECT_TRUE(delegate->scroll_end());
- else
- EXPECT_FALSE(delegate->scroll_end());
+ EXPECT_TRUE(delegate->scroll_end());
}
-// Tests the behavior of 2F scroll when all the touch-move events are consumed.
-TEST_P(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) {
- // TODO(tdresser): enable this test with unified GR once two finger tap is
- // supported. See crbug.com/354396.
- if (UsingUnifiedGR())
- return;
-
+// Tests the behavior of 2F scroll when some of the touch-move events are
+// consumed.
+TEST_F(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) {
scoped_ptr<ConsumesTouchMovesDelegate> delegate(
new ConsumesTouchMovesDelegate());
const int kWindowWidth = 123;
DispatchEventUsingWindowDispatcher(&press1);
tes.SendScrollEvent(event_processor(), 131, 231, kTouchId1, delegate.get());
- // First finger touches down and moves.
- EXPECT_FALSE(delegate->tap());
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
+ EXPECT_2_EVENTS(delegate->events(),
+ ui::ET_GESTURE_TAP_CANCEL,
+ ui::ET_GESTURE_SCROLL_BEGIN);
delegate->Reset();
// Second finger touches down and moves.
kTouchId2, tes.LeapForward(50));
DispatchEventUsingWindowDispatcher(&press2);
tes.SendScrollEvent(event_processor(), 161, 231, kTouchId2, delegate.get());
-
- // PinchBegin & ScrollBegin were not sent if the touch-move events were
- // consumed.
- EXPECT_FALSE(delegate->pinch_begin());
- EXPECT_FALSE(delegate->scroll_begin());
-
- EXPECT_FALSE(delegate->tap());
- EXPECT_FALSE(delegate->two_finger_tap());
-
- // Should be no PinchUpdate & ScrollUpdate.
- EXPECT_FALSE(delegate->pinch_update());
- EXPECT_FALSE(delegate->pinch_end());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
+ EXPECT_0_EVENTS(delegate->events());
delegate->Reset();
- // Moves First finger again, no PinchUpdate & ScrollUpdate.
+ // Move first finger again, no PinchUpdate & ScrollUpdate.
tes.SendScrollEvent(event_processor(), 161, 261, kTouchId1, delegate.get());
-
- EXPECT_FALSE(delegate->pinch_update());
- EXPECT_FALSE(delegate->pinch_end());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
+ EXPECT_0_EVENTS(delegate->events());
// Stops consuming touch-move.
delegate->set_consume_touch_move(false);
delegate->Reset();
// Making a pinch gesture.
- tes.SendScrollEvent(event_processor(), 161, 251, kTouchId1, delegate.get());
- // If touch moves are ever consumed, we should not see PinchBegin/Update
- // even touch moves become not consumed.
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
-
- EXPECT_FALSE(delegate->pinch_begin());
- EXPECT_FALSE(delegate->pinch_update());
- EXPECT_FALSE(delegate->pinch_end());
+ tes.SendScrollEvent(event_processor(), 161, 260, kTouchId1, delegate.get());
+ EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
delegate->Reset();
- tes.SendScrollEvent(event_processor(), 161, 241, kTouchId2, delegate.get());
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
-
- EXPECT_FALSE(delegate->pinch_begin());
- EXPECT_FALSE(delegate->pinch_update());
- EXPECT_FALSE(delegate->pinch_end());
+ tes.SendScrollEvent(event_processor(), 161, 261, kTouchId2, delegate.get());
+ EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
delegate->Reset();
ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
DispatchEventUsingWindowDispatcher(&release1);
DispatchEventUsingWindowDispatcher(&release2);
- EXPECT_FALSE(delegate->tap());
- // Touch release is not consumed, so we still see two finger tap.
- EXPECT_TRUE(delegate->two_finger_tap());
-
- // Should not see PinchEnd.
- EXPECT_TRUE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->scroll_end());
- EXPECT_TRUE(delegate->fling());
-
- EXPECT_FALSE(delegate->pinch_begin());
- EXPECT_FALSE(delegate->pinch_update());
- EXPECT_FALSE(delegate->pinch_end());
+ EXPECT_3_EVENTS(delegate->events(),
+ ui::ET_GESTURE_END,
+ ui::ET_SCROLL_FLING_START,
+ ui::ET_GESTURE_END);
}
// Like as GestureEventTouchMoveConsumed but tests the different behavior
// depending on whether the events were consumed before or after the scroll
// started.
-TEST_P(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) {
+TEST_F(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) {
scoped_ptr<ConsumesTouchMovesDelegate> delegate(
new ConsumesTouchMovesDelegate());
const int kWindowWidth = 123;
EXPECT_FALSE(delegate->scroll_update());
EXPECT_FALSE(delegate->scroll_end());
- // With the unified gesture detector, consuming the first touch move event
- // won't prevent all future scrolling.
- if (UsingUnifiedGR())
- EXPECT_TRUE(delegate->scroll_begin());
- else
- EXPECT_FALSE(delegate->scroll_begin());
+ // Consuming the first touch move event won't prevent all future scrolling.
+ EXPECT_TRUE(delegate->scroll_begin());
// Now, stop consuming touch-move events, and move the touch-point again.
delegate->set_consume_touch_move(false);
EXPECT_FALSE(delegate->scroll_begin());
EXPECT_FALSE(delegate->scroll_end());
- if (UsingUnifiedGR()) {
- // Scroll not prevented by consumed first touch move.
- EXPECT_TRUE(delegate->scroll_update());
- EXPECT_EQ(29, delegate->scroll_x());
- EXPECT_EQ(29, delegate->scroll_y());
- EXPECT_EQ(gfx::Point(0, 0).ToString(),
- delegate->scroll_begin_position().ToString());
- } else {
- EXPECT_FALSE(delegate->scroll_update());
- // No scroll has occurred, because an early touch move was consumed.
- EXPECT_EQ(0, delegate->scroll_x());
- EXPECT_EQ(0, delegate->scroll_y());
- EXPECT_EQ(gfx::Point(0, 0).ToString(),
- delegate->scroll_begin_position().ToString());
- }
+ // Scroll not prevented by consumed first touch move.
+ EXPECT_TRUE(delegate->scroll_update());
+ EXPECT_EQ(29, delegate->scroll_x());
+ EXPECT_EQ(29, delegate->scroll_y());
+ EXPECT_EQ(gfx::Point(0, 0).ToString(),
+ delegate->scroll_begin_position().ToString());
// Start consuming touch-move events again.
delegate->set_consume_touch_move(true);
EXPECT_FALSE(delegate->scroll_update());
EXPECT_FALSE(delegate->fling());
- if (UsingUnifiedGR())
- EXPECT_TRUE(delegate->scroll_end());
- else
- EXPECT_FALSE(delegate->scroll_end());
+ EXPECT_TRUE(delegate->scroll_end());
}
// Check that appropriate touch events generate double tap gesture events.
-TEST_P(GestureRecognizerTest, GestureEventDoubleTap) {
+TEST_F(GestureRecognizerTest, GestureEventDoubleTap) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
}
// Check that appropriate touch events generate triple tap gesture events.
-TEST_P(GestureRecognizerTest, GestureEventTripleTap) {
+TEST_F(GestureRecognizerTest, GestureEventTripleTap) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
EXPECT_FALSE(delegate->scroll_begin());
EXPECT_FALSE(delegate->scroll_update());
EXPECT_FALSE(delegate->scroll_end());
-
- // The behavior for the Aura GR is incorrect.
- if (UsingUnifiedGR())
- EXPECT_EQ(1 + (i % 3), delegate->tap_count());
- else
- EXPECT_EQ(3, delegate->tap_count());
+ EXPECT_EQ(1 + (i % 3), delegate->tap_count());
}
}
// Check that we don't get a double tap when the two taps are far apart.
-TEST_P(GestureRecognizerTest, TwoTapsFarApart) {
+TEST_F(GestureRecognizerTest, TwoTapsFarApart) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
// Check that we don't get a double tap when the two taps have a long enough
// delay in between.
-TEST_P(GestureRecognizerTest, TwoTapsWithDelayBetween) {
+TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 123;
// Checks that if the bounding-box of a gesture changes because of change in
// radius of a touch-point, and not because of change in position, then there
// are not gesture events from that.
-TEST_P(GestureRecognizerTest, BoundingBoxRadiusChange) {
- // TODO(tdresser): enable this test with unified GR when (if?) bounding box
- // behavior is unified.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 234;
press2.set_radius_x(5);
DispatchEventUsingWindowDispatcher(&press2);
EXPECT_FALSE(delegate->pinch_begin());
- EXPECT_EQ(gfx::Rect(101, 201, 100, 0).ToString(),
+ EXPECT_EQ(gfx::Rect(101, 196, 105, 10).ToString(),
delegate->bounding_box().ToString());
delegate->Reset();
- ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(141, 201), kTouchId,
+ ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(50, 50), kTouchId,
tes.LeapForward(40));
DispatchEventUsingWindowDispatcher(&move1);
EXPECT_TRUE(delegate->pinch_begin());
- EXPECT_EQ(gfx::Rect(141, 201, 60, 0).ToString(),
+ EXPECT_EQ(gfx::Rect(50, 50, 156, 156).ToString(),
delegate->bounding_box().ToString());
delegate->Reset();
// The position doesn't move, but the radius changes.
- ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 201), kTouchId,
- tes.LeapForward(40));
+ ui::TouchEvent move2(
+ ui::ET_TOUCH_MOVED, gfx::Point(50, 50), kTouchId, tes.LeapForward(40));
move2.set_radius_x(50);
move2.set_radius_y(60);
DispatchEventUsingWindowDispatcher(&move2);
// Checks that slow scrolls deliver the correct deltas.
// In particular, fix for http;//crbug.com/150573.
-TEST_P(GestureRecognizerTest, NoDriftInScroll) {
- ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3);
- ui::GestureConfiguration::set_min_scroll_delta_squared(9);
+TEST_F(GestureRecognizerTest, NoDriftInScroll) {
+ ui::GestureConfiguration::GetInstance()
+ ->set_max_touch_move_in_pixels_for_click(3);
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 234;
// Ensure that move events which are preventDefaulted will cause a tap
// cancel gesture event to be fired if the move would normally cause a
// scroll. See bug http://crbug.com/146397.
-TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) {
+TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) {
scoped_ptr<ConsumesTouchMovesDelegate> delegate(
new ConsumesTouchMovesDelegate());
const int kTouchId = 5;
EXPECT_FALSE(delegate->scroll_end());
}
-TEST_P(GestureRecognizerTest,
+TEST_F(GestureRecognizerTest,
TransferEventDispatchesTouchCancel) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
const int kWindowWidth = 800;
const int kWindowHeight = 600;
- const int kTouchId = 2;
+ const int kTouchId1 = 1;
+ const int kTouchId2 = 2;
gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, bounds, root_window()));
- scoped_ptr<RemoveOnTouchCancelHandler>
- handler(new RemoveOnTouchCancelHandler());
+ scoped_ptr<TestEventHandler> handler(new TestEventHandler());
window->AddPreTargetHandler(handler.get());
// Start a gesture sequence on |window|. Then transfer the events to NULL.
// Make sure |window| receives a touch-cancel event.
delegate->Reset();
- ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
- kTouchId, tes.Now());
- ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 1, tes.Now());
+ ui::TouchEvent press(
+ ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now());
DispatchEventUsingWindowDispatcher(&press);
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN);
+ delegate->Reset();
+ ui::TouchEvent p2(
+ ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), kTouchId2, tes.Now());
DispatchEventUsingWindowDispatcher(&p2);
- EXPECT_FALSE(delegate->tap());
- EXPECT_TRUE(delegate->tap_down());
- EXPECT_TRUE(delegate->tap_cancel());
- EXPECT_TRUE(delegate->begin());
+ EXPECT_2_EVENTS(
+ delegate->events(), ui::ET_GESTURE_TAP_CANCEL, ui::ET_GESTURE_BEGIN);
+ delegate->Reset();
+ ui::TouchEvent move(
+ ui::ET_TOUCH_MOVED, gfx::Point(350, 300), kTouchId2, tes.Now());
+ DispatchEventUsingWindowDispatcher(&move);
+ EXPECT_3_EVENTS(delegate->events(),
+ ui::ET_GESTURE_SCROLL_BEGIN,
+ ui::ET_GESTURE_SCROLL_UPDATE,
+ ui::ET_GESTURE_PINCH_BEGIN);
EXPECT_EQ(2, handler->touch_pressed_count());
delegate->Reset();
handler->Reset();
gesture_recognizer->TransferEventsTo(window.get(), NULL);
EXPECT_EQ(NULL,
gesture_recognizer->GetTouchLockedTarget(press));
- // The event-handler removes |window| from its parent on the first
- // touch-cancel event, so it won't receive the second touch-cancel event.
- EXPECT_EQ(1, handler->touch_cancelled_count());
+ EXPECT_4_EVENTS(delegate->events(),
+ ui::ET_GESTURE_PINCH_END,
+ ui::ET_GESTURE_SCROLL_END,
+ ui::ET_GESTURE_END,
+ ui::ET_GESTURE_END);
+ const std::vector<gfx::PointF>& points = handler->cancelled_touch_points();
+ EXPECT_EQ(2U, points.size());
+ EXPECT_EQ(gfx::Point(101, 201), points[0]);
+ EXPECT_EQ(gfx::Point(350, 300), points[1]);
}
// Check that appropriate touch events generate show press events
-TEST_P(GestureRecognizerTest, GestureEventShowPress) {
+TEST_F(GestureRecognizerTest, GestureEventShowPress) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
delegate->Reset();
- TimerTestGestureRecognizer* gesture_recognizer =
- new TimerTestGestureRecognizer();
-
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
kTouchId, tes.Now());
DispatchEventUsingWindowDispatcher(&press1);
}
// Check that scrolling cancels a show press
-TEST_P(GestureRecognizerTest, GestureEventShowPressCancelledByScroll) {
+TEST_F(GestureRecognizerTest, GestureEventShowPressCancelledByScroll) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
delegate->Reset();
- TimerTestGestureRecognizer* gesture_recognizer =
- new TimerTestGestureRecognizer();
-
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
- TimerTestGestureSequence* gesture_sequence =
- static_cast<TimerTestGestureSequence*>(
- gesture_recognizer->GetGestureSequenceForTesting(window.get()));
-
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
kTouchId, tes.Now());
DispatchEventUsingWindowDispatcher(&press1);
// Scroll around, to cancel the show press
tes.SendScrollEvent(event_processor(), 130, 230, kTouchId, delegate.get());
// Wait until the timer runs out
- gesture_sequence->ForceTimeout();
+ DelayByShowPressTimeout();
EXPECT_FALSE(delegate->show_press());
EXPECT_TRUE(delegate->tap_cancel());
}
// Test that show press events are sent immediately on tap
-TEST_P(GestureRecognizerTest, GestureEventShowPressSentOnTap) {
+TEST_F(GestureRecognizerTest, GestureEventShowPressSentOnTap) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
}
// Test that consuming the first move touch event prevents a scroll.
-TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) {
+TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveScrollTest) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
DispatchEventUsingWindowDispatcher(&move2);
delegate->ReceivedAck();
- if (UsingUnifiedGR()) {
// With the unified gesture detector, consuming the first touch move event
// won't prevent all future scrolling.
EXPECT_TRUE(delegate->scroll_begin());
EXPECT_TRUE(delegate->scroll_update());
- } else {
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- }
-}
-
-// Test that consuming the first touch move event of a touch point doesn't
-// prevent pinching once an additional touch has been pressed.
-TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMovePinchTest) {
- // Consuming moves within the touch slop and the the disposition handling of
- // pinch events behave differently between the Unified GR and the Aura GR.
- if (UsingUnifiedGR())
- return;
-
- scoped_ptr<QueueTouchEventDelegate> delegate(
- new QueueTouchEventDelegate(host()->dispatcher()));
- TimedEvents tes;
- const int kTouchId1 = 7;
- const int kTouchId2 = 4;
- gfx::Rect bounds(0, 0, 1000, 1000);
- scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
- delegate.get(), -1234, bounds, root_window()));
-
- ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
- kTouchId1, tes.Now());
- DispatchEventUsingWindowDispatcher(&press1);
- delegate->ReceivedAck();
-
- ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(2, 2),
- kTouchId1, tes.Now());
- DispatchEventUsingWindowDispatcher(&move1);
- delegate->ReceivedAckPreventDefaulted();
-
- ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
- kTouchId1, tes.Now());
- DispatchEventUsingWindowDispatcher(&move2);
- delegate->ReceivedAck();
-
- // We can't scroll, because a move has been consumed.
- EXPECT_FALSE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_FALSE(delegate->pinch_begin());
-
- // An additional press will allow us to pinch.
- ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
- kTouchId2, tes.Now());
- DispatchEventUsingWindowDispatcher(&press2);
- delegate->ReceivedAck();
-
- ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(20, 20),
- kTouchId2, tes.Now());
- DispatchEventUsingWindowDispatcher(&move3);
- delegate->ReceivedAck();
-
- EXPECT_TRUE(delegate->pinch_begin());
- EXPECT_FALSE(delegate->pinch_update());
-
- delegate->Reset();
-
- ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(40, 40),
- kTouchId2, tes.Now());
- DispatchEventUsingWindowDispatcher(&move4);
- delegate->ReceivedAck();
-
- EXPECT_TRUE(delegate->pinch_update());
- EXPECT_EQ(10, delegate->scroll_x());
- EXPECT_EQ(10, delegate->scroll_y());
}
// Test that consuming the first move touch doesn't prevent a tap.
-TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) {
+TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveTapTest) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
}
// Test that consuming the first move touch doesn't prevent a long press.
-TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) {
+TEST_F(GestureRecognizerTest, GestureEventConsumedTouchMoveLongPressTest) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
delegate->Reset();
- TimerTestGestureRecognizer* gesture_recognizer =
- new TimerTestGestureRecognizer();
-
- ScopedGestureRecognizerSetter gr_setter(gesture_recognizer);
-
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
kTouchId, tes.Now());
DispatchEventUsingWindowDispatcher(&press1);
}
// Tests that the deltas are correct when leaving the slop region very slowly.
-TEST_P(GestureRecognizerTest, TestExceedingSlopSlowly) {
- // Disabled for unified GR due to subtle differences in touch slop handling.
- if (UsingUnifiedGR())
- return;
-
- ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3);
+TEST_F(GestureRecognizerTest, TestExceedingSlopSlowly) {
+ ui::GestureConfiguration::GetInstance()
+ ->set_max_touch_move_in_pixels_for_click(3);
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 234;
delegate->Reset();
- ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(13, 10), kTouchId,
+ ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::PointF(13.1f, 10.f), kTouchId,
tes.LeapForward(40));
DispatchEventUsingWindowDispatcher(&move3);
EXPECT_TRUE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
- EXPECT_EQ(0, delegate->scroll_x());
- EXPECT_EQ(3, delegate->scroll_x_hint());
+ EXPECT_TRUE(delegate->scroll_update());
+ EXPECT_NEAR(0.1, delegate->scroll_x(), 0.0001);
+ EXPECT_FLOAT_EQ(3.1f, delegate->scroll_x_hint());
delegate->Reset();
-
ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(14, 10), kTouchId,
tes.LeapForward(40));
DispatchEventUsingWindowDispatcher(&move4);
EXPECT_FALSE(delegate->scroll_begin());
EXPECT_TRUE(delegate->scroll_update());
- EXPECT_EQ(1, delegate->scroll_x());
- EXPECT_EQ(0, delegate->scroll_x_hint());
+ EXPECT_NEAR(0.9, delegate->scroll_x(), 0.0001);
+ EXPECT_EQ(0.f, delegate->scroll_x_hint());
delegate->Reset();
}
-TEST_P(GestureRecognizerTest, ScrollAlternatelyConsumedTest) {
+TEST_F(GestureRecognizerTest, ScrollAlternatelyConsumedTest) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
}
}
-TEST_P(GestureRecognizerTest, PinchAlternatelyConsumedTest) {
- // Disabled for unified GR due to differences in when scroll update is
- // sent. The Aura GR will never send a ScrollUpdate with a ScrollBegin, but
- // the unified GR will.
- if (UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, PinchAlternatelyConsumedTest) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, bounds, root_window()));
-
+ delegate->set_window(window.get());
delegate->Reset();
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
DispatchEventUsingWindowDispatcher(&move1);
delegate->ReceivedAck();
EXPECT_TRUE(delegate->scroll_begin());
- EXPECT_FALSE(delegate->scroll_update());
+ EXPECT_TRUE(delegate->scroll_update());
EXPECT_TRUE(delegate->pinch_begin());
EXPECT_FALSE(delegate->pinch_update());
delegate->Reset();
}
// Test that touch event flags are passed through to the gesture event.
-TEST_P(GestureRecognizerTest, GestureEventFlagsPassedFromTouchEvent) {
+TEST_F(GestureRecognizerTest, GestureEventFlagsPassedFromTouchEvent) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
}
// Test that latency info is passed through to the gesture event.
-TEST_P(GestureRecognizerTest, LatencyPassedFromTouchEvent) {
+TEST_F(GestureRecognizerTest, LatencyPassedFromTouchEvent) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
ui::INPUT_EVENT_LATENCY_UI_COMPONENT, 0, 0, time_ui, 1);
press1.latency()->AddLatencyNumberWithTimestamp(
- ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, 0, 0, time_acked, 1);
+ ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0, time_acked, 1);
DispatchEventUsingWindowDispatcher(&press1);
EXPECT_TRUE(delegate->tap_down());
EXPECT_EQ(time_ui, component.event_time);
ASSERT_TRUE(delegate->latency_info().FindLatency(
- ui::INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT, 0, &component));
+ ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, &component));
EXPECT_EQ(time_acked, component.event_time);
delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS);
void set_window(aura::Window** window) { window_ = window; }
- virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
+ void OnGestureEvent(ui::GestureEvent* gesture) override {
GestureEventConsumeDelegate::OnGestureEvent(gesture);
if (gesture->type() != ui::ET_GESTURE_LONG_PRESS)
return;
// Check that deleting the window in response to a long press gesture doesn't
// crash.
-TEST_P(GestureRecognizerTest, GestureEventLongPressDeletingWindow) {
+TEST_F(GestureRecognizerTest, GestureEventLongPressDeletingWindow) {
GestureEventDeleteWindowOnLongPress delegate;
const int kWindowWidth = 123;
const int kWindowHeight = 45;
EXPECT_EQ(NULL, window);
}
-TEST_P(GestureRecognizerTest, GestureEventSmallPinchDisabled) {
- if (!UsingUnifiedGR())
- return;
- CommandLine::ForCurrentProcess()->AppendSwitch(
- switches::kCompensateForUnstablePinchZoom);
-
+TEST_F(GestureRecognizerWithSwitchTest, GestureEventSmallPinchDisabled) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
}
-TEST_P(GestureRecognizerTest, GestureEventSmallPinchEnabled) {
- if (!UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, GestureEventSmallPinchEnabled) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
TimedEvents tes;
// Tests that delaying the ack of a touch release doesn't trigger a long press
// gesture.
-TEST_P(GestureRecognizerTest, DISABLED_EagerGestureDetection) {
- if (!UsingUnifiedGR())
- return;
+TEST_F(GestureRecognizerTest, DISABLED_EagerGestureDetection) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
delegate->Reset();
// Wait until the long press event would fire (if we weren't eager).
- base::MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::MessageLoop::QuitClosure(),
- base::TimeDelta::FromSecondsD(
- ui::GestureConfiguration::long_press_time_in_seconds() * 1.1));
- base::MessageLoop::current()->Run();
+ DelayByLongPressTimeout();
// Ack the touch release.
delegate->ReceivedAck();
// This tests crbug.com/405519, in which events which the gesture detector
// ignores cause future events to also be thrown away.
-TEST_P(GestureRecognizerTest, IgnoredEventsDontPreventFutureEvents) {
- if (!UsingUnifiedGR())
- return;
-
+TEST_F(GestureRecognizerTest, IgnoredEventsDontPreventFutureEvents) {
scoped_ptr<QueueTouchEventDelegate> delegate(
new QueueTouchEventDelegate(host()->dispatcher()));
TimedEvents tes;
EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
}
-INSTANTIATE_TEST_CASE_P(GestureRecognizer,
- GestureRecognizerTest,
- ::testing::Bool());
-
} // namespace test
} // namespace aura