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

Side by Side Diff: chrome/browser/prefs/proxy_policy_unittest.cc

Issue 9111022: Removed ConfigurationPolicyType and extended PolicyMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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"
11 #include "chrome/browser/prefs/proxy_prefs.h" 11 #include "chrome/browser/prefs/proxy_prefs.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "policy/policy_constants.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 void assertProxyMode(const ProxyConfigDictionary& dict, 17 void assertProxyMode(const ProxyConfigDictionary& dict,
17 ProxyPrefs::ProxyMode expected_mode) { 18 ProxyPrefs::ProxyMode expected_mode) {
18 ProxyPrefs::ProxyMode actual_mode; 19 ProxyPrefs::ProxyMode actual_mode;
19 ASSERT_TRUE(dict.GetMode(&actual_mode)); 20 ASSERT_TRUE(dict.GetMode(&actual_mode));
20 EXPECT_EQ(expected_mode, actual_mode); 21 EXPECT_EQ(expected_mode, actual_mode);
21 } 22 }
22 23
23 void assertProxyServer(const ProxyConfigDictionary& dict, 24 void assertProxyServer(const ProxyConfigDictionary& dict,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 } 63 }
63 64
64 TEST(ProxyPolicyTest, OverridesCommandLineOptions) { 65 TEST(ProxyPolicyTest, OverridesCommandLineOptions) {
65 CommandLine command_line(CommandLine::NO_PROGRAM); 66 CommandLine command_line(CommandLine::NO_PROGRAM);
66 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123"); 67 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123");
67 command_line.AppendSwitchASCII(switches::kProxyServer, "789"); 68 command_line.AppendSwitchASCII(switches::kProxyServer, "789");
68 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( 69 scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
69 new policy::MockConfigurationPolicyProvider()); 70 new policy::MockConfigurationPolicyProvider());
70 Value* mode_name = Value::CreateStringValue( 71 Value* mode_name = Value::CreateStringValue(
71 ProxyPrefs::kFixedServersProxyModeName); 72 ProxyPrefs::kFixedServersProxyModeName);
72 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); 73 provider->AddMandatoryPolicy(policy::key::kProxyMode, mode_name);
73 provider->AddPolicy(policy::kPolicyProxyBypassList, 74 provider->AddMandatoryPolicy(policy::key::kProxyBypassList,
74 Value::CreateStringValue("abc")); 75 Value::CreateStringValue("abc"));
75 provider->AddPolicy(policy::kPolicyProxyServer, 76 provider->AddMandatoryPolicy(policy::key::kProxyServer,
76 Value::CreateStringValue("ghi")); 77 Value::CreateStringValue("ghi"));
77 78
78 // First verify that command-line options are set correctly when 79 // First verify that command-line options are set correctly when
79 // there is no policy in effect. 80 // there is no policy in effect.
80 PrefServiceMockBuilder builder; 81 PrefServiceMockBuilder builder;
81 builder.WithCommandLine(&command_line); 82 builder.WithCommandLine(&command_line);
82 scoped_ptr<PrefService> prefs(builder.Create()); 83 scoped_ptr<PrefService> prefs(builder.Create());
83 browser::RegisterUserPrefs(prefs.get()); 84 browser::RegisterUserPrefs(prefs.get());
84 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 85 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
85 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 86 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
86 assertProxyServer(dict, "789"); 87 assertProxyServer(dict, "789");
(...skipping 15 matching lines...) Expand all
102 } 103 }
103 104
104 TEST(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { 105 TEST(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) {
105 CommandLine command_line(CommandLine::NO_PROGRAM); 106 CommandLine command_line(CommandLine::NO_PROGRAM);
106 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123"); 107 command_line.AppendSwitchASCII(switches::kProxyBypassList, "123");
107 command_line.AppendSwitchASCII(switches::kProxyServer, "789"); 108 command_line.AppendSwitchASCII(switches::kProxyServer, "789");
108 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( 109 scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
109 new policy::MockConfigurationPolicyProvider()); 110 new policy::MockConfigurationPolicyProvider());
110 Value* mode_name = Value::CreateStringValue( 111 Value* mode_name = Value::CreateStringValue(
111 ProxyPrefs::kAutoDetectProxyModeName); 112 ProxyPrefs::kAutoDetectProxyModeName);
112 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); 113 provider->AddMandatoryPolicy(policy::key::kProxyMode, mode_name);
113 114
114 // First verify that command-line options are set correctly when 115 // First verify that command-line options are set correctly when
115 // there is no policy in effect. 116 // there is no policy in effect.
116 PrefServiceMockBuilder builder; 117 PrefServiceMockBuilder builder;
117 builder.WithCommandLine(&command_line); 118 builder.WithCommandLine(&command_line);
118 scoped_ptr<PrefService> prefs(builder.Create()); 119 scoped_ptr<PrefService> prefs(builder.Create());
119 browser::RegisterUserPrefs(prefs.get()); 120 browser::RegisterUserPrefs(prefs.get());
120 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 121 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
121 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 122 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
122 assertProxyServer(dict, "789"); 123 assertProxyServer(dict, "789");
(...skipping 12 matching lines...) Expand all
135 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 136 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
136 } 137 }
137 138
138 TEST(ProxyPolicyTest, OverridesCommandLineNoProxy) { 139 TEST(ProxyPolicyTest, OverridesCommandLineNoProxy) {
139 CommandLine command_line(CommandLine::NO_PROGRAM); 140 CommandLine command_line(CommandLine::NO_PROGRAM);
140 command_line.AppendSwitch(switches::kNoProxyServer); 141 command_line.AppendSwitch(switches::kNoProxyServer);
141 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( 142 scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
142 new policy::MockConfigurationPolicyProvider()); 143 new policy::MockConfigurationPolicyProvider());
143 Value* mode_name = Value::CreateStringValue( 144 Value* mode_name = Value::CreateStringValue(
144 ProxyPrefs::kAutoDetectProxyModeName); 145 ProxyPrefs::kAutoDetectProxyModeName);
145 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); 146 provider->AddMandatoryPolicy(policy::key::kProxyMode, mode_name);
146 147
147 // First verify that command-line options are set correctly when 148 // First verify that command-line options are set correctly when
148 // there is no policy in effect. 149 // there is no policy in effect.
149 PrefServiceMockBuilder builder; 150 PrefServiceMockBuilder builder;
150 builder.WithCommandLine(&command_line); 151 builder.WithCommandLine(&command_line);
151 scoped_ptr<PrefService> prefs(builder.Create()); 152 scoped_ptr<PrefService> prefs(builder.Create());
152 browser::RegisterUserPrefs(prefs.get()); 153 browser::RegisterUserPrefs(prefs.get());
153 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 154 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
154 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); 155 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
155 156
156 // Try a second time time with the managed PrefStore in place, the 157 // Try a second time time with the managed PrefStore in place, the
157 // auto-detect should be overridden. The default pref store must be 158 // auto-detect should be overridden. The default pref store must be
158 // in place with the appropriate default value for this to work. 159 // in place with the appropriate default value for this to work.
159 builder.WithCommandLine(&command_line); 160 builder.WithCommandLine(&command_line);
160 builder.WithManagedPlatformProvider(provider.get()); 161 builder.WithManagedPlatformProvider(provider.get());
161 scoped_ptr<PrefService> prefs2(builder.Create()); 162 scoped_ptr<PrefService> prefs2(builder.Create());
162 browser::RegisterUserPrefs(prefs2.get()); 163 browser::RegisterUserPrefs(prefs2.get());
163 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy)); 164 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
164 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 165 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
165 } 166 }
166 167
167 TEST(ProxyPolicyTest, OverridesCommandLineAutoDetect) { 168 TEST(ProxyPolicyTest, OverridesCommandLineAutoDetect) {
168 CommandLine command_line(CommandLine::NO_PROGRAM); 169 CommandLine command_line(CommandLine::NO_PROGRAM);
169 command_line.AppendSwitch(switches::kProxyAutoDetect); 170 command_line.AppendSwitch(switches::kProxyAutoDetect);
170 scoped_ptr<policy::MockConfigurationPolicyProvider> provider( 171 scoped_ptr<policy::MockConfigurationPolicyProvider> provider(
171 new policy::MockConfigurationPolicyProvider()); 172 new policy::MockConfigurationPolicyProvider());
172 Value* mode_name = Value::CreateStringValue( 173 Value* mode_name = Value::CreateStringValue(
173 ProxyPrefs::kDirectProxyModeName); 174 ProxyPrefs::kDirectProxyModeName);
174 provider->AddPolicy(policy::kPolicyProxyMode, mode_name); 175 provider->AddMandatoryPolicy(policy::key::kProxyMode, mode_name);
175 176
176 // First verify that the auto-detect is set if there is no managed 177 // First verify that the auto-detect is set if there is no managed
177 // PrefStore. 178 // PrefStore.
178 PrefServiceMockBuilder builder; 179 PrefServiceMockBuilder builder;
179 builder.WithCommandLine(&command_line); 180 builder.WithCommandLine(&command_line);
180 scoped_ptr<PrefService> prefs(builder.Create()); 181 scoped_ptr<PrefService> prefs(builder.Create());
181 browser::RegisterUserPrefs(prefs.get()); 182 browser::RegisterUserPrefs(prefs.get());
182 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 183 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
183 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); 184 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
184 185
185 // Try a second time time with the managed PrefStore in place, the 186 // Try a second time time with the managed PrefStore in place, the
186 // auto-detect should be overridden. The default pref store must be 187 // auto-detect should be overridden. The default pref store must be
187 // in place with the appropriate default value for this to work. 188 // in place with the appropriate default value for this to work.
188 builder.WithCommandLine(&command_line); 189 builder.WithCommandLine(&command_line);
189 builder.WithManagedPlatformProvider(provider.get()); 190 builder.WithManagedPlatformProvider(provider.get());
190 scoped_ptr<PrefService> prefs2(builder.Create()); 191 scoped_ptr<PrefService> prefs2(builder.Create());
191 browser::RegisterUserPrefs(prefs2.get()); 192 browser::RegisterUserPrefs(prefs2.get());
192 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy)); 193 ProxyConfigDictionary dict2(prefs2->GetDictionary(prefs::kProxy));
193 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); 194 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
194 } 195 }
OLDNEW
« no previous file with comments | « chrome/browser/policy/user_policy_cache_unittest.cc ('k') | chrome/browser/resources/policy.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698