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

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

Issue 2484323002: Add a NetworkQualityEstimator to TestURLRequestContext. (Closed)
Patch Set: Fix tests Created 4 years, 1 month 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/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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
173 // higher layers to do so, so create the context, with its own NQE, and then
174 // just set the one on the URLRequestContext, not the one used by the
175 // HttpNetworkSession.
176 // TODO(mmenke): Fix that?
tbansal1 2016/11/14 20:39:27 can you reassign these to me. As mentioned elsewhe
mmenke 2016/11/14 20:43:02 Do you want to do it, or would you rather me do it
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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
315 // higher layers to do so, so create the context, with its own NQE, and then
316 // just set the one on the URLRequestContext, not the one used by the
317 // HttpNetworkSession.
318 // TODO(mmenke): 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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
380 // higher layers to do so, so create the context, with its own NQE, and then
381 // just set the one on the URLRequestContext, not the one used by the
382 // HttpNetworkSession.
383 // TODO(mmenke): 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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
429 // higher layers to do so, so create the context, with its own NQE, and then
430 // just set the one on the URLRequestContext, not the one used by the
431 // HttpNetworkSession.
432 // TODO(mmenke): 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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
1328 // higher layers to do so, so create the context, with its own NQE, and then
1329 // just set the one on the URLRequestContext, not the one used by the
1330 // HttpNetworkSession.
1331 // TODO(mmenke): 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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
1379 // higher layers to do so, so create the context, with its own NQE, and then
1380 // just set the one on the URLRequestContext, not the one used by the
1381 // HttpNetworkSession.
1382 // TODO(mmenke): 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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
1416 // higher layers to do so, so create the context, with its own NQE, and then
1417 // just set the one on the URLRequestContext, not the one used by the
1418 // HttpNetworkSession.
1419 // TODO(mmenke): 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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
1483 // higher layers to do so, so create the context, with its own NQE, and then
1484 // just set the one on the URLRequestContext, not the one used by the
1485 // HttpNetworkSession.
1486 // TODO(mmenke): 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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
1608 // higher layers to do so, so create the context, with its own NQE, and then
1609 // just set the one on the URLRequestContext, not the one used by the
1610 // HttpNetworkSession.
1611 // TODO(mmenke): 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
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 // Theses tests expect the HttpNetworkSession not to use this NQE, but the
1694 // higher layers to do so, so create the context, with its own NQE, and then
1695 // just set the one on the URLRequestContext, not the one used by the
1696 // HttpNetworkSession.
1697 // TODO(mmenke): 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 650 matching lines...) Expand 10 before | Expand all | Expand 10 after
2320 if (expected_count == 1) { 2360 if (expected_count == 1) {
2321 EffectiveConnectionType last_notified_type = 2361 EffectiveConnectionType last_notified_type =
2322 observer.effective_connection_types().at( 2362 observer.effective_connection_types().at(
2323 observer.effective_connection_types().size() - 1); 2363 observer.effective_connection_types().size() - 1);
2324 EXPECT_EQ(i, last_notified_type); 2364 EXPECT_EQ(i, last_notified_type);
2325 } 2365 }
2326 } 2366 }
2327 } 2367 }
2328 2368
2329 } // namespace net 2369 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698