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

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

Issue 2863973003: Expose RTT and downlink bandwidth using experimental Javascript API (Closed)
Patch Set: ps 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/strings/string_number_conversions.h" 7 #include "base/strings/string_number_conversions.h"
8 #include "base/test/histogram_tester.h" 8 #include "base/test/histogram_tester.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "content/browser/net/network_quality_observer_impl.h" 10 #include "content/browser/net/network_quality_observer_impl.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 138
139 // Open the same page in a new window on the same process. 139 // Open the same page in a new window on the same process.
140 EXPECT_TRUE(ExecuteScript(shell(), "window.open(\"net_info.html\")")); 140 EXPECT_TRUE(ExecuteScript(shell(), "window.open(\"net_info.html\")"));
141 141
142 // The network state should not have reinitialized to what it was when opening 142 // The network state should not have reinitialized to what it was when opening
143 // the first window (online). 143 // the first window (online).
144 EXPECT_FALSE(RunScriptExtractBool("getOnLine()")); 144 EXPECT_FALSE(RunScriptExtractBool("getOnLine()"));
145 } 145 }
146 146
147 // Make sure the changes in the network quality are notified to the render 147 // Make sure the changes in the network quality are notified to the render
148 // thread. 148 // thread, and the changed network quality is accessible via Javascript API.
149 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) { 149 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
150 base::HistogramTester histogram_tester; 150 base::HistogramTester histogram_tester;
151 net::TestNetworkQualityEstimator estimator; 151 net::TestNetworkQualityEstimator estimator;
152 estimator.SuppressNotificationsForTesting();
152 NetworkQualityObserverImpl impl(&estimator); 153 NetworkQualityObserverImpl impl(&estimator);
154
155 net::nqe::internal::NetworkQuality network_quality_1(
156 base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
153 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed( 157 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
154 net::nqe::internal::NetworkQuality(base::TimeDelta::FromSeconds(1), 158 network_quality_1);
155 base::TimeDelta::FromSeconds(2), 3));
156
157 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html")); 159 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
158 160
161 base::RunLoop().RunUntilIdle();
159 FetchHistogramsFromChildProcesses(); 162 FetchHistogramsFromChildProcesses();
160 EXPECT_FALSE( 163 EXPECT_FALSE(
161 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty()); 164 histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty());
165
166 EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(),
167 RunScriptExtractDouble("getRtt()"));
168 EXPECT_EQ(
169 static_cast<double>(network_quality_1.downstream_throughput_kbps()) /
170 1000,
171 RunScriptExtractDouble("getDownlink()"));
172
173 // Verify that the network quality change is accessible via Javascript API.
174 net::nqe::internal::NetworkQuality network_quality_2(
175 base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000);
176 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
177 network_quality_2);
178 base::RunLoop().RunUntilIdle();
179 EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(),
180 RunScriptExtractDouble("getRtt()"));
181 EXPECT_EQ(
182 static_cast<double>(network_quality_2.downstream_throughput_kbps()) /
183 1000,
184 RunScriptExtractDouble("getDownlink()"));
185 }
186
187 // Make sure the changes in the network quality are rounded to the nearest
188 // 25 milliseconds or 25 kbps.
189 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
190 base::HistogramTester histogram_tester;
191 net::TestNetworkQualityEstimator estimator;
192 estimator.SuppressNotificationsForTesting();
193 NetworkQualityObserverImpl impl(&estimator);
194
195 // Verify that the network quality is rounded properly.
196 net::nqe::internal::NetworkQuality network_quality_1(
197 base::TimeDelta::FromMilliseconds(123),
bengr 2017/05/12 19:09:54 I would also test value of -1 since that's how you
tbansal1 2017/05/12 22:18:17 Added -1 and 0 check.
198 base::TimeDelta::FromMilliseconds(212), 303);
199 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
200 network_quality_1);
201 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
202 base::RunLoop().RunUntilIdle();
203 EXPECT_EQ(200, RunScriptExtractDouble("getRtt()"));
204 EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()"));
205
206 net::nqe::internal::NetworkQuality network_quality_2(
207 base::TimeDelta::FromMilliseconds(123),
208 base::TimeDelta::FromMilliseconds(1217), 1317);
209 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
210 network_quality_2);
211 base::RunLoop().RunUntilIdle();
212 EXPECT_EQ(1225, RunScriptExtractDouble("getRtt()"));
213 EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()"));
214 }
215
216 // Make sure the minor changes in the network quality are not notified.
bengr 2017/05/12 19:09:54 Say how minor is minor, or at least say how to det
tbansal1 2017/05/12 22:18:17 Done.
217 IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
218 base::HistogramTester histogram_tester;
219 net::TestNetworkQualityEstimator estimator;
220 estimator.SuppressNotificationsForTesting();
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(1123),
226 base::TimeDelta::FromMilliseconds(1212), 1303);
227 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
228 network_quality_1);
229 NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
230 base::RunLoop().RunUntilIdle();
231 EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
232 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
233
234 // All the 3 metrics change by less than 10%. So, the observers are not
235 // notified.
236 net::nqe::internal::NetworkQuality network_quality_2(
237 base::TimeDelta::FromMilliseconds(1223),
238 base::TimeDelta::FromMilliseconds(1312), 1403);
239 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
240 network_quality_2);
241 base::RunLoop().RunUntilIdle();
242 EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
243 EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
244
245 // Transport RTT has changed by more than 10% from the last notified value of
246 // |network_quality_1|. The observers should be notified.
247 net::nqe::internal::NetworkQuality network_quality_3(
248 base::TimeDelta::FromMilliseconds(1223),
249 base::TimeDelta::FromMilliseconds(2312), 1403);
250 estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
251 network_quality_3);
252 base::RunLoop().RunUntilIdle();
253 EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()"));
254 EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()"));
162 } 255 }
163 256
164 } // namespace content 257 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/render_thread_impl.cc » ('j') | net/nqe/network_quality_estimator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698