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

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

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (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
« no previous file with comments | « content/browser/net/network_quality_observer_impl.cc ('k') | content/common/renderer.mojom » ('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 EXPECT_TRUE(embedded_test_server()->Start());
162 EXPECT_TRUE(
163 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
164
165 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()"));
166 EXPECT_EQ(std::numeric_limits<double>::infinity(),
167 RunScriptExtractDouble("getDownlink()"));
168 }
169
147 // Make sure the changes in the network quality are notified to the render 170 // Make sure the changes in the network quality are notified to the render
148 // thread. 171 // thread, and the changed network quality is accessible via Javascript API.
149 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) { 172 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
150 base::HistogramTester histogram_tester; 173 base::HistogramTester histogram_tester;
151 net::TestNetworkQualityEstimator estimator; 174 net::TestNetworkQualityEstimator estimator(
175 nullptr, std::map<std::string, std::string>(), false, false, true, true,
176 base::MakeUnique<net::BoundTestNetLog>());
152 NetworkQualityObserverImpl impl(&estimator); 177 NetworkQualityObserverImpl impl(&estimator);
178
179 net::nqe::internal::NetworkQuality network_quality_1(
180 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
153 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 181 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
154 net::nqe::internal::NetworkQuality(base::TimeDelta::FromSeconds(1), 182 network_quality_1);
155 base::TimeDelta::FromSeconds(2), 3));
156 183
157 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html")); 184 EXPECT_TRUE(embedded_test_server()->Start());
185 EXPECT_TRUE(
186 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
158 187
159 FetchHistogramsFromChildProcesses(); 188 FetchHistogramsFromChildProcesses();
160 EXPECT_FALSE( 189 EXPECT_FALSE(
161 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty()); 190 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty());
191
192 EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(),
193 RunScriptExtractDouble("getRtt()"));
194 EXPECT_EQ(
195 static_cast<double>(network_quality_1.downstream_throughput_kbps()) /
196 1000,
197 RunScriptExtractDouble("getDownlink()"));
198
199 // Verify that the network quality change is accessible via Javascript API.
200 net::nqe::internal::NetworkQuality network_quality_2(
201 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000);
202 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
203 network_quality_2);
204 base::RunLoop().RunUntilIdle();
205 EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(),
206 RunScriptExtractDouble("getRtt()"));
207 EXPECT_EQ(
208 static_cast<double>(network_quality_2.downstream_throughput_kbps()) /
209 1000,
210 RunScriptExtractDouble("getDownlink()"));
211 }
212
213 // Make sure the changes in the network quality are rounded to the nearest
214 // 25 milliseconds or 25 kbps.
215 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
216 base::HistogramTester histogram_tester;
217 net::TestNetworkQualityEstimator estimator(
218 std::unique_ptr<net::ExternalEstimateProvider>(),
219 std::map<std::string, std::string>(), false, false, true, true,
220 base::MakeUnique<net::BoundTestNetLog>());
221 NetworkQualityObserverImpl impl(&estimator);
222
223 // Verify that the network quality is rounded properly.
224 net::nqe::internal::NetworkQuality network_quality_1(
225 base::TimeDelta::FromMilliseconds(123),
226 base::TimeDelta::FromMilliseconds(212), 303);
227 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
228 network_quality_1);
229
230 EXPECT_TRUE(embedded_test_server()->Start());
231 EXPECT_TRUE(
232 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
233 EXPECT_EQ(200, RunScriptExtractDouble("getRtt()"));
234 EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()"));
235
236 net::nqe::internal::NetworkQuality network_quality_2(
237 base::TimeDelta::FromMilliseconds(123),
238 base::TimeDelta::FromMilliseconds(1217), 1317);
239 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
240 network_quality_2);
241 base::RunLoop().RunUntilIdle();
242 EXPECT_EQ(1225, RunScriptExtractDouble("getRtt()"));
243 EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()"));
244
245 net::nqe::internal::NetworkQuality network_quality_3(
246 base::TimeDelta::FromMilliseconds(12),
247 base::TimeDelta::FromMilliseconds(12), 12);
248 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
249 network_quality_3);
250 base::RunLoop().RunUntilIdle();
251 EXPECT_EQ(0, RunScriptExtractDouble("getRtt()"));
252 EXPECT_EQ(0, RunScriptExtractDouble("getDownlink()"));
253 }
254
255 // Make sure the minor changes (<10%) in the network quality are not notified.
256 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
257 base::HistogramTester histogram_tester;
258 net::TestNetworkQualityEstimator estimator(
259 nullptr, std::map<std::string, std::string>(), false, false, true, true,
260 base::MakeUnique<net::BoundTestNetLog>());
261 NetworkQualityObserverImpl impl(&estimator);
262
263 // Verify that the network quality is rounded properly.
264 net::nqe::internal::NetworkQuality network_quality_1(
265 base::TimeDelta::FromMilliseconds(1123),
266 base::TimeDelta::FromMilliseconds(1212), 1303);
267 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
268 network_quality_1);
269
270 EXPECT_TRUE(embedded_test_server()->Start());
271 EXPECT_TRUE(
272 NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
273 EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
274 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
275
276 // All the 3 metrics change by less than 10%. So, the observers are not
277 // notified.
278 net::nqe::internal::NetworkQuality network_quality_2(
279 base::TimeDelta::FromMilliseconds(1223),
280 base::TimeDelta::FromMilliseconds(1312), 1403);
281 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
282 network_quality_2);
283 base::RunLoop().RunUntilIdle();
284 EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
285 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
286
287 // Transport RTT has changed by more than 10% from the last notified value of
288 // |network_quality_1|. The observers should be notified.
289 net::nqe::internal::NetworkQuality network_quality_3(
290 base::TimeDelta::FromMilliseconds(1223),
291 base::TimeDelta::FromMilliseconds(2312), 1403);
292 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
293 network_quality_3);
294 base::RunLoop().RunUntilIdle();
295 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()"));
296 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()"));
162 } 297 }
163 298
164 } // namespace content 299 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/net/network_quality_observer_impl.cc ('k') | content/common/renderer.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698