| 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 <map> | 5 #include <map> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/test/histogram_tester.h" | 11 #include "base/test/histogram_tester.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "content/browser/net/network_quality_observer_impl.h" | 13 #include "content/browser/net/network_quality_observer_impl.h" |
| 14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 15 #include "content/public/test/browser_test_utils.h" | 15 #include "content/public/test/browser_test_utils.h" |
| 16 #include "content/public/test/content_browser_test.h" | 16 #include "content/public/test/content_browser_test.h" |
| 17 #include "content/public/test/content_browser_test_utils.h" | 17 #include "content/public/test/content_browser_test_utils.h" |
| 18 #include "content/shell/browser/shell.h" | 18 #include "content/shell/browser/shell.h" |
| 19 #include "net/base/network_change_notifier.h" | 19 #include "net/base/network_change_notifier.h" |
| 20 #include "net/base/network_change_notifier_factory.h" | 20 #include "net/base/network_change_notifier_factory.h" |
| 21 #include "net/log/test_net_log.h" | 21 #include "net/log/test_net_log.h" |
| 22 #include "net/nqe/effective_connection_type.h" |
| 22 #include "net/nqe/network_quality_estimator_test_util.h" | 23 #include "net/nqe/network_quality_estimator_test_util.h" |
| 23 | 24 |
| 25 namespace { |
| 26 |
| 27 // Returns the total count of samples in |histogram|. |
| 28 int GetTotalSampleCount(base::HistogramTester* tester, |
| 29 const std::string& histogram) { |
| 30 int count = 0; |
| 31 std::vector<base::Bucket> buckets = tester->GetAllSamples(histogram); |
| 32 for (const auto& bucket : buckets) |
| 33 count += bucket.count; |
| 34 return count; |
| 35 } |
| 36 |
| 37 } // namespace |
| 38 |
| 24 namespace content { | 39 namespace content { |
| 25 | 40 |
| 26 class NetInfoBrowserTest : public content::ContentBrowserTest { | 41 class NetInfoBrowserTest : public content::ContentBrowserTest { |
| 27 protected: | 42 protected: |
| 28 void SetUpCommandLine(base::CommandLine* command_line) override { | 43 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 29 // TODO(jkarlin): Once NetInfo is enabled on all platforms remove this | 44 // TODO(jkarlin): Once NetInfo is enabled on all platforms remove this |
| 30 // switch. | 45 // switch. |
| 31 command_line->AppendSwitch(switches::kEnableNetworkInformation); | 46 command_line->AppendSwitch(switches::kEnableNetworkInformation); |
| 32 | 47 |
| 33 // TODO(jkarlin): Remove this once downlinkMax is no longer | 48 // TODO(jkarlin): Remove this once downlinkMax is no longer |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 | 175 |
| 161 EXPECT_TRUE(embedded_test_server()->Start()); | 176 EXPECT_TRUE(embedded_test_server()->Start()); |
| 162 EXPECT_TRUE( | 177 EXPECT_TRUE( |
| 163 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); | 178 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); |
| 164 | 179 |
| 165 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()")); | 180 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()")); |
| 166 EXPECT_EQ(std::numeric_limits<double>::infinity(), | 181 EXPECT_EQ(std::numeric_limits<double>::infinity(), |
| 167 RunScriptExtractDouble("getDownlink()")); | 182 RunScriptExtractDouble("getDownlink()")); |
| 168 } | 183 } |
| 169 | 184 |
| 185 // Make sure the changes in the effective connection typeare notified to the |
| 186 // render thread. |
| 187 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, |
| 188 EffectiveConnectionTypeChangeNotfied) { |
| 189 base::HistogramTester histogram_tester; |
| 190 net::TestNetworkQualityEstimator estimator( |
| 191 nullptr, std::map<std::string, std::string>(), false, false, true, true, |
| 192 base::MakeUnique<net::BoundTestNetLog>()); |
| 193 NetworkQualityObserverImpl impl(&estimator); |
| 194 |
| 195 net::nqe::internal::NetworkQuality network_quality_1( |
| 196 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300); |
| 197 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 198 network_quality_1); |
| 199 |
| 200 EXPECT_TRUE(embedded_test_server()->Start()); |
| 201 EXPECT_TRUE( |
| 202 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html"))); |
| 203 |
| 204 FetchHistogramsFromChildProcesses(); |
| 205 |
| 206 int samples = |
| 207 GetTotalSampleCount(&histogram_tester, "NQE.RenderThreadNotified"); |
| 208 EXPECT_LT(0, samples); |
| 209 |
| 210 // Change effective connection type so that the renderer process is notified. |
| 211 // Changing the effective connection type from 2G to 3G is guaranteed to |
| 212 // generate the notification to the renderers, irrespective of the current |
| 213 // effective connection type. |
| 214 estimator.NotifyObserversOfEffectiveConnectionType( |
| 215 net::EFFECTIVE_CONNECTION_TYPE_2G); |
| 216 base::RunLoop().RunUntilIdle(); |
| 217 estimator.NotifyObserversOfEffectiveConnectionType( |
| 218 net::EFFECTIVE_CONNECTION_TYPE_3G); |
| 219 base::RunLoop().RunUntilIdle(); |
| 220 FetchHistogramsFromChildProcesses(); |
| 221 base::RunLoop().RunUntilIdle(); |
| 222 EXPECT_GT(GetTotalSampleCount(&histogram_tester, "NQE.RenderThreadNotified"), |
| 223 samples); |
| 224 } |
| 225 |
| 170 // Make sure the changes in the network quality are notified to the render | 226 // Make sure the changes in the network quality are notified to the render |
| 171 // thread, and the changed network quality is accessible via Javascript API. | 227 // thread, and the changed network quality is accessible via Javascript API. |
| 172 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) { | 228 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) { |
| 173 base::HistogramTester histogram_tester; | 229 base::HistogramTester histogram_tester; |
| 174 net::TestNetworkQualityEstimator estimator( | 230 net::TestNetworkQualityEstimator estimator( |
| 175 nullptr, std::map<std::string, std::string>(), false, false, true, true, | 231 nullptr, std::map<std::string, std::string>(), false, false, true, true, |
| 176 base::MakeUnique<net::BoundTestNetLog>()); | 232 base::MakeUnique<net::BoundTestNetLog>()); |
| 177 NetworkQualityObserverImpl impl(&estimator); | 233 NetworkQualityObserverImpl impl(&estimator); |
| 178 | 234 |
| 179 net::nqe::internal::NetworkQuality network_quality_1( | 235 net::nqe::internal::NetworkQuality network_quality_1( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 base::TimeDelta::FromMilliseconds(1223), | 346 base::TimeDelta::FromMilliseconds(1223), |
| 291 base::TimeDelta::FromMilliseconds(2312), 1403); | 347 base::TimeDelta::FromMilliseconds(2312), 1403); |
| 292 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( | 348 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( |
| 293 network_quality_3); | 349 network_quality_3); |
| 294 base::RunLoop().RunUntilIdle(); | 350 base::RunLoop().RunUntilIdle(); |
| 295 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()")); | 351 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()")); |
| 296 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()")); | 352 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()")); |
| 297 } | 353 } |
| 298 | 354 |
| 299 } // namespace content | 355 } // namespace content |
| OLD | NEW |