1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/events/latency_info.h"
7 #include "testing/gtest/include/gtest/gtest.h"
11 TEST(LatencyInfoTest
, AddTwoSeparateEvent
) {
13 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT
,
16 base::TimeTicks::FromInternalValue(100),
19 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
22 base::TimeTicks::FromInternalValue(1000),
26 EXPECT_EQ(info
.latency_components
.size(), 2u);
27 LatencyInfo::LatencyComponent component
;
29 info
.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, &component
));
31 info
.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT
, 1, &component
));
33 info
.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT
, 0, &component
));
34 EXPECT_EQ(component
.sequence_number
, 1);
35 EXPECT_EQ(component
.event_count
, 1u);
36 EXPECT_EQ(component
.event_time
.ToInternalValue(), 100);
38 info
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 1, &component
));
39 EXPECT_EQ(component
.sequence_number
, 5);
40 EXPECT_EQ(component
.event_count
, 2u);
41 EXPECT_EQ(component
.event_time
.ToInternalValue(), 1000);
44 TEST(LatencyInfoTest
, AddTwoSameEvent
) {
46 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
49 base::TimeTicks::FromInternalValue(100),
52 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
55 base::TimeTicks::FromInternalValue(200),
59 EXPECT_EQ(info
.latency_components
.size(), 1u);
60 LatencyInfo::LatencyComponent component
;
62 info
.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, &component
));
64 info
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 1, &component
));
66 info
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 0, &component
));
67 EXPECT_EQ(component
.sequence_number
, 30);
68 EXPECT_EQ(component
.event_count
, 5u);
69 EXPECT_EQ(component
.event_time
.ToInternalValue(), (100 * 2 + 200 * 3) / 5);
72 TEST(LatencyInfoTest
, MergeTwoSeparateEvent
) {
75 info1
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT
,
78 base::TimeTicks::FromInternalValue(100),
81 info2
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
84 base::TimeTicks::FromInternalValue(1000),
87 info1
.MergeWith(info2
);
89 EXPECT_EQ(info1
.latency_components
.size(), 2u);
90 LatencyInfo::LatencyComponent component
;
92 info1
.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, &component
));
93 EXPECT_FALSE(info1
.FindLatency(
94 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT
, 1, &component
));
95 EXPECT_TRUE(info1
.FindLatency(
96 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT
, 0, &component
));
97 EXPECT_EQ(component
.sequence_number
, 1);
98 EXPECT_EQ(component
.event_count
, 1u);
99 EXPECT_EQ(component
.event_time
.ToInternalValue(), 100);
101 info1
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 1, &component
));
102 EXPECT_EQ(component
.sequence_number
, 5);
103 EXPECT_EQ(component
.event_count
, 2u);
104 EXPECT_EQ(component
.event_time
.ToInternalValue(), 1000);
107 TEST(LatencyInfoTest
, MergeTwoSameEvent
) {
110 info1
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
113 base::TimeTicks::FromInternalValue(100),
116 info2
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
119 base::TimeTicks::FromInternalValue(200),
122 info1
.MergeWith(info2
);
124 EXPECT_EQ(info1
.latency_components
.size(), 1u);
125 LatencyInfo::LatencyComponent component
;
127 info1
.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, &component
));
129 info1
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 1, &component
));
131 info1
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 0, &component
));
132 EXPECT_EQ(component
.sequence_number
, 30);
133 EXPECT_EQ(component
.event_count
, 5u);
134 EXPECT_EQ(component
.event_time
.ToInternalValue(), (100 * 2 + 200 * 3) / 5);
137 TEST(LatencyInfoTest
, ClearEvents
) {
139 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
142 base::TimeTicks::FromInternalValue(100),
146 EXPECT_EQ(info
.latency_components
.size(), 1u);
148 EXPECT_EQ(info
.latency_components
.size(), 0u);