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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/WebKit/public/web/WebInputEvent.h" | 10 #include "third_party/WebKit/public/web/WebInputEvent.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 static WebGestureEvent CreateGesture(WebInputEvent::Type type, | 45 static WebGestureEvent CreateGesture(WebInputEvent::Type type, |
46 float x, | 46 float x, |
47 float y) { | 47 float y) { |
48 WebGestureEvent event; | 48 WebGestureEvent event; |
49 event.type = type; | 49 event.type = type; |
50 event.x = x; | 50 event.x = x; |
51 event.y = y; | 51 event.y = y; |
52 return event; | 52 return event; |
53 } | 53 } |
| 54 |
| 55 static WebMouseWheelEvent CreateMouseWheel(float deltaX, |
| 56 float deltaY, |
| 57 bool canScroll) { |
| 58 WebMouseWheelEvent event; |
| 59 event.type = WebInputEvent::MouseWheel; |
| 60 event.deltaX = deltaX; |
| 61 event.deltaY = deltaY; |
| 62 event.canScroll = canScroll; |
| 63 return event; |
| 64 } |
54 }; | 65 }; |
55 | 66 |
56 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { | 67 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { |
57 WebTouchEvent touch0 = CreateTouch(WebInputEvent::TouchStart); | 68 WebTouchEvent touch0 = CreateTouch(WebInputEvent::TouchStart); |
58 WebTouchEvent touch1 = CreateTouch(WebInputEvent::TouchMove); | 69 WebTouchEvent touch1 = CreateTouch(WebInputEvent::TouchMove); |
59 | 70 |
60 // Non touch-moves won't coalesce. | 71 // Non touch-moves won't coalesce. |
61 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0)); | 72 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0)); |
62 | 73 |
63 // Touches of different types won't coalesce. | 74 // Touches of different types won't coalesce. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 // Scales have a maximum value and can never reach Infinity. | 166 // Scales have a maximum value and can never reach Infinity. |
156 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 167 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
157 pinch0.data.pinchUpdate.scale = numeric_limits<float>::max() / 2.0f; | 168 pinch0.data.pinchUpdate.scale = numeric_limits<float>::max() / 2.0f; |
158 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 169 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
159 pinch1.data.pinchUpdate.scale = 10.0f; | 170 pinch1.data.pinchUpdate.scale = 10.0f; |
160 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); | 171 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); |
161 WebInputEventTraits::Coalesce(pinch0, &pinch1); | 172 WebInputEventTraits::Coalesce(pinch0, &pinch1); |
162 EXPECT_EQ(numeric_limits<float>::max(), pinch1.data.pinchUpdate.scale); | 173 EXPECT_EQ(numeric_limits<float>::max(), pinch1.data.pinchUpdate.scale); |
163 } | 174 } |
164 | 175 |
| 176 TEST_F(WebInputEventTraitsTest, WebMouseWheelEventCoalescing) { |
| 177 WebMouseWheelEvent mouseWheel0 = |
| 178 CreateMouseWheel(1, 1, true); |
| 179 WebMouseWheelEvent mouseWheel1 = |
| 180 CreateMouseWheel(2, 2, true); |
| 181 |
| 182 // WebMouseWheelEvent objects with same values except different deltaX and |
| 183 // deltaY should coalesce. |
| 184 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(mouseWheel0, mouseWheel1)); |
| 185 |
| 186 mouseWheel0 = CreateMouseWheel(1, 1, true); |
| 187 mouseWheel1 = CreateMouseWheel(1, 1, false); |
| 188 |
| 189 // WebMouseWheelEvent objects with different canScroll values should not |
| 190 // coalesce. |
| 191 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(mouseWheel0, mouseWheel1)); |
| 192 |
| 193 // WebMouseWheelEvent objects with different modifiers should not coalesce. |
| 194 mouseWheel0 = CreateMouseWheel(1, 1, true); |
| 195 mouseWheel1 = CreateMouseWheel(1, 1, true); |
| 196 mouseWheel0.modifiers = blink::WebInputEvent::ControlKey; |
| 197 mouseWheel1.modifiers = blink::WebInputEvent::ShiftKey; |
| 198 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(mouseWheel0, mouseWheel1)); |
| 199 } |
| 200 |
165 // Very basic smoke test to ensure stringification doesn't explode. | 201 // Very basic smoke test to ensure stringification doesn't explode. |
166 TEST_F(WebInputEventTraitsTest, ToString) { | 202 TEST_F(WebInputEventTraitsTest, ToString) { |
167 WebKeyboardEvent key; | 203 WebKeyboardEvent key; |
168 key.type = WebInputEvent::RawKeyDown; | 204 key.type = WebInputEvent::RawKeyDown; |
169 EXPECT_FALSE(WebInputEventTraits::ToString(key).empty()); | 205 EXPECT_FALSE(WebInputEventTraits::ToString(key).empty()); |
170 | 206 |
171 WebMouseEvent mouse; | 207 WebMouseEvent mouse; |
172 mouse.type = WebInputEvent::MouseMove; | 208 mouse.type = WebInputEvent::MouseMove; |
173 EXPECT_FALSE(WebInputEventTraits::ToString(mouse).empty()); | 209 EXPECT_FALSE(WebInputEventTraits::ToString(mouse).empty()); |
174 | 210 |
175 WebMouseWheelEvent mouse_wheel; | 211 WebMouseWheelEvent mouse_wheel; |
176 mouse_wheel.type = WebInputEvent::MouseWheel; | 212 mouse_wheel.type = WebInputEvent::MouseWheel; |
177 EXPECT_FALSE(WebInputEventTraits::ToString(mouse_wheel).empty()); | 213 EXPECT_FALSE(WebInputEventTraits::ToString(mouse_wheel).empty()); |
178 | 214 |
179 WebGestureEvent gesture = | 215 WebGestureEvent gesture = |
180 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); | 216 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); |
181 EXPECT_FALSE(WebInputEventTraits::ToString(gesture).empty()); | 217 EXPECT_FALSE(WebInputEventTraits::ToString(gesture).empty()); |
182 | 218 |
183 WebTouchEvent touch = CreateTouch(WebInputEvent::TouchStart); | 219 WebTouchEvent touch = CreateTouch(WebInputEvent::TouchStart); |
184 EXPECT_FALSE(WebInputEventTraits::ToString(touch).empty()); | 220 EXPECT_FALSE(WebInputEventTraits::ToString(touch).empty()); |
185 } | 221 } |
186 | 222 |
187 } // namespace | 223 } // namespace |
188 } // namespace content | 224 } // namespace content |
OLD | NEW |