OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "build/build_config.h" | 5 #include "build/build_config.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <shlobj.h> | 9 #include <shlobj.h> |
10 #endif | 10 #endif |
(...skipping 4059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4070 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) | 4070 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) |
4071 << " Parameter = \"" << test_file << "\""; | 4071 << " Parameter = \"" << test_file << "\""; |
4072 } | 4072 } |
4073 } | 4073 } |
4074 } | 4074 } |
4075 } | 4075 } |
4076 | 4076 |
4077 TEST_F(URLRequestTestHTTP, NetworkQualityEstimator) { | 4077 TEST_F(URLRequestTestHTTP, NetworkQualityEstimator) { |
4078 ASSERT_TRUE(test_server_.Start()); | 4078 ASSERT_TRUE(test_server_.Start()); |
4079 // Enable requests to local host to be used for network quality estimation. | 4079 // Enable requests to local host to be used for network quality estimation. |
4080 NetworkQualityEstimator estimator(true); | 4080 NetworkQualityEstimator estimator(true, true); |
4081 | 4081 |
4082 TestDelegate d; | 4082 TestDelegate d; |
4083 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 4083 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
4084 TestURLRequestContext context(true); | 4084 TestURLRequestContext context(true); |
4085 context.set_network_quality_estimator(&estimator); | 4085 context.set_network_quality_estimator(&estimator); |
4086 context.set_network_delegate(&network_delegate); | 4086 context.set_network_delegate(&network_delegate); |
4087 context.Init(); | 4087 context.Init(); |
4088 | 4088 |
4089 uint64_t min_transfer_size_in_bytes = | 4089 std::string url = "echo.html"; |
4090 NetworkQualityEstimator::kMinTransferSizeInBytes; | |
4091 // Create a long enough URL such that response size exceeds network quality | |
4092 // estimator's minimum transfer size. | |
4093 std::string url = "echo.html?"; | |
4094 url.append(min_transfer_size_in_bytes, 'x'); | |
4095 | 4090 |
4096 scoped_ptr<URLRequest> r( | 4091 scoped_ptr<URLRequest> r( |
4097 context.CreateRequest(test_server_.GetURL(url), DEFAULT_PRIORITY, &d)); | 4092 context.CreateRequest(test_server_.GetURL(url), DEFAULT_PRIORITY, &d)); |
4098 int sleep_duration_milliseconds = 1; | |
4099 base::PlatformThread::Sleep( | |
4100 base::TimeDelta::FromMilliseconds(sleep_duration_milliseconds)); | |
4101 r->Start(); | 4093 r->Start(); |
4102 | 4094 |
4103 base::RunLoop().Run(); | 4095 base::RunLoop().Run(); |
4104 | 4096 |
4105 NetworkQuality network_quality = | 4097 NetworkQuality network_quality = |
4106 context.network_quality_estimator()->GetPeakEstimate(); | 4098 context.network_quality_estimator()->GetPeakEstimate(); |
4107 EXPECT_GE(network_quality.rtt(), | 4099 EXPECT_GE(network_quality.rtt(), base::TimeDelta()); |
4108 base::TimeDelta::FromMilliseconds(sleep_duration_milliseconds)); | 4100 EXPECT_LT(network_quality.rtt(), base::TimeDelta::Max()); |
4109 EXPECT_GT(network_quality.downstream_throughput_kbps(), 0); | 4101 EXPECT_GT(network_quality.downstream_throughput_kbps(), 0); |
4110 | 4102 |
4111 // Verify that histograms are not populated. They should populate only when | 4103 // Verify that histograms are not populated. They should populate only when |
4112 // there is a change in ConnectionType. | 4104 // there is a change in ConnectionType. |
4113 base::HistogramTester histogram_tester; | 4105 base::HistogramTester histogram_tester; |
4114 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); | 4106 histogram_tester.ExpectTotalCount("NQE.PeakKbps.Unknown", 0); |
4115 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); | 4107 histogram_tester.ExpectTotalCount("NQE.FastestRTT.Unknown", 0); |
4116 | 4108 |
4117 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests( | 4109 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests( |
4118 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); | 4110 NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); |
(...skipping 5059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9178 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 9170 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); |
9179 | 9171 |
9180 EXPECT_FALSE(req->response_info().network_accessed); | 9172 EXPECT_FALSE(req->response_info().network_accessed); |
9181 | 9173 |
9182 req->Start(); | 9174 req->Start(); |
9183 base::RunLoop().Run(); | 9175 base::RunLoop().Run(); |
9184 EXPECT_TRUE(req->response_info().network_accessed); | 9176 EXPECT_TRUE(req->response_info().network_accessed); |
9185 } | 9177 } |
9186 | 9178 |
9187 } // namespace net | 9179 } // namespace net |
OLD | NEW |