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

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

Issue 1164713004: Store network quality samples so we can compute percentiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mmenke comments Created 5 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
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/base/network_quality_estimator.h" 5 #include "net/base/network_quality_estimator.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 14 matching lines...) Expand all
25 #if !defined(OS_IOS) 25 #if !defined(OS_IOS)
26 TEST(NetworkQualityEstimatorTest, TestPeakKbpsFastestRTTUpdates) { 26 TEST(NetworkQualityEstimatorTest, TestPeakKbpsFastestRTTUpdates) {
27 SpawnedTestServer test_server_( 27 SpawnedTestServer test_server_(
28 SpawnedTestServer::TYPE_HTTP, SpawnedTestServer::kLocalhost, 28 SpawnedTestServer::TYPE_HTTP, SpawnedTestServer::kLocalhost,
29 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 29 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
30 ASSERT_TRUE(test_server_.Start()); 30 ASSERT_TRUE(test_server_.Start());
31 31
32 // Enable requests to local host to be used for network quality estimation. 32 // Enable requests to local host to be used for network quality estimation.
33 NetworkQualityEstimator estimator(true); 33 NetworkQualityEstimator estimator(true);
34 { 34 {
35 NetworkQuality network_quality = estimator.GetEstimate(); 35 NetworkQuality network_quality = estimator.GetPeakEstimate();
36 EXPECT_EQ(network_quality.fastest_rtt_confidence, 0); 36 EXPECT_EQ(network_quality.GetRtt(), base::TimeDelta());
37 EXPECT_EQ(network_quality.peak_throughput_kbps_confidence, 0); 37 EXPECT_EQ(network_quality.GetThroughputKbps(), 0U);
38 } 38 }
39 39
40 TestDelegate d; 40 TestDelegate d;
41 TestURLRequestContext context(false); 41 TestURLRequestContext context(false);
42 42
43 uint64_t min_transfer_size_in_bytes = 43 uint64_t min_transfer_size_in_bytes =
44 NetworkQualityEstimator::kMinTransferSizeInBytes; 44 NetworkQualityEstimator::kMinTransferSizeInBytes;
45 base::TimeDelta request_duration = base::TimeDelta::FromMicroseconds( 45 base::TimeDelta request_duration = base::TimeDelta::FromMicroseconds(
46 NetworkQualityEstimator::kMinRequestDurationMicroseconds); 46 NetworkQualityEstimator::kMinRequestDurationMicroseconds);
47 47
48 scoped_ptr<URLRequest> request(context.CreateRequest( 48 scoped_ptr<URLRequest> request(context.CreateRequest(
49 test_server_.GetURL("echo.html"), DEFAULT_PRIORITY, &d)); 49 test_server_.GetURL("echo.html"), DEFAULT_PRIORITY, &d));
50 request->Start(); 50 request->Start();
51 51
52 base::RunLoop().Run(); 52 base::RunLoop().Run();
53 53
54 base::PlatformThread::Sleep(request_duration); 54 base::PlatformThread::Sleep(request_duration);
55 55
56 // With smaller transfer, |fastest_rtt| will be updated but not 56 // With smaller transfer, |fastest_rtt| will be updated but not
57 // |peak_throughput_kbps|. 57 // |peak_throughput_kbps|.
58 estimator.NotifyDataReceived(*(request.get()), 58 estimator.NotifyDataReceived(*(request.get()), min_transfer_size_in_bytes - 1,
59 min_transfer_size_in_bytes - 1); 59 min_transfer_size_in_bytes - 1);
60 { 60 {
61 NetworkQuality network_quality = estimator.GetEstimate(); 61 NetworkQuality network_quality = estimator.GetPeakEstimate();
62 EXPECT_GT(network_quality.fastest_rtt_confidence, 0); 62 EXPECT_GT(network_quality.GetRtt(), base::TimeDelta());
63 EXPECT_EQ(network_quality.peak_throughput_kbps_confidence, 0); 63 EXPECT_EQ(network_quality.GetThroughputKbps(), 0U);
64 } 64 }
65 65
66 // With large transfer, both |fastest_rtt| and |peak_throughput_kbps| will be 66 // With large transfer, both |fastest_rtt| and |peak_throughput_kbps| will be
67 // updated. 67 // updated.
68 estimator.NotifyDataReceived(*(request.get()), min_transfer_size_in_bytes); 68 estimator.NotifyDataReceived(*(request.get()), min_transfer_size_in_bytes,
69 min_transfer_size_in_bytes);
69 { 70 {
70 NetworkQuality network_quality = estimator.GetEstimate(); 71 NetworkQuality network_quality = estimator.GetPeakEstimate();
71 EXPECT_GT(network_quality.fastest_rtt_confidence, 0); 72 EXPECT_GE(network_quality.GetRtt(), request_duration);
72 EXPECT_GT(network_quality.peak_throughput_kbps_confidence, 0); 73 EXPECT_GT(network_quality.GetThroughputKbps(), 0U);
73 EXPECT_GE(network_quality.fastest_rtt, request_duration);
74 EXPECT_GT(network_quality.peak_throughput_kbps, uint32_t(0));
75 EXPECT_LE( 74 EXPECT_LE(
76 network_quality.peak_throughput_kbps, 75 network_quality.GetThroughputKbps(),
77 min_transfer_size_in_bytes * 8.0 / request_duration.InMilliseconds()); 76 min_transfer_size_in_bytes * 8.0 / request_duration.InMilliseconds());
78 } 77 }
79 EXPECT_EQ(estimator.bytes_read_since_last_connection_change_, true); 78 EXPECT_EQ(estimator.bytes_read_since_last_connection_change_, true);
80 79
81 // Check UMA histograms. 80 // Check UMA histograms.
82 base::HistogramTester histogram_tester; 81 base::HistogramTester histogram_tester;
83 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); 82 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0);
84 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); 83 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0);
85 84
86 estimator.OnConnectionTypeChanged( 85 estimator.OnConnectionTypeChanged(
87 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); 86 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
88 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1); 87 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 1);
89 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1); 88 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 1);
90 { 89 {
91 NetworkQuality network_quality = estimator.GetEstimate(); 90 NetworkQuality network_quality = estimator.GetPeakEstimate();
92 EXPECT_EQ(estimator.current_connection_type_, 91 EXPECT_EQ(estimator.current_connection_type_,
93 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); 92 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI);
94 EXPECT_EQ(network_quality.fastest_rtt_confidence, 0); 93 EXPECT_EQ(network_quality.GetRtt(), base::TimeDelta());
95 EXPECT_EQ(network_quality.peak_throughput_kbps_confidence, 0); 94 EXPECT_EQ(network_quality.GetThroughputKbps(), 0U);
96 } 95 }
97 } 96 }
98 #endif // !defined(OS_IOS) 97 #endif // !defined(OS_IOS)
99 98
100 } // namespace net 99 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698