Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 | 158 |
| 158 // Open the same page in a new window on the same process. | 159 // Open the same page in a new window on the same process. |
| 159 EXPECT_TRUE(ExecuteScript(shell(), "window.open(\"net_info.html\")")); | 160 EXPECT_TRUE(ExecuteScript(shell(), "window.open(\"net_info.html\")")); |
| 160 | 161 |
| 161 // The network state should not have reinitialized to what it was when opening | 162 // The network state should not have reinitialized to what it was when opening |
| 162 // the first window (online). | 163 // the first window (online). |
| 163 EXPECT_FALSE(RunScriptExtractBool("getOnLine()")); | 164 EXPECT_FALSE(RunScriptExtractBool("getOnLine()")); |
| 164 } | 165 } |
| 165 | 166 |
| 166 // Verify that when the network quality notifications are not sent, the | 167 // Verify that when the network quality notifications are not sent, the |
| 167 // Javascript API returns invalid estimate. | 168 // Javascript API returns a valid estimate that is multiple of 25 msec and 25 |
| 169 // kbps. | |
| 168 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, | 170 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, |
| 169 NetworkQualityEstimatorNotInitialized) { | 171 NetworkQualityEstimatorNotInitialized) { |
| 170 base::HistogramTester histogram_tester; | 172 base::HistogramTester histogram_tester; |
| 171 net::TestNetworkQualityEstimator estimator( | 173 net::TestNetworkQualityEstimator estimator( |
| 172 nullptr, std::map<std::string, std::string>(), false, false, true, true, | 174 nullptr, std::map<std::string, std::string>(), false, false, true, true, |
| 173 base::MakeUnique<net::BoundTestNetLog>()); | 175 base::MakeUnique<net::BoundTestNetLog>()); |
| 174 NetworkQualityObserverImpl impl(&estimator); | 176 NetworkQualityObserverImpl impl(&estimator); |
| 175 | 177 |
| 176 EXPECT_TRUE(embedded_test_server()->Start()); | 178 EXPECT_TRUE(embedded_test_server()->Start()); |
| 177 EXPECT_TRUE( | 179 EXPECT_TRUE( |
| 178 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); | 180 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); |
| 179 | 181 |
| 180 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()")); | 182 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()")); |
|
jkarlin
2017/05/31 17:44:22
Doesn't rtt return an unsigned long long?
tbansal1
2017/06/01 20:41:52
Done.
| |
| 181 EXPECT_EQ(std::numeric_limits<double>::infinity(), | 183 EXPECT_EQ(0, static_cast<int>(RunScriptExtractDouble("getRtt()")) % 25); |
|
jkarlin
2017/05/31 17:44:22
ditto, and everywhere else in this file.
tbansal1
2017/06/01 20:41:52
Done.
| |
| 182 RunScriptExtractDouble("getDownlink()")); | 184 |
| 185 double downlink_mbps = RunScriptExtractDouble("getDownlink()"); | |
| 186 EXPECT_LE(0, downlink_mbps); | |
| 187 | |
| 188 double fraction_part, int_part; | |
| 189 fraction_part = std::modf(downlink_mbps, &int_part); | |
| 190 // If |fraction_part| is 0, it implies |downlink_mbps| is a multiple of 1 | |
| 191 // Mbps, and hence it is a multiple of 25 kbps. | |
| 192 EXPECT_TRUE(static_cast<int>(downlink_mbps * 1000) % 25 == 0 || | |
| 193 fraction_part == 0); | |
| 194 | |
| 183 EXPECT_EQ("4g", RunScriptExtractString("getEffectiveType()")); | 195 EXPECT_EQ("4g", RunScriptExtractString("getEffectiveType()")); |
| 184 } | 196 } |
| 185 | 197 |
| 186 // Make sure the changes in the effective connection typeare notified to the | 198 // Make sure the changes in the effective connection typeare notified to the |
| 187 // render thread. | 199 // render thread. |
| 188 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, | 200 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, |
| 189 EffectiveConnectionTypeChangeNotfied) { | 201 EffectiveConnectionTypeChangeNotfied) { |
| 190 base::HistogramTester histogram_tester; | 202 base::HistogramTester histogram_tester; |
| 191 net::TestNetworkQualityEstimator estimator( | 203 net::TestNetworkQualityEstimator estimator( |
| 192 nullptr, std::map<std::string, std::string>(), false, false, true, true, | 204 nullptr, std::map<std::string, std::string>(), false, false, true, true, |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 base::TimeDelta::FromMilliseconds(1223), | 361 base::TimeDelta::FromMilliseconds(1223), |
| 350 base::TimeDelta::FromMilliseconds(2312), 1403); | 362 base::TimeDelta::FromMilliseconds(2312), 1403); |
| 351 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 363 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 352 network_quality_3); | 364 network_quality_3); |
| 353 base::RunLoop().RunUntilIdle(); | 365 base::RunLoop().RunUntilIdle(); |
| 354 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()")); | 366 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()")); |
| 355 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()")); | 367 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()")); |
| 356 } | 368 } |
| 357 | 369 |
| 358 } // namespace content | 370 } // namespace content |
| OLD | NEW |