| OLD | NEW |
| 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" |
| 11 #include "chrome/browser/browser_thread.h" |
| 11 #include "chrome/browser/policy/config_dir_policy_provider.h" | 12 #include "chrome/browser/policy/config_dir_policy_provider.h" |
| 12 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 13 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 13 #include "chrome/browser/policy/mock_configuration_policy_store.h" | 14 #include "chrome/browser/policy/mock_configuration_policy_store.h" |
| 14 #include "chrome/common/json_value_serializer.h" | 15 #include "chrome/common/json_value_serializer.h" |
| 15 #include "chrome/common/policy_constants.h" | 16 #include "chrome/common/policy_constants.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 18 |
| 18 namespace policy { | 19 namespace policy { |
| 19 | 20 |
| 20 template<typename BASE> | 21 template<typename BASE> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 42 ScopedTempDir test_dir_; | 43 ScopedTempDir test_dir_; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 class ConfigDirPolicyLoaderTest | 46 class ConfigDirPolicyLoaderTest |
| 46 : public ConfigDirPolicyProviderTestBase<testing::Test> { | 47 : public ConfigDirPolicyProviderTestBase<testing::Test> { |
| 47 }; | 48 }; |
| 48 | 49 |
| 49 // The preferences dictionary is expected to be empty when there are no files to | 50 // The preferences dictionary is expected to be empty when there are no files to |
| 50 // load. | 51 // load. |
| 51 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) { | 52 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) { |
| 52 ConfigDirPolicyLoader loader(test_dir()); | 53 ConfigDirPolicyProviderDelegate loader(test_dir()); |
| 53 scoped_ptr<DictionaryValue> policy(loader.Load()); | 54 scoped_ptr<DictionaryValue> policy(loader.Load()); |
| 54 EXPECT_TRUE(policy.get()); | 55 EXPECT_TRUE(policy.get()); |
| 55 EXPECT_TRUE(policy->empty()); | 56 EXPECT_TRUE(policy->empty()); |
| 56 } | 57 } |
| 57 | 58 |
| 58 // Reading from a non-existent directory should result in an empty preferences | 59 // Reading from a non-existent directory should result in an empty preferences |
| 59 // dictionary. | 60 // dictionary. |
| 60 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) { | 61 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) { |
| 61 FilePath non_existent_dir(test_dir().Append(FILE_PATH_LITERAL("not_there"))); | 62 FilePath non_existent_dir(test_dir().Append(FILE_PATH_LITERAL("not_there"))); |
| 62 ConfigDirPolicyLoader loader(non_existent_dir); | 63 ConfigDirPolicyProviderDelegate loader(non_existent_dir); |
| 63 scoped_ptr<DictionaryValue> policy(loader.Load()); | 64 scoped_ptr<DictionaryValue> policy(loader.Load()); |
| 64 EXPECT_TRUE(policy.get()); | 65 EXPECT_TRUE(policy.get()); |
| 65 EXPECT_TRUE(policy->empty()); | 66 EXPECT_TRUE(policy->empty()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 // Test reading back a single preference value. | 69 // Test reading back a single preference value. |
| 69 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsSinglePref) { | 70 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsSinglePref) { |
| 70 DictionaryValue test_dict; | 71 DictionaryValue test_dict; |
| 71 test_dict.SetString("HomepageLocation", "http://www.google.com"); | 72 test_dict.SetString("HomepageLocation", "http://www.google.com"); |
| 72 WriteConfigFile(test_dict, "config_file"); | 73 WriteConfigFile(test_dict, "config_file"); |
| 73 | 74 |
| 74 ConfigDirPolicyLoader loader(test_dir()); | 75 ConfigDirPolicyProviderDelegate loader(test_dir()); |
| 75 scoped_ptr<DictionaryValue> policy(loader.Load()); | 76 scoped_ptr<DictionaryValue> policy(loader.Load()); |
| 76 EXPECT_TRUE(policy.get()); | 77 EXPECT_TRUE(policy.get()); |
| 77 EXPECT_TRUE(policy->Equals(&test_dict)); | 78 EXPECT_TRUE(policy->Equals(&test_dict)); |
| 78 } | 79 } |
| 79 | 80 |
| 80 // Test merging values from different files. | 81 // Test merging values from different files. |
| 81 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) { | 82 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) { |
| 82 // Write a bunch of data files in order to increase the chance to detect the | 83 // 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 | 84 // 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, | 85 // filesystem may return files in arbitrary order, there is no way to be sure, |
| 85 // but this is better than nothing. | 86 // but this is better than nothing. |
| 86 DictionaryValue test_dict_bar; | 87 DictionaryValue test_dict_bar; |
| 87 test_dict_bar.SetString("HomepageLocation", "http://bar.com"); | 88 test_dict_bar.SetString("HomepageLocation", "http://bar.com"); |
| 88 for (unsigned int i = 1; i <= 4; ++i) | 89 for (unsigned int i = 1; i <= 4; ++i) |
| 89 WriteConfigFile(test_dict_bar, base::IntToString(i)); | 90 WriteConfigFile(test_dict_bar, base::IntToString(i)); |
| 90 DictionaryValue test_dict_foo; | 91 DictionaryValue test_dict_foo; |
| 91 test_dict_foo.SetString("HomepageLocation", "http://foo.com"); | 92 test_dict_foo.SetString("HomepageLocation", "http://foo.com"); |
| 92 WriteConfigFile(test_dict_foo, "9"); | 93 WriteConfigFile(test_dict_foo, "9"); |
| 93 for (unsigned int i = 5; i <= 8; ++i) | 94 for (unsigned int i = 5; i <= 8; ++i) |
| 94 WriteConfigFile(test_dict_bar, base::IntToString(i)); | 95 WriteConfigFile(test_dict_bar, base::IntToString(i)); |
| 95 | 96 |
| 96 ConfigDirPolicyLoader loader(test_dir()); | 97 ConfigDirPolicyProviderDelegate loader(test_dir()); |
| 97 scoped_ptr<DictionaryValue> policy(loader.Load()); | 98 scoped_ptr<DictionaryValue> policy(loader.Load()); |
| 98 EXPECT_TRUE(policy.get()); | 99 EXPECT_TRUE(policy.get()); |
| 99 EXPECT_TRUE(policy->Equals(&test_dict_foo)); | 100 EXPECT_TRUE(policy->Equals(&test_dict_foo)); |
| 100 } | 101 } |
| 101 | 102 |
| 102 // Holds policy type, corresponding policy key string and a valid value for use | 103 // Holds policy type, corresponding policy key string and a valid value for use |
| 103 // in parametrized value tests. | 104 // in parametrized value tests. |
| 104 class ValueTestParams { | 105 class ValueTestParams { |
| 105 public: | 106 public: |
| 106 // Assumes ownership of |test_value|. | 107 // Assumes ownership of |test_value|. |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 kPolicyExtensionInstallDenyList, | 310 kPolicyExtensionInstallDenyList, |
| 310 key::kExtensionInstallDenyList), | 311 key::kExtensionInstallDenyList), |
| 311 ValueTestParams::ForBooleanPolicy( | 312 ValueTestParams::ForBooleanPolicy( |
| 312 kPolicyShowHomeButton, | 313 kPolicyShowHomeButton, |
| 313 key::kShowHomeButton), | 314 key::kShowHomeButton), |
| 314 ValueTestParams::ForBooleanPolicy( | 315 ValueTestParams::ForBooleanPolicy( |
| 315 kPolicyPrintingEnabled, | 316 kPolicyPrintingEnabled, |
| 316 key::kPrintingEnabled))); | 317 key::kPrintingEnabled))); |
| 317 | 318 |
| 318 } // namespace policy | 319 } // namespace policy |
| OLD | NEW |