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

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

Issue 2899453002: Pass parsed network quality estimator params when constructing NQE (Closed)
Patch Set: Rebased Created 3 years, 6 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
« no previous file with comments | « net/nqe/throughput_analyzer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/throughput_analyzer.h" 5 #include "net/nqe/throughput_analyzer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <deque> 9 #include <deque>
10 #include <map> 10 #include <map>
(...skipping 16 matching lines...) Expand all
27 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
28 28
29 namespace net { 29 namespace net {
30 30
31 namespace nqe { 31 namespace nqe {
32 32
33 namespace { 33 namespace {
34 34
35 class TestThroughputAnalyzer : public internal::ThroughputAnalyzer { 35 class TestThroughputAnalyzer : public internal::ThroughputAnalyzer {
36 public: 36 public:
37 explicit TestThroughputAnalyzer( 37 explicit TestThroughputAnalyzer(NetworkQualityEstimatorParams* params)
38 internal::NetworkQualityEstimatorParams* params)
39 : internal::ThroughputAnalyzer( 38 : internal::ThroughputAnalyzer(
40 params, 39 params,
41 base::ThreadTaskRunnerHandle::Get(), 40 base::ThreadTaskRunnerHandle::Get(),
42 base::Bind( 41 base::Bind(
43 &TestThroughputAnalyzer::OnNewThroughputObservationAvailable, 42 &TestThroughputAnalyzer::OnNewThroughputObservationAvailable,
44 base::Unretained(this)), 43 base::Unretained(this)),
45 false, 44 false,
46 false), 45 false),
47 throughput_observations_received_(0), 46 throughput_observations_received_(0),
48 bits_received_(0) {} 47 bits_received_(0) {}
(...skipping 29 matching lines...) Expand all
78 bool use_local_requests; 77 bool use_local_requests;
79 } tests[] = {{ 78 } tests[] = {{
80 false, 79 false,
81 }, 80 },
82 { 81 {
83 true, 82 true,
84 }}; 83 }};
85 84
86 for (const auto& test : tests) { 85 for (const auto& test : tests) {
87 std::map<std::string, std::string> variation_params; 86 std::map<std::string, std::string> variation_params;
88 internal::NetworkQualityEstimatorParams params(variation_params); 87 NetworkQualityEstimatorParams params(variation_params);
89 TestThroughputAnalyzer throughput_analyzer(&params); 88 TestThroughputAnalyzer throughput_analyzer(&params);
90 89
91 TestDelegate test_delegate; 90 TestDelegate test_delegate;
92 TestURLRequestContext context; 91 TestURLRequestContext context;
93 92
94 ASSERT_FALSE(throughput_analyzer.disable_throughput_measurements()); 93 ASSERT_FALSE(throughput_analyzer.disable_throughput_measurements());
95 std::deque<std::unique_ptr<URLRequest>> requests; 94 std::deque<std::unique_ptr<URLRequest>> requests;
96 95
97 // Start more requests than the maximum number of requests that can be held 96 // Start more requests than the maximum number of requests that can be held
98 // in the memory. 97 // in the memory.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 true, false, false, 129 true, false, false,
131 }, 130 },
132 { 131 {
133 true, true, true, 132 true, true, true,
134 }, 133 },
135 }; 134 };
136 135
137 for (const auto& test : tests) { 136 for (const auto& test : tests) {
138 // Localhost requests are not allowed for estimation purposes. 137 // Localhost requests are not allowed for estimation purposes.
139 std::map<std::string, std::string> variation_params; 138 std::map<std::string, std::string> variation_params;
140 internal::NetworkQualityEstimatorParams params(variation_params); 139 NetworkQualityEstimatorParams params(variation_params);
141 TestThroughputAnalyzer throughput_analyzer(&params); 140 TestThroughputAnalyzer throughput_analyzer(&params);
142 141
143 TestDelegate test_delegate; 142 TestDelegate test_delegate;
144 TestURLRequestContext context; 143 TestURLRequestContext context;
145 144
146 std::unique_ptr<URLRequest> request_local; 145 std::unique_ptr<URLRequest> request_local;
147 146
148 std::unique_ptr<URLRequest> request_not_local(context.CreateRequest( 147 std::unique_ptr<URLRequest> request_not_local(context.CreateRequest(
149 GURL("http://example.com/echo.html"), DEFAULT_PRIORITY, &test_delegate, 148 GURL("http://example.com/echo.html"), DEFAULT_PRIORITY, &test_delegate,
150 TRAFFIC_ANNOTATION_FOR_TESTS)); 149 TRAFFIC_ANNOTATION_FOR_TESTS));
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 { 218 {
220 1, 2, 1, false, 219 1, 2, 1, false,
221 }, 220 },
222 }; 221 };
223 222
224 for (const auto& test : tests) { 223 for (const auto& test : tests) {
225 // Localhost requests are not allowed for estimation purposes. 224 // Localhost requests are not allowed for estimation purposes.
226 std::map<std::string, std::string> variation_params; 225 std::map<std::string, std::string> variation_params;
227 variation_params["throughput_min_requests_in_flight"] = 226 variation_params["throughput_min_requests_in_flight"] =
228 base::IntToString(test.throughput_min_requests_in_flight); 227 base::IntToString(test.throughput_min_requests_in_flight);
229 internal::NetworkQualityEstimatorParams params(variation_params); 228 NetworkQualityEstimatorParams params(variation_params);
230 TestThroughputAnalyzer throughput_analyzer(&params); 229 TestThroughputAnalyzer throughput_analyzer(&params);
231 TestDelegate test_delegate; 230 TestDelegate test_delegate;
232 TestURLRequestContext context; 231 TestURLRequestContext context;
233 232
234 EXPECT_EQ(0, throughput_analyzer.throughput_observations_received()); 233 EXPECT_EQ(0, throughput_analyzer.throughput_observations_received());
235 234
236 std::vector<std::unique_ptr<URLRequest>> requests_in_flight; 235 std::vector<std::unique_ptr<URLRequest>> requests_in_flight;
237 236
238 for (size_t i = 0; i < test.number_requests_in_flight; ++i) { 237 for (size_t i = 0; i < test.number_requests_in_flight; ++i) {
239 std::unique_ptr<URLRequest> request_network_1 = context.CreateRequest( 238 std::unique_ptr<URLRequest> request_network_1 = context.CreateRequest(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 270 }
272 } 271 }
273 } 272 }
274 273
275 // Tests if the throughput observation is taken correctly when the start and end 274 // Tests if the throughput observation is taken correctly when the start and end
276 // of network requests overlap, and the minimum number of in flight requests 275 // of network requests overlap, and the minimum number of in flight requests
277 // when taking an observation is more than 1. 276 // when taking an observation is more than 1.
278 TEST(ThroughputAnalyzerTest, TestThroughputWithMultipleNetworkRequests) { 277 TEST(ThroughputAnalyzerTest, TestThroughputWithMultipleNetworkRequests) {
279 std::map<std::string, std::string> variation_params; 278 std::map<std::string, std::string> variation_params;
280 variation_params["throughput_min_requests_in_flight"] = "3"; 279 variation_params["throughput_min_requests_in_flight"] = "3";
281 internal::NetworkQualityEstimatorParams params(variation_params); 280 NetworkQualityEstimatorParams params(variation_params);
282 TestThroughputAnalyzer throughput_analyzer(&params); 281 TestThroughputAnalyzer throughput_analyzer(&params);
283 TestDelegate test_delegate; 282 TestDelegate test_delegate;
284 TestURLRequestContext context; 283 TestURLRequestContext context;
285 284
286 EXPECT_EQ(0, throughput_analyzer.throughput_observations_received()); 285 EXPECT_EQ(0, throughput_analyzer.throughput_observations_received());
287 286
288 std::unique_ptr<URLRequest> request_1 = context.CreateRequest( 287 std::unique_ptr<URLRequest> request_1 = context.CreateRequest(
289 GURL("http://example.com/echo.html"), DEFAULT_PRIORITY, &test_delegate, 288 GURL("http://example.com/echo.html"), DEFAULT_PRIORITY, &test_delegate,
290 TRAFFIC_ANNOTATION_FOR_TESTS); 289 TRAFFIC_ANNOTATION_FOR_TESTS);
291 std::unique_ptr<URLRequest> request_2 = context.CreateRequest( 290 std::unique_ptr<URLRequest> request_2 = context.CreateRequest(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 throughput_analyzer.NotifyRequestCompleted(*(request_3.get())); 336 throughput_analyzer.NotifyRequestCompleted(*(request_3.get()));
338 throughput_analyzer.NotifyRequestCompleted(*(request_4.get())); 337 throughput_analyzer.NotifyRequestCompleted(*(request_4.get()));
339 EXPECT_EQ(1, throughput_analyzer.throughput_observations_received()); 338 EXPECT_EQ(1, throughput_analyzer.throughput_observations_received());
340 } 339 }
341 340
342 } // namespace 341 } // namespace
343 342
344 } // namespace nqe 343 } // namespace nqe
345 344
346 } // namespace net 345 } // namespace net
OLDNEW
« no previous file with comments | « net/nqe/throughput_analyzer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698