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

Side by Side Diff: chrome/browser/policy/config_dir_policy_provider_unittest.cc

Issue 8258018: Generate Chrome policy definition list from policy_templates.json. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix the unittest fix Created 9 years, 2 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) 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/json/json_value_serializer.h" 8 #include "base/json/json_value_serializer.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 loop_.RunAllPending(); 179 loop_.RunAllPending();
180 } 180 }
181 181
182 private: 182 private:
183 MessageLoop loop_; 183 MessageLoop loop_;
184 BrowserThread ui_thread_; 184 BrowserThread ui_thread_;
185 BrowserThread file_thread_; 185 BrowserThread file_thread_;
186 }; 186 };
187 187
188 TEST_P(ConfigDirPolicyProviderValueTest, Default) { 188 TEST_P(ConfigDirPolicyProviderValueTest, Default) {
189 ConfigDirPolicyProvider provider( 189 ConfigDirPolicyProvider provider(GetChromePolicyDefinitionList(), test_dir());
190 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
191 test_dir());
192 PolicyMap policy_map; 190 PolicyMap policy_map;
193 EXPECT_TRUE(provider.Provide(&policy_map)); 191 EXPECT_TRUE(provider.Provide(&policy_map));
194 EXPECT_TRUE(policy_map.empty()); 192 EXPECT_TRUE(policy_map.empty());
195 } 193 }
196 194
197 TEST_P(ConfigDirPolicyProviderValueTest, NullValue) { 195 TEST_P(ConfigDirPolicyProviderValueTest, NullValue) {
198 DictionaryValue dict; 196 DictionaryValue dict;
199 dict.Set(GetParam().policy_key(), Value::CreateNullValue()); 197 dict.Set(GetParam().policy_key(), Value::CreateNullValue());
200 WriteConfigFile(dict, "empty"); 198 WriteConfigFile(dict, "empty");
201 ConfigDirPolicyProvider provider( 199 ConfigDirPolicyProvider provider(GetChromePolicyDefinitionList(), test_dir());
202 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
203 test_dir());
204 PolicyMap policy_map; 200 PolicyMap policy_map;
205 EXPECT_TRUE(provider.Provide(&policy_map)); 201 EXPECT_TRUE(provider.Provide(&policy_map));
206 EXPECT_TRUE(policy_map.empty()); 202 EXPECT_TRUE(policy_map.empty());
207 } 203 }
208 204
209 TEST_P(ConfigDirPolicyProviderValueTest, TestValue) { 205 TEST_P(ConfigDirPolicyProviderValueTest, TestValue) {
210 DictionaryValue dict; 206 DictionaryValue dict;
211 dict.Set(GetParam().policy_key(), GetParam().test_value()->DeepCopy()); 207 dict.Set(GetParam().policy_key(), GetParam().test_value()->DeepCopy());
212 WriteConfigFile(dict, "policy"); 208 WriteConfigFile(dict, "policy");
213 ConfigDirPolicyProvider provider( 209 ConfigDirPolicyProvider provider(GetChromePolicyDefinitionList(), test_dir());
214 ConfigurationPolicyPrefStore::GetChromePolicyDefinitionList(),
215 test_dir());
216 PolicyMap policy_map; 210 PolicyMap policy_map;
217 EXPECT_TRUE(provider.Provide(&policy_map)); 211 EXPECT_TRUE(provider.Provide(&policy_map));
218 EXPECT_EQ(1U, policy_map.size()); 212 EXPECT_EQ(1U, policy_map.size());
219 const Value* value = policy_map.Get(GetParam().type()); 213 const Value* value = policy_map.Get(GetParam().type());
220 ASSERT_TRUE(value); 214 ASSERT_TRUE(value);
221 EXPECT_TRUE(GetParam().test_value()->Equals(value)); 215 EXPECT_TRUE(GetParam().test_value()->Equals(value));
222 } 216 }
223 217
224 // Test parameters for all supported policies. 218 // Test parameters for all supported policies. testing::Values() has a limit of
219 // 50 parameters which is reached in this instantiation; new policies should go
220 // in a new instantiation.
225 INSTANTIATE_TEST_CASE_P( 221 INSTANTIATE_TEST_CASE_P(
226 ConfigDirPolicyProviderValueTestInstance, 222 ConfigDirPolicyProviderValueTestInstance,
227 ConfigDirPolicyProviderValueTest, 223 ConfigDirPolicyProviderValueTest,
228 testing::Values( 224 testing::Values(
229 ValueTestParams::ForStringPolicy( 225 ValueTestParams::ForStringPolicy(
230 kPolicyHomepageLocation, 226 kPolicyHomepageLocation,
231 key::kHomepageLocation), 227 key::kHomepageLocation),
232 ValueTestParams::ForBooleanPolicy( 228 ValueTestParams::ForBooleanPolicy(
233 kPolicyHomepageIsNewTabPage, 229 kPolicyHomepageIsNewTabPage,
234 key::kHomepageIsNewTabPage), 230 key::kHomepageIsNewTabPage),
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 key::kExtensionInstallWhitelist), 317 key::kExtensionInstallWhitelist),
322 ValueTestParams::ForListPolicy( 318 ValueTestParams::ForListPolicy(
323 kPolicyExtensionInstallBlacklist, 319 kPolicyExtensionInstallBlacklist,
324 key::kExtensionInstallBlacklist), 320 key::kExtensionInstallBlacklist),
325 ValueTestParams::ForBooleanPolicy( 321 ValueTestParams::ForBooleanPolicy(
326 kPolicyShowHomeButton, 322 kPolicyShowHomeButton,
327 key::kShowHomeButton), 323 key::kShowHomeButton),
328 ValueTestParams::ForBooleanPolicy( 324 ValueTestParams::ForBooleanPolicy(
329 kPolicyPrintingEnabled, 325 kPolicyPrintingEnabled,
330 key::kPrintingEnabled), 326 key::kPrintingEnabled),
331 ValueTestParams::ForIntegerPolicy(
332 kPolicyDevicePolicyRefreshRate,
333 key::kDevicePolicyRefreshRate),
334 ValueTestParams::ForIntegerPolicy(
335 kPolicyPolicyRefreshRate,
336 key::kPolicyRefreshRate),
337 ValueTestParams::ForBooleanPolicy( 327 ValueTestParams::ForBooleanPolicy(
338 kPolicyInstantEnabled, 328 kPolicyInstantEnabled,
339 key::kInstantEnabled), 329 key::kInstantEnabled),
340 ValueTestParams::ForIntegerPolicy( 330 ValueTestParams::ForIntegerPolicy(
341 kPolicyIncognitoModeAvailability, 331 kPolicyIncognitoModeAvailability,
342 key::kIncognitoModeAvailability), 332 key::kIncognitoModeAvailability),
343 ValueTestParams::ForBooleanPolicy( 333 ValueTestParams::ForBooleanPolicy(
344 kPolicyDisablePluginFinder, 334 kPolicyDisablePluginFinder,
345 key::kDisablePluginFinder), 335 key::kDisablePluginFinder),
346 ValueTestParams::ForBooleanPolicy( 336 ValueTestParams::ForBooleanPolicy(
(...skipping 21 matching lines...) Expand all
368 kPolicyBookmarkBarEnabled, 358 kPolicyBookmarkBarEnabled,
369 key::kBookmarkBarEnabled), 359 key::kBookmarkBarEnabled),
370 ValueTestParams::ForBooleanPolicy( 360 ValueTestParams::ForBooleanPolicy(
371 kPolicyEditBookmarksEnabled, 361 kPolicyEditBookmarksEnabled,
372 key::kEditBookmarksEnabled), 362 key::kEditBookmarksEnabled),
373 ValueTestParams::ForListPolicy( 363 ValueTestParams::ForListPolicy(
374 kPolicyDisabledSchemes, 364 kPolicyDisabledSchemes,
375 key::kDisabledSchemes), 365 key::kDisabledSchemes),
376 ValueTestParams::ForStringPolicy( 366 ValueTestParams::ForStringPolicy(
377 kPolicyDiskCacheDir, 367 kPolicyDiskCacheDir,
378 key::kDiskCacheDir))); 368 key::kDiskCacheDir),
379
380 // testing::Values has a limit of 50 test templates, which is reached by the
381 // instantiations above. Add tests for new policies here:
382 INSTANTIATE_TEST_CASE_P(
383 ConfigDirPolicyProviderValueTestInstance2,
384 ConfigDirPolicyProviderValueTest,
385 testing::Values(
386 ValueTestParams::ForListPolicy( 369 ValueTestParams::ForListPolicy(
387 kPolicyURLBlacklist, 370 kPolicyURLBlacklist,
388 key::kURLBlacklist), 371 key::kURLBlacklist),
389 ValueTestParams::ForListPolicy( 372 ValueTestParams::ForListPolicy(
390 kPolicyURLWhitelist, 373 kPolicyURLWhitelist,
391 key::kURLWhitelist))); 374 key::kURLWhitelist)));
392 375
376 // Test parameters for all policies that are supported on ChromeOS only.
377 #if defined(OS_CHROMEOS)
378 INSTANTIATE_TEST_CASE_P(
379 ConfigDirPolicyProviderValueTestChromeOSInstance,
380 ConfigDirPolicyProviderValueTest,
381 testing::Values(
382 ValueTestParams::ForIntegerPolicy(
383 kPolicyPolicyRefreshRate,
384 key::kPolicyRefreshRate)));
385 #endif
386
393 } // namespace policy 387 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/config_dir_policy_provider.cc ('k') | chrome/browser/policy/configuration_policy_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698