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" |
11 #include "content/browser/renderer_host/input/input_router_impl.h" | 11 #include "content/browser/renderer_host/input/input_router_impl.h" |
12 #include "content/browser/renderer_host/input/mock_input_ack_handler.h" | 12 #include "content/browser/renderer_host/input/mock_input_ack_handler.h" |
13 #include "content/browser/renderer_host/input/mock_input_router_client.h" | 13 #include "content/browser/renderer_host/input/mock_input_router_client.h" |
14 #include "content/common/content_constants_internal.h" | 14 #include "content/common/content_constants_internal.h" |
15 #include "content/common/edit_command.h" | 15 #include "content/common/edit_command.h" |
16 #include "content/common/input/synthetic_web_input_event_builders.h" | 16 #include "content/common/input/synthetic_web_input_event_builders.h" |
17 #include "content/common/input/touch_action.h" | |
17 #include "content/common/input/web_input_event_traits.h" | 18 #include "content/common/input/web_input_event_traits.h" |
18 #include "content/common/input_messages.h" | 19 #include "content/common/input_messages.h" |
19 #include "content/common/view_messages.h" | 20 #include "content/common/view_messages.h" |
20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
21 #include "content/public/test/mock_render_process_host.h" | 22 #include "content/public/test/mock_render_process_host.h" |
22 #include "content/public/test/test_browser_context.h" | 23 #include "content/public/test/test_browser_context.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
24 #include "ui/events/keycodes/keyboard_codes.h" | 25 #include "ui/events/keycodes/keyboard_codes.h" |
25 | 26 |
26 #if defined(OS_WIN) || defined(USE_AURA) | 27 #if defined(OS_WIN) || defined(USE_AURA) |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
267 | 268 |
268 bool TouchEventTimeoutEnabled() const { | 269 bool TouchEventTimeoutEnabled() const { |
269 return input_router()->touch_event_queue_->ack_timeout_enabled(); | 270 return input_router()->touch_event_queue_->ack_timeout_enabled(); |
270 } | 271 } |
271 | 272 |
272 void OnHasTouchEventHandlers(bool has_handlers) { | 273 void OnHasTouchEventHandlers(bool has_handlers) { |
273 input_router_->OnMessageReceived( | 274 input_router_->OnMessageReceived( |
274 ViewHostMsg_HasTouchEventHandlers(0, has_handlers)); | 275 ViewHostMsg_HasTouchEventHandlers(0, has_handlers)); |
275 } | 276 } |
276 | 277 |
278 void OnSetTouchAction(content::TouchAction touch_action) { | |
279 input_router_->OnMessageReceived( | |
280 InputHostMsg_SetTouchAction(0, touch_action)); | |
281 } | |
282 | |
277 size_t GetSentMessageCountAndResetSink() { | 283 size_t GetSentMessageCountAndResetSink() { |
278 size_t count = process_->sink().message_count(); | 284 size_t count = process_->sink().message_count(); |
279 process_->sink().ClearMessages(); | 285 process_->sink().ClearMessages(); |
280 return count; | 286 return count; |
281 } | 287 } |
282 | 288 |
283 scoped_ptr<MockRenderProcessHost> process_; | 289 scoped_ptr<MockRenderProcessHost> process_; |
284 scoped_ptr<MockInputRouterClient> client_; | 290 scoped_ptr<MockInputRouterClient> client_; |
285 scoped_ptr<MockInputAckHandler> ack_handler_; | 291 scoped_ptr<MockInputAckHandler> ack_handler_; |
286 scoped_ptr<InputRouterImpl> input_router_; | 292 scoped_ptr<InputRouterImpl> input_router_; |
(...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
948 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 954 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
949 | 955 |
950 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT | | 956 input_router()->OnViewUpdated(InputRouter::MOBILE_VIEWPORT | |
951 InputRouter::FIXED_PAGE_SCALE); | 957 InputRouter::FIXED_PAGE_SCALE); |
952 EXPECT_FALSE(TouchEventTimeoutEnabled()); | 958 EXPECT_FALSE(TouchEventTimeoutEnabled()); |
953 | 959 |
954 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE); | 960 input_router()->OnViewUpdated(InputRouter::VIEW_FLAGS_NONE); |
955 EXPECT_TRUE(TouchEventTimeoutEnabled()); | 961 EXPECT_TRUE(TouchEventTimeoutEnabled()); |
956 } | 962 } |
957 | 963 |
964 // Test that TouchActionFilter::OnStartNewTouchSequence is called before the | |
965 // first touch event for a touch sequence reaches the renderer. | |
966 TEST_F(InputRouterImplTest, OnStartNewTouchSequenceBeforeEventReachesRenderer) { | |
967 OnHasTouchEventHandlers(true); | |
968 | |
969 // Sequence 1. | |
970 PressTouchPoint(1, 1); | |
971 SendTouchEvent(); | |
972 OnSetTouchAction(TouchAction::TOUCH_ACTION_NONE); | |
973 MoveTouchPoint(0, 5, 5); | |
974 SendTouchEvent(); | |
975 ReleaseTouchPoint(0); | |
976 SendTouchEvent(); | |
977 | |
978 // Sequence 2. | |
979 PressTouchPoint(1, 1); | |
980 SendTouchEvent(); | |
981 MoveTouchPoint(0, 5, 5); | |
982 SendTouchEvent(); | |
983 ReleaseTouchPoint(0); | |
984 SendTouchEvent(); | |
985 | |
986 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | |
987 SendInputEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED); | |
988 | |
989 // Ensure touch action is still none, as the next touch start hasn't been | |
990 // acked yet. ScrollBegin and ScrollEnd don't require acks. | |
991 EXPECT_EQ(3U, GetSentMessageCountAndResetSink()); | |
992 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | |
993 WebGestureEvent::Touchpad); | |
994 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
995 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | |
996 WebGestureEvent::Touchpad); | |
997 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
998 | |
999 // This allows the next touch sequence to start. | |
1000 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | |
1001 | |
1002 // Ensure touch action has been set to auto, as a new touch sequence has | |
1003 // started. | |
1004 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
1005 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | |
1006 WebGestureEvent::Touchpad); | |
1007 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
1008 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | |
1009 WebGestureEvent::Touchpad); | |
1010 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
1011 | |
1012 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | |
1013 SendInputEventACK(WebInputEvent::TouchMove, INPUT_EVENT_ACK_STATE_CONSUMED); | |
1014 SendInputEventACK(WebInputEvent::TouchEnd, INPUT_EVENT_ACK_STATE_CONSUMED); | |
1015 } | |
1016 | |
1017 // Test that TouchActionFilter::OnStartNewTouchSequence is called when a touch | |
1018 // handler is removed. | |
1019 TEST_F(InputRouterImplTest, OnStartNewTouchSequenceWhenTouchHandlerRemoved) { | |
1020 OnHasTouchEventHandlers(true); | |
1021 | |
1022 // Sequence 1. | |
1023 PressTouchPoint(1, 1); | |
1024 SendTouchEvent(); | |
1025 OnSetTouchAction(TouchAction::TOUCH_ACTION_NONE); | |
1026 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | |
1027 | |
1028 MoveTouchPoint(0, 5, 5); | |
1029 SendTouchEvent(); | |
1030 | |
1031 // Ensure we have touch-action:none. ScrollBegin and ScrollEnd don't require | |
1032 // acks. | |
1033 EXPECT_EQ(2U, GetSentMessageCountAndResetSink()); | |
1034 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | |
1035 WebGestureEvent::Touchpad); | |
1036 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
1037 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | |
1038 WebGestureEvent::Touchpad); | |
1039 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
1040 | |
1041 SendInputEventACK(WebInputEvent::TouchMove, | |
Rick Byers
2014/02/25 23:03:37
You should probably make this a valid sequence: se
tdresser
2014/02/26 14:04:49
Done.
| |
1042 INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS); | |
1043 | |
1044 // Ensure touch action has been set to auto, the touch handler has been | |
1045 // removed. | |
1046 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | |
1047 SimulateGestureEvent(WebInputEvent::GestureScrollBegin, | |
1048 WebGestureEvent::Touchpad); | |
1049 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
1050 SimulateGestureEvent(WebInputEvent::GestureScrollEnd, | |
1051 WebGestureEvent::Touchpad); | |
1052 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | |
1053 } | |
1054 | |
958 } // namespace content | 1055 } // namespace content |
OLD | NEW |