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