| 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 2307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2318 3000 >> kTrimBits, | 2318 3000 >> kTrimBits, |
| 2319 }, | 2319 }, |
| 2320 { | 2320 { |
| 2321 // Verify that the metric is recorded if the logging probability is | 2321 // Verify that the metric is recorded if the logging probability is |
| 2322 // higher than the value returned by the random number generator. | 2322 // higher than the value returned by the random number generator. |
| 2323 false, 0.3, 0.4, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, | 2323 false, 0.3, 0.4, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| 2324 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, | 2324 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, |
| 2325 3000 >> kTrimBits, | 2325 3000 >> kTrimBits, |
| 2326 }, | 2326 }, |
| 2327 { | 2327 { |
| 2328 // Verify that the metric is not recorded if the HTTP RTT is |
| 2329 // unavailable. |
| 2330 false, 0.3, 0.4, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| 2331 nqe::internal::InvalidRTT(), 2000 >> kTrimBits, 3000, |
| 2332 3000 >> kTrimBits, |
| 2333 }, |
| 2334 { |
| 2335 // Verify that the metric is not recorded if the transport RTT is |
| 2336 // unavailable. |
| 2337 true, 0.3, 0.4, nqe::internal::InvalidRTT(), 1000 >> kTrimBits, |
| 2338 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, |
| 2339 3000 >> kTrimBits, |
| 2340 }, |
| 2341 { |
| 2342 // Verify that the metric is not recorded if the throughput is |
| 2343 // unavailable. |
| 2344 false, 0.3, 0.4, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| 2345 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, |
| 2346 nqe::internal::kInvalidThroughput, 3000 >> kTrimBits, |
| 2347 }, |
| 2348 { |
| 2328 // Verify that the metric is recorded if the logging probability is | 2349 // Verify that the metric is recorded if the logging probability is |
| 2329 // set to 1.0. | 2350 // set to 1.0. |
| 2330 false, 0.5, 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, | 2351 false, 0.5, 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| 2331 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, | 2352 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, |
| 2332 3000 >> kTrimBits, | 2353 3000 >> kTrimBits, |
| 2333 }, | 2354 }, |
| 2334 { | 2355 { |
| 2335 // Verify that the metric is recorded if the logging probability is | 2356 // Verify that the metric is recorded if the logging probability is |
| 2336 // set to 1.0. | 2357 // set to 1.0. |
| 2337 true, 0.5, 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, | 2358 true, 0.5, 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2389 std::unique_ptr<URLRequest> request_2(context.CreateRequest( | 2410 std::unique_ptr<URLRequest> request_2(context.CreateRequest( |
| 2390 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2411 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 2391 request_2->Start(); | 2412 request_2->Start(); |
| 2392 base::RunLoop().Run(); | 2413 base::RunLoop().Run(); |
| 2393 | 2414 |
| 2394 if (test.rand_double >= test.correlation_logging_probability) { | 2415 if (test.rand_double >= test.correlation_logging_probability) { |
| 2395 histogram_tester.ExpectTotalCount( | 2416 histogram_tester.ExpectTotalCount( |
| 2396 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); | 2417 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2397 continue; | 2418 continue; |
| 2398 } | 2419 } |
| 2420 if (!test.use_transport_rtt && |
| 2421 test.http_rtt == nqe::internal::InvalidRTT()) { |
| 2422 histogram_tester.ExpectTotalCount( |
| 2423 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2424 continue; |
| 2425 } |
| 2426 if (test.use_transport_rtt && |
| 2427 test.transport_rtt == nqe::internal::InvalidRTT()) { |
| 2428 histogram_tester.ExpectTotalCount( |
| 2429 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2430 continue; |
| 2431 } |
| 2432 if (test.downstream_throughput_kbps == nqe::internal::kInvalidThroughput) { |
| 2433 histogram_tester.ExpectTotalCount( |
| 2434 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2435 continue; |
| 2436 } |
| 2437 |
| 2399 histogram_tester.ExpectTotalCount( | 2438 histogram_tester.ExpectTotalCount( |
| 2400 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 1); | 2439 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 1); |
| 2401 std::vector<base::Bucket> buckets = histogram_tester.GetAllSamples( | 2440 std::vector<base::Bucket> buckets = histogram_tester.GetAllSamples( |
| 2402 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb"); | 2441 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb"); |
| 2403 // Get the bits at index 0-10 which contain the RTT. | 2442 // Get the bits at index 0-10 which contain the RTT. |
| 2404 // 128 is 2^kBitsPerMetric. | 2443 // 128 is 2^kBitsPerMetric. |
| 2405 if (test.use_transport_rtt) { | 2444 if (test.use_transport_rtt) { |
| 2406 EXPECT_EQ(test.expected_transport_rtt_milliseconds, | 2445 EXPECT_EQ(test.expected_transport_rtt_milliseconds, |
| 2407 buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric >> | 2446 buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric >> |
| 2408 kBitsPerMetric); | 2447 kBitsPerMetric); |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2772 | 2811 |
| 2773 // Cleanup. | 2812 // Cleanup. |
| 2774 estimator.RemoveRTTObserver(&rtt_observer); | 2813 estimator.RemoveRTTObserver(&rtt_observer); |
| 2775 estimator.RemoveThroughputObserver(&throughput_observer); | 2814 estimator.RemoveThroughputObserver(&throughput_observer); |
| 2776 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); | 2815 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
| 2777 estimator.RemoveEffectiveConnectionTypeObserver( | 2816 estimator.RemoveEffectiveConnectionTypeObserver( |
| 2778 &effective_connection_type_observer); | 2817 &effective_connection_type_observer); |
| 2779 } | 2818 } |
| 2780 | 2819 |
| 2781 } // namespace net | 2820 } // namespace net |
| OLD | NEW |