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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 // An installer state on which we can access otherwise protected members. | 48 // An installer state on which we can access otherwise protected members. |
49 class MockInstallerState : public InstallerState { | 49 class MockInstallerState : public InstallerState { |
50 public: | 50 public: |
51 MockInstallerState() : InstallerState() { } | 51 MockInstallerState() : InstallerState() { } |
52 void set_target_path(const base::FilePath& target_path) { | 52 void set_target_path(const base::FilePath& target_path) { |
53 target_path_ = target_path; | 53 target_path_ = target_path; |
54 } | 54 } |
55 static bool IsFileInUse(const base::FilePath& file) { | 55 static bool IsFileInUse(const base::FilePath& file) { |
56 return InstallerState::IsFileInUse(file); | 56 return InstallerState::IsFileInUse(file); |
57 } | 57 } |
58 const Version& critical_update_version() const { | 58 const base::Version& critical_update_version() const { |
59 return critical_update_version_; | 59 return critical_update_version_; |
60 } | 60 } |
61 void GetExistingExeVersions(std::set<std::string>* existing_version_strings) { | 61 void GetExistingExeVersions(std::set<std::string>* existing_version_strings) { |
62 return InstallerState::GetExistingExeVersions(existing_version_strings); | 62 return InstallerState::GetExistingExeVersions(existing_version_strings); |
63 } | 63 } |
64 }; | 64 }; |
65 | 65 |
66 // Simple function to dump some text into a new file. | 66 // Simple function to dump some text into a new file. |
67 void CreateTextFile(const std::wstring& filename, | 67 void CreateTextFile(const std::wstring& filename, |
68 const std::wstring& contents) { | 68 const std::wstring& contents) { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 CreateTextFile(chrome_dll_3.value(), text_content_1); | 133 CreateTextFile(chrome_dll_3.value(), text_content_1); |
134 ASSERT_TRUE(base::PathExists(chrome_dll_3)); | 134 ASSERT_TRUE(base::PathExists(chrome_dll_3)); |
135 | 135 |
136 base::FilePath chrome_dll_4(chrome_dir_4); | 136 base::FilePath chrome_dll_4(chrome_dir_4); |
137 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); | 137 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); |
138 CreateTextFile(chrome_dll_4.value(), text_content_1); | 138 CreateTextFile(chrome_dll_4.value(), text_content_1); |
139 ASSERT_TRUE(base::PathExists(chrome_dll_4)); | 139 ASSERT_TRUE(base::PathExists(chrome_dll_4)); |
140 | 140 |
141 MockInstallerState installer_state; | 141 MockInstallerState installer_state; |
142 BuildSingleChromeState(chrome_dir, &installer_state); | 142 BuildSingleChromeState(chrome_dir, &installer_state); |
143 Version latest_version("1.0.4.0"); | 143 base::Version latest_version("1.0.4.0"); |
144 { | 144 { |
145 base::ScopedTempDir temp_dir; | 145 base::ScopedTempDir temp_dir; |
146 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 146 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
147 installer_state.RemoveOldVersionDirectories(latest_version, NULL, | 147 installer_state.RemoveOldVersionDirectories(latest_version, NULL, |
148 temp_dir.path()); | 148 temp_dir.path()); |
149 } | 149 } |
150 | 150 |
151 // old versions should be gone | 151 // old versions should be gone |
152 EXPECT_FALSE(base::PathExists(chrome_dir_1)); | 152 EXPECT_FALSE(base::PathExists(chrome_dir_1)); |
153 EXPECT_FALSE(base::PathExists(chrome_dir_2)); | 153 EXPECT_FALSE(base::PathExists(chrome_dir_2)); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 CreateTextFile(chrome_dll_3.value(), text_content_1); | 213 CreateTextFile(chrome_dll_3.value(), text_content_1); |
214 ASSERT_TRUE(base::PathExists(chrome_dll_3)); | 214 ASSERT_TRUE(base::PathExists(chrome_dll_3)); |
215 | 215 |
216 base::FilePath chrome_dll_4(chrome_dir_4); | 216 base::FilePath chrome_dll_4(chrome_dir_4); |
217 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); | 217 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); |
218 CreateTextFile(chrome_dll_4.value(), text_content_1); | 218 CreateTextFile(chrome_dll_4.value(), text_content_1); |
219 ASSERT_TRUE(base::PathExists(chrome_dll_4)); | 219 ASSERT_TRUE(base::PathExists(chrome_dll_4)); |
220 | 220 |
221 MockInstallerState installer_state; | 221 MockInstallerState installer_state; |
222 BuildSingleChromeState(chrome_dir, &installer_state); | 222 BuildSingleChromeState(chrome_dir, &installer_state); |
223 Version latest_version("1.0.4.0"); | 223 base::Version latest_version("1.0.4.0"); |
224 Version existing_version("1.0.1.0"); | 224 base::Version existing_version("1.0.1.0"); |
225 { | 225 { |
226 base::ScopedTempDir temp_dir; | 226 base::ScopedTempDir temp_dir; |
227 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 227 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
228 installer_state.RemoveOldVersionDirectories(latest_version, | 228 installer_state.RemoveOldVersionDirectories(latest_version, |
229 &existing_version, | 229 &existing_version, |
230 temp_dir.path()); | 230 temp_dir.path()); |
231 } | 231 } |
232 | 232 |
233 // the version defined as the existing version should stay | 233 // the version defined as the existing version should stay |
234 EXPECT_TRUE(base::PathExists(chrome_dir_1)); | 234 EXPECT_TRUE(base::PathExists(chrome_dir_1)); |
(...skipping 22 matching lines...) Expand all Loading... |
257 machine_state.Initialize(); | 257 machine_state.Initialize(); |
258 MockInstallerState installer_state; | 258 MockInstallerState installer_state; |
259 installer_state.Initialize(cmd_line, prefs, machine_state); | 259 installer_state.Initialize(cmd_line, prefs, machine_state); |
260 installer_state.set_target_path(test_dir_.path()); | 260 installer_state.set_target_path(test_dir_.path()); |
261 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); | 261 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); |
262 EXPECT_EQ(1U, installer_state.products().size()); | 262 EXPECT_EQ(1U, installer_state.products().size()); |
263 | 263 |
264 const char kOldVersion[] = "1.2.3.4"; | 264 const char kOldVersion[] = "1.2.3.4"; |
265 const char kNewVersion[] = "2.3.4.5"; | 265 const char kNewVersion[] = "2.3.4.5"; |
266 | 266 |
267 Version new_version(kNewVersion); | 267 base::Version new_version(kNewVersion); |
268 Version old_version(kOldVersion); | 268 base::Version old_version(kOldVersion); |
269 ASSERT_TRUE(new_version.IsValid()); | 269 ASSERT_TRUE(new_version.IsValid()); |
270 ASSERT_TRUE(old_version.IsValid()); | 270 ASSERT_TRUE(old_version.IsValid()); |
271 | 271 |
272 base::FilePath installer_dir( | 272 base::FilePath installer_dir( |
273 installer_state.GetInstallerDirectory(new_version)); | 273 installer_state.GetInstallerDirectory(new_version)); |
274 EXPECT_FALSE(installer_dir.empty()); | 274 EXPECT_FALSE(installer_dir.empty()); |
275 | 275 |
276 base::FilePath new_version_dir(installer_state.target_path().Append( | 276 base::FilePath new_version_dir(installer_state.target_path().Append( |
277 UTF8ToWide(new_version.GetString()))); | 277 UTF8ToWide(new_version.GetString()))); |
278 base::FilePath old_version_dir(installer_state.target_path().Append( | 278 base::FilePath old_version_dir(installer_state.target_path().Append( |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 MasterPreferences prefs(cmd_line); | 338 MasterPreferences prefs(cmd_line); |
339 InstallationState machine_state; | 339 InstallationState machine_state; |
340 machine_state.Initialize(); | 340 machine_state.Initialize(); |
341 MockInstallerState installer_state; | 341 MockInstallerState installer_state; |
342 installer_state.Initialize(cmd_line, prefs, machine_state); | 342 installer_state.Initialize(cmd_line, prefs, machine_state); |
343 installer_state.set_target_path(test_dir_.path()); | 343 installer_state.set_target_path(test_dir_.path()); |
344 EXPECT_EQ(1U, installer_state.products().size()); | 344 EXPECT_EQ(1U, installer_state.products().size()); |
345 EXPECT_EQ(system_level, installer_state.system_install()); | 345 EXPECT_EQ(system_level, installer_state.system_install()); |
346 | 346 |
347 const char kCurrentVersion[] = "1.2.3.4"; | 347 const char kCurrentVersion[] = "1.2.3.4"; |
348 Version current_version(kCurrentVersion); | 348 base::Version current_version(kCurrentVersion); |
349 | 349 |
350 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 350 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
351 EXPECT_EQ(root, installer_state.root_key()); | 351 EXPECT_EQ(root, installer_state.root_key()); |
352 | 352 |
353 { | 353 { |
354 RegistryOverrideManager override_manager; | 354 RegistryOverrideManager override_manager; |
355 override_manager.OverrideRegistry(root, L"root_pit"); | 355 override_manager.OverrideRegistry(root, L"root_pit"); |
356 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( | 356 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( |
357 BrowserDistribution::CHROME_BROWSER); | 357 BrowserDistribution::CHROME_BROWSER); |
358 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); | 358 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); |
359 EXPECT_TRUE(chrome_key.Valid()); | 359 EXPECT_TRUE(chrome_key.Valid()); |
360 if (chrome_key.Valid()) { | 360 if (chrome_key.Valid()) { |
361 chrome_key.WriteValue(google_update::kRegVersionField, | 361 chrome_key.WriteValue(google_update::kRegVersionField, |
362 UTF8ToWide(current_version.GetString()).c_str()); | 362 UTF8ToWide(current_version.GetString()).c_str()); |
363 machine_state.Initialize(); | 363 machine_state.Initialize(); |
364 // TODO(tommi): Also test for when there exists a new_chrome.exe. | 364 // TODO(tommi): Also test for when there exists a new_chrome.exe. |
365 Version found_version(*installer_state.GetCurrentVersion(machine_state)); | 365 base::Version found_version( |
| 366 *installer_state.GetCurrentVersion(machine_state)); |
366 EXPECT_TRUE(found_version.IsValid()); | 367 EXPECT_TRUE(found_version.IsValid()); |
367 if (found_version.IsValid()) | 368 if (found_version.IsValid()) |
368 EXPECT_TRUE(current_version.Equals(found_version)); | 369 EXPECT_TRUE(current_version.Equals(found_version)); |
369 } | 370 } |
370 } | 371 } |
371 } | 372 } |
372 | 373 |
373 TEST_F(InstallerStateTest, InstallerResult) { | 374 TEST_F(InstallerStateTest, InstallerResult) { |
374 const bool system_level = true; | 375 const bool system_level = true; |
375 bool multi_install = false; | 376 bool multi_install = false; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 | 447 |
447 // Test GetCurrentVersion when migrating single Chrome to multi | 448 // Test GetCurrentVersion when migrating single Chrome to multi |
448 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { | 449 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { |
449 using installer::FakeInstallationState; | 450 using installer::FakeInstallationState; |
450 | 451 |
451 const bool system_install = false; | 452 const bool system_install = false; |
452 FakeInstallationState machine_state; | 453 FakeInstallationState machine_state; |
453 | 454 |
454 // Pretend that this version of single-install Chrome is already installed. | 455 // Pretend that this version of single-install Chrome is already installed. |
455 machine_state.AddChrome(system_install, false, | 456 machine_state.AddChrome(system_install, false, |
456 new Version(chrome::kChromeVersion)); | 457 new base::Version(chrome::kChromeVersion)); |
457 | 458 |
458 // Now we're invoked to install multi Chrome. | 459 // Now we're invoked to install multi Chrome. |
459 CommandLine cmd_line( | 460 CommandLine cmd_line( |
460 CommandLine::FromString(L"setup.exe --multi-install --chrome")); | 461 CommandLine::FromString(L"setup.exe --multi-install --chrome")); |
461 MasterPreferences prefs(cmd_line); | 462 MasterPreferences prefs(cmd_line); |
462 InstallerState installer_state; | 463 InstallerState installer_state; |
463 installer_state.Initialize(cmd_line, prefs, machine_state); | 464 installer_state.Initialize(cmd_line, prefs, machine_state); |
464 | 465 |
465 // Is the Chrome version picked up? | 466 // Is the Chrome version picked up? |
466 scoped_ptr<Version> version(installer_state.GetCurrentVersion(machine_state)); | 467 scoped_ptr<base::Version> version( |
| 468 installer_state.GetCurrentVersion(machine_state)); |
467 EXPECT_TRUE(version.get() != NULL); | 469 EXPECT_TRUE(version.get() != NULL); |
468 } | 470 } |
469 | 471 |
470 TEST_F(InstallerStateTest, IsFileInUse) { | 472 TEST_F(InstallerStateTest, IsFileInUse) { |
471 base::ScopedTempDir temp_dir; | 473 base::ScopedTempDir temp_dir; |
472 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 474 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
473 | 475 |
474 base::FilePath temp_file; | 476 base::FilePath temp_file; |
475 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); | 477 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); |
476 | 478 |
(...skipping 21 matching lines...) Expand all Loading... |
498 MockInstallerState installer_state; | 500 MockInstallerState installer_state; |
499 installer_state.set_target_path(test_dir_.path()); | 501 installer_state.set_target_path(test_dir_.path()); |
500 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); | 502 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); |
501 | 503 |
502 const char kOldVersion[] = "2.0.0.0"; | 504 const char kOldVersion[] = "2.0.0.0"; |
503 const char kNewVersion[] = "3.0.0.0"; | 505 const char kNewVersion[] = "3.0.0.0"; |
504 const char kOldChromeExeVersion[] = "2.1.0.0"; | 506 const char kOldChromeExeVersion[] = "2.1.0.0"; |
505 const char kChromeExeVersion[] = "2.1.1.1"; | 507 const char kChromeExeVersion[] = "2.1.1.1"; |
506 const char kNewChromeExeVersion[] = "3.0.0.0"; | 508 const char kNewChromeExeVersion[] = "3.0.0.0"; |
507 | 509 |
508 Version new_version(kNewVersion); | 510 base::Version new_version(kNewVersion); |
509 Version old_version(kOldVersion); | 511 base::Version old_version(kOldVersion); |
510 Version old_chrome_exe_version(kOldChromeExeVersion); | 512 base::Version old_chrome_exe_version(kOldChromeExeVersion); |
511 Version chrome_exe_version(kChromeExeVersion); | 513 base::Version chrome_exe_version(kChromeExeVersion); |
512 Version new_chrome_exe_version(kNewChromeExeVersion); | 514 base::Version new_chrome_exe_version(kNewChromeExeVersion); |
513 | 515 |
514 ASSERT_TRUE(new_version.IsValid()); | 516 ASSERT_TRUE(new_version.IsValid()); |
515 ASSERT_TRUE(old_version.IsValid()); | 517 ASSERT_TRUE(old_version.IsValid()); |
516 ASSERT_TRUE(old_chrome_exe_version.IsValid()); | 518 ASSERT_TRUE(old_chrome_exe_version.IsValid()); |
517 ASSERT_TRUE(chrome_exe_version.IsValid()); | 519 ASSERT_TRUE(chrome_exe_version.IsValid()); |
518 ASSERT_TRUE(new_chrome_exe_version.IsValid()); | 520 ASSERT_TRUE(new_chrome_exe_version.IsValid()); |
519 | 521 |
520 // Set up a bunch of version dir paths. | 522 // Set up a bunch of version dir paths. |
521 base::FilePath version_dirs[] = { | 523 base::FilePath version_dirs[] = { |
522 installer_state.target_path().Append(L"1.2.3.4"), | 524 installer_state.target_path().Append(L"1.2.3.4"), |
(...skipping 13 matching lines...) Expand all Loading... |
536 EXPECT_TRUE(base::PathExists(version_dirs[i])); | 538 EXPECT_TRUE(base::PathExists(version_dirs[i])); |
537 } | 539 } |
538 | 540 |
539 // Create exes with the appropriate version resource. | 541 // Create exes with the appropriate version resource. |
540 // Use the current test exe as a baseline. | 542 // Use the current test exe as a baseline. |
541 base::FilePath exe_path; | 543 base::FilePath exe_path; |
542 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | 544 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
543 | 545 |
544 struct target_info { | 546 struct target_info { |
545 base::FilePath target_file; | 547 base::FilePath target_file; |
546 const Version& target_version; | 548 const base::Version& target_version; |
547 } targets[] = { | 549 } targets[] = { |
548 { installer_state.target_path().Append(installer::kChromeOldExe), | 550 { installer_state.target_path().Append(installer::kChromeOldExe), |
549 old_chrome_exe_version }, | 551 old_chrome_exe_version }, |
550 { installer_state.target_path().Append(installer::kChromeExe), | 552 { installer_state.target_path().Append(installer::kChromeExe), |
551 chrome_exe_version }, | 553 chrome_exe_version }, |
552 { installer_state.target_path().Append(installer::kChromeNewExe), | 554 { installer_state.target_path().Append(installer::kChromeNewExe), |
553 new_chrome_exe_version }, | 555 new_chrome_exe_version }, |
554 }; | 556 }; |
555 for (int i = 0; i < arraysize(targets); ++i) { | 557 for (int i = 0; i < arraysize(targets); ++i) { |
556 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( | 558 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( |
(...skipping 23 matching lines...) Expand all Loading... |
580 expected_remaining_dirs.insert(kOldChromeExeVersion); | 582 expected_remaining_dirs.insert(kOldChromeExeVersion); |
581 expected_remaining_dirs.insert(kChromeExeVersion); | 583 expected_remaining_dirs.insert(kChromeExeVersion); |
582 expected_remaining_dirs.insert(kNewChromeExeVersion); | 584 expected_remaining_dirs.insert(kNewChromeExeVersion); |
583 | 585 |
584 // Enumerate dirs in target_path(), ensure only desired remain. | 586 // Enumerate dirs in target_path(), ensure only desired remain. |
585 base::FileEnumerator version_enum(installer_state.target_path(), false, | 587 base::FileEnumerator version_enum(installer_state.target_path(), false, |
586 base::FileEnumerator::DIRECTORIES); | 588 base::FileEnumerator::DIRECTORIES); |
587 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); | 589 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); |
588 next_version = version_enum.Next()) { | 590 next_version = version_enum.Next()) { |
589 base::FilePath dir_name(next_version.BaseName()); | 591 base::FilePath dir_name(next_version.BaseName()); |
590 Version version(WideToASCII(dir_name.value())); | 592 base::Version version(WideToASCII(dir_name.value())); |
591 if (version.IsValid()) { | 593 if (version.IsValid()) { |
592 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) | 594 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) |
593 << "Unexpected version dir found: " << version.GetString(); | 595 << "Unexpected version dir found: " << version.GetString(); |
594 } | 596 } |
595 } | 597 } |
596 | 598 |
597 std::set<std::string>::const_iterator iter( | 599 std::set<std::string>::const_iterator iter( |
598 expected_remaining_dirs.begin()); | 600 expected_remaining_dirs.begin()); |
599 for (; iter != expected_remaining_dirs.end(); ++iter) | 601 for (; iter != expected_remaining_dirs.end(); ++iter) |
600 ADD_FAILURE() << "Expected to find version dir for " << *iter; | 602 ADD_FAILURE() << "Expected to find version dir for " << *iter; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
655 } | 657 } |
656 | 658 |
657 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual | 659 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual |
658 // tests must invoke Initialize() with a critical version. | 660 // tests must invoke Initialize() with a critical version. |
659 class InstallerStateCriticalVersionTest : public ::testing::Test { | 661 class InstallerStateCriticalVersionTest : public ::testing::Test { |
660 protected: | 662 protected: |
661 InstallerStateCriticalVersionTest() : cmd_line_(CommandLine::NO_PROGRAM) {} | 663 InstallerStateCriticalVersionTest() : cmd_line_(CommandLine::NO_PROGRAM) {} |
662 | 664 |
663 // Creates a set of versions for use by all test runs. | 665 // Creates a set of versions for use by all test runs. |
664 static void SetUpTestCase() { | 666 static void SetUpTestCase() { |
665 low_version_ = new Version("15.0.874.106"); | 667 low_version_ = new base::Version("15.0.874.106"); |
666 opv_version_ = new Version("15.0.874.255"); | 668 opv_version_ = new base::Version("15.0.874.255"); |
667 middle_version_ = new Version("16.0.912.32"); | 669 middle_version_ = new base::Version("16.0.912.32"); |
668 pv_version_ = new Version("16.0.912.255"); | 670 pv_version_ = new base::Version("16.0.912.255"); |
669 high_version_ = new Version("17.0.932.0"); | 671 high_version_ = new base::Version("17.0.932.0"); |
670 } | 672 } |
671 | 673 |
672 // Cleans up versions used by all test runs. | 674 // Cleans up versions used by all test runs. |
673 static void TearDownTestCase() { | 675 static void TearDownTestCase() { |
674 delete low_version_; | 676 delete low_version_; |
675 delete opv_version_; | 677 delete opv_version_; |
676 delete middle_version_; | 678 delete middle_version_; |
677 delete pv_version_; | 679 delete pv_version_; |
678 delete high_version_; | 680 delete high_version_; |
679 } | 681 } |
680 | 682 |
681 // Initializes the InstallerState to use for a test run. The returned | 683 // Initializes the InstallerState to use for a test run. The returned |
682 // instance's critical update version is set to |version|. |version| may be | 684 // instance's critical update version is set to |version|. |version| may be |
683 // NULL, in which case the critical update version is unset. | 685 // NULL, in which case the critical update version is unset. |
684 MockInstallerState& Initialize(const Version* version) { | 686 MockInstallerState& Initialize(const base::Version* version) { |
685 cmd_line_ = version == NULL ? | 687 cmd_line_ = version == NULL ? |
686 CommandLine::FromString(L"setup.exe") : | 688 CommandLine::FromString(L"setup.exe") : |
687 CommandLine::FromString( | 689 CommandLine::FromString( |
688 L"setup.exe --critical-update-version=" + | 690 L"setup.exe --critical-update-version=" + |
689 ASCIIToWide(version->GetString())); | 691 ASCIIToWide(version->GetString())); |
690 prefs_.reset(new MasterPreferences(cmd_line_)); | 692 prefs_.reset(new MasterPreferences(cmd_line_)); |
691 machine_state_.Initialize(); | 693 machine_state_.Initialize(); |
692 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); | 694 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); |
693 return installer_state_; | 695 return installer_state_; |
694 } | 696 } |
695 | 697 |
696 static Version* low_version_; | 698 static base::Version* low_version_; |
697 static Version* opv_version_; | 699 static base::Version* opv_version_; |
698 static Version* middle_version_; | 700 static base::Version* middle_version_; |
699 static Version* pv_version_; | 701 static base::Version* pv_version_; |
700 static Version* high_version_; | 702 static base::Version* high_version_; |
701 | 703 |
702 CommandLine cmd_line_; | 704 CommandLine cmd_line_; |
703 scoped_ptr<MasterPreferences> prefs_; | 705 scoped_ptr<MasterPreferences> prefs_; |
704 InstallationState machine_state_; | 706 InstallationState machine_state_; |
705 MockInstallerState installer_state_; | 707 MockInstallerState installer_state_; |
706 }; | 708 }; |
707 | 709 |
708 Version* InstallerStateCriticalVersionTest::low_version_ = NULL; | 710 base::Version* InstallerStateCriticalVersionTest::low_version_ = NULL; |
709 Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; | 711 base::Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; |
710 Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; | 712 base::Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; |
711 Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; | 713 base::Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; |
712 Version* InstallerStateCriticalVersionTest::high_version_ = NULL; | 714 base::Version* InstallerStateCriticalVersionTest::high_version_ = NULL; |
713 | 715 |
714 // Test the case where the critical version is less than the currently-running | 716 // Test the case where the critical version is less than the currently-running |
715 // Chrome. The critical version is ignored since it doesn't apply. | 717 // Chrome. The critical version is ignored since it doesn't apply. |
716 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { | 718 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { |
717 MockInstallerState& installer_state(Initialize(low_version_)); | 719 MockInstallerState& installer_state(Initialize(low_version_)); |
718 | 720 |
719 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_)); | 721 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_)); |
720 // Unable to determine the installed version, so assume critical update. | 722 // Unable to determine the installed version, so assume critical update. |
721 EXPECT_TRUE( | 723 EXPECT_TRUE( |
722 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 724 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 // Critical update newer than the new version. | 801 // Critical update newer than the new version. |
800 EXPECT_FALSE( | 802 EXPECT_FALSE( |
801 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 803 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
802 EXPECT_FALSE( | 804 EXPECT_FALSE( |
803 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) | 805 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) |
804 .IsValid()); | 806 .IsValid()); |
805 EXPECT_FALSE( | 807 EXPECT_FALSE( |
806 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) | 808 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) |
807 .IsValid()); | 809 .IsValid()); |
808 } | 810 } |
OLD | NEW |