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),
18 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
21 base::TimeTicks::FromInternalValue(1000),
24 EXPECT_EQ(info
.latency_components
.size(), 2u);
25 LatencyInfo::LatencyComponent component
;
27 info
.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, &component
));
29 info
.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT
, 1, &component
));
31 info
.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT
, 0, &component
));
32 EXPECT_EQ(component
.sequence_number
, 1);
33 EXPECT_EQ(component
.event_count
, 1u);
34 EXPECT_EQ(component
.event_time
.ToInternalValue(), 100);
36 info
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 1, &component
));
37 EXPECT_EQ(component
.sequence_number
, 5);
38 EXPECT_EQ(component
.event_count
, 2u);
39 EXPECT_EQ(component
.event_time
.ToInternalValue(), 1000);
42 TEST(LatencyInfoTest
, AddTwoSameEvent
) {
44 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
47 base::TimeTicks::FromInternalValue(100),
49 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
52 base::TimeTicks::FromInternalValue(200),
55 EXPECT_EQ(info
.latency_components
.size(), 1u);
56 LatencyInfo::LatencyComponent component
;
58 info
.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT
, 0, &component
));
60 info
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 1, &component
));
62 info
.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
, 0, &component
));
63 EXPECT_EQ(component
.sequence_number
, 30);
64 EXPECT_EQ(component
.event_count
, 5u);
65 EXPECT_EQ(component
.event_time
.ToInternalValue(), (100 * 2 + 200 * 3) / 5);
68 TEST(LatencyInfoTest
, ClearEvents
) {
70 info
.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT
,
73 base::TimeTicks::FromInternalValue(100),
76 EXPECT_EQ(info
.latency_components
.size(), 1u);
78 EXPECT_EQ(info
.latency_components
.size(), 0u);