OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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. |
| 4 |
| 5 #include "ui/base/latency_info.h" |
| 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace ui { |
| 10 |
| 11 TEST(LatencyInfoTest, AddTwoSeparateEvent) { |
| 12 LatencyInfo info; |
| 13 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 14 0, |
| 15 1, |
| 16 base::TimeTicks::FromInternalValue(100), |
| 17 1); |
| 18 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 19 1, |
| 20 5, |
| 21 base::TimeTicks::FromInternalValue(1000), |
| 22 2); |
| 23 |
| 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_RWH_COMPONENT, 1, &component)); |
| 30 EXPECT_TRUE( |
| 31 info.FindLatency(INPUT_EVENT_LATENCY_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); |
| 40 } |
| 41 |
| 42 TEST(LatencyInfoTest, AddTwoSameEvent) { |
| 43 LatencyInfo info; |
| 44 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 45 0, |
| 46 30, |
| 47 base::TimeTicks::FromInternalValue(100), |
| 48 2); |
| 49 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 50 0, |
| 51 13, |
| 52 base::TimeTicks::FromInternalValue(200), |
| 53 3); |
| 54 |
| 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_RWH_COMPONENT, 1, &component)); |
| 61 EXPECT_TRUE( |
| 62 info.FindLatency(INPUT_EVENT_LATENCY_RWH_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); |
| 66 } |
| 67 |
| 68 TEST(LatencyInfoTest, MergeTwoSeparateEvent) { |
| 69 LatencyInfo info1; |
| 70 LatencyInfo info2; |
| 71 info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 72 0, |
| 73 1, |
| 74 base::TimeTicks::FromInternalValue(100), |
| 75 1); |
| 76 info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 77 1, |
| 78 5, |
| 79 base::TimeTicks::FromInternalValue(1000), |
| 80 2); |
| 81 info1.MergeWith(info2); |
| 82 |
| 83 EXPECT_EQ(info1.latency_components.size(), 2u); |
| 84 LatencyInfo::LatencyComponent component; |
| 85 EXPECT_FALSE( |
| 86 info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); |
| 87 EXPECT_FALSE( |
| 88 info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component)); |
| 89 EXPECT_TRUE( |
| 90 info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component)); |
| 91 EXPECT_EQ(component.sequence_number, 1); |
| 92 EXPECT_EQ(component.event_count, 1u); |
| 93 EXPECT_EQ(component.event_time.ToInternalValue(), 100); |
| 94 EXPECT_TRUE( |
| 95 info1.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component)); |
| 96 EXPECT_EQ(component.sequence_number, 5); |
| 97 EXPECT_EQ(component.event_count, 2u); |
| 98 EXPECT_EQ(component.event_time.ToInternalValue(), 1000); |
| 99 } |
| 100 |
| 101 TEST(LatencyInfoTest, MergeTwoSameEvent) { |
| 102 LatencyInfo info1; |
| 103 LatencyInfo info2; |
| 104 info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 105 0, |
| 106 30, |
| 107 base::TimeTicks::FromInternalValue(100), |
| 108 2); |
| 109 info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 110 0, |
| 111 13, |
| 112 base::TimeTicks::FromInternalValue(200), |
| 113 3); |
| 114 info1.MergeWith(info2); |
| 115 |
| 116 EXPECT_EQ(info1.latency_components.size(), 1u); |
| 117 LatencyInfo::LatencyComponent component; |
| 118 EXPECT_FALSE( |
| 119 info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); |
| 120 EXPECT_FALSE( |
| 121 info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component)); |
| 122 EXPECT_TRUE( |
| 123 info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component)); |
| 124 EXPECT_EQ(component.sequence_number, 30); |
| 125 EXPECT_EQ(component.event_count, 5u); |
| 126 EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5); |
| 127 } |
| 128 |
| 129 TEST(LatencyInfoTest, ClearEvents) { |
| 130 LatencyInfo info; |
| 131 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, |
| 132 0, |
| 133 30, |
| 134 base::TimeTicks::FromInternalValue(100), |
| 135 2); |
| 136 |
| 137 EXPECT_EQ(info.latency_components.size(), 1u); |
| 138 info.Clear(); |
| 139 EXPECT_EQ(info.latency_components.size(), 0u); |
| 140 } |
| 141 |
| 142 } // namespace ui |
OLD | NEW |