| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/event_with_latency_info.h" | 5 #include "content/common/input/event_with_latency_info.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/platform/WebInputEvent.h" | 10 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 11 | 11 |
| 12 using blink::WebGestureEvent; | 12 using blink::WebGestureEvent; |
| 13 using blink::WebInputEvent; | 13 using blink::WebInputEvent; |
| 14 using blink::WebMouseEvent; | 14 using blink::WebMouseEvent; |
| 15 using blink::WebMouseWheelEvent; | 15 using blink::WebMouseWheelEvent; |
| 16 using blink::WebTouchEvent; | 16 using blink::WebTouchEvent; |
| 17 using blink::WebTouchPoint; | 17 using blink::WebTouchPoint; |
| 18 using std::numeric_limits; | 18 using std::numeric_limits; |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 using EventWithLatencyInfoTest = testing::Test; | 23 using EventWithLatencyInfoTest = testing::Test; |
| 24 | 24 |
| 25 TouchEventWithLatencyInfo CreateTouchEvent(WebInputEvent::Type type, | 25 TouchEventWithLatencyInfo CreateTouchEvent(WebInputEvent::Type type, |
| 26 double timestamp, | 26 double timestamp, |
| 27 unsigned touch_count = 1) { | 27 unsigned touch_count = 1) { |
| 28 TouchEventWithLatencyInfo touch; | 28 TouchEventWithLatencyInfo touch(type, WebInputEvent::NoModifiers, timestamp, |
| 29 ui::LatencyInfo()); |
| 29 touch.event.touchesLength = touch_count; | 30 touch.event.touchesLength = touch_count; |
| 30 touch.event.type = type; | |
| 31 touch.event.timeStampSeconds = timestamp; | |
| 32 return touch; | 31 return touch; |
| 33 } | 32 } |
| 34 | 33 |
| 35 MouseEventWithLatencyInfo CreateMouseEvent(WebInputEvent::Type type, | 34 MouseEventWithLatencyInfo CreateMouseEvent(WebInputEvent::Type type, |
| 36 double timestamp) { | 35 double timestamp) { |
| 37 MouseEventWithLatencyInfo mouse; | 36 return MouseEventWithLatencyInfo(type, WebInputEvent::NoModifiers, timestamp, |
| 38 mouse.event.type = type; | 37 ui::LatencyInfo()); |
| 39 mouse.event.timeStampSeconds = timestamp; | |
| 40 return mouse; | |
| 41 } | 38 } |
| 42 | 39 |
| 43 MouseWheelEventWithLatencyInfo CreateMouseWheelEvent(double timestamp, | 40 MouseWheelEventWithLatencyInfo CreateMouseWheelEvent( |
| 44 float deltaX = 0.0f, | 41 double timestamp, |
| 45 float deltaY = 0.0f) { | 42 float deltaX = 0.0f, |
| 46 MouseWheelEventWithLatencyInfo mouse_wheel; | 43 float deltaY = 0.0f, |
| 47 mouse_wheel.event.type = WebInputEvent::MouseWheel; | 44 int modifiers = WebInputEvent::NoModifiers) { |
| 45 MouseWheelEventWithLatencyInfo mouse_wheel( |
| 46 WebInputEvent::MouseWheel, modifiers, timestamp, ui::LatencyInfo()); |
| 48 mouse_wheel.event.deltaX = deltaX; | 47 mouse_wheel.event.deltaX = deltaX; |
| 49 mouse_wheel.event.deltaY = deltaY; | 48 mouse_wheel.event.deltaY = deltaY; |
| 50 mouse_wheel.event.timeStampSeconds = timestamp; | |
| 51 return mouse_wheel; | 49 return mouse_wheel; |
| 52 } | 50 } |
| 53 | 51 |
| 54 GestureEventWithLatencyInfo CreateGestureEvent(WebInputEvent::Type type, | 52 GestureEventWithLatencyInfo CreateGestureEvent(WebInputEvent::Type type, |
| 55 double timestamp, | 53 double timestamp, |
| 56 float x = 0.0f, | 54 float x = 0.0f, |
| 57 float y = 0.0f) { | 55 float y = 0.0f) { |
| 58 GestureEventWithLatencyInfo gesture; | 56 GestureEventWithLatencyInfo gesture(type, WebInputEvent::NoModifiers, |
| 59 gesture.event.type = type; | 57 timestamp, ui::LatencyInfo()); |
| 60 gesture.event.x = x; | 58 gesture.event.x = x; |
| 61 gesture.event.y = y; | 59 gesture.event.y = y; |
| 62 gesture.event.timeStampSeconds = timestamp; | |
| 63 return gesture; | 60 return gesture; |
| 64 } | 61 } |
| 65 | 62 |
| 66 TEST_F(EventWithLatencyInfoTest, TimestampCoalescingForMouseEvent) { | 63 TEST_F(EventWithLatencyInfoTest, TimestampCoalescingForMouseEvent) { |
| 67 MouseEventWithLatencyInfo mouse_0 = CreateMouseEvent( | 64 MouseEventWithLatencyInfo mouse_0 = CreateMouseEvent( |
| 68 WebInputEvent::MouseMove, 5.0); | 65 WebInputEvent::MouseMove, 5.0); |
| 69 MouseEventWithLatencyInfo mouse_1 = CreateMouseEvent( | 66 MouseEventWithLatencyInfo mouse_1 = CreateMouseEvent( |
| 70 WebInputEvent::MouseMove, 10.0); | 67 WebInputEvent::MouseMove, 10.0); |
| 71 | 68 |
| 72 ASSERT_TRUE(mouse_0.CanCoalesceWith(mouse_1)); | 69 ASSERT_TRUE(mouse_0.CanCoalesceWith(mouse_1)); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 297 } |
| 301 | 298 |
| 302 TEST_F(EventWithLatencyInfoTest, WebMouseWheelEventCoalescing) { | 299 TEST_F(EventWithLatencyInfoTest, WebMouseWheelEventCoalescing) { |
| 303 MouseWheelEventWithLatencyInfo mouse_wheel_0 = CreateMouseWheel(1, 1); | 300 MouseWheelEventWithLatencyInfo mouse_wheel_0 = CreateMouseWheel(1, 1); |
| 304 MouseWheelEventWithLatencyInfo mouse_wheel_1 = CreateMouseWheel(2, 2); | 301 MouseWheelEventWithLatencyInfo mouse_wheel_1 = CreateMouseWheel(2, 2); |
| 305 // WebMouseWheelEvent objects with same values except different deltaX and | 302 // WebMouseWheelEvent objects with same values except different deltaX and |
| 306 // deltaY should coalesce. | 303 // deltaY should coalesce. |
| 307 EXPECT_TRUE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); | 304 EXPECT_TRUE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); |
| 308 | 305 |
| 309 // WebMouseWheelEvent objects with different modifiers should not coalesce. | 306 // WebMouseWheelEvent objects with different modifiers should not coalesce. |
| 310 mouse_wheel_0 = CreateMouseWheel(1, 1); | 307 mouse_wheel_0 = CreateMouseWheelEvent(2.0, 1, 1, WebInputEvent::ControlKey); |
| 311 mouse_wheel_1 = CreateMouseWheel(1, 1); | 308 mouse_wheel_1 = CreateMouseWheelEvent(2.0, 1, 1, WebInputEvent::ShiftKey); |
| 312 mouse_wheel_0.event.modifiers = WebInputEvent::ControlKey; | |
| 313 mouse_wheel_1.event.modifiers = WebInputEvent::ShiftKey; | |
| 314 EXPECT_FALSE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); | 309 EXPECT_FALSE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); |
| 315 | 310 |
| 316 // Coalesce old and new events. | 311 // Coalesce old and new events. |
| 317 mouse_wheel_0 = CreateMouseWheel(1, 1); | 312 mouse_wheel_0 = CreateMouseWheel(1, 1); |
| 318 mouse_wheel_0.event.x = 1; | 313 mouse_wheel_0.event.x = 1; |
| 319 mouse_wheel_0.event.y = 1; | 314 mouse_wheel_0.event.y = 1; |
| 320 mouse_wheel_1 = CreateMouseWheel(2, 2); | 315 mouse_wheel_1 = CreateMouseWheel(2, 2); |
| 321 mouse_wheel_1.event.x = 2; | 316 mouse_wheel_1.event.x = 2; |
| 322 mouse_wheel_1.event.y = 2; | 317 mouse_wheel_1.event.y = 2; |
| 323 MouseWheelEventWithLatencyInfo mouse_wheel_1_copy = mouse_wheel_1; | 318 MouseWheelEventWithLatencyInfo mouse_wheel_1_copy = mouse_wheel_1; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 348 mouse_wheel_1_copy.event.wheelTicksY + mouse_wheel_0.event.wheelTicksY, | 343 mouse_wheel_1_copy.event.wheelTicksY + mouse_wheel_0.event.wheelTicksY, |
| 349 mouse_wheel_1.event.wheelTicksY); | 344 mouse_wheel_1.event.wheelTicksY); |
| 350 EXPECT_EQ(mouse_wheel_1_copy.event.movementX + mouse_wheel_0.event.movementX, | 345 EXPECT_EQ(mouse_wheel_1_copy.event.movementX + mouse_wheel_0.event.movementX, |
| 351 mouse_wheel_1.event.movementX); | 346 mouse_wheel_1.event.movementX); |
| 352 EXPECT_EQ(mouse_wheel_1_copy.event.movementY + mouse_wheel_0.event.movementY, | 347 EXPECT_EQ(mouse_wheel_1_copy.event.movementY + mouse_wheel_0.event.movementY, |
| 353 mouse_wheel_1.event.movementY); | 348 mouse_wheel_1.event.movementY); |
| 354 } | 349 } |
| 355 | 350 |
| 356 // Coalescing preserves the newer timestamp. | 351 // Coalescing preserves the newer timestamp. |
| 357 TEST_F(EventWithLatencyInfoTest, TimestampCoalescing) { | 352 TEST_F(EventWithLatencyInfoTest, TimestampCoalescing) { |
| 358 MouseWheelEventWithLatencyInfo mouse_wheel_0 = CreateMouseWheel(1, 1); | 353 MouseWheelEventWithLatencyInfo mouse_wheel_0 = |
| 359 mouse_wheel_0.event.timeStampSeconds = 5.0; | 354 CreateMouseWheelEvent(5.0, 1, 1); |
| 360 MouseWheelEventWithLatencyInfo mouse_wheel_1 = CreateMouseWheel(2, 2); | 355 MouseWheelEventWithLatencyInfo mouse_wheel_1 = |
| 361 mouse_wheel_1.event.timeStampSeconds = 10.0; | 356 CreateMouseWheelEvent(10.0, 2, 2); |
| 362 | 357 |
| 363 EXPECT_TRUE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); | 358 EXPECT_TRUE(CanCoalesce(mouse_wheel_0, mouse_wheel_1)); |
| 364 Coalesce(mouse_wheel_1, &mouse_wheel_0); | 359 Coalesce(mouse_wheel_1, &mouse_wheel_0); |
| 365 EXPECT_EQ(10.0, mouse_wheel_0.event.timeStampSeconds); | 360 EXPECT_EQ(10.0, mouse_wheel_0.event.timeStampSeconds); |
| 366 } | 361 } |
| 367 | 362 |
| 368 } // namespace | 363 } // namespace |
| 369 } // namespace content | 364 } // namespace content |
| OLD | NEW |