Chromium Code Reviews| Index: chrome/browser/policy/managed_mode_policy_provider_unittest.cc |
| diff --git a/chrome/browser/policy/managed_mode_policy_provider_unittest.cc b/chrome/browser/policy/managed_mode_policy_provider_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..51dacaf5e0882a57d61a0f416d6e6e87166aebc8 |
| --- /dev/null |
| +++ b/chrome/browser/policy/managed_mode_policy_provider_unittest.cc |
| @@ -0,0 +1,131 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/policy/managed_mode_policy_provider.h" |
| +#include "chrome/browser/policy/configuration_policy_provider_test.h" |
|
Mattias Nissler (ping if slow)
2012/06/12 02:58:54
alphabetize (or blank line between managed_mode_po
Bernhard Bauer
2012/06/12 21:27:18
Done.
|
| +#include "chrome/browser/policy/policy_bundle.h" |
| +#include "chrome/browser/policy/policy_map.h" |
| +#include "chrome/browser/prefs/testing_pref_store.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +const char kPolicies[] = "policies"; |
| + |
| +namespace policy { |
| + |
| +namespace { |
| + |
| +class TestHarness : public PolicyProviderTestHarness { |
| + public: |
| + TestHarness(); |
| + virtual ~TestHarness(); |
| + |
| + static PolicyProviderTestHarness* Create(); |
| + |
| + virtual void SetUp() OVERRIDE; |
| + |
| + // PolicyProviderTestHarness implementation: |
| + virtual ConfigurationPolicyProvider* CreateProvider( |
| + const PolicyDefinitionList* policy_definition_list) OVERRIDE; |
| + |
| + virtual void InstallEmptyPolicy() OVERRIDE; |
| + virtual void InstallStringPolicy(const std::string& policy_name, |
| + const std::string& policy_value) OVERRIDE; |
| + virtual void InstallIntegerPolicy(const std::string& policy_name, |
| + int policy_value) OVERRIDE; |
| + virtual void InstallBooleanPolicy(const std::string& policy_name, |
| + bool policy_value) OVERRIDE; |
| + virtual void InstallStringListPolicy( |
| + const std::string& policy_name, |
| + const base::ListValue* policy_value) OVERRIDE; |
| + virtual void InstallDictionaryPolicy( |
| + const std::string& policy_name, |
| + const base::DictionaryValue* policy_value) OVERRIDE; |
| + |
| + private: |
| + void InstallPolicy(const std::string& policy_name, base::Value* policy_value); |
| + |
| + scoped_refptr<TestingPrefStore> pref_store_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestHarness); |
| +}; |
| + |
| +TestHarness::TestHarness() |
| + : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER), |
| + pref_store_(new TestingPrefStore) {} |
| + |
| +TestHarness::~TestHarness() {} |
| + |
| +// static |
| +PolicyProviderTestHarness* TestHarness::Create() { |
| + return new TestHarness(); |
| +} |
| + |
| +void TestHarness::SetUp() { |
| +} |
| + |
| +ConfigurationPolicyProvider* TestHarness::CreateProvider( |
| + const PolicyDefinitionList* policy_definition_list) { |
| + return new ManagedModePolicyProvider(pref_store_); |
| +} |
| + |
| +void TestHarness::InstallEmptyPolicy() {} |
| + |
| +void TestHarness::InstallStringPolicy(const std::string& policy_name, |
| + const std::string& policy_value) { |
| + InstallPolicy(policy_name, base::Value::CreateStringValue(policy_value)); |
| +} |
| + |
| +void TestHarness::InstallIntegerPolicy(const std::string& policy_name, |
| + int policy_value) { |
| + InstallPolicy(policy_name, base::Value::CreateIntegerValue(policy_value)); |
| +} |
| + |
| +void TestHarness::InstallBooleanPolicy(const std::string& policy_name, |
| + bool policy_value) { |
| + InstallPolicy(policy_name, base::Value::CreateBooleanValue(policy_value)); |
| +} |
| + |
| +void TestHarness::InstallStringListPolicy(const std::string& policy_name, |
| + const base::ListValue* policy_value) { |
| + InstallPolicy(policy_name, policy_value->DeepCopy()); |
| +} |
| + |
| +void TestHarness::InstallDictionaryPolicy( |
| + const std::string& policy_name, |
| + const base::DictionaryValue* policy_value) { |
| + InstallPolicy(policy_name, policy_value->DeepCopy()); |
| +} |
| + |
| +void TestHarness::InstallPolicy(const std::string& policy_name, |
| + base::Value* policy_value) { |
| + base::DictionaryValue* cached_policy = NULL; |
| + base::Value* value = NULL; |
| + PrefStore::ReadResult result = |
| + pref_store_->GetMutableValue(ManagedModePolicyProvider::kPolicies, |
| + &value); |
| + switch (result) { |
| + case PrefStore::READ_NO_VALUE: |
| + cached_policy = new base::DictionaryValue; |
| + pref_store_->SetValue(ManagedModePolicyProvider::kPolicies, |
| + cached_policy); |
| + break; |
| + case PrefStore::READ_OK: |
| + ASSERT_TRUE(value->GetAsDictionary(&cached_policy)); |
| + break; |
| + default: |
| + FAIL() << "Invalid result reading policy: " << result; |
| + return; |
| + } |
| + cached_policy->SetWithoutPathExpansion(policy_name, policy_value); |
| +} |
| + |
| +} // namespace |
| + |
| +// Instantiate abstract test case for basic policy reading tests. |
| +INSTANTIATE_TEST_CASE_P( |
| + ManagedModeConfigurationPolicyProviderTest, |
| + ConfigurationPolicyProviderTest, |
| + testing::Values(TestHarness::Create)); |
|
Mattias Nissler (ping if slow)
2012/06/12 02:58:54
Can you please also add test cases for the interfa
Bernhard Bauer
2012/06/12 21:27:18
Done.
|
| + |
| +} // namespace policy |