| Index: chrome/installer/util/installer_state_unittest.cc
|
| diff --git a/chrome/installer/util/installer_state_unittest.cc b/chrome/installer/util/installer_state_unittest.cc
|
| index 14dec6da3eb6985f82c906ce52339db39ebf6208..5029699bac06854b9717237f8ed6069956016e0b 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());
|
| +}
|
|
|