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 2b55df8b84f40bfd407ec501e4412eb9bddc4ac6..51b671c8d066728680a9b291dc20f5ebfd3b8fb3 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 |
@@ -810,100 +810,96 @@ TEST_F(DataReductionProxyConfigTest, IsDataReductionProxyWithMutableConfig) { |
} |
} |
-TEST_F(DataReductionProxyConfigTest, LoFiOn) { |
+TEST_F(DataReductionProxyConfigTest, ShouldEnableLoFi) { |
bengr
2017/05/01 16:53:14
Would you mind breaking each one of these cases ou
|
const struct { |
- bool lofi_switch_enabled; |
+ const char* lofi_switch; |
const std::string lofi_field_trial_group_name; |
- bool network_prohibitively_slow; |
- bool expect_lofi_header; |
- int bucket_to_check_for_auto_lofi_uma; |
- int expect_bucket_count; |
+ bool has_cellular_connection; |
+ bool has_slow_connection; |
+ bool supports_fallback; |
+ bool expect_enabled; |
} tests[] = { |
{ |
- // The Lo-Fi switch is off and the user is not in the enabled field |
+ // No Lo-Fi switch is set and the user is not in an enabled field |
// trial group. Lo-Fi should not be used. |
- false, std::string(), false, false, 0, |
- 0, // not in enabled field trial, UMA is not recorded |
+ nullptr, std::string(), true, true, true, false, |
bengr
2017/05/01 16:53:14
#include <string>
|
}, |
{ |
- // The Lo-Fi switch is off and the user is not in enabled field trial |
- // group and the network quality is bad. Lo-Fi should not be used. |
- false, std::string(), true, false, 0, |
- 0, // not in enabled field trial, UMA is not recorded |
+ // Lo-Fi is disabled through command line switch is off and the user |
bengr
2017/05/01 16:53:14
I can't parse. Do you mean "switch being off?"
|
+ // is also in an enabled field trial group. Lo-Fi should not be used. |
+ switches::kDataReductionProxyLoFiValueDisabled, "Enabled", false, |
+ true, true, false, |
}, |
{ |
// Lo-Fi is enabled through command line switch. LoFi should be used. |
- true, std::string(), false, true, 0, |
- 0, // not in enabled field trial, UMA is not recorded |
+ switches::kDataReductionProxyLoFiValueAlwaysOn, std::string(), false, |
+ false, false, true, |
}, |
{ |
- // The user is in the enabled field trial group but the network |
- // quality is not bad. Lo-Fi should not be used. |
- false, "Enabled", false, false, |
- 0, // Lo-Fi request header is not used (state change: empty to empty) |
- 1, |
+ // Lo-Fi on cellular through command line switch with cellular |
+ // connection. LoFi should be used. |
+ switches::kDataReductionProxyLoFiValueCellularOnly, std::string(), |
+ true /* cell connection */, false, false, true, |
}, |
{ |
- // The user is in the enabled field trial group but the network |
- // quality is not bad. Lo-Fi should not be used. |
- false, "Enabled_Control", false, false, |
- 0, // Lo-Fi request header is not used (state change: empty to empty) |
- 1, |
+ // Lo-Fi on cellular through command line switch without cellular |
+ // connection. LoFi should not be used. |
+ switches::kDataReductionProxyLoFiValueCellularOnly, std::string(), |
+ false /* cell connection */, true, true, false, |
}, |
{ |
- // The user is in the enabled field trial group and the network |
- // quality is bad. Lo-Fi should be used. |
- false, "Enabled", true, true, |
- 1, // Lo-Fi request header is now used (state change: empty to low) |
- 1, |
+ // Experimental field trial group enabled. Lo-Fi should be used. |
+ nullptr, "Enabled", false, true /* slow connection */, false, true, |
}, |
{ |
- // The user is in the enabled field trial group and the network |
- // quality is bad. Lo-Fi should be used. |
- false, "Enabled_Control", true, true, |
- 3, // Lo-Fi request header is now used (state change: low to low) |
- 1, |
+ // Experimental field trial group enabled but not slow connection. |
+ nullptr, "Enabled", false, false /* slow connection */, false, false, |
}, |
{ |
- // The user is in the enabled field trial group and the network |
- // quality is bad. Lo-Fi should be used again. |
- false, "Enabled", true, true, |
- 3, // Lo-Fi request header is now used (state change: low to low) |
- 1, |
+ // Control field trial group enabled. Lo-Fi should not be used. |
+ nullptr, "Control", false, true, false, false, |
}, |
{ |
- // The user is in the enabled field trial group and the network |
- // quality is bad. Lo-Fi should be used again. |
- false, "Enabled_Control", true, true, |
- 3, // Lo-Fi request header is now used (state change: low to low) |
- 1, |
+ // Lo-Fi is enabled through command line switch for slow connections |
+ // only. LoFi should be used for slow connection. |
+ switches::kDataReductionProxyLoFiValueSlowConnectionsOnly, |
+ std::string(), false, true /* slow connection */, false, true, |
}, |
{ |
- // The user is in the enabled field trial group but the network |
- // quality is not bad. Lo-Fi should not be used. |
- false, "Enabled", false, false, |
- 2, // Lo-Fi request header is not used (state change: low to empty) |
- 1, |
+ // Lo-Fi is enabled through command line switch for slow connections |
+ // only. LoFi should be not used for non-slow connection. |
+ switches::kDataReductionProxyLoFiValueSlowConnectionsOnly, |
+ std::string(), false, false /* slow connection */, false, false, |
}, |
{ |
- // The user is in the enabled field trial group but the network |
- // quality is not bad. Lo-Fi should not be used. |
- false, "Enabled_Control", false, false, |
- 0, // Lo-Fi request header is not used (state change: empty to empty) |
- 1, |
+ // LitePage fallback support enables Lo-Fi. LoFi should be used |
bengr
2017/05/01 16:53:14
Is it Lo-Fi or LoFi?
|
+ // for slow connection. |
+ nullptr, "Enabled_Preview" /* kLitePage */, true, |
+ true /* slow connection */, true, true, |
+ }, |
+ { |
+ // LitePage fallback support enables Lo-Fi. LoFi should be not used |
+ // for non-slow connection. |
+ nullptr, "Enabled_Preview" /* kLitePage */, true, |
+ false /* slow connection */, true, false, |
}, |
}; |
for (size_t i = 0; i < arraysize(tests); ++i) { |
+ base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
config()->ResetLoFiStatusForTest(); |
- if (tests[i].lofi_switch_enabled) { |
+ if (tests[i].lofi_switch) { |
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
- switches::kDataReductionProxyLoFi, |
- switches::kDataReductionProxyLoFiValueAlwaysOn); |
+ switches::kDataReductionProxyLoFi, tests[i].lofi_switch); |
} else { |
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
switches::kDataReductionProxyLoFi, std::string()); |
} |
+ config()->SetConnectionTypeForTesting( |
+ tests[i].has_cellular_connection |
+ ? net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G |
+ : net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); |
+ |
base::FieldTrialList field_trial_list(nullptr); |
if (!tests[i].lofi_field_trial_group_name.empty()) { |
base::FieldTrialList::CreateFieldTrial( |
@@ -911,356 +907,123 @@ TEST_F(DataReductionProxyConfigTest, LoFiOn) { |
tests[i].lofi_field_trial_group_name); |
} |
- EXPECT_CALL(*config(), IsNetworkQualityProhibitivelySlow(_)) |
- .WillRepeatedly(testing::Return(tests[i].network_prohibitively_slow)); |
+ config()->SetNetworkProhibitivelySlow(tests[i].has_slow_connection); |
+ |
+ if (tests[i].supports_fallback) { |
+ base::FieldTrialList::CreateFieldTrial( |
+ params::GetLitePageFallbackFieldTrialName(), "Enabled"); |
+ } |
- base::HistogramTester histogram_tester; |
net::TestURLRequestContext context_; |
net::TestDelegate delegate_; |
std::unique_ptr<net::URLRequest> request = context_.CreateRequest( |
GURL(), net::IDLE, &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
request->SetLoadFlags(request->load_flags() | |
net::LOAD_MAIN_FRAME_DEPRECATED); |
+ |
bool should_enable_lofi = config()->ShouldEnableLoFi(*request.get()); |
- if (tests[i].expect_bucket_count != 0) { |
- histogram_tester.ExpectBucketCount( |
- "DataReductionProxy.AutoLoFiRequestHeaderState.Unknown", |
- tests[i].bucket_to_check_for_auto_lofi_uma, |
- tests[i].expect_bucket_count); |
- } |
- EXPECT_EQ(tests[i].expect_lofi_header, should_enable_lofi) << i; |
+ EXPECT_EQ(tests[i].expect_enabled, should_enable_lofi) << i; |
} |
} |
-TEST_F(DataReductionProxyConfigTest, AutoLoFiParams) { |
- DataReductionProxyConfig config(task_runner(), nullptr, nullptr, |
- configurator(), event_creator()); |
- variations::testing::ClearAllVariationParams(); |
- std::map<std::string, std::string> variation_params; |
- std::map<std::string, std::string> variation_params_flag; |
- |
- variation_params["effective_connection_type"] = "Slow2G"; |
- variation_params_flag["effective_connection_type"] = "2G"; |
- |
- variation_params["hysteresis_period_seconds"] = "360"; |
- variation_params_flag["hysteresis_period_seconds"] = "361"; |
- |
- variation_params["spurious_field"] = "480"; |
- variation_params_flag["spurious_field"] = "481"; |
- |
- ASSERT_TRUE(variations::AssociateVariationParams( |
- params::GetLoFiFieldTrialName(), "Enabled", variation_params)); |
- |
- ASSERT_TRUE(variations::AssociateVariationParams( |
- params::GetLoFiFlagFieldTrialName(), "Enabled", variation_params_flag)); |
- |
- base::FieldTrialList field_trial_list(nullptr); |
- base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
- "Enabled"); |
- 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()); |
- |
+TEST_F(DataReductionProxyConfigTest, ShouldEnableLitePages) { |
bengr
2017/05/01 16:53:14
Likewise, please break out into separate tests.
|
const struct { |
- bool lofi_flag_group; |
- |
+ bool lite_page_switch; |
+ const char* lofi_switch; |
+ const std::string lite_page_field_trial_group_name; |
+ bool has_cellular_connection; |
+ bool expect_enabled; |
} tests[] = { |
{ |
- false, |
+ // No Lo-Fi switch is set and the user is not in an enabled field |
+ // trial group. Lo-Fi should not be used. |
+ true, nullptr, std::string(), false, false, |
}, |
{ |
- true, |
+ // Lo-Fi is disabled through command line switch is off and the user |
+ // is also in an enabled field trial group. Lo-Fi should not be used. |
+ false, switches::kDataReductionProxyLoFiValueDisabled, "Enabled", |
+ false, false, |
+ }, |
+ { |
+ // Lo-Fi is enabled through command line switch. LoFi should be used. |
+ true, switches::kDataReductionProxyLoFiValueAlwaysOn, std::string(), |
+ false, true, |
+ }, |
+ { |
+ // Lite Pages enabled with Lo-Fi enabled for cellular with cellular |
+ // connection. LoFi should be used. |
+ true, switches::kDataReductionProxyLoFiValueCellularOnly, |
+ std::string(), true, true, |
+ }, |
+ { |
+ // Lite Pages not enabled with Lo-Fi enabled for cellular with |
+ // cellular connection. LoFi should not be used. |
+ false, switches::kDataReductionProxyLoFiValueCellularOnly, |
+ std::string(), true, false, |
+ }, |
+ { |
+ // Lite Pages enabled with Lo-Fi enabled for cellular but no |
+ // cellular connection. LoFi should not be used. |
+ true, switches::kDataReductionProxyLoFiValueCellularOnly, |
+ std::string(), false, false, |
+ }, |
+ { |
+ // Experimental field trial group enabled for lite page. Lo-Fi should |
+ // be used. |
+ false, nullptr, "Enabled_Preview" /* kLitePage */, false, true, |
+ }, |
+ { |
+ // Control field trial group enabled. Lo-Fi should not be used. |
+ false, nullptr, "Control" /* kControl */, false, false, |
+ }, |
+ { |
+ // Lo-Fi is enabled through command line switch. LoFi |
+ // should be used. |
+ true, switches::kDataReductionProxyLoFiValueSlowConnectionsOnly, |
+ std::string(), false, true, |
}, |
}; |
- |
for (size_t i = 0; i < arraysize(tests); ++i) { |
- net::EffectiveConnectionType expected_effective_connection_type = |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; |
- int expected_hysteresis_sec = 360; |
- |
- if (tests[i].lofi_flag_group) { |
- // LoFi flag field trial has higher priority than LoFi field trial. |
+ base::CommandLine::ForCurrentProcess()->InitFromArgv(0, NULL); |
bengr
2017/05/01 16:53:14
You can put all of this stuff into a test helper.
|
+ config()->ResetLoFiStatusForTest(); |
+ if (tests[i].lofi_switch) { |
+ base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
+ switches::kDataReductionProxyLoFi, tests[i].lofi_switch); |
+ } else { |
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
- switches::kDataReductionProxyLoFi, |
- switches::kDataReductionProxyLoFiValueSlowConnectionsOnly); |
- expected_effective_connection_type = net::EFFECTIVE_CONNECTION_TYPE_2G; |
- expected_hysteresis_sec = 361; |
+ switches::kDataReductionProxyLoFi, std::string()); |
} |
- config.PopulateAutoLoFiParams(); |
- |
- EXPECT_EQ(expected_effective_connection_type, |
- config.lofi_effective_connection_type_threshold_); |
- EXPECT_EQ(base::TimeDelta::FromSeconds(expected_hysteresis_sec), |
- config.auto_lofi_hysteresis_); |
- |
- net::TestNetworkQualityEstimator test_network_quality_estimator; |
- |
- // Network is slow. |
- test_network_quality_estimator.set_effective_connection_type( |
- expected_effective_connection_type); |
- EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- |
- // Network quality improved. However, network should still be marked as slow |
- // because of hysteresis. |
- test_network_quality_estimator.set_effective_connection_type( |
- net::EFFECTIVE_CONNECTION_TYPE_4G); |
- EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- |
- // Change the last update time to be older than the hysteresis duration. |
- // Checking network quality afterwards should show that network is no longer |
- // slow. |
- config.network_quality_last_checked_ = |
- base::TimeTicks::Now() - |
- base::TimeDelta::FromSeconds(expected_hysteresis_sec + 1); |
- EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- |
- // Changing the network quality has no effect because of hysteresis. |
- test_network_quality_estimator.set_effective_connection_type( |
- expected_effective_connection_type); |
- EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- |
- // Change in connection type changes the network quality despite hysteresis. |
- 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)); |
- } |
-} |
- |
-// Tests that default parameters for Lo-Fi are used when the parameters from |
-// field trial are missing. |
-TEST_F(DataReductionProxyConfigTest, AutoLoFiMissingParams) { |
- DataReductionProxyConfig config(task_runner(), nullptr, nullptr, |
- configurator(), event_creator()); |
- variations::testing::ClearAllVariationParams(); |
- std::map<std::string, std::string> variation_params; |
- variation_params["spurious_field"] = "480"; |
- |
- ASSERT_TRUE(variations::AssociateVariationParams( |
- params::GetLoFiFieldTrialName(), "Enabled", variation_params)); |
- |
- base::FieldTrialList field_trial_list(nullptr); |
- base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
- "Enabled"); |
- |
- config.PopulateAutoLoFiParams(); |
- |
- EXPECT_EQ(net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
- config.lofi_effective_connection_type_threshold_); |
- EXPECT_EQ(base::TimeDelta::FromSeconds(60), config.auto_lofi_hysteresis_); |
-} |
- |
-TEST_F(DataReductionProxyConfigTest, AutoLoFiParamsSlowConnectionsFlag) { |
- DataReductionProxyConfig config(task_runner(), nullptr, nullptr, |
- configurator(), event_creator()); |
- variations::testing::ClearAllVariationParams(); |
- |
- 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(); |
- |
- net::EffectiveConnectionType expected_effective_connection_type = |
- net::EffectiveConnectionType::EFFECTIVE_CONNECTION_TYPE_SLOW_2G; |
- int hysteresis_sec = 60; |
- EXPECT_EQ(expected_effective_connection_type, |
- config.lofi_effective_connection_type_threshold_); |
- EXPECT_EQ(base::TimeDelta::FromSeconds(hysteresis_sec), |
- config.auto_lofi_hysteresis_); |
- |
- net::TestNetworkQualityEstimator test_network_quality_estimator; |
- |
- // Network is slow. |
- test_network_quality_estimator.set_effective_connection_type( |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
- EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- |
- // Network quality improved. However, network should still be marked as slow |
- // because of hysteresis. |
- test_network_quality_estimator.set_effective_connection_type( |
- net::EFFECTIVE_CONNECTION_TYPE_2G); |
- EXPECT_TRUE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- |
- // Change the last update time to be older than the hysteresis duration. |
- // Checking network quality afterwards should show that network is no longer |
- // slow. |
- config.network_quality_last_checked_ = |
- base::TimeTicks::Now() - base::TimeDelta::FromSeconds(hysteresis_sec + 1); |
- EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- |
- // Changing the network quality has no effect because of hysteresis. |
- test_network_quality_estimator.set_effective_connection_type( |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
- EXPECT_FALSE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- |
- // Change in connection type changes the network quality despite hysteresis. |
- 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)); |
-} |
- |
-// Tests if metrics for Lo-Fi accuracy are recorded properly. |
-TEST_F(DataReductionProxyConfigTest, LoFiAccuracy) { |
- std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
- new base::SimpleTestTickClock()); |
- |
- std::vector<base::TimeDelta> lofi_accuracy_recording_intervals; |
- lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(0)); |
- |
- TestDataReductionProxyConfig config( |
- 0, TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr, |
- configurator(), event_creator()); |
- config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals); |
- config.SetTickClock(tick_clock.get()); |
- |
- variations::testing::ClearAllVariationParams(); |
- std::map<std::string, std::string> variation_params; |
- |
- int expected_hysteresis_sec = 360; |
+ if (tests[i].lite_page_switch) { |
+ base::CommandLine::ForCurrentProcess()->AppendSwitch( |
+ switches::kEnableDataReductionProxyLitePage); |
+ } |
- variation_params["effective_connection_type"] = "Slow2G"; |
- variation_params["hysteresis_period_seconds"] = |
- base::IntToString(expected_hysteresis_sec); |
+ config()->SetConnectionTypeForTesting( |
+ tests[i].has_cellular_connection |
+ ? net::NetworkChangeNotifier::ConnectionType::CONNECTION_2G |
+ : net::NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI); |
- const struct { |
- std::string description; |
- std::string field_trial_group; |
- net::EffectiveConnectionType effective_connection_type; |
- net::EffectiveConnectionType recent_effective_connection_type; |
- bool expect_network_quality_slow; |
- uint32_t bucket_to_check; |
- uint32_t expected_bucket_count; |
- } tests[] = { |
- {"Predicted slow, actually slow, Enabled group", "Enabled", |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, true, 0, 1}, |
- {"Predicted slow, actually slow, Enabled_NoControl group", |
- "Enabled_NoControl", net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, true, 0, 1}, |
- {"Predicted slow, actually slow, Control group", "Control", |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, true, 0, 1}, |
- {"Predicted slow, actually not slow", "Enabled", |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, |
- net::EFFECTIVE_CONNECTION_TYPE_2G, true, 1, 1}, |
- {"Predicted not slow, actually slow", "Enabled", |
- net::EFFECTIVE_CONNECTION_TYPE_2G, |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G, false, 2, 1}, |
- {"Predicted not slow, actually not slow", "Enabled", |
- net::EFFECTIVE_CONNECTION_TYPE_2G, net::EFFECTIVE_CONNECTION_TYPE_2G, |
- false, 3, 1}, |
- }; |
- |
- for (const auto& test : tests) { |
base::FieldTrialList field_trial_list(nullptr); |
- variations::testing::ClearAllVariationIDs(); |
- variations::testing::ClearAllVariationParams(); |
- ASSERT_TRUE(variations::AssociateVariationParams( |
- params::GetLoFiFieldTrialName(), test.field_trial_group, |
- variation_params)) |
- << test.description; |
- |
- ASSERT_NE(nullptr, |
- base::FieldTrialList::CreateFieldTrial( |
- params::GetLoFiFieldTrialName(), test.field_trial_group)) |
- << test.description; |
- config.PopulateAutoLoFiParams(); |
+ if (!tests[i].lite_page_field_trial_group_name.empty()) { |
+ base::FieldTrialList::CreateFieldTrial( |
+ params::GetLoFiFieldTrialName(), |
+ tests[i].lite_page_field_trial_group_name); |
+ } |
- net::TestNetworkQualityEstimator test_network_quality_estimator; |
+ net::TestURLRequestContext context_; |
+ net::TestDelegate delegate_; |
+ std::unique_ptr<net::URLRequest> request = |
+ context_.CreateRequest(GURL(), net::IDLE, &delegate_); |
+ request->SetLoadFlags(request->load_flags() | |
+ net::LOAD_MAIN_FRAME_DEPRECATED); |
+ bool should_enable_lite_page = |
+ config()->ShouldEnableLitePages(*request.get()); |
- base::HistogramTester histogram_tester; |
- test_network_quality_estimator.set_effective_connection_type( |
- test.effective_connection_type); |
- test_network_quality_estimator.set_recent_effective_connection_type( |
- test.recent_effective_connection_type); |
- ASSERT_EQ(test.expect_network_quality_slow, |
- config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)) |
- << test.description; |
- RunUntilIdle(); |
- histogram_tester.ExpectTotalCount( |
- "DataReductionProxy.LoFi.Accuracy.0.Unknown", 1); |
- histogram_tester.ExpectBucketCount( |
- "DataReductionProxy.LoFi.Accuracy.0.Unknown", test.bucket_to_check, |
- test.expected_bucket_count); |
+ EXPECT_EQ(tests[i].expect_enabled, should_enable_lite_page) << i; |
} |
} |
-// Tests if metrics for Lo-Fi accuracy are recorded properly at the specified |
-// interval. |
-TEST_F(DataReductionProxyConfigTest, LoFiAccuracyNonZeroDelay) { |
- std::unique_ptr<base::SimpleTestTickClock> tick_clock( |
- new base::SimpleTestTickClock()); |
- |
- std::vector<base::TimeDelta> lofi_accuracy_recording_intervals; |
- lofi_accuracy_recording_intervals.push_back(base::TimeDelta::FromSeconds(1)); |
- |
- TestDataReductionProxyConfig config( |
- 0, TestDataReductionProxyParams::HAS_EVERYTHING, task_runner(), nullptr, |
- configurator(), event_creator()); |
- config.SetLofiAccuracyRecordingIntervals(lofi_accuracy_recording_intervals); |
- config.SetTickClock(tick_clock.get()); |
- |
- variations::testing::ClearAllVariationParams(); |
- std::map<std::string, std::string> variation_params; |
- |
- variation_params["effective_connection_type"] = "Slow2G"; |
- |
- ASSERT_TRUE(variations::AssociateVariationParams( |
- params::GetLoFiFieldTrialName(), "Enabled", variation_params)); |
- |
- base::FieldTrialList field_trial_list(nullptr); |
- base::FieldTrialList::CreateFieldTrial(params::GetLoFiFieldTrialName(), |
- "Enabled"); |
- config.PopulateAutoLoFiParams(); |
- |
- net::TestNetworkQualityEstimator test_network_quality_estimator; |
- |
- base::HistogramTester histogram_tester; |
- // Network was predicted to be slow and actually was slow. |
- test_network_quality_estimator.set_effective_connection_type( |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
- test_network_quality_estimator.set_recent_effective_connection_type( |
- net::EFFECTIVE_CONNECTION_TYPE_SLOW_2G); |
- ASSERT_TRUE(config.IsNetworkQualityProhibitivelySlow( |
- &test_network_quality_estimator)); |
- tick_clock->Advance(base::TimeDelta::FromSeconds(1)); |
- |
- // Sleep to ensure that the delayed task is posted. |
- base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(1)); |
- RunUntilIdle(); |
- histogram_tester.ExpectTotalCount( |
- "DataReductionProxy.LoFi.Accuracy.1.Unknown", 1); |
- histogram_tester.ExpectBucketCount( |
- "DataReductionProxy.LoFi.Accuracy.1.Unknown", 0, 1); |
-} |
- |
} // namespace data_reduction_proxy |