| 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 <cmath> // For std::modf. | 5 #include <cmath> // For std::modf. |
| 6 #include <map> | 6 #include <map> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 network_quality_1); | 262 network_quality_1); |
| 263 | 263 |
| 264 EXPECT_TRUE(embedded_test_server()->Start()); | 264 EXPECT_TRUE(embedded_test_server()->Start()); |
| 265 EXPECT_TRUE( | 265 EXPECT_TRUE( |
| 266 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); | 266 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); |
| 267 | 267 |
| 268 FetchHistogramsFromChildProcesses(); | 268 FetchHistogramsFromChildProcesses(); |
| 269 EXPECT_FALSE( | 269 EXPECT_FALSE( |
| 270 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty()); | 270 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty()); |
| 271 | 271 |
| 272 EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(), | 272 EXPECT_EQ(network_quality_1.http_rtt().InMilliseconds(), |
| 273 RunScriptExtractInt("getRtt()")); | 273 RunScriptExtractInt("getRtt()")); |
| 274 EXPECT_EQ( | 274 EXPECT_EQ( |
| 275 static_cast<double>(network_quality_1.downstream_throughput_kbps()) / | 275 static_cast<double>(network_quality_1.downstream_throughput_kbps()) / |
| 276 1000, | 276 1000, |
| 277 RunScriptExtractDouble("getDownlink()")); | 277 RunScriptExtractDouble("getDownlink()")); |
| 278 | 278 |
| 279 // Verify that the network quality change is accessible via Javascript API. | 279 // Verify that the network quality change is accessible via Javascript API. |
| 280 net::nqe::internal::NetworkQuality network_quality_2( | 280 net::nqe::internal::NetworkQuality network_quality_2( |
| 281 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000); | 281 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000); |
| 282 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 282 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 283 network_quality_2); | 283 network_quality_2); |
| 284 base::RunLoop().RunUntilIdle(); | 284 base::RunLoop().RunUntilIdle(); |
| 285 EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(), | 285 EXPECT_EQ(network_quality_2.http_rtt().InMilliseconds(), |
| 286 RunScriptExtractInt("getRtt()")); | 286 RunScriptExtractInt("getRtt()")); |
| 287 EXPECT_EQ( | 287 EXPECT_EQ( |
| 288 static_cast<double>(network_quality_2.downstream_throughput_kbps()) / | 288 static_cast<double>(network_quality_2.downstream_throughput_kbps()) / |
| 289 1000, | 289 1000, |
| 290 RunScriptExtractDouble("getDownlink()")); | 290 RunScriptExtractDouble("getDownlink()")); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // Make sure the changes in the network quality are rounded to the nearest | 293 // Make sure the changes in the network quality are rounded to the nearest |
| 294 // 25 milliseconds or 25 kbps. | 294 // 25 milliseconds or 25 kbps. |
| 295 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) { | 295 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) { |
| 296 base::HistogramTester histogram_tester; | 296 base::HistogramTester histogram_tester; |
| 297 net::TestNetworkQualityEstimator estimator( | 297 net::TestNetworkQualityEstimator estimator( |
| 298 std::unique_ptr<net::ExternalEstimateProvider>(), | 298 std::unique_ptr<net::ExternalEstimateProvider>(), |
| 299 std::map<std::string, std::string>(), false, false, true, true, | 299 std::map<std::string, std::string>(), false, false, true, true, |
| 300 base::MakeUnique<net::BoundTestNetLog>()); | 300 base::MakeUnique<net::BoundTestNetLog>()); |
| 301 NetworkQualityObserverImpl impl(&estimator); | 301 NetworkQualityObserverImpl impl(&estimator); |
| 302 | 302 |
| 303 // Verify that the network quality is rounded properly. | 303 // Verify that the network quality is rounded properly. |
| 304 net::nqe::internal::NetworkQuality network_quality_1( | 304 net::nqe::internal::NetworkQuality network_quality_1( |
| 305 base::TimeDelta::FromMilliseconds(123), | 305 base::TimeDelta::FromMilliseconds(123), |
| 306 base::TimeDelta::FromMilliseconds(212), 303); | 306 base::TimeDelta::FromMilliseconds(212), 303); |
| 307 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 307 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 308 network_quality_1); | 308 network_quality_1); |
| 309 | 309 |
| 310 EXPECT_TRUE(embedded_test_server()->Start()); | 310 EXPECT_TRUE(embedded_test_server()->Start()); |
| 311 EXPECT_TRUE( | 311 EXPECT_TRUE( |
| 312 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); | 312 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); |
| 313 EXPECT_EQ(200, RunScriptExtractInt("getRtt()")); | 313 EXPECT_EQ(125, RunScriptExtractInt("getRtt()")); |
| 314 EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()")); | 314 EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()")); |
| 315 | 315 |
| 316 net::nqe::internal::NetworkQuality network_quality_2( | 316 net::nqe::internal::NetworkQuality network_quality_2( |
| 317 base::TimeDelta::FromMilliseconds(123), | 317 base::TimeDelta::FromMilliseconds(1123), |
| 318 base::TimeDelta::FromMilliseconds(1217), 1317); | 318 base::TimeDelta::FromMilliseconds(212), 1317); |
| 319 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 319 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 320 network_quality_2); | 320 network_quality_2); |
| 321 base::RunLoop().RunUntilIdle(); | 321 base::RunLoop().RunUntilIdle(); |
| 322 EXPECT_EQ(1225, RunScriptExtractInt("getRtt()")); | 322 EXPECT_EQ(1125, RunScriptExtractInt("getRtt()")); |
| 323 EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()")); | 323 EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()")); |
| 324 | 324 |
| 325 net::nqe::internal::NetworkQuality network_quality_3( | 325 net::nqe::internal::NetworkQuality network_quality_3( |
| 326 base::TimeDelta::FromMilliseconds(12), | 326 base::TimeDelta::FromMilliseconds(12), |
| 327 base::TimeDelta::FromMilliseconds(12), 12); | 327 base::TimeDelta::FromMilliseconds(12), 12); |
| 328 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 328 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 329 network_quality_3); | 329 network_quality_3); |
| 330 base::RunLoop().RunUntilIdle(); | 330 base::RunLoop().RunUntilIdle(); |
| 331 EXPECT_EQ(0, RunScriptExtractInt("getRtt()")); | 331 EXPECT_EQ(0, RunScriptExtractInt("getRtt()")); |
| 332 EXPECT_EQ(0, RunScriptExtractDouble("getDownlink()")); | 332 EXPECT_EQ(0, RunScriptExtractDouble("getDownlink()")); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 343 // Verify that the network quality is rounded properly. | 343 // Verify that the network quality is rounded properly. |
| 344 net::nqe::internal::NetworkQuality network_quality_1( | 344 net::nqe::internal::NetworkQuality network_quality_1( |
| 345 base::TimeDelta::FromMilliseconds(1123), | 345 base::TimeDelta::FromMilliseconds(1123), |
| 346 base::TimeDelta::FromMilliseconds(1212), 1303); | 346 base::TimeDelta::FromMilliseconds(1212), 1303); |
| 347 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 347 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 348 network_quality_1); | 348 network_quality_1); |
| 349 | 349 |
| 350 EXPECT_TRUE(embedded_test_server()->Start()); | 350 EXPECT_TRUE(embedded_test_server()->Start()); |
| 351 EXPECT_TRUE( | 351 EXPECT_TRUE( |
| 352 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); | 352 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); |
| 353 EXPECT_EQ(1200, RunScriptExtractInt("getRtt()")); | 353 EXPECT_EQ(1125, RunScriptExtractInt("getRtt()")); |
| 354 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()")); | 354 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()")); |
| 355 | 355 |
| 356 // All the 3 metrics change by less than 10%. So, the observers are not | 356 // All the 3 metrics change by less than 10%. So, the observers are not |
| 357 // notified. | 357 // notified. |
| 358 net::nqe::internal::NetworkQuality network_quality_2( | 358 net::nqe::internal::NetworkQuality network_quality_2( |
| 359 base::TimeDelta::FromMilliseconds(1223), | 359 base::TimeDelta::FromMilliseconds(1223), |
| 360 base::TimeDelta::FromMilliseconds(1312), 1403); | 360 base::TimeDelta::FromMilliseconds(1312), 1403); |
| 361 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 361 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 362 network_quality_2); | 362 network_quality_2); |
| 363 base::RunLoop().RunUntilIdle(); | 363 base::RunLoop().RunUntilIdle(); |
| 364 EXPECT_EQ(1200, RunScriptExtractInt("getRtt()")); | 364 EXPECT_EQ(1125, RunScriptExtractInt("getRtt()")); |
| 365 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()")); | 365 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()")); |
| 366 | 366 |
| 367 // Transport RTT has changed by more than 10% from the last notified value of | 367 // HTTP RTT has changed by more than 10% from the last notified value of |
| 368 // |network_quality_1|. The observers should be notified. | 368 // |network_quality_1|. The observers should be notified. |
| 369 net::nqe::internal::NetworkQuality network_quality_3( | 369 net::nqe::internal::NetworkQuality network_quality_3( |
| 370 base::TimeDelta::FromMilliseconds(1223), | 370 base::TimeDelta::FromMilliseconds(2223), |
| 371 base::TimeDelta::FromMilliseconds(2312), 1403); | 371 base::TimeDelta::FromMilliseconds(1312), 1403); |
| 372 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 372 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 373 network_quality_3); | 373 network_quality_3); |
| 374 base::RunLoop().RunUntilIdle(); | 374 base::RunLoop().RunUntilIdle(); |
| 375 EXPECT_EQ(2300, RunScriptExtractInt("getRtt()")); | 375 EXPECT_EQ(2225, RunScriptExtractInt("getRtt()")); |
| 376 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()")); | 376 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()")); |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace content | 379 } // namespace content |
| OLD | NEW |