Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(399)

Side by Side Diff: net/nqe/network_quality_estimator_unittest.cc

Issue 2076353002: Record NQE ECT at main frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "net/nqe/network_quality_estimator.h" 5 #include "net/nqe/network_quality_estimator.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 base::RunLoop().Run(); 377 base::RunLoop().Run();
378 378
379 // Both RTT and downstream throughput should be updated. 379 // Both RTT and downstream throughput should be updated.
380 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt)); 380 EXPECT_TRUE(estimator.GetHttpRTTEstimate(&rtt));
381 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); 381 EXPECT_TRUE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps));
382 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt)); 382 EXPECT_FALSE(estimator.GetTransportRTTEstimate(&rtt));
383 383
384 // Check UMA histograms. 384 // Check UMA histograms.
385 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); 385 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0);
386 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); 386 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0);
387 histogram_tester.ExpectUniqueSample(
388 "NQE.MainFrame.EffectiveConnectionType.Unknown",
389 NetworkQualityEstimator::EffectiveConnectionType::
390 EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
391 1);
387 392
388 std::unique_ptr<URLRequest> request2(context.CreateRequest( 393 std::unique_ptr<URLRequest> request2(context.CreateRequest(
389 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 394 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
390 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME); 395 request2->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME);
391 request2->Start(); 396 request2->Start();
392 base::RunLoop().Run(); 397 base::RunLoop().Run();
398 histogram_tester.ExpectTotalCount(
399 "NQE.MainFrame.EffectiveConnectionType.Unknown", 2);
393 400
394 estimator.SimulateNetworkChangeTo( 401 estimator.SimulateNetworkChangeTo(
395 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1"); 402 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, "test-1");
396 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); 403 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1);
397 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); 404 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1);
398 405
399 histogram_tester.ExpectTotalCount("NQE.RatioMedianRTT.WiFi", 0); 406 histogram_tester.ExpectTotalCount("NQE.RatioMedianRTT.WiFi", 0);
400 407
401 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile0.Unknown", 1); 408 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile0.Unknown", 1);
402 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile10.Unknown", 1); 409 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile10.Unknown", 1);
403 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile50.Unknown", 1); 410 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile50.Unknown", 1);
404 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile90.Unknown", 1); 411 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile90.Unknown", 1);
405 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile100.Unknown", 1); 412 histogram_tester.ExpectTotalCount("NQE.RTT.Percentile100.Unknown", 1);
406 413
407 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0); 414 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 0);
408 415
409 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); 416 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt));
410 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); 417 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps));
411 418
412 // Verify that metrics are logged correctly on main-frame requests. 419 // Verify that metrics are logged correctly on main-frame requests.
413 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50.Unknown", 420 histogram_tester.ExpectTotalCount("NQE.MainFrame.RTT.Percentile50.Unknown",
414 1); 421 1);
415 histogram_tester.ExpectTotalCount( 422 histogram_tester.ExpectTotalCount(
416 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", 0); 423 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", 0);
417 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50.Unknown", 424 histogram_tester.ExpectTotalCount("NQE.MainFrame.Kbps.Percentile50.Unknown",
418 1); 425 1);
426
419 estimator.SimulateNetworkChangeTo( 427 estimator.SimulateNetworkChangeTo(
420 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string()); 428 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI, std::string());
421 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); 429 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1);
422 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); 430 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1);
423 431
424 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); 432 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt));
425 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); 433 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps));
434
435 std::unique_ptr<URLRequest> request3(context.CreateRequest(
436 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
437 request3->SetLoadFlags(request2->load_flags() | LOAD_MAIN_FRAME);
438 request3->Start();
439 base::RunLoop().Run();
440 histogram_tester.ExpectUniqueSample(
441 "NQE.MainFrame.EffectiveConnectionType.WiFi",
442 NetworkQualityEstimator::EffectiveConnectionType::
443 EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
444 1);
426 } 445 }
427 446
428 TEST(NetworkQualityEstimatorTest, StoreObservations) { 447 TEST(NetworkQualityEstimatorTest, StoreObservations) {
429 std::map<std::string, std::string> variation_params; 448 std::map<std::string, std::string> variation_params;
430 TestNetworkQualityEstimator estimator(variation_params); 449 TestNetworkQualityEstimator estimator(variation_params);
431 450
432 base::TimeDelta rtt; 451 base::TimeDelta rtt;
433 int32_t kbps; 452 int32_t kbps;
434 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt)); 453 EXPECT_FALSE(estimator.GetHttpRTTEstimate(&rtt));
435 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); 454 EXPECT_FALSE(estimator.GetDownlinkThroughputKbpsEstimate(&kbps));
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 EXPECT_EQ(test.allow_small_localhost_requests, 1373 EXPECT_EQ(test.allow_small_localhost_requests,
1355 estimator.GetHttpRTTEstimate(&rtt)); 1374 estimator.GetHttpRTTEstimate(&rtt));
1356 EXPECT_EQ(test.allow_small_localhost_requests, 1375 EXPECT_EQ(test.allow_small_localhost_requests,
1357 estimator.GetDownlinkThroughputKbpsEstimate(&kbps)); 1376 estimator.GetDownlinkThroughputKbpsEstimate(&kbps));
1358 } 1377 }
1359 } 1378 }
1360 1379
1361 // Tests that the effective connection type is computed at the specified 1380 // Tests that the effective connection type is computed at the specified
1362 // interval, and that the observers are notified of any change. 1381 // interval, and that the observers are notified of any change.
1363 TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) { 1382 TEST(NetworkQualityEstimatorTest, TestEffectiveConnectionTypeObserver) {
1383 base::HistogramTester histogram_tester;
1364 std::unique_ptr<base::SimpleTestTickClock> tick_clock( 1384 std::unique_ptr<base::SimpleTestTickClock> tick_clock(
1365 new base::SimpleTestTickClock()); 1385 new base::SimpleTestTickClock());
1366 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); 1386 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get();
1367 1387
1368 TestEffectiveConnectionTypeObserver observer; 1388 TestEffectiveConnectionTypeObserver observer;
1369 std::map<std::string, std::string> variation_params; 1389 std::map<std::string, std::string> variation_params;
1370 TestNetworkQualityEstimator estimator(variation_params); 1390 TestNetworkQualityEstimator estimator(variation_params);
1371 estimator.AddEffectiveConnectionTypeObserver(&observer); 1391 estimator.AddEffectiveConnectionTypeObserver(&observer);
1372 estimator.SetTickClockForTesting(std::move(tick_clock)); 1392 estimator.SetTickClockForTesting(std::move(tick_clock));
1373 1393
1374 TestDelegate test_delegate; 1394 TestDelegate test_delegate;
1375 TestURLRequestContext context(true); 1395 TestURLRequestContext context(true);
1376 context.set_network_quality_estimator(&estimator); 1396 context.set_network_quality_estimator(&estimator);
1377 context.Init(); 1397 context.Init();
1378 1398
1379 EXPECT_EQ(0U, observer.effective_connection_types().size()); 1399 EXPECT_EQ(0U, observer.effective_connection_types().size());
1380 1400
1381 estimator.set_effective_connection_type( 1401 estimator.set_effective_connection_type(
1382 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G); 1402 NetworkQualityEstimator::EFFECTIVE_CONNECTION_TYPE_2G);
1383 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); 1403 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
1384 1404
1385 std::unique_ptr<URLRequest> request(context.CreateRequest( 1405 std::unique_ptr<URLRequest> request(context.CreateRequest(
1386 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 1406 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1387 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); 1407 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME);
1388 request->Start(); 1408 request->Start();
1389 base::RunLoop().Run(); 1409 base::RunLoop().Run();
1390 EXPECT_EQ(1U, observer.effective_connection_types().size()); 1410 EXPECT_EQ(1U, observer.effective_connection_types().size());
1411 histogram_tester.ExpectUniqueSample(
1412 "NQE.MainFrame.EffectiveConnectionType.Unknown",
1413 NetworkQualityEstimator::EffectiveConnectionType::
1414 EFFECTIVE_CONNECTION_TYPE_2G,
1415 1);
1391 1416
1392 // Next request should not trigger recomputation of effective connection type 1417 // Next request should not trigger recomputation of effective connection type
1393 // since there has been no change in the clock. 1418 // since there has been no change in the clock.
1394 std::unique_ptr<URLRequest> request2(context.CreateRequest( 1419 std::unique_ptr<URLRequest> request2(context.CreateRequest(
1395 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 1420 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1396 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME); 1421 request2->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME);
1397 request2->Start(); 1422 request2->Start();
1398 base::RunLoop().Run(); 1423 base::RunLoop().Run();
1399 EXPECT_EQ(1U, observer.effective_connection_types().size()); 1424 EXPECT_EQ(1U, observer.effective_connection_types().size());
1400 1425
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 rtt.InMilliseconds(), 1); 1590 rtt.InMilliseconds(), 1);
1566 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1); 1591 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile10.Unknown", 1);
1567 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1); 1592 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile50.Unknown", 1);
1568 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1); 1593 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile90.Unknown", 1);
1569 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown", 1594 histogram_tester.ExpectTotalCount("NQE.TransportRTT.Percentile100.Unknown",
1570 1); 1595 1);
1571 1596
1572 // Verify that metrics are logged correctly on main-frame requests. 1597 // Verify that metrics are logged correctly on main-frame requests.
1573 histogram_tester.ExpectTotalCount( 1598 histogram_tester.ExpectTotalCount(
1574 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests); 1599 "NQE.MainFrame.TransportRTT.Percentile50.Unknown", num_requests);
1600 histogram_tester.ExpectTotalCount(
1601 "NQE.MainFrame.EffectiveConnectionType.Unknown", num_requests);
1602 histogram_tester.ExpectBucketCount(
1603 "NQE.MainFrame.EffectiveConnectionType.Unknown",
1604 NetworkQualityEstimator::EffectiveConnectionType::
1605 EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
1606 1);
1575 } 1607 }
1576 1608
1577 #if defined(OS_IOS) 1609 #if defined(OS_IOS)
1578 // Flaky on iOS when |accuracy_recording_delay| is non-zero. 1610 // Flaky on iOS when |accuracy_recording_delay| is non-zero.
1579 #define MAYBE_RecordAccuracy DISABLED_RecordAccuracy 1611 #define MAYBE_RecordAccuracy DISABLED_RecordAccuracy
1580 #else 1612 #else
1581 #define MAYBE_RecordAccuracy RecordAccuracy 1613 #define MAYBE_RecordAccuracy RecordAccuracy
1582 #endif 1614 #endif
1583 // Tests if the NQE accuracy metrics are recorded properly. 1615 // Tests if the NQE accuracy metrics are recorded properly.
1584 TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) { 1616 TEST(NetworkQualityEstimatorTest, MAYBE_RecordAccuracy) {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType( 1722 std::string(NetworkQualityEstimator::GetNameForEffectiveConnectionType(
1691 effective_connection_type)); 1723 effective_connection_type));
1692 EXPECT_FALSE(connection_type_name.empty()); 1724 EXPECT_FALSE(connection_type_name.empty());
1693 EXPECT_EQ(effective_connection_type, 1725 EXPECT_EQ(effective_connection_type,
1694 NetworkQualityEstimator::GetEffectiveConnectionTypeForName( 1726 NetworkQualityEstimator::GetEffectiveConnectionTypeForName(
1695 connection_type_name)); 1727 connection_type_name));
1696 } 1728 }
1697 } 1729 }
1698 1730
1699 } // namespace net 1731 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698