| 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 <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" |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 Version new_version(kNewVersion); | 269 Version new_version(kNewVersion); |
| 270 Version old_version(kOldVersion); | 270 Version old_version(kOldVersion); |
| 271 ASSERT_TRUE(new_version.IsValid()); | 271 ASSERT_TRUE(new_version.IsValid()); |
| 272 ASSERT_TRUE(old_version.IsValid()); | 272 ASSERT_TRUE(old_version.IsValid()); |
| 273 | 273 |
| 274 base::FilePath installer_dir( | 274 base::FilePath installer_dir( |
| 275 installer_state.GetInstallerDirectory(new_version)); | 275 installer_state.GetInstallerDirectory(new_version)); |
| 276 EXPECT_FALSE(installer_dir.empty()); | 276 EXPECT_FALSE(installer_dir.empty()); |
| 277 | 277 |
| 278 base::FilePath new_version_dir(installer_state.target_path().Append( | 278 base::FilePath new_version_dir(installer_state.target_path().Append( |
| 279 UTF8ToWide(new_version.GetString()))); | 279 base::UTF8ToWide(new_version.GetString()))); |
| 280 base::FilePath old_version_dir(installer_state.target_path().Append( | 280 base::FilePath old_version_dir(installer_state.target_path().Append( |
| 281 UTF8ToWide(old_version.GetString()))); | 281 base::UTF8ToWide(old_version.GetString()))); |
| 282 | 282 |
| 283 EXPECT_FALSE(file_util::PathExists(new_version_dir)); | 283 EXPECT_FALSE(file_util::PathExists(new_version_dir)); |
| 284 EXPECT_FALSE(file_util::PathExists(old_version_dir)); | 284 EXPECT_FALSE(file_util::PathExists(old_version_dir)); |
| 285 | 285 |
| 286 EXPECT_FALSE(file_util::PathExists(installer_dir)); | 286 EXPECT_FALSE(file_util::PathExists(installer_dir)); |
| 287 file_util::CreateDirectory(installer_dir); | 287 file_util::CreateDirectory(installer_dir); |
| 288 EXPECT_TRUE(file_util::PathExists(new_version_dir)); | 288 EXPECT_TRUE(file_util::PathExists(new_version_dir)); |
| 289 | 289 |
| 290 file_util::CreateDirectory(old_version_dir); | 290 file_util::CreateDirectory(old_version_dir); |
| 291 EXPECT_TRUE(file_util::PathExists(old_version_dir)); | 291 EXPECT_TRUE(file_util::PathExists(old_version_dir)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 | 354 |
| 355 { | 355 { |
| 356 RegistryOverrideManager override_manager; | 356 RegistryOverrideManager override_manager; |
| 357 override_manager.OverrideRegistry(root, L"root_pit"); | 357 override_manager.OverrideRegistry(root, L"root_pit"); |
| 358 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( | 358 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( |
| 359 BrowserDistribution::CHROME_BROWSER); | 359 BrowserDistribution::CHROME_BROWSER); |
| 360 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); | 360 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); |
| 361 EXPECT_TRUE(chrome_key.Valid()); | 361 EXPECT_TRUE(chrome_key.Valid()); |
| 362 if (chrome_key.Valid()) { | 362 if (chrome_key.Valid()) { |
| 363 chrome_key.WriteValue(google_update::kRegVersionField, | 363 chrome_key.WriteValue(google_update::kRegVersionField, |
| 364 UTF8ToWide(current_version.GetString()).c_str()); | 364 base::UTF8ToWide( |
| 365 current_version.GetString()).c_str()); |
| 365 machine_state.Initialize(); | 366 machine_state.Initialize(); |
| 366 // TODO(tommi): Also test for when there exists a new_chrome.exe. | 367 // TODO(tommi): Also test for when there exists a new_chrome.exe. |
| 367 Version found_version(*installer_state.GetCurrentVersion(machine_state)); | 368 Version found_version(*installer_state.GetCurrentVersion(machine_state)); |
| 368 EXPECT_TRUE(found_version.IsValid()); | 369 EXPECT_TRUE(found_version.IsValid()); |
| 369 if (found_version.IsValid()) | 370 if (found_version.IsValid()) |
| 370 EXPECT_TRUE(current_version.Equals(found_version)); | 371 EXPECT_TRUE(current_version.Equals(found_version)); |
| 371 } | 372 } |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 | 375 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 ASSERT_TRUE(old_version.IsValid()); | 526 ASSERT_TRUE(old_version.IsValid()); |
| 526 ASSERT_TRUE(old_chrome_exe_version.IsValid()); | 527 ASSERT_TRUE(old_chrome_exe_version.IsValid()); |
| 527 ASSERT_TRUE(chrome_exe_version.IsValid()); | 528 ASSERT_TRUE(chrome_exe_version.IsValid()); |
| 528 ASSERT_TRUE(new_chrome_exe_version.IsValid()); | 529 ASSERT_TRUE(new_chrome_exe_version.IsValid()); |
| 529 | 530 |
| 530 // Set up a bunch of version dir paths. | 531 // Set up a bunch of version dir paths. |
| 531 base::FilePath version_dirs[] = { | 532 base::FilePath version_dirs[] = { |
| 532 installer_state.target_path().Append(L"1.2.3.4"), | 533 installer_state.target_path().Append(L"1.2.3.4"), |
| 533 installer_state.target_path().Append(L"1.2.3.5"), | 534 installer_state.target_path().Append(L"1.2.3.5"), |
| 534 installer_state.target_path().Append(L"1.2.3.6"), | 535 installer_state.target_path().Append(L"1.2.3.6"), |
| 535 installer_state.target_path().Append(ASCIIToWide(kOldVersion)), | 536 installer_state.target_path().Append(base::ASCIIToWide(kOldVersion)), |
| 536 installer_state.target_path().Append(ASCIIToWide(kOldChromeExeVersion)), | 537 installer_state.target_path().Append( |
| 538 base::ASCIIToWide(kOldChromeExeVersion)), |
| 537 installer_state.target_path().Append(L"2.1.1.0"), | 539 installer_state.target_path().Append(L"2.1.1.0"), |
| 538 installer_state.target_path().Append(ASCIIToWide(kChromeExeVersion)), | 540 installer_state.target_path().Append(base::ASCIIToWide(kChromeExeVersion)), |
| 539 installer_state.target_path().Append(ASCIIToWide(kNewVersion)), | 541 installer_state.target_path().Append(base::ASCIIToWide(kNewVersion)), |
| 540 installer_state.target_path().Append(L"3.9.1.1"), | 542 installer_state.target_path().Append(L"3.9.1.1"), |
| 541 }; | 543 }; |
| 542 | 544 |
| 543 // Create the version directories. | 545 // Create the version directories. |
| 544 for (int i = 0; i < arraysize(version_dirs); i++) { | 546 for (int i = 0; i < arraysize(version_dirs); i++) { |
| 545 file_util::CreateDirectory(version_dirs[i]); | 547 file_util::CreateDirectory(version_dirs[i]); |
| 546 EXPECT_TRUE(file_util::PathExists(version_dirs[i])); | 548 EXPECT_TRUE(file_util::PathExists(version_dirs[i])); |
| 547 } | 549 } |
| 548 | 550 |
| 549 // Create exes with the appropriate version resource. | 551 // Create exes with the appropriate version resource. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 expected_remaining_dirs.insert(kOldChromeExeVersion); | 592 expected_remaining_dirs.insert(kOldChromeExeVersion); |
| 591 expected_remaining_dirs.insert(kChromeExeVersion); | 593 expected_remaining_dirs.insert(kChromeExeVersion); |
| 592 expected_remaining_dirs.insert(kNewChromeExeVersion); | 594 expected_remaining_dirs.insert(kNewChromeExeVersion); |
| 593 | 595 |
| 594 // Enumerate dirs in target_path(), ensure only desired remain. | 596 // Enumerate dirs in target_path(), ensure only desired remain. |
| 595 file_util::FileEnumerator version_enum(installer_state.target_path(), false, | 597 file_util::FileEnumerator version_enum(installer_state.target_path(), false, |
| 596 file_util::FileEnumerator::DIRECTORIES); | 598 file_util::FileEnumerator::DIRECTORIES); |
| 597 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); | 599 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); |
| 598 next_version = version_enum.Next()) { | 600 next_version = version_enum.Next()) { |
| 599 base::FilePath dir_name(next_version.BaseName()); | 601 base::FilePath dir_name(next_version.BaseName()); |
| 600 Version version(WideToASCII(dir_name.value())); | 602 Version version(base::WideToASCII(dir_name.value())); |
| 601 if (version.IsValid()) { | 603 if (version.IsValid()) { |
| 602 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) | 604 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) |
| 603 << "Unexpected version dir found: " << version.GetString(); | 605 << "Unexpected version dir found: " << version.GetString(); |
| 604 } | 606 } |
| 605 } | 607 } |
| 606 | 608 |
| 607 std::set<std::string>::const_iterator iter( | 609 std::set<std::string>::const_iterator iter( |
| 608 expected_remaining_dirs.begin()); | 610 expected_remaining_dirs.begin()); |
| 609 for (; iter != expected_remaining_dirs.end(); ++iter) | 611 for (; iter != expected_remaining_dirs.end(); ++iter) |
| 610 ADD_FAILURE() << "Expected to find version dir for " << *iter; | 612 ADD_FAILURE() << "Expected to find version dir for " << *iter; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 636 } | 638 } |
| 637 | 639 |
| 638 // Initializes the InstallerState to use for a test run. The returned | 640 // Initializes the InstallerState to use for a test run. The returned |
| 639 // instance's critical update version is set to |version|. |version| may be | 641 // instance's critical update version is set to |version|. |version| may be |
| 640 // NULL, in which case the critical update version is unset. | 642 // NULL, in which case the critical update version is unset. |
| 641 MockInstallerState& Initialize(const Version* version) { | 643 MockInstallerState& Initialize(const Version* version) { |
| 642 cmd_line_ = version == NULL ? | 644 cmd_line_ = version == NULL ? |
| 643 CommandLine::FromString(L"setup.exe") : | 645 CommandLine::FromString(L"setup.exe") : |
| 644 CommandLine::FromString( | 646 CommandLine::FromString( |
| 645 L"setup.exe --critical-update-version=" + | 647 L"setup.exe --critical-update-version=" + |
| 646 ASCIIToWide(version->GetString())); | 648 base::ASCIIToWide(version->GetString())); |
| 647 prefs_.reset(new MasterPreferences(cmd_line_)); | 649 prefs_.reset(new MasterPreferences(cmd_line_)); |
| 648 machine_state_.Initialize(); | 650 machine_state_.Initialize(); |
| 649 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); | 651 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); |
| 650 return installer_state_; | 652 return installer_state_; |
| 651 } | 653 } |
| 652 | 654 |
| 653 static Version* low_version_; | 655 static Version* low_version_; |
| 654 static Version* opv_version_; | 656 static Version* opv_version_; |
| 655 static Version* middle_version_; | 657 static Version* middle_version_; |
| 656 static Version* pv_version_; | 658 static Version* pv_version_; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 // Critical update newer than the new version. | 758 // Critical update newer than the new version. |
| 757 EXPECT_FALSE( | 759 EXPECT_FALSE( |
| 758 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 760 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
| 759 EXPECT_FALSE( | 761 EXPECT_FALSE( |
| 760 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) | 762 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) |
| 761 .IsValid()); | 763 .IsValid()); |
| 762 EXPECT_FALSE( | 764 EXPECT_FALSE( |
| 763 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) | 765 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) |
| 764 .IsValid()); | 766 .IsValid()); |
| 765 } | 767 } |
| OLD | NEW |