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

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

Issue 12315071: Revert 184352 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/installer/util/installer_state.cc ('k') | chrome/installer/util/logging_installer.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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 Version new_version(kNewVersion); 269 Version new_version(kNewVersion);
270 Version old_version(kOldVersion); 270 Version old_version(kOldVersion);
271 ASSERT_TRUE(new_version.IsValid()); 271 ASSERT_TRUE(new_version.IsValid());
272 ASSERT_TRUE(old_version.IsValid()); 272 ASSERT_TRUE(old_version.IsValid());
273 273
274 base::FilePath installer_dir( 274 base::FilePath installer_dir(
275 installer_state.GetInstallerDirectory(new_version)); 275 installer_state.GetInstallerDirectory(new_version));
276 EXPECT_FALSE(installer_dir.empty()); 276 EXPECT_FALSE(installer_dir.empty());
277 277
278 base::FilePath new_version_dir(installer_state.target_path().Append( 278 base::FilePath new_version_dir(installer_state.target_path().Append(
279 base::UTF8ToWide(new_version.GetString()))); 279 UTF8ToWide(new_version.GetString())));
280 base::FilePath old_version_dir(installer_state.target_path().Append( 280 base::FilePath old_version_dir(installer_state.target_path().Append(
281 base::UTF8ToWide(old_version.GetString()))); 281 UTF8ToWide(old_version.GetString())));
282 282
283 EXPECT_FALSE(file_util::PathExists(new_version_dir)); 283 EXPECT_FALSE(file_util::PathExists(new_version_dir));
284 EXPECT_FALSE(file_util::PathExists(old_version_dir)); 284 EXPECT_FALSE(file_util::PathExists(old_version_dir));
285 285
286 EXPECT_FALSE(file_util::PathExists(installer_dir)); 286 EXPECT_FALSE(file_util::PathExists(installer_dir));
287 file_util::CreateDirectory(installer_dir); 287 file_util::CreateDirectory(installer_dir);
288 EXPECT_TRUE(file_util::PathExists(new_version_dir)); 288 EXPECT_TRUE(file_util::PathExists(new_version_dir));
289 289
290 file_util::CreateDirectory(old_version_dir); 290 file_util::CreateDirectory(old_version_dir);
291 EXPECT_TRUE(file_util::PathExists(old_version_dir)); 291 EXPECT_TRUE(file_util::PathExists(old_version_dir));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 354
355 { 355 {
356 RegistryOverrideManager override_manager; 356 RegistryOverrideManager override_manager;
357 override_manager.OverrideRegistry(root, L"root_pit"); 357 override_manager.OverrideRegistry(root, L"root_pit");
358 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( 358 BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution(
359 BrowserDistribution::CHROME_BROWSER); 359 BrowserDistribution::CHROME_BROWSER);
360 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS); 360 RegKey chrome_key(root, dist->GetVersionKey().c_str(), KEY_ALL_ACCESS);
361 EXPECT_TRUE(chrome_key.Valid()); 361 EXPECT_TRUE(chrome_key.Valid());
362 if (chrome_key.Valid()) { 362 if (chrome_key.Valid()) {
363 chrome_key.WriteValue(google_update::kRegVersionField, 363 chrome_key.WriteValue(google_update::kRegVersionField,
364 base::UTF8ToWide( 364 UTF8ToWide(current_version.GetString()).c_str());
365 current_version.GetString()).c_str());
366 machine_state.Initialize(); 365 machine_state.Initialize();
367 // TODO(tommi): Also test for when there exists a new_chrome.exe. 366 // TODO(tommi): Also test for when there exists a new_chrome.exe.
368 Version found_version(*installer_state.GetCurrentVersion(machine_state)); 367 Version found_version(*installer_state.GetCurrentVersion(machine_state));
369 EXPECT_TRUE(found_version.IsValid()); 368 EXPECT_TRUE(found_version.IsValid());
370 if (found_version.IsValid()) 369 if (found_version.IsValid())
371 EXPECT_TRUE(current_version.Equals(found_version)); 370 EXPECT_TRUE(current_version.Equals(found_version));
372 } 371 }
373 } 372 }
374 } 373 }
375 374
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 ASSERT_TRUE(old_version.IsValid()); 525 ASSERT_TRUE(old_version.IsValid());
527 ASSERT_TRUE(old_chrome_exe_version.IsValid()); 526 ASSERT_TRUE(old_chrome_exe_version.IsValid());
528 ASSERT_TRUE(chrome_exe_version.IsValid()); 527 ASSERT_TRUE(chrome_exe_version.IsValid());
529 ASSERT_TRUE(new_chrome_exe_version.IsValid()); 528 ASSERT_TRUE(new_chrome_exe_version.IsValid());
530 529
531 // Set up a bunch of version dir paths. 530 // Set up a bunch of version dir paths.
532 base::FilePath version_dirs[] = { 531 base::FilePath version_dirs[] = {
533 installer_state.target_path().Append(L"1.2.3.4"), 532 installer_state.target_path().Append(L"1.2.3.4"),
534 installer_state.target_path().Append(L"1.2.3.5"), 533 installer_state.target_path().Append(L"1.2.3.5"),
535 installer_state.target_path().Append(L"1.2.3.6"), 534 installer_state.target_path().Append(L"1.2.3.6"),
536 installer_state.target_path().Append(base::ASCIIToWide(kOldVersion)), 535 installer_state.target_path().Append(ASCIIToWide(kOldVersion)),
537 installer_state.target_path().Append( 536 installer_state.target_path().Append(ASCIIToWide(kOldChromeExeVersion)),
538 base::ASCIIToWide(kOldChromeExeVersion)),
539 installer_state.target_path().Append(L"2.1.1.0"), 537 installer_state.target_path().Append(L"2.1.1.0"),
540 installer_state.target_path().Append(base::ASCIIToWide(kChromeExeVersion)), 538 installer_state.target_path().Append(ASCIIToWide(kChromeExeVersion)),
541 installer_state.target_path().Append(base::ASCIIToWide(kNewVersion)), 539 installer_state.target_path().Append(ASCIIToWide(kNewVersion)),
542 installer_state.target_path().Append(L"3.9.1.1"), 540 installer_state.target_path().Append(L"3.9.1.1"),
543 }; 541 };
544 542
545 // Create the version directories. 543 // Create the version directories.
546 for (int i = 0; i < arraysize(version_dirs); i++) { 544 for (int i = 0; i < arraysize(version_dirs); i++) {
547 file_util::CreateDirectory(version_dirs[i]); 545 file_util::CreateDirectory(version_dirs[i]);
548 EXPECT_TRUE(file_util::PathExists(version_dirs[i])); 546 EXPECT_TRUE(file_util::PathExists(version_dirs[i]));
549 } 547 }
550 548
551 // Create exes with the appropriate version resource. 549 // Create exes with the appropriate version resource.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 expected_remaining_dirs.insert(kOldChromeExeVersion); 590 expected_remaining_dirs.insert(kOldChromeExeVersion);
593 expected_remaining_dirs.insert(kChromeExeVersion); 591 expected_remaining_dirs.insert(kChromeExeVersion);
594 expected_remaining_dirs.insert(kNewChromeExeVersion); 592 expected_remaining_dirs.insert(kNewChromeExeVersion);
595 593
596 // Enumerate dirs in target_path(), ensure only desired remain. 594 // Enumerate dirs in target_path(), ensure only desired remain.
597 file_util::FileEnumerator version_enum(installer_state.target_path(), false, 595 file_util::FileEnumerator version_enum(installer_state.target_path(), false,
598 file_util::FileEnumerator::DIRECTORIES); 596 file_util::FileEnumerator::DIRECTORIES);
599 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); 597 for (base::FilePath next_version = version_enum.Next(); !next_version.empty();
600 next_version = version_enum.Next()) { 598 next_version = version_enum.Next()) {
601 base::FilePath dir_name(next_version.BaseName()); 599 base::FilePath dir_name(next_version.BaseName());
602 Version version(base::WideToASCII(dir_name.value())); 600 Version version(WideToASCII(dir_name.value()));
603 if (version.IsValid()) { 601 if (version.IsValid()) {
604 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) 602 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString()))
605 << "Unexpected version dir found: " << version.GetString(); 603 << "Unexpected version dir found: " << version.GetString();
606 } 604 }
607 } 605 }
608 606
609 std::set<std::string>::const_iterator iter( 607 std::set<std::string>::const_iterator iter(
610 expected_remaining_dirs.begin()); 608 expected_remaining_dirs.begin());
611 for (; iter != expected_remaining_dirs.end(); ++iter) 609 for (; iter != expected_remaining_dirs.end(); ++iter)
612 ADD_FAILURE() << "Expected to find version dir for " << *iter; 610 ADD_FAILURE() << "Expected to find version dir for " << *iter;
(...skipping 25 matching lines...) Expand all
638 } 636 }
639 637
640 // Initializes the InstallerState to use for a test run. The returned 638 // Initializes the InstallerState to use for a test run. The returned
641 // instance's critical update version is set to |version|. |version| may be 639 // instance's critical update version is set to |version|. |version| may be
642 // NULL, in which case the critical update version is unset. 640 // NULL, in which case the critical update version is unset.
643 MockInstallerState& Initialize(const Version* version) { 641 MockInstallerState& Initialize(const Version* version) {
644 cmd_line_ = version == NULL ? 642 cmd_line_ = version == NULL ?
645 CommandLine::FromString(L"setup.exe") : 643 CommandLine::FromString(L"setup.exe") :
646 CommandLine::FromString( 644 CommandLine::FromString(
647 L"setup.exe --critical-update-version=" + 645 L"setup.exe --critical-update-version=" +
648 base::ASCIIToWide(version->GetString())); 646 ASCIIToWide(version->GetString()));
649 prefs_.reset(new MasterPreferences(cmd_line_)); 647 prefs_.reset(new MasterPreferences(cmd_line_));
650 machine_state_.Initialize(); 648 machine_state_.Initialize();
651 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); 649 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_);
652 return installer_state_; 650 return installer_state_;
653 } 651 }
654 652
655 static Version* low_version_; 653 static Version* low_version_;
656 static Version* opv_version_; 654 static Version* opv_version_;
657 static Version* middle_version_; 655 static Version* middle_version_;
658 static Version* pv_version_; 656 static Version* pv_version_;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 // Critical update newer than the new version. 756 // Critical update newer than the new version.
759 EXPECT_FALSE( 757 EXPECT_FALSE(
760 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); 758 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
761 EXPECT_FALSE( 759 EXPECT_FALSE(
762 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) 760 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
763 .IsValid()); 761 .IsValid());
764 EXPECT_FALSE( 762 EXPECT_FALSE(
765 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) 763 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
766 .IsValid()); 764 .IsValid());
767 } 765 }
OLDNEW
« no previous file with comments | « chrome/installer/util/installer_state.cc ('k') | chrome/installer/util/logging_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698