OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/common/input/web_input_event_traits.h" | 5 #include "content/common/input/web_input_event_traits.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
| 9 #include "content/common/input/event_with_latency_info.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/WebKit/public/web/WebInputEvent.h" | 11 #include "third_party/WebKit/public/web/WebInputEvent.h" |
11 | 12 |
12 using blink::WebGestureEvent; | 13 using blink::WebGestureEvent; |
13 using blink::WebInputEvent; | 14 using blink::WebInputEvent; |
14 using blink::WebKeyboardEvent; | 15 using blink::WebKeyboardEvent; |
15 using blink::WebMouseEvent; | 16 using blink::WebMouseEvent; |
16 using blink::WebMouseWheelEvent; | 17 using blink::WebMouseWheelEvent; |
17 using blink::WebTouchEvent; | 18 using blink::WebTouchEvent; |
18 using blink::WebTouchPoint; | 19 using blink::WebTouchPoint; |
19 using std::numeric_limits; | 20 using std::numeric_limits; |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 namespace { | 23 namespace { |
23 | 24 |
| 25 // TODO(tapted): Move the Coalesce tests to event_with_latency_info_unittest.cc. |
| 26 // Merge this test harness into EventWithLatencyInfoTest. |
| 27 // http://crbug.com/625000. |
24 class WebInputEventTraitsTest : public testing::Test { | 28 class WebInputEventTraitsTest : public testing::Test { |
25 protected: | 29 protected: |
26 static WebTouchPoint CreateTouchPoint(WebTouchPoint::State state, int id) { | 30 static WebTouchPoint CreateTouchPoint(WebTouchPoint::State state, int id) { |
27 WebTouchPoint touch; | 31 WebTouchPoint touch; |
28 touch.state = state; | 32 touch.state = state; |
29 touch.id = id; | 33 touch.id = id; |
30 return touch; | 34 return touch; |
31 } | 35 } |
32 | 36 |
33 static WebTouchEvent CreateTouch(WebInputEvent::Type type) { | 37 static TouchEventWithLatencyInfo CreateTouch(WebInputEvent::Type type) { |
34 return CreateTouch(type, 1); | 38 return CreateTouch(type, 1); |
35 } | 39 } |
36 | 40 |
37 static WebTouchEvent CreateTouch(WebInputEvent::Type type, | 41 static TouchEventWithLatencyInfo CreateTouch(WebInputEvent::Type type, |
38 unsigned touch_count) { | 42 unsigned touch_count) { |
39 WebTouchEvent event; | 43 WebTouchEvent event; |
40 event.touchesLength = touch_count; | 44 event.touchesLength = touch_count; |
41 event.type = type; | 45 event.type = type; |
42 return event; | 46 return TouchEventWithLatencyInfo(event); |
43 } | 47 } |
44 | 48 |
45 static WebGestureEvent CreateGesture(WebInputEvent::Type type, | 49 static GestureEventWithLatencyInfo CreateGesture(WebInputEvent::Type type, |
46 float x, | 50 float x, |
47 float y) { | 51 float y) { |
48 WebGestureEvent event; | 52 WebGestureEvent event; |
49 event.type = type; | 53 event.type = type; |
50 event.x = x; | 54 event.x = x; |
51 event.y = y; | 55 event.y = y; |
52 return event; | 56 return GestureEventWithLatencyInfo(event); |
53 } | 57 } |
54 | 58 |
55 static WebMouseWheelEvent CreateMouseWheel(float deltaX, float deltaY) { | 59 static MouseWheelEventWithLatencyInfo CreateMouseWheel(float deltaX, |
| 60 float deltaY) { |
56 WebMouseWheelEvent event; | 61 WebMouseWheelEvent event; |
57 event.type = WebInputEvent::MouseWheel; | 62 event.type = WebInputEvent::MouseWheel; |
58 event.deltaX = deltaX; | 63 event.deltaX = deltaX; |
59 event.deltaY = deltaY; | 64 event.deltaY = deltaY; |
60 return event; | 65 return MouseWheelEventWithLatencyInfo(event); |
61 } | 66 } |
62 }; | 67 }; |
63 | 68 |
| 69 template <class T> |
| 70 bool CanCoalesce(const T& event_to_coalesce, const T& event) { |
| 71 return event.CanCoalesceWith(event_to_coalesce); |
| 72 } |
| 73 |
| 74 template <class T> |
| 75 void Coalesce(const T& event_to_coalesce, T* event) { |
| 76 return event->CoalesceWith(event_to_coalesce); |
| 77 } |
| 78 |
64 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { | 79 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { |
65 WebTouchEvent touch0 = CreateTouch(WebInputEvent::TouchStart); | 80 TouchEventWithLatencyInfo touch0 = CreateTouch(WebInputEvent::TouchStart); |
66 WebTouchEvent touch1 = CreateTouch(WebInputEvent::TouchMove); | 81 TouchEventWithLatencyInfo touch1 = CreateTouch(WebInputEvent::TouchMove); |
67 | 82 |
68 // Non touch-moves won't coalesce. | 83 // Non touch-moves won't coalesce. |
69 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0)); | 84 EXPECT_FALSE(CanCoalesce(touch0, touch0)); |
70 | 85 |
71 // Touches of different types won't coalesce. | 86 // Touches of different types won't coalesce. |
72 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1)); | 87 EXPECT_FALSE(CanCoalesce(touch0, touch1)); |
73 | 88 |
74 // Touch moves with idential touch lengths and touch ids should coalesce. | 89 // Touch moves with idential touch lengths and touch ids should coalesce. |
75 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(touch1, touch1)); | 90 EXPECT_TRUE(CanCoalesce(touch1, touch1)); |
76 | 91 |
77 // Touch moves with different touch ids should not coalesce. | 92 // Touch moves with different touch ids should not coalesce. |
78 touch0 = CreateTouch(WebInputEvent::TouchMove); | 93 touch0 = CreateTouch(WebInputEvent::TouchMove); |
79 touch1 = CreateTouch(WebInputEvent::TouchMove); | 94 touch1 = CreateTouch(WebInputEvent::TouchMove); |
80 touch0.touches[0].id = 7; | 95 touch0.event.touches[0].id = 7; |
81 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1)); | 96 EXPECT_FALSE(CanCoalesce(touch0, touch1)); |
82 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); | 97 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); |
83 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); | 98 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); |
84 touch0.touches[0].id = 1; | 99 touch0.event.touches[0].id = 1; |
85 touch1.touches[0].id = 0; | 100 touch1.event.touches[0].id = 0; |
86 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1)); | 101 EXPECT_FALSE(CanCoalesce(touch0, touch1)); |
87 | 102 |
88 // Touch moves with different touch lengths should not coalesce. | 103 // Touch moves with different touch lengths should not coalesce. |
89 touch0 = CreateTouch(WebInputEvent::TouchMove, 1); | 104 touch0 = CreateTouch(WebInputEvent::TouchMove, 1); |
90 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); | 105 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); |
91 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch1)); | 106 EXPECT_FALSE(CanCoalesce(touch0, touch1)); |
92 | 107 |
93 // Touch moves with identical touch ids in different orders should coalesce. | 108 // Touch moves with identical touch ids in different orders should coalesce. |
94 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); | 109 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); |
95 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); | 110 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); |
96 touch0.touches[0] = touch1.touches[1] = | 111 touch0.event.touches[0] = touch1.event.touches[1] = |
97 CreateTouchPoint(WebTouchPoint::StateMoved, 1); | 112 CreateTouchPoint(WebTouchPoint::StateMoved, 1); |
98 touch0.touches[1] = touch1.touches[0] = | 113 touch0.event.touches[1] = touch1.event.touches[0] = |
99 CreateTouchPoint(WebTouchPoint::StateMoved, 0); | 114 CreateTouchPoint(WebTouchPoint::StateMoved, 0); |
100 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(touch0, touch1)); | 115 EXPECT_TRUE(CanCoalesce(touch0, touch1)); |
101 | 116 |
102 // Pointers with the same ID's should coalesce. | 117 // Pointers with the same ID's should coalesce. |
103 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); | 118 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); |
104 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); | 119 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); |
105 touch0.touches[0] = touch1.touches[1] = | 120 touch0.event.touches[0] = touch1.event.touches[1] = |
106 CreateTouchPoint(WebTouchPoint::StateMoved, 1); | 121 CreateTouchPoint(WebTouchPoint::StateMoved, 1); |
107 WebInputEventTraits::Coalesce(touch0, &touch1); | 122 Coalesce(touch0, &touch1); |
108 ASSERT_EQ(1, touch1.touches[0].id); | 123 ASSERT_EQ(1, touch1.event.touches[0].id); |
109 ASSERT_EQ(0, touch1.touches[1].id); | 124 ASSERT_EQ(0, touch1.event.touches[1].id); |
110 EXPECT_EQ(WebTouchPoint::StateUndefined, touch1.touches[1].state); | 125 EXPECT_EQ(WebTouchPoint::StateUndefined, touch1.event.touches[1].state); |
111 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[0].state); | 126 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.event.touches[0].state); |
112 | 127 |
113 // Movement from now-stationary pointers should be preserved. | 128 // Movement from now-stationary pointers should be preserved. |
114 touch0 = touch1 = CreateTouch(WebInputEvent::TouchMove, 2); | 129 touch0 = touch1 = CreateTouch(WebInputEvent::TouchMove, 2); |
115 touch0.touches[0] = CreateTouchPoint(WebTouchPoint::StateMoved, 1); | 130 touch0.event.touches[0] = CreateTouchPoint(WebTouchPoint::StateMoved, 1); |
116 touch1.touches[1] = CreateTouchPoint(WebTouchPoint::StateStationary, 1); | 131 touch1.event.touches[1] = CreateTouchPoint(WebTouchPoint::StateStationary, 1); |
117 touch0.touches[1] = CreateTouchPoint(WebTouchPoint::StateStationary, 0); | 132 touch0.event.touches[1] = CreateTouchPoint(WebTouchPoint::StateStationary, 0); |
118 touch1.touches[0] = CreateTouchPoint(WebTouchPoint::StateMoved, 0); | 133 touch1.event.touches[0] = CreateTouchPoint(WebTouchPoint::StateMoved, 0); |
119 WebInputEventTraits::Coalesce(touch0, &touch1); | 134 Coalesce(touch0, &touch1); |
120 ASSERT_EQ(1, touch1.touches[0].id); | 135 ASSERT_EQ(1, touch1.event.touches[0].id); |
121 ASSERT_EQ(0, touch1.touches[1].id); | 136 ASSERT_EQ(0, touch1.event.touches[1].id); |
122 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[0].state); | 137 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.event.touches[0].state); |
123 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.touches[1].state); | 138 EXPECT_EQ(WebTouchPoint::StateMoved, touch1.event.touches[1].state); |
124 | 139 |
125 // Touch moves with different dispatchTypes coalesce. | 140 // Touch moves with different dispatchTypes coalesce. |
126 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); | 141 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); |
127 touch0.dispatchType = WebInputEvent::DispatchType::Blocking; | 142 touch0.event.dispatchType = WebInputEvent::DispatchType::Blocking; |
128 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); | 143 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); |
129 touch1.dispatchType = WebInputEvent::DispatchType::EventNonBlocking; | 144 touch1.event.dispatchType = WebInputEvent::DispatchType::EventNonBlocking; |
130 touch0.touches[0] = touch1.touches[1] = | 145 touch0.event.touches[0] = touch1.event.touches[1] = |
131 CreateTouchPoint(WebTouchPoint::StateMoved, 1); | 146 CreateTouchPoint(WebTouchPoint::StateMoved, 1); |
132 touch0.touches[1] = touch1.touches[0] = | 147 touch0.event.touches[1] = touch1.event.touches[0] = |
133 CreateTouchPoint(WebTouchPoint::StateMoved, 0); | 148 CreateTouchPoint(WebTouchPoint::StateMoved, 0); |
134 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(touch0, touch1)); | 149 EXPECT_TRUE(CanCoalesce(touch0, touch1)); |
135 WebInputEventTraits::Coalesce(touch0, &touch1); | 150 Coalesce(touch0, &touch1); |
136 ASSERT_EQ(WebInputEvent::DispatchType::Blocking, touch1.dispatchType); | 151 ASSERT_EQ(WebInputEvent::DispatchType::Blocking, touch1.event.dispatchType); |
137 | 152 |
138 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); | 153 touch0 = CreateTouch(WebInputEvent::TouchMove, 2); |
139 touch0.dispatchType = | 154 touch0.event.dispatchType = |
140 WebInputEvent::DispatchType::ListenersForcedNonBlockingPassive; | 155 WebInputEvent::DispatchType::ListenersForcedNonBlockingPassive; |
141 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); | 156 touch1 = CreateTouch(WebInputEvent::TouchMove, 2); |
142 touch1.dispatchType = | 157 touch1.event.dispatchType = |
143 WebInputEvent::DispatchType::ListenersNonBlockingPassive; | 158 WebInputEvent::DispatchType::ListenersNonBlockingPassive; |
144 touch0.touches[0] = touch1.touches[1] = | 159 touch0.event.touches[0] = touch1.event.touches[1] = |
145 CreateTouchPoint(WebTouchPoint::StateMoved, 1); | 160 CreateTouchPoint(WebTouchPoint::StateMoved, 1); |
146 touch0.touches[1] = touch1.touches[0] = | 161 touch0.event.touches[1] = touch1.event.touches[0] = |
147 CreateTouchPoint(WebTouchPoint::StateMoved, 0); | 162 CreateTouchPoint(WebTouchPoint::StateMoved, 0); |
148 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(touch0, touch1)); | 163 EXPECT_TRUE(CanCoalesce(touch0, touch1)); |
149 WebInputEventTraits::Coalesce(touch0, &touch1); | 164 Coalesce(touch0, &touch1); |
150 ASSERT_EQ(WebInputEvent::DispatchType::ListenersNonBlockingPassive, | 165 ASSERT_EQ(WebInputEvent::DispatchType::ListenersNonBlockingPassive, |
151 touch1.dispatchType); | 166 touch1.event.dispatchType); |
152 } | 167 } |
153 | 168 |
154 TEST_F(WebInputEventTraitsTest, PinchEventCoalescing) { | 169 TEST_F(WebInputEventTraitsTest, PinchEventCoalescing) { |
155 WebGestureEvent pinch0 = | 170 GestureEventWithLatencyInfo pinch0 = |
156 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); | 171 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); |
157 WebGestureEvent pinch1 = | 172 GestureEventWithLatencyInfo pinch1 = |
158 CreateGesture(WebInputEvent::GesturePinchUpdate, 2, 2); | 173 CreateGesture(WebInputEvent::GesturePinchUpdate, 2, 2); |
159 | 174 |
160 // Only GesturePinchUpdate's coalesce. | 175 // Only GesturePinchUpdate's coalesce. |
161 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(pinch0, pinch0)); | 176 EXPECT_FALSE(CanCoalesce(pinch0, pinch0)); |
162 | 177 |
163 // Pinch gestures of different types should not coalesce. | 178 // Pinch gestures of different types should not coalesce. |
164 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); | 179 EXPECT_FALSE(CanCoalesce(pinch0, pinch1)); |
165 | 180 |
166 // Pinches with different focal points should not coalesce. | 181 // Pinches with different focal points should not coalesce. |
167 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 182 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
168 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 2, 2); | 183 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 2, 2); |
169 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); | 184 EXPECT_FALSE(CanCoalesce(pinch0, pinch1)); |
170 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch0)); | 185 EXPECT_TRUE(CanCoalesce(pinch0, pinch0)); |
171 | 186 |
172 // Coalesced scales are multiplicative. | 187 // Coalesced scales are multiplicative. |
173 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 188 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
174 pinch0.data.pinchUpdate.scale = 2.f; | 189 pinch0.event.data.pinchUpdate.scale = 2.f; |
175 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 190 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
176 pinch1.data.pinchUpdate.scale = 3.f; | 191 pinch1.event.data.pinchUpdate.scale = 3.f; |
177 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch0)); | 192 EXPECT_TRUE(CanCoalesce(pinch0, pinch0)); |
178 WebInputEventTraits::Coalesce(pinch0, &pinch1); | 193 Coalesce(pinch0, &pinch1); |
179 EXPECT_EQ(2.f * 3.f, pinch1.data.pinchUpdate.scale); | 194 EXPECT_EQ(2.f * 3.f, pinch1.event.data.pinchUpdate.scale); |
180 | 195 |
181 // Scales have a minimum value and can never reach 0. | 196 // Scales have a minimum value and can never reach 0. |
182 ASSERT_GT(numeric_limits<float>::min(), 0); | 197 ASSERT_GT(numeric_limits<float>::min(), 0); |
183 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 198 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
184 pinch0.data.pinchUpdate.scale = numeric_limits<float>::min() * 2.0f; | 199 pinch0.event.data.pinchUpdate.scale = numeric_limits<float>::min() * 2.0f; |
185 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 200 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
186 pinch1.data.pinchUpdate.scale = numeric_limits<float>::min() * 5.0f; | 201 pinch1.event.data.pinchUpdate.scale = numeric_limits<float>::min() * 5.0f; |
187 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); | 202 EXPECT_TRUE(CanCoalesce(pinch0, pinch1)); |
188 WebInputEventTraits::Coalesce(pinch0, &pinch1); | 203 Coalesce(pinch0, &pinch1); |
189 EXPECT_EQ(numeric_limits<float>::min(), pinch1.data.pinchUpdate.scale); | 204 EXPECT_EQ(numeric_limits<float>::min(), pinch1.event.data.pinchUpdate.scale); |
190 | 205 |
191 // Scales have a maximum value and can never reach Infinity. | 206 // Scales have a maximum value and can never reach Infinity. |
192 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 207 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
193 pinch0.data.pinchUpdate.scale = numeric_limits<float>::max() / 2.0f; | 208 pinch0.event.data.pinchUpdate.scale = numeric_limits<float>::max() / 2.0f; |
194 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 209 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
195 pinch1.data.pinchUpdate.scale = 10.0f; | 210 pinch1.event.data.pinchUpdate.scale = 10.0f; |
196 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); | 211 EXPECT_TRUE(CanCoalesce(pinch0, pinch1)); |
197 WebInputEventTraits::Coalesce(pinch0, &pinch1); | 212 Coalesce(pinch0, &pinch1); |
198 EXPECT_EQ(numeric_limits<float>::max(), pinch1.data.pinchUpdate.scale); | 213 EXPECT_EQ(numeric_limits<float>::max(), pinch1.event.data.pinchUpdate.scale); |
199 } | 214 } |
200 | 215 |
201 TEST_F(WebInputEventTraitsTest, WebMouseWheelEventCoalescing) { | 216 TEST_F(WebInputEventTraitsTest, WebMouseWheelEventCoalescing) { |
202 WebMouseWheelEvent mouse_wheel_0 = CreateMouseWheel(1, 1); | 217 MouseWheelEventWithLatencyInfo mouse_wheel_0 = CreateMouseWheel(1, 1); |
203 WebMouseWheelEvent mouse_wheel_1 = CreateMouseWheel(2, 2); | 218 MouseWheelEventWithLatencyInfo mouse_wheel_1 = CreateMouseWheel(2, 2); |
204 | 219 |
205 // WebMouseWheelEvent objects with same values except different deltaX and | 220 // WebMouseWheelEvent objects with same values except different deltaX and |
206 // deltaY should coalesce. | 221 // deltaY should coalesce. |
207 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(mouse_wheel_0, mouse_wheel_1)); | 222 EXPECT_TRUE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); |
208 | 223 |
209 // WebMouseWheelEvent objects with different modifiers should not coalesce. | 224 // WebMouseWheelEvent objects with different modifiers should not coalesce. |
210 mouse_wheel_0 = CreateMouseWheel(1, 1); | 225 mouse_wheel_0 = CreateMouseWheel(1, 1); |
211 mouse_wheel_1 = CreateMouseWheel(1, 1); | 226 mouse_wheel_1 = CreateMouseWheel(1, 1); |
212 mouse_wheel_0.modifiers = blink::WebInputEvent::ControlKey; | 227 mouse_wheel_0.event.modifiers = blink::WebInputEvent::ControlKey; |
213 mouse_wheel_1.modifiers = blink::WebInputEvent::ShiftKey; | 228 mouse_wheel_1.event.modifiers = blink::WebInputEvent::ShiftKey; |
214 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(mouse_wheel_0, mouse_wheel_1)); | 229 EXPECT_FALSE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); |
215 } | 230 } |
216 | 231 |
217 // Coalescing preserves the newer timestamp. | 232 // Coalescing preserves the newer timestamp. |
218 TEST_F(WebInputEventTraitsTest, TimestampCoalescing) { | 233 TEST_F(WebInputEventTraitsTest, TimestampCoalescing) { |
219 WebMouseWheelEvent mouse_wheel_0 = CreateMouseWheel(1, 1); | 234 MouseWheelEventWithLatencyInfo mouse_wheel_0 = CreateMouseWheel(1, 1); |
220 mouse_wheel_0.timeStampSeconds = 5.0; | 235 mouse_wheel_0.event.timeStampSeconds = 5.0; |
221 WebMouseWheelEvent mouse_wheel_1 = CreateMouseWheel(2, 2); | 236 MouseWheelEventWithLatencyInfo mouse_wheel_1 = CreateMouseWheel(2, 2); |
222 mouse_wheel_1.timeStampSeconds = 10.0; | 237 mouse_wheel_1.event.timeStampSeconds = 10.0; |
223 | 238 |
224 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(mouse_wheel_0, mouse_wheel_1)); | 239 EXPECT_TRUE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); |
225 WebInputEventTraits::Coalesce(mouse_wheel_1, &mouse_wheel_0); | 240 Coalesce(mouse_wheel_1, &mouse_wheel_0); |
226 EXPECT_EQ(10.0, mouse_wheel_0.timeStampSeconds); | 241 EXPECT_EQ(10.0, mouse_wheel_0.event.timeStampSeconds); |
227 } | 242 } |
228 | 243 |
229 // Very basic smoke test to ensure stringification doesn't explode. | 244 // Very basic smoke test to ensure stringification doesn't explode. |
230 TEST_F(WebInputEventTraitsTest, ToString) { | 245 TEST_F(WebInputEventTraitsTest, ToString) { |
231 WebKeyboardEvent key; | 246 WebKeyboardEvent key; |
232 key.type = WebInputEvent::RawKeyDown; | 247 key.type = WebInputEvent::RawKeyDown; |
233 EXPECT_FALSE(WebInputEventTraits::ToString(key).empty()); | 248 EXPECT_FALSE(WebInputEventTraits::ToString(key).empty()); |
234 | 249 |
235 WebMouseEvent mouse; | 250 WebMouseEvent mouse; |
236 mouse.type = WebInputEvent::MouseMove; | 251 mouse.type = WebInputEvent::MouseMove; |
237 EXPECT_FALSE(WebInputEventTraits::ToString(mouse).empty()); | 252 EXPECT_FALSE(WebInputEventTraits::ToString(mouse).empty()); |
238 | 253 |
239 WebMouseWheelEvent mouse_wheel; | 254 WebMouseWheelEvent mouse_wheel; |
240 mouse_wheel.type = WebInputEvent::MouseWheel; | 255 mouse_wheel.type = WebInputEvent::MouseWheel; |
241 EXPECT_FALSE(WebInputEventTraits::ToString(mouse_wheel).empty()); | 256 EXPECT_FALSE(WebInputEventTraits::ToString(mouse_wheel).empty()); |
242 | 257 |
243 WebGestureEvent gesture = | 258 WebGestureEvent gesture; |
244 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); | 259 gesture.type = WebInputEvent::GesturePinchBegin; |
| 260 gesture.x = 1; |
| 261 gesture.y = 1; |
245 EXPECT_FALSE(WebInputEventTraits::ToString(gesture).empty()); | 262 EXPECT_FALSE(WebInputEventTraits::ToString(gesture).empty()); |
246 | 263 |
247 WebTouchEvent touch = CreateTouch(WebInputEvent::TouchStart); | 264 WebTouchEvent touch; |
| 265 touch.type = WebInputEvent::TouchStart; |
| 266 touch.touchesLength = 1; |
248 EXPECT_FALSE(WebInputEventTraits::ToString(touch).empty()); | 267 EXPECT_FALSE(WebInputEventTraits::ToString(touch).empty()); |
249 } | 268 } |
250 | 269 |
251 } // namespace | 270 } // namespace |
252 } // namespace content | 271 } // namespace content |
OLD | NEW |