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 "content/browser/renderer_host/input/input_router_impl.h" | 5 #include "content/browser/renderer_host/input/input_router_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <memory> | 11 #include <memory> |
12 #include <tuple> | 12 #include <tuple> |
| 13 #include <vector> |
13 | 14 |
14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" |
17 #include "base/run_loop.h" | 19 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
20 #include "base/test/scoped_feature_list.h" | 22 #include "base/test/scoped_feature_list.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
22 #include "build/build_config.h" | 24 #include "build/build_config.h" |
23 #include "content/browser/renderer_host/input/gesture_event_queue.h" | 25 #include "content/browser/renderer_host/input/gesture_event_queue.h" |
24 #include "content/browser/renderer_host/input/input_router_client.h" | 26 #include "content/browser/renderer_host/input/input_router_client.h" |
25 #include "content/browser/renderer_host/input/mock_input_ack_handler.h" | 27 #include "content/browser/renderer_host/input/mock_input_ack_handler.h" |
26 #include "content/browser/renderer_host/input/mock_input_router_client.h" | 28 #include "content/browser/renderer_host/input/mock_input_router_client.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return false; | 125 return false; |
124 if (first.location() != second.location()) | 126 if (first.location() != second.location()) |
125 return false; | 127 return false; |
126 if (first.pointer_details().id != second.pointer_details().id) | 128 if (first.pointer_details().id != second.pointer_details().id) |
127 return false; | 129 return false; |
128 if (second.time_stamp() != first.time_stamp()) | 130 if (second.time_stamp() != first.time_stamp()) |
129 return false; | 131 return false; |
130 return true; | 132 return true; |
131 } | 133 } |
132 | 134 |
133 bool EventListIsSubset(const ScopedVector<ui::TouchEvent>& subset, | 135 bool EventListIsSubset( |
134 const ScopedVector<ui::TouchEvent>& set) { | 136 const std::vector<std::unique_ptr<ui::TouchEvent>>& subset, |
| 137 const std::vector<std::unique_ptr<ui::TouchEvent>>& set) { |
135 if (subset.size() > set.size()) | 138 if (subset.size() > set.size()) |
136 return false; | 139 return false; |
137 for (size_t i = 0; i < subset.size(); ++i) { | 140 for (size_t i = 0; i < subset.size(); ++i) { |
138 const ui::TouchEvent* first = subset[i]; | 141 bool equivalent = TouchEventsAreEquivalent(*(subset[i]), *(set[i])); |
139 const ui::TouchEvent* second = set[i]; | |
140 bool equivalent = TouchEventsAreEquivalent(*first, *second); | |
141 if (!equivalent) | 142 if (!equivalent) |
142 return false; | 143 return false; |
143 } | 144 } |
144 | 145 |
145 return true; | 146 return true; |
146 } | 147 } |
147 #endif // defined(USE_AURA) | 148 #endif // defined(USE_AURA) |
148 | 149 |
149 } // namespace | 150 } // namespace |
150 | 151 |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 | 909 |
909 #if defined(USE_AURA) | 910 #if defined(USE_AURA) |
910 // Tests that the acked events have correct state. (ui::Events are used only on | 911 // Tests that the acked events have correct state. (ui::Events are used only on |
911 // windows and aura) | 912 // windows and aura) |
912 TEST_F(InputRouterImplTest, AckedTouchEventState) { | 913 TEST_F(InputRouterImplTest, AckedTouchEventState) { |
913 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); | 914 input_router_->OnMessageReceived(ViewHostMsg_HasTouchEventHandlers(0, true)); |
914 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); | 915 EXPECT_EQ(0U, GetSentMessageCountAndResetSink()); |
915 EXPECT_TRUE(TouchEventQueueEmpty()); | 916 EXPECT_TRUE(TouchEventQueueEmpty()); |
916 | 917 |
917 // Send a bunch of events, and make sure the ACKed events are correct. | 918 // Send a bunch of events, and make sure the ACKed events are correct. |
918 ScopedVector<ui::TouchEvent> expected_events; | 919 std::vector<std::unique_ptr<ui::TouchEvent>> expected_events; |
919 | 920 |
920 // Use a custom timestamp for all the events to test that the acked events | 921 // Use a custom timestamp for all the events to test that the acked events |
921 // have the same timestamp; | 922 // have the same timestamp; |
922 base::TimeTicks timestamp = base::TimeTicks::Now(); | 923 base::TimeTicks timestamp = base::TimeTicks::Now(); |
923 timestamp -= base::TimeDelta::FromSeconds(600); | 924 timestamp -= base::TimeDelta::FromSeconds(600); |
924 | 925 |
925 // Press the first finger. | 926 // Press the first finger. |
926 PressTouchPoint(1, 1); | 927 PressTouchPoint(1, 1); |
927 SetTouchTimestamp(timestamp); | 928 SetTouchTimestamp(timestamp); |
928 uint32_t touch_press_event_id1 = SendTouchEvent(); | 929 uint32_t touch_press_event_id1 = SendTouchEvent(); |
929 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); | 930 EXPECT_EQ(1U, GetSentMessageCountAndResetSink()); |
930 expected_events.push_back( | 931 expected_events.push_back(base::MakeUnique<ui::TouchEvent>( |
931 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(1, 1), 0, timestamp)); | 932 ui::ET_TOUCH_PRESSED, gfx::Point(1, 1), 0, timestamp)); |
932 | 933 |
933 // Move the finger. | 934 // Move the finger. |
934 timestamp += base::TimeDelta::FromSeconds(10); | 935 timestamp += base::TimeDelta::FromSeconds(10); |
935 MoveTouchPoint(0, 500, 500); | 936 MoveTouchPoint(0, 500, 500); |
936 SetTouchTimestamp(timestamp); | 937 SetTouchTimestamp(timestamp); |
937 uint32_t touch_move_event_id1 = SendTouchEvent(); | 938 uint32_t touch_move_event_id1 = SendTouchEvent(); |
938 EXPECT_FALSE(TouchEventQueueEmpty()); | 939 EXPECT_FALSE(TouchEventQueueEmpty()); |
939 expected_events.push_back(new ui::TouchEvent( | 940 expected_events.push_back(base::MakeUnique<ui::TouchEvent>( |
940 ui::ET_TOUCH_MOVED, gfx::Point(500, 500), 0, timestamp)); | 941 ui::ET_TOUCH_MOVED, gfx::Point(500, 500), 0, timestamp)); |
941 | 942 |
942 // Now press a second finger. | 943 // Now press a second finger. |
943 timestamp += base::TimeDelta::FromSeconds(10); | 944 timestamp += base::TimeDelta::FromSeconds(10); |
944 PressTouchPoint(2, 2); | 945 PressTouchPoint(2, 2); |
945 SetTouchTimestamp(timestamp); | 946 SetTouchTimestamp(timestamp); |
946 uint32_t touch_press_event_id2 = SendTouchEvent(); | 947 uint32_t touch_press_event_id2 = SendTouchEvent(); |
947 EXPECT_FALSE(TouchEventQueueEmpty()); | 948 EXPECT_FALSE(TouchEventQueueEmpty()); |
948 expected_events.push_back( | 949 expected_events.push_back(base::MakeUnique<ui::TouchEvent>( |
949 new ui::TouchEvent(ui::ET_TOUCH_PRESSED, gfx::Point(2, 2), 1, timestamp)); | 950 ui::ET_TOUCH_PRESSED, gfx::Point(2, 2), 1, timestamp)); |
950 | 951 |
951 // Move both fingers. | 952 // Move both fingers. |
952 timestamp += base::TimeDelta::FromSeconds(10); | 953 timestamp += base::TimeDelta::FromSeconds(10); |
953 MoveTouchPoint(0, 10, 10); | 954 MoveTouchPoint(0, 10, 10); |
954 MoveTouchPoint(1, 20, 20); | 955 MoveTouchPoint(1, 20, 20); |
955 SetTouchTimestamp(timestamp); | 956 SetTouchTimestamp(timestamp); |
956 uint32_t touch_move_event_id2 = SendTouchEvent(); | 957 uint32_t touch_move_event_id2 = SendTouchEvent(); |
957 EXPECT_FALSE(TouchEventQueueEmpty()); | 958 EXPECT_FALSE(TouchEventQueueEmpty()); |
958 expected_events.push_back( | 959 expected_events.push_back(base::MakeUnique<ui::TouchEvent>( |
959 new ui::TouchEvent(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 0, timestamp)); | 960 ui::ET_TOUCH_MOVED, gfx::Point(10, 10), 0, timestamp)); |
960 expected_events.push_back( | 961 expected_events.push_back(base::MakeUnique<ui::TouchEvent>( |
961 new ui::TouchEvent(ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 1, timestamp)); | 962 ui::ET_TOUCH_MOVED, gfx::Point(20, 20), 1, timestamp)); |
962 | 963 |
963 // Receive the ACKs and make sure the generated events from the acked events | 964 // Receive the ACKs and make sure the generated events from the acked events |
964 // are correct. | 965 // are correct. |
965 WebInputEvent::Type acks[] = { WebInputEvent::TouchStart, | 966 WebInputEvent::Type acks[] = { WebInputEvent::TouchStart, |
966 WebInputEvent::TouchMove, | 967 WebInputEvent::TouchMove, |
967 WebInputEvent::TouchStart, | 968 WebInputEvent::TouchStart, |
968 WebInputEvent::TouchMove }; | 969 WebInputEvent::TouchMove }; |
969 | 970 |
970 uint32_t touch_event_ids[] = {touch_press_event_id1, touch_move_event_id1, | 971 uint32_t touch_event_ids[] = {touch_press_event_id1, touch_move_event_id1, |
971 touch_press_event_id2, touch_move_event_id2}; | 972 touch_press_event_id2, touch_move_event_id2}; |
972 | 973 |
973 TouchEventCoordinateSystem coordinate_system = LOCAL_COORDINATES; | 974 TouchEventCoordinateSystem coordinate_system = LOCAL_COORDINATES; |
974 #if !defined(OS_WIN) | 975 #if !defined(OS_WIN) |
975 coordinate_system = SCREEN_COORDINATES; | 976 coordinate_system = SCREEN_COORDINATES; |
976 #endif | 977 #endif |
977 for (size_t i = 0; i < arraysize(acks); ++i) { | 978 for (size_t i = 0; i < arraysize(acks); ++i) { |
978 SendTouchEventACK(acks[i], INPUT_EVENT_ACK_STATE_NOT_CONSUMED, | 979 SendTouchEventACK(acks[i], INPUT_EVENT_ACK_STATE_NOT_CONSUMED, |
979 touch_event_ids[i]); | 980 touch_event_ids[i]); |
980 EXPECT_EQ(acks[i], ack_handler_->acked_touch_event().event.type()); | 981 EXPECT_EQ(acks[i], ack_handler_->acked_touch_event().event.type()); |
981 ScopedVector<ui::TouchEvent> acked; | 982 std::vector<std::unique_ptr<ui::TouchEvent>> acked; |
982 | 983 |
983 MakeUITouchEventsFromWebTouchEvents( | 984 MakeUITouchEventsFromWebTouchEvents( |
984 ack_handler_->acked_touch_event(), &acked, coordinate_system); | 985 ack_handler_->acked_touch_event(), &acked, coordinate_system); |
985 bool success = EventListIsSubset(acked, expected_events); | 986 bool success = EventListIsSubset(acked, expected_events); |
986 EXPECT_TRUE(success) << "Failed on step: " << i; | 987 EXPECT_TRUE(success) << "Failed on step: " << i; |
987 if (!success) | 988 if (!success) |
988 break; | 989 break; |
989 expected_events.erase(expected_events.begin(), | 990 expected_events.erase(expected_events.begin(), |
990 expected_events.begin() + acked.size()); | 991 expected_events.begin() + acked.size()); |
991 } | 992 } |
(...skipping 1445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2437 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); | 2438 EXPECT_EQ(80, sent_event->data.flingStart.velocityY); |
2438 | 2439 |
2439 const WebGestureEvent* filter_event = | 2440 const WebGestureEvent* filter_event = |
2440 GetFilterWebInputEvent<WebGestureEvent>(); | 2441 GetFilterWebInputEvent<WebGestureEvent>(); |
2441 TestLocationInFilterEvent(filter_event, orig); | 2442 TestLocationInFilterEvent(filter_event, orig); |
2442 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); | 2443 EXPECT_EQ(30, filter_event->data.flingStart.velocityX); |
2443 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); | 2444 EXPECT_EQ(40, filter_event->data.flingStart.velocityY); |
2444 } | 2445 } |
2445 | 2446 |
2446 } // namespace content | 2447 } // namespace content |
OLD | NEW |