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

Unified Diff: content/browser/net_info_browsertest.cc

Issue 2908233002: NetInfo default values (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 | net/nqe/network_quality_estimator_test_util.h » ('j') | no next file with comments »
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 e4eec850d7fa659c225611fd3eaa1ad18a8b29a9..552aa9393e93f495d91db786b6010a471fe3c033 100644
--- a/content/browser/net_info_browsertest.cc
+++ b/content/browser/net_info_browsertest.cc
@@ -66,6 +66,10 @@ class NetInfoBrowserTest : public content::ContentBrowserTest {
void SetUpOnMainThread() override {
base::RunLoop().RunUntilIdle();
+ estimator_ = base::MakeUnique<net::TestNetworkQualityEstimator>(
+ nullptr, std::map<std::string, std::string>(), false, false, true,
+ base::MakeUnique<net::BoundTestNetLog>());
+ impl_ = base::MakeUnique<NetworkQualityObserverImpl>(estimator_.get());
}
static void SetConnectionType(
@@ -95,6 +99,12 @@ class NetInfoBrowserTest : public content::ContentBrowserTest {
EXPECT_TRUE(base::StringToDouble(RunScriptExtractString(script), &data));
return data;
}
+
+ net::TestNetworkQualityEstimator* estimator() { return estimator_.get(); }
+
+ private:
+ std::unique_ptr<net::TestNetworkQualityEstimator> estimator_;
+ std::unique_ptr<NetworkQualityObserverImpl> impl_;
};
// Make sure the type is correct when the page is first opened.
@@ -163,39 +173,16 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, TwoRenderViewsInOneProcess) {
EXPECT_FALSE(RunScriptExtractBool("getOnLine()"));
}
-// Verify that when the network quality notifications are not sent, the
-// Javascript API returns invalid estimate.
-IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
- NetworkQualityEstimatorNotInitialized) {
- base::HistogramTester histogram_tester;
- net::TestNetworkQualityEstimator estimator(
- nullptr, std::map<std::string, std::string>(), false, false, true, true,
- base::MakeUnique<net::BoundTestNetLog>());
- NetworkQualityObserverImpl impl(&estimator);
-
- EXPECT_TRUE(embedded_test_server()->Start());
- 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("4g", RunScriptExtractString("getEffectiveType()"));
-}
-
// Make sure the changes in the effective connection typeare notified to the
// render thread.
IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
EffectiveConnectionTypeChangeNotfied) {
base::HistogramTester histogram_tester;
- net::TestNetworkQualityEstimator estimator(
- nullptr, std::map<std::string, std::string>(), false, false, true, true,
- base::MakeUnique<net::BoundTestNetLog>());
- NetworkQualityObserverImpl impl(&estimator);
+ estimator()->SetSuppressNotificationsForTesting(true);
net::nqe::internal::NetworkQuality network_quality_1(
base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
- estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_1);
EXPECT_TRUE(embedded_test_server()->Start());
@@ -212,11 +199,11 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
// Changing the effective connection type from 2G to 3G is guaranteed to
// generate the notification to the renderers, irrespective of the current
// effective connection type.
- estimator.NotifyObserversOfEffectiveConnectionType(
+ estimator()->NotifyObserversOfEffectiveConnectionType(
net::EFFECTIVE_CONNECTION_TYPE_2G);
base::RunLoop().RunUntilIdle();
EXPECT_EQ("2g", RunScriptExtractString("getEffectiveType()"));
- estimator.NotifyObserversOfEffectiveConnectionType(
+ estimator()->NotifyObserversOfEffectiveConnectionType(
net::EFFECTIVE_CONNECTION_TYPE_3G);
base::RunLoop().RunUntilIdle();
EXPECT_EQ("3g", RunScriptExtractString("getEffectiveType()"));
@@ -230,14 +217,11 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest,
// 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(
- nullptr, std::map<std::string, std::string>(), false, false, true, true,
- base::MakeUnique<net::BoundTestNetLog>());
- NetworkQualityObserverImpl impl(&estimator);
+ estimator()->SetSuppressNotificationsForTesting(true);
net::nqe::internal::NetworkQuality network_quality_1(
base::TimeDelta::FromSeconds(1), base::TimeDelta::FromSeconds(2), 300);
- estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_1);
EXPECT_TRUE(embedded_test_server()->Start());
@@ -258,7 +242,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
// 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(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_2);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(network_quality_2.transport_rtt().InMilliseconds(),
@@ -273,17 +257,13 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotified) {
// 25 milliseconds or 25 kbps.
IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
base::HistogramTester histogram_tester;
- net::TestNetworkQualityEstimator estimator(
- std::unique_ptr<net::ExternalEstimateProvider>(),
- std::map<std::string, std::string>(), false, false, true, true,
- base::MakeUnique<net::BoundTestNetLog>());
- NetworkQualityObserverImpl impl(&estimator);
+ estimator()->SetSuppressNotificationsForTesting(true);
// Verify that the network quality is rounded properly.
net::nqe::internal::NetworkQuality network_quality_1(
base::TimeDelta::FromMilliseconds(123),
base::TimeDelta::FromMilliseconds(212), 303);
- estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_1);
EXPECT_TRUE(embedded_test_server()->Start());
@@ -295,7 +275,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
net::nqe::internal::NetworkQuality network_quality_2(
base::TimeDelta::FromMilliseconds(123),
base::TimeDelta::FromMilliseconds(1217), 1317);
- estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_2);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1225, RunScriptExtractDouble("getRtt()"));
@@ -304,7 +284,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
net::nqe::internal::NetworkQuality network_quality_3(
base::TimeDelta::FromMilliseconds(12),
base::TimeDelta::FromMilliseconds(12), 12);
- estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_3);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(0, RunScriptExtractDouble("getRtt()"));
@@ -314,16 +294,13 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeRounded) {
// Make sure the minor changes (<10%) in the network quality are not notified.
IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
base::HistogramTester histogram_tester;
- net::TestNetworkQualityEstimator estimator(
- nullptr, std::map<std::string, std::string>(), false, false, true, true,
- base::MakeUnique<net::BoundTestNetLog>());
- NetworkQualityObserverImpl impl(&estimator);
+ estimator()->SetSuppressNotificationsForTesting(true);
// 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(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_1);
EXPECT_TRUE(embedded_test_server()->Start());
@@ -337,7 +314,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
net::nqe::internal::NetworkQuality network_quality_2(
base::TimeDelta::FromMilliseconds(1223),
base::TimeDelta::FromMilliseconds(1312), 1403);
- estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_2);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(1200, RunScriptExtractDouble("getRtt()"));
@@ -348,7 +325,7 @@ IN_PROC_BROWSER_TEST_F(NetInfoBrowserTest, NetworkQualityChangeNotNotified) {
net::nqe::internal::NetworkQuality network_quality_3(
base::TimeDelta::FromMilliseconds(1223),
base::TimeDelta::FromMilliseconds(2312), 1403);
- estimator.NotifyObserversOfRTTOrThroughputEstimatesComputed(
+ estimator()->NotifyObserversOfRTTOrThroughputEstimatesComputed(
network_quality_3);
base::RunLoop().RunUntilIdle();
EXPECT_EQ(2300, RunScriptExtractDouble("getRtt()"));
« no previous file with comments | « no previous file | net/nqe/network_quality_estimator_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698