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); | 355 override_manager.OverrideRegistry(root); |
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 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 376 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
(...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 base::CommandLine cmd_line( | 460 base::CommandLine cmd_line( |
462 base::CommandLine::FromString(L"setup.exe --multi-install --chrome")); | 461 base::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 13 matching lines...) Expand all Loading... |
539 EXPECT_TRUE(base::PathExists(version_dirs[i])); | 537 EXPECT_TRUE(base::PathExists(version_dirs[i])); |
540 } | 538 } |
541 | 539 |
542 // Create exes with the appropriate version resource. | 540 // Create exes with the appropriate version resource. |
543 // Use the current test exe as a baseline. | 541 // Use the current test exe as a baseline. |
544 base::FilePath exe_path; | 542 base::FilePath exe_path; |
545 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | 543 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); |
546 | 544 |
547 struct target_info { | 545 struct target_info { |
548 base::FilePath target_file; | 546 base::FilePath target_file; |
549 const base::Version& target_version; | 547 const Version& target_version; |
550 } targets[] = { | 548 } targets[] = { |
551 { installer_state.target_path().Append(installer::kChromeOldExe), | 549 { installer_state.target_path().Append(installer::kChromeOldExe), |
552 old_chrome_exe_version }, | 550 old_chrome_exe_version }, |
553 { installer_state.target_path().Append(installer::kChromeExe), | 551 { installer_state.target_path().Append(installer::kChromeExe), |
554 chrome_exe_version }, | 552 chrome_exe_version }, |
555 { installer_state.target_path().Append(installer::kChromeNewExe), | 553 { installer_state.target_path().Append(installer::kChromeNewExe), |
556 new_chrome_exe_version }, | 554 new_chrome_exe_version }, |
557 }; | 555 }; |
558 for (int i = 0; i < arraysize(targets); ++i) { | 556 for (int i = 0; i < arraysize(targets); ++i) { |
559 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( | 557 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( |
(...skipping 23 matching lines...) Expand all Loading... |
583 expected_remaining_dirs.insert(kOldChromeExeVersion); | 581 expected_remaining_dirs.insert(kOldChromeExeVersion); |
584 expected_remaining_dirs.insert(kChromeExeVersion); | 582 expected_remaining_dirs.insert(kChromeExeVersion); |
585 expected_remaining_dirs.insert(kNewChromeExeVersion); | 583 expected_remaining_dirs.insert(kNewChromeExeVersion); |
586 | 584 |
587 // Enumerate dirs in target_path(), ensure only desired remain. | 585 // Enumerate dirs in target_path(), ensure only desired remain. |
588 base::FileEnumerator version_enum(installer_state.target_path(), false, | 586 base::FileEnumerator version_enum(installer_state.target_path(), false, |
589 base::FileEnumerator::DIRECTORIES); | 587 base::FileEnumerator::DIRECTORIES); |
590 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); | 588 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); |
591 next_version = version_enum.Next()) { | 589 next_version = version_enum.Next()) { |
592 base::FilePath dir_name(next_version.BaseName()); | 590 base::FilePath dir_name(next_version.BaseName()); |
593 base::Version version(base::UTF16ToASCII(dir_name.value())); | 591 Version version(base::UTF16ToASCII(dir_name.value())); |
594 if (version.IsValid()) { | 592 if (version.IsValid()) { |
595 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) | 593 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) |
596 << "Unexpected version dir found: " << version.GetString(); | 594 << "Unexpected version dir found: " << version.GetString(); |
597 } | 595 } |
598 } | 596 } |
599 | 597 |
600 std::set<std::string>::const_iterator iter( | 598 std::set<std::string>::const_iterator iter( |
601 expected_remaining_dirs.begin()); | 599 expected_remaining_dirs.begin()); |
602 for (; iter != expected_remaining_dirs.end(); ++iter) | 600 for (; iter != expected_remaining_dirs.end(); ++iter) |
603 ADD_FAILURE() << "Expected to find version dir for " << *iter; | 601 ADD_FAILURE() << "Expected to find version dir for " << *iter; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 | 673 |
676 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual | 674 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual |
677 // tests must invoke Initialize() with a critical version. | 675 // tests must invoke Initialize() with a critical version. |
678 class InstallerStateCriticalVersionTest : public ::testing::Test { | 676 class InstallerStateCriticalVersionTest : public ::testing::Test { |
679 protected: | 677 protected: |
680 InstallerStateCriticalVersionTest() | 678 InstallerStateCriticalVersionTest() |
681 : cmd_line_(base::CommandLine::NO_PROGRAM) {} | 679 : cmd_line_(base::CommandLine::NO_PROGRAM) {} |
682 | 680 |
683 // Creates a set of versions for use by all test runs. | 681 // Creates a set of versions for use by all test runs. |
684 static void SetUpTestCase() { | 682 static void SetUpTestCase() { |
685 low_version_ = new base::Version("15.0.874.106"); | 683 low_version_ = new Version("15.0.874.106"); |
686 opv_version_ = new base::Version("15.0.874.255"); | 684 opv_version_ = new Version("15.0.874.255"); |
687 middle_version_ = new base::Version("16.0.912.32"); | 685 middle_version_ = new Version("16.0.912.32"); |
688 pv_version_ = new base::Version("16.0.912.255"); | 686 pv_version_ = new Version("16.0.912.255"); |
689 high_version_ = new base::Version("17.0.932.0"); | 687 high_version_ = new Version("17.0.932.0"); |
690 } | 688 } |
691 | 689 |
692 // Cleans up versions used by all test runs. | 690 // Cleans up versions used by all test runs. |
693 static void TearDownTestCase() { | 691 static void TearDownTestCase() { |
694 delete low_version_; | 692 delete low_version_; |
695 delete opv_version_; | 693 delete opv_version_; |
696 delete middle_version_; | 694 delete middle_version_; |
697 delete pv_version_; | 695 delete pv_version_; |
698 delete high_version_; | 696 delete high_version_; |
699 } | 697 } |
700 | 698 |
701 // Initializes the InstallerState to use for a test run. The returned | 699 // Initializes the InstallerState to use for a test run. The returned |
702 // instance's critical update version is set to |version|. |version| may be | 700 // instance's critical update version is set to |version|. |version| may be |
703 // NULL, in which case the critical update version is unset. | 701 // NULL, in which case the critical update version is unset. |
704 MockInstallerState& Initialize(const base::Version* version) { | 702 MockInstallerState& Initialize(const Version* version) { |
705 cmd_line_ = version == NULL ? base::CommandLine::FromString(L"setup.exe") | 703 cmd_line_ = version == NULL ? base::CommandLine::FromString(L"setup.exe") |
706 : base::CommandLine::FromString( | 704 : base::CommandLine::FromString( |
707 L"setup.exe --critical-update-version=" + | 705 L"setup.exe --critical-update-version=" + |
708 base::ASCIIToUTF16(version->GetString())); | 706 base::ASCIIToUTF16(version->GetString())); |
709 prefs_.reset(new MasterPreferences(cmd_line_)); | 707 prefs_.reset(new MasterPreferences(cmd_line_)); |
710 machine_state_.Initialize(); | 708 machine_state_.Initialize(); |
711 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); | 709 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); |
712 return installer_state_; | 710 return installer_state_; |
713 } | 711 } |
714 | 712 |
715 static base::Version* low_version_; | 713 static Version* low_version_; |
716 static base::Version* opv_version_; | 714 static Version* opv_version_; |
717 static base::Version* middle_version_; | 715 static Version* middle_version_; |
718 static base::Version* pv_version_; | 716 static Version* pv_version_; |
719 static base::Version* high_version_; | 717 static Version* high_version_; |
720 | 718 |
721 base::CommandLine cmd_line_; | 719 base::CommandLine cmd_line_; |
722 scoped_ptr<MasterPreferences> prefs_; | 720 scoped_ptr<MasterPreferences> prefs_; |
723 InstallationState machine_state_; | 721 InstallationState machine_state_; |
724 MockInstallerState installer_state_; | 722 MockInstallerState installer_state_; |
725 }; | 723 }; |
726 | 724 |
727 base::Version* InstallerStateCriticalVersionTest::low_version_ = NULL; | 725 Version* InstallerStateCriticalVersionTest::low_version_ = NULL; |
728 base::Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; | 726 Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; |
729 base::Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; | 727 Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; |
730 base::Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; | 728 Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; |
731 base::Version* InstallerStateCriticalVersionTest::high_version_ = NULL; | 729 Version* InstallerStateCriticalVersionTest::high_version_ = NULL; |
732 | 730 |
733 // Test the case where the critical version is less than the currently-running | 731 // Test the case where the critical version is less than the currently-running |
734 // Chrome. The critical version is ignored since it doesn't apply. | 732 // Chrome. The critical version is ignored since it doesn't apply. |
735 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { | 733 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { |
736 MockInstallerState& installer_state(Initialize(low_version_)); | 734 MockInstallerState& installer_state(Initialize(low_version_)); |
737 | 735 |
738 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_)); | 736 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_)); |
739 // Unable to determine the installed version, so assume critical update. | 737 // Unable to determine the installed version, so assume critical update. |
740 EXPECT_TRUE( | 738 EXPECT_TRUE( |
741 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 739 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 // Critical update newer than the new version. | 816 // Critical update newer than the new version. |
819 EXPECT_FALSE( | 817 EXPECT_FALSE( |
820 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 818 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
821 EXPECT_FALSE( | 819 EXPECT_FALSE( |
822 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) | 820 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) |
823 .IsValid()); | 821 .IsValid()); |
824 EXPECT_FALSE( | 822 EXPECT_FALSE( |
825 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) | 823 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) |
826 .IsValid()); | 824 .IsValid()); |
827 } | 825 } |
OLD | NEW |