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 base::Version& critical_update_version() const { | 58 const 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 base::Version latest_version("1.0.4.0"); | 143 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 base::Version latest_version("1.0.4.0"); | 223 Version latest_version("1.0.4.0"); |
224 base::Version existing_version("1.0.1.0"); | 224 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 base::Version new_version(kNewVersion); | 267 Version new_version(kNewVersion); |
268 base::Version old_version(kOldVersion); | 268 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 base::UTF8ToWide(new_version.GetString()))); | 277 base::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 base::Version current_version(kCurrentVersion); | 348 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 base::UTF8ToWide( | 362 base::UTF8ToWide( |
363 current_version.GetString()).c_str()); | 363 current_version.GetString()).c_str()); |
364 machine_state.Initialize(); | 364 machine_state.Initialize(); |
365 // TODO(tommi): Also test for when there exists a new_chrome.exe. | 365 // TODO(tommi): Also test for when there exists a new_chrome.exe. |
366 base::Version found_version( | 366 Version found_version(*installer_state.GetCurrentVersion(machine_state)); |
367 *installer_state.GetCurrentVersion(machine_state)); | |
368 EXPECT_TRUE(found_version.IsValid()); | 367 EXPECT_TRUE(found_version.IsValid()); |
369 if (found_version.IsValid()) | 368 if (found_version.IsValid()) |
370 EXPECT_TRUE(current_version.Equals(found_version)); | 369 EXPECT_TRUE(current_version.Equals(found_version)); |
371 } | 370 } |
372 } | 371 } |
373 } | 372 } |
374 | 373 |
375 TEST_F(InstallerStateTest, InstallerResult) { | 374 TEST_F(InstallerStateTest, InstallerResult) { |
376 const bool system_level = true; | 375 const bool system_level = true; |
377 bool multi_install = false; | 376 bool multi_install = false; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 | 447 |
449 // Test GetCurrentVersion when migrating single Chrome to multi | 448 // Test GetCurrentVersion when migrating single Chrome to multi |
450 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { | 449 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { |
451 using installer::FakeInstallationState; | 450 using installer::FakeInstallationState; |
452 | 451 |
453 const bool system_install = false; | 452 const bool system_install = false; |
454 FakeInstallationState machine_state; | 453 FakeInstallationState machine_state; |
455 | 454 |
456 // Pretend that this version of single-install Chrome is already installed. | 455 // Pretend that this version of single-install Chrome is already installed. |
457 machine_state.AddChrome(system_install, false, | 456 machine_state.AddChrome(system_install, false, |
458 new base::Version(chrome::kChromeVersion)); | 457 new Version(chrome::kChromeVersion)); |
459 | 458 |
460 // Now we're invoked to install multi Chrome. | 459 // Now we're invoked to install multi Chrome. |
461 CommandLine cmd_line( | 460 CommandLine cmd_line( |
462 CommandLine::FromString(L"setup.exe --multi-install --chrome")); | 461 CommandLine::FromString(L"setup.exe --multi-install --chrome")); |
463 MasterPreferences prefs(cmd_line); | 462 MasterPreferences prefs(cmd_line); |
464 InstallerState installer_state; | 463 InstallerState installer_state; |
465 installer_state.Initialize(cmd_line, prefs, machine_state); | 464 installer_state.Initialize(cmd_line, prefs, machine_state); |
466 | 465 |
467 // Is the Chrome version picked up? | 466 // Is the Chrome version picked up? |
468 scoped_ptr<base::Version> version( | 467 scoped_ptr<Version> version(installer_state.GetCurrentVersion(machine_state)); |
469 installer_state.GetCurrentVersion(machine_state)); | |
470 EXPECT_TRUE(version.get() != NULL); | 468 EXPECT_TRUE(version.get() != NULL); |
471 } | 469 } |
472 | 470 |
473 TEST_F(InstallerStateTest, IsFileInUse) { | 471 TEST_F(InstallerStateTest, IsFileInUse) { |
474 base::ScopedTempDir temp_dir; | 472 base::ScopedTempDir temp_dir; |
475 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 473 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
476 | 474 |
477 base::FilePath temp_file; | 475 base::FilePath temp_file; |
478 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); | 476 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); |
479 | 477 |
(...skipping 21 matching lines...) Expand all Loading... |
501 MockInstallerState installer_state; | 499 MockInstallerState installer_state; |
502 installer_state.set_target_path(test_dir_.path()); | 500 installer_state.set_target_path(test_dir_.path()); |
503 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); | 501 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); |
504 | 502 |
505 const char kOldVersion[] = "2.0.0.0"; | 503 const char kOldVersion[] = "2.0.0.0"; |
506 const char kNewVersion[] = "3.0.0.0"; | 504 const char kNewVersion[] = "3.0.0.0"; |
507 const char kOldChromeExeVersion[] = "2.1.0.0"; | 505 const char kOldChromeExeVersion[] = "2.1.0.0"; |
508 const char kChromeExeVersion[] = "2.1.1.1"; | 506 const char kChromeExeVersion[] = "2.1.1.1"; |
509 const char kNewChromeExeVersion[] = "3.0.0.0"; | 507 const char kNewChromeExeVersion[] = "3.0.0.0"; |
510 | 508 |
511 base::Version new_version(kNewVersion); | 509 Version new_version(kNewVersion); |
512 base::Version old_version(kOldVersion); | 510 Version old_version(kOldVersion); |
513 base::Version old_chrome_exe_version(kOldChromeExeVersion); | 511 Version old_chrome_exe_version(kOldChromeExeVersion); |
514 base::Version chrome_exe_version(kChromeExeVersion); | 512 Version chrome_exe_version(kChromeExeVersion); |
515 base::Version new_chrome_exe_version(kNewChromeExeVersion); | 513 Version new_chrome_exe_version(kNewChromeExeVersion); |
516 | 514 |
517 ASSERT_TRUE(new_version.IsValid()); | 515 ASSERT_TRUE(new_version.IsValid()); |
518 ASSERT_TRUE(old_version.IsValid()); | 516 ASSERT_TRUE(old_version.IsValid()); |
519 ASSERT_TRUE(old_chrome_exe_version.IsValid()); | 517 ASSERT_TRUE(old_chrome_exe_version.IsValid()); |
520 ASSERT_TRUE(chrome_exe_version.IsValid()); | 518 ASSERT_TRUE(chrome_exe_version.IsValid()); |
521 ASSERT_TRUE(new_chrome_exe_version.IsValid()); | 519 ASSERT_TRUE(new_chrome_exe_version.IsValid()); |
522 | 520 |
523 // Set up a bunch of version dir paths. | 521 // Set up a bunch of version dir paths. |
524 base::FilePath version_dirs[] = { | 522 base::FilePath version_dirs[] = { |
525 installer_state.target_path().Append(L"1.2.3.4"), | 523 installer_state.target_path().Append(L"1.2.3.4"), |
(...skipping 14 matching lines...) Expand all Loading... |
540 EXPECT_TRUE(base::PathExists(version_dirs[i])); | 538 EXPECT_TRUE(base::PathExists(version_dirs[i])); |
541 } | 539 } |
542 | 540 |
543 // Create exes with the appropriate version resource. | 541 // Create exes with the appropriate version resource. |
544 // Use the current test exe as a baseline. | 542 // Use the current test exe as a baseline. |
545 base::FilePath exe_path; | 543 base::FilePath exe_path; |
546 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | 544 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
547 | 545 |
548 struct target_info { | 546 struct target_info { |
549 base::FilePath target_file; | 547 base::FilePath target_file; |
550 const base::Version& target_version; | 548 const Version& target_version; |
551 } targets[] = { | 549 } targets[] = { |
552 { installer_state.target_path().Append(installer::kChromeOldExe), | 550 { installer_state.target_path().Append(installer::kChromeOldExe), |
553 old_chrome_exe_version }, | 551 old_chrome_exe_version }, |
554 { installer_state.target_path().Append(installer::kChromeExe), | 552 { installer_state.target_path().Append(installer::kChromeExe), |
555 chrome_exe_version }, | 553 chrome_exe_version }, |
556 { installer_state.target_path().Append(installer::kChromeNewExe), | 554 { installer_state.target_path().Append(installer::kChromeNewExe), |
557 new_chrome_exe_version }, | 555 new_chrome_exe_version }, |
558 }; | 556 }; |
559 for (int i = 0; i < arraysize(targets); ++i) { | 557 for (int i = 0; i < arraysize(targets); ++i) { |
560 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( | 558 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( |
(...skipping 23 matching lines...) Expand all Loading... |
584 expected_remaining_dirs.insert(kOldChromeExeVersion); | 582 expected_remaining_dirs.insert(kOldChromeExeVersion); |
585 expected_remaining_dirs.insert(kChromeExeVersion); | 583 expected_remaining_dirs.insert(kChromeExeVersion); |
586 expected_remaining_dirs.insert(kNewChromeExeVersion); | 584 expected_remaining_dirs.insert(kNewChromeExeVersion); |
587 | 585 |
588 // Enumerate dirs in target_path(), ensure only desired remain. | 586 // Enumerate dirs in target_path(), ensure only desired remain. |
589 base::FileEnumerator version_enum(installer_state.target_path(), false, | 587 base::FileEnumerator version_enum(installer_state.target_path(), false, |
590 base::FileEnumerator::DIRECTORIES); | 588 base::FileEnumerator::DIRECTORIES); |
591 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); | 589 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); |
592 next_version = version_enum.Next()) { | 590 next_version = version_enum.Next()) { |
593 base::FilePath dir_name(next_version.BaseName()); | 591 base::FilePath dir_name(next_version.BaseName()); |
594 base::Version version(WideToASCII(dir_name.value())); | 592 Version version(WideToASCII(dir_name.value())); |
595 if (version.IsValid()) { | 593 if (version.IsValid()) { |
596 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) | 594 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) |
597 << "Unexpected version dir found: " << version.GetString(); | 595 << "Unexpected version dir found: " << version.GetString(); |
598 } | 596 } |
599 } | 597 } |
600 | 598 |
601 std::set<std::string>::const_iterator iter( | 599 std::set<std::string>::const_iterator iter( |
602 expected_remaining_dirs.begin()); | 600 expected_remaining_dirs.begin()); |
603 for (; iter != expected_remaining_dirs.end(); ++iter) | 601 for (; iter != expected_remaining_dirs.end(); ++iter) |
604 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... |
659 } | 657 } |
660 | 658 |
661 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual | 659 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual |
662 // tests must invoke Initialize() with a critical version. | 660 // tests must invoke Initialize() with a critical version. |
663 class InstallerStateCriticalVersionTest : public ::testing::Test { | 661 class InstallerStateCriticalVersionTest : public ::testing::Test { |
664 protected: | 662 protected: |
665 InstallerStateCriticalVersionTest() : cmd_line_(CommandLine::NO_PROGRAM) {} | 663 InstallerStateCriticalVersionTest() : cmd_line_(CommandLine::NO_PROGRAM) {} |
666 | 664 |
667 // Creates a set of versions for use by all test runs. | 665 // Creates a set of versions for use by all test runs. |
668 static void SetUpTestCase() { | 666 static void SetUpTestCase() { |
669 low_version_ = new base::Version("15.0.874.106"); | 667 low_version_ = new Version("15.0.874.106"); |
670 opv_version_ = new base::Version("15.0.874.255"); | 668 opv_version_ = new Version("15.0.874.255"); |
671 middle_version_ = new base::Version("16.0.912.32"); | 669 middle_version_ = new Version("16.0.912.32"); |
672 pv_version_ = new base::Version("16.0.912.255"); | 670 pv_version_ = new Version("16.0.912.255"); |
673 high_version_ = new base::Version("17.0.932.0"); | 671 high_version_ = new Version("17.0.932.0"); |
674 } | 672 } |
675 | 673 |
676 // Cleans up versions used by all test runs. | 674 // Cleans up versions used by all test runs. |
677 static void TearDownTestCase() { | 675 static void TearDownTestCase() { |
678 delete low_version_; | 676 delete low_version_; |
679 delete opv_version_; | 677 delete opv_version_; |
680 delete middle_version_; | 678 delete middle_version_; |
681 delete pv_version_; | 679 delete pv_version_; |
682 delete high_version_; | 680 delete high_version_; |
683 } | 681 } |
684 | 682 |
685 // Initializes the InstallerState to use for a test run. The returned | 683 // Initializes the InstallerState to use for a test run. The returned |
686 // 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 |
687 // NULL, in which case the critical update version is unset. | 685 // NULL, in which case the critical update version is unset. |
688 MockInstallerState& Initialize(const base::Version* version) { | 686 MockInstallerState& Initialize(const Version* version) { |
689 cmd_line_ = version == NULL ? | 687 cmd_line_ = version == NULL ? |
690 CommandLine::FromString(L"setup.exe") : | 688 CommandLine::FromString(L"setup.exe") : |
691 CommandLine::FromString( | 689 CommandLine::FromString( |
692 L"setup.exe --critical-update-version=" + | 690 L"setup.exe --critical-update-version=" + |
693 base::ASCIIToWide(version->GetString())); | 691 base::ASCIIToWide(version->GetString())); |
694 prefs_.reset(new MasterPreferences(cmd_line_)); | 692 prefs_.reset(new MasterPreferences(cmd_line_)); |
695 machine_state_.Initialize(); | 693 machine_state_.Initialize(); |
696 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); | 694 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); |
697 return installer_state_; | 695 return installer_state_; |
698 } | 696 } |
699 | 697 |
700 static base::Version* low_version_; | 698 static Version* low_version_; |
701 static base::Version* opv_version_; | 699 static Version* opv_version_; |
702 static base::Version* middle_version_; | 700 static Version* middle_version_; |
703 static base::Version* pv_version_; | 701 static Version* pv_version_; |
704 static base::Version* high_version_; | 702 static Version* high_version_; |
705 | 703 |
706 CommandLine cmd_line_; | 704 CommandLine cmd_line_; |
707 scoped_ptr<MasterPreferences> prefs_; | 705 scoped_ptr<MasterPreferences> prefs_; |
708 InstallationState machine_state_; | 706 InstallationState machine_state_; |
709 MockInstallerState installer_state_; | 707 MockInstallerState installer_state_; |
710 }; | 708 }; |
711 | 709 |
712 base::Version* InstallerStateCriticalVersionTest::low_version_ = NULL; | 710 Version* InstallerStateCriticalVersionTest::low_version_ = NULL; |
713 base::Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; | 711 Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; |
714 base::Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; | 712 Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; |
715 base::Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; | 713 Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; |
716 base::Version* InstallerStateCriticalVersionTest::high_version_ = NULL; | 714 Version* InstallerStateCriticalVersionTest::high_version_ = NULL; |
717 | 715 |
718 // 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 |
719 // Chrome. The critical version is ignored since it doesn't apply. | 717 // Chrome. The critical version is ignored since it doesn't apply. |
720 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { | 718 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { |
721 MockInstallerState& installer_state(Initialize(low_version_)); | 719 MockInstallerState& installer_state(Initialize(low_version_)); |
722 | 720 |
723 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_)); | 721 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_)); |
724 // Unable to determine the installed version, so assume critical update. | 722 // Unable to determine the installed version, so assume critical update. |
725 EXPECT_TRUE( | 723 EXPECT_TRUE( |
726 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... |
803 // Critical update newer than the new version. | 801 // Critical update newer than the new version. |
804 EXPECT_FALSE( | 802 EXPECT_FALSE( |
805 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 803 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
806 EXPECT_FALSE( | 804 EXPECT_FALSE( |
807 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) | 805 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) |
808 .IsValid()); | 806 .IsValid()); |
809 EXPECT_FALSE( | 807 EXPECT_FALSE( |
810 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) | 808 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) |
811 .IsValid()); | 809 .IsValid()); |
812 } | 810 } |
OLD | NEW |