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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/renderer/render_thread_impl.cc » ('j') | net/nqe/network_quality_estimator.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/net_info_browsertest.cc
diff --git a/content/browser/net_info_browsertest.cc b/content/browser/net_info_browsertest.cc
index 135ac36037517d3752ffb39f2d6df92059f6e029..1c0a5ea28f219b85971acc7f23974db8814f0897 100644
--- a/content/browser/net_info_browsertest.cc
+++ b/content/browser/net_info_browsertest.cc
@@ -145,20 +145,113 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, TwoRenderViewsInOneProcess) {
}
// Make sure the changes in the network quality are notified to the render
-// thread.
+// thread, and the changed network quality is accessible via Javascript API.
IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
base::HistogramTester histogram_tester;
net::TestNetworkQualityEstimator estimator;
+ estimator.SuppressNotificationsForTesting();
NetworkQualityObserverImpl impl(&estimator);
- estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
- net::nqe::internal::NetworkQuality(base::TimeDelta::FromSeconds(1),
- base::TimeDelta::FromSeconds(2), 3));
+ net::nqe::internal::NetworkQuality network_quality_1(
+ base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
+ estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ network_quality_1);
NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
+ base::RunLoop().RunUntilIdle();
FetchHistogramsFromChildProcesses();
EXPECT_FALSE(
histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty());
+
+ EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(),
+ RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(
+ static_cast<double>(network_quality_1.downstream_throughput_kbps()) /
+ 1000,
+ RunScriptExtractDouble("getDownlink()"));
+
+ // Verify that the network quality change is accessible via Javascript API.
+ net::nqe::internal::NetworkQuality network_quality_2(
+ base::TimeDelta::FromSeconds(10), base::TimeDelta::FromSeconds(20), 3000);
+ estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ network_quality_2);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(),
+ RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(
+ static_cast<double>(network_quality_2.downstream_throughput_kbps()) /
+ 1000,
+ RunScriptExtractDouble("getDownlink()"));
+}
+
+// Make sure the changes in the network quality are rounded to the nearest
+// 25 milliseconds or 25 kbps.
+IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
+ base::HistogramTester histogram_tester;
+ net::TestNetworkQualityEstimator estimator;
+ estimator.SuppressNotificationsForTesting();
+ NetworkQualityObserverImpl impl(&estimator);
+
+ // Verify that the network quality is rounded properly.
+ net::nqe::internal::NetworkQuality network_quality_1(
+ 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.
+ base::TimeDelta::FromMilliseconds(212), 303);
+ estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ network_quality_1);
+ NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(200, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()"));
+
+ net::nqe::internal::NetworkQuality network_quality_2(
+ base::TimeDelta::FromMilliseconds(123),
+ base::TimeDelta::FromMilliseconds(1217), 1317);
+ estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ network_quality_2);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1225, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()"));
+}
+
+// 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.
+IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
+ base::HistogramTester histogram_tester;
+ net::TestNetworkQualityEstimator estimator;
+ estimator.SuppressNotificationsForTesting();
+ NetworkQualityObserverImpl impl(&estimator);
+
+ // Verify that the network quality is rounded properly.
+ net::nqe::internal::NetworkQuality network_quality_1(
+ base::TimeDelta::FromMilliseconds(1123),
+ base::TimeDelta::FromMilliseconds(1212), 1303);
+ estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ network_quality_1);
+ NavigateToURL(shell(), content::GetTestUrl("", "net_info.html"));
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
+
+ // All the 3 metrics change by less than 10%. So, the observers are not
+ // notified.
+ net::nqe::internal::NetworkQuality network_quality_2(
+ base::TimeDelta::FromMilliseconds(1223),
+ base::TimeDelta::FromMilliseconds(1312), 1403);
+ estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ network_quality_2);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
+
+ // Transport RTT has changed by more than 10% from the last notified value of
+ // |network_quality_1|. The observers should be notified.
+ net::nqe::internal::NetworkQuality network_quality_3(
+ base::TimeDelta::FromMilliseconds(1223),
+ base::TimeDelta::FromMilliseconds(2312), 1403);
+ estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ network_quality_3);
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()"));
}
} // namespace content
« 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