OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <gtest/gtest.h> | 5 #include <gtest/gtest.h> |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/registry.h" | 10 #include "base/registry.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "base/stl_util-inl.h" | 12 #include "base/stl_util-inl.h" |
13 #include "base/string_piece.h" | 13 #include "base/string_piece.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/configuration_policy_provider_win.h" | 15 #include "chrome/browser/configuration_policy_provider_win.h" |
16 #include "chrome/browser/mock_configuration_policy_store.h" | 16 #include "chrome/browser/mock_configuration_policy_store.h" |
| 17 #include "chrome/common/policy_constants.h" |
17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const wchar_t kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; | 22 const wchar_t kUnitTestRegistrySubKey[] = L"SOFTWARE\\Chromium Unit Tests"; |
22 const wchar_t kUnitTestMachineOverrideSubKey[] = | 23 const wchar_t kUnitTestMachineOverrideSubKey[] = |
23 L"SOFTWARE\\Chromium Unit Tests\\HKLM Override"; | 24 L"SOFTWARE\\Chromium Unit Tests\\HKLM Override"; |
24 const wchar_t kUnitTestUserOverrideSubKey[] = | 25 const wchar_t kUnitTestUserOverrideSubKey[] = |
25 L"SOFTWARE\\Chromium Unit Tests\\HKCU Override"; | 26 L"SOFTWARE\\Chromium Unit Tests\\HKCU Override"; |
26 | 27 |
(...skipping 30 matching lines...) Expand all Loading... |
57 return UTF8ToWide(current->name); | 58 return UTF8ToWide(current->name); |
58 } | 59 } |
59 return NULL; | 60 return NULL; |
60 } | 61 } |
61 | 62 |
62 } // namespace | 63 } // namespace |
63 | 64 |
64 void TestConfigurationPolicyProviderWin::SetHomepageRegistryValue( | 65 void TestConfigurationPolicyProviderWin::SetHomepageRegistryValue( |
65 HKEY hive, | 66 HKEY hive, |
66 const wchar_t* value) { | 67 const wchar_t* value) { |
67 RegKey key(hive, | 68 RegKey key(hive, policy::kRegistrySubKey, KEY_ALL_ACCESS); |
68 ConfigurationPolicyProviderWin::kPolicyRegistrySubKey, | |
69 KEY_ALL_ACCESS); | |
70 EXPECT_TRUE(key.WriteValue( | 69 EXPECT_TRUE(key.WriteValue( |
71 NameForPolicy(ConfigurationPolicyStore::kPolicyHomePage).c_str(), | 70 NameForPolicy(ConfigurationPolicyStore::kPolicyHomePage).c_str(), |
72 value)); | 71 value)); |
73 } | 72 } |
74 | 73 |
75 void TestConfigurationPolicyProviderWin::SetHomepageRegistryValueWrongType( | 74 void TestConfigurationPolicyProviderWin::SetHomepageRegistryValueWrongType( |
76 HKEY hive) { | 75 HKEY hive) { |
77 RegKey key(hive, | 76 RegKey key(hive, policy::kRegistrySubKey, KEY_ALL_ACCESS); |
78 ConfigurationPolicyProviderWin::kPolicyRegistrySubKey, | |
79 KEY_ALL_ACCESS); | |
80 EXPECT_TRUE(key.WriteValue( | 77 EXPECT_TRUE(key.WriteValue( |
81 NameForPolicy(ConfigurationPolicyStore::kPolicyHomePage).c_str(), | 78 NameForPolicy(ConfigurationPolicyStore::kPolicyHomePage).c_str(), |
82 5)); | 79 5)); |
83 } | 80 } |
84 | 81 |
85 void TestConfigurationPolicyProviderWin::SetBooleanPolicy( | 82 void TestConfigurationPolicyProviderWin::SetBooleanPolicy( |
86 ConfigurationPolicyStore::PolicyType type, | 83 ConfigurationPolicyStore::PolicyType type, |
87 HKEY hive, | 84 HKEY hive, |
88 bool value) { | 85 bool value) { |
89 RegKey key(hive, ConfigurationPolicyProviderWin::kPolicyRegistrySubKey, | 86 RegKey key(hive, policy::kRegistrySubKey, KEY_ALL_ACCESS); |
90 KEY_ALL_ACCESS); | |
91 EXPECT_TRUE(key.WriteValue(NameForPolicy(type).c_str(), value)); | 87 EXPECT_TRUE(key.WriteValue(NameForPolicy(type).c_str(), value)); |
92 } | 88 } |
93 | 89 |
94 // This test class provides sandboxing and mocking for the parts of the | 90 // This test class provides sandboxing and mocking for the parts of the |
95 // Windows Registry implementing Group Policy. The |SetUp| method prepares | 91 // Windows Registry implementing Group Policy. The |SetUp| method prepares |
96 // two temporary sandbox keys in |kUnitTestRegistrySubKey|, one for HKLM and one | 92 // two temporary sandbox keys in |kUnitTestRegistrySubKey|, one for HKLM and one |
97 // for HKCU. A test's calls to the registry are redirected by Windows to these | 93 // for HKCU. A test's calls to the registry are redirected by Windows to these |
98 // sandboxes, allowing the tests to manipulate and access policy as if it | 94 // sandboxes, allowing the tests to manipulate and access policy as if it |
99 // were active, but without actually changing the parts of the Registry that | 95 // were active, but without actually changing the parts of the Registry that |
100 // are managed by Group Policy. | 96 // are managed by Group Policy. |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 | 301 |
306 TEST_F(ConfigurationPolicyProviderWinTest, | 302 TEST_F(ConfigurationPolicyProviderWinTest, |
307 TestPolicyMetricsReportingEnabled) { | 303 TestPolicyMetricsReportingEnabled) { |
308 TestBooleanPolicy(ConfigurationPolicyStore::kPolicyMetricsReportingEnabled); | 304 TestBooleanPolicy(ConfigurationPolicyStore::kPolicyMetricsReportingEnabled); |
309 } | 305 } |
310 | 306 |
311 TEST_F(ConfigurationPolicyProviderWinTest, | 307 TEST_F(ConfigurationPolicyProviderWinTest, |
312 TestPolicyPasswordManagerEnabled) { | 308 TestPolicyPasswordManagerEnabled) { |
313 TestBooleanPolicy(ConfigurationPolicyStore::kPolicyPasswordManagerEnabled); | 309 TestBooleanPolicy(ConfigurationPolicyStore::kPolicyPasswordManagerEnabled); |
314 } | 310 } |
315 | |
OLD | NEW |