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

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

Issue 893003002: Data Reduction Proxy class ownership updates and Settings cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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: components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
diff --git a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
index 053b0bcde26d9b861fc3f4e7fd025b37dc17c6ab..ef01e0014648c3e6410d0f9b77e202812855f695 100644
--- a/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
+++ b/components/data_reduction_proxy/core/browser/data_reduction_proxy_settings_test_utils.cc
@@ -12,6 +12,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/test/test_simple_task_runner.h"
#include "base/time/time.h"
+#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_config_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_configurator_test_utils.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_prefs.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_statistics_prefs.h"
@@ -26,29 +27,12 @@ using testing::Return;
namespace {
-const char kProbeURLWithOKResponse[] = "http://ok.org/";
-
const char kProxy[] = "proxy";
} // namespace
namespace data_reduction_proxy {
-namespace {
-
-ProbeURLFetchResult FetchResult(bool enabled, bool success) {
- if (enabled) {
- if (success)
- return SUCCEEDED_PROXY_ALREADY_ENABLED;
- return FAILED_PROXY_DISABLED;
- }
- if (success)
- return SUCCEEDED_PROXY_ENABLED;
- return FAILED_PROXY_ALREADY_DISABLED;
-}
-
-} // namespace
-
DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase()
: testing::Test() {
}
@@ -76,6 +60,16 @@ void DataReductionProxySettingsTestBase::SetUp() {
event_store_.reset(new DataReductionProxyEventStore(
scoped_refptr<base::TestSimpleTaskRunner>(
new base::TestSimpleTaskRunner())));
+ configurator_.reset(new TestDataReductionProxyConfigurator(
+ scoped_refptr<base::TestSimpleTaskRunner>(
+ new base::TestSimpleTaskRunner()),
+ &net_log_, event_store_.get()));
+ config_.reset(new MockDataReductionProxyConfig(
+ scoped_refptr<base::TestSimpleTaskRunner>(
+ new base::TestSimpleTaskRunner()),
+ &net_log_,
+ configurator_.get(),
+ event_store_.get()));
//AddProxyToCommandLine();
ResetSettings(true, true, false, true, false);
@@ -93,13 +87,6 @@ void DataReductionProxySettingsTestBase::SetUp() {
statistics_prefs_->SetInt64(
prefs::kDailyHttpContentLengthLastUpdateDate,
last_update_time_.ToInternalValue());
- expected_params_.reset(new TestDataReductionProxyParams(
- DataReductionProxyParams::kAllowed |
- DataReductionProxyParams::kFallbackAllowed |
- DataReductionProxyParams::kPromoAllowed,
- TestDataReductionProxyParams::HAS_EVERYTHING &
- ~TestDataReductionProxyParams::HAS_DEV_ORIGIN &
- ~TestDataReductionProxyParams::HAS_DEV_FALLBACK_ORIGIN));
}
template <class C>
@@ -120,20 +107,19 @@ void DataReductionProxySettingsTestBase::ResetSettings(bool allowed,
if (holdback)
flags |= DataReductionProxyParams::kHoldback;
MockDataReductionProxySettings<C>* settings =
- new MockDataReductionProxySettings<C>(flags);
+ new MockDataReductionProxySettings<C>();
+ MockDataReductionProxyConfig* config =
+ static_cast<MockDataReductionProxyConfig*>(config_.get());
+ settings->config_ = config;
+ config->ResetParamsForTest(flags);
+ settings->UpdateConfigValues();
EXPECT_CALL(*settings, GetOriginalProfilePrefs())
.Times(AnyNumber())
.WillRepeatedly(Return(&pref_service_));
EXPECT_CALL(*settings, GetLocalStatePrefs())
.Times(AnyNumber())
.WillRepeatedly(Return(&pref_service_));
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
- EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
settings_.reset(settings);
- configurator_.reset(new TestDataReductionProxyConfigurator(
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner()), &net_log_, event_store_.get()));
- settings_->configurator_ = configurator_.get();
settings_->SetDataReductionProxyStatisticsPrefs(statistics_prefs_.get());
}
@@ -146,106 +132,20 @@ DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(
bool promo_allowed,
bool holdback);
-template <class C>
-void DataReductionProxySettingsTestBase::SetProbeResult(
- const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult result,
- bool success,
- int expected_calls) {
- MockDataReductionProxySettings<C>* settings =
- static_cast<MockDataReductionProxySettings<C>*>(settings_.get());
- if (0 == expected_calls) {
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck()).Times(0);
- EXPECT_CALL(*settings, RecordProbeURLFetchResult(_)).Times(0);
- } else {
- EXPECT_CALL(*settings, RecordProbeURLFetchResult(result)).Times(1);
- EXPECT_CALL(*settings, GetURLFetcherForAvailabilityCheck())
- .Times(expected_calls)
- .WillRepeatedly(Return(new net::FakeURLFetcher(
- GURL(test_url),
- settings,
- response,
- success ? net::HTTP_OK : net::HTTP_INTERNAL_SERVER_ERROR,
- success ? net::URLRequestStatus::SUCCESS :
- net::URLRequestStatus::FAILED)));
- }
-}
-
-// Explicitly generate required instantiations.
-template void
-DataReductionProxySettingsTestBase::SetProbeResult<DataReductionProxySettings>(
- const std::string& test_url,
- const std::string& response,
- ProbeURLFetchResult result,
- bool success,
- int expected_calls);
-
-void DataReductionProxySettingsTestBase::CheckProxyConfigs(
- bool expected_enabled,
- bool expected_restricted,
- bool expected_fallback_restricted) {
- TestDataReductionProxyConfigurator* config =
- static_cast<TestDataReductionProxyConfigurator*>(
- settings_->configurator_);
- ASSERT_EQ(expected_restricted, config->restricted());
- ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted());
- ASSERT_EQ(expected_enabled, config->enabled());
-}
-
-void DataReductionProxySettingsTestBase::CheckProbe(
- bool initially_enabled,
- const std::string& probe_url,
- const std::string& response,
- bool request_succeeded,
+void DataReductionProxySettingsTestBase::ExpectSetProxyPrefs(
bool expected_enabled,
- bool expected_restricted,
- bool expected_fallback_restricted) {
- pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled,
- initially_enabled);
- if (initially_enabled)
- settings_->enabled_by_user_ = true;
- settings_->restricted_by_carrier_ = false;
- SetProbeResult(probe_url,
- response,
- FetchResult(initially_enabled,
- request_succeeded && (response == "OK")),
- request_succeeded,
- initially_enabled ? 1 : 0);
- settings_->MaybeActivateDataReductionProxy(false);
- base::MessageLoop::current()->RunUntilIdle();
- CheckProxyConfigs(expected_enabled,
- expected_restricted,
- expected_fallback_restricted);
-}
-
-void DataReductionProxySettingsTestBase::CheckProbeOnIPChange(
- const std::string& probe_url,
- const std::string& response,
- bool request_succeeded,
- bool expected_restricted,
- bool expected_fallback_restricted) {
- SetProbeResult(probe_url,
- response,
- FetchResult(!settings_->restricted_by_carrier_,
- request_succeeded && (response == "OK")),
- request_succeeded,
- 1);
- settings_->OnIPAddressChanged();
- base::MessageLoop::current()->RunUntilIdle();
- CheckProxyConfigs(true, expected_restricted, expected_fallback_restricted);
+ bool expected_alternate_enabled,
+ bool expected_at_startup) {
+ MockDataReductionProxyConfig* config = config_.get();
+ EXPECT_CALL(*config, SetProxyPrefs(
+ expected_enabled, expected_alternate_enabled, expected_at_startup));
}
void DataReductionProxySettingsTestBase::CheckOnPrefChange(
bool enabled,
bool expected_enabled,
bool managed) {
- // Always have a sucessful probe for pref change tests.
- SetProbeResult(kProbeURLWithOKResponse,
- "OK",
- FetchResult(enabled, true),
- true,
- expected_enabled ? 1 : 0);
+ ExpectSetProxyPrefs(expected_enabled, false, false);
if (managed) {
pref_service_.SetManagedPref(prefs::kDataReductionProxyEnabled,
new base::FundamentalValue(enabled));
@@ -254,26 +154,13 @@ void DataReductionProxySettingsTestBase::CheckOnPrefChange(
}
base::MessageLoop::current()->RunUntilIdle();
// Never expect the proxy to be restricted for pref change tests.
- CheckProxyConfigs(expected_enabled, false, false);
}
void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
bool enabled_at_startup) {
base::MessageLoopForUI loop;
- scoped_ptr<DataReductionProxyConfigurator> configurator(
- new TestDataReductionProxyConfigurator(
- scoped_refptr<base::TestSimpleTaskRunner>(
- new base::TestSimpleTaskRunner()), &net_log_,
- event_store_.get()));
- settings_->SetProxyConfigurator(configurator.get());
- scoped_refptr<net::TestURLRequestContextGetter> request_context =
- new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
-
- settings_->InitDataReductionProxySettings(
- &pref_service_,
- request_context.get(),
- &net_log_,
- event_store_.get());
+ settings_->InitDataReductionProxySettings(&pref_service_, config_.get(),
+ event_store_.get());
settings_->SetOnDataReductionEnabledCallback(
base::Bind(&DataReductionProxySettingsTestBase::
RegisterSyntheticFieldTrialCallback,

Powered by Google App Engine
This is Rietveld 408576698