| OLD | NEW |
| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", | 162 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 163 false, 1); | 163 false, 1); |
| 164 | 164 |
| 165 base::TimeDelta rtt; | 165 base::TimeDelta rtt; |
| 166 int32_t kbps; | 166 int32_t kbps; |
| 167 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 167 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 168 EXPECT_FALSE( | 168 EXPECT_FALSE( |
| 169 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 169 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 170 | 170 |
| 171 TestDelegate test_delegate; | 171 TestDelegate test_delegate; |
| 172 // These tests expect the URLRequestContext to use the NQE, but not the | 172 TestURLRequestContext context(true); |
| 173 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 174 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 175 // by the HttpNetworkSession. | |
| 176 // TODO(tbansal): Fix that. | |
| 177 TestURLRequestContext context; | |
| 178 context.set_network_quality_estimator(&estimator); | 173 context.set_network_quality_estimator(&estimator); |
| 174 context.Init(); |
| 179 | 175 |
| 180 std::unique_ptr<URLRequest> request(context.CreateRequest( | 176 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 181 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 177 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 182 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 178 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 183 request->Start(); | 179 request->Start(); |
| 184 base::RunLoop().Run(); | 180 base::RunLoop().Run(); |
| 185 | 181 |
| 186 // Both RTT and downstream throughput should be updated. | 182 // Both RTT and downstream throughput should be updated. |
| 187 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 183 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 188 EXPECT_TRUE( | 184 EXPECT_TRUE( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", | 300 histogram_tester.ExpectUniqueSample("NQE.CachedNetworkQualityAvailable", |
| 305 false, 1); | 301 false, 1); |
| 306 | 302 |
| 307 base::TimeDelta rtt; | 303 base::TimeDelta rtt; |
| 308 int32_t kbps; | 304 int32_t kbps; |
| 309 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 305 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 310 EXPECT_FALSE( | 306 EXPECT_FALSE( |
| 311 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 307 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 312 | 308 |
| 313 TestDelegate test_delegate; | 309 TestDelegate test_delegate; |
| 314 // These tests expect the URLRequestContext to use the NQE, but not the | 310 TestURLRequestContext context(true); |
| 315 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 316 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 317 // by the HttpNetworkSession. | |
| 318 // TODO(tbansal): Fix that. | |
| 319 TestURLRequestContext context; | |
| 320 context.set_network_quality_estimator(&estimator); | 311 context.set_network_quality_estimator(&estimator); |
| 312 context.Init(); |
| 321 | 313 |
| 322 // Start two requests so that the network quality is added to cache store at | 314 // Start two requests so that the network quality is added to cache store at |
| 323 // the beginning of the second request from the network traffic observed from | 315 // the beginning of the second request from the network traffic observed from |
| 324 // the first request. | 316 // the first request. |
| 325 for (size_t i = 0; i < 2; ++i) { | 317 for (size_t i = 0; i < 2; ++i) { |
| 326 std::unique_ptr<URLRequest> request(context.CreateRequest( | 318 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 327 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 319 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 328 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 320 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 329 request->Start(); | 321 request->Start(); |
| 330 base::RunLoop().Run(); | 322 base::RunLoop().Run(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 std::map<std::string, std::string> variation_params; | 361 std::map<std::string, std::string> variation_params; |
| 370 TestNetworkQualityEstimator estimator(variation_params); | 362 TestNetworkQualityEstimator estimator(variation_params); |
| 371 | 363 |
| 372 base::TimeDelta rtt; | 364 base::TimeDelta rtt; |
| 373 int32_t kbps; | 365 int32_t kbps; |
| 374 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 366 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 375 EXPECT_FALSE( | 367 EXPECT_FALSE( |
| 376 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 368 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 377 | 369 |
| 378 TestDelegate test_delegate; | 370 TestDelegate test_delegate; |
| 379 // These tests expect the URLRequestContext to use the NQE, but not the | 371 TestURLRequestContext context(true); |
| 380 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 381 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 382 // by the HttpNetworkSession. | |
| 383 // TODO(tbansal): Fix that. | |
| 384 TestURLRequestContext context; | |
| 385 context.set_network_quality_estimator(&estimator); | 372 context.set_network_quality_estimator(&estimator); |
| 373 context.Init(); |
| 386 | 374 |
| 387 // Push more observations than the maximum buffer size. | 375 // Push more observations than the maximum buffer size. |
| 388 const size_t kMaxObservations = 1000; | 376 const size_t kMaxObservations = 1000; |
| 389 for (size_t i = 0; i < kMaxObservations; ++i) { | 377 for (size_t i = 0; i < kMaxObservations; ++i) { |
| 390 std::unique_ptr<URLRequest> request(context.CreateRequest( | 378 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 391 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 379 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 392 request->Start(); | 380 request->Start(); |
| 393 base::RunLoop().Run(); | 381 base::RunLoop().Run(); |
| 394 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 382 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 395 EXPECT_TRUE( | 383 EXPECT_TRUE( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 418 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); | 406 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC); |
| 419 | 407 |
| 420 EXPECT_EQ(nqe::internal::InvalidRTT(), | 408 EXPECT_EQ(nqe::internal::InvalidRTT(), |
| 421 estimator.GetRTTEstimateInternal(disallowed_observation_sources, | 409 estimator.GetRTTEstimateInternal(disallowed_observation_sources, |
| 422 base::TimeTicks(), 100)); | 410 base::TimeTicks(), 100)); |
| 423 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 411 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 424 estimator.GetDownlinkThroughputKbpsEstimateInternal( | 412 estimator.GetDownlinkThroughputKbpsEstimateInternal( |
| 425 base::TimeTicks(), 100)); | 413 base::TimeTicks(), 100)); |
| 426 | 414 |
| 427 TestDelegate test_delegate; | 415 TestDelegate test_delegate; |
| 428 // These tests expect the URLRequestContext to use the NQE, but not the | 416 TestURLRequestContext context(true); |
| 429 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 430 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 431 // by the HttpNetworkSession. | |
| 432 // TODO(tbansal): Fix that. | |
| 433 TestURLRequestContext context; | |
| 434 context.set_network_quality_estimator(&estimator); | 417 context.set_network_quality_estimator(&estimator); |
| 418 context.Init(); |
| 435 | 419 |
| 436 // Number of observations are more than the maximum buffer size. | 420 // Number of observations are more than the maximum buffer size. |
| 437 for (size_t i = 0; i < 1000U; ++i) { | 421 for (size_t i = 0; i < 1000U; ++i) { |
| 438 std::unique_ptr<URLRequest> request(context.CreateRequest( | 422 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 439 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 423 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 440 request->Start(); | 424 request->Start(); |
| 441 base::RunLoop().Run(); | 425 base::RunLoop().Run(); |
| 442 } | 426 } |
| 443 | 427 |
| 444 // Verify the percentiles through simple tests. | 428 // Verify the percentiles through simple tests. |
| (...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1317 // provided by external estimate provider. | 1301 // provided by external estimate provider. |
| 1318 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1302 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1319 EXPECT_EQ(external_estimate_provider_rtt, rtt); | 1303 EXPECT_EQ(external_estimate_provider_rtt, rtt); |
| 1320 | 1304 |
| 1321 int32_t kbps; | 1305 int32_t kbps; |
| 1322 EXPECT_TRUE( | 1306 EXPECT_TRUE( |
| 1323 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1307 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1324 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); | 1308 EXPECT_EQ(external_estimate_provider_downstream_throughput, kbps); |
| 1325 | 1309 |
| 1326 TestDelegate test_delegate; | 1310 TestDelegate test_delegate; |
| 1327 // These tests expect the URLRequestContext to use the NQE, but not the | 1311 TestURLRequestContext context(true); |
| 1328 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 1329 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 1330 // by the HttpNetworkSession. | |
| 1331 // TODO(tbansal): Fix that. | |
| 1332 TestURLRequestContext context; | |
| 1333 context.set_network_quality_estimator(&estimator); | 1312 context.set_network_quality_estimator(&estimator); |
| 1313 context.Init(); |
| 1334 | 1314 |
| 1335 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1315 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1336 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1316 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1337 request->Start(); | 1317 request->Start(); |
| 1338 base::RunLoop().Run(); | 1318 base::RunLoop().Run(); |
| 1339 | 1319 |
| 1340 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1320 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1341 EXPECT_NE(external_estimate_provider_rtt, rtt); | 1321 EXPECT_NE(external_estimate_provider_rtt, rtt); |
| 1342 | 1322 |
| 1343 EXPECT_TRUE( | 1323 EXPECT_TRUE( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1368 test.allow_small_localhost_requests, | 1348 test.allow_small_localhost_requests, |
| 1369 test.allow_small_localhost_requests); | 1349 test.allow_small_localhost_requests); |
| 1370 | 1350 |
| 1371 base::TimeDelta rtt; | 1351 base::TimeDelta rtt; |
| 1372 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1352 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1373 int32_t kbps; | 1353 int32_t kbps; |
| 1374 EXPECT_FALSE( | 1354 EXPECT_FALSE( |
| 1375 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); | 1355 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); |
| 1376 | 1356 |
| 1377 TestDelegate test_delegate; | 1357 TestDelegate test_delegate; |
| 1378 // These tests expect the URLRequestContext to use the NQE, but not the | 1358 TestURLRequestContext context(true); |
| 1379 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 1380 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 1381 // by the HttpNetworkSession. | |
| 1382 // TODO(tbansal): Fix that. | |
| 1383 TestURLRequestContext context; | |
| 1384 context.set_network_quality_estimator(&estimator); | 1359 context.set_network_quality_estimator(&estimator); |
| 1360 context.Init(); |
| 1385 | 1361 |
| 1386 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1362 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1387 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1363 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1388 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1364 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1389 request->Start(); | 1365 request->Start(); |
| 1390 base::RunLoop().Run(); | 1366 base::RunLoop().Run(); |
| 1391 | 1367 |
| 1392 EXPECT_EQ(test.allow_small_localhost_requests, | 1368 EXPECT_EQ(test.allow_small_localhost_requests, |
| 1393 estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1369 estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1394 EXPECT_EQ( | 1370 EXPECT_EQ( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1405 new base::SimpleTestTickClock()); | 1381 new base::SimpleTestTickClock()); |
| 1406 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1382 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1407 | 1383 |
| 1408 TestEffectiveConnectionTypeObserver observer; | 1384 TestEffectiveConnectionTypeObserver observer; |
| 1409 std::map<std::string, std::string> variation_params; | 1385 std::map<std::string, std::string> variation_params; |
| 1410 TestNetworkQualityEstimator estimator(variation_params); | 1386 TestNetworkQualityEstimator estimator(variation_params); |
| 1411 estimator.AddEffectiveConnectionTypeObserver(&observer); | 1387 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 1412 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1388 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1413 | 1389 |
| 1414 TestDelegate test_delegate; | 1390 TestDelegate test_delegate; |
| 1415 // These tests expect the URLRequestContext to use the NQE, but not the | 1391 TestURLRequestContext context(true); |
| 1416 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 1417 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 1418 // by the HttpNetworkSession. | |
| 1419 // TODO(tbansal): Fix that. | |
| 1420 TestURLRequestContext context; | |
| 1421 context.set_network_quality_estimator(&estimator); | 1392 context.set_network_quality_estimator(&estimator); |
| 1393 context.Init(); |
| 1422 | 1394 |
| 1423 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 1395 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 1424 | 1396 |
| 1425 estimator.set_start_time_null_http_rtt( | 1397 estimator.set_start_time_null_http_rtt( |
| 1426 base::TimeDelta::FromMilliseconds(1500)); | 1398 base::TimeDelta::FromMilliseconds(1500)); |
| 1427 estimator.set_start_time_null_downlink_throughput_kbps(100000); | 1399 estimator.set_start_time_null_downlink_throughput_kbps(100000); |
| 1428 | 1400 |
| 1429 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1401 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1430 | 1402 |
| 1431 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1403 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 new base::SimpleTestTickClock()); | 1444 new base::SimpleTestTickClock()); |
| 1473 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); | 1445 base::SimpleTestTickClock* tick_clock_ptr = tick_clock.get(); |
| 1474 | 1446 |
| 1475 TestRTTAndThroughputEstimatesObserver observer; | 1447 TestRTTAndThroughputEstimatesObserver observer; |
| 1476 std::map<std::string, std::string> variation_params; | 1448 std::map<std::string, std::string> variation_params; |
| 1477 TestNetworkQualityEstimator estimator(variation_params); | 1449 TestNetworkQualityEstimator estimator(variation_params); |
| 1478 estimator.AddRTTAndThroughputEstimatesObserver(&observer); | 1450 estimator.AddRTTAndThroughputEstimatesObserver(&observer); |
| 1479 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1451 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1480 | 1452 |
| 1481 TestDelegate test_delegate; | 1453 TestDelegate test_delegate; |
| 1482 // These tests expect the URLRequestContext to use the NQE, but not the | 1454 TestURLRequestContext context(true); |
| 1483 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 1484 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 1485 // by the HttpNetworkSession. | |
| 1486 // TODO(tbansal): Fix that. | |
| 1487 TestURLRequestContext context; | |
| 1488 context.set_network_quality_estimator(&estimator); | 1455 context.set_network_quality_estimator(&estimator); |
| 1456 context.Init(); |
| 1489 | 1457 |
| 1490 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.http_rtt()); | 1458 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.http_rtt()); |
| 1491 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.transport_rtt()); | 1459 EXPECT_EQ(nqe::internal::InvalidRTT(), observer.transport_rtt()); |
| 1492 EXPECT_EQ(nqe::internal::kInvalidThroughput, | 1460 EXPECT_EQ(nqe::internal::kInvalidThroughput, |
| 1493 observer.downstream_throughput_kbps()); | 1461 observer.downstream_throughput_kbps()); |
| 1494 int notifications_received = observer.notifications_received(); | 1462 int notifications_received = observer.notifications_received(); |
| 1495 EXPECT_EQ(0, notifications_received); | 1463 EXPECT_EQ(0, notifications_received); |
| 1496 | 1464 |
| 1497 base::TimeDelta http_rtt(base::TimeDelta::FromMilliseconds(100)); | 1465 base::TimeDelta http_rtt(base::TimeDelta::FromMilliseconds(100)); |
| 1498 base::TimeDelta transport_rtt(base::TimeDelta::FromMilliseconds(200)); | 1466 base::TimeDelta transport_rtt(base::TimeDelta::FromMilliseconds(200)); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1597 | 1565 |
| 1598 TestEffectiveConnectionTypeObserver observer; | 1566 TestEffectiveConnectionTypeObserver observer; |
| 1599 std::map<std::string, std::string> variation_params; | 1567 std::map<std::string, std::string> variation_params; |
| 1600 TestNetworkQualityEstimator estimator(variation_params); | 1568 TestNetworkQualityEstimator estimator(variation_params); |
| 1601 estimator.SetTickClockForTesting(std::move(tick_clock)); | 1569 estimator.SetTickClockForTesting(std::move(tick_clock)); |
| 1602 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, | 1570 estimator.SimulateNetworkChange(NetworkChangeNotifier::CONNECTION_WIFI, |
| 1603 "test"); | 1571 "test"); |
| 1604 estimator.AddEffectiveConnectionTypeObserver(&observer); | 1572 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 1605 | 1573 |
| 1606 TestDelegate test_delegate; | 1574 TestDelegate test_delegate; |
| 1607 // These tests expect the URLRequestContext to use the NQE, but not the | 1575 TestURLRequestContext context(true); |
| 1608 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 1609 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 1610 // by the HttpNetworkSession. | |
| 1611 // TODO(tbansal): Fix that. | |
| 1612 TestURLRequestContext context; | |
| 1613 context.set_network_quality_estimator(&estimator); | 1576 context.set_network_quality_estimator(&estimator); |
| 1577 context.Init(); |
| 1614 | 1578 |
| 1615 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 1579 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 1616 | 1580 |
| 1617 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); | 1581 estimator.set_recent_effective_connection_type(EFFECTIVE_CONNECTION_TYPE_2G); |
| 1618 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); | 1582 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); |
| 1619 | 1583 |
| 1620 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1584 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1621 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1585 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1622 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1586 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1623 request->Start(); | 1587 request->Start(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 | 1647 |
| 1684 TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) { | 1648 TEST(NetworkQualityEstimatorTest, TestRttThroughputObservers) { |
| 1685 TestRTTObserver rtt_observer; | 1649 TestRTTObserver rtt_observer; |
| 1686 TestThroughputObserver throughput_observer; | 1650 TestThroughputObserver throughput_observer; |
| 1687 std::map<std::string, std::string> variation_params; | 1651 std::map<std::string, std::string> variation_params; |
| 1688 TestNetworkQualityEstimator estimator(variation_params); | 1652 TestNetworkQualityEstimator estimator(variation_params); |
| 1689 estimator.AddRTTObserver(&rtt_observer); | 1653 estimator.AddRTTObserver(&rtt_observer); |
| 1690 estimator.AddThroughputObserver(&throughput_observer); | 1654 estimator.AddThroughputObserver(&throughput_observer); |
| 1691 | 1655 |
| 1692 TestDelegate test_delegate; | 1656 TestDelegate test_delegate; |
| 1693 // These tests expect the URLRequestContext to use the NQE, but not the | 1657 TestURLRequestContext context(true); |
| 1694 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 1695 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 1696 // by the HttpNetworkSession. | |
| 1697 // TODO(tbansal): Fix that. | |
| 1698 TestURLRequestContext context; | |
| 1699 context.set_network_quality_estimator(&estimator); | 1658 context.set_network_quality_estimator(&estimator); |
| 1659 context.Init(); |
| 1700 | 1660 |
| 1701 EXPECT_EQ(0U, rtt_observer.observations().size()); | 1661 EXPECT_EQ(0U, rtt_observer.observations().size()); |
| 1702 EXPECT_EQ(0U, throughput_observer.observations().size()); | 1662 EXPECT_EQ(0U, throughput_observer.observations().size()); |
| 1703 base::TimeTicks then = base::TimeTicks::Now(); | 1663 base::TimeTicks then = base::TimeTicks::Now(); |
| 1704 | 1664 |
| 1705 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1665 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1706 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1666 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1707 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1667 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1708 request->Start(); | 1668 request->Start(); |
| 1709 base::RunLoop().Run(); | 1669 base::RunLoop().Run(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { | 1738 TEST(NetworkQualityEstimatorTest, MAYBE_TestTCPSocketRTT) { |
| 1779 base::HistogramTester histogram_tester; | 1739 base::HistogramTester histogram_tester; |
| 1780 TestRTTObserver rtt_observer; | 1740 TestRTTObserver rtt_observer; |
| 1781 std::map<std::string, std::string> variation_params; | 1741 std::map<std::string, std::string> variation_params; |
| 1782 TestNetworkQualityEstimator estimator(variation_params); | 1742 TestNetworkQualityEstimator estimator(variation_params); |
| 1783 estimator.AddRTTObserver(&rtt_observer); | 1743 estimator.AddRTTObserver(&rtt_observer); |
| 1784 | 1744 |
| 1785 TestDelegate test_delegate; | 1745 TestDelegate test_delegate; |
| 1786 TestURLRequestContext context(true); | 1746 TestURLRequestContext context(true); |
| 1787 context.set_network_quality_estimator(&estimator); | 1747 context.set_network_quality_estimator(&estimator); |
| 1748 |
| 1749 std::unique_ptr<HttpNetworkSession::Params> params( |
| 1750 new HttpNetworkSession::Params); |
| 1751 // |estimator| should be notified of TCP RTT observations. |
| 1752 params->socket_performance_watcher_factory = |
| 1753 estimator.GetSocketPerformanceWatcherFactory(); |
| 1754 context.set_http_network_session_params(std::move(params)); |
| 1788 context.Init(); | 1755 context.Init(); |
| 1789 | 1756 |
| 1790 EXPECT_EQ(0U, rtt_observer.observations().size()); | 1757 EXPECT_EQ(0U, rtt_observer.observations().size()); |
| 1791 base::TimeDelta rtt; | 1758 base::TimeDelta rtt; |
| 1792 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); | 1759 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); |
| 1793 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); | 1760 EXPECT_FALSE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); |
| 1794 | 1761 |
| 1795 // Send two requests. Verify that the completion of each request generates at | 1762 // Send two requests. Verify that the completion of each request generates at |
| 1796 // least one TCP RTT observation. | 1763 // least one TCP RTT observation. |
| 1797 const size_t num_requests = 2; | 1764 const size_t num_requests = 2; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 estimator.set_start_time_null_transport_rtt(test.rtt); | 1898 estimator.set_start_time_null_transport_rtt(test.rtt); |
| 1932 estimator.set_recent_transport_rtt(test.recent_rtt); | 1899 estimator.set_recent_transport_rtt(test.recent_rtt); |
| 1933 estimator.set_start_time_null_downlink_throughput_kbps( | 1900 estimator.set_start_time_null_downlink_throughput_kbps( |
| 1934 test.downstream_throughput_kbps); | 1901 test.downstream_throughput_kbps); |
| 1935 estimator.set_recent_downlink_throughput_kbps( | 1902 estimator.set_recent_downlink_throughput_kbps( |
| 1936 test.recent_downstream_throughput_kbps); | 1903 test.recent_downstream_throughput_kbps); |
| 1937 | 1904 |
| 1938 base::HistogramTester histogram_tester; | 1905 base::HistogramTester histogram_tester; |
| 1939 | 1906 |
| 1940 TestDelegate test_delegate; | 1907 TestDelegate test_delegate; |
| 1941 // These tests expect the URLRequestContext to use the NQE, but not the | 1908 TestURLRequestContext context(true); |
| 1942 // HttpNetworkSession. To do this, have to create the context, with its | |
| 1943 // own NQE, and then just set the one on the URLRequestContext, not the | |
| 1944 // one used by the HttpNetworkSession. | |
| 1945 // TODO(tbansal): Fix that. | |
| 1946 TestURLRequestContext context; | |
| 1947 context.set_network_quality_estimator(&estimator); | 1909 context.set_network_quality_estimator(&estimator); |
| 1910 context.Init(); |
| 1948 | 1911 |
| 1949 // Start a main-frame request which should cause network quality estimator | 1912 // Start a main-frame request which should cause network quality estimator |
| 1950 // to record accuracy UMA. | 1913 // to record accuracy UMA. |
| 1951 std::unique_ptr<URLRequest> request(context.CreateRequest( | 1914 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 1952 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 1915 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 1953 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 1916 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 1954 request->Start(); | 1917 request->Start(); |
| 1955 base::RunLoop().Run(); | 1918 base::RunLoop().Run(); |
| 1956 | 1919 |
| 1957 if (accuracy_recording_delay != base::TimeDelta()) { | 1920 if (accuracy_recording_delay != base::TimeDelta()) { |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2165 | 2128 |
| 2166 estimator.set_start_time_null_transport_rtt(test.transport_rtt); | 2129 estimator.set_start_time_null_transport_rtt(test.transport_rtt); |
| 2167 estimator.set_recent_transport_rtt(test.transport_rtt); | 2130 estimator.set_recent_transport_rtt(test.transport_rtt); |
| 2168 estimator.set_start_time_null_http_rtt(test.http_rtt); | 2131 estimator.set_start_time_null_http_rtt(test.http_rtt); |
| 2169 estimator.set_recent_http_rtt(test.http_rtt); | 2132 estimator.set_recent_http_rtt(test.http_rtt); |
| 2170 estimator.set_start_time_null_downlink_throughput_kbps( | 2133 estimator.set_start_time_null_downlink_throughput_kbps( |
| 2171 test.downstream_throughput_kbps); | 2134 test.downstream_throughput_kbps); |
| 2172 estimator.set_rand_double(test.rand_double); | 2135 estimator.set_rand_double(test.rand_double); |
| 2173 | 2136 |
| 2174 TestDelegate test_delegate; | 2137 TestDelegate test_delegate; |
| 2175 // These tests expect the URLRequestContext to use the NQE, but not the | 2138 TestURLRequestContext context(true); |
| 2176 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 2177 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 2178 // by the HttpNetworkSession. | |
| 2179 // TODO(tbansal): Fix that. | |
| 2180 TestURLRequestContext context; | |
| 2181 context.set_network_quality_estimator(&estimator); | 2139 context.set_network_quality_estimator(&estimator); |
| 2140 context.Init(); |
| 2182 | 2141 |
| 2183 // Start a main-frame request that should cause network quality estimator to | 2142 // Start a main-frame request that should cause network quality estimator to |
| 2184 // record the network quality at the last main frame request. | 2143 // record the network quality at the last main frame request. |
| 2185 std::unique_ptr<URLRequest> request_1(context.CreateRequest( | 2144 std::unique_ptr<URLRequest> request_1(context.CreateRequest( |
| 2186 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2145 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 2187 request_1->SetLoadFlags(request_1->load_flags() | | 2146 request_1->SetLoadFlags(request_1->load_flags() | |
| 2188 LOAD_MAIN_FRAME_DEPRECATED); | 2147 LOAD_MAIN_FRAME_DEPRECATED); |
| 2189 request_1->Start(); | 2148 request_1->Start(); |
| 2190 base::RunLoop().Run(); | 2149 base::RunLoop().Run(); |
| 2191 histogram_tester.ExpectTotalCount( | 2150 histogram_tester.ExpectTotalCount( |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2332 std::map<std::string, std::string> variation_params; | 2291 std::map<std::string, std::string> variation_params; |
| 2333 variation_params["force_effective_connection_type"] = | 2292 variation_params["force_effective_connection_type"] = |
| 2334 GetNameForEffectiveConnectionType( | 2293 GetNameForEffectiveConnectionType( |
| 2335 static_cast<EffectiveConnectionType>(i)); | 2294 static_cast<EffectiveConnectionType>(i)); |
| 2336 TestNetworkQualityEstimator estimator(variation_params); | 2295 TestNetworkQualityEstimator estimator(variation_params); |
| 2337 | 2296 |
| 2338 TestEffectiveConnectionTypeObserver observer; | 2297 TestEffectiveConnectionTypeObserver observer; |
| 2339 estimator.AddEffectiveConnectionTypeObserver(&observer); | 2298 estimator.AddEffectiveConnectionTypeObserver(&observer); |
| 2340 | 2299 |
| 2341 TestDelegate test_delegate; | 2300 TestDelegate test_delegate; |
| 2342 // These tests expect the URLRequestContext to use the NQE, but not the | 2301 TestURLRequestContext context(true); |
| 2343 // HttpNetworkSession. To do this, have to create the context, with its own | |
| 2344 // NQE, and then just set the one on the URLRequestContext, not the one used | |
| 2345 // by the HttpNetworkSession. | |
| 2346 // TODO(tbansal): Fix that. | |
| 2347 TestURLRequestContext context; | |
| 2348 context.set_network_quality_estimator(&estimator); | 2302 context.set_network_quality_estimator(&estimator); |
| 2303 context.Init(); |
| 2349 | 2304 |
| 2350 EXPECT_EQ(0U, observer.effective_connection_types().size()); | 2305 EXPECT_EQ(0U, observer.effective_connection_types().size()); |
| 2351 | 2306 |
| 2352 std::unique_ptr<URLRequest> request(context.CreateRequest( | 2307 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 2353 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2308 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 2354 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); | 2309 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); |
| 2355 request->Start(); | 2310 request->Start(); |
| 2356 base::RunLoop().Run(); | 2311 base::RunLoop().Run(); |
| 2357 | 2312 |
| 2358 EXPECT_EQ(i, estimator.GetEffectiveConnectionType()); | 2313 EXPECT_EQ(i, estimator.GetEffectiveConnectionType()); |
| 2359 | 2314 |
| 2360 size_t expected_count = static_cast<EffectiveConnectionType>(i) == | 2315 size_t expected_count = static_cast<EffectiveConnectionType>(i) == |
| 2361 EFFECTIVE_CONNECTION_TYPE_UNKNOWN | 2316 EFFECTIVE_CONNECTION_TYPE_UNKNOWN |
| 2362 ? 0 | 2317 ? 0 |
| 2363 : 1; | 2318 : 1; |
| 2364 ASSERT_EQ(expected_count, observer.effective_connection_types().size()); | 2319 ASSERT_EQ(expected_count, observer.effective_connection_types().size()); |
| 2365 if (expected_count == 1) { | 2320 if (expected_count == 1) { |
| 2366 EffectiveConnectionType last_notified_type = | 2321 EffectiveConnectionType last_notified_type = |
| 2367 observer.effective_connection_types().at( | 2322 observer.effective_connection_types().at( |
| 2368 observer.effective_connection_types().size() - 1); | 2323 observer.effective_connection_types().size() - 1); |
| 2369 EXPECT_EQ(i, last_notified_type); | 2324 EXPECT_EQ(i, last_notified_type); |
| 2370 } | 2325 } |
| 2371 } | 2326 } |
| 2372 } | 2327 } |
| 2373 | 2328 |
| 2374 } // namespace net | 2329 } // namespace net |
| OLD | NEW |