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

Unified Diff: content/browser/net_info_browsertest.cc

Issue 2912013002: NetInfo: Slight update to the default network quality value (Closed)
Patch Set: jkarlin 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/net_info_browsertest.cc
diff --git a/content/browser/net_info_browsertest.cc b/content/browser/net_info_browsertest.cc
index e4eec850d7fa659c225611fd3eaa1ad18a8b29a9..6e5042e798d2b4ddfe644485bc91011d6e1ef24f 100644
--- a/content/browser/net_info_browsertest.cc
+++ b/content/browser/net_info_browsertest.cc
@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <cmath> // For std::modf.
#include <map>
#include <string>
@@ -95,6 +96,12 @@ class NetInfoBrowserTest : public content::ContentBrowserTest {
EXPECT_TRUE(base::StringToDouble(RunScriptExtractString(script), &data));
return data;
}
+
+ int RunScriptExtractInt(const std::string& script) {
+ int data = 0;
+ EXPECT_TRUE(base::StringToInt(RunScriptExtractString(script), &data));
nasko 2017/06/01 22:16:13 ExecuteScriptAndExtractInt?
tbansal1 2017/06/01 23:26:46 Done.
+ return data;
+ }
};
// Make sure the type is correct when the page is first opened.
@@ -164,7 +171,8 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, TwoRenderViewsInOneProcess) {
}
// Verify that when the network quality notifications are not sent, the
-// Javascript API returns invalid estimate.
+// Javascript API returns a valid estimate that is multiple of 25 msec and 25
+// kbps.
IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
NetworkQualityEstimatorNotInitialized) {
base::HistogramTester histogram_tester;
@@ -177,9 +185,19 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
EXPECT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
- EXPECT_EQ(0, RunScriptExtractDouble("getRtt()"));
- EXPECT_EQ(std::numeric_limits<double>::infinity(),
- RunScriptExtractDouble("getDownlink()"));
+ EXPECT_EQ(0, RunScriptExtractInt("getRtt()"));
nasko 2017/06/01 22:16:12 Why can't ExecuteScriptAndExtractInt be used?
tbansal1 2017/06/01 23:26:46 Can be. RunScriptExtractInt() is slightly easier t
+ EXPECT_EQ(0, RunScriptExtractInt("getRtt()") % 25);
+
+ double downlink_mbps = RunScriptExtractDouble("getDownlink()");
nasko 2017/06/01 22:16:13 Similarly ExecuteScriptAndExtractDouble?
tbansal1 2017/06/01 23:26:46 Same as above. Helper method RunScriptExtractDoubl
+ EXPECT_LE(0, downlink_mbps);
+
+ double fraction_part, int_part;
+ fraction_part = std::modf(downlink_mbps, &int_part);
+ // If |fraction_part| is 0, it implies |downlink_mbps| is a multiple of 1
+ // Mbps, and hence it is a multiple of 25 kbps.
+ EXPECT_TRUE(static_cast<int>(downlink_mbps * 1000) % 25 == 0 ||
nasko 2017/06/01 22:16:12 Shouldn't we be dividing the mbps to get kbps inst
tbansal1 2017/06/01 23:26:46 nope, multiplying it by 1000 would give kbps. We w
nasko 2017/06/03 00:09:47 Well, when you have mbps and multiply by 1000, you
tbansal1 2017/06/05 13:52:20 We probably are. |downlink_mbps| is a double. Let'
nasko 2017/06/05 23:43:01 Thanks for the explanation. If you were to only mu
+ fraction_part == 0);
+
EXPECT_EQ("4g", RunScriptExtractString("getEffectiveType()"));
}
@@ -249,7 +267,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
histogram_tester.GetAllSamples("NQE.RenderThreadNotified").empty());
EXPECT_EQ(network_quality_1.transport_rtt().InMilliseconds(),
- RunScriptExtractDouble("getRtt()"));
+ RunScriptExtractInt("getRtt()"));
EXPECT_EQ(
static_cast<double>(network_quality_1.downstream_throughput_kbps()) /
1000,
@@ -262,7 +280,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
network_quality_2);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(),
- RunScriptExtractDouble("getRtt()"));
+ RunScriptExtractInt("getRtt()"));
EXPECT_EQ(
static_cast<double>(network_quality_2.downstream_throughput_kbps()) /
1000,
@@ -289,7 +307,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
EXPECT_TRUE(embedded_test_server()->Start());
EXPECT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
- EXPECT_EQ(200, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(200, RunScriptExtractInt("getRtt()"));
EXPECT_EQ(0.300, RunScriptExtractDouble("getDownlink()"));
net::nqe::internal::NetworkQuality network_quality_2(
@@ -298,7 +316,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_2);
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(1225, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(1225, RunScriptExtractInt("getRtt()"));
EXPECT_EQ(1.325, RunScriptExtractDouble("getDownlink()"));
net::nqe::internal::NetworkQuality network_quality_3(
@@ -307,7 +325,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_3);
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(0, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(0, RunScriptExtractInt("getRtt()"));
EXPECT_EQ(0, RunScriptExtractDouble("getDownlink()"));
}
@@ -329,7 +347,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
EXPECT_TRUE(embedded_test_server()->Start());
EXPECT_TRUE(
NavigateToURL(shell(), embedded_test_server()->GetURL("/net_info.html")));
- EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(1200, RunScriptExtractInt("getRtt()"));
EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
// All the 3 metrics change by less than 10%. So, the observers are not
@@ -340,7 +358,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_2);
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(1200, RunScriptExtractInt("getRtt()"));
EXPECT_EQ(1.300, RunScriptExtractDouble("getDownlink()"));
// Transport RTT has changed by more than 10% from the last notified value of
@@ -351,7 +369,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_3);
base::RunLoop().RunUntilIdle();
- EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()"));
+ EXPECT_EQ(2300, RunScriptExtractInt("getRtt()"));
EXPECT_EQ(1.400, RunScriptExtractDouble("getDownlink()"));
}

Powered by Google App Engine
This is Rietveld 408576698