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

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

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 11 months 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
« no previous file with comments | « chrome_frame/test/perf/chrome_frame_perftest.cc ('k') | chrome_frame/utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome_frame/test/chrome_frame_test_utils.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 using base::win::RegKey; 17 using base::win::RegKey;
18 using chrome_frame_test::ScopedVirtualizeHklmAndHkcu; 18 using chrome_frame_test::ScopedVirtualizeHklmAndHkcu;
19 using chrome_frame_test::TempRegKeyOverride; 19 using chrome_frame_test::TempRegKeyOverride;
20 20
21 namespace { 21 namespace {
22 22
23 // 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.
24 void DeleteChromeFramePolicyEntries(HKEY root) { 24 void DeleteChromeFramePolicyEntries(HKEY root) {
25 RegKey key; 25 RegKey key;
26 if (key.Open(root, policy::kRegistrySubKey, KEY_ALL_ACCESS)) { 26 if (key.Open(root, policy::kRegistrySubKey,
27 KEY_ALL_ACCESS) == ERROR_SUCCESS) {
27 key.DeleteValue( 28 key.DeleteValue(
28 ASCIIToWide(policy::key::kChromeFrameRendererSettings).c_str()); 29 ASCIIToWide(policy::key::kChromeFrameRendererSettings).c_str());
29 key.DeleteKey(ASCIIToWide(policy::key::kRenderInChromeFrameList).c_str()); 30 key.DeleteKey(ASCIIToWide(policy::key::kRenderInChromeFrameList).c_str());
30 key.DeleteKey(ASCIIToWide(policy::key::kRenderInHostList).c_str()); 31 key.DeleteKey(ASCIIToWide(policy::key::kRenderInHostList).c_str());
31 key.DeleteKey(ASCIIToWide(policy::key::kChromeFrameContentTypes).c_str()); 32 key.DeleteKey(ASCIIToWide(policy::key::kChromeFrameContentTypes).c_str());
32 key.DeleteKey(ASCIIToWide(policy::key::kApplicationLocaleValue).c_str()); 33 key.DeleteKey(ASCIIToWide(policy::key::kApplicationLocaleValue).c_str());
33 } 34 }
34 } 35 }
35 36
36 bool InitializePolicyKey(HKEY policy_root, RegKey* policy_key) { 37 bool InitializePolicyKey(HKEY policy_root, RegKey* policy_key) {
37 EXPECT_TRUE(policy_key->Create(policy_root, policy::kRegistrySubKey, 38 EXPECT_EQ(ERROR_SUCCESS, policy_key->Create(policy_root,
38 KEY_ALL_ACCESS)); 39 policy::kRegistrySubKey, KEY_ALL_ACCESS));
39 return policy_key->Valid(); 40 return policy_key->Valid();
40 } 41 }
41 42
42 void WritePolicyList(RegKey* policy_key, const wchar_t* list_name, 43 void WritePolicyList(RegKey* policy_key, const wchar_t* list_name,
43 const wchar_t* values[], int count) { 44 const wchar_t* values[], int count) {
44 DCHECK(policy_key); 45 DCHECK(policy_key);
45 // Remove any previous settings 46 // Remove any previous settings
46 policy_key->DeleteKey(list_name); 47 policy_key->DeleteKey(list_name);
47 48
48 RegKey list_key; 49 RegKey list_key;
49 EXPECT_TRUE(list_key.Create(policy_key->Handle(), list_name, KEY_ALL_ACCESS)); 50 EXPECT_EQ(ERROR_SUCCESS, list_key.Create(policy_key->Handle(), list_name,
51 KEY_ALL_ACCESS));
50 for (int i = 0; i < count; ++i) { 52 for (int i = 0; i < count; ++i) {
51 EXPECT_TRUE(list_key.WriteValue(base::StringPrintf(L"%i", i).c_str(), 53 EXPECT_EQ(ERROR_SUCCESS,
52 values[i])); 54 list_key.WriteValue(base::StringPrintf(L"%i", i).c_str(), values[i]));
53 } 55 }
54 } 56 }
55 57
56 bool SetRendererSettings(HKEY policy_root, 58 bool SetRendererSettings(HKEY policy_root,
57 PolicySettings::RendererForUrl renderer, 59 PolicySettings::RendererForUrl renderer,
58 const wchar_t* exclusions[], 60 const wchar_t* exclusions[],
59 int exclusion_count) { 61 int exclusion_count) {
60 RegKey policy_key; 62 RegKey policy_key;
61 if (!InitializePolicyKey(policy_root, &policy_key)) 63 if (!InitializePolicyKey(policy_root, &policy_key))
62 return false; 64 return false;
(...skipping 24 matching lines...) Expand all
87 return true; 89 return true;
88 } 90 }
89 91
90 bool SetChromeApplicationLocale(HKEY policy_root, const wchar_t* locale) { 92 bool SetChromeApplicationLocale(HKEY policy_root, const wchar_t* locale) {
91 RegKey policy_key; 93 RegKey policy_key;
92 if (!InitializePolicyKey(policy_root, &policy_key)) 94 if (!InitializePolicyKey(policy_root, &policy_key))
93 return false; 95 return false;
94 96
95 std::wstring application_locale_value( 97 std::wstring application_locale_value(
96 ASCIIToWide(policy::key::kApplicationLocaleValue)); 98 ASCIIToWide(policy::key::kApplicationLocaleValue));
97 EXPECT_TRUE(policy_key.WriteValue(application_locale_value.c_str(), locale)); 99 EXPECT_EQ(ERROR_SUCCESS,
100 policy_key.WriteValue(application_locale_value.c_str(), locale));
98 return true; 101 return true;
99 } 102 }
100 103
101 } // end namespace 104 } // end namespace
102 105
103 class PolicySettingsTest : public testing::Test { 106 class PolicySettingsTest : public testing::Test {
104 protected: 107 protected:
105 void SetUp() { 108 void SetUp() {
106 ResetPolicySettings(); 109 ResetPolicySettings();
107 } 110 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER }; 208 HKEY root[] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER };
206 for (int i = 0; i < arraysize(root); ++i) { 209 for (int i = 0; i < arraysize(root); ++i) {
207 SetChromeApplicationLocale(root[i], kTestApplicationLocale); 210 SetChromeApplicationLocale(root[i], kTestApplicationLocale);
208 ResetPolicySettings(); 211 ResetPolicySettings();
209 EXPECT_EQ(std::wstring(kTestApplicationLocale), 212 EXPECT_EQ(std::wstring(kTestApplicationLocale),
210 PolicySettings::GetInstance()->ApplicationLocale()); 213 PolicySettings::GetInstance()->ApplicationLocale());
211 214
212 DeleteChromeFramePolicyEntries(root[i]); 215 DeleteChromeFramePolicyEntries(root[i]);
213 } 216 }
214 } 217 }
OLDNEW
« no previous file with comments | « chrome_frame/test/perf/chrome_frame_perftest.cc ('k') | chrome_frame/utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698