| 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 "chrome/installer/util/installer_state.h" | 5 #include "chrome/installer/util/installer_state.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <fstream> | 10 #include <fstream> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // An installer state on which we can access otherwise protected members. | 60 // An installer state on which we can access otherwise protected members. |
| 61 class MockInstallerState : public InstallerState { | 61 class MockInstallerState : public InstallerState { |
| 62 public: | 62 public: |
| 63 MockInstallerState() : InstallerState() { } | 63 MockInstallerState() : InstallerState() { } |
| 64 void set_target_path(const base::FilePath& target_path) { | 64 void set_target_path(const base::FilePath& target_path) { |
| 65 target_path_ = target_path; | 65 target_path_ = target_path; |
| 66 } | 66 } |
| 67 static bool IsFileInUse(const base::FilePath& file) { | 67 static bool IsFileInUse(const base::FilePath& file) { |
| 68 return InstallerState::IsFileInUse(file); | 68 return InstallerState::IsFileInUse(file); |
| 69 } | 69 } |
| 70 const Version& critical_update_version() const { | 70 const base::Version& critical_update_version() const { |
| 71 return critical_update_version_; | 71 return critical_update_version_; |
| 72 } | 72 } |
| 73 void GetExistingExeVersions(std::set<std::string>* existing_version_strings) { | 73 void GetExistingExeVersions(std::set<std::string>* existing_version_strings) { |
| 74 return InstallerState::GetExistingExeVersions(existing_version_strings); | 74 return InstallerState::GetExistingExeVersions(existing_version_strings); |
| 75 } | 75 } |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 // Simple function to dump some text into a new file. | 78 // Simple function to dump some text into a new file. |
| 79 void CreateTextFile(const std::wstring& filename, | 79 void CreateTextFile(const std::wstring& filename, |
| 80 const std::wstring& contents) { | 80 const std::wstring& contents) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 CreateTextFile(chrome_dll_3.value(), text_content_1); | 145 CreateTextFile(chrome_dll_3.value(), text_content_1); |
| 146 ASSERT_TRUE(base::PathExists(chrome_dll_3)); | 146 ASSERT_TRUE(base::PathExists(chrome_dll_3)); |
| 147 | 147 |
| 148 base::FilePath chrome_dll_4(chrome_dir_4); | 148 base::FilePath chrome_dll_4(chrome_dir_4); |
| 149 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); | 149 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); |
| 150 CreateTextFile(chrome_dll_4.value(), text_content_1); | 150 CreateTextFile(chrome_dll_4.value(), text_content_1); |
| 151 ASSERT_TRUE(base::PathExists(chrome_dll_4)); | 151 ASSERT_TRUE(base::PathExists(chrome_dll_4)); |
| 152 | 152 |
| 153 MockInstallerState installer_state; | 153 MockInstallerState installer_state; |
| 154 BuildSingleChromeState(chrome_dir, &installer_state); | 154 BuildSingleChromeState(chrome_dir, &installer_state); |
| 155 Version latest_version("1.0.4.0"); | 155 base::Version latest_version("1.0.4.0"); |
| 156 { | 156 { |
| 157 base::ScopedTempDir temp_dir; | 157 base::ScopedTempDir temp_dir; |
| 158 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 158 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 159 installer_state.RemoveOldVersionDirectories(latest_version, NULL, | 159 installer_state.RemoveOldVersionDirectories(latest_version, NULL, |
| 160 temp_dir.path()); | 160 temp_dir.path()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // old versions should be gone | 163 // old versions should be gone |
| 164 EXPECT_FALSE(base::PathExists(chrome_dir_1)); | 164 EXPECT_FALSE(base::PathExists(chrome_dir_1)); |
| 165 EXPECT_FALSE(base::PathExists(chrome_dir_2)); | 165 EXPECT_FALSE(base::PathExists(chrome_dir_2)); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 CreateTextFile(chrome_dll_3.value(), text_content_1); | 225 CreateTextFile(chrome_dll_3.value(), text_content_1); |
| 226 ASSERT_TRUE(base::PathExists(chrome_dll_3)); | 226 ASSERT_TRUE(base::PathExists(chrome_dll_3)); |
| 227 | 227 |
| 228 base::FilePath chrome_dll_4(chrome_dir_4); | 228 base::FilePath chrome_dll_4(chrome_dir_4); |
| 229 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); | 229 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); |
| 230 CreateTextFile(chrome_dll_4.value(), text_content_1); | 230 CreateTextFile(chrome_dll_4.value(), text_content_1); |
| 231 ASSERT_TRUE(base::PathExists(chrome_dll_4)); | 231 ASSERT_TRUE(base::PathExists(chrome_dll_4)); |
| 232 | 232 |
| 233 MockInstallerState installer_state; | 233 MockInstallerState installer_state; |
| 234 BuildSingleChromeState(chrome_dir, &installer_state); | 234 BuildSingleChromeState(chrome_dir, &installer_state); |
| 235 Version latest_version("1.0.4.0"); | 235 base::Version latest_version("1.0.4.0"); |
| 236 Version existing_version("1.0.1.0"); | 236 base::Version existing_version("1.0.1.0"); |
| 237 { | 237 { |
| 238 base::ScopedTempDir temp_dir; | 238 base::ScopedTempDir temp_dir; |
| 239 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 239 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 240 installer_state.RemoveOldVersionDirectories(latest_version, | 240 installer_state.RemoveOldVersionDirectories(latest_version, |
| 241 &existing_version, | 241 &existing_version, |
| 242 temp_dir.path()); | 242 temp_dir.path()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // the version defined as the existing version should stay | 245 // the version defined as the existing version should stay |
| 246 EXPECT_TRUE(base::PathExists(chrome_dir_1)); | 246 EXPECT_TRUE(base::PathExists(chrome_dir_1)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 269 machine_state.Initialize(); | 269 machine_state.Initialize(); |
| 270 MockInstallerState installer_state; | 270 MockInstallerState installer_state; |
| 271 installer_state.Initialize(cmd_line, prefs, machine_state); | 271 installer_state.Initialize(cmd_line, prefs, machine_state); |
| 272 installer_state.set_target_path(test_dir_.path()); | 272 installer_state.set_target_path(test_dir_.path()); |
| 273 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); | 273 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); |
| 274 EXPECT_EQ(1U, installer_state.products().size()); | 274 EXPECT_EQ(1U, installer_state.products().size()); |
| 275 | 275 |
| 276 const char kOldVersion[] = "1.2.3.4"; | 276 const char kOldVersion[] = "1.2.3.4"; |
| 277 const char kNewVersion[] = "2.3.4.5"; | 277 const char kNewVersion[] = "2.3.4.5"; |
| 278 | 278 |
| 279 Version new_version(kNewVersion); | 279 base::Version new_version(kNewVersion); |
| 280 Version old_version(kOldVersion); | 280 base::Version old_version(kOldVersion); |
| 281 ASSERT_TRUE(new_version.IsValid()); | 281 ASSERT_TRUE(new_version.IsValid()); |
| 282 ASSERT_TRUE(old_version.IsValid()); | 282 ASSERT_TRUE(old_version.IsValid()); |
| 283 | 283 |
| 284 base::FilePath installer_dir( | 284 base::FilePath installer_dir( |
| 285 installer_state.GetInstallerDirectory(new_version)); | 285 installer_state.GetInstallerDirectory(new_version)); |
| 286 EXPECT_FALSE(installer_dir.empty()); | 286 EXPECT_FALSE(installer_dir.empty()); |
| 287 | 287 |
| 288 base::FilePath new_version_dir(installer_state.target_path().Append( | 288 base::FilePath new_version_dir(installer_state.target_path().Append( |
| 289 base::UTF8ToWide(new_version.GetString()))); | 289 base::UTF8ToWide(new_version.GetString()))); |
| 290 base::FilePath old_version_dir(installer_state.target_path().Append( | 290 base::FilePath old_version_dir(installer_state.target_path().Append( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 MasterPreferences prefs(cmd_line); | 350 MasterPreferences prefs(cmd_line); |
| 351 InstallationState machine_state; | 351 InstallationState machine_state; |
| 352 machine_state.Initialize(); | 352 machine_state.Initialize(); |
| 353 MockInstallerState installer_state; | 353 MockInstallerState installer_state; |
| 354 installer_state.Initialize(cmd_line, prefs, machine_state); | 354 installer_state.Initialize(cmd_line, prefs, machine_state); |
| 355 installer_state.set_target_path(test_dir_.path()); | 355 installer_state.set_target_path(test_dir_.path()); |
| 356 EXPECT_EQ(1U, installer_state.products().size()); | 356 EXPECT_EQ(1U, installer_state.products().size()); |
| 357 EXPECT_EQ(system_level, installer_state.system_install()); | 357 EXPECT_EQ(system_level, installer_state.system_install()); |
| 358 | 358 |
| 359 const char kCurrentVersion[] = "1.2.3.4"; | 359 const char kCurrentVersion[] = "1.2.3.4"; |
| 360 Version current_version(kCurrentVersion); | 360 base::Version current_version(kCurrentVersion); |
| 361 | 361 |
| 362 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 362 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 363 EXPECT_EQ(root, installer_state.root_key()); | 363 EXPECT_EQ(root, installer_state.root_key()); |
| 364 | 364 |
| 365 { | 365 { |
| 366 RegistryOverrideManager override_manager; | 366 RegistryOverrideManager override_manager; |
| 367 override_manager.OverrideRegistry(root); | 367 override_manager.OverrideRegistry(root); |
| 368 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( | 368 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( |
| 369 BrowserDistribution::CHROME_BROWSER); | 369 BrowserDistribution::CHROME_BROWSER); |
| 370 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); | 370 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); |
| 371 EXPECT_TRUE(chrome_key.Valid()); | 371 EXPECT_TRUE(chrome_key.Valid()); |
| 372 if (chrome_key.Valid()) { | 372 if (chrome_key.Valid()) { |
| 373 chrome_key.WriteValue(google_update::kRegVersionField, | 373 chrome_key.WriteValue(google_update::kRegVersionField, |
| 374 base::UTF8ToWide( | 374 base::UTF8ToWide( |
| 375 current_version.GetString()).c_str()); | 375 current_version.GetString()).c_str()); |
| 376 machine_state.Initialize(); | 376 machine_state.Initialize(); |
| 377 // TODO(tommi): Also test for when there exists a new_chrome.exe. | 377 // TODO(tommi): Also test for when there exists a new_chrome.exe. |
| 378 Version found_version(*installer_state.GetCurrentVersion(machine_state)); | 378 base::Version found_version( |
| 379 *installer_state.GetCurrentVersion(machine_state)); |
| 379 EXPECT_TRUE(found_version.IsValid()); | 380 EXPECT_TRUE(found_version.IsValid()); |
| 380 if (found_version.IsValid()) | 381 if (found_version.IsValid()) |
| 381 EXPECT_EQ(current_version, found_version); | 382 EXPECT_EQ(current_version, found_version); |
| 382 } | 383 } |
| 383 } | 384 } |
| 384 } | 385 } |
| 385 | 386 |
| 386 TEST_F(InstallerStateTest, InstallerResult) { | 387 TEST_F(InstallerStateTest, InstallerResult) { |
| 387 const bool system_level = true; | 388 const bool system_level = true; |
| 388 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 389 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 460 |
| 460 // Test GetCurrentVersion when migrating single Chrome to multi | 461 // Test GetCurrentVersion when migrating single Chrome to multi |
| 461 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { | 462 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { |
| 462 using installer::FakeInstallationState; | 463 using installer::FakeInstallationState; |
| 463 | 464 |
| 464 const bool system_install = false; | 465 const bool system_install = false; |
| 465 FakeInstallationState machine_state; | 466 FakeInstallationState machine_state; |
| 466 | 467 |
| 467 // Pretend that this version of single-install Chrome is already installed. | 468 // Pretend that this version of single-install Chrome is already installed. |
| 468 machine_state.AddChrome(system_install, false, | 469 machine_state.AddChrome(system_install, false, |
| 469 new Version(chrome::kChromeVersion)); | 470 new base::Version(chrome::kChromeVersion)); |
| 470 | 471 |
| 471 // Now we're invoked to install multi Chrome. | 472 // Now we're invoked to install multi Chrome. |
| 472 base::CommandLine cmd_line( | 473 base::CommandLine cmd_line( |
| 473 base::CommandLine::FromString(L"setup.exe --multi-install --chrome")); | 474 base::CommandLine::FromString(L"setup.exe --multi-install --chrome")); |
| 474 MasterPreferences prefs(cmd_line); | 475 MasterPreferences prefs(cmd_line); |
| 475 InstallerState installer_state; | 476 InstallerState installer_state; |
| 476 installer_state.Initialize(cmd_line, prefs, machine_state); | 477 installer_state.Initialize(cmd_line, prefs, machine_state); |
| 477 | 478 |
| 478 // Is the Chrome version picked up? | 479 // Is the Chrome version picked up? |
| 479 std::unique_ptr<Version> version( | 480 std::unique_ptr<base::Version> version( |
| 480 installer_state.GetCurrentVersion(machine_state)); | 481 installer_state.GetCurrentVersion(machine_state)); |
| 481 EXPECT_TRUE(version.get() != NULL); | 482 EXPECT_TRUE(version.get() != NULL); |
| 482 } | 483 } |
| 483 | 484 |
| 484 TEST_F(InstallerStateTest, IsFileInUse) { | 485 TEST_F(InstallerStateTest, IsFileInUse) { |
| 485 base::ScopedTempDir temp_dir; | 486 base::ScopedTempDir temp_dir; |
| 486 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 487 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 487 | 488 |
| 488 base::FilePath temp_file; | 489 base::FilePath temp_file; |
| 489 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); | 490 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 512 MockInstallerState installer_state; | 513 MockInstallerState installer_state; |
| 513 installer_state.set_target_path(test_dir_.path()); | 514 installer_state.set_target_path(test_dir_.path()); |
| 514 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); | 515 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); |
| 515 | 516 |
| 516 const char kOldVersion[] = "2.0.0.0"; | 517 const char kOldVersion[] = "2.0.0.0"; |
| 517 const char kNewVersion[] = "3.0.0.0"; | 518 const char kNewVersion[] = "3.0.0.0"; |
| 518 const char kOldChromeExeVersion[] = "2.1.0.0"; | 519 const char kOldChromeExeVersion[] = "2.1.0.0"; |
| 519 const char kChromeExeVersion[] = "2.1.1.1"; | 520 const char kChromeExeVersion[] = "2.1.1.1"; |
| 520 const char kNewChromeExeVersion[] = "3.0.0.0"; | 521 const char kNewChromeExeVersion[] = "3.0.0.0"; |
| 521 | 522 |
| 522 Version new_version(kNewVersion); | 523 base::Version new_version(kNewVersion); |
| 523 Version old_version(kOldVersion); | 524 base::Version old_version(kOldVersion); |
| 524 Version old_chrome_exe_version(kOldChromeExeVersion); | 525 base::Version old_chrome_exe_version(kOldChromeExeVersion); |
| 525 Version chrome_exe_version(kChromeExeVersion); | 526 base::Version chrome_exe_version(kChromeExeVersion); |
| 526 Version new_chrome_exe_version(kNewChromeExeVersion); | 527 base::Version new_chrome_exe_version(kNewChromeExeVersion); |
| 527 | 528 |
| 528 ASSERT_TRUE(new_version.IsValid()); | 529 ASSERT_TRUE(new_version.IsValid()); |
| 529 ASSERT_TRUE(old_version.IsValid()); | 530 ASSERT_TRUE(old_version.IsValid()); |
| 530 ASSERT_TRUE(old_chrome_exe_version.IsValid()); | 531 ASSERT_TRUE(old_chrome_exe_version.IsValid()); |
| 531 ASSERT_TRUE(chrome_exe_version.IsValid()); | 532 ASSERT_TRUE(chrome_exe_version.IsValid()); |
| 532 ASSERT_TRUE(new_chrome_exe_version.IsValid()); | 533 ASSERT_TRUE(new_chrome_exe_version.IsValid()); |
| 533 | 534 |
| 534 // Set up a bunch of version dir paths. | 535 // Set up a bunch of version dir paths. |
| 535 base::FilePath version_dirs[] = { | 536 base::FilePath version_dirs[] = { |
| 536 installer_state.target_path().Append(L"1.2.3.4"), | 537 installer_state.target_path().Append(L"1.2.3.4"), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 550 EXPECT_TRUE(base::PathExists(version_dirs[i])); | 551 EXPECT_TRUE(base::PathExists(version_dirs[i])); |
| 551 } | 552 } |
| 552 | 553 |
| 553 // Create exes with the appropriate version resource. | 554 // Create exes with the appropriate version resource. |
| 554 // Use the current test exe as a baseline. | 555 // Use the current test exe as a baseline. |
| 555 base::FilePath exe_path; | 556 base::FilePath exe_path; |
| 556 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | 557 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
| 557 | 558 |
| 558 struct target_info { | 559 struct target_info { |
| 559 base::FilePath target_file; | 560 base::FilePath target_file; |
| 560 const Version& target_version; | 561 const base::Version& target_version; |
| 561 } targets[] = { | 562 } targets[] = { |
| 562 { installer_state.target_path().Append(installer::kChromeOldExe), | 563 { installer_state.target_path().Append(installer::kChromeOldExe), |
| 563 old_chrome_exe_version }, | 564 old_chrome_exe_version }, |
| 564 { installer_state.target_path().Append(installer::kChromeExe), | 565 { installer_state.target_path().Append(installer::kChromeExe), |
| 565 chrome_exe_version }, | 566 chrome_exe_version }, |
| 566 { installer_state.target_path().Append(installer::kChromeNewExe), | 567 { installer_state.target_path().Append(installer::kChromeNewExe), |
| 567 new_chrome_exe_version }, | 568 new_chrome_exe_version }, |
| 568 }; | 569 }; |
| 569 for (size_t i = 0; i < arraysize(targets); ++i) { | 570 for (size_t i = 0; i < arraysize(targets); ++i) { |
| 570 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( | 571 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 594 expected_remaining_dirs.insert(kOldChromeExeVersion); | 595 expected_remaining_dirs.insert(kOldChromeExeVersion); |
| 595 expected_remaining_dirs.insert(kChromeExeVersion); | 596 expected_remaining_dirs.insert(kChromeExeVersion); |
| 596 expected_remaining_dirs.insert(kNewChromeExeVersion); | 597 expected_remaining_dirs.insert(kNewChromeExeVersion); |
| 597 | 598 |
| 598 // Enumerate dirs in target_path(), ensure only desired remain. | 599 // Enumerate dirs in target_path(), ensure only desired remain. |
| 599 base::FileEnumerator version_enum(installer_state.target_path(), false, | 600 base::FileEnumerator version_enum(installer_state.target_path(), false, |
| 600 base::FileEnumerator::DIRECTORIES); | 601 base::FileEnumerator::DIRECTORIES); |
| 601 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); | 602 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); |
| 602 next_version = version_enum.Next()) { | 603 next_version = version_enum.Next()) { |
| 603 base::FilePath dir_name(next_version.BaseName()); | 604 base::FilePath dir_name(next_version.BaseName()); |
| 604 Version version(base::UTF16ToASCII(dir_name.value())); | 605 base::Version version(base::UTF16ToASCII(dir_name.value())); |
| 605 if (version.IsValid()) { | 606 if (version.IsValid()) { |
| 606 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) | 607 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) |
| 607 << "Unexpected version dir found: " << version.GetString(); | 608 << "Unexpected version dir found: " << version.GetString(); |
| 608 } | 609 } |
| 609 } | 610 } |
| 610 | 611 |
| 611 std::set<std::string>::const_iterator iter( | 612 std::set<std::string>::const_iterator iter( |
| 612 expected_remaining_dirs.begin()); | 613 expected_remaining_dirs.begin()); |
| 613 for (; iter != expected_remaining_dirs.end(); ++iter) | 614 for (; iter != expected_remaining_dirs.end(); ++iter) |
| 614 ADD_FAILURE() << "Expected to find version dir for " << *iter; | 615 ADD_FAILURE() << "Expected to find version dir for " << *iter; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 | 687 |
| 687 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual | 688 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual |
| 688 // tests must invoke Initialize() with a critical version. | 689 // tests must invoke Initialize() with a critical version. |
| 689 class InstallerStateCriticalVersionTest : public ::testing::Test { | 690 class InstallerStateCriticalVersionTest : public ::testing::Test { |
| 690 protected: | 691 protected: |
| 691 InstallerStateCriticalVersionTest() | 692 InstallerStateCriticalVersionTest() |
| 692 : cmd_line_(base::CommandLine::NO_PROGRAM) {} | 693 : cmd_line_(base::CommandLine::NO_PROGRAM) {} |
| 693 | 694 |
| 694 // Creates a set of versions for use by all test runs. | 695 // Creates a set of versions for use by all test runs. |
| 695 static void SetUpTestCase() { | 696 static void SetUpTestCase() { |
| 696 low_version_ = new Version("15.0.874.106"); | 697 low_version_ = new base::Version("15.0.874.106"); |
| 697 opv_version_ = new Version("15.0.874.255"); | 698 opv_version_ = new base::Version("15.0.874.255"); |
| 698 middle_version_ = new Version("16.0.912.32"); | 699 middle_version_ = new base::Version("16.0.912.32"); |
| 699 pv_version_ = new Version("16.0.912.255"); | 700 pv_version_ = new base::Version("16.0.912.255"); |
| 700 high_version_ = new Version("17.0.932.0"); | 701 high_version_ = new base::Version("17.0.932.0"); |
| 701 } | 702 } |
| 702 | 703 |
| 703 // Cleans up versions used by all test runs. | 704 // Cleans up versions used by all test runs. |
| 704 static void TearDownTestCase() { | 705 static void TearDownTestCase() { |
| 705 delete low_version_; | 706 delete low_version_; |
| 706 delete opv_version_; | 707 delete opv_version_; |
| 707 delete middle_version_; | 708 delete middle_version_; |
| 708 delete pv_version_; | 709 delete pv_version_; |
| 709 delete high_version_; | 710 delete high_version_; |
| 710 } | 711 } |
| 711 | 712 |
| 712 // Initializes the InstallerState to use for a test run. The returned | 713 // Initializes the InstallerState to use for a test run. The returned |
| 713 // instance's critical update version is set to |version|. |version| may be | 714 // instance's critical update version is set to |version|. |version| may be |
| 714 // NULL, in which case the critical update version is unset. | 715 // NULL, in which case the critical update version is unset. |
| 715 MockInstallerState& Initialize(const Version* version) { | 716 MockInstallerState& Initialize(const base::Version* version) { |
| 716 cmd_line_ = version == NULL ? base::CommandLine::FromString(L"setup.exe") | 717 cmd_line_ = version == NULL ? base::CommandLine::FromString(L"setup.exe") |
| 717 : base::CommandLine::FromString( | 718 : base::CommandLine::FromString( |
| 718 L"setup.exe --critical-update-version=" + | 719 L"setup.exe --critical-update-version=" + |
| 719 base::ASCIIToUTF16(version->GetString())); | 720 base::ASCIIToUTF16(version->GetString())); |
| 720 prefs_.reset(new MasterPreferences(cmd_line_)); | 721 prefs_.reset(new MasterPreferences(cmd_line_)); |
| 721 machine_state_.Initialize(); | 722 machine_state_.Initialize(); |
| 722 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); | 723 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); |
| 723 return installer_state_; | 724 return installer_state_; |
| 724 } | 725 } |
| 725 | 726 |
| 726 static Version* low_version_; | 727 static base::Version* low_version_; |
| 727 static Version* opv_version_; | 728 static base::Version* opv_version_; |
| 728 static Version* middle_version_; | 729 static base::Version* middle_version_; |
| 729 static Version* pv_version_; | 730 static base::Version* pv_version_; |
| 730 static Version* high_version_; | 731 static base::Version* high_version_; |
| 731 | 732 |
| 732 base::CommandLine cmd_line_; | 733 base::CommandLine cmd_line_; |
| 733 std::unique_ptr<MasterPreferences> prefs_; | 734 std::unique_ptr<MasterPreferences> prefs_; |
| 734 InstallationState machine_state_; | 735 InstallationState machine_state_; |
| 735 MockInstallerState installer_state_; | 736 MockInstallerState installer_state_; |
| 736 }; | 737 }; |
| 737 | 738 |
| 738 Version* InstallerStateCriticalVersionTest::low_version_ = NULL; | 739 base::Version* InstallerStateCriticalVersionTest::low_version_ = NULL; |
| 739 Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; | 740 base::Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; |
| 740 Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; | 741 base::Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; |
| 741 Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; | 742 base::Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; |
| 742 Version* InstallerStateCriticalVersionTest::high_version_ = NULL; | 743 base::Version* InstallerStateCriticalVersionTest::high_version_ = NULL; |
| 743 | 744 |
| 744 // Test the case where the critical version is less than the currently-running | 745 // Test the case where the critical version is less than the currently-running |
| 745 // Chrome. The critical version is ignored since it doesn't apply. | 746 // Chrome. The critical version is ignored since it doesn't apply. |
| 746 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { | 747 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { |
| 747 MockInstallerState& installer_state(Initialize(low_version_)); | 748 MockInstallerState& installer_state(Initialize(low_version_)); |
| 748 | 749 |
| 749 EXPECT_EQ(installer_state.critical_update_version(), *low_version_); | 750 EXPECT_EQ(installer_state.critical_update_version(), *low_version_); |
| 750 // Unable to determine the installed version, so assume critical update. | 751 // Unable to determine the installed version, so assume critical update. |
| 751 EXPECT_TRUE( | 752 EXPECT_TRUE( |
| 752 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 753 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 // Critical update newer than the new version. | 827 // Critical update newer than the new version. |
| 827 EXPECT_FALSE( | 828 EXPECT_FALSE( |
| 828 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 829 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
| 829 EXPECT_FALSE( | 830 EXPECT_FALSE( |
| 830 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) | 831 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) |
| 831 .IsValid()); | 832 .IsValid()); |
| 832 EXPECT_FALSE( | 833 EXPECT_FALSE( |
| 833 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) | 834 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) |
| 834 .IsValid()); | 835 .IsValid()); |
| 835 } | 836 } |
| OLD | NEW |