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

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

Issue 183923034: Disable the touch ack timeout for touch-action:none (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final cleanup pass 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) {
292 base::MessageLoop::current()->PostDelayedTask(
293 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
294 base::MessageLoop::current()->Run();
295 }
296
291 scoped_ptr<MockRenderProcessHost> process_; 297 scoped_ptr<MockRenderProcessHost> process_;
292 scoped_ptr<MockInputRouterClient> client_; 298 scoped_ptr<MockInputRouterClient> client_;
293 scoped_ptr<MockInputAckHandler> ack_handler_; 299 scoped_ptr<MockInputAckHandler> ack_handler_;
294 scoped_ptr<InputRouterImpl> input_router_; 300 scoped_ptr<InputRouterImpl> input_router_;
295 301
296 private: 302 private:
297 base::MessageLoopForUI message_loop_; 303 base::MessageLoopForUI message_loop_;
298 SyntheticWebTouchEvent touch_event_; 304 SyntheticWebTouchEvent touch_event_;
299 305
300 scoped_ptr<TestBrowserContext> browser_context_; 306 scoped_ptr<TestBrowserContext> browser_context_;
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 991
986 SendInputEventACK(WebInputEvent::GesturePinchUpdate, 992 SendInputEventACK(WebInputEvent::GesturePinchUpdate,
987 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); 993 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
988 // Now that the Tap has been ACKed, the ShowPress events should receive 994 // Now that the Tap has been ACKed, the ShowPress events should receive
989 // synthetic acks, and fire immediately. 995 // synthetic acks, and fire immediately.
990 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); 996 EXPECT_EQ(2U, GetSentMessageCountAndResetSink());
991 EXPECT_EQ(3U, ack_handler_->GetAndResetAckCount()); 997 EXPECT_EQ(3U, ack_handler_->GetAndResetAckCount());
992 } 998 }
993 999
994 // 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
995 // line, and toggled by the view update flags. 1001 // line, and toggled by view update flags and allowed touch actions.
996 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) { 1002 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) {
1003 // Unless explicitly supported via the command-line, the touch timeout should
1004 // be disabled.
1005 EXPECT_FALSE(TouchEventTimeoutEnabled());
1006
997 CommandLine::ForCurrentProcess()->AppendSwitchASCII( 1007 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
998 switches::kTouchAckTimeoutDelayMs, "5"); 1008 switches::kTouchAckTimeoutDelayMs, "5");
999 TearDown(); 1009 TearDown();
1000 SetUp(); 1010 SetUp();
1001 ASSERT_TRUE(TouchEventTimeoutEnabled()); 1011 ASSERT_TRUE(TouchEventTimeoutEnabled());
1002 1012
1013 // Verify that the touch ack timeout fires upon the delayed ack.
1014 PressTouchPoint(1, 1);
1015 SendTouchEvent();
1016 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1017 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1018 Wait(base::TimeDelta::FromMilliseconds(15));
1019
1020 // The timed-out event should have been ack'ed.
1021 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1022 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1023
1024 // Ack'ing the timed-out event should fire a TouchCancel.
1025 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
1026 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1027 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1028
1029 // The remainder of the touch sequence should be dropped.
1030 ReleaseTouchPoint(0);
1031 SendTouchEvent();
1032 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1033 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1034 ASSERT_TRUE(TouchEventTimeoutEnabled());
1035
1003 // A fixed page scale or mobile viewport should disable the touch timeout. 1036 // A fixed page scale or mobile viewport should disable the touch timeout.
1004 input_router()->OnViewUpdated(InputRouter::FIXED_PAGE_SCALE); 1037 input_router()->OnViewUpdated(InputRouter::FIXED_PAGE_SCALE);
1005 EXPECT_FALSE(TouchEventTimeoutEnabled()); 1038 EXPECT_FALSE(TouchEventTimeoutEnabled());
1006 1039
1007 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE); 1040 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE);
1008 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1041 EXPECT_TRUE(TouchEventTimeoutEnabled());
1009 1042
1010 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT); 1043 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT);
1011 EXPECT_FALSE(TouchEventTimeoutEnabled()); 1044 EXPECT_FALSE(TouchEventTimeoutEnabled());
1012 1045
1013 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT | 1046 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT |
1014 InputRouter::FIXED_PAGE_SCALE); 1047 InputRouter::FIXED_PAGE_SCALE);
1015 EXPECT_FALSE(TouchEventTimeoutEnabled()); 1048 EXPECT_FALSE(TouchEventTimeoutEnabled());
1016 1049
1017 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE); 1050 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE);
1018 EXPECT_TRUE(TouchEventTimeoutEnabled()); 1051 EXPECT_TRUE(TouchEventTimeoutEnabled());
1052
1053 // TOUCH_ACTION_NONE (and no other touch-action) should disable the timeout.
1054 OnHasTouchEventHandlers(true);
1055 PressTouchPoint(1, 1);
1056 SendTouchEvent();
1057 OnSetTouchAction(TOUCH_ACTION_PAN_Y);
1058 EXPECT_TRUE(TouchEventTimeoutEnabled());
1059 ReleaseTouchPoint(0);
1060 SendTouchEvent();
1061 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
1062 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
1063
1064 PressTouchPoint(1, 1);
1065 SendTouchEvent();
1066 OnSetTouchAction(TOUCH_ACTION_NONE);
1067 EXPECT_FALSE(TouchEventTimeoutEnabled());
1068 ReleaseTouchPoint(0);
1069 SendTouchEvent();
1070 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
1071 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
1072
1073 // As the touch-action is reset by a new touch sequence, the timeout behavior
1074 // should be restored.
1075 PressTouchPoint(1, 1);
1076 SendTouchEvent();
1077 EXPECT_TRUE(TouchEventTimeoutEnabled());
1078 }
1079
1080 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by
1081 // the touch timeout.
1082 TEST_F(InputRouterImplTest,
1083 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) {
1084 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
1085 switches::kTouchAckTimeoutDelayMs, "5");
1086 TearDown();
1087 SetUp();
1088 ASSERT_TRUE(TouchEventTimeoutEnabled());
1089 OnHasTouchEventHandlers(true);
1090
1091 // Start a touch sequence.
1092 PressTouchPoint(1, 1);
1093 SendTouchEvent();
1094
1095 // TOUCH_ACTION_NONE should disable the timeout.
1096 OnSetTouchAction(TOUCH_ACTION_NONE);
1097 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED);
1098 EXPECT_FALSE(TouchEventTimeoutEnabled());
1099
1100 // End the touch sequence.
1101 ReleaseTouchPoint(0);
1102 SendTouchEvent();
1103 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
1104 EXPECT_FALSE(TouchEventTimeoutEnabled());
1105 ack_handler_->GetAndResetAckCount();
1106 GetSentMessageCountAndResetSink();
1107
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
1110 // touch-action response from the renderer without racing against the timeout.
1111 PressTouchPoint(1, 1);
1112 SendTouchEvent();
1113 EXPECT_TRUE(TouchEventTimeoutEnabled());
1114 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1115
1116 // Delay the ack. The timeout should *not* fire.
1117 Wait(base::TimeDelta::FromMilliseconds(15));
1118 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1119 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1120
1121 // Finally send the ack. The touch sequence should not have been cancelled.
1122 SendInputEventACK(WebInputEvent::TouchStart,
1123 INPUT_EVENT_ACK_STATE_NOT_CONSUMED);
1124 EXPECT_TRUE(TouchEventTimeoutEnabled());
1125 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1126 EXPECT_EQ(0U, GetSentMessageCountAndResetSink());
1127
1128 // End the sequence.
1129 ReleaseTouchPoint(0);
1130 SendTouchEvent();
1131 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED);
1132 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1133 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1134
1135 // A new touch sequence should (finally) be subject to the timeout.
1136 PressTouchPoint(1, 1);
1137 SendTouchEvent();
1138 EXPECT_TRUE(TouchEventTimeoutEnabled());
1139 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount());
1140 EXPECT_EQ(1U, GetSentMessageCountAndResetSink());
1141
1142 // Wait for the touch ack timeout to fire.
1143 Wait(base::TimeDelta::FromMilliseconds(15));
1144 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount());
1019 } 1145 }
1020 1146
1021 // Test that TouchActionFilter::ResetTouchAction is called before the 1147 // Test that TouchActionFilter::ResetTouchAction is called before the
1022 // first touch event for a touch sequence reaches the renderer. 1148 // first touch event for a touch sequence reaches the renderer.
1023 TEST_F(InputRouterImplTest, ResetTouchActionBeforeEventReachesRenderer) { 1149 TEST_F(InputRouterImplTest, ResetTouchActionBeforeEventReachesRenderer) {
1024 OnHasTouchEventHandlers(true); 1150 OnHasTouchEventHandlers(true);
1025 1151
1026 // Sequence 1. 1152 // Sequence 1.
1027 PressTouchPoint(1, 1); 1153 PressTouchPoint(1, 1);
1028 SendTouchEvent(); 1154 SendTouchEvent();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 // 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.
1166 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, 1292 SimulateGestureEvent(WebInputEvent::GestureDoubleTap,
1167 WebGestureEvent::Touchscreen); 1293 WebGestureEvent::Touchscreen);
1168 // This test will become invalid if GestureDoubleTap stops requiring an ack. 1294 // This test will become invalid if GestureDoubleTap stops requiring an ack.
1169 DCHECK(!WebInputEventTraits::IgnoresAckDisposition( 1295 DCHECK(!WebInputEventTraits::IgnoresAckDisposition(
1170 WebInputEvent::GestureDoubleTap)); 1296 WebInputEvent::GestureDoubleTap));
1171 EXPECT_EQ(0, client_->in_flight_event_count()); 1297 EXPECT_EQ(0, client_->in_flight_event_count());
1172 } 1298 }
1173 1299
1174 } // 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_action_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698