| 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> |
| 11 #include <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/metrics/histogram_samples.h" | 19 #include "base/metrics/histogram_samples.h" |
| 20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 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" |
| 30 #include "net/http/http_response_info.h" |
| 29 #include "net/http/http_status_code.h" | 31 #include "net/http/http_status_code.h" |
| 30 #include "net/nqe/effective_connection_type.h" | 32 #include "net/nqe/effective_connection_type.h" |
| 31 #include "net/nqe/external_estimate_provider.h" | 33 #include "net/nqe/external_estimate_provider.h" |
| 32 #include "net/nqe/network_quality_estimator_test_util.h" | 34 #include "net/nqe/network_quality_estimator_test_util.h" |
| 33 #include "net/nqe/network_quality_observation.h" | 35 #include "net/nqe/network_quality_observation.h" |
| 34 #include "net/nqe/network_quality_observation_source.h" | 36 #include "net/nqe/network_quality_observation_source.h" |
| 35 #include "net/nqe/observation_buffer.h" | 37 #include "net/nqe/observation_buffer.h" |
| 36 #include "net/socket/socket_performance_watcher.h" | 38 #include "net/socket/socket_performance_watcher.h" |
| 37 #include "net/socket/socket_performance_watcher_factory.h" | 39 #include "net/socket/socket_performance_watcher_factory.h" |
| 38 #include "net/url_request/url_request.h" | 40 #include "net/url_request/url_request.h" |
| (...skipping 2139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2178 | 2180 |
| 2179 // Get the bits at index 11-17 which contain the downstream throughput. | 2181 // Get the bits at index 11-17 which contain the downstream throughput. |
| 2180 EXPECT_EQ(test.expected_downstream_throughput_kbps, | 2182 EXPECT_EQ(test.expected_downstream_throughput_kbps, |
| 2181 (buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric) % 128); | 2183 (buckets.at(0).min >> kBitsPerMetric >> kBitsPerMetric) % 128); |
| 2182 | 2184 |
| 2183 // Get the bits at index 18-24 which contain the resource fetch time. | 2185 // Get the bits at index 18-24 which contain the resource fetch time. |
| 2184 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); | 2186 EXPECT_LE(0, (buckets.at(0).min >> kBitsPerMetric) % 128); |
| 2185 | 2187 |
| 2186 // Get the bits at index 25-31 which contain the resource load size. | 2188 // Get the bits at index 25-31 which contain the resource load size. |
| 2187 EXPECT_LE(0, (buckets.at(0).min) % 128); | 2189 EXPECT_LE(0, (buckets.at(0).min) % 128); |
| 2190 |
| 2191 // Start another main-frame request which is redirected to an HTTPS URL. |
| 2192 // Redirection should not cause any crashes. |
| 2193 std::unique_ptr<URLRequest> request_3(context.CreateRequest( |
| 2194 estimator.GetRedirectURL(), DEFAULT_PRIORITY, &test_delegate)); |
| 2195 request_3->Start(); |
| 2196 base::RunLoop().Run(); |
| 2197 EXPECT_FALSE(request_3->original_url().SchemeIsCryptographic()); |
| 2198 EXPECT_TRUE(request_3->url().SchemeIsCryptographic()); |
| 2199 EXPECT_TRUE(!request_3->response_info().headers.get() || |
| 2200 request_3->response_info().headers->response_code() != HTTP_OK); |
| 2201 // Correlation metric should not be logged for redirected requests. |
| 2202 histogram_tester.ExpectTotalCount( |
| 2203 "NQE.Correlation.ResourceLoadTime.0Kb_128Kb", 1); |
| 2188 } | 2204 } |
| 2189 } | 2205 } |
| 2190 | 2206 |
| 2191 class TestNetworkQualitiesCacheObserver | 2207 class TestNetworkQualitiesCacheObserver |
| 2192 : public nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver { | 2208 : public nqe::internal::NetworkQualityStore::NetworkQualitiesCacheObserver { |
| 2193 public: | 2209 public: |
| 2194 TestNetworkQualitiesCacheObserver() | 2210 TestNetworkQualitiesCacheObserver() |
| 2195 : network_id_(net::NetworkChangeNotifier::CONNECTION_UNKNOWN, | 2211 : network_id_(net::NetworkChangeNotifier::CONNECTION_UNKNOWN, |
| 2196 std::string()), | 2212 std::string()), |
| 2197 notification_received_(0) {} | 2213 notification_received_(0) {} |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2304 if (expected_count == 1) { | 2320 if (expected_count == 1) { |
| 2305 EffectiveConnectionType last_notified_type = | 2321 EffectiveConnectionType last_notified_type = |
| 2306 observer.effective_connection_types().at( | 2322 observer.effective_connection_types().at( |
| 2307 observer.effective_connection_types().size() - 1); | 2323 observer.effective_connection_types().size() - 1); |
| 2308 EXPECT_EQ(i, last_notified_type); | 2324 EXPECT_EQ(i, last_notified_type); |
| 2309 } | 2325 } |
| 2310 } | 2326 } |
| 2311 } | 2327 } |
| 2312 | 2328 |
| 2313 } // namespace net | 2329 } // namespace net |
| OLD | NEW |