#include "base/base_paths.h"
#include "base/callback.h"
-#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/json/json_writer.h"
#include "base/path_service.h"
-#include "base/process/process.h"
+#include "base/process/process_handle.h"
#include "base/strings/string16.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/sys_byteorder.h"
#include "base/win/registry.h"
+#include "base/win/win_util.h"
#include "components/policy/core/common/async_policy_provider.h"
#include "components/policy/core/common/configuration_policy_provider_test.h"
#include "components/policy/core/common/external_data_fetcher.h"
// Deletes the sandbox keys.
void DeleteKeys();
- std::wstring key_name_;
+ base::string16 key_name_;
// Keys are created for the lifetime of a test to contain
// the sandboxed HKCU and HKLM hives, respectively.
virtual ~RegistryTestHarness();
// PolicyProviderTestHarness:
- virtual void SetUp() OVERRIDE;
+ virtual void SetUp() override;
virtual ConfigurationPolicyProvider* CreateProvider(
SchemaRegistry* registry,
- scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE;
+ scoped_refptr<base::SequencedTaskRunner> task_runner) override;
- virtual void InstallEmptyPolicy() OVERRIDE;
+ virtual void InstallEmptyPolicy() override;
virtual void InstallStringPolicy(const std::string& policy_name,
- const std::string& policy_value) OVERRIDE;
+ const std::string& policy_value) override;
virtual void InstallIntegerPolicy(const std::string& policy_name,
- int policy_value) OVERRIDE;
+ int policy_value) override;
virtual void InstallBooleanPolicy(const std::string& policy_name,
- bool policy_value) OVERRIDE;
+ bool policy_value) override;
virtual void InstallStringListPolicy(
const std::string& policy_name,
- const base::ListValue* policy_value) OVERRIDE;
+ const base::ListValue* policy_value) override;
virtual void InstallDictionaryPolicy(
const std::string& policy_name,
- const base::DictionaryValue* policy_value) OVERRIDE;
+ const base::DictionaryValue* policy_value) override;
virtual void Install3rdPartyPolicy(
- const base::DictionaryValue* policies) OVERRIDE;
+ const base::DictionaryValue* policies) override;
// AppliedGPOListProvider:
virtual DWORD GetAppliedGPOList(DWORD flags,
LPCTSTR machine_name,
PSID sid_user,
GUID* extension_guid,
- PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE;
- virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) OVERRIDE;
+ PGROUP_POLICY_OBJECT* gpo_list) override;
+ virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) override;
// Creates a harness instance that will install policy in HKCU or HKLM,
// respectively.
virtual ~PRegTestHarness();
// PolicyProviderTestHarness:
- virtual void SetUp() OVERRIDE;
+ virtual void SetUp() override;
virtual ConfigurationPolicyProvider* CreateProvider(
SchemaRegistry* registry,
- scoped_refptr<base::SequencedTaskRunner> task_runner) OVERRIDE;
+ scoped_refptr<base::SequencedTaskRunner> task_runner) override;
- virtual void InstallEmptyPolicy() OVERRIDE;
+ virtual void InstallEmptyPolicy() override;
virtual void InstallStringPolicy(const std::string& policy_name,
- const std::string& policy_value) OVERRIDE;
+ const std::string& policy_value) override;
virtual void InstallIntegerPolicy(const std::string& policy_name,
- int policy_value) OVERRIDE;
+ int policy_value) override;
virtual void InstallBooleanPolicy(const std::string& policy_name,
- bool policy_value) OVERRIDE;
+ bool policy_value) override;
virtual void InstallStringListPolicy(
const std::string& policy_name,
- const base::ListValue* policy_value) OVERRIDE;
+ const base::ListValue* policy_value) override;
virtual void InstallDictionaryPolicy(
const std::string& policy_name,
- const base::DictionaryValue* policy_value) OVERRIDE;
+ const base::DictionaryValue* policy_value) override;
virtual void Install3rdPartyPolicy(
- const base::DictionaryValue* policies) OVERRIDE;
+ const base::DictionaryValue* policies) override;
// AppliedGPOListProvider:
virtual DWORD GetAppliedGPOList(DWORD flags,
LPCTSTR machine_name,
PSID sid_user,
GUID* extension_guid,
- PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE;
- virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) OVERRIDE;
+ PGROUP_POLICY_OBJECT* gpo_list) override;
+ virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) override;
// Creates a harness instance.
static PolicyProviderTestHarness* Create();
// Generate a unique registry key for the override for each test. This
// makes sure that tests executing in parallel won't delete each other's
// key, at DeleteKeys().
- key_name_ = base::ASCIIToWide(base::StringPrintf(
- "SOFTWARE\\chromium unittest %d",
- base::Process::Current().pid()));
+ key_name_ = base::ASCIIToUTF16(base::StringPrintf(
+ "SOFTWARE\\chromium unittest %d", base::GetCurrentProcId()));
std::wstring hklm_key_name = key_name_ + L"\\HKLM";
std::wstring hkcu_key_name = key_name_ + L"\\HKCU";
ConfigurationPolicyProvider* RegistryTestHarness::CreateProvider(
SchemaRegistry* registry,
scoped_refptr<base::SequencedTaskRunner> task_runner) {
+ base::win::SetDomainStateForTesting(true);
scoped_ptr<AsyncPolicyLoader> loader(
new PolicyLoaderWin(task_runner, kTestPolicyKey, this));
return new AsyncPolicyProvider(registry, loader.Pass());
PRegTestHarness::~PRegTestHarness() {}
void PRegTestHarness::SetUp() {
+ base::win::SetDomainStateForTesting(false);
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
preg_file_path_ = temp_dir_.path().Append(PolicyLoaderWin::kPRegFileName);
- ASSERT_TRUE(file_util::WriteFile(preg_file_path_,
+ ASSERT_TRUE(base::WriteFile(preg_file_path_,
preg_parser::kPRegFileHeader,
arraysize(preg_parser::kPRegFileHeader)));
buffer.insert(buffer.end(), data, data + size);
AppendChars(&buffer, L"]");
- ASSERT_EQ(buffer.size(),
- file_util::AppendToFile(
- preg_file_path_,
- reinterpret_cast<const char*>(vector_as_array(&buffer)),
- buffer.size()));
+ ASSERT_TRUE(base::AppendToFile(
+ preg_file_path_,
+ reinterpret_cast<const char*>(vector_as_array(&buffer)),
+ buffer.size()));
}
void PRegTestHarness::AppendDWORDToPRegFile(const base::string16& path,
gpo_list_status_(ERROR_ACCESS_DENIED) {}
virtual ~PolicyLoaderWinTest() {}
- virtual void SetUp() OVERRIDE {
+ virtual void SetUp() override {
+ base::win::SetDomainStateForTesting(false);
PolicyTestBase::SetUp();
ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &test_data_dir_));
LPCTSTR machine_name,
PSID sid_user,
GUID* extension_guid,
- PGROUP_POLICY_OBJECT* gpo_list) OVERRIDE {
+ PGROUP_POLICY_OBJECT* gpo_list) override {
*gpo_list = gpo_list_;
return gpo_list_status_;
}
- virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) OVERRIDE {
+ virtual BOOL FreeGPOList(PGROUP_POLICY_OBJECT gpo_list) override {
return TRUE;
}
.Set(test_keys::kKeyString,
POLICY_LEVEL_MANDATORY,
POLICY_SCOPE_MACHINE,
- base::Value::CreateStringValue("hklm"), NULL);
+ new base::StringValue("hklm"),
+ NULL);
EXPECT_TRUE(Matches(expected));
}
PolicyBundle expected;
PolicyMap& expected_policy = expected.Get(ns);
- expected_policy.Set("a", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE,
- base::Value::CreateStringValue(kMachineMandatory), NULL);
- expected_policy.Set("b", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
- base::Value::CreateStringValue(kUserMandatory), NULL);
- expected_policy.Set("c", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_MACHINE,
- base::Value::CreateStringValue(kMachineRecommended),
+ expected_policy.Set("a",
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_MACHINE,
+ new base::StringValue(kMachineMandatory),
+ NULL);
+ expected_policy.Set("b",
+ POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER,
+ new base::StringValue(kUserMandatory),
+ NULL);
+ expected_policy.Set("c",
+ POLICY_LEVEL_RECOMMENDED,
+ POLICY_SCOPE_MACHINE,
+ new base::StringValue(kMachineRecommended),
+ NULL);
+ expected_policy.Set("d",
+ POLICY_LEVEL_RECOMMENDED,
+ POLICY_SCOPE_USER,
+ new base::StringValue(kUserRecommended),
NULL);
- expected_policy.Set("d", POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER,
- base::Value::CreateStringValue(kUserRecommended), NULL);
EXPECT_TRUE(Matches(expected));
}
EXPECT_TRUE(Matches(empty));
}
+TEST_F(PolicyLoaderWinTest, AppliedPolicyInDomain) {
+ base::win::SetDomainStateForTesting(true);
+ InstallRegistrySentinel();
+ base::FilePath gpo_dir(test_data_dir_.AppendASCII("empty"));
+ GROUP_POLICY_OBJECT gpo;
+ InitGPO(&gpo, 0, gpo_dir, NULL, NULL);
+ gpo_list_ = &gpo;
+ gpo_list_status_ = ERROR_SUCCESS;
+
+ PolicyBundle empty;
+ EXPECT_TRUE(MatchesRegistrySentinel());
+}
+
TEST_F(PolicyLoaderWinTest, AppliedPolicyNonExistingFile) {
InstallRegistrySentinel();
GROUP_POLICY_OBJECT gpo;