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

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

Issue 2593243003: Add network quality change events to net log (Closed)
Patch Set: ps Created 3 years, 11 months 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 11 matching lines...) Expand all
22 #include "base/test/histogram_tester.h" 22 #include "base/test/histogram_tester.h"
23 #include "base/test/simple_test_tick_clock.h" 23 #include "base/test/simple_test_tick_clock.h"
24 #include "base/threading/platform_thread.h" 24 #include "base/threading/platform_thread.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "build/build_config.h" 26 #include "build/build_config.h"
27 #include "net/base/load_flags.h" 27 #include "net/base/load_flags.h"
28 #include "net/base/network_change_notifier.h" 28 #include "net/base/network_change_notifier.h"
29 #include "net/http/http_response_headers.h" 29 #include "net/http/http_response_headers.h"
30 #include "net/http/http_response_info.h" 30 #include "net/http/http_response_info.h"
31 #include "net/http/http_status_code.h" 31 #include "net/http/http_status_code.h"
32 #include "net/log/test_net_log.h"
32 #include "net/nqe/effective_connection_type.h" 33 #include "net/nqe/effective_connection_type.h"
33 #include "net/nqe/external_estimate_provider.h" 34 #include "net/nqe/external_estimate_provider.h"
34 #include "net/nqe/network_quality_estimator_test_util.h" 35 #include "net/nqe/network_quality_estimator_test_util.h"
35 #include "net/nqe/network_quality_observation.h" 36 #include "net/nqe/network_quality_observation.h"
36 #include "net/nqe/network_quality_observation_source.h" 37 #include "net/nqe/network_quality_observation_source.h"
37 #include "net/nqe/observation_buffer.h" 38 #include "net/nqe/observation_buffer.h"
38 #include "net/socket/socket_performance_watcher.h" 39 #include "net/socket/socket_performance_watcher.h"
39 #include "net/socket/socket_performance_watcher_factory.h" 40 #include "net/socket/socket_performance_watcher_factory.h"
40 #include "net/url_request/url_request.h" 41 #include "net/url_request/url_request.h"
41 #include "net/url_request/url_request_test_util.h" 42 #include "net/url_request/url_request_test_util.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 2); 290 2);
290 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 1, 291 histogram_tester.ExpectBucketCount("NQE.EstimateAvailable.MainFrame.Kbps", 1,
291 1); 292 1);
292 293
293 estimator.SimulateNetworkChange( 294 estimator.SimulateNetworkChange(
294 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test"); 295 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, "test");
295 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false, 296 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", false,
296 3); 297 3);
297 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true, 298 histogram_tester.ExpectBucketCount("NQE.CachedNetworkQualityAvailable", true,
298 1); 299 1);
300
301 EXPECT_LT(
302 0, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED));
299 } 303 }
300 304
301 // Tests that the network quality estimator writes and reads network quality 305 // Tests that the network quality estimator writes and reads network quality
302 // from the cache store correctly. 306 // from the cache store correctly.
303 TEST(NetworkQualityEstimatorTest, Caching) { 307 TEST(NetworkQualityEstimatorTest, Caching) {
304 base::HistogramTester histogram_tester; 308 base::HistogramTester histogram_tester;
305 TestNetworkQualityEstimator estimator; 309 TestNetworkQualityEstimator estimator;
306 310
307 estimator.SimulateNetworkChange( 311 estimator.SimulateNetworkChange(
308 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); 312 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test");
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 // Verifies that the observers receive the notifications when default estimates 471 // Verifies that the observers receive the notifications when default estimates
468 // are added to the observations. 472 // are added to the observations.
469 TEST(NetworkQualityEstimatorTest, DefaultObservations) { 473 TEST(NetworkQualityEstimatorTest, DefaultObservations) {
470 TestEffectiveConnectionTypeObserver effective_connection_type_observer; 474 TestEffectiveConnectionTypeObserver effective_connection_type_observer;
471 TestRTTAndThroughputEstimatesObserver rtt_throughput_estimates_observer; 475 TestRTTAndThroughputEstimatesObserver rtt_throughput_estimates_observer;
472 TestRTTObserver rtt_observer; 476 TestRTTObserver rtt_observer;
473 TestThroughputObserver throughput_observer; 477 TestThroughputObserver throughput_observer;
474 std::map<std::string, std::string> variation_params; 478 std::map<std::string, std::string> variation_params;
475 TestNetworkQualityEstimator estimator( 479 TestNetworkQualityEstimator estimator(
476 nullptr, variation_params, false, false, 480 nullptr, variation_params, false, false,
477 true /* add_default_platform_observations */); 481 true /* add_default_platform_observations */,
482 base::MakeUnique<BoundTestNetLog>());
478 base::TimeDelta rtt; 483 base::TimeDelta rtt;
479 int32_t kbps; 484 int32_t kbps;
480 485
481 // Default estimates should be available. 486 // Default estimates should be available.
482 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); 487 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
483 EXPECT_EQ(base::TimeDelta::FromMilliseconds(115), rtt); 488 EXPECT_EQ(base::TimeDelta::FromMilliseconds(115), rtt);
484 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); 489 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
485 EXPECT_EQ(base::TimeDelta::FromMilliseconds(55), rtt); 490 EXPECT_EQ(base::TimeDelta::FromMilliseconds(55), rtt);
486 EXPECT_TRUE( 491 EXPECT_TRUE(
487 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); 492 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
(...skipping 19 matching lines...) Expand all
507 EXPECT_EQ(749, kbps); 512 EXPECT_EQ(749, kbps);
508 513
509 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 514 EXPECT_NE(EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
510 estimator.GetEffectiveConnectionType()); 515 estimator.GetEffectiveConnectionType());
511 EXPECT_EQ( 516 EXPECT_EQ(
512 1U, 517 1U,
513 effective_connection_type_observer.effective_connection_types().size()); 518 effective_connection_type_observer.effective_connection_types().size());
514 EXPECT_NE( 519 EXPECT_NE(
515 EFFECTIVE_CONNECTION_TYPE_UNKNOWN, 520 EFFECTIVE_CONNECTION_TYPE_UNKNOWN,
516 effective_connection_type_observer.effective_connection_types().front()); 521 effective_connection_type_observer.effective_connection_types().front());
522 EXPECT_LT(
523 0, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED));
517 524
518 EXPECT_EQ(3, rtt_throughput_estimates_observer.notifications_received()); 525 EXPECT_EQ(3, rtt_throughput_estimates_observer.notifications_received());
519 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272), 526 EXPECT_EQ(base::TimeDelta::FromMilliseconds(272),
520 rtt_throughput_estimates_observer.http_rtt()); 527 rtt_throughput_estimates_observer.http_rtt());
521 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209), 528 EXPECT_EQ(base::TimeDelta::FromMilliseconds(209),
522 rtt_throughput_estimates_observer.transport_rtt()); 529 rtt_throughput_estimates_observer.transport_rtt());
523 EXPECT_EQ(749, 530 EXPECT_EQ(749,
524 rtt_throughput_estimates_observer.downstream_throughput_kbps()); 531 rtt_throughput_estimates_observer.downstream_throughput_kbps());
525 532
526 EXPECT_EQ(2U, rtt_observer.observations().size()); 533 EXPECT_EQ(2U, rtt_observer.observations().size());
(...skipping 24 matching lines...) Expand all
551 // Negative variation value should not be used. 558 // Negative variation value should not be used.
552 variation_params["2G.DefaultMedianRTTMsec"] = "-5"; 559 variation_params["2G.DefaultMedianRTTMsec"] = "-5";
553 560
554 variation_params["Unknown.DefaultMedianTransportRTTMsec"] = "500"; 561 variation_params["Unknown.DefaultMedianTransportRTTMsec"] = "500";
555 variation_params["WiFi.DefaultMedianTransportRTTMsec"] = "1000"; 562 variation_params["WiFi.DefaultMedianTransportRTTMsec"] = "1000";
556 // Negative variation value should not be used. 563 // Negative variation value should not be used.
557 variation_params["2G.DefaultMedianTransportRTTMsec"] = "-5"; 564 variation_params["2G.DefaultMedianTransportRTTMsec"] = "-5";
558 565
559 TestNetworkQualityEstimator estimator( 566 TestNetworkQualityEstimator estimator(
560 nullptr, variation_params, false, false, 567 nullptr, variation_params, false, false,
561 true /* add_default_platform_observations */); 568 true /* add_default_platform_observations */,
569 base::MakeUnique<BoundTestNetLog>());
RyanSturm 2017/01/10 16:22:38 include ptr_util.h
tbansal1 2017/01/10 18:27:53 Done.
562 570
563 base::TimeDelta rtt; 571 base::TimeDelta rtt;
564 int32_t kbps; 572 int32_t kbps;
565 573
566 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); 574 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
567 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt); 575 EXPECT_EQ(base::TimeDelta::FromMilliseconds(1000), rtt);
568 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt)); 576 EXPECT_TRUE(estimator.GetRecentTransportRTT(base::TimeTicks(), &rtt));
569 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), rtt); 577 EXPECT_EQ(base::TimeDelta::FromMilliseconds(500), rtt);
570 EXPECT_TRUE( 578 EXPECT_TRUE(
571 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); 579 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 }, 1452 },
1445 { 1453 {
1446 true, 1454 true,
1447 }, 1455 },
1448 }; 1456 };
1449 1457
1450 for (const auto& test : tests) { 1458 for (const auto& test : tests) {
1451 TestNetworkQualityEstimator estimator( 1459 TestNetworkQualityEstimator estimator(
1452 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, 1460 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params,
1453 test.allow_small_localhost_requests, 1461 test.allow_small_localhost_requests,
1454 test.allow_small_localhost_requests, false); 1462 test.allow_small_localhost_requests, false,
1463 base::MakeUnique<BoundTestNetLog>());
1455 1464
1456 base::TimeDelta rtt; 1465 base::TimeDelta rtt;
1457 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt)); 1466 EXPECT_FALSE(estimator.GetRecentHttpRTT(base::TimeTicks(), &rtt));
1458 int32_t kbps; 1467 int32_t kbps;
1459 EXPECT_FALSE( 1468 EXPECT_FALSE(
1460 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); 1469 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
1461 1470
1462 TestDelegate test_delegate; 1471 TestDelegate test_delegate;
1463 TestURLRequestContext context(true); 1472 TestURLRequestContext context(true);
1464 context.set_network_quality_estimator(&estimator); 1473 context.set_network_quality_estimator(&estimator);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 estimator.set_start_time_null_downlink_throughput_kbps(100000); 1521 estimator.set_start_time_null_downlink_throughput_kbps(100000);
1513 1522
1514 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); 1523 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
1515 1524
1516 std::unique_ptr<URLRequest> request(context.CreateRequest( 1525 std::unique_ptr<URLRequest> request(context.CreateRequest(
1517 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 1526 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1518 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); 1527 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED);
1519 request->Start(); 1528 request->Start();
1520 base::RunLoop().Run(); 1529 base::RunLoop().Run();
1521 EXPECT_EQ(1U, observer.effective_connection_types().size()); 1530 EXPECT_EQ(1U, observer.effective_connection_types().size());
1531 EXPECT_LT(
1532 0, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED));
1522 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType", 1533 histogram_tester.ExpectUniqueSample("NQE.MainFrame.EffectiveConnectionType",
1523 EFFECTIVE_CONNECTION_TYPE_2G, 1); 1534 EFFECTIVE_CONNECTION_TYPE_2G, 1);
1524 histogram_tester.ExpectUniqueSample( 1535 histogram_tester.ExpectUniqueSample(
1525 "NQE.MainFrame.EffectiveConnectionType.Unknown", 1536 "NQE.MainFrame.EffectiveConnectionType.Unknown",
1526 EFFECTIVE_CONNECTION_TYPE_2G, 1); 1537 EFFECTIVE_CONNECTION_TYPE_2G, 1);
1527 1538
1528 // Next request should not trigger recomputation of effective connection type 1539 // Next request should not trigger recomputation of effective connection type
1529 // since there has been no change in the clock. 1540 // since there has been no change in the clock.
1530 std::unique_ptr<URLRequest> request2(context.CreateRequest( 1541 std::unique_ptr<URLRequest> request2(context.CreateRequest(
1531 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 1542 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 "test_ect_4g")] = 2613 "test_ect_4g")] =
2603 nqe::internal::CachedNetworkQuality(EFFECTIVE_CONNECTION_TYPE_4G); 2614 nqe::internal::CachedNetworkQuality(EFFECTIVE_CONNECTION_TYPE_4G);
2604 2615
2605 std::map<std::string, std::string> variation_params; 2616 std::map<std::string, std::string> variation_params;
2606 variation_params["effective_connection_type_algorithm"] = 2617 variation_params["effective_connection_type_algorithm"] =
2607 "TransportRTTOrDownstreamThroughput"; 2618 "TransportRTTOrDownstreamThroughput";
2608 // Disable default platform values so that the effect of cached estimates 2619 // Disable default platform values so that the effect of cached estimates
2609 // at the time of startup can be studied in isolation. 2620 // at the time of startup can be studied in isolation.
2610 TestNetworkQualityEstimator estimator( 2621 TestNetworkQualityEstimator estimator(
2611 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, true, 2622 std::unique_ptr<net::ExternalEstimateProvider>(), variation_params, true,
2612 true, false /* use_default_platform_values */); 2623 true, false /* use_default_platform_values */,
2624 base::MakeUnique<BoundTestNetLog>());
2613 2625
2614 // Add observers. 2626 // Add observers.
2615 TestRTTObserver rtt_observer; 2627 TestRTTObserver rtt_observer;
2616 TestThroughputObserver throughput_observer; 2628 TestThroughputObserver throughput_observer;
2617 TestRTTAndThroughputEstimatesObserver rtt_throughput_observer; 2629 TestRTTAndThroughputEstimatesObserver rtt_throughput_observer;
2618 TestEffectiveConnectionTypeObserver effective_connection_type_observer; 2630 TestEffectiveConnectionTypeObserver effective_connection_type_observer;
2619 estimator.AddRTTObserver(&rtt_observer); 2631 estimator.AddRTTObserver(&rtt_observer);
2620 estimator.AddThroughputObserver(&throughput_observer); 2632 estimator.AddThroughputObserver(&throughput_observer);
2621 estimator.AddRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); 2633 estimator.AddRTTAndThroughputEstimatesObserver(&rtt_throughput_observer);
2622 estimator.AddEffectiveConnectionTypeObserver( 2634 estimator.AddEffectiveConnectionTypeObserver(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 2701
2690 // Cleanup. 2702 // Cleanup.
2691 estimator.RemoveRTTObserver(&rtt_observer); 2703 estimator.RemoveRTTObserver(&rtt_observer);
2692 estimator.RemoveThroughputObserver(&throughput_observer); 2704 estimator.RemoveThroughputObserver(&throughput_observer);
2693 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); 2705 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer);
2694 estimator.RemoveEffectiveConnectionTypeObserver( 2706 estimator.RemoveEffectiveConnectionTypeObserver(
2695 &effective_connection_type_observer); 2707 &effective_connection_type_observer);
2696 } 2708 }
2697 2709
2698 } // namespace net 2710 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698