Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: chrome/installer/util/installer_state_unittest.cc

Issue 1281313003: base: Remove using:: declaration from version.h header. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/util/installer_state.cc ('k') | chrome/installer/util/product_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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 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
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); 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 Version found_version(*installer_state.GetCurrentVersion(machine_state)); 366 base::Version found_version(
367 *installer_state.GetCurrentVersion(machine_state));
367 EXPECT_TRUE(found_version.IsValid()); 368 EXPECT_TRUE(found_version.IsValid());
368 if (found_version.IsValid()) 369 if (found_version.IsValid())
369 EXPECT_TRUE(current_version.Equals(found_version)); 370 EXPECT_TRUE(current_version.Equals(found_version));
370 } 371 }
371 } 372 }
372 } 373 }
373 374
374 TEST_F(InstallerStateTest, InstallerResult) { 375 TEST_F(InstallerStateTest, InstallerResult) {
375 const bool system_level = true; 376 const bool system_level = true;
376 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 377 HKEY root = system_level ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 448
448 // Test GetCurrentVersion when migrating single Chrome to multi 449 // Test GetCurrentVersion when migrating single Chrome to multi
449 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) { 450 TEST_F(InstallerStateTest, GetCurrentVersionMigrateChrome) {
450 using installer::FakeInstallationState; 451 using installer::FakeInstallationState;
451 452
452 const bool system_install = false; 453 const bool system_install = false;
453 FakeInstallationState machine_state; 454 FakeInstallationState machine_state;
454 455
455 // Pretend that this version of single-install Chrome is already installed. 456 // Pretend that this version of single-install Chrome is already installed.
456 machine_state.AddChrome(system_install, false, 457 machine_state.AddChrome(system_install, false,
457 new Version(chrome::kChromeVersion)); 458 new base::Version(chrome::kChromeVersion));
458 459
459 // Now we're invoked to install multi Chrome. 460 // Now we're invoked to install multi Chrome.
460 base::CommandLine cmd_line( 461 base::CommandLine cmd_line(
461 base::CommandLine::FromString(L"setup.exe --multi-install --chrome")); 462 base::CommandLine::FromString(L"setup.exe --multi-install --chrome"));
462 MasterPreferences prefs(cmd_line); 463 MasterPreferences prefs(cmd_line);
463 InstallerState installer_state; 464 InstallerState installer_state;
464 installer_state.Initialize(cmd_line, prefs, machine_state); 465 installer_state.Initialize(cmd_line, prefs, machine_state);
465 466
466 // Is the Chrome version picked up? 467 // Is the Chrome version picked up?
467 scoped_ptr<Version> version(installer_state.GetCurrentVersion(machine_state)); 468 scoped_ptr<base::Version> version(
469 installer_state.GetCurrentVersion(machine_state));
468 EXPECT_TRUE(version.get() != NULL); 470 EXPECT_TRUE(version.get() != NULL);
469 } 471 }
470 472
471 TEST_F(InstallerStateTest, IsFileInUse) { 473 TEST_F(InstallerStateTest, IsFileInUse) {
472 base::ScopedTempDir temp_dir; 474 base::ScopedTempDir temp_dir;
473 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 475 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
474 476
475 base::FilePath temp_file; 477 base::FilePath temp_file;
476 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); 478 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file));
477 479
(...skipping 21 matching lines...) Expand all
499 MockInstallerState installer_state; 501 MockInstallerState installer_state;
500 installer_state.set_target_path(test_dir_.path()); 502 installer_state.set_target_path(test_dir_.path());
501 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); 503 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value());
502 504
503 const char kOldVersion[] = "2.0.0.0"; 505 const char kOldVersion[] = "2.0.0.0";
504 const char kNewVersion[] = "3.0.0.0"; 506 const char kNewVersion[] = "3.0.0.0";
505 const char kOldChromeExeVersion[] = "2.1.0.0"; 507 const char kOldChromeExeVersion[] = "2.1.0.0";
506 const char kChromeExeVersion[] = "2.1.1.1"; 508 const char kChromeExeVersion[] = "2.1.1.1";
507 const char kNewChromeExeVersion[] = "3.0.0.0"; 509 const char kNewChromeExeVersion[] = "3.0.0.0";
508 510
509 Version new_version(kNewVersion); 511 base::Version new_version(kNewVersion);
510 Version old_version(kOldVersion); 512 base::Version old_version(kOldVersion);
511 Version old_chrome_exe_version(kOldChromeExeVersion); 513 base::Version old_chrome_exe_version(kOldChromeExeVersion);
512 Version chrome_exe_version(kChromeExeVersion); 514 base::Version chrome_exe_version(kChromeExeVersion);
513 Version new_chrome_exe_version(kNewChromeExeVersion); 515 base::Version new_chrome_exe_version(kNewChromeExeVersion);
514 516
515 ASSERT_TRUE(new_version.IsValid()); 517 ASSERT_TRUE(new_version.IsValid());
516 ASSERT_TRUE(old_version.IsValid()); 518 ASSERT_TRUE(old_version.IsValid());
517 ASSERT_TRUE(old_chrome_exe_version.IsValid()); 519 ASSERT_TRUE(old_chrome_exe_version.IsValid());
518 ASSERT_TRUE(chrome_exe_version.IsValid()); 520 ASSERT_TRUE(chrome_exe_version.IsValid());
519 ASSERT_TRUE(new_chrome_exe_version.IsValid()); 521 ASSERT_TRUE(new_chrome_exe_version.IsValid());
520 522
521 // Set up a bunch of version dir paths. 523 // Set up a bunch of version dir paths.
522 base::FilePath version_dirs[] = { 524 base::FilePath version_dirs[] = {
523 installer_state.target_path().Append(L"1.2.3.4"), 525 installer_state.target_path().Append(L"1.2.3.4"),
(...skipping 13 matching lines...) Expand all
537 EXPECT_TRUE(base::PathExists(version_dirs[i])); 539 EXPECT_TRUE(base::PathExists(version_dirs[i]));
538 } 540 }
539 541
540 // Create exes with the appropriate version resource. 542 // Create exes with the appropriate version resource.
541 // Use the current test exe as a baseline. 543 // Use the current test exe as a baseline.
542 base::FilePath exe_path; 544 base::FilePath exe_path;
543 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); 545 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path));
544 546
545 struct target_info { 547 struct target_info {
546 base::FilePath target_file; 548 base::FilePath target_file;
547 const Version& target_version; 549 const base::Version& target_version;
548 } targets[] = { 550 } targets[] = {
549 { installer_state.target_path().Append(installer::kChromeOldExe), 551 { installer_state.target_path().Append(installer::kChromeOldExe),
550 old_chrome_exe_version }, 552 old_chrome_exe_version },
551 { installer_state.target_path().Append(installer::kChromeExe), 553 { installer_state.target_path().Append(installer::kChromeExe),
552 chrome_exe_version }, 554 chrome_exe_version },
553 { installer_state.target_path().Append(installer::kChromeNewExe), 555 { installer_state.target_path().Append(installer::kChromeNewExe),
554 new_chrome_exe_version }, 556 new_chrome_exe_version },
555 }; 557 };
556 for (int i = 0; i < arraysize(targets); ++i) { 558 for (int i = 0; i < arraysize(targets); ++i) {
557 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( 559 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion(
(...skipping 23 matching lines...) Expand all
581 expected_remaining_dirs.insert(kOldChromeExeVersion); 583 expected_remaining_dirs.insert(kOldChromeExeVersion);
582 expected_remaining_dirs.insert(kChromeExeVersion); 584 expected_remaining_dirs.insert(kChromeExeVersion);
583 expected_remaining_dirs.insert(kNewChromeExeVersion); 585 expected_remaining_dirs.insert(kNewChromeExeVersion);
584 586
585 // Enumerate dirs in target_path(), ensure only desired remain. 587 // Enumerate dirs in target_path(), ensure only desired remain.
586 base::FileEnumerator version_enum(installer_state.target_path(), false, 588 base::FileEnumerator version_enum(installer_state.target_path(), false,
587 base::FileEnumerator::DIRECTORIES); 589 base::FileEnumerator::DIRECTORIES);
588 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); 590 for (base::FilePath next_version = version_enum.Next(); !next_version.empty();
589 next_version = version_enum.Next()) { 591 next_version = version_enum.Next()) {
590 base::FilePath dir_name(next_version.BaseName()); 592 base::FilePath dir_name(next_version.BaseName());
591 Version version(base::UTF16ToASCII(dir_name.value())); 593 base::Version version(base::UTF16ToASCII(dir_name.value()));
592 if (version.IsValid()) { 594 if (version.IsValid()) {
593 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) 595 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString()))
594 << "Unexpected version dir found: " << version.GetString(); 596 << "Unexpected version dir found: " << version.GetString();
595 } 597 }
596 } 598 }
597 599
598 std::set<std::string>::const_iterator iter( 600 std::set<std::string>::const_iterator iter(
599 expected_remaining_dirs.begin()); 601 expected_remaining_dirs.begin());
600 for (; iter != expected_remaining_dirs.end(); ++iter) 602 for (; iter != expected_remaining_dirs.end(); ++iter)
601 ADD_FAILURE() << "Expected to find version dir for " << *iter; 603 ADD_FAILURE() << "Expected to find version dir for " << *iter;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 675
674 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual 676 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual
675 // tests must invoke Initialize() with a critical version. 677 // tests must invoke Initialize() with a critical version.
676 class InstallerStateCriticalVersionTest : public ::testing::Test { 678 class InstallerStateCriticalVersionTest : public ::testing::Test {
677 protected: 679 protected:
678 InstallerStateCriticalVersionTest() 680 InstallerStateCriticalVersionTest()
679 : cmd_line_(base::CommandLine::NO_PROGRAM) {} 681 : cmd_line_(base::CommandLine::NO_PROGRAM) {}
680 682
681 // Creates a set of versions for use by all test runs. 683 // Creates a set of versions for use by all test runs.
682 static void SetUpTestCase() { 684 static void SetUpTestCase() {
683 low_version_ = new Version("15.0.874.106"); 685 low_version_ = new base::Version("15.0.874.106");
684 opv_version_ = new Version("15.0.874.255"); 686 opv_version_ = new base::Version("15.0.874.255");
685 middle_version_ = new Version("16.0.912.32"); 687 middle_version_ = new base::Version("16.0.912.32");
686 pv_version_ = new Version("16.0.912.255"); 688 pv_version_ = new base::Version("16.0.912.255");
687 high_version_ = new Version("17.0.932.0"); 689 high_version_ = new base::Version("17.0.932.0");
688 } 690 }
689 691
690 // Cleans up versions used by all test runs. 692 // Cleans up versions used by all test runs.
691 static void TearDownTestCase() { 693 static void TearDownTestCase() {
692 delete low_version_; 694 delete low_version_;
693 delete opv_version_; 695 delete opv_version_;
694 delete middle_version_; 696 delete middle_version_;
695 delete pv_version_; 697 delete pv_version_;
696 delete high_version_; 698 delete high_version_;
697 } 699 }
698 700
699 // Initializes the InstallerState to use for a test run. The returned 701 // Initializes the InstallerState to use for a test run. The returned
700 // instance's critical update version is set to |version|. |version| may be 702 // instance's critical update version is set to |version|. |version| may be
701 // NULL, in which case the critical update version is unset. 703 // NULL, in which case the critical update version is unset.
702 MockInstallerState& Initialize(const Version* version) { 704 MockInstallerState& Initialize(const base::Version* version) {
703 cmd_line_ = version == NULL ? base::CommandLine::FromString(L"setup.exe") 705 cmd_line_ = version == NULL ? base::CommandLine::FromString(L"setup.exe")
704 : base::CommandLine::FromString( 706 : base::CommandLine::FromString(
705 L"setup.exe --critical-update-version=" + 707 L"setup.exe --critical-update-version=" +
706 base::ASCIIToUTF16(version->GetString())); 708 base::ASCIIToUTF16(version->GetString()));
707 prefs_.reset(new MasterPreferences(cmd_line_)); 709 prefs_.reset(new MasterPreferences(cmd_line_));
708 machine_state_.Initialize(); 710 machine_state_.Initialize();
709 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); 711 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_);
710 return installer_state_; 712 return installer_state_;
711 } 713 }
712 714
713 static Version* low_version_; 715 static base::Version* low_version_;
714 static Version* opv_version_; 716 static base::Version* opv_version_;
715 static Version* middle_version_; 717 static base::Version* middle_version_;
716 static Version* pv_version_; 718 static base::Version* pv_version_;
717 static Version* high_version_; 719 static base::Version* high_version_;
718 720
719 base::CommandLine cmd_line_; 721 base::CommandLine cmd_line_;
720 scoped_ptr<MasterPreferences> prefs_; 722 scoped_ptr<MasterPreferences> prefs_;
721 InstallationState machine_state_; 723 InstallationState machine_state_;
722 MockInstallerState installer_state_; 724 MockInstallerState installer_state_;
723 }; 725 };
724 726
725 Version* InstallerStateCriticalVersionTest::low_version_ = NULL; 727 base::Version* InstallerStateCriticalVersionTest::low_version_ = NULL;
726 Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; 728 base::Version* InstallerStateCriticalVersionTest::opv_version_ = NULL;
727 Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; 729 base::Version* InstallerStateCriticalVersionTest::middle_version_ = NULL;
728 Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; 730 base::Version* InstallerStateCriticalVersionTest::pv_version_ = NULL;
729 Version* InstallerStateCriticalVersionTest::high_version_ = NULL; 731 base::Version* InstallerStateCriticalVersionTest::high_version_ = NULL;
730 732
731 // Test the case where the critical version is less than the currently-running 733 // Test the case where the critical version is less than the currently-running
732 // Chrome. The critical version is ignored since it doesn't apply. 734 // Chrome. The critical version is ignored since it doesn't apply.
733 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { 735 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) {
734 MockInstallerState& installer_state(Initialize(low_version_)); 736 MockInstallerState& installer_state(Initialize(low_version_));
735 737
736 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_)); 738 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_));
737 // Unable to determine the installed version, so assume critical update. 739 // Unable to determine the installed version, so assume critical update.
738 EXPECT_TRUE( 740 EXPECT_TRUE(
739 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); 741 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 // Critical update newer than the new version. 818 // Critical update newer than the new version.
817 EXPECT_FALSE( 819 EXPECT_FALSE(
818 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); 820 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
819 EXPECT_FALSE( 821 EXPECT_FALSE(
820 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) 822 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
821 .IsValid()); 823 .IsValid());
822 EXPECT_FALSE( 824 EXPECT_FALSE(
823 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) 825 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
824 .IsValid()); 826 .IsValid());
825 } 827 }
OLDNEW
« no previous file with comments | « chrome/installer/util/installer_state.cc ('k') | chrome/installer/util/product_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698