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

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

Issue 2724403004: NQE: Add net log event if the metric changes substantially (Closed)
Patch Set: ryansturm comments Created 3 years, 9 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
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 // Both RTT and downstream throughput should be updated. 219 // Both RTT and downstream throughput should be updated.
220 base::TimeDelta http_rtt; 220 base::TimeDelta http_rtt;
221 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &http_rtt)); 221 EXPECT_TRUE(estimator.GetRecentHttpRTT(base::TimeTicks(), &http_rtt));
222 EXPECT_TRUE( 222 EXPECT_TRUE(
223 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps)); 223 estimator.GetRecentDownlinkThroughputKbps(base::TimeTicks(), &kbps));
224 base::TimeDelta transport_rtt; 224 base::TimeDelta transport_rtt;
225 EXPECT_FALSE( 225 EXPECT_FALSE(
226 estimator.GetRecentTransportRTT(base::TimeTicks(), &transport_rtt)); 226 estimator.GetRecentTransportRTT(base::TimeTicks(), &transport_rtt));
227 227
228 // Verify the contents of the net log. 228 // Verify the contents of the net log.
229 EXPECT_EQ( 229 EXPECT_LE(
230 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); 230 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED));
231 EXPECT_EQ(http_rtt.InMilliseconds(), 231 EXPECT_EQ(http_rtt.InMilliseconds(),
232 estimator.GetNetLogLastIntegerValue( 232 estimator.GetNetLogLastIntegerValue(
233 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms")); 233 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms"));
234 EXPECT_EQ(-1, 234 EXPECT_EQ(-1,
235 estimator.GetNetLogLastIntegerValue( 235 estimator.GetNetLogLastIntegerValue(
236 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms")); 236 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms"));
237 EXPECT_EQ(kbps, estimator.GetNetLogLastIntegerValue( 237 EXPECT_EQ(kbps, estimator.GetNetLogLastIntegerValue(
238 NetLogEventType::NETWORK_QUALITY_CHANGED, 238 NetLogEventType::NETWORK_QUALITY_CHANGED,
239 "downstream_throughput_kbps")); 239 "downstream_throughput_kbps"));
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 TestEffectiveConnectionTypeObserver observer; 404 TestEffectiveConnectionTypeObserver observer;
405 estimator.AddEffectiveConnectionTypeObserver(&observer); 405 estimator.AddEffectiveConnectionTypeObserver(&observer);
406 TestRTTObserver rtt_observer; 406 TestRTTObserver rtt_observer;
407 estimator.AddRTTObserver(&rtt_observer); 407 estimator.AddRTTObserver(&rtt_observer);
408 TestThroughputObserver throughput_observer; 408 TestThroughputObserver throughput_observer;
409 estimator.AddThroughputObserver(&throughput_observer); 409 estimator.AddThroughputObserver(&throughput_observer);
410 410
411 // |observer| should be notified as soon as it is added. 411 // |observer| should be notified as soon as it is added.
412 base::RunLoop().RunUntilIdle(); 412 base::RunLoop().RunUntilIdle();
413 EXPECT_EQ(1U, observer.effective_connection_types().size()); 413 EXPECT_EQ(1U, observer.effective_connection_types().size());
414 EXPECT_EQ( 414
415 2, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); 415 int num_net_log_entries =
416 estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED);
417 EXPECT_LE(2, num_net_log_entries);
416 418
417 estimator.SimulateNetworkChange( 419 estimator.SimulateNetworkChange(
418 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test"); 420 NetworkChangeNotifier::ConnectionType::CONNECTION_2G, "test");
419 histogram_tester.ExpectBucketCount( 421 histogram_tester.ExpectBucketCount(
420 "NQE.RTT.ObservationSource", 422 "NQE.RTT.ObservationSource",
421 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE, 1); 423 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE, 1);
422 histogram_tester.ExpectBucketCount( 424 histogram_tester.ExpectBucketCount(
423 "NQE.Kbps.ObservationSource", 425 "NQE.Kbps.ObservationSource",
424 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE, 1); 426 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE, 1);
425 427
426 // Verify the contents of the net log. 428 // Verify the contents of the net log.
427 EXPECT_LE( 429 EXPECT_LE(
428 3, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); 430 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED) -
431 num_net_log_entries);
429 EXPECT_NE(-1, estimator.GetNetLogLastIntegerValue( 432 EXPECT_NE(-1, estimator.GetNetLogLastIntegerValue(
430 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms")); 433 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms"));
431 EXPECT_EQ(-1, 434 EXPECT_EQ(-1,
432 estimator.GetNetLogLastIntegerValue( 435 estimator.GetNetLogLastIntegerValue(
433 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms")); 436 NetLogEventType::NETWORK_QUALITY_CHANGED, "transport_rtt_ms"));
434 EXPECT_NE(-1, estimator.GetNetLogLastIntegerValue( 437 EXPECT_NE(-1, estimator.GetNetLogLastIntegerValue(
435 NetLogEventType::NETWORK_QUALITY_CHANGED, 438 NetLogEventType::NETWORK_QUALITY_CHANGED,
436 "downstream_throughput_kbps")); 439 "downstream_throughput_kbps"));
437 EXPECT_EQ( 440 EXPECT_EQ(
438 GetNameForEffectiveConnectionType(estimator.GetEffectiveConnectionType()), 441 GetNameForEffectiveConnectionType(estimator.GetEffectiveConnectionType()),
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1734 estimator.set_start_time_null_downlink_throughput_kbps(100000); 1737 estimator.set_start_time_null_downlink_throughput_kbps(100000);
1735 1738
1736 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60)); 1739 tick_clock_ptr->Advance(base::TimeDelta::FromMinutes(60));
1737 1740
1738 std::unique_ptr<URLRequest> request(context.CreateRequest( 1741 std::unique_ptr<URLRequest> request(context.CreateRequest(
1739 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); 1742 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate));
1740 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED); 1743 request->SetLoadFlags(request->load_flags() | LOAD_MAIN_FRAME_DEPRECATED);
1741 request->Start(); 1744 request->Start();
1742 base::RunLoop().Run(); 1745 base::RunLoop().Run();
1743 EXPECT_EQ(1U, observer.effective_connection_types().size()); 1746 EXPECT_EQ(1U, observer.effective_connection_types().size());
1744 EXPECT_EQ( 1747 EXPECT_LE(
1745 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED)); 1748 1, estimator.GetEntriesCount(NetLogEventType::NETWORK_QUALITY_CHANGED));
1746 1749
1747 // Verify the contents of the net log. 1750 // Verify the contents of the net log.
1748 EXPECT_EQ(GetNameForEffectiveConnectionType(EFFECTIVE_CONNECTION_TYPE_2G), 1751 EXPECT_EQ(GetNameForEffectiveConnectionType(EFFECTIVE_CONNECTION_TYPE_2G),
1749 estimator.GetNetLogLastStringValue( 1752 estimator.GetNetLogLastStringValue(
1750 NetLogEventType::NETWORK_QUALITY_CHANGED, 1753 NetLogEventType::NETWORK_QUALITY_CHANGED,
1751 "effective_connection_type")); 1754 "effective_connection_type"));
1752 EXPECT_EQ(1500, estimator.GetNetLogLastIntegerValue( 1755 EXPECT_EQ(1500, estimator.GetNetLogLastIntegerValue(
1753 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms")); 1756 NetLogEventType::NETWORK_QUALITY_CHANGED, "http_rtt_ms"));
1754 EXPECT_EQ(-1, 1757 EXPECT_EQ(-1,
(...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after
3114 3117
3115 // Cleanup. 3118 // Cleanup.
3116 estimator.RemoveRTTObserver(&rtt_observer); 3119 estimator.RemoveRTTObserver(&rtt_observer);
3117 estimator.RemoveThroughputObserver(&throughput_observer); 3120 estimator.RemoveThroughputObserver(&throughput_observer);
3118 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); 3121 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer);
3119 estimator.RemoveEffectiveConnectionTypeObserver( 3122 estimator.RemoveEffectiveConnectionTypeObserver(
3120 &effective_connection_type_observer); 3123 &effective_connection_type_observer);
3121 } 3124 }
3122 3125
3123 } // namespace net 3126 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698