| 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 } | |
| 65 }; | 54 }; |
| 66 | 55 |
| 67 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { | 56 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { |
| 68 WebTouchEvent touch0 = CreateTouch(WebInputEvent::TouchStart); | 57 WebTouchEvent touch0 = CreateTouch(WebInputEvent::TouchStart); |
| 69 WebTouchEvent touch1 = CreateTouch(WebInputEvent::TouchMove); | 58 WebTouchEvent touch1 = CreateTouch(WebInputEvent::TouchMove); |
| 70 | 59 |
| 71 // Non touch-moves won't coalesce. | 60 // Non touch-moves won't coalesce. |
| 72 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0)); | 61 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0)); |
| 73 | 62 |
| 74 // Touches of different types won't coalesce. | 63 // Touches of different types won't coalesce. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // Scales have a maximum value and can never reach Infinity. | 155 // Scales have a maximum value and can never reach Infinity. |
| 167 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 156 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
| 168 pinch0.data.pinchUpdate.scale = numeric_limits<float>::max() / 2.0f; | 157 pinch0.data.pinchUpdate.scale = numeric_limits<float>::max() / 2.0f; |
| 169 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 158 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
| 170 pinch1.data.pinchUpdate.scale = 10.0f; | 159 pinch1.data.pinchUpdate.scale = 10.0f; |
| 171 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); | 160 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); |
| 172 WebInputEventTraits::Coalesce(pinch0, &pinch1); | 161 WebInputEventTraits::Coalesce(pinch0, &pinch1); |
| 173 EXPECT_EQ(numeric_limits<float>::max(), pinch1.data.pinchUpdate.scale); | 162 EXPECT_EQ(numeric_limits<float>::max(), pinch1.data.pinchUpdate.scale); |
| 174 } | 163 } |
| 175 | 164 |
| 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 | |
| 201 // Very basic smoke test to ensure stringification doesn't explode. | 165 // Very basic smoke test to ensure stringification doesn't explode. |
| 202 TEST_F(WebInputEventTraitsTest, ToString) { | 166 TEST_F(WebInputEventTraitsTest, ToString) { |
| 203 WebKeyboardEvent key; | 167 WebKeyboardEvent key; |
| 204 key.type = WebInputEvent::RawKeyDown; | 168 key.type = WebInputEvent::RawKeyDown; |
| 205 EXPECT_FALSE(WebInputEventTraits::ToString(key).empty()); | 169 EXPECT_FALSE(WebInputEventTraits::ToString(key).empty()); |
| 206 | 170 |
| 207 WebMouseEvent mouse; | 171 WebMouseEvent mouse; |
| 208 mouse.type = WebInputEvent::MouseMove; | 172 mouse.type = WebInputEvent::MouseMove; |
| 209 EXPECT_FALSE(WebInputEventTraits::ToString(mouse).empty()); | 173 EXPECT_FALSE(WebInputEventTraits::ToString(mouse).empty()); |
| 210 | 174 |
| 211 WebMouseWheelEvent mouse_wheel; | 175 WebMouseWheelEvent mouse_wheel; |
| 212 mouse_wheel.type = WebInputEvent::MouseWheel; | 176 mouse_wheel.type = WebInputEvent::MouseWheel; |
| 213 EXPECT_FALSE(WebInputEventTraits::ToString(mouse_wheel).empty()); | 177 EXPECT_FALSE(WebInputEventTraits::ToString(mouse_wheel).empty()); |
| 214 | 178 |
| 215 WebGestureEvent gesture = | 179 WebGestureEvent gesture = |
| 216 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); | 180 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); |
| 217 EXPECT_FALSE(WebInputEventTraits::ToString(gesture).empty()); | 181 EXPECT_FALSE(WebInputEventTraits::ToString(gesture).empty()); |
| 218 | 182 |
| 219 WebTouchEvent touch = CreateTouch(WebInputEvent::TouchStart); | 183 WebTouchEvent touch = CreateTouch(WebInputEvent::TouchStart); |
| 220 EXPECT_FALSE(WebInputEventTraits::ToString(touch).empty()); | 184 EXPECT_FALSE(WebInputEventTraits::ToString(touch).empty()); |
| 221 } | 185 } |
| 222 | 186 |
| 223 } // namespace | 187 } // namespace |
| 224 } // namespace content | 188 } // namespace content |
| OLD | NEW |