OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/browser/renderer_host/input/render_widget_host_latency_tracker
.h" | 5 #include "content/browser/renderer_host/input/render_widget_host_latency_tracker
.h" |
6 #include "base/metrics/metrics_hashes.h" | 6 #include "base/metrics/metrics_hashes.h" |
7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
8 #include "components/metrics/proto/ukm/entry.pb.h" | 8 #include "components/metrics/proto/ukm/entry.pb.h" |
9 #include "components/rappor/public/rappor_utils.h" | 9 #include "components/rappor/public/rappor_utils.h" |
10 #include "components/rappor/test_rappor_service.h" | 10 #include "components/rappor/test_rappor_service.h" |
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 fake_latency, ack_state); | 1278 fake_latency, ack_state); |
1279 | 1279 |
1280 tracker()->OnInputEventAck(wheel_event, &latency, ack_state); | 1280 tracker()->OnInputEventAck(wheel_event, &latency, ack_state); |
1281 } | 1281 } |
1282 | 1282 |
1283 EXPECT_THAT(histogram_tester().GetAllSamples( | 1283 EXPECT_THAT(histogram_tester().GetAllSamples( |
1284 "Event.Latency.QueueingTime.MouseWheelDefaultAllowed"), | 1284 "Event.Latency.QueueingTime.MouseWheelDefaultAllowed"), |
1285 ElementsAre(Bucket(14, 1))); | 1285 ElementsAre(Bucket(14, 1))); |
1286 } | 1286 } |
1287 | 1287 |
| 1288 TEST_F(RenderWidgetHostLatencyTrackerTest, ExpectedQueueingTimeAccuracy) { |
| 1289 // These numbers are sensitive to where the histogram buckets are. |
| 1290 int event_timestamps_ms[] = {11, 25, 35}; |
| 1291 |
| 1292 for (float expected_queueing_time_ms : {2, 15, 200, 400}) { |
| 1293 base::TimeDelta expected_queueing_time = |
| 1294 base::TimeDelta::FromMilliseconds(expected_queueing_time_ms); |
| 1295 SyntheticWebTouchEvent event; |
| 1296 // Touch start. |
| 1297 event.PressPoint(1, 1); |
| 1298 |
| 1299 ui::LatencyInfo latency; |
| 1300 latency.set_source_event_type(ui::SourceEventType::TOUCH); |
| 1301 tracker()->OnInputEvent(event, &latency); |
| 1302 |
| 1303 ui::LatencyInfo fake_latency; |
| 1304 fake_latency.set_expected_queueing_time_on_dispatch(expected_queueing_time); |
| 1305 fake_latency.set_source_event_type(ui::SourceEventType::TOUCH); |
| 1306 fake_latency.AddLatencyNumberWithTimestamp( |
| 1307 ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
| 1308 tracker()->latency_component_id(), 0, |
| 1309 base::TimeTicks() + |
| 1310 base::TimeDelta::FromMilliseconds(event_timestamps_ms[0]), |
| 1311 1); |
| 1312 |
| 1313 fake_latency.AddLatencyNumberWithTimestamp( |
| 1314 ui::INPUT_EVENT_LATENCY_RENDERER_MAIN_COMPONENT, 0, 0, |
| 1315 base::TimeTicks() + |
| 1316 base::TimeDelta::FromMilliseconds(event_timestamps_ms[1]), |
| 1317 1); |
| 1318 |
| 1319 fake_latency.AddLatencyNumberWithTimestamp( |
| 1320 ui::INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT, 0, 0, |
| 1321 base::TimeTicks() + |
| 1322 base::TimeDelta::FromMilliseconds(event_timestamps_ms[2]), |
| 1323 1); |
| 1324 |
| 1325 // Call ComputeInputLatencyHistograms directly to avoid OnInputEventAck |
| 1326 // overwriting components. |
| 1327 tracker()->ComputeInputLatencyHistograms( |
| 1328 event.GetType(), tracker()->latency_component_id(), fake_latency, |
| 1329 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1330 |
| 1331 tracker()->OnInputEventAck(event, &latency, |
| 1332 INPUT_EVENT_ACK_STATE_NOT_CONSUMED); |
| 1333 } |
| 1334 |
| 1335 EXPECT_THAT( |
| 1336 histogram_tester().GetAllSamples( |
| 1337 "RendererScheduler." |
| 1338 "QueueingDurationWhenExpectedQueueingTime.LessThan.10ms"), |
| 1339 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 1))); |
| 1340 |
| 1341 EXPECT_THAT( |
| 1342 histogram_tester().GetAllSamples( |
| 1343 "RendererScheduler." |
| 1344 "QueueingDurationWhenExpectedQueueingTime.LessThan.150ms"), |
| 1345 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 2))); |
| 1346 |
| 1347 EXPECT_THAT( |
| 1348 histogram_tester().GetAllSamples( |
| 1349 "RendererScheduler." |
| 1350 "QueueingDurationWhenExpectedQueueingTime.LessThan.300ms"), |
| 1351 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 3))); |
| 1352 |
| 1353 EXPECT_THAT( |
| 1354 histogram_tester().GetAllSamples( |
| 1355 "RendererScheduler." |
| 1356 "QueueingDurationWhenExpectedQueueingTime.LessThan.450ms"), |
| 1357 ElementsAre(Bucket(event_timestamps_ms[1] - event_timestamps_ms[0], 4))); |
| 1358 } |
| 1359 |
1288 } // namespace content | 1360 } // namespace content |
OLD | NEW |