| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "chrome/browser/policy/mock_configuration_policy_provider.h" | 6 #include "chrome/browser/policy/mock_configuration_policy_provider.h" |
| 7 #include "chrome/browser/prefs/browser_prefs.h" | 7 #include "chrome/browser/prefs/browser_prefs.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/prefs/pref_service_mock_builder.h" | 9 #include "chrome/browser/prefs/pref_service_mock_builder.h" |
| 10 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 10 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 assertPacUrl(dict, ""); | 60 assertPacUrl(dict, ""); |
| 61 assertBypassList(dict, ""); | 61 assertBypassList(dict, ""); |
| 62 } | 62 } |
| 63 | 63 |
| 64 TEST(ProxyPolicyTest, OverridesCommandLineOptions) { | 64 TEST(ProxyPolicyTest, OverridesCommandLineOptions) { |
| 65 CommandLine command_line(CommandLine::NO_PROGRAM); | 65 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 66 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123"); | 66 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123"); |
| 67 command_line.AppendSwitchASCII(switches::kProxyServer, "789"); | 67 command_line.AppendSwitchASCII(switches::kProxyServer, "789"); |
| 68 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( | 68 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( |
| 69 new policy::MockConfigurationPolicyProvider()); | 69 new policy::MockConfigurationPolicyProvider()); |
| 70 Value* mode_name = Value::CreateStringValue( | 70 Value* mode_name = base::StringValue::New( |
| 71 ProxyPrefs::kFixedServersProxyModeName); | 71 ProxyPrefs::kFixedServersProxyModeName); |
| 72 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); | 72 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); |
| 73 provider->AddPolicy(policy::kPolicyProxyBypassList, | 73 provider->AddPolicy(policy::kPolicyProxyBypassList, |
| 74 Value::CreateStringValue("abc")); | 74 base::StringValue::New("abc")); |
| 75 provider->AddPolicy(policy::kPolicyProxyServer, | 75 provider->AddPolicy(policy::kPolicyProxyServer, |
| 76 Value::CreateStringValue("ghi")); | 76 base::StringValue::New("ghi")); |
| 77 | 77 |
| 78 // First verify that command-line options are set correctly when | 78 // First verify that command-line options are set correctly when |
| 79 // there is no policy in effect. | 79 // there is no policy in effect. |
| 80 PrefServiceMockBuilder builder; | 80 PrefServiceMockBuilder builder; |
| 81 builder.WithCommandLine(&command_line); | 81 builder.WithCommandLine(&command_line); |
| 82 scoped_ptr<PrefService> prefs(builder.Create()); | 82 scoped_ptr<PrefService> prefs(builder.Create()); |
| 83 browser::RegisterUserPrefs(prefs.get()); | 83 browser::RegisterUserPrefs(prefs.get()); |
| 84 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); | 84 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); |
| 85 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); | 85 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); |
| 86 assertProxyServer(dict, "789"); | 86 assertProxyServer(dict, "789"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 100 assertPacUrl(dict2, ""); | 100 assertPacUrl(dict2, ""); |
| 101 assertBypassList(dict2, "abc"); | 101 assertBypassList(dict2, "abc"); |
| 102 } | 102 } |
| 103 | 103 |
| 104 TEST(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { | 104 TEST(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { |
| 105 CommandLine command_line(CommandLine::NO_PROGRAM); | 105 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 106 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123"); | 106 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123"); |
| 107 command_line.AppendSwitchASCII(switches::kProxyServer, "789"); | 107 command_line.AppendSwitchASCII(switches::kProxyServer, "789"); |
| 108 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( | 108 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( |
| 109 new policy::MockConfigurationPolicyProvider()); | 109 new policy::MockConfigurationPolicyProvider()); |
| 110 Value* mode_name = Value::CreateStringValue( | 110 Value* mode_name = base::StringValue::New( |
| 111 ProxyPrefs::kAutoDetectProxyModeName); | 111 ProxyPrefs::kAutoDetectProxyModeName); |
| 112 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); | 112 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); |
| 113 | 113 |
| 114 // First verify that command-line options are set correctly when | 114 // First verify that command-line options are set correctly when |
| 115 // there is no policy in effect. | 115 // there is no policy in effect. |
| 116 PrefServiceMockBuilder builder; | 116 PrefServiceMockBuilder builder; |
| 117 builder.WithCommandLine(&command_line); | 117 builder.WithCommandLine(&command_line); |
| 118 scoped_ptr<PrefService> prefs(builder.Create()); | 118 scoped_ptr<PrefService> prefs(builder.Create()); |
| 119 browser::RegisterUserPrefs(prefs.get()); | 119 browser::RegisterUserPrefs(prefs.get()); |
| 120 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); | 120 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 133 browser::RegisterUserPrefs(prefs2.get()); | 133 browser::RegisterUserPrefs(prefs2.get()); |
| 134 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy)); | 134 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy)); |
| 135 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); | 135 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST(ProxyPolicyTest, OverridesCommandLineNoProxy) { | 138 TEST(ProxyPolicyTest, OverridesCommandLineNoProxy) { |
| 139 CommandLine command_line(CommandLine::NO_PROGRAM); | 139 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 140 command_line.AppendSwitch(switches::kNoProxyServer); | 140 command_line.AppendSwitch(switches::kNoProxyServer); |
| 141 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( | 141 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( |
| 142 new policy::MockConfigurationPolicyProvider()); | 142 new policy::MockConfigurationPolicyProvider()); |
| 143 Value* mode_name = Value::CreateStringValue( | 143 Value* mode_name = base::StringValue::New( |
| 144 ProxyPrefs::kAutoDetectProxyModeName); | 144 ProxyPrefs::kAutoDetectProxyModeName); |
| 145 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); | 145 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); |
| 146 | 146 |
| 147 // First verify that command-line options are set correctly when | 147 // First verify that command-line options are set correctly when |
| 148 // there is no policy in effect. | 148 // there is no policy in effect. |
| 149 PrefServiceMockBuilder builder; | 149 PrefServiceMockBuilder builder; |
| 150 builder.WithCommandLine(&command_line); | 150 builder.WithCommandLine(&command_line); |
| 151 scoped_ptr<PrefService> prefs(builder.Create()); | 151 scoped_ptr<PrefService> prefs(builder.Create()); |
| 152 browser::RegisterUserPrefs(prefs.get()); | 152 browser::RegisterUserPrefs(prefs.get()); |
| 153 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); | 153 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); |
| 154 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); | 154 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); |
| 155 | 155 |
| 156 // Try a second time time with the managed PrefStore in place, the | 156 // Try a second time time with the managed PrefStore in place, the |
| 157 // auto-detect should be overridden. The default pref store must be | 157 // auto-detect should be overridden. The default pref store must be |
| 158 // in place with the appropriate default value for this to work. | 158 // in place with the appropriate default value for this to work. |
| 159 builder.WithCommandLine(&command_line); | 159 builder.WithCommandLine(&command_line); |
| 160 builder.WithManagedPlatformProvider(provider.get()); | 160 builder.WithManagedPlatformProvider(provider.get()); |
| 161 scoped_ptr<PrefService> prefs2(builder.Create()); | 161 scoped_ptr<PrefService> prefs2(builder.Create()); |
| 162 browser::RegisterUserPrefs(prefs2.get()); | 162 browser::RegisterUserPrefs(prefs2.get()); |
| 163 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy)); | 163 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy)); |
| 164 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); | 164 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); |
| 165 } | 165 } |
| 166 | 166 |
| 167 TEST(ProxyPolicyTest, OverridesCommandLineAutoDetect) { | 167 TEST(ProxyPolicyTest, OverridesCommandLineAutoDetect) { |
| 168 CommandLine command_line(CommandLine::NO_PROGRAM); | 168 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 169 command_line.AppendSwitch(switches::kProxyAutoDetect); | 169 command_line.AppendSwitch(switches::kProxyAutoDetect); |
| 170 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( | 170 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( |
| 171 new policy::MockConfigurationPolicyProvider()); | 171 new policy::MockConfigurationPolicyProvider()); |
| 172 Value* mode_name = Value::CreateStringValue( | 172 Value* mode_name = base::StringValue::New( |
| 173 ProxyPrefs::kDirectProxyModeName); | 173 ProxyPrefs::kDirectProxyModeName); |
| 174 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); | 174 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); |
| 175 | 175 |
| 176 // First verify that the auto-detect is set if there is no managed | 176 // First verify that the auto-detect is set if there is no managed |
| 177 // PrefStore. | 177 // PrefStore. |
| 178 PrefServiceMockBuilder builder; | 178 PrefServiceMockBuilder builder; |
| 179 builder.WithCommandLine(&command_line); | 179 builder.WithCommandLine(&command_line); |
| 180 scoped_ptr<PrefService> prefs(builder.Create()); | 180 scoped_ptr<PrefService> prefs(builder.Create()); |
| 181 browser::RegisterUserPrefs(prefs.get()); | 181 browser::RegisterUserPrefs(prefs.get()); |
| 182 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); | 182 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); |
| 183 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); | 183 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); |
| 184 | 184 |
| 185 // Try a second time time with the managed PrefStore in place, the | 185 // Try a second time time with the managed PrefStore in place, the |
| 186 // auto-detect should be overridden. The default pref store must be | 186 // auto-detect should be overridden. The default pref store must be |
| 187 // in place with the appropriate default value for this to work. | 187 // in place with the appropriate default value for this to work. |
| 188 builder.WithCommandLine(&command_line); | 188 builder.WithCommandLine(&command_line); |
| 189 builder.WithManagedPlatformProvider(provider.get()); | 189 builder.WithManagedPlatformProvider(provider.get()); |
| 190 scoped_ptr<PrefService> prefs2(builder.Create()); | 190 scoped_ptr<PrefService> prefs2(builder.Create()); |
| 191 browser::RegisterUserPrefs(prefs2.get()); | 191 browser::RegisterUserPrefs(prefs2.get()); |
| 192 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy)); | 192 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy)); |
| 193 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); | 193 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); |
| 194 } | 194 } |
| OLD | NEW |