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

Unified Diff: content/browser/renderer_host/render_widget_host_unittest.cc

Issue 10855027: Filter unnecessary GestureFlingCancel events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review comments Created 8 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 | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/renderer_host/render_widget_host_unittest.cc
diff --git a/content/browser/renderer_host/render_widget_host_unittest.cc b/content/browser/renderer_host/render_widget_host_unittest.cc
index 1bd6550f9bb73ae24439933ed9ed912f021563a0..d358680c405c556fd14e7ea423a544addee94e35 100644
--- a/content/browser/renderer_host/render_widget_host_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_unittest.cc
@@ -224,6 +224,7 @@ class MockRenderWidgetHost : public RenderWidgetHostImpl {
using RenderWidgetHostImpl::is_hidden_;
using RenderWidgetHostImpl::resize_ack_pending_;
using RenderWidgetHostImpl::coalesced_gesture_events_;
+ using RenderWidgetHostImpl::fling_in_progress_;
bool unresponsive_timer_fired() const {
return unresponsive_timer_fired_;
@@ -854,6 +855,87 @@ TEST_F(RenderWidgetHostTest, CoalescesGesturesEvents) {
EXPECT_EQ(0U, process_->sink().message_count());
}
+TEST_F(RenderWidgetHostTest, GestureFlingCancelsFiltered) {
+ process_->sink().ClearMessages();
+ // GFC without previous GFS is dropped.
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel);
+ EXPECT_EQ(0U, process_->sink().message_count());
+ EXPECT_EQ(0U, host_->coalesced_gesture_events_.size());
+
+ // GFC after previous GFS is dispatched and acked.
+ process_->sink().ClearMessages();
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart);
+ EXPECT_TRUE(host_->fling_in_progress_);
+ SendInputEventACK(WebInputEvent::GestureFlingStart, true);
+ MessageLoop::current()->RunAllPending();
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel);
+ EXPECT_FALSE(host_->fling_in_progress_);
+ EXPECT_EQ(2U, process_->sink().message_count());
+ SendInputEventACK(WebInputEvent::GestureFlingCancel, true);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(0U, host_->coalesced_gesture_events_.size());
+
+ // GFC before previous GFS is acked.
+ process_->sink().ClearMessages();
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart);
+ EXPECT_TRUE(host_->fling_in_progress_);
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel);
+ EXPECT_FALSE(host_->fling_in_progress_);
+ EXPECT_EQ(1U, process_->sink().message_count());
+ EXPECT_FALSE(host_->coalesced_gesture_events_.empty());
+
+ // Advance state realistically.
+ SendInputEventACK(WebInputEvent::GestureFlingStart, true);
+ MessageLoop::current()->RunAllPending();
+ SendInputEventACK(WebInputEvent::GestureFlingCancel, true);
+ MessageLoop::current()->RunAllPending();
+ EXPECT_EQ(0U, host_->coalesced_gesture_events_.size());
+
+ // GFS is added to the queue if another event is pending
+ process_->sink().ClearMessages();
+ SimulateGestureEvent(8, -7, 0, WebInputEvent::GestureScrollUpdate);
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart);
+ EXPECT_EQ(1U, process_->sink().message_count());
+ WebGestureEvent merged_event = host_->coalesced_gesture_events_.back();
+ EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type);
+ EXPECT_FALSE(host_->fling_in_progress_);
+ EXPECT_EQ(1U, host_->coalesced_gesture_events_.size());
+
+ // GFS in queue means that a GFC is added to the queue
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel);
+ merged_event = host_->coalesced_gesture_events_.back();
+ EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
+ EXPECT_FALSE(host_->fling_in_progress_);
+ EXPECT_EQ(2U, host_->coalesced_gesture_events_.size());
+
+
+ // Adding a second GFC is dropped.
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel);
+ EXPECT_FALSE(host_->fling_in_progress_);
+ EXPECT_EQ(2U, host_->coalesced_gesture_events_.size());
+
+ // Adding another GFS will add it to the queue.
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingStart);
+ merged_event = host_->coalesced_gesture_events_.back();
+ EXPECT_EQ(WebInputEvent::GestureFlingStart, merged_event.type);
+ EXPECT_FALSE(host_->fling_in_progress_);
+ EXPECT_EQ(3U, host_->coalesced_gesture_events_.size());
+
+ // GFS in queue means that a GFC is added to the queue
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel);
+ merged_event = host_->coalesced_gesture_events_.back();
+ EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
+ EXPECT_FALSE(host_->fling_in_progress_);
+ EXPECT_EQ(4U, host_->coalesced_gesture_events_.size());
+
+ // Adding another GFC with a GFC already there is dropped.
+ SimulateGestureEvent(0, -10, 0, WebInputEvent::GestureFlingCancel);
+ merged_event = host_->coalesced_gesture_events_.back();
+ EXPECT_EQ(WebInputEvent::GestureFlingCancel, merged_event.type);
+ EXPECT_FALSE(host_->fling_in_progress_);
+ EXPECT_EQ(4U, host_->coalesced_gesture_events_.size());
+}
+
// Test that the hang monitor timer expires properly if a new timer is started
// while one is in progress (see crbug.com/11007).
TEST_F(RenderWidgetHostTest, DontPostponeHangMonitorTimeout) {
« no previous file with comments | « content/browser/renderer_host/render_widget_host_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698