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

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

Issue 2593243003: Add network quality change events to net log (Closed)
Patch Set: rebased 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_test_util.h" 5 #include "net/nqe/network_quality_estimator_test_util.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 9 #include "base/run_loop.h"
9 #include "net/base/load_flags.h" 10 #include "net/base/load_flags.h"
11 #include "net/log/net_log_with_source.h"
12 #include "net/log/test_net_log.h"
13 #include "net/log/test_net_log_entry.h"
10 #include "net/test/embedded_test_server/http_response.h" 14 #include "net/test/embedded_test_server/http_response.h"
11 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request.h"
12 #include "net/url_request/url_request_test_util.h" 16 #include "net/url_request/url_request_test_util.h"
13 17
14 namespace { 18 namespace {
15 19
16 const base::FilePath::CharType kTestFilePath[] = 20 const base::FilePath::CharType kTestFilePath[] =
17 FILE_PATH_LITERAL("net/data/url_request_unittest"); 21 FILE_PATH_LITERAL("net/data/url_request_unittest");
18 22
19 } // namespace 23 } // namespace
20 24
21 namespace net { 25 namespace net {
22 26
23 TestNetworkQualityEstimator::TestNetworkQualityEstimator() 27 TestNetworkQualityEstimator::TestNetworkQualityEstimator()
24 : TestNetworkQualityEstimator(std::map<std::string, std::string>()) {} 28 : TestNetworkQualityEstimator(std::map<std::string, std::string>()) {}
25 29
26 TestNetworkQualityEstimator::TestNetworkQualityEstimator( 30 TestNetworkQualityEstimator::TestNetworkQualityEstimator(
27 const std::map<std::string, std::string>& variation_params) 31 const std::map<std::string, std::string>& variation_params)
28 : TestNetworkQualityEstimator(variation_params, 32 : TestNetworkQualityEstimator(variation_params,
29 std::unique_ptr<ExternalEstimateProvider>()) { 33 std::unique_ptr<ExternalEstimateProvider>()) {
30 } 34 }
31 35
32 TestNetworkQualityEstimator::TestNetworkQualityEstimator( 36 TestNetworkQualityEstimator::TestNetworkQualityEstimator(
33 const std::map<std::string, std::string>& variation_params, 37 const std::map<std::string, std::string>& variation_params,
34 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider) 38 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider)
35 : TestNetworkQualityEstimator(std::move(external_estimate_provider), 39 : TestNetworkQualityEstimator(std::move(external_estimate_provider),
36 variation_params, 40 variation_params,
37 true, 41 true,
38 true, 42 true,
39 false) {} 43 false,
44 base::MakeUnique<BoundTestNetLog>()) {}
40 45
41 TestNetworkQualityEstimator::TestNetworkQualityEstimator( 46 TestNetworkQualityEstimator::TestNetworkQualityEstimator(
42 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider, 47 std::unique_ptr<net::ExternalEstimateProvider> external_estimate_provider,
43 const std::map<std::string, std::string>& variation_params, 48 const std::map<std::string, std::string>& variation_params,
44 bool allow_local_host_requests_for_tests, 49 bool allow_local_host_requests_for_tests,
45 bool allow_smaller_responses_for_tests, 50 bool allow_smaller_responses_for_tests,
46 bool add_default_platform_observations) 51 bool add_default_platform_observations,
52 std::unique_ptr<BoundTestNetLog> net_log)
47 : NetworkQualityEstimator(std::move(external_estimate_provider), 53 : NetworkQualityEstimator(std::move(external_estimate_provider),
48 variation_params, 54 variation_params,
49 allow_local_host_requests_for_tests, 55 allow_local_host_requests_for_tests,
50 allow_smaller_responses_for_tests, 56 allow_smaller_responses_for_tests,
51 add_default_platform_observations), 57 add_default_platform_observations,
58 net_log->bound()),
52 current_network_type_(NetworkChangeNotifier::CONNECTION_UNKNOWN), 59 current_network_type_(NetworkChangeNotifier::CONNECTION_UNKNOWN),
53 accuracy_recording_intervals_set_(false), 60 accuracy_recording_intervals_set_(false),
54 rand_double_(0.0), 61 rand_double_(0.0),
55 embedded_test_server_(base::FilePath(kTestFilePath)) { 62 embedded_test_server_(base::FilePath(kTestFilePath)),
63 net_log_(std::move(net_log)) {
56 // Set up the embedded test server. 64 // Set up the embedded test server.
57 EXPECT_TRUE(embedded_test_server_.Start()); 65 EXPECT_TRUE(embedded_test_server_.Start());
58 } 66 }
59 67
60 TestNetworkQualityEstimator::~TestNetworkQualityEstimator() {} 68 TestNetworkQualityEstimator::~TestNetworkQualityEstimator() {}
61 69
62 void TestNetworkQualityEstimator::RunOneRequest() { 70 void TestNetworkQualityEstimator::RunOneRequest() {
63 TestDelegate test_delegate; 71 TestDelegate test_delegate;
64 TestURLRequestContext context(true); 72 TestURLRequestContext context(true);
65 context.set_network_quality_estimator(this); 73 context.set_network_quality_estimator(this);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 if (accuracy_recording_intervals_set_) 193 if (accuracy_recording_intervals_set_)
186 return accuracy_recording_intervals_; 194 return accuracy_recording_intervals_;
187 195
188 return NetworkQualityEstimator::GetAccuracyRecordingIntervals(); 196 return NetworkQualityEstimator::GetAccuracyRecordingIntervals();
189 } 197 }
190 198
191 double TestNetworkQualityEstimator::RandDouble() const { 199 double TestNetworkQualityEstimator::RandDouble() const {
192 return rand_double_; 200 return rand_double_;
193 } 201 }
194 202
203 int TestNetworkQualityEstimator::GetEntriesCount(NetLogEventType type) const {
204 TestNetLogEntry::List entries;
205 net_log_->GetEntries(&entries);
206
207 int count = 0;
208 for (const auto& entry : entries) {
209 if (entry.type == type)
210 ++count;
211 }
212 return count;
213 }
214
195 nqe::internal::NetworkID TestNetworkQualityEstimator::GetCurrentNetworkID() 215 nqe::internal::NetworkID TestNetworkQualityEstimator::GetCurrentNetworkID()
196 const { 216 const {
197 return nqe::internal::NetworkID(current_network_type_, current_network_id_); 217 return nqe::internal::NetworkID(current_network_type_, current_network_id_);
198 } 218 }
199 219
200 TestNetworkQualityEstimator::LocalHttpTestServer::LocalHttpTestServer( 220 TestNetworkQualityEstimator::LocalHttpTestServer::LocalHttpTestServer(
201 const base::FilePath& document_root) { 221 const base::FilePath& document_root) {
202 AddDefaultHandlers(document_root); 222 AddDefaultHandlers(document_root);
203 } 223 }
204 224
205 } // namespace net 225 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/network_quality_estimator_test_util.h ('k') | net/nqe/network_quality_estimator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698