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

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

Issue 8517012: Add support for --critical-update-version to installer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 24 matching lines...) Expand all
35 using base::win::RegKey; 35 using base::win::RegKey;
36 using installer::InstallationState; 36 using installer::InstallationState;
37 using installer::InstallerState; 37 using installer::InstallerState;
38 using installer::MasterPreferences; 38 using installer::MasterPreferences;
39 using registry_util::RegistryOverrideManager; 39 using registry_util::RegistryOverrideManager;
40 40
41 class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys { 41 class InstallerStateTest : public TestWithTempDirAndDeleteTempOverrideKeys {
42 protected: 42 protected:
43 }; 43 };
44 44
45 // An installer state on which we can tweak the target path. 45 // An installer state on which we can access otherwise protected members.
46 class MockInstallerState : public InstallerState { 46 class MockInstallerState : public InstallerState {
47 public: 47 public:
48 MockInstallerState() : InstallerState() { } 48 MockInstallerState() : InstallerState() { }
49 void set_target_path(const FilePath& target_path) { 49 void set_target_path(const FilePath& target_path) {
50 target_path_ = target_path; 50 target_path_ = target_path;
51 } 51 }
52 static bool IsFileInUse(const FilePath& file) { 52 static bool IsFileInUse(const FilePath& file) {
53 return InstallerState::IsFileInUse(file); 53 return InstallerState::IsFileInUse(file);
54 } 54 }
55 const Version& critical_update_version() const {
56 return critical_update_version_;
57 }
55 }; 58 };
56 59
57 // Simple function to dump some text into a new file. 60 // Simple function to dump some text into a new file.
58 void CreateTextFile(const std::wstring& filename, 61 void CreateTextFile(const std::wstring& filename,
59 const std::wstring& contents) { 62 const std::wstring& contents) {
60 std::ofstream file; 63 std::ofstream file;
61 file.open(filename.c_str()); 64 file.open(filename.c_str());
62 ASSERT_TRUE(file.is_open()); 65 ASSERT_TRUE(file.is_open());
63 file << contents; 66 file << contents;
64 file.close(); 67 file.close();
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 NULL, OPEN_EXISTING, 0, 0)); 487 NULL, OPEN_EXISTING, 0, 0));
485 ASSERT_TRUE(temp_handle != NULL); 488 ASSERT_TRUE(temp_handle != NULL);
486 489
487 // The file should now be in use. 490 // The file should now be in use.
488 EXPECT_TRUE(MockInstallerState::IsFileInUse(temp_file)); 491 EXPECT_TRUE(MockInstallerState::IsFileInUse(temp_file));
489 } 492 }
490 493
491 // And once the handle is gone, it should no longer be in use. 494 // And once the handle is gone, it should no longer be in use.
492 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); 495 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file));
493 } 496 }
497
498 // A fixture for testing InstallerState::DetermineCriticalVersion. Individual
499 // tests must invoke Initialize() with a critical version.
500 class InstallerStateCriticalVersionTest : public ::testing::Test {
501 protected:
502 InstallerStateCriticalVersionTest() : cmd_line_(CommandLine::NO_PROGRAM) {}
503
504 // Creates a set of versions for use by all test runs.
505 static void SetUpTestCase() {
506 low_version_ = new Version("15.0.874.106");
507 opv_version_ = new Version("15.0.874.255");
508 middle_version_ = new Version("16.0.912.32");
509 pv_version_ = new Version("16.0.912.255");
510 high_version_ = new Version("17.0.932.0");
511 }
512
513 // Cleans up versions used by all test runs.
514 static void TearDownTestCase() {
515 delete low_version_;
516 delete opv_version_;
517 delete middle_version_;
518 delete pv_version_;
519 delete high_version_;
520 }
521
522 // Initializes the InstallerState to use for a test run. The returned
523 // instance's critical update version is set to |version|. |version| may be
524 // NULL, in which case the critical update version is unset.
525 MockInstallerState& Initialize(const Version* version) {
526 cmd_line_ = version == NULL ?
527 CommandLine::FromString(L"setup.exe") :
528 CommandLine::FromString(
529 L"setup.exe --critical-update-version=" +
530 ASCIIToWide(version->GetString()));
531 prefs_.reset(new MasterPreferences(cmd_line_));
532 machine_state_.Initialize();
533 installer_state_.Initialize(cmd_line_, *prefs_, machine_state_);
534 return installer_state_;
535 }
536
537 static Version* low_version_;
538 static Version* opv_version_;
539 static Version* middle_version_;
540 static Version* pv_version_;
541 static Version* high_version_;
542
543 CommandLine cmd_line_;
544 scoped_ptr<MasterPreferences> prefs_;
545 InstallationState machine_state_;
546 MockInstallerState installer_state_;
547 };
548
549 Version* InstallerStateCriticalVersionTest::low_version_;
550 Version* InstallerStateCriticalVersionTest::opv_version_;
551 Version* InstallerStateCriticalVersionTest::middle_version_;
552 Version* InstallerStateCriticalVersionTest::pv_version_;
553 Version* InstallerStateCriticalVersionTest::high_version_;
Finnur 2011/11/11 10:31:01 = NULL; ?
grt (UTC plus 2) 2011/11/11 11:40:08 C++ zero-initializes these during static initializ
554
555 // Test the case where the critical version is less than the currently-running
556 // Chrome. The critical version is ignored since it doesn't apply.
557 TEST_F(InstallerStateCriticalVersionTest, CriticalBeforeOpv) {
558 MockInstallerState& installer_state(Initialize(low_version_));
559
560 EXPECT_TRUE(installer_state.critical_update_version().Equals(*low_version_));
561 // Unable to determine the installed version, so assume critical update.
562 EXPECT_TRUE(
563 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
564 // Installed version is past the critical update.
565 EXPECT_FALSE(
566 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
567 .IsValid());
568 // Installed version is past the critical update.
569 EXPECT_FALSE(
570 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
571 .IsValid());
572 }
573
574 // Test the case where the critical version is equal to the currently-running
575 // Chrome. The critical version is ignored since it doesn't apply.
576 TEST_F(InstallerStateCriticalVersionTest, CriticalEqualsOpv) {
577 MockInstallerState& installer_state(Initialize(opv_version_));
578
579 EXPECT_TRUE(installer_state.critical_update_version().Equals(*opv_version_));
580 // Unable to determine the installed version, so assume critical update.
581 EXPECT_TRUE(
582 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
583 // Installed version equals the critical update.
584 EXPECT_FALSE(
585 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
586 .IsValid());
587 // Installed version equals the critical update.
588 EXPECT_FALSE(
589 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
590 .IsValid());
591 }
592
593 // Test the case where the critical version is between the currently-running
594 // Chrome and the to-be-installed Chrome.
595 TEST_F(InstallerStateCriticalVersionTest, CriticalBetweenOpvAndPv) {
596 MockInstallerState& installer_state(Initialize(middle_version_));
597
598 EXPECT_TRUE(installer_state.critical_update_version().Equals(
599 *middle_version_));
600 // Unable to determine the installed version, so assume critical update.
601 EXPECT_TRUE(
602 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
603 // Installed version before the critical update.
604 EXPECT_TRUE(
605 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
606 .IsValid());
607 // Installed version is past the critical update.
608 EXPECT_FALSE(
609 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
610 .IsValid());
611 }
612
613 // Test the case where the critical version is the same as the to-be-installed
614 // Chrome.
615 TEST_F(InstallerStateCriticalVersionTest, CriticalEqualsPv) {
616 MockInstallerState& installer_state(Initialize(pv_version_));
617
618 EXPECT_TRUE(installer_state.critical_update_version().Equals(
619 *pv_version_));
620 // Unable to determine the installed version, so assume critical update.
621 EXPECT_TRUE(
622 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
623 // Installed version before the critical update.
624 EXPECT_TRUE(
625 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
626 .IsValid());
627 // Installed version equals the critical update.
628 EXPECT_FALSE(
629 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
630 .IsValid());
631 }
632
633 // Test the case where the critical version is greater than the to-be-installed
634 // Chrome.
635 TEST_F(InstallerStateCriticalVersionTest, CriticalAfterPv) {
636 MockInstallerState& installer_state(Initialize(high_version_));
637
638 EXPECT_TRUE(installer_state.critical_update_version().Equals(
639 *high_version_));
640 // Critical update newer than the new version.
641 EXPECT_FALSE(
642 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
643 EXPECT_FALSE(
644 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
645 .IsValid());
646 EXPECT_FALSE(
647 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
648 .IsValid());
649 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698