summaryrefslogtreecommitdiffstats
path: root/content/browser/renderer_host/event_with_latency_info_unittest.cc
blob: 42d490f8ad36d5e2cba85afdf81d3e8dbd81cb80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/renderer_host/event_with_latency_info.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"

using blink::WebGestureEvent;
using blink::WebInputEvent;
using blink::WebMouseEvent;
using blink::WebMouseWheelEvent;
using blink::WebTouchEvent;

namespace content {
namespace {

class EventWithLatencyInfoTest : public testing::Test {
 protected:
  TouchEventWithLatencyInfo CreateTouchEvent(WebInputEvent::Type type,
                                             double timestamp) {
    TouchEventWithLatencyInfo touch;
    touch.event.touchesLength = 1;
    touch.event.type = type;
    touch.event.timeStampSeconds = timestamp;
    return touch;
  }

  MouseEventWithLatencyInfo CreateMouseEvent(WebInputEvent::Type type,
                                             double timestamp) {
    MouseEventWithLatencyInfo mouse;
    mouse.event.type = type;
    mouse.event.timeStampSeconds = timestamp;
    return mouse;
  }

  MouseWheelEventWithLatencyInfo CreateMouseWheelEvent(double timestamp) {
    MouseWheelEventWithLatencyInfo mouse_wheel;
    mouse_wheel.event.type = WebInputEvent::MouseWheel;
    mouse_wheel.event.timeStampSeconds = timestamp;
    return mouse_wheel;
  }

  GestureEventWithLatencyInfo CreateGestureEvent(WebInputEvent::Type type,
                                                 double timestamp) {
    GestureEventWithLatencyInfo gesture;
    gesture.event.type = type;
    gesture.event.timeStampSeconds = timestamp;
    return gesture;
  }
};

TEST_F(EventWithLatencyInfoTest, TimestampCoalescingForMouseEvent) {
  MouseEventWithLatencyInfo mouse_0 = CreateMouseEvent(
      WebInputEvent::MouseMove, 5.0);
  MouseEventWithLatencyInfo mouse_1 = CreateMouseEvent(
      WebInputEvent::MouseMove, 10.0);

  ASSERT_TRUE(mouse_0.CanCoalesceWith(mouse_1));
  mouse_0.CoalesceWith(mouse_1);
  // Coalescing WebMouseEvent preserves newer timestamp.
  EXPECT_EQ(10.0, mouse_0.event.timeStampSeconds);
  ASSERT_EQ(1u, mouse_0.latency.coalesced_events_size());
  EXPECT_EQ(5.0, mouse_0.latency.timestamps_of_coalesced_events()[0]);
}

TEST_F(EventWithLatencyInfoTest, TimestampCoalescingForMouseWheelEvent) {
  MouseWheelEventWithLatencyInfo mouse_wheel_0 = CreateMouseWheelEvent(5.0);
  MouseWheelEventWithLatencyInfo mouse_wheel_1 = CreateMouseWheelEvent(10.0);

  ASSERT_TRUE(mouse_wheel_0.CanCoalesceWith(mouse_wheel_1));
  mouse_wheel_0.CoalesceWith(mouse_wheel_1);
  // Coalescing WebMouseWheelEvent preserves newer timestamp.
  EXPECT_EQ(10.0, mouse_wheel_0.event.timeStampSeconds);
  ASSERT_EQ(1u, mouse_wheel_0.latency.coalesced_events_size());
  EXPECT_EQ(5.0, mouse_wheel_0.latency.timestamps_of_coalesced_events()[0]);
}

TEST_F(EventWithLatencyInfoTest, TimestampCoalescingForTouchEvent) {
  TouchEventWithLatencyInfo touch_0 = CreateTouchEvent(
      WebInputEvent::TouchMove, 5.0);
  TouchEventWithLatencyInfo touch_1 = CreateTouchEvent(
      WebInputEvent::TouchMove, 10.0);

  ASSERT_TRUE(touch_0.CanCoalesceWith(touch_1));
  touch_0.CoalesceWith(touch_1);
  // Coalescing WebTouchEvent preserves newer timestamp.
  EXPECT_EQ(10.0, touch_0.event.timeStampSeconds);
  ASSERT_EQ(1u, touch_0.latency.coalesced_events_size());
  EXPECT_EQ(5.0, touch_0.latency.timestamps_of_coalesced_events()[0]);
}

TEST_F(EventWithLatencyInfoTest, TimestampCoalescingForGestureEvent) {
  GestureEventWithLatencyInfo scroll_0 = CreateGestureEvent(
      WebInputEvent::GestureScrollUpdate, 5.0);
  GestureEventWithLatencyInfo scroll_1 = CreateGestureEvent(
      WebInputEvent::GestureScrollUpdate, 10.0);

  ASSERT_TRUE(scroll_0.CanCoalesceWith(scroll_1));
  scroll_0.CoalesceWith(scroll_1);
  // Coalescing WebGestureEvent preserves newer timestamp.
  EXPECT_EQ(10.0, scroll_0.event.timeStampSeconds);
  ASSERT_EQ(1u, scroll_0.latency.coalesced_events_size());
  EXPECT_EQ(5.0, scroll_0.latency.timestamps_of_coalesced_events()[0]);
}

}  // namespace
}  // namespace content