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

Unified Diff: chrome/browser/policy/config_dir_policy_loader_unittest.cc

Issue 10443108: Implement the ConfigDirPolicyProvider based on the AsyncPolicyLoader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/policy/config_dir_policy_loader_unittest.cc
diff --git a/chrome/browser/policy/config_dir_policy_provider_unittest.cc b/chrome/browser/policy/config_dir_policy_loader_unittest.cc
similarity index 86%
rename from chrome/browser/policy/config_dir_policy_provider_unittest.cc
rename to chrome/browser/policy/config_dir_policy_loader_unittest.cc
index 84ce4678c89bac49c5c6563e6f5ebe28e2da5475..681162952a976a9a12170d6ca49703e61672015f 100644
--- a/chrome/browser/policy/config_dir_policy_provider_unittest.cc
+++ b/chrome/browser/policy/config_dir_policy_loader_unittest.cc
@@ -9,7 +9,8 @@
#include "base/scoped_temp_dir.h"
#include "base/string_number_conversions.h"
#include "base/values.h"
-#include "chrome/browser/policy/config_dir_policy_provider.h"
+#include "chrome/browser/policy/async_policy_provider.h"
+#include "chrome/browser/policy/config_dir_policy_loader.h"
#include "chrome/browser/policy/configuration_policy_provider_test.h"
#include "chrome/browser/policy/policy_bundle.h"
#include "chrome/browser/policy/policy_map.h"
@@ -18,6 +19,9 @@ namespace policy {
namespace {
+// Subdirectory of the config dir that contains mandatory policies.
+const FilePath::CharType kMandatoryPath[] = FILE_PATH_LITERAL("managed");
+
class TestHarness : public PolicyProviderTestHarness {
public:
TestHarness();
@@ -67,10 +71,9 @@ void TestHarness::SetUp() {
ConfigurationPolicyProvider* TestHarness::CreateProvider(
const PolicyDefinitionList* policy_definition_list) {
- return new ConfigDirPolicyProvider(policy_definition_list,
- POLICY_LEVEL_MANDATORY,
- POLICY_SCOPE_MACHINE,
- test_dir());
+ scoped_ptr<AsyncPolicyLoader> loader(
+ new ConfigDirPolicyLoader(test_dir(), POLICY_SCOPE_MACHINE));
+ return new AsyncPolicyProvider(policy_definition_list, loader.Pass());
}
void TestHarness::InstallEmptyPolicy() {
@@ -119,8 +122,11 @@ void TestHarness::WriteConfigFile(const base::DictionaryValue& dict,
std::string data;
JSONStringValueSerializer serializer(&data);
serializer.Serialize(dict);
- const FilePath file_path(test_dir().AppendASCII(file_name));
- ASSERT_TRUE(file_util::WriteFile(file_path, data.c_str(), data.size()));
+ const FilePath mandatory_dir(test_dir().Append(kMandatoryPath));
+ ASSERT_TRUE(file_util::CreateDirectory(mandatory_dir));
+ const FilePath file_path(mandatory_dir.AppendASCII(file_name));
+ ASSERT_EQ((int) data.size(),
+ file_util::WriteFile(file_path, data.c_str(), data.size()));
}
// static
@@ -132,14 +138,15 @@ PolicyProviderTestHarness* TestHarness::Create() {
// Instantiate abstract test case for basic policy reading tests.
INSTANTIATE_TEST_CASE_P(
- ConfigDirPolicyProviderTest,
+ ConfigDirPolicyLoaderTest,
ConfigurationPolicyProviderTest,
testing::Values(TestHarness::Create));
// Some tests that exercise special functionality in ConfigDirPolicyLoader.
-class ConfigDirPolicyLoaderTest : public testing::Test {
+class ConfigDirPolicyLoaderTest : public PolicyTestBase {
protected:
- void SetUp() {
+ void SetUp() OVERRIDE {
+ PolicyTestBase::SetUp();
harness_.SetUp();
}
@@ -149,9 +156,7 @@ class ConfigDirPolicyLoaderTest : public testing::Test {
// The preferences dictionary is expected to be empty when there are no files to
// load.
TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) {
- ConfigDirPolicyProviderDelegate loader(harness_.test_dir(),
- POLICY_LEVEL_MANDATORY,
- POLICY_SCOPE_MACHINE);
+ ConfigDirPolicyLoader loader(harness_.test_dir(), POLICY_SCOPE_MACHINE);
scoped_ptr<PolicyBundle> bundle(loader.Load());
ASSERT_TRUE(bundle.get());
const PolicyBundle kEmptyBundle;
@@ -163,9 +168,7 @@ TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) {
TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) {
FilePath non_existent_dir(
harness_.test_dir().Append(FILE_PATH_LITERAL("not_there")));
- ConfigDirPolicyProviderDelegate loader(non_existent_dir,
- POLICY_LEVEL_MANDATORY,
- POLICY_SCOPE_MACHINE);
+ ConfigDirPolicyLoader loader(non_existent_dir, POLICY_SCOPE_MACHINE);
scoped_ptr<PolicyBundle> bundle(loader.Load());
ASSERT_TRUE(bundle.get());
const PolicyBundle kEmptyBundle;
@@ -188,9 +191,7 @@ TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) {
for (unsigned int i = 5; i <= 8; ++i)
harness_.WriteConfigFile(test_dict_bar, base::IntToString(i));
- ConfigDirPolicyProviderDelegate loader(harness_.test_dir(),
- POLICY_LEVEL_MANDATORY,
- POLICY_SCOPE_USER);
+ ConfigDirPolicyLoader loader(harness_.test_dir(), POLICY_SCOPE_USER);
scoped_ptr<PolicyBundle> bundle(loader.Load());
ASSERT_TRUE(bundle.get());
PolicyBundle expected_bundle;
@@ -225,9 +226,7 @@ TEST_F(ConfigDirPolicyLoaderTest, Load3rdParty) {
policy_dict.DeepCopy());
harness_.WriteConfigFile(json_dict, "policy.json");
- ConfigDirPolicyProviderDelegate loader(harness_.test_dir(),
- POLICY_LEVEL_MANDATORY,
- POLICY_SCOPE_USER);
+ ConfigDirPolicyLoader loader(harness_.test_dir(), POLICY_SCOPE_USER);
scoped_ptr<PolicyBundle> bundle(loader.Load());
ASSERT_TRUE(bundle.get());
PolicyMap expected_policy;
« no previous file with comments | « chrome/browser/policy/config_dir_policy_loader.cc ('k') | chrome/browser/policy/config_dir_policy_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698