diff options
author | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-11 13:28:34 +0000 |
---|---|---|
committer | grt@chromium.org <grt@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-11 13:28:34 +0000 |
commit | 2589396510cb9ec9a4e3520dcef3524e65fecd58 (patch) | |
tree | 54824cb5227354c24f04c7f34b5c104c78a14943 /chrome/installer/util/installer_state_unittest.cc | |
parent | c7959c98c6625ad4e0758bd8e95e35be3442219a (diff) | |
download | chromium_src-2589396510cb9ec9a4e3520dcef3524e65fecd58.zip chromium_src-2589396510cb9ec9a4e3520dcef3524e65fecd58.tar.gz chromium_src-2589396510cb9ec9a4e3520dcef3524e65fecd58.tar.bz2 |
Add support for --critical-update-version to installer.
The installer may now be given a --critical-update-version=W.X.Y.Z option on the command line. If this is present for an in-use update and the indicated version is newer than the in-use Chrome, a new "cpv" value is dropped in the registry alongside "opv" and "cmd" (the other state associated with an in-use update). Thanks to Finnur, Chrome will eventually notice that there's a pending critical update and do magical things to keep our users safe and secure. Go users!
Other things I did while I was at it:
- switched version string conversions from UTF8ToWide to ASCIIToWide since version numbers are always ASCII dotted numbers.
- renamed the reg value from "CriticalUpdate" to "cpv" so it fits in nicely with the other cryptic values in the product's Clients key (a.k.a. Version key).
BUG=103526,97665
TEST=Install version N, launch it with --check-for-update-interval=5, then install verison M>N with --critical-update-version=M. After a few seconds, Chrome should do something fantastic. Note that the alternate_version_generator can be used to create a newer versioned mini_installer from an existing one (just build it and run it).
Review URL: http://codereview.chromium.org/8517012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109620 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/util/installer_state_unittest.cc')
-rw-r--r-- | chrome/installer/util/installer_state_unittest.cc | 158 |
1 files changed, 157 insertions, 1 deletions
diff --git a/chrome/installer/util/installer_state_unittest.cc b/chrome/installer/util/installer_state_unittest.cc index 14dec6d..5029699 100644 --- a/chrome/installer/util/installer_state_unittest.cc +++ b/chrome/installer/util/installer_state_unittest.cc @@ -42,7 +42,7 @@ class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys { protected: }; -// An installer state on which we can tweak the target path. +// An installer state on which we can access otherwise protected members. class MockInstallerState : public InstallerState { public: MockInstallerState() : InstallerState() { } @@ -52,6 +52,9 @@ class MockInstallerState : public InstallerState { static bool IsFileInUse(const FilePath& file) { return InstallerState::IsFileInUse(file); } + const Version& critical_update_version() const { + return critical_update_version_; + } }; // Simple function to dump some text into a new file. @@ -491,3 +494,156 @@ TEST_F(InstallerStateTest, IsFileInUse) { // And once the handle is gone, it should no longer be in use. EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); } + +// A fixture for testing InstallerState::DetermineCriticalVersion. Individual +// tests must invoke Initialize() with a critical version. +class InstallerStateCriticalVersionTest : public ::testing::Test { + protected: + InstallerStateCriticalVersionTest() : cmd_line_(CommandLine::NO_PROGRAM) {} + + // Creates a set of versions for use by all test runs. + static void SetUpTestCase() { + low_version_ = new Version("15.0.874.106"); + opv_version_ = new Version("15.0.874.255"); + middle_version_ = new Version("16.0.912.32"); + pv_version_ = new Version("16.0.912.255"); + high_version_ = new Version("17.0.932.0"); + } + + // Cleans up versions used by all test runs. + static void TearDownTestCase() { + delete low_version_; + delete opv_version_; + delete middle_version_; + delete pv_version_; + delete high_version_; + } + + // Initializes the InstallerState to use for a test run. The returned + // instance's critical update version is set to |version|. |version| may be + // NULL, in which case the critical update version is unset. + MockInstallerState& Initialize(const Version* version) { + cmd_line_ = version == NULL ? + CommandLine::FromString(L"setup.exe") : + CommandLine::FromString( + L"setup.exe --critical-update-version=" + + ASCIIToWide(version->GetString())); + prefs_.reset(new MasterPreferences(cmd_line_)); + machine_state_.Initialize(); + installer_state_.Initialize(cmd_line_, *prefs_, machine_state_); + return installer_state_; + } + + static Version* low_version_; + static Version* opv_version_; + static Version* middle_version_; + static Version* pv_version_; + static Version* high_version_; + + CommandLine cmd_line_; + scoped_ptr<MasterPreferences> prefs_; + InstallationState machine_state_; + MockInstallerState installer_state_; +}; + +Version* InstallerStateCriticalVersionTest::low_version_ = NULL; +Version* InstallerStateCriticalVersionTest::opv_version_ = NULL; +Version* InstallerStateCriticalVersionTest::middle_version_ = NULL; +Version* InstallerStateCriticalVersionTest::pv_version_ = NULL; +Version* InstallerStateCriticalVersionTest::high_version_ = NULL; + +// Test the case where the critical version is less than the currently-running +// Chrome. The critical version is ignored since it doesn't apply. +TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) { + MockInstallerState& installer_state(Initialize(low_version_)); + + EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_)); + // Unable to determine the installed version, so assume critical update. + EXPECT_TRUE( + installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); + // Installed version is past the critical update. + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) + .IsValid()); + // Installed version is past the critical update. + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) + .IsValid()); +} + +// Test the case where the critical version is equal to the currently-running +// Chrome. The critical version is ignored since it doesn't apply. +TEST_F(InstallerStateCriticalVersionTest, CriticalEqualsOpv) { + MockInstallerState& installer_state(Initialize(opv_version_)); + + EXPECT_TRUE(installer_state.critical_update_version().Equals(*opv_version_)); + // Unable to determine the installed version, so assume critical update. + EXPECT_TRUE( + installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); + // Installed version equals the critical update. + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) + .IsValid()); + // Installed version equals the critical update. + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) + .IsValid()); +} + +// Test the case where the critical version is between the currently-running +// Chrome and the to-be-installed Chrome. +TEST_F(InstallerStateCriticalVersionTest, CriticalBetweenOpvAndPv) { + MockInstallerState& installer_state(Initialize(middle_version_)); + + EXPECT_TRUE(installer_state.critical_update_version().Equals( + *middle_version_)); + // Unable to determine the installed version, so assume critical update. + EXPECT_TRUE( + installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); + // Installed version before the critical update. + EXPECT_TRUE( + installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) + .IsValid()); + // Installed version is past the critical update. + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) + .IsValid()); +} + +// Test the case where the critical version is the same as the to-be-installed +// Chrome. +TEST_F(InstallerStateCriticalVersionTest, CriticalEqualsPv) { + MockInstallerState& installer_state(Initialize(pv_version_)); + + EXPECT_TRUE(installer_state.critical_update_version().Equals( + *pv_version_)); + // Unable to determine the installed version, so assume critical update. + EXPECT_TRUE( + installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); + // Installed version before the critical update. + EXPECT_TRUE( + installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) + .IsValid()); + // Installed version equals the critical update. + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) + .IsValid()); +} + +// Test the case where the critical version is greater than the to-be-installed +// Chrome. +TEST_F(InstallerStateCriticalVersionTest, CriticalAfterPv) { + MockInstallerState& installer_state(Initialize(high_version_)); + + EXPECT_TRUE(installer_state.critical_update_version().Equals( + *high_version_)); + // Critical update newer than the new version. + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) + .IsValid()); + EXPECT_FALSE( + installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) + .IsValid()); +} |