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

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

Issue 5562002: Refactor FileBasedPolicyProvider, introduce AsynchronousPolicyProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review feedback Created 10 years 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/path_service.h" 8 #include "base/path_service.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 ScopedTempDir test_dir_; 42 ScopedTempDir test_dir_;
43 }; 43 };
44 44
45 class ConfigDirPolicyLoaderTest 45 class ConfigDirPolicyLoaderTest
46 : public ConfigDirPolicyProviderTestBase<testing::Test> { 46 : public ConfigDirPolicyProviderTestBase<testing::Test> {
47 }; 47 };
48 48
49 // The preferences dictionary is expected to be empty when there are no files to 49 // The preferences dictionary is expected to be empty when there are no files to
50 // load. 50 // load.
51 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) { 51 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) {
52 ConfigDirPolicyLoader loader(test_dir()); 52 ConfigDirPolicyProviderDelegate loader(test_dir());
53 scoped_ptr<DictionaryValue> policy(loader.Load()); 53 scoped_ptr<DictionaryValue> policy(loader.Load());
54 EXPECT_TRUE(policy.get()); 54 EXPECT_TRUE(policy.get());
55 EXPECT_TRUE(policy->empty()); 55 EXPECT_TRUE(policy->empty());
56 } 56 }
57 57
58 // Reading from a non-existent directory should result in an empty preferences 58 // Reading from a non-existent directory should result in an empty preferences
59 // dictionary. 59 // dictionary.
60 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) { 60 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) {
61 FilePath non_existent_dir(test_dir().Append(FILE_PATH_LITERAL("not_there"))); 61 FilePath non_existent_dir(test_dir().Append(FILE_PATH_LITERAL("not_there")));
62 ConfigDirPolicyLoader loader(non_existent_dir); 62 ConfigDirPolicyProviderDelegate loader(non_existent_dir);
63 scoped_ptr<DictionaryValue> policy(loader.Load()); 63 scoped_ptr<DictionaryValue> policy(loader.Load());
64 EXPECT_TRUE(policy.get()); 64 EXPECT_TRUE(policy.get());
65 EXPECT_TRUE(policy->empty()); 65 EXPECT_TRUE(policy->empty());
66 } 66 }
67 67
68 // Test reading back a single preference value. 68 // Test reading back a single preference value.
69 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsSinglePref) { 69 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsSinglePref) {
70 DictionaryValue test_dict; 70 DictionaryValue test_dict;
71 test_dict.SetString("HomepageLocation", "http://www.google.com"); 71 test_dict.SetString("HomepageLocation", "http://www.google.com");
72 WriteConfigFile(test_dict, "config_file"); 72 WriteConfigFile(test_dict, "config_file");
73 73
74 ConfigDirPolicyLoader loader(test_dir()); 74 ConfigDirPolicyProviderDelegate loader(test_dir());
75 scoped_ptr<DictionaryValue> policy(loader.Load()); 75 scoped_ptr<DictionaryValue> policy(loader.Load());
76 EXPECT_TRUE(policy.get()); 76 EXPECT_TRUE(policy.get());
77 EXPECT_TRUE(policy->Equals(&test_dict)); 77 EXPECT_TRUE(policy->Equals(&test_dict));
78 } 78 }
79 79
80 // Test merging values from different files. 80 // Test merging values from different files.
81 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) { 81 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) {
82 // Write a bunch of data files in order to increase the chance to detect the 82 // Write a bunch of data files in order to increase the chance to detect the
83 // provider not respecting lexicographic ordering when reading them. Since the 83 // provider not respecting lexicographic ordering when reading them. Since the
84 // filesystem may return files in arbitrary order, there is no way to be sure, 84 // filesystem may return files in arbitrary order, there is no way to be sure,
85 // but this is better than nothing. 85 // but this is better than nothing.
86 DictionaryValue test_dict_bar; 86 DictionaryValue test_dict_bar;
87 test_dict_bar.SetString("HomepageLocation", "http://bar.com"); 87 test_dict_bar.SetString("HomepageLocation", "http://bar.com");
88 for (unsigned int i = 1; i <= 4; ++i) 88 for (unsigned int i = 1; i <= 4; ++i)
89 WriteConfigFile(test_dict_bar, base::IntToString(i)); 89 WriteConfigFile(test_dict_bar, base::IntToString(i));
90 DictionaryValue test_dict_foo; 90 DictionaryValue test_dict_foo;
91 test_dict_foo.SetString("HomepageLocation", "http://foo.com"); 91 test_dict_foo.SetString("HomepageLocation", "http://foo.com");
92 WriteConfigFile(test_dict_foo, "9"); 92 WriteConfigFile(test_dict_foo, "9");
93 for (unsigned int i = 5; i <= 8; ++i) 93 for (unsigned int i = 5; i <= 8; ++i)
94 WriteConfigFile(test_dict_bar, base::IntToString(i)); 94 WriteConfigFile(test_dict_bar, base::IntToString(i));
95 95
96 ConfigDirPolicyLoader loader(test_dir()); 96 ConfigDirPolicyProviderDelegate loader(test_dir());
97 scoped_ptr<DictionaryValue> policy(loader.Load()); 97 scoped_ptr<DictionaryValue> policy(loader.Load());
98 EXPECT_TRUE(policy.get()); 98 EXPECT_TRUE(policy.get());
99 EXPECT_TRUE(policy->Equals(&test_dict_foo)); 99 EXPECT_TRUE(policy->Equals(&test_dict_foo));
100 } 100 }
101 101
102 // Holds policy type, corresponding policy key string and a valid value for use 102 // Holds policy type, corresponding policy key string and a valid value for use
103 // in parametrized value tests. 103 // in parametrized value tests.
104 class ValueTestParams { 104 class ValueTestParams {
105 public: 105 public:
106 // Assumes ownership of |test_value|. 106 // Assumes ownership of |test_value|.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 kPolicyExtensionInstallDenyList, 309 kPolicyExtensionInstallDenyList,
310 key::kExtensionInstallDenyList), 310 key::kExtensionInstallDenyList),
311 ValueTestParams::ForBooleanPolicy( 311 ValueTestParams::ForBooleanPolicy(
312 kPolicyShowHomeButton, 312 kPolicyShowHomeButton,
313 key::kShowHomeButton), 313 key::kShowHomeButton),
314 ValueTestParams::ForBooleanPolicy( 314 ValueTestParams::ForBooleanPolicy(
315 kPolicyPrintingEnabled, 315 kPolicyPrintingEnabled,
316 key::kPrintingEnabled))); 316 key::kPrintingEnabled)));
317 317
318 } // namespace policy 318 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698