| 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 2223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2234 3000 >> kTrimBits, | 2234 3000 >> kTrimBits, |
| 2235 }, | 2235 }, |
| 2236 { | 2236 { |
| 2237 // Verify that the metric is recorded if the logging probability is | 2237 // Verify that the metric is recorded if the logging probability is |
| 2238 // higher than the value returned by the random number generator. | 2238 // higher than the value returned by the random number generator. |
| 2239 false, 0.3, 0.4, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, | 2239 false, 0.3, 0.4, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| 2240 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, | 2240 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, |
| 2241 3000 >> kTrimBits, | 2241 3000 >> kTrimBits, |
| 2242 }, | 2242 }, |
| 2243 { | 2243 { |
| 2244 // Verify that the metric is not recorded if the HTTP RTT is |
| 2245 // unavailable. |
| 2246 false, 0.3, 0.4, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| 2247 nqe::internal::InvalidRTT(), 2000 >> kTrimBits, 3000, |
| 2248 3000 >> kTrimBits, |
| 2249 }, |
| 2250 { |
| 2251 // Verify that the metric is not recorded if the transport RTT is |
| 2252 // unavailable. |
| 2253 true, 0.3, 0.4, nqe::internal::InvalidRTT(), 1000 >> kTrimBits, |
| 2254 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, |
| 2255 3000 >> kTrimBits, |
| 2256 }, |
| 2257 { |
| 2258 // Verify that the metric is not recorded if the throughput is |
| 2259 // unavailable. |
| 2260 false, 0.3, 0.4, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| 2261 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, |
| 2262 nqe::internal::kInvalidThroughput, 3000 >> kTrimBits, |
| 2263 }, |
| 2264 { |
| 2244 // Verify that the metric is recorded if the logging probability is | 2265 // Verify that the metric is recorded if the logging probability is |
| 2245 // set to 1.0. | 2266 // set to 1.0. |
| 2246 false, 0.5, 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, | 2267 false, 0.5, 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| 2247 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, | 2268 base::TimeDelta::FromSeconds(2), 2000 >> kTrimBits, 3000, |
| 2248 3000 >> kTrimBits, | 2269 3000 >> kTrimBits, |
| 2249 }, | 2270 }, |
| 2250 { | 2271 { |
| 2251 // Verify that the metric is recorded if the logging probability is | 2272 // Verify that the metric is recorded if the logging probability is |
| 2252 // set to 1.0. | 2273 // set to 1.0. |
| 2253 true, 0.5, 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, | 2274 true, 0.5, 1.0, base::TimeDelta::FromSeconds(1), 1000 >> kTrimBits, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2305 std::unique_ptr<URLRequest> request_2(context.CreateRequest( | 2326 std::unique_ptr<URLRequest> request_2(context.CreateRequest( |
| 2306 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); | 2327 estimator.GetEchoURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 2307 request_2->Start(); | 2328 request_2->Start(); |
| 2308 base::RunLoop().Run(); | 2329 base::RunLoop().Run(); |
| 2309 | 2330 |
| 2310 if (test.rand_double >= test.correlation_logging_probability) { | 2331 if (test.rand_double >= test.correlation_logging_probability) { |
| 2311 histogram_tester.ExpectTotalCount( | 2332 histogram_tester.ExpectTotalCount( |
| 2312 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); | 2333 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2313 continue; | 2334 continue; |
| 2314 } | 2335 } |
| 2336 if (!test.use_transport_rtt && |
| 2337 test.http_rtt == nqe::internal::InvalidRTT()) { |
| 2338 histogram_tester.ExpectTotalCount( |
| 2339 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2340 continue; |
| 2341 } |
| 2342 if (test.use_transport_rtt && |
| 2343 test.transport_rtt == nqe::internal::InvalidRTT()) { |
| 2344 histogram_tester.ExpectTotalCount( |
| 2345 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2346 continue; |
| 2347 } |
| 2348 if (test.downstream_throughput_kbps == nqe::internal::kInvalidThroughput) { |
| 2349 histogram_tester.ExpectTotalCount( |
| 2350 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 0); |
| 2351 continue; |
| 2352 } |
| 2353 |
| 2315 histogram_tester.ExpectTotalCount( | 2354 histogram_tester.ExpectTotalCount( |
| 2316 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 1); | 2355 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 1); |
| 2317 std::vector<base::Bucket> buckets = histogram_tester.GetAllSamples( | 2356 std::vector<base::Bucket> buckets = histogram_tester.GetAllSamples( |
| 2318 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb"); | 2357 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb"); |
| 2319 // Get the bits at index 0-10 which contain the RTT. | 2358 // Get the bits at index 0-10 which contain the RTT. |
| 2320 // 128 is 2^kBitsPerMetric. | 2359 // 128 is 2^kBitsPerMetric. |
| 2321 if (test.use_transport_rtt) { | 2360 if (test.use_transport_rtt) { |
| 2322 EXPECT_EQ(test.expected_transport_rtt_milliseconds, | 2361 EXPECT_EQ(test.expected_transport_rtt_milliseconds, |
| 2323 buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric >> | 2362 buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric >> |
| 2324 kBitsPerMetric); | 2363 kBitsPerMetric); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2687 | 2726 |
| 2688 // Cleanup. | 2727 // Cleanup. |
| 2689 estimator.RemoveRTTObserver(&rtt_observer); | 2728 estimator.RemoveRTTObserver(&rtt_observer); |
| 2690 estimator.RemoveThroughputObserver(&throughput_observer); | 2729 estimator.RemoveThroughputObserver(&throughput_observer); |
| 2691 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); | 2730 estimator.RemoveRTTAndThroughputEstimatesObserver(&rtt_throughput_observer); |
| 2692 estimator.RemoveEffectiveConnectionTypeObserver( | 2731 estimator.RemoveEffectiveConnectionTypeObserver( |
| 2693 &effective_connection_type_observer); | 2732 &effective_connection_type_observer); |
| 2694 } | 2733 } |
| 2695 | 2734 |
| 2696 } // namespace net | 2735 } // namespace net |
| OLD | NEW |