Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Unified Diff: ui/aura/gestures/gesture_recognizer_unittest.cc

Issue 469523003: Add the actual location coordinates to the touch cancel event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: canceling the touch points from GestureConsumer Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/aura/window_event_dispatcher.cc » ('j') | ui/aura/window_event_dispatcher.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/gestures/gesture_recognizer_unittest.cc
diff --git a/ui/aura/gestures/gesture_recognizer_unittest.cc b/ui/aura/gestures/gesture_recognizer_unittest.cc
index 963b24dac9c16db7845d6839a14f86743cac1941..f4f73a43c84d657b400b32d4ba2ee67cd6746404 100644
--- a/ui/aura/gestures/gesture_recognizer_unittest.cc
+++ b/ui/aura/gestures/gesture_recognizer_unittest.cc
@@ -602,11 +602,10 @@ class TimedEvents {
// 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() {}
@@ -622,7 +621,7 @@ class TestEventHandler : public ui::EventHandler {
touch_moved_count_++;
break;
case ui::ET_TOUCH_CANCELLED:
- touch_cancelled_count_++;
+ touch_points_.push_back(event->location());
break;
default:
break;
@@ -633,46 +632,26 @@ class TestEventHandler : public ui::EventHandler {
touch_released_count_ = 0;
touch_pressed_count_ = 0;
touch_moved_count_ = 0;
- touch_cancelled_count_ = 0;
+ 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>(touch_points_.size());
+ }
+ const std::vector<gfx::PointF>& touch_points() const { return touch_points_; }
private:
int touch_released_count_;
int touch_pressed_count_;
int touch_moved_count_;
- int touch_cancelled_count_;
+ std::vector<gfx::PointF> touch_points_;
DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
};
-// Removes the target window from its parent when it receives a touch-cancel
-// event.
-class RemoveOnTouchCancelHandler : public TestEventHandler {
- public:
- RemoveOnTouchCancelHandler() {}
- virtual ~RemoveOnTouchCancelHandler() {}
-
- private:
- // ui::EventHandler:
- virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
- TestEventHandler::OnTouchEvent(event);
- if (event->type() == ui::ET_TOUCH_CANCELLED) {
- Window* target = static_cast<Window*>(event->target());
- // This is tiptoeing around crbug.com/310172. If this event handler isn't
- // removed, we enter an infinite loop.
- target->RemovePreTargetHandler(this);
- target->parent()->RemoveChild(target);
- }
- }
-
- DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler);
-};
-
} // namespace
class GestureRecognizerTest : public AuraTestBase,
@@ -3769,31 +3748,46 @@ TEST_P(GestureRecognizerTest, GestureEventConsumedTouchMoveCanFireTapCancel) {
TEST_P(GestureRecognizerTest,
TransferEventDispatchesTouchCancel) {
+ // Only enabled for unified GR, as the old Aura GR doesn't assign
+ // positions to touch cancel events correctly.
+ if (!UsingUnifiedGR())
+ return;
+
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();
@@ -3804,9 +3798,15 @@ TEST_P(GestureRecognizerTest,
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->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
« no previous file with comments | « no previous file | ui/aura/window_event_dispatcher.cc » ('j') | ui/aura/window_event_dispatcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698