Chromium Code Reviews| 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(WebInputEvent::Type type, | |
|
Rick Byers
2014/12/12 22:20:29
no need to take a 'type' here - unlike touch/gestu
lanwei
2014/12/17 23:16:40
Done.
| |
| 56 bool canScroll) { | |
| 57 WebMouseWheelEvent event; | |
| 58 event.type = type; | |
| 59 event.canScroll = canScroll; | |
| 60 return event; | |
| 61 } | |
| 54 }; | 62 }; |
| 55 | 63 |
| 56 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { | 64 TEST_F(WebInputEventTraitsTest, TouchEventCoalescing) { |
| 57 WebTouchEvent touch0 = CreateTouch(WebInputEvent::TouchStart); | 65 WebTouchEvent touch0 = CreateTouch(WebInputEvent::TouchStart); |
| 58 WebTouchEvent touch1 = CreateTouch(WebInputEvent::TouchMove); | 66 WebTouchEvent touch1 = CreateTouch(WebInputEvent::TouchMove); |
| 59 | 67 |
| 60 // Non touch-moves won't coalesce. | 68 // Non touch-moves won't coalesce. |
| 61 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0)); | 69 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(touch0, touch0)); |
| 62 | 70 |
| 63 // Touches of different types won't coalesce. | 71 // 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. | 163 // Scales have a maximum value and can never reach Infinity. |
| 156 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 164 pinch0 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
| 157 pinch0.data.pinchUpdate.scale = numeric_limits<float>::max() / 2.0f; | 165 pinch0.data.pinchUpdate.scale = numeric_limits<float>::max() / 2.0f; |
| 158 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); | 166 pinch1 = CreateGesture(WebInputEvent::GesturePinchUpdate, 1, 1); |
| 159 pinch1.data.pinchUpdate.scale = 10.0f; | 167 pinch1.data.pinchUpdate.scale = 10.0f; |
| 160 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); | 168 EXPECT_TRUE(WebInputEventTraits::CanCoalesce(pinch0, pinch1)); |
| 161 WebInputEventTraits::Coalesce(pinch0, &pinch1); | 169 WebInputEventTraits::Coalesce(pinch0, &pinch1); |
| 162 EXPECT_EQ(numeric_limits<float>::max(), pinch1.data.pinchUpdate.scale); | 170 EXPECT_EQ(numeric_limits<float>::max(), pinch1.data.pinchUpdate.scale); |
| 163 } | 171 } |
| 164 | 172 |
| 173 TEST_F(WebInputEventTraitsTest, WebMouseWheelEventCoalescing) { | |
| 174 WebMouseWheelEvent mouseWheel0 = | |
| 175 CreateMouseWheel(WebInputEvent::MouseWheel, true); | |
| 176 WebMouseWheelEvent mouseWheel1 = | |
| 177 CreateMouseWheel(WebInputEvent::MouseWheel, false); | |
| 178 | |
| 179 // WebMouseWheelEvent objects with different canScroll values should not | |
|
Rick Byers
2014/12/12 22:20:29
please add a baseline that verifies CanCoalesce ev
lanwei
2014/12/17 23:16:40
Done.
| |
| 180 // coalesce. | |
| 181 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(mouseWheel0, mouseWheel1)); | |
| 182 | |
| 183 // WebMouseWheelEvent objects with different modifiers should not coalesce. | |
| 184 mouseWheel0 = CreateMouseWheel(WebInputEvent::MouseWheel, true); | |
| 185 mouseWheel1 = CreateMouseWheel(WebInputEvent::MouseWheel, true); | |
| 186 mouseWheel0.modifiers = blink::WebInputEvent::ControlKey; | |
| 187 mouseWheel1.modifiers = blink::WebInputEvent::ShiftKey; | |
| 188 EXPECT_FALSE(WebInputEventTraits::CanCoalesce(mouseWheel0, mouseWheel1)); | |
| 189 } | |
| 190 | |
| 165 // Very basic smoke test to ensure stringification doesn't explode. | 191 // Very basic smoke test to ensure stringification doesn't explode. |
| 166 TEST_F(WebInputEventTraitsTest, ToString) { | 192 TEST_F(WebInputEventTraitsTest, ToString) { |
| 167 WebKeyboardEvent key; | 193 WebKeyboardEvent key; |
| 168 key.type = WebInputEvent::RawKeyDown; | 194 key.type = WebInputEvent::RawKeyDown; |
| 169 EXPECT_FALSE(WebInputEventTraits::ToString(key).empty()); | 195 EXPECT_FALSE(WebInputEventTraits::ToString(key).empty()); |
| 170 | 196 |
| 171 WebMouseEvent mouse; | 197 WebMouseEvent mouse; |
| 172 mouse.type = WebInputEvent::MouseMove; | 198 mouse.type = WebInputEvent::MouseMove; |
| 173 EXPECT_FALSE(WebInputEventTraits::ToString(mouse).empty()); | 199 EXPECT_FALSE(WebInputEventTraits::ToString(mouse).empty()); |
| 174 | 200 |
| 175 WebMouseWheelEvent mouse_wheel; | 201 WebMouseWheelEvent mouse_wheel; |
| 176 mouse_wheel.type = WebInputEvent::MouseWheel; | 202 mouse_wheel.type = WebInputEvent::MouseWheel; |
| 177 EXPECT_FALSE(WebInputEventTraits::ToString(mouse_wheel).empty()); | 203 EXPECT_FALSE(WebInputEventTraits::ToString(mouse_wheel).empty()); |
| 178 | 204 |
| 179 WebGestureEvent gesture = | 205 WebGestureEvent gesture = |
| 180 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); | 206 CreateGesture(WebInputEvent::GesturePinchBegin, 1, 1); |
| 181 EXPECT_FALSE(WebInputEventTraits::ToString(gesture).empty()); | 207 EXPECT_FALSE(WebInputEventTraits::ToString(gesture).empty()); |
| 182 | 208 |
| 183 WebTouchEvent touch = CreateTouch(WebInputEvent::TouchStart); | 209 WebTouchEvent touch = CreateTouch(WebInputEvent::TouchStart); |
| 184 EXPECT_FALSE(WebInputEventTraits::ToString(touch).empty()); | 210 EXPECT_FALSE(WebInputEventTraits::ToString(touch).empty()); |
| 185 } | 211 } |
| 186 | 212 |
| 187 } // namespace | 213 } // namespace |
| 188 } // namespace content | 214 } // namespace content |
| OLD | NEW |