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

Side by Side Diff: chrome/installer/util/install_util_unittest.cc

Issue 7669061: Tommi: I need an owner review for the chrome frame changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixing license issue from presubmit check Created 9 years, 4 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 | « base/test/test_reg_util_win.cc ('k') | chrome/installer/util/installer_state_unittest.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/test/test_reg_util_win.h"
9 #include "base/win/registry.h" 10 #include "base/win/registry.h"
10 #include "chrome/installer/util/google_update_constants.h" 11 #include "chrome/installer/util/google_update_constants.h"
11 #include "chrome/installer/util/install_util.h" 12 #include "chrome/installer/util/install_util.h"
12 #include "chrome/installer/util/product_unittest.h" 13 #include "chrome/installer/util/product_unittest.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 15
15 using base::win::RegKey; 16 using base::win::RegKey;
17 using registry_util::RegistryOverrideManager;
16 using ::testing::_; 18 using ::testing::_;
17 using ::testing::Return; 19 using ::testing::Return;
18 using ::testing::StrEq; 20 using ::testing::StrEq;
19 21
20 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate { 22 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate {
21 public: 23 public:
22 MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&)); 24 MOCK_CONST_METHOD1(Evaluate, bool(const std::wstring&));
23 }; 25 };
24 26
25 class InstallUtilTest : public TestWithTempDirAndDeleteTempOverrideKeys { 27 class InstallUtilTest : public TestWithTempDirAndDeleteTempOverrideKeys {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 } 71 }
70 } 72 }
71 73
72 TEST_F(InstallUtilTest, UpdateInstallerStageAP) { 74 TEST_F(InstallUtilTest, UpdateInstallerStageAP) {
73 const bool system_level = false; 75 const bool system_level = false;
74 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 76 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
75 std::wstring state_key_path(L"PhonyClientState"); 77 std::wstring state_key_path(L"PhonyClientState");
76 78
77 // Update the stage when there's no "ap" value. 79 // Update the stage when there's no "ap" value.
78 { 80 {
79 TempRegKeyOverride override(root, L"root_inst_res"); 81 RegistryOverrideManager override_manager;
82 override_manager.OverrideRegistry(root, L"root_inst_res");
80 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE); 83 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE);
81 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 84 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
82 installer::BUILDING); 85 installer::BUILDING);
83 std::wstring value; 86 std::wstring value;
84 EXPECT_EQ(ERROR_SUCCESS, 87 EXPECT_EQ(ERROR_SUCCESS,
85 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 88 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
86 .ReadValue(google_update::kRegApField, &value)); 89 .ReadValue(google_update::kRegApField, &value));
87 EXPECT_EQ(L"-stage:building", value); 90 EXPECT_EQ(L"-stage:building", value);
88 } 91 }
89 TempRegKeyOverride::DeleteAllTempKeys();
90 92
91 // Update the stage when there is an "ap" value. 93 // Update the stage when there is an "ap" value.
92 { 94 {
93 TempRegKeyOverride override(root, L"root_inst_res"); 95 RegistryOverrideManager override_manager;
96 override_manager.OverrideRegistry(root, L"root_inst_res");
94 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 97 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
95 .WriteValue(google_update::kRegApField, L"2.0-dev"); 98 .WriteValue(google_update::kRegApField, L"2.0-dev");
96 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 99 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
97 installer::BUILDING); 100 installer::BUILDING);
98 std::wstring value; 101 std::wstring value;
99 EXPECT_EQ(ERROR_SUCCESS, 102 EXPECT_EQ(ERROR_SUCCESS,
100 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 103 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
101 .ReadValue(google_update::kRegApField, &value)); 104 .ReadValue(google_update::kRegApField, &value));
102 EXPECT_EQ(L"2.0-dev-stage:building", value); 105 EXPECT_EQ(L"2.0-dev-stage:building", value);
103 } 106 }
104 TempRegKeyOverride::DeleteAllTempKeys();
105 107
106 // Clear the stage. 108 // Clear the stage.
107 { 109 {
108 TempRegKeyOverride override(root, L"root_inst_res"); 110 RegistryOverrideManager override_manager;
111 override_manager.OverrideRegistry(root, L"root_inst_res");
109 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 112 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
110 .WriteValue(google_update::kRegApField, L"2.0-dev-stage:building"); 113 .WriteValue(google_update::kRegApField, L"2.0-dev-stage:building");
111 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 114 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
112 installer::NO_STAGE); 115 installer::NO_STAGE);
113 std::wstring value; 116 std::wstring value;
114 EXPECT_EQ(ERROR_SUCCESS, 117 EXPECT_EQ(ERROR_SUCCESS,
115 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 118 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
116 .ReadValue(google_update::kRegApField, &value)); 119 .ReadValue(google_update::kRegApField, &value));
117 EXPECT_EQ(L"2.0-dev", value); 120 EXPECT_EQ(L"2.0-dev", value);
118 } 121 }
119 TempRegKeyOverride::DeleteAllTempKeys();
120 } 122 }
121 123
122 TEST_F(InstallUtilTest, UpdateInstallerStage) { 124 TEST_F(InstallUtilTest, UpdateInstallerStage) {
123 const bool system_level = false; 125 const bool system_level = false;
124 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 126 const HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
125 std::wstring state_key_path(L"PhonyClientState"); 127 std::wstring state_key_path(L"PhonyClientState");
126 128
127 // Update the stage when there's no "InstallerExtraCode1" value. 129 // Update the stage when there's no "InstallerExtraCode1" value.
128 { 130 {
129 TempRegKeyOverride override(root, L"root_inst_res"); 131 RegistryOverrideManager override_manager;
132 override_manager.OverrideRegistry(root, L"root_inst_res");
130 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 133 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
131 .DeleteValue(installer::kInstallerExtraCode1); 134 .DeleteValue(installer::kInstallerExtraCode1);
132 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 135 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
133 installer::BUILDING); 136 installer::BUILDING);
134 DWORD value; 137 DWORD value;
135 EXPECT_EQ(ERROR_SUCCESS, 138 EXPECT_EQ(ERROR_SUCCESS,
136 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 139 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
137 .ReadValueDW(installer::kInstallerExtraCode1, &value)); 140 .ReadValueDW(installer::kInstallerExtraCode1, &value));
138 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value); 141 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value);
139 } 142 }
140 TempRegKeyOverride::DeleteAllTempKeys();
141 143
142 // Update the stage when there is an "InstallerExtraCode1" value. 144 // Update the stage when there is an "InstallerExtraCode1" value.
143 { 145 {
144 TempRegKeyOverride override(root, L"root_inst_res"); 146 RegistryOverrideManager override_manager;
147 override_manager.OverrideRegistry(root, L"root_inst_res");
145 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 148 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
146 .WriteValue(installer::kInstallerExtraCode1, 149 .WriteValue(installer::kInstallerExtraCode1,
147 static_cast<DWORD>(installer::UNPACKING)); 150 static_cast<DWORD>(installer::UNPACKING));
148 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 151 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
149 installer::BUILDING); 152 installer::BUILDING);
150 DWORD value; 153 DWORD value;
151 EXPECT_EQ(ERROR_SUCCESS, 154 EXPECT_EQ(ERROR_SUCCESS,
152 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 155 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
153 .ReadValueDW(installer::kInstallerExtraCode1, &value)); 156 .ReadValueDW(installer::kInstallerExtraCode1, &value));
154 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value); 157 EXPECT_EQ(static_cast<DWORD>(installer::BUILDING), value);
155 } 158 }
156 TempRegKeyOverride::DeleteAllTempKeys();
157 159
158 // Clear the stage. 160 // Clear the stage.
159 { 161 {
160 TempRegKeyOverride override(root, L"root_inst_res"); 162 RegistryOverrideManager override_manager;
163 override_manager.OverrideRegistry(root, L"root_inst_res");
161 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE) 164 RegKey(root, state_key_path.c_str(), KEY_SET_VALUE)
162 .WriteValue(installer::kInstallerExtraCode1, static_cast<DWORD>(5)); 165 .WriteValue(installer::kInstallerExtraCode1, static_cast<DWORD>(5));
163 InstallUtil::UpdateInstallerStage(system_level, state_key_path, 166 InstallUtil::UpdateInstallerStage(system_level, state_key_path,
164 installer::NO_STAGE); 167 installer::NO_STAGE);
165 DWORD value; 168 DWORD value;
166 EXPECT_EQ(ERROR_FILE_NOT_FOUND, 169 EXPECT_EQ(ERROR_FILE_NOT_FOUND,
167 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE) 170 RegKey(root, state_key_path.c_str(), KEY_QUERY_VALUE)
168 .ReadValueDW(installer::kInstallerExtraCode1, &value)); 171 .ReadValueDW(installer::kInstallerExtraCode1, &value));
169 } 172 }
170 TempRegKeyOverride::DeleteAllTempKeys();
171 } 173 }
172 174
173 TEST_F(InstallUtilTest, DeleteRegistryKeyIf) { 175 TEST_F(InstallUtilTest, DeleteRegistryKeyIf) {
174 const HKEY root = HKEY_CURRENT_USER; 176 const HKEY root = HKEY_CURRENT_USER;
175 std::wstring parent_key_path(L"SomeKey\\ToDelete"); 177 std::wstring parent_key_path(L"SomeKey\\ToDelete");
176 std::wstring child_key_path(parent_key_path); 178 std::wstring child_key_path(parent_key_path);
177 child_key_path.append(L"\\ChildKey\\WithAValue"); 179 child_key_path.append(L"\\ChildKey\\WithAValue");
178 const wchar_t value_name[] = L"some_value_name"; 180 const wchar_t value_name[] = L"some_value_name";
179 const wchar_t value[] = L"hi mom"; 181 const wchar_t value[] = L"hi mom";
180 182
181 { 183 {
182 TempRegKeyOverride override(root, L"root_key"); 184 RegistryOverrideManager override_manager;
185 override_manager.OverrideRegistry(root, L"root_key");
183 // Nothing to delete if the keys aren't even there. 186 // Nothing to delete if the keys aren't even there.
184 { 187 {
185 MockRegistryValuePredicate pred; 188 MockRegistryValuePredicate pred;
186 189
187 EXPECT_CALL(pred, Evaluate(_)).Times(0); 190 EXPECT_CALL(pred, Evaluate(_)).Times(0);
188 ASSERT_FALSE(RegKey(root, parent_key_path.c_str(), 191 ASSERT_FALSE(RegKey(root, parent_key_path.c_str(),
189 KEY_QUERY_VALUE).Valid()); 192 KEY_QUERY_VALUE).Valid());
190 EXPECT_TRUE(InstallUtil::DeleteRegistryKeyIf( 193 EXPECT_TRUE(InstallUtil::DeleteRegistryKeyIf(
191 root, parent_key_path, child_key_path, value_name, pred)); 194 root, parent_key_path, child_key_path, value_name, pred));
192 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), 195 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(),
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); 241 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
239 ASSERT_EQ(ERROR_SUCCESS, 242 ASSERT_EQ(ERROR_SUCCESS,
240 RegKey(root, child_key_path.c_str(), 243 RegKey(root, child_key_path.c_str(),
241 KEY_SET_VALUE).WriteValue(value_name, value)); 244 KEY_SET_VALUE).WriteValue(value_name, value));
242 EXPECT_TRUE(InstallUtil::DeleteRegistryKeyIf( 245 EXPECT_TRUE(InstallUtil::DeleteRegistryKeyIf(
243 root, parent_key_path, child_key_path, value_name, pred)); 246 root, parent_key_path, child_key_path, value_name, pred));
244 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), 247 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(),
245 KEY_QUERY_VALUE).Valid()); 248 KEY_QUERY_VALUE).Valid());
246 } 249 }
247 } 250 }
248 TempRegKeyOverride::DeleteAllTempKeys();
249 } 251 }
250 252
251 TEST_F(InstallUtilTest, DeleteRegistryValueIf) { 253 TEST_F(InstallUtilTest, DeleteRegistryValueIf) {
252 const HKEY root = HKEY_CURRENT_USER; 254 const HKEY root = HKEY_CURRENT_USER;
253 std::wstring key_path(L"SomeKey\\ToDelete"); 255 std::wstring key_path(L"SomeKey\\ToDelete");
254 const wchar_t value_name[] = L"some_value_name"; 256 const wchar_t value_name[] = L"some_value_name";
255 const wchar_t value[] = L"hi mom"; 257 const wchar_t value[] = L"hi mom";
256 258
257 { 259 {
258 TempRegKeyOverride override(root, L"root_key"); 260 RegistryOverrideManager override_manager;
261 override_manager.OverrideRegistry(root, L"root_key");
259 // Nothing to delete if the key isn't even there. 262 // Nothing to delete if the key isn't even there.
260 { 263 {
261 MockRegistryValuePredicate pred; 264 MockRegistryValuePredicate pred;
262 265
263 EXPECT_CALL(pred, Evaluate(_)).Times(0); 266 EXPECT_CALL(pred, Evaluate(_)).Times(0);
264 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); 267 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid());
265 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( 268 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf(
266 root, key_path.c_str(), value_name, pred)); 269 root, key_path.c_str(), value_name, pred));
267 EXPECT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); 270 EXPECT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid());
268 } 271 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 ASSERT_EQ(ERROR_SUCCESS, 304 ASSERT_EQ(ERROR_SUCCESS,
302 RegKey(root, key_path.c_str(), 305 RegKey(root, key_path.c_str(),
303 KEY_SET_VALUE).WriteValue(value_name, value)); 306 KEY_SET_VALUE).WriteValue(value_name, value));
304 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( 307 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf(
305 root, key_path.c_str(), value_name, pred)); 308 root, key_path.c_str(), value_name, pred));
306 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); 309 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid());
307 EXPECT_FALSE(RegKey(root, key_path.c_str(), 310 EXPECT_FALSE(RegKey(root, key_path.c_str(),
308 KEY_QUERY_VALUE).ValueExists(value_name)); 311 KEY_QUERY_VALUE).ValueExists(value_name));
309 } 312 }
310 } 313 }
311 TempRegKeyOverride::DeleteAllTempKeys();
312 314
313 { 315 {
314 TempRegKeyOverride override(root, L"root_key"); 316 RegistryOverrideManager override_manager;
317 override_manager.OverrideRegistry(root, L"root_key");
315 // Default value matches: delete. 318 // Default value matches: delete.
316 { 319 {
317 MockRegistryValuePredicate pred; 320 MockRegistryValuePredicate pred;
318 321
319 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); 322 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true));
320 ASSERT_EQ(ERROR_SUCCESS, 323 ASSERT_EQ(ERROR_SUCCESS,
321 RegKey(root, key_path.c_str(), 324 RegKey(root, key_path.c_str(),
322 KEY_SET_VALUE).WriteValue(L"", value)); 325 KEY_SET_VALUE).WriteValue(L"", value));
323 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf( 326 EXPECT_TRUE(InstallUtil::DeleteRegistryValueIf(
324 root, key_path.c_str(), L"", pred)); 327 root, key_path.c_str(), L"", pred));
325 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); 328 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid());
326 EXPECT_FALSE(RegKey(root, key_path.c_str(), 329 EXPECT_FALSE(RegKey(root, key_path.c_str(),
327 KEY_QUERY_VALUE).ValueExists(L"")); 330 KEY_QUERY_VALUE).ValueExists(L""));
328 } 331 }
329 } 332 }
330 TempRegKeyOverride::DeleteAllTempKeys();
331 } 333 }
332 334
333 TEST_F(InstallUtilTest, ValueEquals) { 335 TEST_F(InstallUtilTest, ValueEquals) {
334 InstallUtil::ValueEquals pred(L"howdy"); 336 InstallUtil::ValueEquals pred(L"howdy");
335 337
336 EXPECT_FALSE(pred.Evaluate(L"")); 338 EXPECT_FALSE(pred.Evaluate(L""));
337 EXPECT_FALSE(pred.Evaluate(L"Howdy")); 339 EXPECT_FALSE(pred.Evaluate(L"Howdy"));
338 EXPECT_FALSE(pred.Evaluate(L"howdy!")); 340 EXPECT_FALSE(pred.Evaluate(L"howdy!"));
339 EXPECT_FALSE(pred.Evaluate(L"!howdy")); 341 EXPECT_FALSE(pred.Evaluate(L"!howdy"));
340 EXPECT_TRUE(pred.Evaluate(L"howdy")); 342 EXPECT_TRUE(pred.Evaluate(L"howdy"));
341 } 343 }
OLDNEW
« no previous file with comments | « base/test/test_reg_util_win.cc ('k') | chrome/installer/util/installer_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698