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

Side by Side Diff: content/browser/net_info_browsertest.cc

Issue 2929703003: NetInfo: Slight update to the default network quality value (Closed)
Patch Set: 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 | « no previous file | content/test/data/net_info.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <cmath> // For std::modf.
5 #include <map> 6 #include <map>
6 #include <string> 7 #include <string>
7 8
8 #include "base/command_line.h" 9 #include "base/command_line.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
11 #include "base/test/histogram_tester.h" 12 #include "base/test/histogram_tester.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "content/browser/net/network_quality_observer_impl.h" 14 #include "content/browser/net/network_quality_observer_impl.h"
14 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 } 86 }
86 87
87 bool RunScriptExtractBool(const std::string& script) { 88 bool RunScriptExtractBool(const std::string& script) {
88 bool data; 89 bool data;
89 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), script, &data)); 90 EXPECT_TRUE(ExecuteScriptAndExtractBool(shell(), script, &data));
90 return data; 91 return data;
91 } 92 }
92 93
93 double RunScriptExtractDouble(const std::string& script) { 94 double RunScriptExtractDouble(const std::string& script) {
94 double data = 0.0; 95 double data = 0.0;
95 EXPECT_TRUE(base::StringToDouble(RunScriptExtractString(script), &data)); 96 EXPECT_TRUE(ExecuteScriptAndExtractDouble(shell(), script, &data));
97 return data;
98 }
99
100 int RunScriptExtractInt(const std::string& script) {
101 int data = 0;
102 EXPECT_TRUE(ExecuteScriptAndExtractInt(shell(), script, &data));
96 return data; 103 return data;
97 } 104 }
98 }; 105 };
99 106
100 // Make sure the type is correct when the page is first opened. 107 // Make sure the type is correct when the page is first opened.
101 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, VerifyNetworkStateInitialized) { 108 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, VerifyNetworkStateInitialized) {
102 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET, 109 SetConnectionType(net::NetworkChangeNotifier::CONNECTION_ETHERNET,
103 net::NetworkChangeNotifier::SUBTYPE_GIGABIT_ETHERNET); 110 net::NetworkChangeNotifier::SUBTYPE_GIGABIT_ETHERNET);
104 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html")); 111 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
105 EXPECT_TRUE(RunScriptExtractBool("getOnLine()")); 112 EXPECT_TRUE(RunScriptExtractBool("getOnLine()"));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 164
158 // Open the same page in a new window on the same process. 165 // Open the same page in a new window on the same process.
159 EXPECT_TRUE(ExecuteScript(shell(), "window.open(\"net_info.html\")")); 166 EXPECT_TRUE(ExecuteScript(shell(), "window.open(\"net_info.html\")"));
160 167
161 // The network state should not have reinitialized to what it was when opening 168 // The network state should not have reinitialized to what it was when opening
162 // the first window (online). 169 // the first window (online).
163 EXPECT_FALSE(RunScriptExtractBool("getOnLine()")); 170 EXPECT_FALSE(RunScriptExtractBool("getOnLine()"));
164 } 171 }
165 172
166 // Verify that when the network quality notifications are not sent, the 173 // Verify that when the network quality notifications are not sent, the
167 // Javascript API returns invalid estimate. 174 // Javascript API returns a valid estimate that is multiple of 25 msec and 25
175 // kbps.
168 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, 176 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
169 NetworkQualityEstimatorNotInitialized) { 177 NetworkQualityEstimatorNotInitialized) {
170 base::HistogramTester histogram_tester; 178 base::HistogramTester histogram_tester;
171 net::TestNetworkQualityEstimator estimator( 179 net::TestNetworkQualityEstimator estimator(
172 nullptr, std::map<std::string, std::string>(), false, false, true, true, 180 nullptr, std::map<std::string, std::string>(), false, false, true, true,
173 base::MakeUnique<net::BoundTestNetLog>()); 181 base::MakeUnique<net::BoundTestNetLog>());
174 NetworkQualityObserverImpl impl(&estimator); 182 NetworkQualityObserverImpl impl(&estimator);
175 183
176 EXPECT_TRUE(embedded_test_server()->Start()); 184 EXPECT_TRUE(embedded_test_server()->Start());
177 EXPECT_TRUE( 185 EXPECT_TRUE(
178 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); 186 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
179 187
180 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()")); 188 EXPECT_EQ(0, RunScriptExtractInt("getRtt()"));
181 EXPECT_EQ(std::numeric_limits<double>::infinity(), 189 EXPECT_EQ(0, RunScriptExtractInt("getRtt()") % 25);
182 RunScriptExtractDouble("getDownlink()")); 190
191 double downlink_mbps = RunScriptExtractDouble("getDownlink()");
192 EXPECT_LE(0, downlink_mbps);
193
194 // Verify that |downlink_mbps| is a multiple of 25 kbps. For example, a value
195 // of 1.250 mbps satisfies that constraint, but a value of 1.254 mbps does
196 // not.
197 double fraction_part, int_part;
198 fraction_part = std::modf(downlink_mbps, &int_part);
199 // If |fraction_part| is a multiple of 0.025, it implies |downlink_mbps| is
200 // also a multiple of 0.025, and hence |downlink_mbps| is a multiple of 25
201 // kbps.
202 EXPECT_EQ(0, static_cast<int>(fraction_part * 1000) % 25);
203
183 EXPECT_EQ("4g", RunScriptExtractString("getEffectiveType()")); 204 EXPECT_EQ("4g", RunScriptExtractString("getEffectiveType()"));
184 } 205 }
185 206
186 // Make sure the changes in the effective connection typeare notified to the 207 // Make sure the changes in the effective connection typeare notified to the
187 // render thread. 208 // render thread.
188 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, 209 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
189 EffectiveConnectionTypeChangeNotfied) { 210 EffectiveConnectionTypeChangeNotfied) {
190 base::HistogramTester histogram_tester; 211 base::HistogramTester histogram_tester;
191 net::TestNetworkQualityEstimator estimator( 212 net::TestNetworkQualityEstimator estimator(
192 nullptr, std::map<std::string, std::string>(), false, false, true, true, 213 nullptr, std::map<std::string, std::string>(), false, false, true, true,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 263
243 EXPECT_TRUE(embedded_test_server()->Start()); 264 EXPECT_TRUE(embedded_test_server()->Start());
244 EXPECT_TRUE( 265 EXPECT_TRUE(
245 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); 266 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
246 267
247 FetchHistogramsFromChildProcesses(); 268 FetchHistogramsFromChildProcesses();
248 EXPECT_FALSE( 269 EXPECT_FALSE(
249 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty()); 270 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty());
250 271
251 EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(), 272 EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(),
252 RunScriptExtractDouble("getRtt()")); 273 RunScriptExtractInt("getRtt()"));
253 EXPECT_EQ( 274 EXPECT_EQ(
254 static_cast<double>(network_quality_1.downstream_throughput_kbps()) / 275 static_cast<double>(network_quality_1.downstream_throughput_kbps()) /
255 1000, 276 1000,
256 RunScriptExtractDouble("getDownlink()")); 277 RunScriptExtractDouble("getDownlink()"));
257 278
258 // Verify that the network quality change is accessible via Javascript API. 279 // Verify that the network quality change is accessible via Javascript API.
259 net::nqe::internal::NetworkQuality network_quality_2( 280 net::nqe::internal::NetworkQuality network_quality_2(
260 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000); 281 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000);
261 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 282 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
262 network_quality_2); 283 network_quality_2);
263 base::RunLoop().RunUntilIdle(); 284 base::RunLoop().RunUntilIdle();
264 EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(), 285 EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(),
265 RunScriptExtractDouble("getRtt()")); 286 RunScriptExtractInt("getRtt()"));
266 EXPECT_EQ( 287 EXPECT_EQ(
267 static_cast<double>(network_quality_2.downstream_throughput_kbps()) / 288 static_cast<double>(network_quality_2.downstream_throughput_kbps()) /
268 1000, 289 1000,
269 RunScriptExtractDouble("getDownlink()")); 290 RunScriptExtractDouble("getDownlink()"));
270 } 291 }
271 292
272 // Make sure the changes in the network quality are rounded to the nearest 293 // Make sure the changes in the network quality are rounded to the nearest
273 // 25 milliseconds or 25 kbps. 294 // 25 milliseconds or 25 kbps.
274 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) { 295 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
275 base::HistogramTester histogram_tester; 296 base::HistogramTester histogram_tester;
276 net::TestNetworkQualityEstimator estimator( 297 net::TestNetworkQualityEstimator estimator(
277 std::unique_ptr<net::ExternalEstimateProvider>(), 298 std::unique_ptr<net::ExternalEstimateProvider>(),
278 std::map<std::string, std::string>(), false, false, true, true, 299 std::map<std::string, std::string>(), false, false, true, true,
279 base::MakeUnique<net::BoundTestNetLog>()); 300 base::MakeUnique<net::BoundTestNetLog>());
280 NetworkQualityObserverImpl impl(&estimator); 301 NetworkQualityObserverImpl impl(&estimator);
281 302
282 // Verify that the network quality is rounded properly. 303 // Verify that the network quality is rounded properly.
283 net::nqe::internal::NetworkQuality network_quality_1( 304 net::nqe::internal::NetworkQuality network_quality_1(
284 base::TimeDelta::FromMilliseconds(123), 305 base::TimeDelta::FromMilliseconds(123),
285 base::TimeDelta::FromMilliseconds(212), 303); 306 base::TimeDelta::FromMilliseconds(212), 303);
286 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 307 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
287 network_quality_1); 308 network_quality_1);
288 309
289 EXPECT_TRUE(embedded_test_server()->Start()); 310 EXPECT_TRUE(embedded_test_server()->Start());
290 EXPECT_TRUE( 311 EXPECT_TRUE(
291 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); 312 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
292 EXPECT_EQ(200, RunScriptExtractDouble("getRtt()")); 313 EXPECT_EQ(200, RunScriptExtractInt("getRtt()"));
293 EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()")); 314 EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()"));
294 315
295 net::nqe::internal::NetworkQuality network_quality_2( 316 net::nqe::internal::NetworkQuality network_quality_2(
296 base::TimeDelta::FromMilliseconds(123), 317 base::TimeDelta::FromMilliseconds(123),
297 base::TimeDelta::FromMilliseconds(1217), 1317); 318 base::TimeDelta::FromMilliseconds(1217), 1317);
298 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 319 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
299 network_quality_2); 320 network_quality_2);
300 base::RunLoop().RunUntilIdle(); 321 base::RunLoop().RunUntilIdle();
301 EXPECT_EQ(1225, RunScriptExtractDouble("getRtt()")); 322 EXPECT_EQ(1225, RunScriptExtractInt("getRtt()"));
302 EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()")); 323 EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()"));
303 324
304 net::nqe::internal::NetworkQuality network_quality_3( 325 net::nqe::internal::NetworkQuality network_quality_3(
305 base::TimeDelta::FromMilliseconds(12), 326 base::TimeDelta::FromMilliseconds(12),
306 base::TimeDelta::FromMilliseconds(12), 12); 327 base::TimeDelta::FromMilliseconds(12), 12);
307 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 328 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
308 network_quality_3); 329 network_quality_3);
309 base::RunLoop().RunUntilIdle(); 330 base::RunLoop().RunUntilIdle();
310 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()")); 331 EXPECT_EQ(0, RunScriptExtractInt("getRtt()"));
311 EXPECT_EQ(0, RunScriptExtractDouble("getDownlink()")); 332 EXPECT_EQ(0, RunScriptExtractDouble("getDownlink()"));
312 } 333 }
313 334
314 // Make sure the minor changes (<10%) in the network quality are not notified. 335 // Make sure the minor changes (<10%) in the network quality are not notified.
315 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) { 336 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
316 base::HistogramTester histogram_tester; 337 base::HistogramTester histogram_tester;
317 net::TestNetworkQualityEstimator estimator( 338 net::TestNetworkQualityEstimator estimator(
318 nullptr, std::map<std::string, std::string>(), false, false, true, true, 339 nullptr, std::map<std::string, std::string>(), false, false, true, true,
319 base::MakeUnique<net::BoundTestNetLog>()); 340 base::MakeUnique<net::BoundTestNetLog>());
320 NetworkQualityObserverImpl impl(&estimator); 341 NetworkQualityObserverImpl impl(&estimator);
321 342
322 // Verify that the network quality is rounded properly. 343 // Verify that the network quality is rounded properly.
323 net::nqe::internal::NetworkQuality network_quality_1( 344 net::nqe::internal::NetworkQuality network_quality_1(
324 base::TimeDelta::FromMilliseconds(1123), 345 base::TimeDelta::FromMilliseconds(1123),
325 base::TimeDelta::FromMilliseconds(1212), 1303); 346 base::TimeDelta::FromMilliseconds(1212), 1303);
326 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 347 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
327 network_quality_1); 348 network_quality_1);
328 349
329 EXPECT_TRUE(embedded_test_server()->Start()); 350 EXPECT_TRUE(embedded_test_server()->Start());
330 EXPECT_TRUE( 351 EXPECT_TRUE(
331 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); 352 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
332 EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()")); 353 EXPECT_EQ(1200, RunScriptExtractInt("getRtt()"));
333 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()")); 354 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
334 355
335 // All the 3 metrics change by less than 10%. So, the observers are not 356 // All the 3 metrics change by less than 10%. So, the observers are not
336 // notified. 357 // notified.
337 net::nqe::internal::NetworkQuality network_quality_2( 358 net::nqe::internal::NetworkQuality network_quality_2(
338 base::TimeDelta::FromMilliseconds(1223), 359 base::TimeDelta::FromMilliseconds(1223),
339 base::TimeDelta::FromMilliseconds(1312), 1403); 360 base::TimeDelta::FromMilliseconds(1312), 1403);
340 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 361 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
341 network_quality_2); 362 network_quality_2);
342 base::RunLoop().RunUntilIdle(); 363 base::RunLoop().RunUntilIdle();
343 EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()")); 364 EXPECT_EQ(1200, RunScriptExtractInt("getRtt()"));
344 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()")); 365 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
345 366
346 // Transport RTT has changed by more than 10% from the last notified value of 367 // Transport RTT has changed by more than 10% from the last notified value of
347 // |network_quality_1|. The observers should be notified. 368 // |network_quality_1|. The observers should be notified.
348 net::nqe::internal::NetworkQuality network_quality_3( 369 net::nqe::internal::NetworkQuality network_quality_3(
349 base::TimeDelta::FromMilliseconds(1223), 370 base::TimeDelta::FromMilliseconds(1223),
350 base::TimeDelta::FromMilliseconds(2312), 1403); 371 base::TimeDelta::FromMilliseconds(2312), 1403);
351 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 372 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
352 network_quality_3); 373 network_quality_3);
353 base::RunLoop().RunUntilIdle(); 374 base::RunLoop().RunUntilIdle();
354 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()")); 375 EXPECT_EQ(2300, RunScriptExtractInt("getRtt()"));
355 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()")); 376 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()"));
356 } 377 }
357 378
358 } // namespace content 379 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/test/data/net_info.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698