Avi Drissman | 3f7a9d8 | 2022-09-08 20:55:42 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 5 | #include "cc/metrics/average_lag_tracker.h" |
| 6 | |
| 7 | #include <memory> |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 8 | |
| 9 | #include "base/test/metrics/histogram_tester.h" |
| 10 | #include "testing/gmock/include/gmock/gmock.h" |
| 11 | #include "testing/gtest/include/gtest/gtest.h" |
| 12 | |
| 13 | using base::Bucket; |
| 14 | using testing::ElementsAre; |
| 15 | |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 16 | namespace cc { |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 17 | namespace { |
| 18 | |
| 19 | class AverageLagTrackerTest : public testing::Test { |
| 20 | public: |
| 21 | AverageLagTrackerTest() { ResetHistograms(); } |
| 22 | |
| 23 | void ResetHistograms() { |
Peter Boström | f238104 | 2019-08-27 00:25:03 | [diff] [blame] | 24 | histogram_tester_ = std::make_unique<base::HistogramTester>(); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | const base::HistogramTester& histogram_tester() { return *histogram_tester_; } |
| 28 | |
| 29 | void SetUp() override { |
Joao Victor Almeida | ae356d4 | 2021-07-06 16:24:34 | [diff] [blame] | 30 | average_lag_tracker_ = std::make_unique<AverageLagTracker>(); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 31 | } |
| 32 | |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 33 | void SyntheticTouchScrollBegin(base::TimeTicks event_time, |
| 34 | base::TimeTicks frame_time, |
| 35 | float delta, |
| 36 | float predicted_delta = 0) { |
| 37 | AverageLagTracker::EventInfo event_info( |
Mohsen Izadi | 9f0a9f7 | 2021-09-08 22:44:38 | [diff] [blame] | 38 | delta, predicted_delta != 0 ? predicted_delta : delta, event_time, |
Ho Cheung | 0636519 | 2023-09-14 17:09:54 | [diff] [blame] | 39 | AverageLagTracker::EventType::kScrollbegin); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 40 | event_info.finish_timestamp = frame_time; |
Joao Victor Almeida | ae356d4 | 2021-07-06 16:24:34 | [diff] [blame] | 41 | average_lag_tracker_->AddScrollEventInFrame(event_info); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 42 | } |
| 43 | |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 44 | void SyntheticTouchScrollUpdate(base::TimeTicks event_time, |
| 45 | base::TimeTicks frame_time, |
| 46 | float delta, |
| 47 | float predicted_delta = 0) { |
| 48 | AverageLagTracker::EventInfo event_info( |
Mohsen Izadi | 9f0a9f7 | 2021-09-08 22:44:38 | [diff] [blame] | 49 | delta, predicted_delta != 0 ? predicted_delta : delta, event_time, |
Ho Cheung | 0636519 | 2023-09-14 17:09:54 | [diff] [blame] | 50 | AverageLagTracker::EventType::kScrollupdate); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 51 | event_info.finish_timestamp = frame_time; |
Joao Victor Almeida | ae356d4 | 2021-07-06 16:24:34 | [diff] [blame] | 52 | average_lag_tracker_->AddScrollEventInFrame(event_info); |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void CheckScrollBeginHistograms(int bucket_value, int count) { |
| 56 | EXPECT_THAT(histogram_tester().GetAllSamples( |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 57 | "Event.Latency.ScrollBegin.Touch.AverageLagPresentation"), |
| 58 | ElementsAre(Bucket(bucket_value, count))); |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 59 | |
| 60 | EXPECT_THAT( |
| 61 | histogram_tester().GetAllSamples("Event.Latency.ScrollBegin.Touch." |
| 62 | "AverageLagPresentation.NoPrediction"), |
| 63 | ElementsAre(Bucket(bucket_value, count))); |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 64 | } |
| 65 | |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 66 | void CheckScrollUpdateWithPredictionHistograms(int bucket_value, int count) { |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 67 | EXPECT_THAT(histogram_tester().GetAllSamples( |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 68 | "Event.Latency.ScrollUpdate.Touch.AverageLagPresentation"), |
| 69 | ElementsAre(Bucket(bucket_value, count))); |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 70 | } |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 71 | |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 72 | void CheckScrollUpdateNoPredictionHistograms(int bucket_value, int count) { |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 73 | EXPECT_THAT( |
| 74 | histogram_tester().GetAllSamples("Event.Latency.ScrollUpdate.Touch." |
| 75 | "AverageLagPresentation.NoPrediction"), |
| 76 | ElementsAre(Bucket(bucket_value, count))); |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void CheckPredictionPositiveHistograms(int bucket_value, int count) { |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 80 | EXPECT_THAT(histogram_tester().GetAllSamples( |
| 81 | "Event.Latency.ScrollUpdate.Touch.AverageLagPresentation." |
| 82 | "PredictionPositive"), |
| 83 | ElementsAre(Bucket(bucket_value, count))); |
| 84 | } |
| 85 | |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 86 | void CheckRemainingLagPercentageHistograms(int bucket_value, int count) { |
| 87 | EXPECT_THAT(histogram_tester().GetAllSamples( |
| 88 | "Event.Latency.ScrollUpdate.Touch.AverageLagPresentation." |
| 89 | "RemainingLagPercentage"), |
| 90 | ElementsAre(Bucket(bucket_value, count))); |
| 91 | } |
| 92 | |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 93 | void CheckPredictionNegativeHistograms(int bucket_value, int count) { |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 94 | EXPECT_THAT(histogram_tester().GetAllSamples( |
| 95 | "Event.Latency.ScrollUpdate.Touch.AverageLagPresentation." |
| 96 | "PredictionNegative"), |
| 97 | ElementsAre(Bucket(bucket_value, count))); |
| 98 | } |
| 99 | |
| 100 | void CheckScrollUpdateHistogramsTotalCount(int count) { |
| 101 | histogram_tester().ExpectTotalCount( |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 102 | "Event.Latency.ScrollUpdate.Touch.AverageLagPresentation", count); |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 103 | histogram_tester().ExpectTotalCount( |
| 104 | "Event.Latency.ScrollUpdate.Touch.AverageLagPresentation.NoPrediction", |
| 105 | count); |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | void CheckPredictionPositiveHistogramsTotalCount(int count) { |
| 109 | histogram_tester().ExpectTotalCount( |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 110 | "Event.Latency.ScrollUpdate.Touch.AverageLagPresentation." |
| 111 | "PredictionPositive", |
| 112 | count); |
| 113 | } |
| 114 | |
| 115 | void CheckPredictionNegativeHistogramsTotalCount(int count) { |
| 116 | histogram_tester().ExpectTotalCount( |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 117 | "Event.Latency.ScrollUpdate.Touch.AverageLagPresentation." |
| 118 | "PredictionNegative", |
| 119 | count); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | protected: |
Joao Victor Almeida | ae356d4 | 2021-07-06 16:24:34 | [diff] [blame] | 123 | std::unique_ptr<AverageLagTracker> average_lag_tracker_; |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 124 | |
| 125 | std::unique_ptr<base::HistogramTester> histogram_tester_; |
| 126 | }; |
| 127 | |
| 128 | base::TimeTicks MillisecondsToTimeTicks(float t_ms) { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 129 | return base::TimeTicks() + base::Milliseconds(t_ms); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // Simulate a simple situation that events at every 10ms and start at t=15ms, |
| 133 | // frame swaps at every 10ms too and start at t=20ms and test we record one |
| 134 | // UMA for ScrollUpdate in one second. |
| 135 | TEST_F(AverageLagTrackerTest, OneSecondInterval) { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 136 | base::TimeTicks event_time = base::TimeTicks() + base::Milliseconds(5); |
| 137 | base::TimeTicks frame_time = base::TimeTicks() + base::Milliseconds(10); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 138 | float scroll_delta = 10; |
| 139 | |
| 140 | // ScrollBegin |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 141 | event_time += base::Milliseconds(10); // 15ms |
| 142 | frame_time += base::Milliseconds(10); // 20ms |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 143 | SyntheticTouchScrollBegin(event_time, frame_time, scroll_delta); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 144 | |
| 145 | // Send 101 ScrollUpdate events to verify that there is 1 AverageLag record |
| 146 | // per 1 second. |
| 147 | const int kUpdates = 101; |
| 148 | for (int i = 0; i < kUpdates; i++) { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 149 | event_time += base::Milliseconds(10); |
| 150 | frame_time += base::Milliseconds(10); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 151 | // First 50 has positive delta, others negetive delta. |
| 152 | const int sign = (i < kUpdates / 2) ? 1 : -1; |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 153 | SyntheticTouchScrollUpdate(event_time, frame_time, sign * scroll_delta); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | // ScrollBegin report_time is at 20ms, so the next ScrollUpdate report_time is |
| 157 | // at 1020ms. The last event_time that finish this report should be later than |
| 158 | // 1020ms. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 159 | EXPECT_EQ(event_time, base::TimeTicks() + base::Milliseconds(1025)); |
| 160 | EXPECT_EQ(frame_time, base::TimeTicks() + base::Milliseconds(1030)); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 161 | |
| 162 | // ScrollBegin AverageLag are the area between the event original component |
| 163 | // (time=15ms, delta=10px) to the frame swap time (time=20ms, expect finger |
| 164 | // position at delta=15px). The AverageLag scaled to 1 second is |
| 165 | // (0.5*(10px+15px)*5ms)/5ms = 12.5px. |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 166 | CheckScrollBeginHistograms(12, 1); |
| 167 | |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 168 | // This ScrollUpdate AverageLag are calculated as the finger uniformly scroll |
| 169 | // 10px each frame. For scroll up/down frame, the Lag at the last frame swap |
| 170 | // is 5px, and Lag at this frame swap is 15px. For the one changing direction, |
| 171 | // the Lag is from 5 to 10 and down to 5 again. So total LagArea is 99 * 100, |
| 172 | // plus 75. the AverageLag in 1 second is 9.975px. |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 173 | CheckScrollUpdateWithPredictionHistograms(9, 1); |
| 174 | CheckScrollUpdateNoPredictionHistograms(9, 1); |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 175 | CheckPredictionPositiveHistograms(0, 1); |
| 176 | CheckPredictionNegativeHistogramsTotalCount(0); |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 177 | CheckRemainingLagPercentageHistograms(100 - 0, 1); |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 178 | |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 179 | ResetHistograms(); |
| 180 | |
| 181 | // Send another ScrollBegin to end the unfinished ScrollUpdate report. |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 182 | event_time += base::Milliseconds(10); |
| 183 | frame_time += base::Milliseconds(10); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 184 | SyntheticTouchScrollBegin(event_time, frame_time, scroll_delta); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 185 | |
| 186 | // The last ScrollUpdate's lag is 8.75px and truncated to 8. |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 187 | CheckScrollUpdateWithPredictionHistograms(8, 1); |
| 188 | CheckScrollUpdateNoPredictionHistograms(8, 1); |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 189 | CheckPredictionPositiveHistograms(0, 1); |
| 190 | CheckPredictionNegativeHistogramsTotalCount(0); |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 191 | CheckRemainingLagPercentageHistograms(100 - 0, 1); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | // Test the case that event's frame swap time is later than next event's |
| 195 | // creation time. (i.e, event at t=10ms will be dispatch at t=30ms, while next |
| 196 | // event is at t=20ms). |
| 197 | TEST_F(AverageLagTrackerTest, LargerLatency) { |
| 198 | base::TimeTicks event_time = MillisecondsToTimeTicks(10); |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 199 | base::TimeTicks frame_time = event_time + base::Milliseconds(20); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 200 | float scroll_delta = 10; |
| 201 | |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 202 | SyntheticTouchScrollBegin(event_time, frame_time, scroll_delta); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 203 | |
| 204 | // Send 2 ScrollUpdate. The second one will record AverageLag.ScrollBegin as |
| 205 | // it's event_time is larger or equal to ScrollBegin's frame_time. |
| 206 | for (int i = 0; i < 2; i++) { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 207 | event_time += base::Milliseconds(10); |
| 208 | frame_time = event_time + base::Milliseconds(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 209 | SyntheticTouchScrollUpdate(event_time, frame_time, scroll_delta); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | // ScrollBegin AveragLag are from t=10ms to t=30ms, with absolute scroll |
| 213 | // position from 10 to 30. The AverageLag should be: |
| 214 | // (0.5*(10px + 30px)*20ms/20ms) = 20px. |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 215 | CheckScrollBeginHistograms(20, 1); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 216 | |
| 217 | // Another ScrollBegin to flush unfinished frames. |
| 218 | // event_time doesn't matter here because the previous frames' lag are |
| 219 | // compute from their frame_time. |
| 220 | event_time = MillisecondsToTimeTicks(1000); |
| 221 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 222 | SyntheticTouchScrollBegin(event_time, frame_time, scroll_delta); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 223 | // The to unfinished frames' lag are (finger_positon-rendered_position)*time, |
| 224 | // AverageLag is ((30px-10px)*10ms+(30px-20px)*10ms)/20ms = 15px. |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 225 | CheckScrollUpdateWithPredictionHistograms(14, 1); |
| 226 | CheckScrollUpdateNoPredictionHistograms(14, 1); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // Test that multiple latency being flush in the same frame swap. |
| 230 | TEST_F(AverageLagTrackerTest, TwoLatencyInfoInSameFrame) { |
| 231 | // ScrollBegin |
| 232 | base::TimeTicks event_time = MillisecondsToTimeTicks(10); |
| 233 | base::TimeTicks frame_time = MillisecondsToTimeTicks(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 234 | SyntheticTouchScrollBegin(event_time, frame_time, -10 /* scroll_delta */); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 235 | |
| 236 | // ScrollUpdate with event_time >= ScrollBegin frame_time will generate |
| 237 | // a histogram for AverageLag.ScrollBegin. |
| 238 | event_time = MillisecondsToTimeTicks(20); |
| 239 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 240 | SyntheticTouchScrollUpdate(event_time, frame_time, -10 /* scroll_delta */); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 241 | |
| 242 | // Absolute position from -10 to -20. The AverageLag should be: |
| 243 | // (0.5*(10px + 20px)*10ms/10ms) = 15px. |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 244 | CheckScrollBeginHistograms(14, 1); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 245 | |
| 246 | event_time = MillisecondsToTimeTicks(25); |
| 247 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 248 | SyntheticTouchScrollUpdate(event_time, frame_time, 5 /* scroll_delta */); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 249 | |
| 250 | // Another ScrollBegin to flush unfinished frames. |
| 251 | event_time = MillisecondsToTimeTicks(1000); |
| 252 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 253 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 254 | |
| 255 | // The ScrollUpdates are at t=20ms, finger_pos=-20px, rendered_pos=-10px, |
| 256 | // at t=25ms, finger_pos=-15px, rendered_pos=-10px; |
| 257 | // To t=30ms both events get flush. |
| 258 | // AverageLag is (0.5*(10px+5px)*5ms + 5px*5ms)/10ms = 6.25px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 259 | CheckScrollUpdateWithPredictionHistograms(6, 1); |
| 260 | CheckScrollUpdateNoPredictionHistograms(6, 1); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | // Test the case that switching direction causes lag at current frame |
| 264 | // time and previous frame time are in different direction. |
| 265 | TEST_F(AverageLagTrackerTest, ChangeDirectionInFrame) { |
| 266 | // ScrollBegin |
| 267 | base::TimeTicks event_time = MillisecondsToTimeTicks(10); |
| 268 | base::TimeTicks frame_time = MillisecondsToTimeTicks(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 269 | SyntheticTouchScrollBegin(event_time, frame_time, 10 /* scroll_delta */); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 270 | |
| 271 | // At t=20, lag = 10px. |
| 272 | event_time = MillisecondsToTimeTicks(20); |
| 273 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 274 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 275 | |
| 276 | // At t=30, lag = -10px. |
| 277 | event_time = MillisecondsToTimeTicks(30); |
| 278 | frame_time = MillisecondsToTimeTicks(40); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 279 | SyntheticTouchScrollUpdate(event_time, frame_time, -20 /* scroll_delta */); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 280 | |
| 281 | // Another ScrollBegin to flush unfinished frames. |
| 282 | event_time = MillisecondsToTimeTicks(1000); |
| 283 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 284 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 285 | |
| 286 | // From t=20 to t=30, lag_area=2*(0.5*10px*5ms)=50px*ms. |
| 287 | // From t=30 to t=40, lag_area=20px*10ms=200px*ms |
| 288 | // AverageLag = (50+200)/20 = 12.5px. |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 289 | CheckScrollUpdateWithPredictionHistograms(12, 1); |
| 290 | CheckScrollUpdateNoPredictionHistograms(12, 1); |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 291 | } |
| 292 | |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 293 | // A simple case without scroll prediction to compare with the two with |
| 294 | // prediction cases below. |
| 295 | TEST_F(AverageLagTrackerTest, NoScrollPrediction) { |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 296 | // ScrollBegin, at t=5, finger_pos=5px. |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 297 | base::TimeTicks event_time = MillisecondsToTimeTicks(5); |
| 298 | base::TimeTicks frame_time = MillisecondsToTimeTicks(10); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 299 | SyntheticTouchScrollBegin(event_time, frame_time, 5 /* scroll_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 300 | |
| 301 | // ScrollUpdate, at t=15, finger_pos=15px. |
| 302 | event_time = MillisecondsToTimeTicks(15); |
| 303 | frame_time = MillisecondsToTimeTicks(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 304 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 305 | |
| 306 | // ScrollUpdate, at t=25, finger_pos=25px. |
| 307 | event_time = MillisecondsToTimeTicks(25); |
| 308 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 309 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 310 | |
| 311 | // Another ScrollBegin to flush unfinished frames. |
| 312 | event_time = MillisecondsToTimeTicks(1000); |
| 313 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 314 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 315 | |
| 316 | // Prediction hasn't take affect on ScrollBegin so it'll stay the same. |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 317 | CheckScrollBeginHistograms(7, 1); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 318 | // At t=10, finger_pos = 10px, rendered_pos = 5px. |
| 319 | // At t=20, finger_pos = 20px, rendered_pos = 15px. |
| 320 | // At t=30, finger_pos = 25px, rendered_pos = 25px. |
| 321 | // AverageLag = ((5px+15px)*10ms/2 + (5px+10px)*5ms/2 + 10px*5ms)/20ms |
| 322 | // = 9.375 |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 323 | CheckScrollUpdateWithPredictionHistograms(9, 1); |
| 324 | CheckScrollUpdateNoPredictionHistograms(9, 1); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // Test AverageLag with perfect scroll prediction. |
| 328 | TEST_F(AverageLagTrackerTest, ScrollPrediction) { |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 329 | // ScrollBegin, at t=5, finger_pos=5px. |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 330 | // Predict frame_time=10, predicted_pos = 10px. |
| 331 | base::TimeTicks event_time = MillisecondsToTimeTicks(5); |
| 332 | base::TimeTicks frame_time = MillisecondsToTimeTicks(10); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 333 | SyntheticTouchScrollBegin(event_time, frame_time, 5 /* scroll_delta */, |
| 334 | 10 /* predicted_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 335 | |
| 336 | // ScrollUpdate, at t=15, finger_pos=15px. |
| 337 | // Predict frame_time=20, predicted_pos = 20px. |
| 338 | event_time = MillisecondsToTimeTicks(15); |
| 339 | frame_time = MillisecondsToTimeTicks(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 340 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */, |
| 341 | 10 /* predicted_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 342 | |
| 343 | // ScrollUpdate, at t=25, finger_pos=25px. |
| 344 | // Predict frame_time=30, predicted_pos = 30px. |
| 345 | event_time = MillisecondsToTimeTicks(25); |
| 346 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 347 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */, |
| 348 | 10 /* predicted_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 349 | |
| 350 | // Another ScrollBegin to flush unfinished frames. |
| 351 | event_time = MillisecondsToTimeTicks(1000); |
| 352 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 353 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 354 | |
| 355 | // Prediction hasn't take affect on ScrollBegin so it'll stay the same. |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 356 | CheckScrollBeginHistograms(7, 1); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 357 | // At t=10, finger_pos = 10px, rendered_pos = 10px. |
| 358 | // At t=20, finger_pos = 20px, rendered_pos = 20px. |
| 359 | // At t=30, finger_pos = 25px, rendered_pos = 30px. |
| 360 | // AverageLag = ((0px+10px)*10ms/2 + (0px+5px)*10ms/2 + 5px*5ms)/20ms |
| 361 | // = 4.375px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 362 | CheckScrollUpdateWithPredictionHistograms(4, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 363 | // AverageLag (w/o prediction) |
| 364 | // ((5px+15px)*10ms/2 + (5px+10px)*5ms/2 + 10px*5ms)/20ms |
| 365 | // = 9.375px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 366 | CheckScrollUpdateNoPredictionHistograms(9, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 367 | // Positive effect of prediction = 5px |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 368 | CheckPredictionPositiveHistograms(5, 1); |
| 369 | CheckPredictionNegativeHistogramsTotalCount(0); |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 370 | CheckRemainingLagPercentageHistograms(100 * 4.375 / 9.375, 1); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | // Test AverageLag with imperfect scroll prediction. |
| 374 | TEST_F(AverageLagTrackerTest, ImperfectScrollPrediction) { |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 375 | // ScrollBegin, at t=5, finger_pos=5px. |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 376 | // Predict frame_time=10, predicted_pos(over) = 12px. |
| 377 | base::TimeTicks event_time = MillisecondsToTimeTicks(5); |
| 378 | base::TimeTicks frame_time = MillisecondsToTimeTicks(10); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 379 | SyntheticTouchScrollBegin(event_time, frame_time, 5 /* scroll_delta */, |
| 380 | 12 /* predicted_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 381 | |
| 382 | // ScrollUpdate, at t=15, finger_pos=15px. |
| 383 | // Predict frame_time=20, predicted_pos(under) = 17px. |
| 384 | event_time = MillisecondsToTimeTicks(15); |
| 385 | frame_time = MillisecondsToTimeTicks(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 386 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */, |
| 387 | 5 /* predicted_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 388 | |
| 389 | // ScrollUpdate, at t=25, finger_pos=25px. |
| 390 | // Predict frame_time=30, predicted_pos(over) = 31px. |
| 391 | event_time = MillisecondsToTimeTicks(25); |
| 392 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 393 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */, |
| 394 | 14 /* predicted_delta */); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 395 | |
| 396 | // Another ScrollBegin to flush unfinished frames. |
| 397 | event_time = MillisecondsToTimeTicks(1000); |
| 398 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 399 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 400 | |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 401 | CheckScrollBeginHistograms(7, 1); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 402 | // AverageLag = ((2px*2ms/2+8px*8ms/2)+ ((3px+8px)*5ms/2+8px*5ms))/20ms |
| 403 | // = 5.075px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 404 | CheckScrollUpdateWithPredictionHistograms(5, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 405 | // AverageLag (w/o prediction = |
| 406 | // ((5px+15px)*10ms/2 + (5px+10px)*5ms/2 + 10px*5ms)/20ms |
| 407 | // = 9.375px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 408 | CheckScrollUpdateNoPredictionHistograms(9, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 409 | // Positive effect of prediction = 4.3px |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 410 | CheckPredictionPositiveHistograms(4, 1); |
| 411 | CheckPredictionNegativeHistogramsTotalCount(0); |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 412 | CheckRemainingLagPercentageHistograms(100 * 5.075 / 9.375, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | TEST_F(AverageLagTrackerTest, NegativePredictionEffect) { |
| 416 | // ScrollBegin, at t=5, finger_pos=5px. |
| 417 | // Predict frame_time=10, predicted_pos(over) = 20px. |
| 418 | base::TimeTicks event_time = MillisecondsToTimeTicks(5); |
| 419 | base::TimeTicks frame_time = MillisecondsToTimeTicks(10); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 420 | SyntheticTouchScrollBegin(event_time, frame_time, 5 /* scroll_delta */, |
| 421 | 20 /* predicted_delta */); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 422 | |
| 423 | // ScrollUpdate, at t=15, finger_pos=15px. |
| 424 | // Predict frame_time=20, predicted_pos(over) = 60px. |
| 425 | event_time = MillisecondsToTimeTicks(15); |
| 426 | frame_time = MillisecondsToTimeTicks(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 427 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */, |
| 428 | 40 /* predicted_delta */); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 429 | |
| 430 | // ScrollUpdate, at t=25, finger_pos=25px. |
| 431 | // Predict frame_time=30, predicted_pos(over) = 60px. |
| 432 | event_time = MillisecondsToTimeTicks(25); |
| 433 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 434 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */, |
| 435 | 0 /* predicted_delta */); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 436 | |
| 437 | // Another ScrollBegin to flush unfinished frames. |
| 438 | event_time = MillisecondsToTimeTicks(1000); |
| 439 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 440 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 441 | |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 442 | CheckScrollBeginHistograms(7, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 443 | // AverageLag = ((10px+0px)*10ms/2)+ ((40px+35px)*5ms/2+35px*5ms))/20ms |
| 444 | // = 20.625px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 445 | CheckScrollUpdateWithPredictionHistograms(20, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 446 | // AverageLag (w/o prediction = |
| 447 | // ((5px+15px)*10ms/2 + (5px+10px)*5ms/2 + 10px*5ms)/20ms |
| 448 | // = 9.375px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 449 | CheckScrollUpdateNoPredictionHistograms(9, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 450 | // Negative effect of prediction = 11.25 |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 451 | CheckPredictionPositiveHistogramsTotalCount(0); |
| 452 | CheckPredictionNegativeHistograms(11, 1); |
Joao Victor Almeida | 49b3d690 | 2021-07-06 17:35:55 | [diff] [blame] | 453 | |
| 454 | // 100 * 20.625 / 9.375 = 220 is logged into bucket 219. |
| 455 | CheckRemainingLagPercentageHistograms(219, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | TEST_F(AverageLagTrackerTest, NoPredictionEffect) { |
| 459 | // ScrollBegin, at t=5, finger_pos=5px. |
| 460 | // Predict frame_time=10, predicted_pos(over) = 25px. |
| 461 | base::TimeTicks event_time = MillisecondsToTimeTicks(5); |
| 462 | base::TimeTicks frame_time = MillisecondsToTimeTicks(10); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 463 | SyntheticTouchScrollBegin(event_time, frame_time, 5 /* scroll_delta */, |
| 464 | 25 /* predicted_delta */); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 465 | |
| 466 | // ScrollUpdate, at t=15, finger_pos=15px. |
| 467 | // Predict frame_time=20, predicted_pos(over) = 32px. |
| 468 | event_time = MillisecondsToTimeTicks(15); |
| 469 | frame_time = MillisecondsToTimeTicks(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 470 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */, |
| 471 | 7 /* predicted_delta */); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 472 | |
| 473 | // ScrollUpdate, at t=25, finger_pos=25px. |
| 474 | // Predict frame_time=30, predicted_pos(over) = 37px. |
| 475 | event_time = MillisecondsToTimeTicks(25); |
| 476 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 477 | SyntheticTouchScrollUpdate(event_time, frame_time, 10 /* scroll_delta */, |
| 478 | 5 /* predicted_delta */); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 479 | |
| 480 | // Another ScrollBegin to flush unfinished frames. |
| 481 | event_time = MillisecondsToTimeTicks(1000); |
| 482 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 483 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 484 | |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 485 | CheckScrollBeginHistograms(7, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 486 | // AverageLag = ((15px+5px)*10ms/2 + (12px+7px)*5ms/2 + 7px*5ms)/20ms |
| 487 | // = 9.125px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 488 | CheckScrollUpdateWithPredictionHistograms(9, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 489 | // AverageLag (w/o prediction) = |
| 490 | // ((5px+15px)*10ms/2 + (5px+10px)*5ms/2 + 10px*5ms)/20ms |
| 491 | // = 9.375px |
Joao Victor Almeida | 06f7be7 | 2021-10-13 21:48:34 | [diff] [blame] | 492 | CheckScrollUpdateNoPredictionHistograms(9, 1); |
Daniel Libby | f7cf7738 | 2019-05-06 19:23:44 | [diff] [blame] | 493 | // Prediction slightly positive, we should see a 0 bucket in |
| 494 | // PredictionPositive UMA |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 495 | CheckPredictionPositiveHistograms(0, 1); |
| 496 | CheckPredictionNegativeHistogramsTotalCount(0); |
Ella Ge | 7d1d3be20 | 2019-04-08 16:47:59 | [diff] [blame] | 497 | } |
| 498 | |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 499 | // Tests that when an event arrives out-of-order, the average lag tracker |
| 500 | // properly ignores it. |
| 501 | TEST_F(AverageLagTrackerTest, EventOutOfOrder) { |
| 502 | base::TimeTicks event_time = MillisecondsToTimeTicks(5); |
| 503 | base::TimeTicks frame_time = MillisecondsToTimeTicks(10); |
| 504 | float scroll_delta = 5.f; |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 505 | SyntheticTouchScrollBegin(event_time, frame_time, scroll_delta); |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 506 | |
| 507 | event_time = MillisecondsToTimeTicks(15); |
| 508 | frame_time = MillisecondsToTimeTicks(20); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 509 | SyntheticTouchScrollUpdate(event_time, frame_time, scroll_delta); |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 510 | |
| 511 | event_time = MillisecondsToTimeTicks(25); |
| 512 | frame_time = MillisecondsToTimeTicks(30); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 513 | SyntheticTouchScrollUpdate(event_time, frame_time, scroll_delta); |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 514 | |
| 515 | // A ScrollBegin to flush unfinished frames. |
| 516 | event_time = MillisecondsToTimeTicks(1000); |
| 517 | frame_time = MillisecondsToTimeTicks(1000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 518 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 519 | |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 520 | CheckScrollUpdateHistogramsTotalCount(1); |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 521 | |
| 522 | // Send an event whose timestamp is earlier than the most recent event, |
| 523 | // representing an event that gets process out of order. |
| 524 | base::TimeTicks earlier_event_time = MillisecondsToTimeTicks(15); |
| 525 | frame_time = MillisecondsToTimeTicks(1010); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 526 | SyntheticTouchScrollUpdate(earlier_event_time, frame_time, scroll_delta); |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 527 | |
| 528 | // Another ScrollBegin to flush unfinished frames. |
| 529 | event_time = MillisecondsToTimeTicks(2000); |
| 530 | frame_time = MillisecondsToTimeTicks(2000); |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 531 | SyntheticTouchScrollBegin(event_time, frame_time, 0); |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 532 | |
| 533 | // Ensure that the event was ignored. |
Joao Victor Almeida | 0b3c5a9 | 2020-07-07 21:04:43 | [diff] [blame] | 534 | CheckScrollUpdateHistogramsTotalCount(1); |
Matt Amert | 9da83c3 | 2019-11-06 06:04:31 | [diff] [blame] | 535 | } |
| 536 | |
Ella Ge | 792e4f1 | 2019-04-05 17:32:15 | [diff] [blame] | 537 | } // namespace |
Joao Victor Almeida | 917ce17 | 2020-07-07 20:56:12 | [diff] [blame] | 538 | } // namespace cc |