| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/events/latency_info.h" | 5 #include "ui/events/latency_info.h" |
| 6 | 6 |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 namespace ui { | 9 namespace ui { |
| 10 | 10 |
| 11 TEST(LatencyInfoTest, AddTwoSeparateEvent) { | 11 TEST(LatencyInfoTest, AddTwoSeparateEvent) { |
| 12 LatencyInfo info; | 12 LatencyInfo info; |
| 13 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, | 13 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 14 0, | 14 0, |
| 15 1, | 15 1, |
| 16 base::TimeTicks::FromInternalValue(100), | 16 base::TimeTicks::FromInternalValue(100), |
| 17 1); | 17 1, |
| 18 true); |
| 18 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 19 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 19 1, | 20 1, |
| 20 5, | 21 5, |
| 21 base::TimeTicks::FromInternalValue(1000), | 22 base::TimeTicks::FromInternalValue(1000), |
| 22 2); | 23 2, |
| 24 true); |
| 23 | 25 |
| 24 EXPECT_EQ(info.latency_components.size(), 2u); | 26 EXPECT_EQ(info.latency_components.size(), 2u); |
| 25 LatencyInfo::LatencyComponent component; | 27 LatencyInfo::LatencyComponent component; |
| 26 EXPECT_FALSE( | 28 EXPECT_FALSE( |
| 27 info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); | 29 info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); |
| 28 EXPECT_FALSE( | 30 EXPECT_FALSE( |
| 29 info.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component)); | 31 info.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1, &component)); |
| 30 EXPECT_TRUE( | 32 EXPECT_TRUE( |
| 31 info.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component)); | 33 info.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, &component)); |
| 32 EXPECT_EQ(component.sequence_number, 1); | 34 EXPECT_EQ(component.sequence_number, 1); |
| 33 EXPECT_EQ(component.event_count, 1u); | 35 EXPECT_EQ(component.event_count, 1u); |
| 34 EXPECT_EQ(component.event_time.ToInternalValue(), 100); | 36 EXPECT_EQ(component.event_time.ToInternalValue(), 100); |
| 35 EXPECT_TRUE( | 37 EXPECT_TRUE( |
| 36 info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component)); | 38 info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component)); |
| 37 EXPECT_EQ(component.sequence_number, 5); | 39 EXPECT_EQ(component.sequence_number, 5); |
| 38 EXPECT_EQ(component.event_count, 2u); | 40 EXPECT_EQ(component.event_count, 2u); |
| 39 EXPECT_EQ(component.event_time.ToInternalValue(), 1000); | 41 EXPECT_EQ(component.event_time.ToInternalValue(), 1000); |
| 40 } | 42 } |
| 41 | 43 |
| 42 TEST(LatencyInfoTest, AddTwoSameEvent) { | 44 TEST(LatencyInfoTest, AddTwoSameEvent) { |
| 43 LatencyInfo info; | 45 LatencyInfo info; |
| 44 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, | 46 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 45 0, | 47 0, |
| 46 30, | 48 30, |
| 47 base::TimeTicks::FromInternalValue(100), | 49 base::TimeTicks::FromInternalValue(100), |
| 48 2); | 50 2, |
| 49 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, | 51 true); |
| 52 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 50 0, | 53 0, |
| 51 13, | 54 13, |
| 52 base::TimeTicks::FromInternalValue(200), | 55 base::TimeTicks::FromInternalValue(200), |
| 53 3); | 56 3, |
| 57 true); |
| 54 | 58 |
| 55 EXPECT_EQ(info.latency_components.size(), 1u); | 59 EXPECT_EQ(info.latency_components.size(), 1u); |
| 56 LatencyInfo::LatencyComponent component; | 60 LatencyInfo::LatencyComponent component; |
| 57 EXPECT_FALSE( | 61 EXPECT_FALSE( |
| 58 info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); | 62 info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); |
| 59 EXPECT_FALSE( | 63 EXPECT_FALSE( |
| 60 info.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component)); | 64 info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component)); |
| 61 EXPECT_TRUE( | 65 EXPECT_TRUE( |
| 62 info.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component)); | 66 info.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, &component)); |
| 63 EXPECT_EQ(component.sequence_number, 30); | 67 EXPECT_EQ(component.sequence_number, 30); |
| 64 EXPECT_EQ(component.event_count, 5u); | 68 EXPECT_EQ(component.event_count, 5u); |
| 65 EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5); | 69 EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5); |
| 66 } | 70 } |
| 67 | 71 |
| 68 TEST(LatencyInfoTest, MergeTwoSeparateEvent) { | 72 TEST(LatencyInfoTest, MergeTwoSeparateEvent) { |
| 69 LatencyInfo info1; | 73 LatencyInfo info1; |
| 70 LatencyInfo info2; | 74 LatencyInfo info2; |
| 71 info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, | 75 info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 72 0, | 76 0, |
| 73 1, | 77 1, |
| 74 base::TimeTicks::FromInternalValue(100), | 78 base::TimeTicks::FromInternalValue(100), |
| 75 1); | 79 1, |
| 80 true); |
| 76 info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 81 info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 77 1, | 82 1, |
| 78 5, | 83 5, |
| 79 base::TimeTicks::FromInternalValue(1000), | 84 base::TimeTicks::FromInternalValue(1000), |
| 80 2); | 85 2, |
| 86 true); |
| 81 info1.MergeWith(info2); | 87 info1.MergeWith(info2); |
| 82 | 88 |
| 83 EXPECT_EQ(info1.latency_components.size(), 2u); | 89 EXPECT_EQ(info1.latency_components.size(), 2u); |
| 84 LatencyInfo::LatencyComponent component; | 90 LatencyInfo::LatencyComponent component; |
| 85 EXPECT_FALSE( | 91 EXPECT_FALSE( |
| 86 info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); | 92 info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); |
| 87 EXPECT_FALSE( | 93 EXPECT_FALSE(info1.FindLatency( |
| 88 info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component)); | 94 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1, &component)); |
| 89 EXPECT_TRUE( | 95 EXPECT_TRUE(info1.FindLatency( |
| 90 info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component)); | 96 INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 0, &component)); |
| 91 EXPECT_EQ(component.sequence_number, 1); | 97 EXPECT_EQ(component.sequence_number, 1); |
| 92 EXPECT_EQ(component.event_count, 1u); | 98 EXPECT_EQ(component.event_count, 1u); |
| 93 EXPECT_EQ(component.event_time.ToInternalValue(), 100); | 99 EXPECT_EQ(component.event_time.ToInternalValue(), 100); |
| 94 EXPECT_TRUE( | 100 EXPECT_TRUE( |
| 95 info1.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component)); | 101 info1.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component)); |
| 96 EXPECT_EQ(component.sequence_number, 5); | 102 EXPECT_EQ(component.sequence_number, 5); |
| 97 EXPECT_EQ(component.event_count, 2u); | 103 EXPECT_EQ(component.event_count, 2u); |
| 98 EXPECT_EQ(component.event_time.ToInternalValue(), 1000); | 104 EXPECT_EQ(component.event_time.ToInternalValue(), 1000); |
| 99 } | 105 } |
| 100 | 106 |
| 101 TEST(LatencyInfoTest, MergeTwoSameEvent) { | 107 TEST(LatencyInfoTest, MergeTwoSameEvent) { |
| 102 LatencyInfo info1; | 108 LatencyInfo info1; |
| 103 LatencyInfo info2; | 109 LatencyInfo info2; |
| 104 info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, | 110 info1.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 105 0, | 111 0, |
| 106 30, | 112 30, |
| 107 base::TimeTicks::FromInternalValue(100), | 113 base::TimeTicks::FromInternalValue(100), |
| 108 2); | 114 2, |
| 109 info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, | 115 true); |
| 116 info2.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 110 0, | 117 0, |
| 111 13, | 118 13, |
| 112 base::TimeTicks::FromInternalValue(200), | 119 base::TimeTicks::FromInternalValue(200), |
| 113 3); | 120 3, |
| 121 true); |
| 114 info1.MergeWith(info2); | 122 info1.MergeWith(info2); |
| 115 | 123 |
| 116 EXPECT_EQ(info1.latency_components.size(), 1u); | 124 EXPECT_EQ(info1.latency_components.size(), 1u); |
| 117 LatencyInfo::LatencyComponent component; | 125 LatencyInfo::LatencyComponent component; |
| 118 EXPECT_FALSE( | 126 EXPECT_FALSE( |
| 119 info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); | 127 info1.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); |
| 120 EXPECT_FALSE( | 128 EXPECT_FALSE( |
| 121 info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 1, &component)); | 129 info1.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1, &component)); |
| 122 EXPECT_TRUE( | 130 EXPECT_TRUE( |
| 123 info1.FindLatency(INPUT_EVENT_LATENCY_RWH_COMPONENT, 0, &component)); | 131 info1.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 0, &component)); |
| 124 EXPECT_EQ(component.sequence_number, 30); | 132 EXPECT_EQ(component.sequence_number, 30); |
| 125 EXPECT_EQ(component.event_count, 5u); | 133 EXPECT_EQ(component.event_count, 5u); |
| 126 EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5); | 134 EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5); |
| 127 } | 135 } |
| 128 | 136 |
| 129 TEST(LatencyInfoTest, ClearEvents) { | 137 TEST(LatencyInfoTest, ClearEvents) { |
| 130 LatencyInfo info; | 138 LatencyInfo info; |
| 131 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_RWH_COMPONENT, | 139 info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 132 0, | 140 0, |
| 133 30, | 141 30, |
| 134 base::TimeTicks::FromInternalValue(100), | 142 base::TimeTicks::FromInternalValue(100), |
| 135 2); | 143 2, |
| 144 true); |
| 136 | 145 |
| 137 EXPECT_EQ(info.latency_components.size(), 1u); | 146 EXPECT_EQ(info.latency_components.size(), 1u); |
| 138 info.Clear(); | 147 info.Clear(); |
| 139 EXPECT_EQ(info.latency_components.size(), 0u); | 148 EXPECT_EQ(info.latency_components.size(), 0u); |
| 140 } | 149 } |
| 141 | 150 |
| 142 } // namespace ui | 151 } // namespace ui |
| OLD | NEW |