| 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 "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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // testing::Test | 117 // testing::Test |
| 118 virtual void SetUp() OVERRIDE { | 118 virtual void SetUp() OVERRIDE { |
| 119 browser_context_.reset(new TestBrowserContext()); | 119 browser_context_.reset(new TestBrowserContext()); |
| 120 process_.reset(new MockRenderProcessHost(browser_context_.get())); | 120 process_.reset(new MockRenderProcessHost(browser_context_.get())); |
| 121 client_.reset(new MockInputRouterClient()); | 121 client_.reset(new MockInputRouterClient()); |
| 122 ack_handler_.reset(new MockInputAckHandler()); | 122 ack_handler_.reset(new MockInputAckHandler()); |
| 123 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 123 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 124 command_line->AppendSwitch(switches::kValidateInputEventStream); | 124 command_line->AppendSwitch(switches::kValidateInputEventStream); |
| 125 input_router_.reset(new InputRouterImpl( | 125 input_router_.reset(new InputRouterImpl( |
| 126 process_.get(), client_.get(), ack_handler_.get(), MSG_ROUTING_NONE)); | 126 process_.get(), client_.get(), ack_handler_.get(), MSG_ROUTING_NONE)); |
| 127 input_router_->gesture_event_queue_->set_debounce_enabled_for_testing( | 127 input_router_->gesture_event_queue_.set_debounce_enabled_for_testing( |
| 128 false); | 128 false); |
| 129 client_->set_input_router(input_router()); | 129 client_->set_input_router(input_router()); |
| 130 ack_handler_->set_input_router(input_router()); | 130 ack_handler_->set_input_router(input_router()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 virtual void TearDown() OVERRIDE { | 133 virtual void TearDown() OVERRIDE { |
| 134 // Process all pending tasks to avoid leaks. | 134 // Process all pending tasks to avoid leaks. |
| 135 base::MessageLoop::current()->RunUntilIdle(); | 135 base::MessageLoop::current()->RunUntilIdle(); |
| 136 | 136 |
| 137 input_router_.reset(); | 137 input_router_.reset(); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 new InputHostMsg_HandleInputEvent_ACK(0, type, ack_result, | 258 new InputHostMsg_HandleInputEvent_ACK(0, type, ack_result, |
| 259 ui::LatencyInfo())); | 259 ui::LatencyInfo())); |
| 260 input_router_->OnMessageReceived(*response); | 260 input_router_->OnMessageReceived(*response); |
| 261 } | 261 } |
| 262 | 262 |
| 263 InputRouterImpl* input_router() const { | 263 InputRouterImpl* input_router() const { |
| 264 return input_router_.get(); | 264 return input_router_.get(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 bool TouchEventQueueEmpty() const { | 267 bool TouchEventQueueEmpty() const { |
| 268 return input_router()->touch_event_queue_->empty(); | 268 return input_router()->touch_event_queue_.empty(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 bool TouchEventTimeoutEnabled() const { | 271 bool TouchEventTimeoutEnabled() const { |
| 272 return input_router()->touch_event_queue_->ack_timeout_enabled(); | 272 return input_router()->touch_event_queue_.ack_timeout_enabled(); |
| 273 } |
| 274 |
| 275 void Flush() const { |
| 276 return input_router_->Flush(); |
| 277 } |
| 278 |
| 279 size_t GetAndResetDidFlushCount() { |
| 280 return client_->GetAndResetDidFlushCount(); |
| 281 } |
| 282 |
| 283 bool HasPendingEvents() const { |
| 284 return input_router_->HasPendingEvents(); |
| 273 } | 285 } |
| 274 | 286 |
| 275 void OnHasTouchEventHandlers(bool has_handlers) { | 287 void OnHasTouchEventHandlers(bool has_handlers) { |
| 276 input_router_->OnMessageReceived( | 288 input_router_->OnMessageReceived( |
| 277 ViewHostMsg_HasTouchEventHandlers(0, has_handlers)); | 289 ViewHostMsg_HasTouchEventHandlers(0, has_handlers)); |
| 278 } | 290 } |
| 279 | 291 |
| 280 void OnSetTouchAction(content::TouchAction touch_action) { | 292 void OnSetTouchAction(content::TouchAction touch_action) { |
| 281 input_router_->OnMessageReceived( | 293 input_router_->OnMessageReceived( |
| 282 InputHostMsg_SetTouchAction(0, touch_action)); | 294 InputHostMsg_SetTouchAction(0, touch_action)); |
| (...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 INPUT_EVENT_ACK_STATE_CONSUMED); | 753 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 742 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); | 754 ASSERT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 743 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 755 ASSERT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 744 ASSERT_EQ(0, client_->in_flight_event_count()); | 756 ASSERT_EQ(0, client_->in_flight_event_count()); |
| 745 } | 757 } |
| 746 | 758 |
| 747 SimulateTouchEvent(type); | 759 SimulateTouchEvent(type); |
| 748 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 760 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 749 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 761 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 750 EXPECT_EQ(0, client_->in_flight_event_count()); | 762 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 763 EXPECT_FALSE(HasPendingEvents()); |
| 751 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 764 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 752 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 765 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 753 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 766 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 767 EXPECT_FALSE(HasPendingEvents()); |
| 754 } | 768 } |
| 755 } | 769 } |
| 756 | 770 |
| 757 TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) { | 771 TEST_F(InputRouterImplTest, GestureTypesIgnoringAck) { |
| 758 // We test every gesture type, ensuring that the stream of gestures is valid. | 772 // We test every gesture type, ensuring that the stream of gestures is valid. |
| 759 const int kEventTypesLength = 29; | 773 const int kEventTypesLength = 29; |
| 760 WebInputEvent::Type eventTypes[kEventTypesLength] = { | 774 WebInputEvent::Type eventTypes[kEventTypesLength] = { |
| 761 WebInputEvent::GestureTapDown, | 775 WebInputEvent::GestureTapDown, |
| 762 WebInputEvent::GestureShowPress, | 776 WebInputEvent::GestureShowPress, |
| 763 WebInputEvent::GestureTapCancel, | 777 WebInputEvent::GestureTapCancel, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 787 WebInputEvent::GesturePinchUpdate, | 801 WebInputEvent::GesturePinchUpdate, |
| 788 WebInputEvent::GesturePinchEnd, | 802 WebInputEvent::GesturePinchEnd, |
| 789 WebInputEvent::GestureScrollEnd}; | 803 WebInputEvent::GestureScrollEnd}; |
| 790 for (int i = 0; i < kEventTypesLength; ++i) { | 804 for (int i = 0; i < kEventTypesLength; ++i) { |
| 791 WebInputEvent::Type type = eventTypes[i]; | 805 WebInputEvent::Type type = eventTypes[i]; |
| 792 if (!WebInputEventTraits::IgnoresAckDisposition(type)) { | 806 if (!WebInputEventTraits::IgnoresAckDisposition(type)) { |
| 793 SimulateGestureEvent(type, WebGestureEvent::Touchscreen); | 807 SimulateGestureEvent(type, WebGestureEvent::Touchscreen); |
| 794 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 808 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 795 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 809 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 796 EXPECT_EQ(1, client_->in_flight_event_count()); | 810 EXPECT_EQ(1, client_->in_flight_event_count()); |
| 811 EXPECT_TRUE(HasPendingEvents()); |
| 797 | 812 |
| 798 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 813 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 799 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 814 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 800 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 815 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 801 EXPECT_EQ(0, client_->in_flight_event_count()); | 816 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 817 EXPECT_FALSE(HasPendingEvents()); |
| 802 continue; | 818 continue; |
| 803 } | 819 } |
| 804 | 820 |
| 805 SimulateGestureEvent(type, WebGestureEvent::Touchscreen); | 821 SimulateGestureEvent(type, WebGestureEvent::Touchscreen); |
| 806 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 822 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
| 807 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 823 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 808 EXPECT_EQ(0, client_->in_flight_event_count()); | 824 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 825 EXPECT_FALSE(HasPendingEvents()); |
| 809 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); | 826 SendInputEventACK(type, INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 810 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 827 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 811 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); | 828 EXPECT_EQ(0U, ack_handler_->GetAndResetAckCount()); |
| 829 EXPECT_FALSE(HasPendingEvents()); |
| 812 } | 830 } |
| 813 } | 831 } |
| 814 | 832 |
| 815 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { | 833 TEST_F(InputRouterImplTest, MouseTypesIgnoringAck) { |
| 816 int start_type = static_cast<int>(WebInputEvent::MouseDown); | 834 int start_type = static_cast<int>(WebInputEvent::MouseDown); |
| 817 int end_type = static_cast<int>(WebInputEvent::ContextMenu); | 835 int end_type = static_cast<int>(WebInputEvent::ContextMenu); |
| 818 ASSERT_LT(start_type, end_type); | 836 ASSERT_LT(start_type, end_type); |
| 819 for (int i = start_type; i <= end_type; ++i) { | 837 for (int i = start_type; i <= end_type; ++i) { |
| 820 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); | 838 WebInputEvent::Type type = static_cast<WebInputEvent::Type>(i); |
| 821 int expected_in_flight_event_count = | 839 int expected_in_flight_event_count = |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 // Although the touch-action is now auto, the double tap still won't be | 1310 // Although the touch-action is now auto, the double tap still won't be |
| 1293 // dispatched, because the first tap occured when the touch-action was none. | 1311 // dispatched, because the first tap occured when the touch-action was none. |
| 1294 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, | 1312 SimulateGestureEvent(WebInputEvent::GestureDoubleTap, |
| 1295 WebGestureEvent::Touchscreen); | 1313 WebGestureEvent::Touchscreen); |
| 1296 // This test will become invalid if GestureDoubleTap stops requiring an ack. | 1314 // This test will become invalid if GestureDoubleTap stops requiring an ack. |
| 1297 DCHECK(!WebInputEventTraits::IgnoresAckDisposition( | 1315 DCHECK(!WebInputEventTraits::IgnoresAckDisposition( |
| 1298 WebInputEvent::GestureDoubleTap)); | 1316 WebInputEvent::GestureDoubleTap)); |
| 1299 EXPECT_EQ(0, client_->in_flight_event_count()); | 1317 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1300 } | 1318 } |
| 1301 | 1319 |
| 1320 // Test that the router will call the client's |DidFlush| after all events have |
| 1321 // been dispatched following a call to |Flush|. |
| 1322 TEST_F(InputRouterImplTest, InputFlush) { |
| 1323 EXPECT_FALSE(HasPendingEvents()); |
| 1324 |
| 1325 // Flushing an empty router should immediately trigger DidFlush. |
| 1326 Flush(); |
| 1327 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1328 EXPECT_FALSE(HasPendingEvents()); |
| 1329 |
| 1330 // Queue a TouchStart. |
| 1331 OnHasTouchEventHandlers(true); |
| 1332 PressTouchPoint(1, 1); |
| 1333 SendTouchEvent(); |
| 1334 EXPECT_TRUE(HasPendingEvents()); |
| 1335 |
| 1336 // DidFlush should be called only after the event is ack'ed. |
| 1337 Flush(); |
| 1338 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1339 SendInputEventACK(WebInputEvent::TouchStart, |
| 1340 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1341 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1342 |
| 1343 // Ensure different types of enqueued events will prevent the DidFlush call |
| 1344 // until all such events have been fully dispatched. |
| 1345 MoveTouchPoint(0, 50, 50); |
| 1346 SendTouchEvent(); |
| 1347 ASSERT_TRUE(HasPendingEvents()); |
| 1348 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, |
| 1349 WebGestureEvent::Touchscreen); |
| 1350 SimulateGestureEvent(WebInputEvent::GestureScrollUpdate, |
| 1351 WebGestureEvent::Touchscreen); |
| 1352 Flush(); |
| 1353 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1354 |
| 1355 // Repeated flush calls should have no effect. |
| 1356 Flush(); |
| 1357 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1358 |
| 1359 // There are still pending gestures. |
| 1360 SendInputEventACK(WebInputEvent::TouchMove, |
| 1361 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1362 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1363 EXPECT_TRUE(HasPendingEvents()); |
| 1364 |
| 1365 // One more gesture to go. |
| 1366 SendInputEventACK(WebInputEvent::GestureScrollBegin, |
| 1367 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1368 EXPECT_EQ(0U, GetAndResetDidFlushCount()); |
| 1369 EXPECT_TRUE(HasPendingEvents()); |
| 1370 |
| 1371 // The final ack'ed gesture should trigger the DidFlush. |
| 1372 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 1373 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1374 EXPECT_EQ(1U, GetAndResetDidFlushCount()); |
| 1375 EXPECT_FALSE(HasPendingEvents()); |
| 1376 } |
| 1377 |
| 1302 // Test that GesturePinchUpdate is handled specially for trackpad | 1378 // Test that GesturePinchUpdate is handled specially for trackpad |
| 1303 TEST_F(InputRouterImplTest, TrackpadPinchUpdate) { | 1379 TEST_F(InputRouterImplTest, TrackpadPinchUpdate) { |
| 1304 // For now Trackpad PinchUpdate events are just immediately ACKed | 1380 // For now Trackpad PinchUpdate events are just immediately ACKed |
| 1305 // as unconsumed without going to the renderer. | 1381 // as unconsumed without going to the renderer. |
| 1306 // TODO(rbyers): Update for wheel event behavior - crbug.com/289887. | 1382 // TODO(rbyers): Update for wheel event behavior - crbug.com/289887. |
| 1307 // Note that the Touchscreen case is verified as NOT doing this as | 1383 // Note that the Touchscreen case is verified as NOT doing this as |
| 1308 // part of the ShowPressIsInOrder test. | 1384 // part of the ShowPressIsInOrder test. |
| 1309 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, | 1385 SimulateGestureEvent(WebInputEvent::GesturePinchUpdate, |
| 1310 WebGestureEvent::Touchpad); | 1386 WebGestureEvent::Touchpad); |
| 1311 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); | 1387 ASSERT_EQ(0U, GetSentMessageCountAndResetSink()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 | 1432 |
| 1357 // Ack the second scroll. | 1433 // Ack the second scroll. |
| 1358 SendInputEventACK(WebInputEvent::GestureScrollUpdate, | 1434 SendInputEventACK(WebInputEvent::GestureScrollUpdate, |
| 1359 INPUT_EVENT_ACK_STATE_CONSUMED); | 1435 INPUT_EVENT_ACK_STATE_CONSUMED); |
| 1360 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 1436 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
| 1361 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); | 1437 EXPECT_EQ(1U, ack_handler_->GetAndResetAckCount()); |
| 1362 EXPECT_EQ(0, client_->in_flight_event_count()); | 1438 EXPECT_EQ(0, client_->in_flight_event_count()); |
| 1363 } | 1439 } |
| 1364 | 1440 |
| 1365 } // namespace content | 1441 } // namespace content |
| OLD | NEW |