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

Unified Diff: ui/aura/window_event_dispatcher_unittest.cc

Issue 332703003: aura: Allow held touch-events to contribute to gesture events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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 | « ui/aura/window_event_dispatcher.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/window_event_dispatcher_unittest.cc
diff --git a/ui/aura/window_event_dispatcher_unittest.cc b/ui/aura/window_event_dispatcher_unittest.cc
index 86b60463bc321b4ead26e7b7010a53b03107efee..716bcc908735142273b3ba8ee6ae4b58c3904f2e 100644
--- a/ui/aura/window_event_dispatcher_unittest.cc
+++ b/ui/aura/window_event_dispatcher_unittest.cc
@@ -588,7 +588,7 @@ std::string EventTypeToString(ui::EventType type) {
default:
// We should explicitly require each event type.
- NOTREACHED();
+ NOTREACHED() << "Received unexpected event: " << type;
break;
}
return "";
@@ -744,12 +744,15 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeld) {
// Check that we don't immediately dispatch the TOUCH_MOVED event.
ui::TouchEvent touch_moved_event(
ui::ET_TOUCH_MOVED, touch_location, 0, ui::EventTimeForNow());
+ ui::TouchEvent touch_moved_event2 = touch_moved_event;
+ ui::TouchEvent touch_moved_event3 = touch_moved_event;
+
DispatchEventUsingWindowDispatcher(&touch_moved_event);
EXPECT_TRUE(recorder.events().empty());
// Check that on ReleasePointerMoves, held events are not dispatched
// immediately, but posted instead.
- DispatchEventUsingWindowDispatcher(&touch_moved_event);
+ DispatchEventUsingWindowDispatcher(&touch_moved_event2);
host()->dispatcher()->ReleasePointerMoves();
EXPECT_TRUE(recorder.events().empty());
@@ -763,7 +766,7 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeld) {
ui::ET_TOUCH_RELEASED, touch_location, 0, ui::EventTimeForNow());
recorder.Reset();
host()->dispatcher()->HoldPointerMoves();
- DispatchEventUsingWindowDispatcher(&touch_moved_event);
+ DispatchEventUsingWindowDispatcher(&touch_moved_event3);
DispatchEventUsingWindowDispatcher(&touch_released_event);
EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP GESTURE_END",
EventTypesToString(recorder.events()));
@@ -773,20 +776,21 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeld) {
EXPECT_TRUE(recorder.events().empty());
}
+// This event handler requests the dispatcher to start holding pointer-move
+// events when it receives the first scroll-update gesture.
class HoldPointerOnScrollHandler : public ui::test::TestEventHandler {
public:
HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher,
- EventFilterRecorder* filter)
+ EventFilterRecorder* filter)
: dispatcher_(dispatcher),
filter_(filter),
- holding_moves_(false) {
- }
+ holding_moves_(false) {}
virtual ~HoldPointerOnScrollHandler() {}
private:
+ // ui::test::TestEventHandler:
virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE {
- if (gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
- CHECK(!holding_moves_);
+ if (!holding_moves_ && gesture->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
holding_moves_ = true;
dispatcher_->HoldPointerMoves();
filter_->Reset();
@@ -825,8 +829,10 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) {
// along with the subsequent events (i.e. touch-release, scroll-end, and
// gesture-end).
const EventFilterRecorder::Events& events = recorder.events();
- EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END",
- EventTypesToString(events));
+ EXPECT_EQ(
+ "TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED "
+ "GESTURE_SCROLL_END GESTURE_END",
+ EventTypesToString(events));
ASSERT_EQ(2u, recorder.touch_locations().size());
EXPECT_EQ(gfx::Point(-40, 10).ToString(),
recorder.touch_locations()[0].ToString());
@@ -834,6 +840,40 @@ TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) {
recorder.touch_locations()[1].ToString());
}
+// Tests that a 'held' touch-event does contribute to gesture event when it is
+// dispatched.
+TEST_F(WindowEventDispatcherTest, HeldTouchMoveContributesToGesture) {
+ EventFilterRecorder recorder;
+ root_window()->AddPreTargetHandler(&recorder);
+
+ const gfx::Point location(20, 20);
+ ui::TouchEvent press(
+ ui::ET_TOUCH_PRESSED, location, 0, ui::EventTimeForNow());
+ DispatchEventUsingWindowDispatcher(&press);
+ EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_PRESSED));
+ recorder.Reset();
+
+ host()->dispatcher()->HoldPointerMoves();
+
+ ui::TouchEvent move(ui::ET_TOUCH_MOVED,
+ location + gfx::Vector2d(100, 100),
+ 0,
+ ui::EventTimeForNow());
+ DispatchEventUsingWindowDispatcher(&move);
+ EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
+ EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN));
+ recorder.Reset();
+
+ host()->dispatcher()->ReleasePointerMoves();
+ EXPECT_FALSE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
+ RunAllPendingInMessageLoop();
+ EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
+ EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN));
+ EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE));
+
+ root_window()->RemovePreTargetHandler(&recorder);
+}
+
// Tests that synthetic mouse events are ignored when mouse
// events are disabled.
TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) {
@@ -1895,8 +1935,10 @@ TEST_F(WindowEventDispatcherTestInHighDPI, TouchMovesHeldOnScroll) {
// along with the subsequent events (i.e. touch-release, scroll-end, and
// gesture-end).
const EventFilterRecorder::Events& events = recorder.events();
- EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END",
- EventTypesToString(events));
+ EXPECT_EQ(
+ "TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED "
+ "GESTURE_SCROLL_END GESTURE_END",
+ EventTypesToString(events));
ASSERT_EQ(2u, recorder.touch_locations().size());
EXPECT_EQ(gfx::Point(-40, 10).ToString(),
recorder.touch_locations()[0].ToString());
« no previous file with comments | « ui/aura/window_event_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698