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

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

Issue 16114003: Don't send touch move to renderer while scrolling (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fix the case touch event queue could be empty when GetLatestEvent() is called Created 7 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
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 f9c2677fee12ffda8862ae769c1799cce42a1bde..a2995bdbc5768e42a6d6edc6bd98015cd8d8f818 100644
--- a/content/browser/renderer_host/render_widget_host_unittest.cc
+++ b/content/browser/renderer_host/render_widget_host_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/basictypes.h"
+#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/shared_memory.h"
#include "base/timer.h"
@@ -24,6 +25,7 @@
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/notification_types.h"
+#include "content/public/common/content_switches.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -3677,6 +3679,10 @@ TEST_F(RenderWidgetHostTest, GestureScrollDebounceTimerOverscroll) {
// Tests that when touch-events are dispatched to the renderer, the overscroll
// gesture deals with them correctly.
TEST_F(RenderWidgetHostTest, OverscrollWithTouchEvents) {
+ // The event flow in this test is not the same if touch-cancel-on-scroll is
+ // enabled. So disable touch-cancel-on-scroll for this test.
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kTouchCancelOnScroll, "0");
host_->SetupForOverscrollControllerTest();
host_->set_debounce_interval_time_ms(10);
host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
@@ -4235,4 +4241,90 @@ TEST_F(RenderWidgetHostTest, OverscrollResetsOnBlur) {
process_->sink().ClearMessages();
}
+// Tests that when scroll starts, fake touch cancel is sent to renderer and
+// no touch events are sent to renderer during scrolling.
+TEST_F(RenderWidgetHostTest, TouchCancelOnScroll) {
+ CommandLine::ForCurrentProcess()->AppendSwitchASCII(
+ switches::kTouchCancelOnScroll, "1");
+ host_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true));
+ host_->set_debounce_interval_time_ms(0);
+ process_->sink().ClearMessages();
+ view_->set_bounds(gfx::Rect(0, 0, 400, 200));
+ view_->Show();
+
+ PressTouchPoint(0, 1);
+ if (host_->ShouldForwardTouchEvent())
sadrul 2013/06/20 08:51:27 Use EXPECT to verify the expectation, since the st
Yufeng Shen (Slow to review) 2013/06/20 17:56:45 Done.
+ SendTouchEvent();
+ EXPECT_EQ(1U, process_->sink().message_count());
+ process_->sink().ClearMessages();
+ SendInputEventACK(WebInputEvent::TouchStart,
+ INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+
+ MoveTouchPoint(0, 20, 5);
+ if (host_->ShouldForwardTouchEvent())
+ SendTouchEvent();
+ EXPECT_EQ(1U, process_->sink().message_count());
+ process_->sink().ClearMessages();
+ SendInputEventACK(WebInputEvent::TouchMove,
+ INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+
+ // GestureScrollBegin does not trigger touch cancel.
+ SimulateGestureEvent(WebInputEvent::GestureScrollBegin,
+ WebGestureEvent::Touchscreen);
+ EXPECT_FALSE(host_->is_scroll_update_in_progress());
+ EXPECT_EQ(1U, process_->sink().message_count());
+ SendInputEventACK(WebInputEvent::GestureScrollBegin,
+ INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ process_->sink().ClearMessages();
+
+ // Touch event keeps coming.
+ MoveTouchPoint(0, 30, 5);
+ if (host_->ShouldForwardTouchEvent())
+ SendTouchEvent();
+ EXPECT_EQ(1U, process_->sink().message_count());
+ process_->sink().ClearMessages();
+
+ // GestureScrollUpdate triggers touch cancel.
+ SimulateGestureScrollUpdateEvent(20, 4, 0);
+ EXPECT_TRUE(host_->is_scroll_update_in_progress());
+ // TouchCancel & GestureScrollUpdate are sent.
+ EXPECT_EQ(2U, process_->sink().message_count());
+ EXPECT_EQ(GetInputEventFromMessage(*process_->sink().GetMessageAt(0))->type,
+ WebInputEvent::TouchCancel);
+ EXPECT_EQ(GetInputEventFromMessage(*process_->sink().GetMessageAt(1))->type,
+ WebInputEvent::GestureScrollUpdate);
+ EXPECT_EQ(1U, host_->GestureEventLastQueueEventSize());
+ // Touch event queue should remain empty since we don't want to process
+ // acked touch cancel.
+ EXPECT_EQ(0U, host_->TouchEventQueueSize());
+
+ SendInputEventACK(WebInputEvent::GestureScrollUpdate,
+ INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+ process_->sink().ClearMessages();
+
+ // Touch move event should not reach the renderer when scroll update is in
+ // progress.
+ MoveTouchPoint(0, 65, 10);
+ if (host_->ShouldForwardTouchEvent())
+ SendTouchEvent();
+ EXPECT_EQ(0U, process_->sink().message_count());
+ process_->sink().ClearMessages();
+
+ SimulateGestureEvent(WebKit::WebInputEvent::GestureScrollEnd,
+ WebGestureEvent::Touchscreen);
+ EXPECT_FALSE(host_->is_scroll_update_in_progress());
+ EXPECT_EQ(1U, process_->sink().message_count());
+ process_->sink().ClearMessages();
+ SendInputEventACK(WebInputEvent::GestureScrollEnd,
+ INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
+
+ // Now touch events should come through to renderer.
+ MoveTouchPoint(0, 80, 10);
+ if (host_->ShouldForwardTouchEvent())
+ SendTouchEvent();
+ EXPECT_EQ(1U, process_->sink().message_count());
+ EXPECT_EQ(GetInputEventFromMessage(*process_->sink().GetMessageAt(0))->type,
+ WebInputEvent::TouchMove);
+ process_->sink().ClearMessages();
+}
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698