OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/test/test_reg_util_win.h" | 11 #include "base/test/test_reg_util_win.h" |
12 #include "base/win/registry.h" | 12 #include "base/win/registry.h" |
13 #include "chrome/installer/util/google_update_constants.h" | 13 #include "chrome/installer/util/google_update_constants.h" |
14 #include "chrome/installer/util/install_util.h" | 14 #include "chrome/installer/util/install_util.h" |
15 #include "chrome/installer/util/product_unittest.h" | 15 #include "chrome/installer/util/product_unittest.h" |
| 16 #include "chrome/installer/util/work_item.h" |
16 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
17 | 18 |
18 using base::win::RegKey; | 19 using base::win::RegKey; |
19 using registry_util::RegistryOverrideManager; | 20 using registry_util::RegistryOverrideManager; |
20 using ::testing::_; | 21 using ::testing::_; |
21 using ::testing::Return; | 22 using ::testing::Return; |
22 using ::testing::StrEq; | 23 using ::testing::StrEq; |
23 | 24 |
24 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate { | 25 class MockRegistryValuePredicate : public InstallUtil::RegistryValuePredicate { |
25 public: | 26 public: |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 override_manager.OverrideRegistry(root, L"root_key"); | 188 override_manager.OverrideRegistry(root, L"root_key"); |
188 // Nothing to delete if the keys aren't even there. | 189 // Nothing to delete if the keys aren't even there. |
189 { | 190 { |
190 MockRegistryValuePredicate pred; | 191 MockRegistryValuePredicate pred; |
191 | 192 |
192 EXPECT_CALL(pred, Evaluate(_)).Times(0); | 193 EXPECT_CALL(pred, Evaluate(_)).Times(0); |
193 ASSERT_FALSE(RegKey(root, parent_key_path.c_str(), | 194 ASSERT_FALSE(RegKey(root, parent_key_path.c_str(), |
194 KEY_QUERY_VALUE).Valid()); | 195 KEY_QUERY_VALUE).Valid()); |
195 EXPECT_EQ(InstallUtil::NOT_FOUND, | 196 EXPECT_EQ(InstallUtil::NOT_FOUND, |
196 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, | 197 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, |
197 child_key_path, value_name, | 198 child_key_path, |
198 pred)); | 199 WorkItem::kWow64Default, |
| 200 value_name, pred)); |
199 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), | 201 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), |
200 KEY_QUERY_VALUE).Valid()); | 202 KEY_QUERY_VALUE).Valid()); |
201 } | 203 } |
202 | 204 |
203 // Parent exists, but not child: no delete. | 205 // Parent exists, but not child: no delete. |
204 { | 206 { |
205 MockRegistryValuePredicate pred; | 207 MockRegistryValuePredicate pred; |
206 | 208 |
207 EXPECT_CALL(pred, Evaluate(_)).Times(0); | 209 EXPECT_CALL(pred, Evaluate(_)).Times(0); |
208 ASSERT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_SET_VALUE).Valid()); | 210 ASSERT_TRUE(RegKey(root, parent_key_path.c_str(), KEY_SET_VALUE).Valid()); |
209 EXPECT_EQ(InstallUtil::NOT_FOUND, | 211 EXPECT_EQ(InstallUtil::NOT_FOUND, |
210 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, | 212 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, |
211 child_key_path, value_name, | 213 child_key_path, |
212 pred)); | 214 WorkItem::kWow64Default, |
| 215 value_name, pred)); |
213 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), | 216 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), |
214 KEY_QUERY_VALUE).Valid()); | 217 KEY_QUERY_VALUE).Valid()); |
215 } | 218 } |
216 | 219 |
217 // Child exists, but no value: no delete. | 220 // Child exists, but no value: no delete. |
218 { | 221 { |
219 MockRegistryValuePredicate pred; | 222 MockRegistryValuePredicate pred; |
220 | 223 |
221 EXPECT_CALL(pred, Evaluate(_)).Times(0); | 224 EXPECT_CALL(pred, Evaluate(_)).Times(0); |
222 ASSERT_TRUE(RegKey(root, child_key_path.c_str(), KEY_SET_VALUE).Valid()); | 225 ASSERT_TRUE(RegKey(root, child_key_path.c_str(), KEY_SET_VALUE).Valid()); |
223 EXPECT_EQ(InstallUtil::NOT_FOUND, | 226 EXPECT_EQ(InstallUtil::NOT_FOUND, |
224 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, | 227 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, |
225 child_key_path, value_name, | 228 child_key_path, |
226 pred)); | 229 WorkItem::kWow64Default, |
| 230 value_name, pred)); |
227 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), | 231 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), |
228 KEY_QUERY_VALUE).Valid()); | 232 KEY_QUERY_VALUE).Valid()); |
229 } | 233 } |
230 | 234 |
231 // Value exists, but doesn't match: no delete. | 235 // Value exists, but doesn't match: no delete. |
232 { | 236 { |
233 MockRegistryValuePredicate pred; | 237 MockRegistryValuePredicate pred; |
234 | 238 |
235 EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false)); | 239 EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false)); |
236 ASSERT_EQ(ERROR_SUCCESS, | 240 ASSERT_EQ(ERROR_SUCCESS, |
237 RegKey(root, child_key_path.c_str(), | 241 RegKey(root, child_key_path.c_str(), |
238 KEY_SET_VALUE).WriteValue(value_name, L"foosball!")); | 242 KEY_SET_VALUE).WriteValue(value_name, L"foosball!")); |
239 EXPECT_EQ(InstallUtil::NOT_FOUND, | 243 EXPECT_EQ(InstallUtil::NOT_FOUND, |
240 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, | 244 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, |
241 child_key_path, value_name, | 245 child_key_path, |
242 pred)); | 246 WorkItem::kWow64Default, |
| 247 value_name, pred)); |
243 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), | 248 EXPECT_TRUE(RegKey(root, parent_key_path.c_str(), |
244 KEY_QUERY_VALUE).Valid()); | 249 KEY_QUERY_VALUE).Valid()); |
245 } | 250 } |
246 | 251 |
247 // Value exists, and matches: delete. | 252 // Value exists, and matches: delete. |
248 { | 253 { |
249 MockRegistryValuePredicate pred; | 254 MockRegistryValuePredicate pred; |
250 | 255 |
251 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 256 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
252 ASSERT_EQ(ERROR_SUCCESS, | 257 ASSERT_EQ(ERROR_SUCCESS, |
253 RegKey(root, child_key_path.c_str(), | 258 RegKey(root, child_key_path.c_str(), |
254 KEY_SET_VALUE).WriteValue(value_name, value)); | 259 KEY_SET_VALUE).WriteValue(value_name, value)); |
255 EXPECT_EQ(InstallUtil::DELETED, | 260 EXPECT_EQ(InstallUtil::DELETED, |
256 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, | 261 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, |
257 child_key_path, value_name, | 262 child_key_path, |
258 pred)); | 263 WorkItem::kWow64Default, |
| 264 value_name, pred)); |
259 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), | 265 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), |
260 KEY_QUERY_VALUE).Valid()); | 266 KEY_QUERY_VALUE).Valid()); |
261 } | 267 } |
262 | 268 |
263 // Default value exists and matches: delete. | 269 // Default value exists and matches: delete. |
264 { | 270 { |
265 MockRegistryValuePredicate pred; | 271 MockRegistryValuePredicate pred; |
266 | 272 |
267 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 273 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
268 ASSERT_EQ(ERROR_SUCCESS, | 274 ASSERT_EQ(ERROR_SUCCESS, |
269 RegKey(root, child_key_path.c_str(), | 275 RegKey(root, child_key_path.c_str(), |
270 KEY_SET_VALUE).WriteValue(NULL, value)); | 276 KEY_SET_VALUE).WriteValue(NULL, value)); |
271 EXPECT_EQ(InstallUtil::DELETED, | 277 EXPECT_EQ(InstallUtil::DELETED, |
272 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, | 278 InstallUtil::DeleteRegistryKeyIf(root, parent_key_path, |
273 child_key_path, NULL, | 279 child_key_path, |
274 pred)); | 280 WorkItem::kWow64Default, |
| 281 NULL, pred)); |
275 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), | 282 EXPECT_FALSE(RegKey(root, parent_key_path.c_str(), |
276 KEY_QUERY_VALUE).Valid()); | 283 KEY_QUERY_VALUE).Valid()); |
277 } | 284 } |
278 } | 285 } |
279 } | 286 } |
280 | 287 |
281 TEST_F(InstallUtilTest, DeleteRegistryValueIf) { | 288 TEST_F(InstallUtilTest, DeleteRegistryValueIf) { |
282 const HKEY root = HKEY_CURRENT_USER; | 289 const HKEY root = HKEY_CURRENT_USER; |
283 std::wstring key_path(L"SomeKey\\ToDelete"); | 290 std::wstring key_path(L"SomeKey\\ToDelete"); |
284 const wchar_t value_name[] = L"some_value_name"; | 291 const wchar_t value_name[] = L"some_value_name"; |
285 const wchar_t value[] = L"hi mom"; | 292 const wchar_t value[] = L"hi mom"; |
286 | 293 |
287 { | 294 { |
288 RegistryOverrideManager override_manager; | 295 RegistryOverrideManager override_manager; |
289 override_manager.OverrideRegistry(root, L"root_key"); | 296 override_manager.OverrideRegistry(root, L"root_key"); |
290 // Nothing to delete if the key isn't even there. | 297 // Nothing to delete if the key isn't even there. |
291 { | 298 { |
292 MockRegistryValuePredicate pred; | 299 MockRegistryValuePredicate pred; |
293 | 300 |
294 EXPECT_CALL(pred, Evaluate(_)).Times(0); | 301 EXPECT_CALL(pred, Evaluate(_)).Times(0); |
295 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 302 ASSERT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
296 EXPECT_EQ(InstallUtil::NOT_FOUND, | 303 EXPECT_EQ(InstallUtil::NOT_FOUND, |
297 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 304 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 305 WorkItem::kWow64Default, |
298 value_name, pred)); | 306 value_name, pred)); |
299 EXPECT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 307 EXPECT_FALSE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
300 } | 308 } |
301 | 309 |
302 // Key exists, but no value: no delete. | 310 // Key exists, but no value: no delete. |
303 { | 311 { |
304 MockRegistryValuePredicate pred; | 312 MockRegistryValuePredicate pred; |
305 | 313 |
306 EXPECT_CALL(pred, Evaluate(_)).Times(0); | 314 EXPECT_CALL(pred, Evaluate(_)).Times(0); |
307 ASSERT_TRUE(RegKey(root, key_path.c_str(), KEY_SET_VALUE).Valid()); | 315 ASSERT_TRUE(RegKey(root, key_path.c_str(), KEY_SET_VALUE).Valid()); |
308 EXPECT_EQ(InstallUtil::NOT_FOUND, | 316 EXPECT_EQ(InstallUtil::NOT_FOUND, |
309 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 317 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 318 WorkItem::kWow64Default, |
310 value_name, pred)); | 319 value_name, pred)); |
311 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 320 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
312 } | 321 } |
313 | 322 |
314 // Value exists, but doesn't match: no delete. | 323 // Value exists, but doesn't match: no delete. |
315 { | 324 { |
316 MockRegistryValuePredicate pred; | 325 MockRegistryValuePredicate pred; |
317 | 326 |
318 EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false)); | 327 EXPECT_CALL(pred, Evaluate(StrEq(L"foosball!"))).WillOnce(Return(false)); |
319 ASSERT_EQ(ERROR_SUCCESS, | 328 ASSERT_EQ(ERROR_SUCCESS, |
320 RegKey(root, key_path.c_str(), | 329 RegKey(root, key_path.c_str(), |
321 KEY_SET_VALUE).WriteValue(value_name, L"foosball!")); | 330 KEY_SET_VALUE).WriteValue(value_name, L"foosball!")); |
322 EXPECT_EQ(InstallUtil::NOT_FOUND, | 331 EXPECT_EQ(InstallUtil::NOT_FOUND, |
323 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 332 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 333 WorkItem::kWow64Default, |
324 value_name, pred)); | 334 value_name, pred)); |
325 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 335 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
326 EXPECT_TRUE(RegKey(root, key_path.c_str(), | 336 EXPECT_TRUE(RegKey(root, key_path.c_str(), |
327 KEY_QUERY_VALUE).HasValue(value_name)); | 337 KEY_QUERY_VALUE).HasValue(value_name)); |
328 } | 338 } |
329 | 339 |
330 // Value exists, and matches: delete. | 340 // Value exists, and matches: delete. |
331 { | 341 { |
332 MockRegistryValuePredicate pred; | 342 MockRegistryValuePredicate pred; |
333 | 343 |
334 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 344 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
335 ASSERT_EQ(ERROR_SUCCESS, | 345 ASSERT_EQ(ERROR_SUCCESS, |
336 RegKey(root, key_path.c_str(), | 346 RegKey(root, key_path.c_str(), |
337 KEY_SET_VALUE).WriteValue(value_name, value)); | 347 KEY_SET_VALUE).WriteValue(value_name, value)); |
338 EXPECT_EQ(InstallUtil::DELETED, | 348 EXPECT_EQ(InstallUtil::DELETED, |
339 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 349 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 350 WorkItem::kWow64Default, |
340 value_name, pred)); | 351 value_name, pred)); |
341 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 352 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
342 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 353 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
343 KEY_QUERY_VALUE).HasValue(value_name)); | 354 KEY_QUERY_VALUE).HasValue(value_name)); |
344 } | 355 } |
345 } | 356 } |
346 | 357 |
347 { | 358 { |
348 RegistryOverrideManager override_manager; | 359 RegistryOverrideManager override_manager; |
349 override_manager.OverrideRegistry(root, L"root_key"); | 360 override_manager.OverrideRegistry(root, L"root_key"); |
350 // Default value matches: delete using empty string. | 361 // Default value matches: delete using empty string. |
351 { | 362 { |
352 MockRegistryValuePredicate pred; | 363 MockRegistryValuePredicate pred; |
353 | 364 |
354 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 365 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
355 ASSERT_EQ(ERROR_SUCCESS, | 366 ASSERT_EQ(ERROR_SUCCESS, |
356 RegKey(root, key_path.c_str(), | 367 RegKey(root, key_path.c_str(), |
357 KEY_SET_VALUE).WriteValue(L"", value)); | 368 KEY_SET_VALUE).WriteValue(L"", value)); |
358 EXPECT_EQ(InstallUtil::DELETED, | 369 EXPECT_EQ(InstallUtil::DELETED, |
359 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), L"", | 370 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 371 WorkItem::kWow64Default, L"", |
360 pred)); | 372 pred)); |
361 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 373 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
362 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 374 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
363 KEY_QUERY_VALUE).HasValue(L"")); | 375 KEY_QUERY_VALUE).HasValue(L"")); |
364 } | 376 } |
365 } | 377 } |
366 | 378 |
367 { | 379 { |
368 RegistryOverrideManager override_manager; | 380 RegistryOverrideManager override_manager; |
369 override_manager.OverrideRegistry(root, L"root_key"); | 381 override_manager.OverrideRegistry(root, L"root_key"); |
370 // Default value matches: delete using NULL. | 382 // Default value matches: delete using NULL. |
371 { | 383 { |
372 MockRegistryValuePredicate pred; | 384 MockRegistryValuePredicate pred; |
373 | 385 |
374 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); | 386 EXPECT_CALL(pred, Evaluate(StrEq(value))).WillOnce(Return(true)); |
375 ASSERT_EQ(ERROR_SUCCESS, | 387 ASSERT_EQ(ERROR_SUCCESS, |
376 RegKey(root, key_path.c_str(), | 388 RegKey(root, key_path.c_str(), |
377 KEY_SET_VALUE).WriteValue(L"", value)); | 389 KEY_SET_VALUE).WriteValue(L"", value)); |
378 EXPECT_EQ(InstallUtil::DELETED, | 390 EXPECT_EQ(InstallUtil::DELETED, |
379 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), | 391 InstallUtil::DeleteRegistryValueIf(root, key_path.c_str(), |
| 392 WorkItem::kWow64Default, |
380 NULL, pred)); | 393 NULL, pred)); |
381 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); | 394 EXPECT_TRUE(RegKey(root, key_path.c_str(), KEY_QUERY_VALUE).Valid()); |
382 EXPECT_FALSE(RegKey(root, key_path.c_str(), | 395 EXPECT_FALSE(RegKey(root, key_path.c_str(), |
383 KEY_QUERY_VALUE).HasValue(L"")); | 396 KEY_QUERY_VALUE).HasValue(L"")); |
384 } | 397 } |
385 } | 398 } |
386 } | 399 } |
387 | 400 |
388 TEST_F(InstallUtilTest, ValueEquals) { | 401 TEST_F(InstallUtilTest, ValueEquals) { |
389 InstallUtil::ValueEquals pred(L"howdy"); | 402 InstallUtil::ValueEquals pred(L"howdy"); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 WriteInto(&short_expect, MAX_PATH), | 447 WriteInto(&short_expect, MAX_PATH), |
435 MAX_PATH); | 448 MAX_PATH); |
436 ASSERT_NE(static_cast<DWORD>(0), short_len); | 449 ASSERT_NE(static_cast<DWORD>(0), short_len); |
437 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); | 450 ASSERT_GT(static_cast<DWORD>(MAX_PATH), short_len); |
438 short_expect.resize(short_len); | 451 short_expect.resize(short_len); |
439 ASSERT_FALSE(base::FilePath::CompareEqualIgnoreCase(expect.value(), | 452 ASSERT_FALSE(base::FilePath::CompareEqualIgnoreCase(expect.value(), |
440 short_expect)); | 453 short_expect)); |
441 EXPECT_TRUE(InstallUtil::ProgramCompare(expect).Evaluate( | 454 EXPECT_TRUE(InstallUtil::ProgramCompare(expect).Evaluate( |
442 L"\"" + short_expect + L"\"")); | 455 L"\"" + short_expect + L"\"")); |
443 } | 456 } |
OLD | NEW |