Index: chrome/browser/policy/configuration_policy_reader_unittest.cc |
diff --git a/chrome/browser/policy/configuration_policy_reader_unittest.cc b/chrome/browser/policy/configuration_policy_reader_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..93c49124f4335dbbf2d8932f4dc1a311b1ca9e45 |
--- /dev/null |
+++ b/chrome/browser/policy/configuration_policy_reader_unittest.cc |
@@ -0,0 +1,313 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
Mattias Nissler (ping if slow)
2011/08/24 11:57:09
I don't think it's required to have test cases for
simo
2011/08/25 10:06:36
Done.
|
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/scoped_ptr.h" |
+#include "base/string16.h" |
+#include "base/utf_string_conversions.h" |
+#include "chrome/browser/policy/configuration_policy_reader.h" |
+#include "chrome/browser/policy/mock_configuration_policy_provider.h" |
+#include "policy/policy_constants.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace policy { |
+ |
+// Holds a set of test parameters, consisting of policy name and type. |
+class TypeAndName { |
+ public: |
+ TypeAndName(ConfigurationPolicyType type, const char* policy_name) |
+ : type_(type), |
+ policy_name_(policy_name) {} |
+ |
+ ConfigurationPolicyType type() const { return type_; } |
+ string16 policy_name() const { return ASCIIToUTF16(policy_name_); } |
+ |
+ private: |
+ ConfigurationPolicyType type_; |
+ const char* policy_name_; |
+}; |
+ |
+template<typename TESTBASE> |
Mattias Nissler (ping if slow)
2011/08/24 11:57:09
It seems TESTBASE is the same in all instantiation
simo
2011/08/25 10:06:36
Done.
|
+class ConfigurationPolicyReaderTestBase : public TESTBASE { |
+ protected: |
+ ConfigurationPolicyReaderTestBase() : provider_() { |
+ managed_reader_.reset(new ConfigurationPolicyReader(&provider_, |
+ PolicyStatusInfo::MANDATORY)); |
+ recommended_reader_.reset(new ConfigurationPolicyReader(&provider_, |
+ PolicyStatusInfo::RECOMMENDED)); |
+ status_ok_ = ASCIIToUTF16("ok"); |
+ } |
+ |
+ DictionaryValue* CreateDictionary(TypeAndName policy) { |
+ DictionaryValue* dict = new DictionaryValue(); |
+ dict->SetString("name", policy.policy_name()); |
Mattias Nissler (ping if slow)
2011/08/24 11:57:09
Use string constants declared in PolicyStatusInfo
simo
2011/08/25 10:06:36
Done.
|
+ dict->SetString("level", |
+ PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::MANDATORY)); |
+ dict->SetString("sourceType", |
+ PolicyStatusInfo::GetSourceTypeString(PolicyStatusInfo::USER)); |
+ dict->SetBoolean("set", true); |
+ dict->SetString("status", status_ok_); |
+ |
+ return dict; |
+ } |
+ |
+ MockConfigurationPolicyProvider provider_; |
+ scoped_ptr<ConfigurationPolicyReader> managed_reader_; |
+ scoped_ptr<ConfigurationPolicyReader> recommended_reader_; |
+ string16 status_ok_; |
+}; |
+ |
+// Test cases for list-valued policy settings. |
+class ConfigurationPolicyReaderListTest : |
+ public ConfigurationPolicyReaderTestBase< |
+ testing::TestWithParam<TypeAndName> > { |
+}; |
+ |
+TEST_P(ConfigurationPolicyReaderListTest, GetDefault) { |
+ EXPECT_EQ(NULL, managed_reader_->GetPolicyStatus(GetParam().type())); |
+} |
+ |
+TEST_P(ConfigurationPolicyReaderListTest, SetValue) { |
+ ListValue* in_value = new ListValue(); |
+ in_value->Append(Value::CreateStringValue("test1")); |
+ in_value->Append(Value::CreateStringValue("test2")); |
+ provider_.AddPolicy(GetParam().type(), in_value); |
+ managed_reader_->OnUpdatePolicy(); |
+ |
+ scoped_ptr<DictionaryValue> dict(CreateDictionary(GetParam())); |
+ dict->Set("value", in_value->DeepCopy()); |
+ EXPECT_TRUE( |
+ dict->Equals(managed_reader_->GetPolicyStatus(GetParam().type()))); |
+ |
+ recommended_reader_->OnUpdatePolicy(); |
+ dict->SetString("level", |
+ PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); |
+ EXPECT_TRUE(dict->Equals( |
+ recommended_reader_->GetPolicyStatus(GetParam().type()))); |
+} |
+ |
+INSTANTIATE_TEST_CASE_P( |
+ ConfigurationPolicyReaderListTestInstance, |
+ ConfigurationPolicyReaderListTest, |
+ testing::Values( |
+ TypeAndName(kPolicyRestoreOnStartupURLs, |
+ key::kRestoreOnStartupURLs), |
+ TypeAndName(kPolicyExtensionInstallWhitelist, |
+ key::kExtensionInstallWhitelist), |
+ TypeAndName(kPolicyExtensionInstallBlacklist, |
+ key::kExtensionInstallBlacklist), |
+ TypeAndName(kPolicyDisabledPlugins, |
+ key::kDisabledPlugins), |
+ TypeAndName(kPolicyDisabledPluginsExceptions, |
+ key::kDisabledPluginsExceptions), |
+ TypeAndName(kPolicyEnabledPlugins, |
+ key::kEnabledPlugins), |
+ TypeAndName(kPolicyDisabledSchemes, |
+ key::kDisabledSchemes))); |
+ |
+// Test cases for string-valued policy settings. |
+class ConfigurationPolicyReaderStringTest : |
+ public ConfigurationPolicyReaderTestBase< |
+ testing::TestWithParam<TypeAndName> > { |
+}; |
+ |
+TEST_P(ConfigurationPolicyReaderStringTest, GetDefault) { |
+ EXPECT_EQ(NULL, managed_reader_->GetPolicyStatus(GetParam().type())); |
+} |
+ |
+TEST_P(ConfigurationPolicyReaderStringTest, SetValue) { |
+ provider_.AddPolicy(GetParam().type(), |
+ Value::CreateStringValue("http://chromium.org")); |
+ managed_reader_->OnUpdatePolicy(); |
+ scoped_ptr<DictionaryValue> dict(CreateDictionary(GetParam())); |
+ dict->Set("value", Value::CreateStringValue("http://chromium.org")); |
+ EXPECT_TRUE( |
+ dict->Equals(managed_reader_->GetPolicyStatus(GetParam().type()))); |
+ |
+ recommended_reader_->OnUpdatePolicy(); |
+ dict->SetString("level", |
+ PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); |
+ EXPECT_TRUE(dict->Equals( |
+ recommended_reader_->GetPolicyStatus(GetParam().type()))); |
+} |
+ |
+INSTANTIATE_TEST_CASE_P( |
+ ConfigurationPolicyReaderStringTestInstance, |
+ ConfigurationPolicyReaderStringTest, |
+ testing::Values( |
+ TypeAndName(kPolicyHomepageLocation, |
+ key::kHomepageLocation), |
+ TypeAndName(kPolicyApplicationLocaleValue, |
+ key::kApplicationLocaleValue), |
+ TypeAndName(kPolicyAuthSchemes, |
+ key::kAuthSchemes), |
+ TypeAndName(kPolicyAuthServerWhitelist, |
+ key::kAuthServerWhitelist), |
+ TypeAndName(kPolicyAuthNegotiateDelegateWhitelist, |
+ key::kAuthNegotiateDelegateWhitelist), |
+ TypeAndName(kPolicyGSSAPILibraryName, |
+ key::kGSSAPILibraryName), |
+ TypeAndName(kPolicyDiskCacheDir, |
+ key::kDiskCacheDir))); |
+ |
+#if !defined(OS_CHROMEOS) |
+INSTANTIATE_TEST_CASE_P( |
+ ConfigurationPolicyReaderDownloadDirectoryInstance, |
+ ConfigurationPolicyReaderStringTest, |
+ testing::Values(TypeAndName(kPolicyDownloadDirectory, |
+ key::kDownloadDirectory))); |
+#endif // !defined(OS_CHROMEOS) |
+ |
+// Test cases for boolean-valued policy settings. |
+class ConfigurationPolicyReaderBooleanTest : |
+ public ConfigurationPolicyReaderTestBase< |
+ testing::TestWithParam<TypeAndName> > { |
+}; |
+ |
+TEST_P(ConfigurationPolicyReaderBooleanTest, GetDefault) { |
+ EXPECT_EQ(NULL, managed_reader_->GetPolicyStatus(GetParam().type())); |
+} |
+ |
+TEST_P(ConfigurationPolicyReaderBooleanTest, SetValue) { |
+ provider_.AddPolicy(GetParam().type(), Value::CreateBooleanValue(true)); |
+ managed_reader_->OnUpdatePolicy(); |
+ scoped_ptr<DictionaryValue> dict(CreateDictionary(GetParam())); |
+ dict->Set("value", Value::CreateBooleanValue(true)); |
+ EXPECT_TRUE(dict->Equals( |
+ managed_reader_->GetPolicyStatus(GetParam().type()))); |
+ |
+ recommended_reader_->OnUpdatePolicy(); |
+ dict->SetString("level", |
+ PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); |
+ EXPECT_TRUE(dict->Equals( |
+ recommended_reader_->GetPolicyStatus(GetParam().type()))); |
+ |
+ provider_.AddPolicy(GetParam().type(), Value::CreateBooleanValue(false)); |
+ managed_reader_->OnUpdatePolicy(); |
+ dict->Set("value", Value::CreateBooleanValue(false)); |
+ dict->SetString("level", |
+ PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::MANDATORY)); |
+ EXPECT_TRUE( |
+ dict->Equals(managed_reader_->GetPolicyStatus(GetParam().type()))); |
+ |
+ recommended_reader_->OnUpdatePolicy(); |
+ dict->SetString("level", |
+ PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); |
+ EXPECT_TRUE(dict->Equals( |
+ recommended_reader_->GetPolicyStatus(GetParam().type()))); |
+} |
+ |
+INSTANTIATE_TEST_CASE_P( |
+ ConfigurationPolicyReaderBooleanTestInstance, |
+ ConfigurationPolicyReaderBooleanTest, |
+ testing::Values( |
+ TypeAndName(kPolicyHomepageIsNewTabPage, |
+ key::kHomepageIsNewTabPage), |
+ TypeAndName(kPolicyAlternateErrorPagesEnabled, |
+ key::kAlternateErrorPagesEnabled), |
+ TypeAndName(kPolicySearchSuggestEnabled, |
+ key::kSearchSuggestEnabled), |
+ TypeAndName(kPolicyDnsPrefetchingEnabled, |
+ key::kDnsPrefetchingEnabled), |
+ TypeAndName(kPolicyDisableSpdy, |
+ key::kDisableSpdy), |
+ TypeAndName(kPolicySafeBrowsingEnabled, |
+ key::kSafeBrowsingEnabled), |
+ TypeAndName(kPolicyMetricsReportingEnabled, |
+ key::kMetricsReportingEnabled), |
+ TypeAndName(kPolicyPasswordManagerEnabled, |
+ key::kPasswordManagerEnabled), |
+ TypeAndName(kPolicyPasswordManagerAllowShowPasswords, |
+ key::kPasswordManagerAllowShowPasswords), |
+ TypeAndName(kPolicyShowHomeButton, |
+ key::kShowHomeButton), |
+ TypeAndName(kPolicyPrintingEnabled, |
+ key::kPrintingEnabled), |
+ TypeAndName(kPolicyJavascriptEnabled, |
+ key::kJavascriptEnabled), |
+ TypeAndName(kPolicyRemoteAccessClientFirewallTraversal, |
+ key::kRemoteAccessClientFirewallTraversal), |
+ TypeAndName(kPolicyRemoteAccessHostFirewallTraversal, |
+ key::kRemoteAccessHostFirewallTraversal), |
+ TypeAndName(kPolicyCloudPrintProxyEnabled, |
+ key::kCloudPrintProxyEnabled), |
+ TypeAndName(kPolicySavingBrowserHistoryDisabled, |
+ key::kSavingBrowserHistoryDisabled), |
+ TypeAndName(kPolicySavingBrowserHistoryDisabled, |
+ key::kSavingBrowserHistoryDisabled), |
+ TypeAndName(kPolicyDisableAuthNegotiateCnameLookup, |
+ key::kDisableAuthNegotiateCnameLookup), |
+ TypeAndName(kPolicyEnableAuthNegotiatePort, |
+ key::kEnableAuthNegotiatePort), |
+ TypeAndName(kPolicyInstantEnabled, |
+ key::kInstantEnabled), |
+ TypeAndName(kPolicyDisablePluginFinder, |
+ key::kDisablePluginFinder), |
+ TypeAndName(kPolicyClearSiteDataOnExit, |
+ key::kClearSiteDataOnExit), |
+ TypeAndName(kPolicyDefaultBrowserSettingEnabled, |
+ key::kDefaultBrowserSettingEnabled), |
+ TypeAndName(kPolicyDisable3DAPIs, |
+ key::kDisable3DAPIs), |
+ TypeAndName(kPolicyTranslateEnabled, |
+ key::kTranslateEnabled), |
+ TypeAndName(kPolicyAllowOutdatedPlugins, |
+ key::kAllowOutdatedPlugins), |
+ TypeAndName(kPolicyAlwaysAuthorizePlugins, |
+ key::kAlwaysAuthorizePlugins), |
+ TypeAndName(kPolicyBookmarkBarEnabled, |
+ key::kBookmarkBarEnabled), |
+ TypeAndName(kPolicyEditBookmarksEnabled, |
+ key::kEditBookmarksEnabled), |
+ TypeAndName(kPolicyAllowFileSelectionDialogs, |
+ key::kAllowFileSelectionDialogs), |
+ TypeAndName(kPolicyAllowCrossOriginAuthPrompt, |
+ key::kAllowCrossOriginAuthPrompt))); |
+ |
+#if defined(OS_CHROMEOS) |
+INSTANTIATE_TEST_CASE_P( |
+ CrosConfigurationPolicyReaderBooleanTestInstance, |
+ ConfigurationPolicyReaderBooleanTest, |
+ testing::Values( |
+ TypeAndName(kPolicyChromeOsLockOnIdleSuspend, |
+ key::kEnableScreenLock))); |
+#endif // defined(OS_CHROMEOS) |
+ |
+// Test cases for integer-valued policy settings. |
+class ConfigurationPolicyReaderIntegerTest : |
+ public ConfigurationPolicyReaderTestBase< |
+ testing::TestWithParam<TypeAndName> > { |
+}; |
+ |
+TEST_P(ConfigurationPolicyReaderIntegerTest, GetDefault) { |
+ EXPECT_EQ(NULL, managed_reader_->GetPolicyStatus(GetParam().type())); |
+} |
+ |
+TEST_P(ConfigurationPolicyReaderIntegerTest, SetValue) { |
+ provider_.AddPolicy(GetParam().type(), Value::CreateIntegerValue(3)); |
+ managed_reader_->OnUpdatePolicy(); |
+ scoped_ptr<DictionaryValue> dict(CreateDictionary(GetParam())); |
+ dict->Set("value", Value::CreateIntegerValue(3)); |
+ |
+ EXPECT_TRUE(dict->Equals( |
+ managed_reader_->GetPolicyStatus(GetParam().type()))); |
+ |
+ recommended_reader_->OnUpdatePolicy(); |
+ dict->SetString("level", |
+ PolicyStatusInfo::GetPolicyLevelString(PolicyStatusInfo::RECOMMENDED)); |
+ EXPECT_TRUE(dict->Equals( |
+ recommended_reader_->GetPolicyStatus(GetParam().type()))); |
+} |
+ |
+INSTANTIATE_TEST_CASE_P( |
+ ConfigurationPolicyReaderIntegerTestInstance, |
+ ConfigurationPolicyReaderIntegerTest, |
+ testing::Values( |
+ TypeAndName(kPolicyRestoreOnStartup, |
+ key::kRestoreOnStartup), |
+ TypeAndName(kPolicyPolicyRefreshRate, |
+ key::kPolicyRefreshRate), |
+ TypeAndName(kPolicyMaxConnectionsPerProxy, |
+ key::kMaxConnectionsPerProxy))); |
+ |
+} // namespace policy |