OLD | NEW |
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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
14 #include "base/scoped_temp_dir.h" | 14 #include "base/scoped_temp_dir.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/test/test_reg_util_win.h" |
16 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
17 #include "base/version.h" | 18 #include "base/version.h" |
18 #include "base/win/registry.h" | 19 #include "base/win/registry.h" |
19 #include "base/win/scoped_handle.h" | 20 #include "base/win/scoped_handle.h" |
20 #include "chrome/common/chrome_constants.h" | 21 #include "chrome/common/chrome_constants.h" |
21 #include "chrome/installer/util/fake_installation_state.h" | 22 #include "chrome/installer/util/fake_installation_state.h" |
22 #include "chrome/installer/util/fake_product_state.h" | 23 #include "chrome/installer/util/fake_product_state.h" |
23 #include "chrome/installer/util/google_update_constants.h" | 24 #include "chrome/installer/util/google_update_constants.h" |
24 #include "chrome/installer/util/helper.h" | 25 #include "chrome/installer/util/helper.h" |
25 #include "chrome/installer/util/installation_state.h" | 26 #include "chrome/installer/util/installation_state.h" |
26 #include "chrome/installer/util/installer_state.h" | 27 #include "chrome/installer/util/installer_state.h" |
27 #include "chrome/installer/util/master_preferences.h" | 28 #include "chrome/installer/util/master_preferences.h" |
28 #include "chrome/installer/util/product_unittest.h" | 29 #include "chrome/installer/util/product_unittest.h" |
29 #include "chrome/installer/util/work_item.h" | 30 #include "chrome/installer/util/work_item.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
31 | 32 |
32 #include "installer_util_strings.h" // NOLINT | 33 #include "installer_util_strings.h" // NOLINT |
33 | 34 |
34 using base::win::RegKey; | 35 using base::win::RegKey; |
35 using installer::InstallationState; | 36 using installer::InstallationState; |
36 using installer::InstallerState; | 37 using installer::InstallerState; |
37 using installer::MasterPreferences; | 38 using installer::MasterPreferences; |
| 39 using registry_util::RegistryOverrideManager; |
38 | 40 |
39 class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys { | 41 class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys { |
40 protected: | 42 protected: |
41 }; | 43 }; |
42 | 44 |
43 // An installer state on which we can tweak the target path. | 45 // An installer state on which we can tweak the target path. |
44 class MockInstallerState : public InstallerState { | 46 class MockInstallerState : public InstallerState { |
45 public: | 47 public: |
46 MockInstallerState() : InstallerState() { } | 48 MockInstallerState() : InstallerState() { } |
47 void set_target_path(const FilePath& target_path) { | 49 void set_target_path(const FilePath& target_path) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 installer_state.set_target_path(test_dir_.path()); | 338 installer_state.set_target_path(test_dir_.path()); |
337 EXPECT_EQ(1U, installer_state.products().size()); | 339 EXPECT_EQ(1U, installer_state.products().size()); |
338 EXPECT_EQ(system_level, installer_state.system_install()); | 340 EXPECT_EQ(system_level, installer_state.system_install()); |
339 | 341 |
340 const char kCurrentVersion[] = "1.2.3.4"; | 342 const char kCurrentVersion[] = "1.2.3.4"; |
341 scoped_ptr<Version> current_version( | 343 scoped_ptr<Version> current_version( |
342 Version::GetVersionFromString(kCurrentVersion)); | 344 Version::GetVersionFromString(kCurrentVersion)); |
343 | 345 |
344 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 346 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
345 EXPECT_EQ(root, installer_state.root_key()); | 347 EXPECT_EQ(root, installer_state.root_key()); |
| 348 |
346 { | 349 { |
347 TempRegKeyOverride override(root, L"root_pit"); | 350 RegistryOverrideManager override_manager; |
| 351 override_manager.OverrideRegistry(root, L"root_pit"); |
348 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( | 352 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( |
349 BrowserDistribution::CHROME_BROWSER); | 353 BrowserDistribution::CHROME_BROWSER); |
350 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); | 354 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); |
351 EXPECT_TRUE(chrome_key.Valid()); | 355 EXPECT_TRUE(chrome_key.Valid()); |
352 if (chrome_key.Valid()) { | 356 if (chrome_key.Valid()) { |
353 chrome_key.WriteValue(google_update::kRegVersionField, | 357 chrome_key.WriteValue(google_update::kRegVersionField, |
354 UTF8ToWide(current_version->GetString()).c_str()); | 358 UTF8ToWide(current_version->GetString()).c_str()); |
355 machine_state.Initialize(); | 359 machine_state.Initialize(); |
356 // TODO(tommi): Also test for when there exists a new_chrome.exe. | 360 // TODO(tommi): Also test for when there exists a new_chrome.exe. |
357 scoped_ptr<Version> found_version(installer_state.GetCurrentVersion( | 361 scoped_ptr<Version> found_version(installer_state.GetCurrentVersion( |
(...skipping 11 matching lines...) Expand all Loading... |
369 bool multi_install = false; | 373 bool multi_install = false; |
370 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 374 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
371 | 375 |
372 RegKey key; | 376 RegKey key; |
373 std::wstring launch_cmd = L"hey diddle diddle"; | 377 std::wstring launch_cmd = L"hey diddle diddle"; |
374 std::wstring value; | 378 std::wstring value; |
375 DWORD dw_value; | 379 DWORD dw_value; |
376 | 380 |
377 // check results for a fresh install of single Chrome | 381 // check results for a fresh install of single Chrome |
378 { | 382 { |
379 TempRegKeyOverride override(root, L"root_inst_res"); | 383 RegistryOverrideManager override_manager; |
| 384 override_manager.OverrideRegistry(root, L"root_inst_res"); |
380 CommandLine cmd_line = CommandLine::FromString(L"setup.exe --system-level"); | 385 CommandLine cmd_line = CommandLine::FromString(L"setup.exe --system-level"); |
381 const MasterPreferences prefs(cmd_line); | 386 const MasterPreferences prefs(cmd_line); |
382 InstallationState machine_state; | 387 InstallationState machine_state; |
383 machine_state.Initialize(); | 388 machine_state.Initialize(); |
384 InstallerState state; | 389 InstallerState state; |
385 state.Initialize(cmd_line, prefs, machine_state); | 390 state.Initialize(cmd_line, prefs, machine_state); |
386 state.WriteInstallerResult(installer::FIRST_INSTALL_SUCCESS, | 391 state.WriteInstallerResult(installer::FIRST_INSTALL_SUCCESS, |
387 IDS_INSTALL_OS_ERROR_BASE, &launch_cmd); | 392 IDS_INSTALL_OS_ERROR_BASE, &launch_cmd); |
388 BrowserDistribution* distribution = | 393 BrowserDistribution* distribution = |
389 BrowserDistribution::GetSpecificDistribution( | 394 BrowserDistribution::GetSpecificDistribution( |
390 BrowserDistribution::CHROME_BROWSER); | 395 BrowserDistribution::CHROME_BROWSER); |
391 EXPECT_EQ(ERROR_SUCCESS, | 396 EXPECT_EQ(ERROR_SUCCESS, |
392 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); | 397 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); |
393 EXPECT_EQ(ERROR_SUCCESS, | 398 EXPECT_EQ(ERROR_SUCCESS, |
394 key.ReadValueDW(installer::kInstallerResult, &dw_value)); | 399 key.ReadValueDW(installer::kInstallerResult, &dw_value)); |
395 EXPECT_EQ(static_cast<DWORD>(0), dw_value); | 400 EXPECT_EQ(static_cast<DWORD>(0), dw_value); |
396 EXPECT_EQ(ERROR_SUCCESS, | 401 EXPECT_EQ(ERROR_SUCCESS, |
397 key.ReadValueDW(installer::kInstallerError, &dw_value)); | 402 key.ReadValueDW(installer::kInstallerError, &dw_value)); |
398 EXPECT_EQ(static_cast<DWORD>(installer::FIRST_INSTALL_SUCCESS), dw_value); | 403 EXPECT_EQ(static_cast<DWORD>(installer::FIRST_INSTALL_SUCCESS), dw_value); |
399 EXPECT_EQ(ERROR_SUCCESS, | 404 EXPECT_EQ(ERROR_SUCCESS, |
400 key.ReadValue(installer::kInstallerResultUIString, &value)); | 405 key.ReadValue(installer::kInstallerResultUIString, &value)); |
401 EXPECT_FALSE(value.empty()); | 406 EXPECT_FALSE(value.empty()); |
402 EXPECT_EQ(ERROR_SUCCESS, | 407 EXPECT_EQ(ERROR_SUCCESS, |
403 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); | 408 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); |
404 EXPECT_EQ(launch_cmd, value); | 409 EXPECT_EQ(launch_cmd, value); |
405 } | 410 } |
406 TempRegKeyOverride::DeleteAllTempKeys(); | |
407 | 411 |
408 // check results for a fresh install of multi Chrome | 412 // check results for a fresh install of multi Chrome |
409 { | 413 { |
410 TempRegKeyOverride override(root, L"root_inst_res"); | 414 RegistryOverrideManager override_manager; |
| 415 override_manager.OverrideRegistry(root, L"root_inst_res"); |
411 CommandLine cmd_line = CommandLine::FromString( | 416 CommandLine cmd_line = CommandLine::FromString( |
412 L"setup.exe --system-level --multi-install --chrome"); | 417 L"setup.exe --system-level --multi-install --chrome"); |
413 const MasterPreferences prefs(cmd_line); | 418 const MasterPreferences prefs(cmd_line); |
414 InstallationState machine_state; | 419 InstallationState machine_state; |
415 machine_state.Initialize(); | 420 machine_state.Initialize(); |
416 InstallerState state; | 421 InstallerState state; |
417 state.Initialize(cmd_line, prefs, machine_state); | 422 state.Initialize(cmd_line, prefs, machine_state); |
418 state.WriteInstallerResult(installer::FIRST_INSTALL_SUCCESS, 0, | 423 state.WriteInstallerResult(installer::FIRST_INSTALL_SUCCESS, 0, |
419 &launch_cmd); | 424 &launch_cmd); |
420 BrowserDistribution* distribution = | 425 BrowserDistribution* distribution = |
421 BrowserDistribution::GetSpecificDistribution( | 426 BrowserDistribution::GetSpecificDistribution( |
422 BrowserDistribution::CHROME_BROWSER); | 427 BrowserDistribution::CHROME_BROWSER); |
423 BrowserDistribution* binaries = | 428 BrowserDistribution* binaries = |
424 BrowserDistribution::GetSpecificDistribution( | 429 BrowserDistribution::GetSpecificDistribution( |
425 BrowserDistribution::CHROME_BINARIES); | 430 BrowserDistribution::CHROME_BINARIES); |
426 EXPECT_EQ(ERROR_SUCCESS, | 431 EXPECT_EQ(ERROR_SUCCESS, |
427 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); | 432 key.Open(root, distribution->GetStateKey().c_str(), KEY_READ)); |
428 EXPECT_EQ(ERROR_SUCCESS, | 433 EXPECT_EQ(ERROR_SUCCESS, |
429 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); | 434 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); |
430 EXPECT_EQ(launch_cmd, value); | 435 EXPECT_EQ(launch_cmd, value); |
431 EXPECT_EQ(ERROR_SUCCESS, | 436 EXPECT_EQ(ERROR_SUCCESS, |
432 key.Open(root, binaries->GetStateKey().c_str(), KEY_READ)); | 437 key.Open(root, binaries->GetStateKey().c_str(), KEY_READ)); |
433 EXPECT_EQ(ERROR_SUCCESS, | 438 EXPECT_EQ(ERROR_SUCCESS, |
434 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); | 439 key.ReadValue(installer::kInstallerSuccessLaunchCmdLine, &value)); |
435 EXPECT_EQ(launch_cmd, value); | 440 EXPECT_EQ(launch_cmd, value); |
436 key.Close(); | 441 key.Close(); |
437 } | 442 } |
438 TempRegKeyOverride::DeleteAllTempKeys(); | |
439 } | 443 } |
440 | 444 |
441 // Test GetCurrentVersion when migrating single Chrome to multi | 445 // Test GetCurrentVersion when migrating single Chrome to multi |
442 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { | 446 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { |
443 using installer::FakeInstallationState; | 447 using installer::FakeInstallationState; |
444 | 448 |
445 const bool system_install = false; | 449 const bool system_install = false; |
446 FakeInstallationState machine_state; | 450 FakeInstallationState machine_state; |
447 | 451 |
448 // Pretend that this version of single-install Chrome is already installed. | 452 // Pretend that this version of single-install Chrome is already installed. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 NULL, OPEN_EXISTING, 0, 0)); | 484 NULL, OPEN_EXISTING, 0, 0)); |
481 ASSERT_TRUE(temp_handle != NULL); | 485 ASSERT_TRUE(temp_handle != NULL); |
482 | 486 |
483 // The file should now be in use. | 487 // The file should now be in use. |
484 EXPECT_TRUE(MockInstallerState::IsFileInUse(temp_file)); | 488 EXPECT_TRUE(MockInstallerState::IsFileInUse(temp_file)); |
485 } | 489 } |
486 | 490 |
487 // And once the handle is gone, it should no longer be in use. | 491 // And once the handle is gone, it should no longer be in use. |
488 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); | 492 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); |
489 } | 493 } |
OLD | NEW |