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

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

Powered by Google App Engine
This is Rietveld 408576698