summaryrefslogtreecommitdiff
path: root/chromium/ui/events/latency_info_unittest.cc
blob: 32bb86957655c9e60a03f7cbb05cbdc1a849c064 (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright 2013 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 "ui/events/latency_info.h"

#include "testing/gtest/include/gtest/gtest.h"

namespace ui {

TEST(LatencyInfoTest, AddTwoSeparateEvent) {
  LatencyInfo info;
  info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT,
                                     0,
                                     1,
                                     base::TimeTicks::FromInternalValue(100),
                                     1);
  info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
                                     1,
                                     5,
                                     base::TimeTicks::FromInternalValue(1000),
                                     2);

  EXPECT_EQ(info.latency_components.size(), 2u);
  LatencyInfo::LatencyComponent component;
  EXPECT_FALSE(
      info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
  EXPECT_FALSE(
      info.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component));
  EXPECT_TRUE(
      info.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component));
  EXPECT_EQ(component.sequence_number, 1);
  EXPECT_EQ(component.event_count, 1u);
  EXPECT_EQ(component.event_time.ToInternalValue(), 100);
  EXPECT_TRUE(
      info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component));
  EXPECT_EQ(component.sequence_number, 5);
  EXPECT_EQ(component.event_count, 2u);
  EXPECT_EQ(component.event_time.ToInternalValue(), 1000);
}

TEST(LatencyInfoTest, AddTwoSameEvent) {
  LatencyInfo info;
  info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT,
                                     0,
                                     30,
                                     base::TimeTicks::FromInternalValue(100),
                                     2);
  info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT,
                                     0,
                                     13,
                                     base::TimeTicks::FromInternalValue(200),
                                     3);

  EXPECT_EQ(info.latency_components.size(), 1u);
  LatencyInfo::LatencyComponent component;
  EXPECT_FALSE(
      info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
  EXPECT_FALSE(
      info.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component));
  EXPECT_TRUE(
      info.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component));
  EXPECT_EQ(component.sequence_number, 30);
  EXPECT_EQ(component.event_count, 5u);
  EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5);
}

TEST(LatencyInfoTest, MergeTwoSeparateEvent) {
  LatencyInfo info1;
  LatencyInfo info2;
  info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT,
                                      0,
                                      1,
                                      base::TimeTicks::FromInternalValue(100),
                                      1);
  info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
                                      1,
                                      5,
                                      base::TimeTicks::FromInternalValue(1000),
                                      2);
  info1.MergeWith(info2);

  EXPECT_EQ(info1.latency_components.size(), 2u);
  LatencyInfo::LatencyComponent component;
  EXPECT_FALSE(
      info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
  EXPECT_FALSE(
      info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component));
  EXPECT_TRUE(
      info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component));
  EXPECT_EQ(component.sequence_number, 1);
  EXPECT_EQ(component.event_count, 1u);
  EXPECT_EQ(component.event_time.ToInternalValue(), 100);
  EXPECT_TRUE(
      info1.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component));
  EXPECT_EQ(component.sequence_number, 5);
  EXPECT_EQ(component.event_count, 2u);
  EXPECT_EQ(component.event_time.ToInternalValue(), 1000);
}

TEST(LatencyInfoTest, MergeTwoSameEvent) {
  LatencyInfo info1;
  LatencyInfo info2;
  info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT,
                                      0,
                                      30,
                                      base::TimeTicks::FromInternalValue(100),
                                      2);
  info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT,
                                      0,
                                      13,
                                      base::TimeTicks::FromInternalValue(200),
                                      3);
  info1.MergeWith(info2);

  EXPECT_EQ(info1.latency_components.size(), 1u);
  LatencyInfo::LatencyComponent component;
  EXPECT_FALSE(
      info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
  EXPECT_FALSE(
      info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component));
  EXPECT_TRUE(
      info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component));
  EXPECT_EQ(component.sequence_number, 30);
  EXPECT_EQ(component.event_count, 5u);
  EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5);
}

TEST(LatencyInfoTest, ClearEvents) {
  LatencyInfo info;
  info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT,
                                     0,
                                     30,
                                     base::TimeTicks::FromInternalValue(100),
                                     2);

  EXPECT_EQ(info.latency_components.size(), 1u);
  info.Clear();
  EXPECT_EQ(info.latency_components.size(), 0u);
}

}  // namespace ui