Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / components / data_reduction_proxy / browser / data_reduction_proxy_settings_test_utils.cc
index 62a5d4b..7cf609a 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "components/data_reduction_proxy/browser/data_reduction_proxy_settings_test_utils.h"
 
+#include "base/bind.h"
 #include "base/command_line.h"
 #include "base/message_loop/message_loop.h"
 #include "base/prefs/pref_registry_simple.h"
@@ -18,10 +19,6 @@ using testing::Return;
 
 namespace {
 
-const char kDataReductionProxy[] = "https://foo.com:443/";
-const char kDataReductionProxyFallback[] = "http://bar.com:80/";
-const char kDataReductionProxyKey[] = "12345";
-
 const char kProbeURLWithOKResponse[] = "http://ok.org/";
 const char kWarmupURLWithNoContentResponse[] = "http://warm.org/";
 
@@ -78,28 +75,12 @@ void TestDataReductionProxyConfig::Disable() {
   ssl_origin_ = "";
 }
 
-// static
-void DataReductionProxySettingsTestBase::AddTestProxyToCommandLine() {
-  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
-      switches::kDataReductionProxy, kDataReductionProxy);
-  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
-      switches::kDataReductionProxyFallback, kDataReductionProxyFallback);
-  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
-      switches::kDataReductionProxyKey, kDataReductionProxyKey);
-  CommandLine::ForCurrentProcess()->AppendSwitchASCII(
-      switches::kDataReductionProxyProbeURL, kProbeURLWithOKResponse);
-}
-
 DataReductionProxySettingsTestBase::DataReductionProxySettingsTestBase()
     : testing::Test() {
 }
 
 DataReductionProxySettingsTestBase::~DataReductionProxySettingsTestBase() {}
 
-void DataReductionProxySettingsTestBase::AddProxyToCommandLine() {
-  AddTestProxyToCommandLine();
-}
-
 // testing::Test implementation:
 void DataReductionProxySettingsTestBase::SetUp() {
   PrefRegistrySimple* registry = pref_service_.registry();
@@ -112,8 +93,8 @@ void DataReductionProxySettingsTestBase::SetUp() {
   registry->RegisterBooleanPref(prefs::kDataReductionProxyAltEnabled, false);
   registry->RegisterBooleanPref(prefs::kDataReductionProxyWasEnabledBefore,
                                 false);
-  AddProxyToCommandLine();
-  ResetSettings(true, true, false, true);
+  //AddProxyToCommandLine();
+  ResetSettings(true, true, false, true, false);
 
   ListPrefUpdate original_update(&pref_service_,
                                  prefs::kDailyHttpOriginalContentLength);
@@ -128,13 +109,20 @@ void DataReductionProxySettingsTestBase::SetUp() {
   pref_service_.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));
 }
 
 template <class C>
 void DataReductionProxySettingsTestBase::ResetSettings(bool allowed,
                                                        bool fallback_allowed,
                                                        bool alt_allowed,
-                                                       bool promo_allowed) {
+                                                       bool promo_allowed,
+                                                       bool holdback) {
   int flags = 0;
   if (allowed)
     flags |= DataReductionProxyParams::kAllowed;
@@ -144,6 +132,8 @@ void DataReductionProxySettingsTestBase::ResetSettings(bool allowed,
     flags |= DataReductionProxyParams::kAlternativeAllowed;
   if (promo_allowed)
     flags |= DataReductionProxyParams::kPromoAllowed;
+  if (holdback)
+    flags |= DataReductionProxyParams::kHoldback;
   MockDataReductionProxySettings<C>* settings =
       new MockDataReductionProxySettings<C>(flags);
   EXPECT_CALL(*settings, GetOriginalProfilePrefs())
@@ -156,13 +146,18 @@ void DataReductionProxySettingsTestBase::ResetSettings(bool allowed,
   EXPECT_CALL(*settings, GetURLFetcherForWarmup()).Times(0);
   EXPECT_CALL(*settings, LogProxyState(_, _, _)).Times(0);
   settings_.reset(settings);
-  settings_->configurator_.reset(new TestDataReductionProxyConfig());
+  configurator_.reset(new TestDataReductionProxyConfig());
+  settings_->configurator_ = configurator_.get();
 }
 
 // Explicitly generate required instantiations.
 template void
 DataReductionProxySettingsTestBase::ResetSettings<DataReductionProxySettings>(
-    bool allowed, bool fallback_allowed, bool alt_allowed, bool promo_allowed);
+    bool allowed,
+    bool fallback_allowed,
+    bool alt_allowed,
+    bool promo_allowed,
+    bool holdback);
 
 template <class C>
 void DataReductionProxySettingsTestBase::SetProbeResult(
@@ -216,8 +211,7 @@ void DataReductionProxySettingsTestBase::CheckProxyConfigs(
     bool expected_restricted,
     bool expected_fallback_restricted) {
   TestDataReductionProxyConfig* config =
-      static_cast<TestDataReductionProxyConfig*>(
-          settings_->configurator_.get());
+      static_cast<TestDataReductionProxyConfig*>(settings_->configurator_);
   ASSERT_EQ(expected_restricted, config->restricted_);
   ASSERT_EQ(expected_fallback_restricted, config->fallback_restricted_);
   ASSERT_EQ(expected_enabled, config->enabled_);
@@ -283,7 +277,7 @@ void DataReductionProxySettingsTestBase::CheckOnPrefChange(
                  expected_enabled ? 1 : 0);
   if (managed) {
     pref_service_.SetManagedPref(prefs::kDataReductionProxyEnabled,
-                                 base::Value::CreateBooleanValue(enabled));
+                                 new base::FundamentalValue(enabled));
   } else {
     pref_service_.SetBoolean(prefs::kDataReductionProxyEnabled, enabled);
   }
@@ -303,15 +297,22 @@ void DataReductionProxySettingsTestBase::CheckInitDataReductionProxy(
                  enabled_at_startup ? 1 : 0);
   scoped_ptr<DataReductionProxyConfigurator> configurator(
       new TestDataReductionProxyConfig());
-  settings_->SetProxyConfigurator(configurator.Pass());
+  settings_->SetProxyConfigurator(configurator.get());
   scoped_refptr<net::TestURLRequestContextGetter> request_context =
       new net::TestURLRequestContextGetter(base::MessageLoopProxy::current());
-  settings_->InitDataReductionProxySettings(&pref_service_,
-                                            &pref_service_,
-                                            request_context.get());
+
+  settings_->InitDataReductionProxySettings(
+      &pref_service_,
+      &pref_service_,
+      request_context.get());
+  settings_->SetOnDataReductionEnabledCallback(
+      base::Bind(&DataReductionProxySettingsTestBase::
+                 RegisterSyntheticFieldTrialCallback,
+                 base::Unretained(this)));
 
   base::MessageLoop::current()->RunUntilIdle();
   CheckProxyConfigs(enabled_at_startup, false, false);
+  EXPECT_EQ(enabled_at_startup, proxy_enabled_);
 }
 
 }  // namespace data_reduction_proxy