Roll src/third_party/WebKit c63b89c:29324ab (svn 202546:202547)
[chromium-blink-merge.git] / ui / events / latency_info_unittest.cc
blobc0d654a82f354021020520f5ed3a42381a1edc1b
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),
17 1);
18 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
21 base::TimeTicks::FromInternalValue(1000),
22 2);
24 EXPECT_EQ(info.latency_components().size(), 2u);
25 LatencyInfo::LatencyComponent component;
26 EXPECT_FALSE(
27 info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
28 EXPECT_FALSE(
29 info.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1, &component));
30 EXPECT_TRUE(
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);
35 EXPECT_TRUE(
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) {
43 LatencyInfo info;
44 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
46 30,
47 base::TimeTicks::FromInternalValue(100),
48 2);
49 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
51 13,
52 base::TimeTicks::FromInternalValue(200),
53 3);
55 EXPECT_EQ(info.latency_components().size(), 1u);
56 LatencyInfo::LatencyComponent component;
57 EXPECT_FALSE(
58 info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component));
59 EXPECT_FALSE(
60 info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component));
61 EXPECT_TRUE(
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, AddCoalescedEventTimestamp) {
69 LatencyInfo info;
70 ASSERT_EQ(0u, info.coalesced_events_size());
71 for (size_t i = 0; i < LatencyInfo::kMaxCoalescedEventTimestamps; i++)
72 EXPECT_TRUE(info.AddCoalescedEventTimestamp(i * 10.0));
73 EXPECT_FALSE(info.AddCoalescedEventTimestamp(99.0));
74 EXPECT_EQ(LatencyInfo::kMaxCoalescedEventTimestamps,
75 info.coalesced_events_size());
76 for (size_t i = 0; i < info.coalesced_events_size(); i++)
77 EXPECT_EQ(i * 10.0, info.timestamps_of_coalesced_events()[i]);
80 } // namespace ui