diff options
author | danno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 11:04:50 +0000 |
---|---|---|
committer | danno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-21 11:04:50 +0000 |
commit | 633877bd6ded864ddc9d89487a7e34c1fcf0b17f (patch) | |
tree | 94bef71e7670430e2498926ebe02ef31989d4f6a | |
parent | 5eac6029cdecb6e15a014f8185f0bac5e118418f (diff) | |
download | chromium_src-633877bd6ded864ddc9d89487a7e34c1fcf0b17f.zip chromium_src-633877bd6ded864ddc9d89487a7e34c1fcf0b17f.tar.gz chromium_src-633877bd6ded864ddc9d89487a7e34c1fcf0b17f.tar.bz2 |
[Win] Implement core mechanism to honor Windows Group Policy
BUG=42640
TEST=--gtest_filter=WinConfigurationPolicyProviderTest*
Review URL: http://codereview.chromium.org/2119005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47910 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/configuration_policy_pref_store.cc | 2 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_pref_store_unittest.cc | 2 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_provider.cc | 4 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_provider.h | 3 | ||||
-rwxr-xr-x | chrome/browser/configuration_policy_provider_win.cc | 158 | ||||
-rwxr-xr-x | chrome/browser/configuration_policy_provider_win.h | 57 | ||||
-rwxr-xr-x | chrome/browser/configuration_policy_provider_win_unittest.cc | 294 | ||||
-rw-r--r-- | chrome/browser/configuration_policy_store.h | 2 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 6 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 |
10 files changed, 521 insertions, 8 deletions
diff --git a/chrome/browser/configuration_policy_pref_store.cc b/chrome/browser/configuration_policy_pref_store.cc index c883b70..9a3a6e5 100644 --- a/chrome/browser/configuration_policy_pref_store.cc +++ b/chrome/browser/configuration_policy_pref_store.cc @@ -14,7 +14,7 @@ ConfigurationPolicyPrefStore::simple_policy_map_[] = { { Value::TYPE_STRING, kPolicyHomePage, prefs::kHomePage }, { Value::TYPE_BOOLEAN, kPolicyHomepageIsNewTabPage, prefs::kHomePageIsNewTabPage }, - { Value::TYPE_INTEGER, kPolicyCookiesEnabled, prefs::kCookieBehavior } + { Value::TYPE_INTEGER, kPolicyCookiesMode, prefs::kCookieBehavior } }; ConfigurationPolicyPrefStore::ConfigurationPolicyPrefStore( diff --git a/chrome/browser/configuration_policy_pref_store_unittest.cc b/chrome/browser/configuration_policy_pref_store_unittest.cc index 1544b18..2074857 100644 --- a/chrome/browser/configuration_policy_pref_store_unittest.cc +++ b/chrome/browser/configuration_policy_pref_store_unittest.cc @@ -56,7 +56,7 @@ TEST(ConfigurationPolicyPrefStoreTest, TestSettingCookiesEnabledDefault) { TEST(ConfigurationPolicyPrefStoreTest, TestSettingCookiesEnabledOverride) { ConfigurationPolicyPrefStore store(0); - store.Apply(ConfigurationPolicyPrefStore::kPolicyCookiesEnabled, + store.Apply(ConfigurationPolicyPrefStore::kPolicyCookiesMode, Value::CreateIntegerValue(2)); int result = 0; store.prefs()->GetInteger(prefs::kCookieBehavior, &result); diff --git a/chrome/browser/configuration_policy_provider.cc b/chrome/browser/configuration_policy_provider.cc index 1b9a5a8..a47e8e2 100644 --- a/chrome/browser/configuration_policy_provider.cc +++ b/chrome/browser/configuration_policy_provider.cc @@ -20,8 +20,8 @@ const PolicyValueTreeMappingEntry kPolicyValueTreeMapping[] = { Value::TYPE_STRING, L"homepage" }, { ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, Value::TYPE_BOOLEAN, L"homepage_is_newtabpage" }, - { ConfigurationPolicyStore::kPolicyCookiesEnabled, - Value::TYPE_BOOLEAN, L"cookies_enabled" } + { ConfigurationPolicyStore::kPolicyCookiesMode, + Value::TYPE_INTEGER, L"cookies_enabled" } }; } diff --git a/chrome/browser/configuration_policy_provider.h b/chrome/browser/configuration_policy_provider.h index daf5cb4..aedc4e7 100644 --- a/chrome/browser/configuration_policy_provider.h +++ b/chrome/browser/configuration_policy_provider.h @@ -22,7 +22,7 @@ class ConfigurationPolicyProvider { // provider-specific policy decisions. The preference service // invokes this |Provide| method when it needs a policy // provider to specify its policy choices. In |Provide|, - // the ConfigurationPolicyProvider must make calls to the + // the |ConfigurationPolicyProvider| must make calls to the // |Apply| method of |store| to apply specific policies. // Returns true if the policy could be provided, otherwise false. virtual bool Provide(ConfigurationPolicyStore* store) = 0; @@ -38,3 +38,4 @@ void DecodePolicyValueTree(DictionaryValue* policies, ConfigurationPolicyStore* store); #endif // CHROME_BROWSER_CONFIGURATION_POLICY_PROVIDER_H_ + diff --git a/chrome/browser/configuration_policy_provider_win.cc b/chrome/browser/configuration_policy_provider_win.cc new file mode 100755 index 0000000..f64ea63 --- /dev/null +++ b/chrome/browser/configuration_policy_provider_win.cc @@ -0,0 +1,158 @@ +// Copyright (c) 2010 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/configuration_policy_provider_win.h" + +#include <algorithm> + +#include "base/logging.h" +#include "base/registry.h" +#include "base/scoped_ptr.h" +#include "base/sys_string_conversions.h" +#include "base/values.h" + +const wchar_t WinConfigurationPolicyProvider::kHomepageRegistryValueName[] = + L"Homepage"; +const wchar_t WinConfigurationPolicyProvider:: + kHomepageIsNewTabPageRegistryValueName[] = L"HomepageIsNewTabPage"; +const wchar_t WinConfigurationPolicyProvider::kCookiesModeRegistryValueName[] = + L"CookiesMode"; + +#if defined(GOOGLE_CHROME_BUILD) +const wchar_t WinConfigurationPolicyProvider::kPolicyRegistrySubKey[] = + L"SOFTWARE\\Policies\\Google\\Google Chrome"; +#else +const wchar_t WinConfigurationPolicyProvider::kPolicyRegistrySubKey[] = + L"SOFTWARE\\Policies\\Chromium"; +#endif + +WinConfigurationPolicyProvider::WinConfigurationPolicyProvider() { +} + +bool WinConfigurationPolicyProvider::GetRegistryPolicyString( + const wchar_t* value_name, string16* result) { + DWORD value_size = 0; + DWORD key_type = 0; + scoped_array<uint8> buffer; + RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); + if (hkcu_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) { + if (key_type != REG_SZ) + return false; + // According to the Microsoft documentation, the string + // buffer may not be explicitly 0-terminated. Allocate a + // slightly larger buffer and prefill to zeros to guarantee + // the 0-termination. + buffer.reset(new uint8[value_size + 2]); + memset(buffer.get(), 0, value_size + 2); + hkcu_policy_key.ReadValue(value_name, buffer.get(), &value_size); + } else { + RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); + if (hklm_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) { + if (key_type != REG_SZ) + return false; + // According to the Microsoft documentation, the string + // buffer may not be explicitly 0-terminated. Allocate a + // slightly larger buffer and prefill to zeros to guarantee + // the 0-termination. + buffer.reset(new uint8[value_size + 2]); + memset(buffer.get(), 0, value_size + 2); + hklm_policy_key.ReadValue(value_name, buffer.get(), &value_size); + } else { + return false; + } + } + + result->assign(reinterpret_cast<const wchar_t*>(buffer.get())); + return true; +} + +bool WinConfigurationPolicyProvider::GetRegistryPolicyBoolean( + const wchar_t* value_name, bool* result) { + DWORD value; + RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); + if (hkcu_policy_key.ReadValueDW(value_name, &value)) { + *result = value != 0; + return true; + } + + RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); + if (hklm_policy_key.ReadValueDW(value_name, &value)) { + *result = value != 0; + return true; + } + return false; +} + +bool WinConfigurationPolicyProvider::GetRegistryPolicyInteger( + const wchar_t* value_name, uint32* result) { + DWORD value; + RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); + if (hkcu_policy_key.ReadValueDW(value_name, &value)) { + *result = value; + return true; + } + + RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); + if (hklm_policy_key.ReadValueDW(value_name, &value)) { + *result = value; + return true; + } + return false; +} + +const WinConfigurationPolicyProvider::RegistryPolicyMapEntry + WinConfigurationPolicyProvider::registry_to_policy_map_[] = { + { Value::TYPE_STRING, + ConfigurationPolicyStore::kPolicyHomePage, + kHomepageRegistryValueName }, + { Value::TYPE_BOOLEAN, + ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, + kHomepageIsNewTabPageRegistryValueName }, + { Value::TYPE_INTEGER, + ConfigurationPolicyStore::kPolicyCookiesMode, + kCookiesModeRegistryValueName }, +}; + +bool WinConfigurationPolicyProvider::Provide( + ConfigurationPolicyStore* store) { + const RegistryPolicyMapEntry* current; + const RegistryPolicyMapEntry* end = registry_to_policy_map_ + + arraysize(registry_to_policy_map_); + + for (current = registry_to_policy_map_; current != end; ++current) { + std::wstring string_value; + uint32 int_value; + bool bool_value; + switch (current->value_type) { + case Value::TYPE_STRING: + if (GetRegistryPolicyString(current->registry_value_name, + &string_value)) { + store->Apply( + current->policy_type, + Value::CreateStringValueFromUTF16(string_value)); + } + break; + case Value::TYPE_BOOLEAN: + if (GetRegistryPolicyBoolean(current->registry_value_name, + &bool_value)) { + store->Apply(current->policy_type, + Value::CreateBooleanValue(bool_value)); + } + break; + case Value::TYPE_INTEGER: + if (GetRegistryPolicyInteger(current->registry_value_name, + &int_value)) { + store->Apply(current->policy_type, + Value::CreateIntegerValue(int_value)); + } + break; + default: + NOTREACHED(); + return false; + } + } + + return true; +} + diff --git a/chrome/browser/configuration_policy_provider_win.h b/chrome/browser/configuration_policy_provider_win.h new file mode 100755 index 0000000..ccf8a24 --- /dev/null +++ b/chrome/browser/configuration_policy_provider_win.h @@ -0,0 +1,57 @@ +// Copyright (c) 2010 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. + +#ifndef CHROME_BROWSER_CONFIGURATION_POLICY_PROVIDER_WIN_H_ +#define CHROME_BROWSER_CONFIGURATION_POLICY_PROVIDER_WIN_H_ + +#include "chrome/browser/configuration_policy_store.h" +#include "chrome/browser/configuration_policy_provider.h" + +// An implementation of |ConfigurationPolicyProvider| using the +// mechanism provided by Windows Groups Policy. Policy decisions are +// stored as values in a special section of the Windows Registry. +// On a managed machine in a domain, this portion of the registry is +// periodically updated by the Windows Group Policy machinery to contain +// the latest version of the policy set by administrators. +class WinConfigurationPolicyProvider : public ConfigurationPolicyProvider { + public: + WinConfigurationPolicyProvider(); + virtual ~WinConfigurationPolicyProvider() { } + + // ConfigurationPolicyProvider method overrides: + virtual bool Provide(ConfigurationPolicyStore* store); + + protected: + // The sub key path for Chromiums's Group Policy information in the + // Windows registry. + static const wchar_t kPolicyRegistrySubKey[]; + + // Constants specifying the names of policy-specifying registry values + // in |kChromiumPolicySubKey|. + static const wchar_t kHomepageRegistryValueName[]; + static const wchar_t kHomepageIsNewTabPageRegistryValueName[]; + static const wchar_t kCookiesModeRegistryValueName[]; + + private: + // For each Group Policy registry value that maps to a browser policy, there + // is an entry in |registry_to_policy_map_| of type |RegistryPolicyMapEntry| + // that specifies the registry value name and the browser policy that it + // maps to. + struct RegistryPolicyMapEntry { + Value::ValueType value_type; + ConfigurationPolicyStore::PolicyType policy_type; + const wchar_t* registry_value_name; + }; + + static const RegistryPolicyMapEntry registry_to_policy_map_[]; + + // Methods to perfrom type-specific policy lookups in the registry + // HKLM is checked fist, then HKLM. + bool GetRegistryPolicyString(const wchar_t* value_name, string16* result); + bool GetRegistryPolicyBoolean(const wchar_t* value_name, bool* result); + bool GetRegistryPolicyInteger(const wchar_t* value_name, uint32* result); +}; + +#endif // CHROME_BROWSER_CONFIGURATION_POLICY_PROVIDER_WIN_H_ + diff --git a/chrome/browser/configuration_policy_provider_win_unittest.cc b/chrome/browser/configuration_policy_provider_win_unittest.cc new file mode 100755 index 0000000..7302b96 --- /dev/null +++ b/chrome/browser/configuration_policy_provider_win_unittest.cc @@ -0,0 +1,294 @@ +// Copyright (c) 2010 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 <gtest/gtest.h> + +#include <windows.h> + +#include "base/logging.h" +#include "base/registry.h" +#include "base/scoped_ptr.h" +#include "chrome/browser/configuration_policy_provider_win.h" +#include "chrome/browser/mock_configuration_policy_store.h" +#include "chrome/common/pref_names.h" + +namespace { +const wchar_t kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; +const wchar_t kUnitTestMachineOverrideSubKey[] = + L"SOFTWARE\\Chromium Unit Tests\\HKLM Override"; +const wchar_t kUnitTestUserOverrideSubKey[] = + L"SOFTWARE\\Chromium Unit Tests\\HKCU Override"; +} + +// A subclass of |WinConfigurationPolicyProvider| providing access to +// internal protected constants without an orgy of FRIEND_TESTS. +class TestWinConfigurationPolicyProvider + : public WinConfigurationPolicyProvider { + public: + TestWinConfigurationPolicyProvider() : WinConfigurationPolicyProvider() { } + virtual ~TestWinConfigurationPolicyProvider() { } + + void SetHomepageRegistryValue(HKEY hive, const wchar_t* value); + void SetHomepageRegistryValueWrongType(HKEY hive); + void SetHomepageIsNewTabPage(HKEY hive, bool value); + void SetCookiesMode(HKEY hive, uint32 value); +}; + +void TestWinConfigurationPolicyProvider::SetHomepageRegistryValue( + HKEY hive, + const wchar_t* value) { + RegKey key(hive, + WinConfigurationPolicyProvider::kPolicyRegistrySubKey, + KEY_ALL_ACCESS); + EXPECT_TRUE(key.WriteValue( + WinConfigurationPolicyProvider::kHomepageRegistryValueName, + value)); +} + +void TestWinConfigurationPolicyProvider::SetHomepageRegistryValueWrongType( + HKEY hive) { + RegKey key(hive, + WinConfigurationPolicyProvider::kPolicyRegistrySubKey, + KEY_ALL_ACCESS); + EXPECT_TRUE(key.WriteValue( + WinConfigurationPolicyProvider::kHomepageRegistryValueName, + 5)); +} + +void TestWinConfigurationPolicyProvider::SetHomepageIsNewTabPage( + HKEY hive, + bool value) { + RegKey key(hive, + WinConfigurationPolicyProvider::kPolicyRegistrySubKey, + KEY_ALL_ACCESS); + EXPECT_TRUE(key.WriteValue( + WinConfigurationPolicyProvider::kHomepageIsNewTabPageRegistryValueName, + value)); +} + +void TestWinConfigurationPolicyProvider::SetCookiesMode( + HKEY hive, + uint32 value) { + RegKey key(hive, + WinConfigurationPolicyProvider::kPolicyRegistrySubKey, + KEY_ALL_ACCESS); + EXPECT_TRUE(key.WriteValue( + WinConfigurationPolicyProvider::kCookiesModeRegistryValueName, + value)); +} + +// This test class provides sandboxing and mocking for the parts of the +// Windows Registry implementing Group Policy. The |SetUp| method prepares +// two temporary sandbox keys in |kUnitTestRegistrySubKey|, one for HKLM and one +// for HKCU. A test's calls to the registry are redirected by Windows to these +// sandboxes, allowing the tests to manipulate and access policy as if it +// were active, but without actually changing the parts of the Registry that +// are managed by Group Policy. +class WinConfigurationPolicyProviderTest : public testing::Test { + public: + WinConfigurationPolicyProviderTest(); + + // testing::Test method overrides: + virtual void SetUp(); + virtual void TearDown(); + + void ActivateOverrides(); + void DeactivateOverrides(); + + // Deletes the registry key created during the tests. + void DeleteRegistrySandbox(); + + private: + // Keys are created for the lifetime of a test to contain + // the sandboxed HKCU and HKLM hives, respectively. + RegKey temp_hkcu_hive_key_; + RegKey temp_hklm_hive_key_; +}; + +WinConfigurationPolicyProviderTest::WinConfigurationPolicyProviderTest() + : temp_hklm_hive_key_(HKEY_CURRENT_USER, kUnitTestMachineOverrideSubKey), + temp_hkcu_hive_key_(HKEY_CURRENT_USER, kUnitTestUserOverrideSubKey) { +} + +void WinConfigurationPolicyProviderTest::SetUp() { + // Cleanup any remnants of previous tests. + DeleteRegistrySandbox(); + + // Create the subkeys to hold the overridden HKLM and HKCU + // policy settings. + temp_hklm_hive_key_.Create(HKEY_CURRENT_USER, + kUnitTestMachineOverrideSubKey, + KEY_ALL_ACCESS); + temp_hkcu_hive_key_.Create(HKEY_CURRENT_USER, + kUnitTestUserOverrideSubKey, + KEY_ALL_ACCESS); + + ActivateOverrides(); +} + +void WinConfigurationPolicyProviderTest::ActivateOverrides() { + HRESULT result = RegOverridePredefKey(HKEY_LOCAL_MACHINE, + temp_hklm_hive_key_.Handle()); + EXPECT_EQ(ERROR_SUCCESS, result); + result = RegOverridePredefKey(HKEY_CURRENT_USER, + temp_hkcu_hive_key_.Handle()); + EXPECT_EQ(ERROR_SUCCESS, result); +} + +void WinConfigurationPolicyProviderTest::DeactivateOverrides() { + uint32 result = RegOverridePredefKey(HKEY_LOCAL_MACHINE, 0); + EXPECT_EQ(ERROR_SUCCESS, result); + result = RegOverridePredefKey(HKEY_CURRENT_USER, 0); + EXPECT_EQ(ERROR_SUCCESS, result); +} + +void WinConfigurationPolicyProviderTest::TearDown() { + DeactivateOverrides(); + DeleteRegistrySandbox(); +} + +void WinConfigurationPolicyProviderTest::DeleteRegistrySandbox() { + temp_hklm_hive_key_.Close(); + temp_hkcu_hive_key_.Close(); + RegKey key(HKEY_CURRENT_USER, kUnitTestRegistrySubKey, KEY_ALL_ACCESS); + key.DeleteKey(L""); +} +TEST_F(WinConfigurationPolicyProviderTest, TestHomePagePolicyDefault) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyHomePage); + EXPECT_TRUE(i == map.end()); +} + +TEST_F(WinConfigurationPolicyProviderTest, TestHomePagePolicyHKCU) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + provider.SetHomepageRegistryValue(HKEY_CURRENT_USER, + L"http://chromium.org"); + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyHomePage); + EXPECT_TRUE(i != map.end()); + string16 value; + i->second->GetAsString(&value); + EXPECT_EQ(L"http://chromium.org", value); +} + +TEST_F(WinConfigurationPolicyProviderTest, TestHomePagePolicyHKCUWrongType) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + provider.SetHomepageRegistryValueWrongType(HKEY_CURRENT_USER); + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyHomePage); + EXPECT_TRUE(i == map.end()); +} + +TEST_F(WinConfigurationPolicyProviderTest, TestHomePagePolicyHKLM) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + provider.SetHomepageRegistryValue(HKEY_LOCAL_MACHINE, + L"http://chromium.org"); + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyHomePage); + EXPECT_TRUE(i != map.end()); + string16 value; + i->second->GetAsString(&value); + EXPECT_EQ(L"http://chromium.org", value); +} + +TEST_F(WinConfigurationPolicyProviderTest, TestHomePagePolicyHKLMOverHKCU) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + provider.SetHomepageRegistryValue(HKEY_CURRENT_USER, + L"http://chromium.org"); + provider.SetHomepageRegistryValue(HKEY_LOCAL_MACHINE, + L"http://crbug.com"); + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyHomePage); + EXPECT_TRUE(i != map.end()); + string16 value; + i->second->GetAsString(&value); + EXPECT_EQ(L"http://crbug.com", value); +} + +TEST_F(WinConfigurationPolicyProviderTest, + TestHomepageIsNewTabPagePolicyDefault) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage); + EXPECT_TRUE(i == map.end()); +} + +TEST_F(WinConfigurationPolicyProviderTest, + TestHomepageIsNewTabPagePolicyHKLM) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + provider.SetHomepageIsNewTabPage(HKEY_LOCAL_MACHINE, true); + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage); + EXPECT_TRUE(i != map.end()); + bool value = false; + i->second->GetAsBoolean(&value); + EXPECT_EQ(true, value); +} + +TEST_F(WinConfigurationPolicyProviderTest, + TestCookiesModePolicyDefault) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyCookiesMode); + EXPECT_TRUE(i == map.end()); +} + +TEST_F(WinConfigurationPolicyProviderTest, + TestCookiesModePolicyHKLM) { + MockConfigurationPolicyStore store; + TestWinConfigurationPolicyProvider provider; + provider.SetCookiesMode(HKEY_LOCAL_MACHINE, 2); + + provider.Provide(&store); + + const MockConfigurationPolicyStore::PolicyMap& map(store.policy_map()); + MockConfigurationPolicyStore::PolicyMap::const_iterator i = + map.find(ConfigurationPolicyStore::kPolicyCookiesMode); + EXPECT_TRUE(i != map.end()); + int value = 0; + i->second->GetAsInteger(&value); + EXPECT_EQ(2, value); +} + diff --git a/chrome/browser/configuration_policy_store.h b/chrome/browser/configuration_policy_store.h index 8d2ea95..638fb2c 100644 --- a/chrome/browser/configuration_policy_store.h +++ b/chrome/browser/configuration_policy_store.h @@ -17,7 +17,7 @@ class ConfigurationPolicyStore { enum PolicyType { kPolicyHomePage, kPolicyHomepageIsNewTabPage, - kPolicyCookiesEnabled + kPolicyCookiesMode }; // A |ConfigurationPolicyProvider| specifes the value of a policy setting diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index b2dd03b..6a76c2c 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -884,11 +884,13 @@ 'browser/cookie_prompt_modal_dialog_delegate.h', 'browser/cookies_tree_model.cc', 'browser/cookies_tree_model.h', - 'browser/configuration_policy_builder.h', + 'browser/configuration_policy_store.h', 'browser/configuration_policy_pref_store.cc', 'browser/configuration_policy_pref_store.h', - 'browser/configuration_policy_provider.h', 'browser/configuration_policy_provider.cc', + 'browser/configuration_policy_provider.h', + 'browser/configuration_policy_provider_win.cc', + 'browser/configuration_policy_provider_win.h', 'browser/cross_site_request_manager.cc', 'browser/cross_site_request_manager.h', 'browser/custom_home_pages_table_model.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index de133041..e6b6a62 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -761,6 +761,7 @@ 'browser/config_dir_policy_provider_unittest.cc', 'browser/command_updater_unittest.cc', 'browser/configuration_policy_pref_store_unittest.cc', + 'browser/configuration_policy_provider_win_unittest.cc', 'browser/cookies_tree_model_unittest.cc', 'browser/debugger/devtools_manager_unittest.cc', 'browser/dom_ui/dom_ui_theme_source_unittest.cc', |