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

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

Issue 2883763002: Expose ECT to render frames, Blink and NetInfo (Closed)
Patch Set: rebased Created 3 years, 7 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 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 base::MakeUnique<net::BoundTestNetLog>()); 173 base::MakeUnique<net::BoundTestNetLog>());
159 NetworkQualityObserverImpl impl(&estimator); 174 NetworkQualityObserverImpl impl(&estimator);
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()"));
183 EXPECT_EQ("4g", RunScriptExtractString("getEffectiveType()"));
184 }
185
186 // Make sure the changes in the effective connection typeare notified to the
187 // render thread.
188 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
189 EffectiveConnectionTypeChangeNotfied) {
190 base::HistogramTester histogram_tester;
191 net::TestNetworkQualityEstimator estimator(
192 nullptr, std::map<std::string, std::string>(), false, false, true, true,
193 base::MakeUnique<net::BoundTestNetLog>());
194 NetworkQualityObserverImpl impl(&estimator);
195
196 net::nqe::internal::NetworkQuality network_quality_1(
197 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
198 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
199 network_quality_1);
200
201 EXPECT_TRUE(embedded_test_server()->Start());
202 EXPECT_TRUE(
203 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
204
205 FetchHistogramsFromChildProcesses();
206
207 int samples =
208 GetTotalSampleCount(&histogram_tester, "NQE.RenderThreadNotified");
209 EXPECT_LT(0, samples);
210
211 // Change effective connection type so that the renderer process is notified.
212 // Changing the effective connection type from 2G to 3G is guaranteed to
213 // generate the notification to the renderers, irrespective of the current
214 // effective connection type.
215 estimator.NotifyObserversOfEffectiveConnectionType(
216 net::EFFECTIVE_CONNECTION_TYPE_2G);
217 base::RunLoop().RunUntilIdle();
218 EXPECT_EQ("2g", RunScriptExtractString("getEffectiveType()"));
219 estimator.NotifyObserversOfEffectiveConnectionType(
220 net::EFFECTIVE_CONNECTION_TYPE_3G);
221 base::RunLoop().RunUntilIdle();
222 EXPECT_EQ("3g", RunScriptExtractString("getEffectiveType()"));
223 FetchHistogramsFromChildProcesses();
224 base::RunLoop().RunUntilIdle();
225 EXPECT_GT(GetTotalSampleCount(&histogram_tester, "NQE.RenderThreadNotified"),
226 samples);
168 } 227 }
169 228
170 // Make sure the changes in the network quality are notified to the render 229 // 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. 230 // thread, and the changed network quality is accessible via Javascript API.
172 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) { 231 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
173 base::HistogramTester histogram_tester; 232 base::HistogramTester histogram_tester;
174 net::TestNetworkQualityEstimator estimator( 233 net::TestNetworkQualityEstimator estimator(
175 nullptr, std::map<std::string, std::string>(), false, false, true, true, 234 nullptr, std::map<std::string, std::string>(), false, false, true, true,
176 base::MakeUnique<net::BoundTestNetLog>()); 235 base::MakeUnique<net::BoundTestNetLog>());
177 NetworkQualityObserverImpl impl(&estimator); 236 NetworkQualityObserverImpl impl(&estimator);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 base::TimeDelta::FromMilliseconds(1223), 349 base::TimeDelta::FromMilliseconds(1223),
291 base::TimeDelta::FromMilliseconds(2312), 1403); 350 base::TimeDelta::FromMilliseconds(2312), 1403);
292 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 351 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
293 network_quality_3); 352 network_quality_3);
294 base::RunLoop().RunUntilIdle(); 353 base::RunLoop().RunUntilIdle();
295 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()")); 354 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()"));
296 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()")); 355 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()"));
297 } 356 }
298 357
299 } // namespace content 358 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698