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

Side by Side Diff: content/browser/renderer_host/input/input_router_impl_unittest.cc

Issue 188833004: [Android] Properly disable the touch ack timeout during a touch sequence (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@input_log_verbose
Patch Set: Timeout tweaks Created 6 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "content/browser/renderer_host/input/gesture_event_queue.h" 9 #include "content/browser/renderer_host/input/gesture_event_queue.h"
10 #include "content/browser/renderer_host/input/input_router_client.h" 10 #include "content/browser/renderer_host/input/input_router_client.h"
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 input_router_->OnMessageReceived( 281 input_router_->OnMessageReceived(
282 InputHostMsg_SetTouchAction(0, touch_action)); 282 InputHostMsg_SetTouchAction(0, touch_action));
283 } 283 }
284 284
285 size_t GetSentMessageCountAndResetSink() { 285 size_t GetSentMessageCountAndResetSink() {
286 size_t count = process_->sink().message_count(); 286 size_t count = process_->sink().message_count();
287 process_->sink().ClearMessages(); 287 process_->sink().ClearMessages();
288 return count; 288 return count;
289 } 289 }
290 290
291 static void Wait(base::TimeDelta delay) { 291 static void RunTasksAndWait(base::TimeDelta delay) {
292 base::MessageLoop::current()->PostDelayedTask( 292 base::MessageLoop::current()->PostDelayedTask(
293 FROM_HERE, base::MessageLoop::QuitClosure(), delay); 293 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
294 base::MessageLoop::current()->Run(); 294 base::MessageLoop::current()->Run();
295 } 295 }
296 296
297 scoped_ptr<MockRenderProcessHost> process_; 297 scoped_ptr<MockRenderProcessHost> process_;
298 scoped_ptr<MockInputRouterClient> client_; 298 scoped_ptr<MockInputRouterClient> client_;
299 scoped_ptr<MockInputAckHandler> ack_handler_; 299 scoped_ptr<MockInputAckHandler> ack_handler_;
300 scoped_ptr<InputRouterImpl> input_router_; 300 scoped_ptr<InputRouterImpl> input_router_;
301 301
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 } 998 }
999 999
1000 // Test that touch ack timeout behavior is properly configured via the command 1000 // Test that touch ack timeout behavior is properly configured via the command
1001 // line, and toggled by view update flags and allowed touch actions. 1001 // line, and toggled by view update flags and allowed touch actions.
1002 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) { 1002 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) {
1003 // Unless explicitly supported via the command-line, the touch timeout should 1003 // Unless explicitly supported via the command-line, the touch timeout should
1004 // be disabled. 1004 // be disabled.
1005 EXPECT_FALSE(TouchEventTimeoutEnabled()); 1005 EXPECT_FALSE(TouchEventTimeoutEnabled());
1006 1006
1007 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 1007 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1008 switches::kTouchAckTimeoutDelayMs, "5"); 1008 switches::kTouchAckTimeoutDelayMs, "1");
1009 TearDown(); 1009 TearDown();
1010 SetUp(); 1010 SetUp();
1011 ASSERT_TRUE(TouchEventTimeoutEnabled()); 1011 ASSERT_TRUE(TouchEventTimeoutEnabled());
1012 1012
1013 // Verify that the touch ack timeout fires upon the delayed ack. 1013 // Verify that the touch ack timeout fires upon the delayed ack.
1014 PressTouchPoint(1, 1); 1014 PressTouchPoint(1, 1);
1015 SendTouchEvent(); 1015 SendTouchEvent();
1016 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1016 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1017 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1017 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1018 Wait(base::TimeDelta::FromMilliseconds(15)); 1018 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2));
1019 1019
1020 // The timed-out event should have been ack'ed. 1020 // The timed-out event should have been ack'ed.
1021 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1021 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1022 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1022 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1023 1023
1024 // Ack'ing the timed-out event should fire a TouchCancel. 1024 // Ack'ing the timed-out event should fire a TouchCancel.
1025 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); 1025 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
1026 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1026 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1027 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1027 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1028 1028
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 PressTouchPoint(1, 1); 1075 PressTouchPoint(1, 1);
1076 SendTouchEvent(); 1076 SendTouchEvent();
1077 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1077 EXPECT_TRUE(TouchEventTimeoutEnabled());
1078 } 1078 }
1079 1079
1080 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by 1080 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by
1081 // the touch timeout. 1081 // the touch timeout.
1082 TEST_F(InputRouterImplTest, 1082 TEST_F(InputRouterImplTest,
1083 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) { 1083 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) {
1084 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 1084 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1085 switches::kTouchAckTimeoutDelayMs, "5"); 1085 switches::kTouchAckTimeoutDelayMs, "1");
1086 TearDown(); 1086 TearDown();
1087 SetUp(); 1087 SetUp();
1088 ASSERT_TRUE(TouchEventTimeoutEnabled()); 1088 ASSERT_TRUE(TouchEventTimeoutEnabled());
1089 OnHasTouchEventHandlers(true); 1089 OnHasTouchEventHandlers(true);
1090 1090
1091 // Start a touch sequence. 1091 // Start a touch sequence.
1092 PressTouchPoint(1, 1); 1092 PressTouchPoint(1, 1);
1093 SendTouchEvent(); 1093 SendTouchEvent();
1094 1094
1095 // TOUCH_ACTION_NONE should disable the timeout. 1095 // TOUCH_ACTION_NONE should disable the timeout.
(...skipping 11 matching lines...) Expand all
1107 1107
1108 // Start another touch sequence. While this does restore the touch timeout 1108 // Start another touch sequence. While this does restore the touch timeout
1109 // the timeout will not apply until the *next* touch sequence. This affords a 1109 // the timeout will not apply until the *next* touch sequence. This affords a
1110 // touch-action response from the renderer without racing against the timeout. 1110 // touch-action response from the renderer without racing against the timeout.
1111 PressTouchPoint(1, 1); 1111 PressTouchPoint(1, 1);
1112 SendTouchEvent(); 1112 SendTouchEvent();
1113 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1113 EXPECT_TRUE(TouchEventTimeoutEnabled());
1114 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1114 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1115 1115
1116 // Delay the ack. The timeout should *not* fire. 1116 // Delay the ack. The timeout should *not* fire.
1117 Wait(base::TimeDelta::FromMilliseconds(15)); 1117 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2));
1118 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1118 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1119 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1119 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1120 1120
1121 // Finally send the ack. The touch sequence should not have been cancelled. 1121 // Finally send the ack. The touch sequence should not have been cancelled.
1122 SendInputEventACK(WebInputEvent::TouchStart, 1122 SendInputEventACK(WebInputEvent::TouchStart,
1123 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 1123 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1124 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1124 EXPECT_TRUE(TouchEventTimeoutEnabled());
1125 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1125 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1126 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); 1126 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1127 1127
1128 // End the sequence. 1128 // End the sequence.
1129 ReleaseTouchPoint(0); 1129 ReleaseTouchPoint(0);
1130 SendTouchEvent(); 1130 SendTouchEvent();
1131 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); 1131 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
1132 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1132 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1133 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1133 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1134 1134
1135 // A new touch sequence should (finally) be subject to the timeout. 1135 // A new touch sequence should (finally) be subject to the timeout.
1136 PressTouchPoint(1, 1); 1136 PressTouchPoint(1, 1);
1137 SendTouchEvent(); 1137 SendTouchEvent();
1138 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1138 EXPECT_TRUE(TouchEventTimeoutEnabled());
1139 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); 1139 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1140 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); 1140 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1141 1141
1142 // Wait for the touch ack timeout to fire. 1142 // Wait for the touch ack timeout to fire.
1143 Wait(base::TimeDelta::FromMilliseconds(15)); 1143 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2));
1144 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); 1144 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1145 } 1145 }
1146 1146
1147 // Test that TouchActionFilter::ResetTouchAction is called before the 1147 // Test that TouchActionFilter::ResetTouchAction is called before the
1148 // first touch event for a touch sequence reaches the renderer. 1148 // first touch event for a touch sequence reaches the renderer.
1149 TEST_F(InputRouterImplTest, ResetTouchActionBeforeEventReachesRenderer) { 1149 TEST_F(InputRouterImplTest, ResetTouchActionBeforeEventReachesRenderer) {
1150 OnHasTouchEventHandlers(true); 1150 OnHasTouchEventHandlers(true);
1151 1151
1152 // Sequence 1. 1152 // Sequence 1.
1153 PressTouchPoint(1, 1); 1153 PressTouchPoint(1, 1);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 // dispatched, because the first tap occured when the touch-action was none. 1291 // dispatched, because the first tap occured when the touch-action was none.
1292 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, 1292 SimulateGestureEvent(WebInputEvent::GestureDoubleTap,
1293 WebGestureEvent::Touchscreen); 1293 WebGestureEvent::Touchscreen);
1294 // This test will become invalid if GestureDoubleTap stops requiring an ack. 1294 // This test will become invalid if GestureDoubleTap stops requiring an ack.
1295 DCHECK(!WebInputEventTraits::IgnoresAckDisposition( 1295 DCHECK(!WebInputEventTraits::IgnoresAckDisposition(
1296 WebInputEvent::GestureDoubleTap)); 1296 WebInputEvent::GestureDoubleTap));
1297 EXPECT_EQ(0, client_->in_flight_event_count()); 1297 EXPECT_EQ(0, client_->in_flight_event_count());
1298 } 1298 }
1299 1299
1300 } // namespace content 1300 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/input_router_impl.cc ('k') | content/browser/renderer_host/input/touch_event_queue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698