Uprev polymer library to 2013-11-26
[chromium-blink-merge.git] / ui / events / latency_info_unittest.cc
blobec39a0dbcba3f675d2b62a90ccccaefeb392b425
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"
9 namespace ui {
11 TEST(LatencyInfoTest, AddTwoSeparateEvent) {
12 LatencyInfo info;
13 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
16 base::TimeTicks::FromInternalValue(100),
18 true);
19 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
22 base::TimeTicks::FromInternalValue(1000),
24 true);
26 EXPECT_EQ(info.latency_components.size(), 2u);
27 LatencyInfo::LatencyComponent component;
28 EXPECT_FALSE(
29 info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
30 EXPECT_FALSE(
31 info.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1, &component));
32 EXPECT_TRUE(
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);
37 EXPECT_TRUE(
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) {
45 LatencyInfo info;
46 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
48 30,
49 base::TimeTicks::FromInternalValue(100),
51 true);
52 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
54 13,
55 base::TimeTicks::FromInternalValue(200),
57 true);
59 EXPECT_EQ(info.latency_components.size(), 1u);
60 LatencyInfo::LatencyComponent component;
61 EXPECT_FALSE(
62 info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
63 EXPECT_FALSE(
64 info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component));
65 EXPECT_TRUE(
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) {
73 LatencyInfo info1;
74 LatencyInfo info2;
75 info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
78 base::TimeTicks::FromInternalValue(100),
80 true);
81 info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
84 base::TimeTicks::FromInternalValue(1000),
86 true);
87 info1.MergeWith(info2);
89 EXPECT_EQ(info1.latency_components.size(), 2u);
90 LatencyInfo::LatencyComponent component;
91 EXPECT_FALSE(
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);
100 EXPECT_TRUE(
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) {
108 LatencyInfo info1;
109 LatencyInfo info2;
110 info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
113 base::TimeTicks::FromInternalValue(100),
115 true);
116 info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
119 base::TimeTicks::FromInternalValue(200),
121 true);
122 info1.MergeWith(info2);
124 EXPECT_EQ(info1.latency_components.size(), 1u);
125 LatencyInfo::LatencyComponent component;
126 EXPECT_FALSE(
127 info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
128 EXPECT_FALSE(
129 info1.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component));
130 EXPECT_TRUE(
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) {
138 LatencyInfo info;
139 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
142 base::TimeTicks::FromInternalValue(100),
144 true);
146 EXPECT_EQ(info.latency_components.size(), 1u);
147 info.Clear();
148 EXPECT_EQ(info.latency_components.size(), 0u);
151 } // namespace ui