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

Unified Diff: chrome/browser/prefs/pref_service_unittest.cc

Issue 7096013: Allow device policy code to be optionally included. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make changes requested by torne. Created 9 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 | « chrome/browser/prefs/pref_service_mock_builder.cc ('k') | chrome/browser/prefs/proxy_policy_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/prefs/pref_service_unittest.cc
diff --git a/chrome/browser/prefs/pref_service_unittest.cc b/chrome/browser/prefs/pref_service_unittest.cc
index 496e9de1560ba24983ee147af602d09552372e96..cf6d0edde2727b5eb624bed17a78a2e22a6ddc05 100644
--- a/chrome/browser/prefs/pref_service_unittest.cc
+++ b/chrome/browser/prefs/pref_service_unittest.cc
@@ -16,7 +16,6 @@
#include "chrome/browser/prefs/pref_observer_mock.h"
#include "chrome/browser/prefs/pref_service_mock_builder.h"
#include "chrome/browser/prefs/pref_value_store.h"
-#include "chrome/browser/prefs/proxy_config_dictionary.h"
#include "chrome/browser/prefs/testing_pref_store.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
@@ -169,186 +168,6 @@ TEST(PrefServiceTest, GetValueChangedType) {
EXPECT_EQ(kTestValue, actual_int_value);
}
-void assertProxyMode(const ProxyConfigDictionary& dict,
- ProxyPrefs::ProxyMode expected_mode) {
- ProxyPrefs::ProxyMode actual_mode;
- ASSERT_TRUE(dict.GetMode(&actual_mode));
- EXPECT_EQ(expected_mode, actual_mode);
-}
-
-void assertProxyServer(const ProxyConfigDictionary& dict,
- const std::string& expected) {
- std::string actual;
- if (!expected.empty()) {
- ASSERT_TRUE(dict.GetProxyServer(&actual));
- EXPECT_EQ(expected, actual);
- } else {
- EXPECT_FALSE(dict.GetProxyServer(&actual));
- }
-}
-
-void assertPacUrl(const ProxyConfigDictionary& dict,
- const std::string& expected) {
- std::string actual;
- if (!expected.empty()) {
- ASSERT_TRUE(dict.GetPacUrl(&actual));
- EXPECT_EQ(expected, actual);
- } else {
- EXPECT_FALSE(dict.GetPacUrl(&actual));
- }
-}
-
-void assertBypassList(const ProxyConfigDictionary& dict,
- const std::string& expected) {
- std::string actual;
- if (!expected.empty()) {
- ASSERT_TRUE(dict.GetBypassList(&actual));
- EXPECT_EQ(expected, actual);
- } else {
- EXPECT_FALSE(dict.GetBypassList(&actual));
- }
-}
-
-void assertProxyModeWithoutParams(const ProxyConfigDictionary& dict,
- ProxyPrefs::ProxyMode proxy_mode) {
- assertProxyMode(dict, proxy_mode);
- assertProxyServer(dict, "");
- assertPacUrl(dict, "");
- assertBypassList(dict, "");
-}
-
-TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineOptions) {
- CommandLine command_line(CommandLine::NO_PROGRAM);
- command_line.AppendSwitchASCII(switches::kProxyBypassList, "123");
- command_line.AppendSwitchASCII(switches::kProxyServer, "789");
- scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
- new policy::MockConfigurationPolicyProvider());
- Value* mode_name = Value::CreateStringValue(
- ProxyPrefs::kFixedServersProxyModeName);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
- provider->AddPolicy(policy::kPolicyProxyBypassList,
- Value::CreateStringValue("abc"));
- provider->AddPolicy(policy::kPolicyProxyServer,
- Value::CreateStringValue("ghi"));
-
- // First verify that command-line options are set correctly when
- // there is no policy in effect.
- PrefServiceMockBuilder builder;
- builder.WithCommandLine(&command_line);
- scoped_ptr<PrefService> prefs(builder.Create());
- browser::RegisterUserPrefs(prefs.get());
- ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
- assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
- assertProxyServer(dict, "789");
- assertPacUrl(dict, "");
- assertBypassList(dict, "123");
-
- // Try a second time time with the managed PrefStore in place, the
- // manual proxy policy should have removed all traces of the command
- // line and replaced them with the policy versions.
- builder.WithCommandLine(&command_line);
- builder.WithManagedPlatformProvider(provider.get());
- scoped_ptr<PrefService> prefs2(builder.Create());
- browser::RegisterUserPrefs(prefs2.get());
- ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
- assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS);
- assertProxyServer(dict2, "ghi");
- assertPacUrl(dict2, "");
- assertBypassList(dict2, "abc");
-}
-
-TEST(PrefServiceTest, ProxyPolicyOverridesUnrelatedCommandLineOptions) {
- CommandLine command_line(CommandLine::NO_PROGRAM);
- command_line.AppendSwitchASCII(switches::kProxyBypassList, "123");
- command_line.AppendSwitchASCII(switches::kProxyServer, "789");
- scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
- new policy::MockConfigurationPolicyProvider());
- Value* mode_name = Value::CreateStringValue(
- ProxyPrefs::kAutoDetectProxyModeName);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
-
- // First verify that command-line options are set correctly when
- // there is no policy in effect.
- PrefServiceMockBuilder builder;
- builder.WithCommandLine(&command_line);
- scoped_ptr<PrefService> prefs(builder.Create());
- browser::RegisterUserPrefs(prefs.get());
- ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
- assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
- assertProxyServer(dict, "789");
- assertPacUrl(dict, "");
- assertBypassList(dict, "123");
-
- // Try a second time time with the managed PrefStore in place, the
- // no proxy policy should have removed all traces of the command
- // line proxy settings, even though they were not the specific one
- // set in policy.
- builder.WithCommandLine(&command_line);
- builder.WithManagedPlatformProvider(provider.get());
- scoped_ptr<PrefService> prefs2(builder.Create());
- browser::RegisterUserPrefs(prefs2.get());
- ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
- assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
-}
-
-TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineNoProxy) {
- CommandLine command_line(CommandLine::NO_PROGRAM);
- command_line.AppendSwitch(switches::kNoProxyServer);
- scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
- new policy::MockConfigurationPolicyProvider());
- Value* mode_name = Value::CreateStringValue(
- ProxyPrefs::kAutoDetectProxyModeName);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
-
- // First verify that command-line options are set correctly when
- // there is no policy in effect.
- PrefServiceMockBuilder builder;
- builder.WithCommandLine(&command_line);
- scoped_ptr<PrefService> prefs(builder.Create());
- browser::RegisterUserPrefs(prefs.get());
- ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
- assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
-
- // Try a second time time with the managed PrefStore in place, the
- // auto-detect should be overridden. The default pref store must be
- // in place with the appropriate default value for this to work.
- builder.WithCommandLine(&command_line);
- builder.WithManagedPlatformProvider(provider.get());
- scoped_ptr<PrefService> prefs2(builder.Create());
- browser::RegisterUserPrefs(prefs2.get());
- ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
- assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
-}
-
-TEST(PrefServiceTest, ProxyPolicyOverridesCommandLineAutoDetect) {
- CommandLine command_line(CommandLine::NO_PROGRAM);
- command_line.AppendSwitch(switches::kProxyAutoDetect);
- scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
- new policy::MockConfigurationPolicyProvider());
- Value* mode_name = Value::CreateStringValue(
- ProxyPrefs::kDirectProxyModeName);
- provider->AddPolicy(policy::kPolicyProxyMode, mode_name);
-
- // First verify that the auto-detect is set if there is no managed
- // PrefStore.
- PrefServiceMockBuilder builder;
- builder.WithCommandLine(&command_line);
- scoped_ptr<PrefService> prefs(builder.Create());
- browser::RegisterUserPrefs(prefs.get());
- ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
- assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
-
- // Try a second time time with the managed PrefStore in place, the
- // auto-detect should be overridden. The default pref store must be
- // in place with the appropriate default value for this to work.
- builder.WithCommandLine(&command_line);
- builder.WithManagedPlatformProvider(provider.get());
- scoped_ptr<PrefService> prefs2(builder.Create());
- browser::RegisterUserPrefs(prefs2.get());
- ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
- assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
-}
-
class PrefServiceSetValueTest : public testing::Test {
protected:
static const char kName[];
« no previous file with comments | « chrome/browser/prefs/pref_service_mock_builder.cc ('k') | chrome/browser/prefs/proxy_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698