OLD | NEW |
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 <math.h> | 5 #include <math.h> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 145 |
146 protected: | 146 protected: |
147 // testing::Test | 147 // testing::Test |
148 virtual void SetUp() OVERRIDE { | 148 virtual void SetUp() OVERRIDE { |
149 browser_context_.reset(new TestBrowserContext()); | 149 browser_context_.reset(new TestBrowserContext()); |
150 process_.reset(new MockRenderProcessHost(browser_context_.get())); | 150 process_.reset(new MockRenderProcessHost(browser_context_.get())); |
151 client_.reset(new MockInputRouterClient()); | 151 client_.reset(new MockInputRouterClient()); |
152 ack_handler_.reset(new MockInputAckHandler()); | 152 ack_handler_.reset(new MockInputAckHandler()); |
153 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 153 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
154 command_line->AppendSwitch(switches::kValidateInputEventStream); | 154 command_line->AppendSwitch(switches::kValidateInputEventStream); |
155 input_router_.reset(new InputRouterImpl( | 155 input_router_.reset(new InputRouterImpl(process_.get(), |
156 process_.get(), client_.get(), ack_handler_.get(), MSG_ROUTING_NONE)); | 156 client_.get(), |
157 input_router_->gesture_event_queue_.set_debounce_enabled_for_testing( | 157 ack_handler_.get(), |
158 false); | 158 MSG_ROUTING_NONE, |
| 159 config_)); |
159 client_->set_input_router(input_router()); | 160 client_->set_input_router(input_router()); |
160 ack_handler_->set_input_router(input_router()); | 161 ack_handler_->set_input_router(input_router()); |
161 } | 162 } |
162 | 163 |
163 virtual void TearDown() OVERRIDE { | 164 virtual void TearDown() OVERRIDE { |
164 // Process all pending tasks to avoid leaks. | 165 // Process all pending tasks to avoid leaks. |
165 base::MessageLoop::current()->RunUntilIdle(); | 166 base::MessageLoop::current()->RunUntilIdle(); |
166 | 167 |
167 input_router_.reset(); | 168 input_router_.reset(); |
168 client_.reset(); | 169 client_.reset(); |
169 process_.reset(); | 170 process_.reset(); |
170 browser_context_.reset(); | 171 browser_context_.reset(); |
171 } | 172 } |
172 | 173 |
| 174 void SetUpForTouchAckTimeoutTest(int timeout_ms) { |
| 175 config_.touch_config.touch_ack_timeout_delay = |
| 176 base::TimeDelta::FromMilliseconds(timeout_ms); |
| 177 config_.touch_config.touch_ack_timeout_supported = true; |
| 178 TearDown(); |
| 179 SetUp(); |
| 180 } |
| 181 |
173 void SimulateKeyboardEvent(WebInputEvent::Type type, bool is_shortcut) { | 182 void SimulateKeyboardEvent(WebInputEvent::Type type, bool is_shortcut) { |
174 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type); | 183 WebKeyboardEvent event = SyntheticWebKeyboardEventBuilder::Build(type); |
175 NativeWebKeyboardEvent native_event; | 184 NativeWebKeyboardEvent native_event; |
176 memcpy(&native_event, &event, sizeof(event)); | 185 memcpy(&native_event, &event, sizeof(event)); |
177 input_router_->SendKeyboardEvent( | 186 input_router_->SendKeyboardEvent( |
178 native_event, | 187 native_event, |
179 ui::LatencyInfo(), | 188 ui::LatencyInfo(), |
180 is_shortcut); | 189 is_shortcut); |
181 } | 190 } |
182 | 191 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 process_->sink().ClearMessages(); | 338 process_->sink().ClearMessages(); |
330 return count; | 339 return count; |
331 } | 340 } |
332 | 341 |
333 static void RunTasksAndWait(base::TimeDelta delay) { | 342 static void RunTasksAndWait(base::TimeDelta delay) { |
334 base::MessageLoop::current()->PostDelayedTask( | 343 base::MessageLoop::current()->PostDelayedTask( |
335 FROM_HERE, base::MessageLoop::QuitClosure(), delay); | 344 FROM_HERE, base::MessageLoop::QuitClosure(), delay); |
336 base::MessageLoop::current()->Run(); | 345 base::MessageLoop::current()->Run(); |
337 } | 346 } |
338 | 347 |
| 348 InputRouterImpl::Config config_; |
339 scoped_ptr<MockRenderProcessHost> process_; | 349 scoped_ptr<MockRenderProcessHost> process_; |
340 scoped_ptr<MockInputRouterClient> client_; | 350 scoped_ptr<MockInputRouterClient> client_; |
341 scoped_ptr<MockInputAckHandler> ack_handler_; | 351 scoped_ptr<MockInputAckHandler> ack_handler_; |
342 scoped_ptr<InputRouterImpl> input_router_; | 352 scoped_ptr<InputRouterImpl> input_router_; |
343 | 353 |
344 private: | 354 private: |
345 base::MessageLoopForUI message_loop_; | 355 base::MessageLoopForUI message_loop_; |
346 SyntheticWebTouchEvent touch_event_; | 356 SyntheticWebTouchEvent touch_event_; |
347 | 357 |
348 scoped_ptr<TestBrowserContext> browser_context_; | 358 scoped_ptr<TestBrowserContext> browser_context_; |
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1020 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1030 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
1021 | 1031 |
1022 SendInputEventACK(WebInputEvent::GesturePinchUpdate, | 1032 SendInputEventACK(WebInputEvent::GesturePinchUpdate, |
1023 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1033 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1024 // Now that the Tap has been ACKed, the ShowPress events should receive | 1034 // Now that the Tap has been ACKed, the ShowPress events should receive |
1025 // synthetic acks, and fire immediately. | 1035 // synthetic acks, and fire immediately. |
1026 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); | 1036 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); |
1027 EXPECT_EQ(3U, ack_handler_->GetAndResetAckCount()); | 1037 EXPECT_EQ(3U, ack_handler_->GetAndResetAckCount()); |
1028 } | 1038 } |
1029 | 1039 |
1030 // Test that touch ack timeout behavior is properly configured via the command | 1040 // Test that touch ack timeout behavior is properly toggled by view update flags |
1031 // line, and toggled by view update flags and allowed touch actions. | 1041 // and allowed touch actions. |
1032 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) { | 1042 TEST_F(InputRouterImplTest, TouchAckTimeoutConfigured) { |
1033 // Unless explicitly supported via the command-line, the touch timeout should | 1043 const int timeout_ms = 1; |
1034 // be disabled. | 1044 SetUpForTouchAckTimeoutTest(timeout_ms); |
1035 EXPECT_FALSE(TouchEventTimeoutEnabled()); | |
1036 | |
1037 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
1038 switches::kTouchAckTimeoutDelayMs, "1"); | |
1039 TearDown(); | |
1040 SetUp(); | |
1041 ASSERT_TRUE(TouchEventTimeoutEnabled()); | 1045 ASSERT_TRUE(TouchEventTimeoutEnabled()); |
1042 | 1046 |
1043 // Verify that the touch ack timeout fires upon the delayed ack. | 1047 // Verify that the touch ack timeout fires upon the delayed ack. |
1044 PressTouchPoint(1, 1); | 1048 PressTouchPoint(1, 1); |
1045 SendTouchEvent(); | 1049 SendTouchEvent(); |
1046 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1050 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
1047 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1051 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
1048 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2)); | 1052 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); |
1049 | 1053 |
1050 // The timed-out event should have been ack'ed. | 1054 // The timed-out event should have been ack'ed. |
1051 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1055 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
1052 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1056 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
1053 | 1057 |
1054 // Ack'ing the timed-out event should fire a TouchCancel. | 1058 // Ack'ing the timed-out event should fire a TouchCancel. |
1055 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1059 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
1056 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1060 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
1057 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1061 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
1058 | 1062 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1104 // should be restored. | 1108 // should be restored. |
1105 PressTouchPoint(1, 1); | 1109 PressTouchPoint(1, 1); |
1106 SendTouchEvent(); | 1110 SendTouchEvent(); |
1107 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1111 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
1108 } | 1112 } |
1109 | 1113 |
1110 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by | 1114 // Test that a touch sequenced preceded by TOUCH_ACTION_NONE is not affected by |
1111 // the touch timeout. | 1115 // the touch timeout. |
1112 TEST_F(InputRouterImplTest, | 1116 TEST_F(InputRouterImplTest, |
1113 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) { | 1117 TouchAckTimeoutDisabledForTouchSequenceAfterTouchActionNone) { |
1114 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 1118 const int timeout_ms = 1; |
1115 switches::kTouchAckTimeoutDelayMs, "1"); | 1119 SetUpForTouchAckTimeoutTest(timeout_ms); |
1116 TearDown(); | |
1117 SetUp(); | |
1118 ASSERT_TRUE(TouchEventTimeoutEnabled()); | 1120 ASSERT_TRUE(TouchEventTimeoutEnabled()); |
1119 OnHasTouchEventHandlers(true); | 1121 OnHasTouchEventHandlers(true); |
1120 | 1122 |
1121 // Start a touch sequence. | 1123 // Start a touch sequence. |
1122 PressTouchPoint(1, 1); | 1124 PressTouchPoint(1, 1); |
1123 SendTouchEvent(); | 1125 SendTouchEvent(); |
1124 | 1126 |
1125 // TOUCH_ACTION_NONE should disable the timeout. | 1127 // TOUCH_ACTION_NONE should disable the timeout. |
1126 OnSetTouchAction(TOUCH_ACTION_NONE); | 1128 OnSetTouchAction(TOUCH_ACTION_NONE); |
1127 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 1129 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
1128 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 1130 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
1129 | 1131 |
1130 // End the touch sequence. | 1132 // End the touch sequence. |
1131 ReleaseTouchPoint(0); | 1133 ReleaseTouchPoint(0); |
1132 SendTouchEvent(); | 1134 SendTouchEvent(); |
1133 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1135 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); |
1134 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 1136 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
1135 ack_handler_->GetAndResetAckCount(); | 1137 ack_handler_->GetAndResetAckCount(); |
1136 GetSentMessageCountAndResetSink(); | 1138 GetSentMessageCountAndResetSink(); |
1137 | 1139 |
1138 // Start another touch sequence. While this does restore the touch timeout | 1140 // Start another touch sequence. While this does restore the touch timeout |
1139 // the timeout will not apply until the *next* touch sequence. This affords a | 1141 // the timeout will not apply until the *next* touch sequence. This affords a |
1140 // touch-action response from the renderer without racing against the timeout. | 1142 // touch-action response from the renderer without racing against the timeout. |
1141 PressTouchPoint(1, 1); | 1143 PressTouchPoint(1, 1); |
1142 SendTouchEvent(); | 1144 SendTouchEvent(); |
1143 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1145 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
1144 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1146 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
1145 | 1147 |
1146 // Delay the ack. The timeout should *not* fire. | 1148 // Delay the ack. The timeout should *not* fire. |
1147 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2)); | 1149 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); |
1148 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1150 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
1149 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1151 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
1150 | 1152 |
1151 // Finally send the ack. The touch sequence should not have been cancelled. | 1153 // Finally send the ack. The touch sequence should not have been cancelled. |
1152 SendInputEventACK(WebInputEvent::TouchStart, | 1154 SendInputEventACK(WebInputEvent::TouchStart, |
1153 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 1155 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
1154 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1156 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
1155 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1157 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
1156 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1158 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
1157 | 1159 |
1158 // End the sequence. | 1160 // End the sequence. |
1159 ReleaseTouchPoint(0); | 1161 ReleaseTouchPoint(0); |
1160 SendTouchEvent(); | 1162 SendTouchEvent(); |
1161 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | 1163 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); |
1162 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1164 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
1163 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1165 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
1164 | 1166 |
1165 // A new touch sequence should (finally) be subject to the timeout. | 1167 // A new touch sequence should (finally) be subject to the timeout. |
1166 PressTouchPoint(1, 1); | 1168 PressTouchPoint(1, 1); |
1167 SendTouchEvent(); | 1169 SendTouchEvent(); |
1168 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 1170 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
1169 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 1171 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
1170 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 1172 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
1171 | 1173 |
1172 // Wait for the touch ack timeout to fire. | 1174 // Wait for the touch ack timeout to fire. |
1173 RunTasksAndWait(base::TimeDelta::FromMilliseconds(2)); | 1175 RunTasksAndWait(base::TimeDelta::FromMilliseconds(timeout_ms + 1)); |
1174 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1176 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
1175 } | 1177 } |
1176 | 1178 |
1177 // Test that TouchActionFilter::ResetTouchAction is called before the | 1179 // Test that TouchActionFilter::ResetTouchAction is called before the |
1178 // first touch event for a touch sequence reaches the renderer. | 1180 // first touch event for a touch sequence reaches the renderer. |
1179 TEST_F(InputRouterImplTest, ResetTouchActionBeforeEventReachesRenderer) { | 1181 TEST_F(InputRouterImplTest, ResetTouchActionBeforeEventReachesRenderer) { |
1180 OnHasTouchEventHandlers(true); | 1182 OnHasTouchEventHandlers(true); |
1181 | 1183 |
1182 // Sequence 1. | 1184 // Sequence 1. |
1183 PressTouchPoint(1, 1); | 1185 PressTouchPoint(1, 1); |
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 EXPECT_EQ(1, client_->in_flight_event_count()); | 1647 EXPECT_EQ(1, client_->in_flight_event_count()); |
1646 | 1648 |
1647 // Ack the wheel event. | 1649 // Ack the wheel event. |
1648 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); | 1650 SendInputEventACK(WebInputEvent::MouseWheel, INPUT_EVENT_ACK_STATE_CONSUMED); |
1649 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1651 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
1650 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1652 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
1651 EXPECT_EQ(0, client_->in_flight_event_count()); | 1653 EXPECT_EQ(0, client_->in_flight_event_count()); |
1652 } | 1654 } |
1653 | 1655 |
1654 } // namespace content | 1656 } // namespace content |
OLD | NEW |