Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: chrome_frame/test/policy_settings_unittest.cc

Issue 5564009: Temporary workaround to get tests that reference singletons either directly o... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/at_exit.h" 6 #include "base/at_exit.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/win/registry.h" 11 #include "base/win/registry.h"
12 #include "chrome/common/policy_constants.h" 12 #include "chrome/common/policy_constants.h"
13 #include "chrome_frame/policy_settings.h" 13 #include "chrome_frame/policy_settings.h"
14 #include "chrome_frame/test/chrome_frame_test_utils.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 using base::win::RegKey; 17 using base::win::RegKey;
18 using chrome_frame_test::ScopedVirtualizeHklmAndHkcu;
19 using chrome_frame_test::TempRegKeyOverride;
17 20
18 namespace { 21 namespace {
19 22
20 // A best effort way to zap CF policy entries that may be in the registry. 23 // A best effort way to zap CF policy entries that may be in the registry.
21 void DeleteChromeFramePolicyEntries(HKEY root) { 24 void DeleteChromeFramePolicyEntries(HKEY root) {
22 RegKey key; 25 RegKey key;
23 if (key.Open(root, policy::kRegistrySubKey, KEY_ALL_ACCESS)) { 26 if (key.Open(root, policy::kRegistrySubKey, KEY_ALL_ACCESS)) {
24 key.DeleteValue( 27 key.DeleteValue(
25 ASCIIToWide(policy::key::kChromeFrameRendererSettings).c_str()); 28 ASCIIToWide(policy::key::kChromeFrameRendererSettings).c_str());
26 key.DeleteKey(ASCIIToWide(policy::key::kRenderInChromeFrameList).c_str()); 29 key.DeleteKey(ASCIIToWide(policy::key::kRenderInChromeFrameList).c_str());
27 key.DeleteKey(ASCIIToWide(policy::key::kRenderInHostList).c_str()); 30 key.DeleteKey(ASCIIToWide(policy::key::kRenderInHostList).c_str());
28 key.DeleteKey(ASCIIToWide(policy::key::kChromeFrameContentTypes).c_str()); 31 key.DeleteKey(ASCIIToWide(policy::key::kChromeFrameContentTypes).c_str());
29 key.DeleteKey(ASCIIToWide(policy::key::kApplicationLocaleValue).c_str()); 32 key.DeleteKey(ASCIIToWide(policy::key::kApplicationLocaleValue).c_str());
30 } 33 }
31 } 34 }
32 35
33 class TempRegKeyOverride {
34 public:
35 static const wchar_t kTempTestKeyPath[];
36
37 TempRegKeyOverride(HKEY override, const wchar_t* temp_name)
38 : override_(override), temp_name_(temp_name) {
39 DCHECK(temp_name && lstrlenW(temp_name));
40 std::wstring key_path(kTempTestKeyPath);
41 key_path += L"\\" + temp_name_;
42 EXPECT_TRUE(temp_key_.Create(HKEY_CURRENT_USER, key_path.c_str(),
43 KEY_ALL_ACCESS));
44 EXPECT_EQ(ERROR_SUCCESS,
45 ::RegOverridePredefKey(override_, temp_key_.Handle()));
46 }
47
48 ~TempRegKeyOverride() {
49 ::RegOverridePredefKey(override_, NULL);
50 // The temp key will be deleted via a call to DeleteAllTempKeys().
51 }
52
53 static void DeleteAllTempKeys() {
54 RegKey key;
55 if (key.Open(HKEY_CURRENT_USER, L"", KEY_ALL_ACCESS)) {
56 key.DeleteKey(kTempTestKeyPath);
57 }
58 }
59
60 protected:
61 HKEY override_;
62 RegKey temp_key_;
63 std::wstring temp_name_;
64 };
65
66 const wchar_t TempRegKeyOverride::kTempTestKeyPath[] =
67 L"Software\\Chromium\\TempTestKeys";
68
69 bool InitializePolicyKey(HKEY policy_root, RegKey* policy_key) { 36 bool InitializePolicyKey(HKEY policy_root, RegKey* policy_key) {
70 EXPECT_TRUE(policy_key->Create(policy_root, policy::kRegistrySubKey, 37 EXPECT_TRUE(policy_key->Create(policy_root, policy::kRegistrySubKey,
71 KEY_ALL_ACCESS)); 38 KEY_ALL_ACCESS));
72 return policy_key->Valid(); 39 return policy_key->Valid();
73 } 40 }
74 41
75 void WritePolicyList(RegKey* policy_key, const wchar_t* list_name, 42 void WritePolicyList(RegKey* policy_key, const wchar_t* list_name,
76 const wchar_t* values[], int count) { 43 const wchar_t* values[], int count) {
77 DCHECK(policy_key); 44 DCHECK(policy_key);
78 // Remove any previous settings 45 // Remove any previous settings
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 ASCIIToWide(policy::key::kApplicationLocaleValue)); 96 ASCIIToWide(policy::key::kApplicationLocaleValue));
130 EXPECT_TRUE(policy_key.WriteValue(application_locale_value.c_str(), locale)); 97 EXPECT_TRUE(policy_key.WriteValue(application_locale_value.c_str(), locale));
131 return true; 98 return true;
132 } 99 }
133 100
134 } // end namespace 101 } // end namespace
135 102
136 class PolicySettingsTest : public testing::Test { 103 class PolicySettingsTest : public testing::Test {
137 protected: 104 protected:
138 void SetUp() { 105 void SetUp() {
139 TempRegKeyOverride::DeleteAllTempKeys();
140
141 hklm_pol_.reset(new TempRegKeyOverride(HKEY_LOCAL_MACHINE, L"hklm_pol"));
142 hkcu_pol_.reset(new TempRegKeyOverride(HKEY_CURRENT_USER, L"hkcu_pol"));
143
144 ResetPolicySettings(); 106 ResetPolicySettings();
145 } 107 }
146 108
147 void TearDown() { 109 void TearDown() {
148 hkcu_pol_.reset(NULL);
149 hklm_pol_.reset(NULL);
150 TempRegKeyOverride::DeleteAllTempKeys();
151 } 110 }
152 111
153 void ResetPolicySettings() { 112 void ResetPolicySettings() {
154 at_exit_manager_.ProcessCallbacksNow(); 113 //at_exit_manager_.ProcessCallbacksNow();
114 DeleteAllSingletons();
155 } 115 }
156 116
157 // This is used to manage life cycle of PolicySettings singleton. 117 // This is used to manage life cycle of PolicySettings singleton.
158 base::ShadowingAtExitManager at_exit_manager_; 118 // base::ShadowingAtExitManager at_exit_manager_;
159 scoped_ptr<TempRegKeyOverride> hklm_pol_; 119
160 scoped_ptr<TempRegKeyOverride> hkcu_pol_; 120 ScopedVirtualizeHklmAndHkcu registry_virtualization_;
161 }; 121 };
162 122
163 TEST_F(PolicySettingsTest, RendererForUrl) { 123 TEST_F(PolicySettingsTest, RendererForUrl) {
164 const wchar_t* kTestUrls[] = { 124 const wchar_t* kTestUrls[] = {
165 L"http://www.example.com", 125 L"http://www.example.com",
166 L"http://www.pattern.com", 126 L"http://www.pattern.com",
167 L"http://www.test.com" 127 L"http://www.test.com"
168 }; 128 };
169 const wchar_t* kTestFilters[] = { 129 const wchar_t* kTestFilters[] = {
170 L"*.example.com", 130 L"*.example.com",
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; 205 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER };
246 for (int i = 0; i < arraysize(root); ++i) { 206 for (int i = 0; i < arraysize(root); ++i) {
247 SetChromeApplicationLocale(root[i], kTestApplicationLocale); 207 SetChromeApplicationLocale(root[i], kTestApplicationLocale);
248 ResetPolicySettings(); 208 ResetPolicySettings();
249 EXPECT_EQ(std::wstring(kTestApplicationLocale), 209 EXPECT_EQ(std::wstring(kTestApplicationLocale),
250 PolicySettings::GetInstance()->ApplicationLocale()); 210 PolicySettings::GetInstance()->ApplicationLocale());
251 211
252 DeleteChromeFramePolicyEntries(root[i]); 212 DeleteChromeFramePolicyEntries(root[i]);
253 } 213 }
254 } 214 }
OLDNEW
« no previous file with comments | « chrome_frame/test/chrome_frame_test_utils.cc ('k') | chrome_frame/test/urlmon_moniker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698