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

Unified Diff: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc

Issue 2700203002: DRP: Do not fetch warm up URL on offline connections (Closed)
Patch Set: Created 3 years, 10 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 | « components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
index 413648371b027df5784ed74032b7e72ce1023fd0..585bf4ae4057a10174368700b4c641e7da165a2e 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_config_unittest.cc
@@ -87,6 +87,7 @@ class DataReductionProxyConfigTest : public testing::Test {
void SetUp() override {
net::NetworkChangeNotifier::SetTestNotificationsOnly(true);
+ base::RunLoop().RunUntilIdle();
network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock());
test_context_ = DataReductionProxyTestContext::Builder()
@@ -377,6 +378,10 @@ TEST_F(DataReductionProxyConfigTest, WarmupURL) {
config.SetWarmupURLFetcherCallbackForTesting(
base::Bind(&DataReductionProxyConfigTest::WarmupURLFetchedCallBack,
base::Unretained(this)));
+
+ // Set the connection type to WiFi so that warm up URL is fetched even if
+ // the test device does not have connectivity.
+ config.connection_type_ = net::NetworkChangeNotifier::CONNECTION_WIFI;
config.SetProxyConfig(test.data_reduction_proxy_enabled, true);
bool warmup_url_enabled =
test.data_reduction_proxy_enabled && test.enabled_via_field_trial;
@@ -390,7 +395,11 @@ TEST_F(DataReductionProxyConfigTest, WarmupURL) {
"DataReductionProxy.WarmupURL.FetchSuccessful", 1, 1);
}
- config.OnIPAddressChanged();
+ // Set the connection type to 4G so that warm up URL is fetched even if
+ // the test device does not have connectivity.
+ net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
+ net::NetworkChangeNotifier::CONNECTION_4G);
+ RunUntilIdle();
if (warmup_url_enabled) {
// Block until warm up URL is fetched successfully.
@@ -405,6 +414,24 @@ TEST_F(DataReductionProxyConfigTest, WarmupURL) {
histogram_tester.ExpectTotalCount(
"DataReductionProxy.WarmupURL.FetchSuccessful", 0);
}
+
+ // Warm up URL should not be fetched since the device does not have
+ // connectivity.
+ net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
+ net::NetworkChangeNotifier::CONNECTION_NONE);
+ RunUntilIdle();
+
+ if (warmup_url_enabled) {
+ histogram_tester.ExpectUniqueSample(
+ "DataReductionProxy.WarmupURL.FetchInitiated", 1, 2);
+ histogram_tester.ExpectUniqueSample(
+ "DataReductionProxy.WarmupURL.FetchSuccessful", 1, 2);
+ } else {
+ histogram_tester.ExpectTotalCount(
+ "DataReductionProxy.WarmupURL.FetchInitiated", 0);
+ histogram_tester.ExpectTotalCount(
+ "DataReductionProxy.WarmupURL.FetchSuccessful", 0);
+ }
}
}
@@ -958,6 +985,11 @@ TEST_F(DataReductionProxyConfigTest, AutoLoFiParams) {
base::FieldTrialList::CreateFieldTrial(params::GetLoFiFlagFieldTrialName(),
"Enabled");
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter =
+ new net::TestURLRequestContextGetter(task_runner());
+ config.InitializeOnIOThread(request_context_getter.get(),
+ request_context_getter.get());
+
const struct {
bool lofi_flag_group;
@@ -1022,7 +1054,12 @@ TEST_F(DataReductionProxyConfigTest, AutoLoFiParams) {
&test_network_quality_estimator));
// Change in connection type changes the network quality despite hysteresis.
- config.connection_type_ = net::NetworkChangeNotifier::CONNECTION_WIFI;
+ EXPECT_FALSE(config.connection_type_changed_);
+ net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
+ net::NetworkChangeNotifier::CONNECTION_WIFI);
+ RunUntilIdle();
+
+ EXPECT_TRUE(config.connection_type_changed_);
EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
&test_network_quality_estimator));
}
@@ -1059,6 +1096,10 @@ TEST_F(DataReductionProxyConfigTest, AutoLoFiParamsSlowConnectionsFlag) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
switches::kDataReductionProxyLoFi,
switches::kDataReductionProxyLoFiValueSlowConnectionsOnly);
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter =
+ new net::TestURLRequestContextGetter(task_runner());
+ config.InitializeOnIOThread(request_context_getter.get(),
+ request_context_getter.get());
config.PopulateAutoLoFiParams();
@@ -1100,7 +1141,12 @@ TEST_F(DataReductionProxyConfigTest, AutoLoFiParamsSlowConnectionsFlag) {
&test_network_quality_estimator));
// Change in connection type changes the network quality despite hysteresis.
- config.connection_type_ = net::NetworkChangeNotifier::CONNECTION_WIFI;
+ EXPECT_FALSE(config.connection_type_changed_);
+ net::NetworkChangeNotifier::NotifyObserversOfConnectionTypeChangeForTests(
+ net::NetworkChangeNotifier::CONNECTION_WIFI);
+ RunUntilIdle();
+
+ EXPECT_TRUE(config.connection_type_changed_);
EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow(
&test_network_quality_estimator));
}
« no previous file with comments | « components/data_reduction_proxy/core/browser/data_reduction_proxy_config.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698