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

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

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (Closed)
Patch Set: bengr comments 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
« no previous file with comments | « no previous file | content/renderer/render_thread_impl.cc » ('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 <map>
6 #include <string>
7
5 #include "base/command_line.h" 8 #include "base/command_line.h"
6 #include "base/run_loop.h" 9 #include "base/run_loop.h"
7 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
8 #include "base/test/histogram_tester.h" 11 #include "base/test/histogram_tester.h"
9 #include "build/build_config.h" 12 #include "build/build_config.h"
10 #include "content/browser/net/network_quality_observer_impl.h" 13 #include "content/browser/net/network_quality_observer_impl.h"
11 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
12 #include "content/public/test/browser_test_utils.h" 15 #include "content/public/test/browser_test_utils.h"
13 #include "content/public/test/content_browser_test.h" 16 #include "content/public/test/content_browser_test.h"
14 #include "content/public/test/content_browser_test_utils.h" 17 #include "content/public/test/content_browser_test_utils.h"
15 #include "content/shell/browser/shell.h" 18 #include "content/shell/browser/shell.h"
16 #include "net/base/network_change_notifier.h" 19 #include "net/base/network_change_notifier.h"
17 #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"
18 #include "net/nqe/network_quality_estimator_test_util.h" 22 #include "net/nqe/network_quality_estimator_test_util.h"
19 23
20 namespace content { 24 namespace content {
21 25
22 class NetInfoBrowserTest : public content::ContentBrowserTest { 26 class NetInfoBrowserTest : public content::ContentBrowserTest {
23 protected: 27 protected:
24 void SetUpCommandLine(base::CommandLine* command_line) override { 28 void SetUpCommandLine(base::CommandLine* command_line) override {
25 // TODO(jkarlin): Once NetInfo is enabled on all platforms remove this 29 // TODO(jkarlin): Once NetInfo is enabled on all platforms remove this
26 // switch. 30 // switch.
27 command_line->AppendSwitch(switches::kEnableNetworkInformation); 31 command_line->AppendSwitch(switches::kEnableNetworkInformation);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 EXPECT_FALSE(RunScriptExtractBool("getOnLine()")); 141 EXPECT_FALSE(RunScriptExtractBool("getOnLine()"));
138 142
139 // Open the same page in a new window on the same process. 143 // Open the same page in a new window on the same process.
140 EXPECT_TRUE(ExecuteScript(shell(), "window.open(\"net_info.html\")")); 144 EXPECT_TRUE(ExecuteScript(shell(), "window.open(\"net_info.html\")"));
141 145
142 // The network state should not have reinitialized to what it was when opening 146 // The network state should not have reinitialized to what it was when opening
143 // the first window (online). 147 // the first window (online).
144 EXPECT_FALSE(RunScriptExtractBool("getOnLine()")); 148 EXPECT_FALSE(RunScriptExtractBool("getOnLine()"));
145 } 149 }
146 150
151 // Verify that when the network quality notifications are not sent, the
152 // Javascript API returns invalid estimate.
153 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
154 NetworkQualityEstimatorNotInitialized) {
155 base::HistogramTester histogram_tester;
156 net::TestNetworkQualityEstimator estimator(
157 nullptr, std::map<std::string, std::string>(), false, false, true, true,
158 base::MakeUnique<net::BoundTestNetLog>());
159 NetworkQualityObserverImpl impl(&estimator);
160
161 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
nasko 2017/05/12 23:29:54 Why not load this through the embedded_test_server
tbansal1 2017/05/15 18:05:03 Done.
162 base::RunLoop().RunUntilIdle();
nasko 2017/05/12 23:29:54 Why do we need this? NavigateToURL is waiting for
tbansal1 2017/05/15 18:05:03 Done. There are still couple of RunUntilIdle() but
163 EXPECT_EQ(-1, RunScriptExtractDouble("getRtt()"));
164 EXPECT_EQ(-0.001, RunScriptExtractDouble("getDownlink()"));
165 }
166
147 // Make sure the changes in the network quality are notified to the render 167 // Make sure the changes in the network quality are notified to the render
148 // thread. 168 // thread, and the changed network quality is accessible via Javascript API.
149 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) { 169 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
150 base::HistogramTester histogram_tester; 170 base::HistogramTester histogram_tester;
151 net::TestNetworkQualityEstimator estimator; 171 net::TestNetworkQualityEstimator estimator(
172 nullptr, std::map<std::string, std::string>(), false, false, true, true,
173 base::MakeUnique<net::BoundTestNetLog>());
152 NetworkQualityObserverImpl impl(&estimator); 174 NetworkQualityObserverImpl impl(&estimator);
175
176 net::nqe::internal::NetworkQuality network_quality_1(
177 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
153 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 178 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
154 net::nqe::internal::NetworkQuality(base::TimeDelta::FromSeconds(1), 179 network_quality_1);
155 base::TimeDelta::FromSeconds(2), 3));
156
157 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html")); 180 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
158 181
182 base::RunLoop().RunUntilIdle();
nasko 2017/05/12 23:29:54 Same here, let's wait for something explicit.
tbansal1 2017/05/15 18:05:03 Done.
159 FetchHistogramsFromChildProcesses(); 183 FetchHistogramsFromChildProcesses();
160 EXPECT_FALSE( 184 EXPECT_FALSE(
161 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty()); 185 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty());
186
187 EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(),
188 RunScriptExtractDouble("getRtt()"));
189 EXPECT_EQ(
190 static_cast<double>(network_quality_1.downstream_throughput_kbps()) /
191 1000,
192 RunScriptExtractDouble("getDownlink()"));
193
194 // Verify that the network quality change is accessible via Javascript API.
195 net::nqe::internal::NetworkQuality network_quality_2(
196 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000);
197 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
198 network_quality_2);
199 base::RunLoop().RunUntilIdle();
200 EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(),
201 RunScriptExtractDouble("getRtt()"));
202 EXPECT_EQ(
203 static_cast<double>(network_quality_2.downstream_throughput_kbps()) /
204 1000,
205 RunScriptExtractDouble("getDownlink()"));
206 }
207
208 // Make sure the changes in the network quality are rounded to the nearest
209 // 25 milliseconds or 25 kbps.
210 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
211 base::HistogramTester histogram_tester;
212 net::TestNetworkQualityEstimator estimator(
213 std::unique_ptr<net::ExternalEstimateProvider>(),
214 std::map<std::string, std::string>(), false, false, true, true,
215 base::MakeUnique<net::BoundTestNetLog>());
216 NetworkQualityObserverImpl impl(&estimator);
217
218 // Verify that the network quality is rounded properly.
219 net::nqe::internal::NetworkQuality network_quality_1(
220 base::TimeDelta::FromMilliseconds(123),
221 base::TimeDelta::FromMilliseconds(212), 303);
222 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
223 network_quality_1);
224 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
225 base::RunLoop().RunUntilIdle();
226 EXPECT_EQ(200, RunScriptExtractDouble("getRtt()"));
227 EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()"));
228
229 net::nqe::internal::NetworkQuality network_quality_2(
230 base::TimeDelta::FromMilliseconds(123),
231 base::TimeDelta::FromMilliseconds(1217), 1317);
232 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
233 network_quality_2);
234 base::RunLoop().RunUntilIdle();
235 EXPECT_EQ(1225, RunScriptExtractDouble("getRtt()"));
236 EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()"));
237
238 net::nqe::internal::NetworkQuality network_quality_3(
239 base::TimeDelta::FromMilliseconds(12),
240 base::TimeDelta::FromMilliseconds(12), 12);
241 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
242 network_quality_3);
243 base::RunLoop().RunUntilIdle();
244 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()"));
245 EXPECT_EQ(0, RunScriptExtractDouble("getDownlink()"));
246 }
247
248 // Make sure the minor changes (<10%) in the network quality are not notified.
249 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
250 base::HistogramTester histogram_tester;
251 net::TestNetworkQualityEstimator estimator(
252 nullptr, std::map<std::string, std::string>(), false, false, true, true,
253 base::MakeUnique<net::BoundTestNetLog>());
254 NetworkQualityObserverImpl impl(&estimator);
255
256 // Verify that the network quality is rounded properly.
257 net::nqe::internal::NetworkQuality network_quality_1(
258 base::TimeDelta::FromMilliseconds(1123),
259 base::TimeDelta::FromMilliseconds(1212), 1303);
260 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
261 network_quality_1);
262 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
263 base::RunLoop().RunUntilIdle();
264 EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
265 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
266
267 // All the 3 metrics change by less than 10%. So, the observers are not
268 // notified.
269 net::nqe::internal::NetworkQuality network_quality_2(
270 base::TimeDelta::FromMilliseconds(1223),
271 base::TimeDelta::FromMilliseconds(1312), 1403);
272 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
273 network_quality_2);
274 base::RunLoop().RunUntilIdle();
275 EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
276 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
277
278 // Transport RTT has changed by more than 10% from the last notified value of
279 // |network_quality_1|. The observers should be notified.
280 net::nqe::internal::NetworkQuality network_quality_3(
281 base::TimeDelta::FromMilliseconds(1223),
282 base::TimeDelta::FromMilliseconds(2312), 1403);
283 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
284 network_quality_3);
285 base::RunLoop().RunUntilIdle();
286 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()"));
287 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()"));
162 } 288 }
163 289
164 } // namespace content 290 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698