diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-21 17:56:08 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-21 17:56:08 +0000 |
commit | 00aef66f5257bebc0d0f4c313d27ec8d129be54a (patch) | |
tree | 51ce4817e42d21938db883798e605bc790717afd /chrome/test/mini_installer_test | |
parent | 15d0ef1f5642facf0c821e7df8b0a0f0d3994ca9 (diff) | |
download | chromium_src-00aef66f5257bebc0d0f4c313d27ec8d129be54a.zip chromium_src-00aef66f5257bebc0d0f4c313d27ec8d129be54a.tar.gz chromium_src-00aef66f5257bebc0d0f4c313d27ec8d129be54a.tar.bz2 |
Add a command-line option for specifying a particular build to test and for permitting the tests to be run regardless of underlying platform. Also some minor fixes and cleanup.
BUG=none
TEST=none
REVIEW=http://codereview.chromium.org/269016/
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29668 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/mini_installer_test')
6 files changed, 263 insertions, 256 deletions
diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.cc b/chrome/test/mini_installer_test/chrome_mini_installer.cc index 6c16075..ff96c072 100644 --- a/chrome/test/mini_installer_test/chrome_mini_installer.cc +++ b/chrome/test/mini_installer_test/chrome_mini_installer.cc @@ -16,93 +16,110 @@ #include "chrome/test/mini_installer_test/mini_installer_test_util.h" #include "testing/gtest/include/gtest/gtest.h" +// Constructor. +ChromeMiniInstaller::ChromeMiniInstaller(const std::wstring& install_type) { + install_type_ = install_type; + installer_name_ = StringPrintf(L"%ls (%ls)", + mini_installer_constants::kChromeBuildType, install_type_.c_str()); + + has_diff_installer_ = false; + has_full_installer_ = false; + has_prev_installer_ = false; +} + +void ChromeMiniInstaller::SetBuildUnderTest(const std::wstring& build) { + // Locate the full, diff, and previous installers. + const wchar_t * build_prefix; + if (LowerCaseEqualsASCII(build, "dev")) + build_prefix = mini_installer_constants::kDevChannelBuild; + else if (LowerCaseEqualsASCII(build, "stable")) + build_prefix = mini_installer_constants::kStableChannelBuild; + else if (LowerCaseEqualsASCII(build, "latest")) + build_prefix = L""; + else + build_prefix = build.c_str(); + + // Do not fail here if cannot find the installer. Set the bool and allow + // to fail in the particular test. + has_full_installer_ = MiniInstallerTestUtil::GetInstaller( + mini_installer_constants::kFullInstallerPattern, + &full_installer_, build_prefix); + has_diff_installer_ = MiniInstallerTestUtil::GetInstaller( + mini_installer_constants::kDiffInstallerPattern, + &diff_installer_, build_prefix); + + if (has_diff_installer_) { + has_prev_installer_ = MiniInstallerTestUtil::GetPreviousFullInstaller( + diff_installer_, &prev_installer_); + } + + // Find the version names. The folder two-levels up from the installer + // is named this. + if (has_full_installer_) { + FilePath folder = FilePath(full_installer_).DirName().DirName(); + curr_version_ = folder.BaseName().value(); + } + if (has_prev_installer_) { + FilePath folder = FilePath(prev_installer_).DirName().DirName(); + prev_version_ = folder.BaseName().value(); + } +} + // Installs Chrome. void ChromeMiniInstaller::Install() { std::wstring installer_path = MiniInstallerTestUtil::GetFilePath( mini_installer_constants::kChromeMiniInstallerExecutable); - InstallMiniInstaller(false, installer_path); + InstallMiniInstaller(false, installer_path); } // This method will get the previous latest full installer from // nightly location, install it and over install with specified install_type. void ChromeMiniInstaller::OverInstallOnFullInstaller( - const std::wstring& install_type, const wchar_t* channel_type) { - std::wstring diff_installer; - ASSERT_TRUE(MiniInstallerTestUtil::GetInstaller( - mini_installer_constants::kDiffInstallerPattern, - &diff_installer, channel_type)); - std::wstring prev_full_installer; - ASSERT_TRUE(MiniInstallerTestUtil::GetPreviousFullInstaller( - diff_installer, &prev_full_installer, channel_type)); - printf("\nPrevious full installer name is %ls\n", - prev_full_installer.c_str()); - InstallMiniInstaller(false, prev_full_installer); - std::wstring full_installer_value; - GetChromeVersionFromRegistry(&full_installer_value); + const std::wstring& install_type) { + ASSERT_TRUE(has_full_installer_ && has_diff_installer_ && + has_prev_installer_); + + InstallMiniInstaller(false, prev_installer_); + + std::wstring got_prev_version; + GetChromeVersionFromRegistry(&got_prev_version); printf("\n\nPreparing to overinstall...\n"); + if (install_type == mini_installer_constants::kDiffInstall) { printf("\nOver installing with latest differential installer: %ls\n", - diff_installer.c_str()); - InstallMiniInstaller(true, diff_installer); + diff_installer_.c_str()); + InstallMiniInstaller(true, diff_installer_); + } else if (install_type == mini_installer_constants::kFullInstall) { - std::wstring latest_full_installer; - ASSERT_TRUE(MiniInstallerTestUtil::GetInstaller( - mini_installer_constants::kFullInstallerPattern, - &latest_full_installer, channel_type)); printf("\nOver installing with latest full insatller: %ls\n", - latest_full_installer.c_str()); - InstallMiniInstaller(true, latest_full_installer); + full_installer_.c_str()); + InstallMiniInstaller(true, full_installer_); } - std::wstring diff_installer_value; - GetChromeVersionFromRegistry(&diff_installer_value); - ASSERT_TRUE(VerifyDifferentialInstall(full_installer_value, - diff_installer_value, diff_installer, channel_type)); -} - -// This method will get the diff installer file name and -// then derives the previous and latest build numbers. -bool ChromeMiniInstaller::VerifyDifferentialInstall( - const std::wstring& full_installer_value, - const std::wstring& diff_installer_value, - const std::wstring& diff_path, - const wchar_t* channel_type) { - std::wstring actual_full_installer_value; - std::wstring diff_installer_name = file_util::GetFilenameFromPath(diff_path); - MiniInstallerTestUtil::GetPreviousBuildNumber(diff_path, - &actual_full_installer_value, channel_type); - // This substring will give the full installer build number. - std::wstring actual_diff_installer_value; - actual_diff_installer_value.assign(channel_type); - // This substring will give the diff installer build number. - actual_diff_installer_value.append(diff_installer_name.substr(0, - diff_installer_name.find(L'_'))); - if ((actual_full_installer_value == full_installer_value) && - (actual_diff_installer_value == diff_installer_value)) { - printf("\n The diff installer is successful. Here are the values:\n"); + + std::wstring got_curr_version; + GetChromeVersionFromRegistry(&got_curr_version); + + if (got_prev_version == prev_version_ && + got_curr_version == curr_version_) { + printf("\n The over install was successful. Here are the values:\n"); printf("\n full installer value: %ls and diff installer value is %ls\n", - full_installer_value.c_str(), diff_installer_value.c_str()); - return true; + prev_version_.c_str(), curr_version_.c_str()); } else { - printf("\n The diff installer is not successful. Here are the values:\n"); + printf("\n The over install was not successful. Here are the values:\n"); printf("\n Expected full installer value: %ls and actual value is %ls\n", - full_installer_value.c_str(), actual_full_installer_value.c_str()); + prev_version_.c_str(), got_prev_version.c_str()); printf("\n Expected diff installer value: %ls and actual value is %ls\n", - diff_installer_value.c_str(), actual_diff_installer_value.c_str()); - return false; + curr_version_.c_str(), got_curr_version.c_str()); + FAIL(); } } + // This method will get the latest full installer from nightly location // and installs it. -void ChromeMiniInstaller::InstallFullInstaller(bool over_install, - const wchar_t* channel_type) { - std::wstring full_installer_file_name; - ASSERT_TRUE(MiniInstallerTestUtil::GetInstaller( - mini_installer_constants::kFullInstallerPattern, - &full_installer_file_name, channel_type)); - printf("The latest full installer is %ls\n\n", - full_installer_file_name.c_str()); - InstallMiniInstaller(over_install, full_installer_file_name); +void ChromeMiniInstaller::InstallFullInstaller(bool over_install) { + ASSERT_TRUE(has_full_installer_); + InstallMiniInstaller(over_install, full_installer_); } // Installs the Chrome mini-installer, checks the registry and shortcuts. @@ -167,13 +184,13 @@ void ChromeMiniInstaller::InstallMetaInstaller() { // If the build type is Google Chrome, then it first installs meta installer // and then over installs with mini_installer. It also verifies if Chrome can // be launched successfully after overinstall. -void ChromeMiniInstaller::OverInstall(const wchar_t* channel_type) { +void ChromeMiniInstaller::OverInstall() { InstallMetaInstaller(); std::wstring reg_key_value_returned; // gets the registry key value before overinstall. GetChromeVersionFromRegistry(®_key_value_returned); printf("\n\nPreparing to overinstall...\n"); - InstallFullInstaller(true, channel_type); + InstallFullInstaller(true); std::wstring reg_key_value_after_overinstall; // Get the registry key value after over install GetChromeVersionFromRegistry(®_key_value_after_overinstall); @@ -185,9 +202,8 @@ void ChromeMiniInstaller::OverInstall(const wchar_t* channel_type) { // folder based on the passed argument, then tries to launch Chrome. // Then installs Chrome again to repair. void ChromeMiniInstaller::Repair( - ChromeMiniInstaller::RepairChrome repair_type, - const wchar_t* channel_type) { - InstallFullInstaller(false, channel_type); + ChromeMiniInstaller::RepairChrome repair_type) { + InstallFullInstaller(false); MiniInstallerTestUtil::CloseProcesses(installer_util::kChromeExe); if (repair_type == ChromeMiniInstaller::VERSION_FOLDER) { DeleteFolder(L"version_folder"); @@ -200,7 +216,7 @@ void ChromeMiniInstaller::Repair( ASSERT_TRUE(MiniInstallerTestUtil::ChangeCurrentDirectory(¤t_path)); VerifyChromeLaunch(false); printf("\nInstalling Chrome again to see if it can be repaired\n\n"); - InstallFullInstaller(true, channel_type); + InstallFullInstaller(true); printf("Chrome repair successful.\n"); // Set the current directory back to original path. ::SetCurrentDirectory(current_path.c_str()); diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.h b/chrome/test/mini_installer_test/chrome_mini_installer.h index 58d43fb2..0a0c956 100644 --- a/chrome/test/mini_installer_test/chrome_mini_installer.h +++ b/chrome/test/mini_installer_test/chrome_mini_installer.h @@ -2,20 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H__ -#define CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H__ +#ifndef CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H_ +#define CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H_ #include <windows.h> #include <string> #include "base/basictypes.h" +#include "base/string_util.h" // This class has methods to install and uninstall Chrome mini installer. class ChromeMiniInstaller { public: - explicit ChromeMiniInstaller(std::wstring install_type) { - install_type_ = install_type; - } + explicit ChromeMiniInstaller(const std::wstring& install_type); ~ChromeMiniInstaller() {} @@ -29,15 +28,14 @@ class ChromeMiniInstaller { std::wstring GetChromeInstallDirectoryLocation(); // Installs the latest full installer. - void InstallFullInstaller(bool over_install, const wchar_t* channel_type); + void InstallFullInstaller(bool over_install); // Installs chrome. void Install(); // This method will first install the full installer and // then over installs with diff installer. - void OverInstallOnFullInstaller(const std::wstring& install_type, - const wchar_t* channel_type); + void OverInstallOnFullInstaller(const std::wstring& install_type); // Installs Google Chrome through meta installer. void InstallMetaInstaller(); @@ -50,13 +48,15 @@ class ChromeMiniInstaller { void InstallStandaloneInstaller(); // Repairs Chrome based on the passed argument. - void Repair(RepairChrome repair_type, const wchar_t* channel_type); + void Repair(RepairChrome repair_type); // Uninstalls Chrome. void UnInstall(); // This method will perform a over install - void OverInstall(const wchar_t* channel_type); + void OverInstall(); + + void SetBuildUnderTest(const std::wstring& build); private: // This variable holds the install type. @@ -65,6 +65,20 @@ class ChromeMiniInstaller { bool standalone_installer; + // Name of the browser (Chrome or Chromium) and install type (sys or user) + std::wstring installer_name_; + + // The full path to the various installers. + std::wstring full_installer_, diff_installer_, prev_installer_; + + // Whether the path to the associated installer could be found. + // This is because we do not want to assert that these paths exist + // except in the tests that use them. + bool has_full_installer_, has_diff_installer_, has_prev_installer_; + + // The version string of the current and previous builds. + std::wstring curr_version_, prev_version_; + // Will clean up the machine if Chrome install is messed up. void CleanChromeInstall(); @@ -124,16 +138,11 @@ class ChromeMiniInstaller { bool VerifyOverInstall(const std::wstring& reg_key_value_before_overinstall, const std::wstring& reg_key_value_after_overinstall); - // Checks if the differential install is correct. - bool VerifyDifferentialInstall(const std::wstring& full_installer_value, - const std::wstring& diff_installer_value, - const std::wstring& diff_installer_name, - const wchar_t* channel_type); - // This method will verify if the installed build is correct. bool VerifyStandaloneInstall(); DISALLOW_COPY_AND_ASSIGN(ChromeMiniInstaller); }; -#endif // CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H__ +#endif // CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H_ + diff --git a/chrome/test/mini_installer_test/mini_installer_test_util.cc b/chrome/test/mini_installer_test/mini_installer_test_util.cc index 3593f10..f076ee0 100644 --- a/chrome/test/mini_installer_test/mini_installer_test_util.cc +++ b/chrome/test/mini_installer_test/mini_installer_test_util.cc @@ -46,7 +46,7 @@ bool MiniInstallerTestUtil::CloseWindow(const wchar_t* window_name, int timer = 0; bool return_val = false; HWND hndl = FindWindow(NULL, window_name); - while (hndl == NULL && (timer < 60000)) { + while (hndl == NULL && (timer < 20000)) { hndl = FindWindow(NULL, window_name); PlatformThread::Sleep(200); timer = timer + 200; @@ -101,16 +101,17 @@ bool MiniInstallerTestUtil::GetInstaller(const wchar_t* pattern, FileInfoList exe_list; std::wstring chrome_diff_installer( mini_installer_constants::kChromeDiffInstallerLocation); + chrome_diff_installer.append(L"*"); if (!GetLatestFile(chrome_diff_installer.c_str(), channel_type, &builds_list)) return false; + FileInfoList::const_reverse_iterator builds_list_size = builds_list.rbegin(); while (builds_list_size != builds_list.rend()) { path->assign(mini_installer_constants::kChromeDiffInstallerLocation); file_util::AppendToPath(path, builds_list_size->name_); - if (channel_type == mini_installer_constants::kDevChannelBuild) - file_util::AppendToPath(path, L"win"); + file_util::AppendToPath(path, L"win"); std::wstring installer_path(path->c_str()); file_util::AppendToPath(&installer_path, L"*.exe"); if (!GetLatestFile(installer_path.c_str(), pattern, &exe_list)) { @@ -130,6 +131,7 @@ bool MiniInstallerTestUtil::GetInstaller(const wchar_t* pattern, // This method will get the latest installer filename from the directory. bool MiniInstallerTestUtil::GetLatestFile(const wchar_t* file_name, const wchar_t* pattern, FileInfoList *file_details) { + WIN32_FIND_DATA find_file_data; HANDLE file_handle = FindFirstFile(file_name, &find_file_data); if (file_handle == INVALID_HANDLE_VALUE) { @@ -162,47 +164,58 @@ bool MiniInstallerTestUtil::GetLatestFile(const wchar_t* file_name, return return_val; } -void MiniInstallerTestUtil::GetPreviousBuildNumber(const std::wstring& path, - std::wstring *build_number, const wchar_t* channel_type) { - std::wstring diff_installer_name = file_util::GetFilenameFromPath(path); - std::wstring::size_type start_position = diff_installer_name.find(L"f"); - std::wstring::size_type end_position = diff_installer_name.find(L"_c"); - end_position = end_position - start_position; - std::wstring file_name = diff_installer_name.substr(start_position, - end_position); - file_name = file_name.substr(file_name.find(L'_')+1, file_name.size()); - file_name = channel_type + file_name; - build_number->assign(file_name); - LOG(INFO) << "Previous build number: " << file_name.c_str(); +// This method retrieves the previous build version for the given diff +// installer path. +bool MiniInstallerTestUtil::GetPreviousBuildNumber(const std::wstring& path, + std::wstring *build_number) { + + std::wstring diff_name = file_util::GetFilenameFromPath(path); + // We want to remove 'from_', so add its length to found index (which is 5) + std::wstring::size_type start_position = diff_name.find(L"from_") + 5; + std::wstring::size_type end_position = diff_name.find(L"_c"); + std::wstring::size_type size = end_position - start_position; + + std::wstring build_no = diff_name.substr(start_position, size); + + // Search for a build folder with this build suffix. + std::wstring pattern = L"*" + build_no; + + file_util::FileEnumerator files(FilePath( + mini_installer_constants::kChromeDiffInstallerLocation), + false, file_util::FileEnumerator::DIRECTORIES, pattern); + FilePath folder = files.Next(); + if (folder.empty()) + return false; + + build_number->assign(folder.BaseName().ToWStringHack()); + return true; } + // This method will get the previous full installer path // from given diff installer path. It will first get the // filename from the diff installer path, gets the previous // build information from the filename, then computes the // path for previous full installer. bool MiniInstallerTestUtil::GetPreviousFullInstaller( - const std::wstring& diff_file_name, std::wstring *previous, - const wchar_t* channel_type) { - std::wstring diff_file = diff_file_name; - std::wstring build_number; - GetPreviousBuildNumber(diff_file, &build_number, channel_type); - file_util::UpOneDirectory(&diff_file); - file_util::UpOneDirectory(&diff_file); - if (channel_type == mini_installer_constants::kDevChannelBuild) - file_util::UpOneDirectory(&diff_file); - file_util::AppendToPath(&diff_file, build_number.c_str()); - if (channel_type == mini_installer_constants::kDevChannelBuild) - file_util::AppendToPath(&diff_file, L"win"); - previous->assign(diff_file); - file_util::AppendToPath(&diff_file, L"*.exe"); - FileInfoList directory_list; - if (!GetLatestFile(diff_file.c_str(), - mini_installer_constants::kFullInstallerPattern, - &directory_list)) + const std::wstring& diff_path, std::wstring *previous) { + std::wstring build_no; + + if (!GetPreviousBuildNumber(diff_path, &build_no)) return false; - file_util::AppendToPath(previous, directory_list.at(0).name_); - return file_util::PathExists(FilePath::FromWStringHack(*previous)); + + // Use the fifth and onward characters of the build version string + // to compose the full installer name. + std::wstring name = build_no.substr(4) + + mini_installer_constants::kFullInstallerPattern + L".exe"; + + // Create the full installer path. + FilePath installer = FilePath( + mini_installer_constants::kChromeDiffInstallerLocation); + installer = installer.Append(build_no).Append(L"win").Append(name); + previous->assign(installer.value()); + + return file_util::PathExists(installer); } bool MiniInstallerTestUtil::GetStandaloneInstallerFileName( @@ -230,7 +243,7 @@ bool MiniInstallerTestUtil::GetStandaloneVersion( file_name = file_name.substr(0, last_dot); std::wstring::size_type pos = file_name.find(L'_'); file_name.replace(pos, 1, L"."); - file_name = L"2.0." + file_name; + file_name = L"3.0." + file_name; return_file_name->assign(file_name.c_str()); LOG(INFO) << "Standalone installer version: " << file_name.c_str(); return true; @@ -249,16 +262,19 @@ void MiniInstallerTestUtil::SendEnterKeyToWindow() { SendInput(1, &key, sizeof(INPUT)); } + void MiniInstallerTestUtil::VerifyProcessLaunch( const wchar_t* process_name, bool expected_status) { int timer = 0, wait_time = 60000; if (!expected_status) wait_time = 8000; + while ((base::GetProcessCount(process_name, NULL) == 0) && (timer < wait_time)) { PlatformThread::Sleep(200); timer = timer + 200; } + if (expected_status) ASSERT_NE(0, base::GetProcessCount(process_name, NULL)); else diff --git a/chrome/test/mini_installer_test/mini_installer_test_util.h b/chrome/test/mini_installer_test/mini_installer_test_util.h index 8312dad..dd205ab 100644 --- a/chrome/test/mini_installer_test/mini_installer_test_util.h +++ b/chrome/test/mini_installer_test/mini_installer_test_util.h @@ -60,22 +60,24 @@ class MiniInstallerTestUtil { // Returns the directory containing exe_name. static std::wstring GetFilePath(const wchar_t* exe_name); + // This method will get the list of all folders or files based on the passed // 'path' and 'pattern' argument. The 'pattern' argument decides if the // requested file is a full or a differential installer. static bool GetLatestFile(const wchar_t* path, const wchar_t* pattern, FileInfoList *file_name); - // This method will get the previous build number - static void GetPreviousBuildNumber(const std::wstring& path, - std::wstring *build_number, const wchar_t* channel_type); + // This method retrieves the previous build version for the given diff + // installer path. + static bool GetPreviousBuildNumber(const std::wstring& path, + std::wstring *build_number); // This method will get the previous full installer based on 'diff_file' // and 'channel_type' arguments. The 'channel_type' // parameter decides if the build is stable/dev/beta. The 'diff_file' // parameter will hold the latest diff installer name. static bool GetPreviousFullInstaller(const std::wstring& diff_file, - std::wstring *previous, const wchar_t* channel_type); + std::wstring *previous); // This method will return standalone installer file name. static bool GetStandaloneInstallerFileName(FileInfoList *file_name); diff --git a/chrome/test/mini_installer_test/run_all_unittests.cc b/chrome/test/mini_installer_test/run_all_unittests.cc index 9f2dc9f..e6ef00f 100644 --- a/chrome/test/mini_installer_test/run_all_unittests.cc +++ b/chrome/test/mini_installer_test/run_all_unittests.cc @@ -8,6 +8,7 @@ #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" #include "chrome_mini_installer.h" + void BackUpProfile() { if (base::GetProcessCount(L"chrome.exe", NULL) > 0) { printf("Chrome is currently running and cannot backup the profile." @@ -46,14 +47,21 @@ int main(int argc, char** argv) { } else if (command_line.HasSwitch("backup")) { BackUpProfile(); } else { - printf("This test needs command line Arguments.\n"); - printf("Usage: mini_installer_tests.exe -{clean|backup}\n"); - printf("Note: -clean arg will uninstall your chrome at all levels" + printf("This test needs command line arguments.\n"); + printf("Usage: %ls -{clean|backup} [-build <version>] [-force] \n", + command_line.program().c_str()); + printf("-clean arg will uninstall your chrome at all levels" " and also delete profile.\n" "-backup arg will make a copy of User Data before uninstalling" " your chrome at all levels. The copy will be named as" - " User Data Copy.\n"); - exit(1); + " User Data Copy.\n" + "-build specifies the build to be tested, e.g., 3.0.195.24." + " Specifying 'dev' or 'stable' will use the latest build from that" + " channel. 'latest', the default, will use the latest build.\n" + "-force allows these tests to be run on the current platform," + " regardless of whether it is supported.\n"); + return 1; } + return TestSuite(argc, argv).Run(); } diff --git a/chrome/test/mini_installer_test/test.cc b/chrome/test/mini_installer_test/test.cc index 6c93acb..345a24d 100644 --- a/chrome/test/mini_installer_test/test.cc +++ b/chrome/test/mini_installer_test/test.cc @@ -1,189 +1,145 @@ // Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/command_line.h" #include "base/platform_thread.h" +#include "base/scoped_ptr.h" #include "base/win_util.h" #include "chrome/installer/util/install_util.h" #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" +#include "chrome/test/mini_installer_test/mini_installer_test_util.h" #include "testing/gtest/include/gtest/gtest.h" #include "chrome_mini_installer.h" +// Although the C++ style guide disallows use of namespace directive, use +// here because this is not only a .cc file, but also a test. +using namespace mini_installer_constants; + namespace { + class MiniInstallTest : public testing::Test { protected: + // Whether these tests should be run regardless of our running platform. + bool force_tests_; + + // Installers created in test fixture setup for convenience. + scoped_ptr<ChromeMiniInstaller> user_inst_, sys_inst_; + + public: void CleanTheSystem() { - ChromeMiniInstaller userinstall(mini_installer_constants::kUserInstall); + ChromeMiniInstaller userinstall(kUserInstall); userinstall.UnInstall(); - ChromeMiniInstaller systeminstall( - mini_installer_constants::kSystemInstall); - systeminstall.UnInstall(); + ChromeMiniInstaller systeminstall(kSystemInstall); + systeminstall.UnInstall(); } + virtual void SetUp() { - if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { - CleanTheSystem(); - } else { - printf("These tests don't run on Vista\n"); - exit(0); - } - } - virtual void TearDown() { - if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { - PlatformThread::Sleep(2000); + // Parse test command-line arguments. + const CommandLine* cmd = CommandLine::ForCurrentProcess(); + std::wstring build = cmd->GetSwitchValue(L"build"); + if (build.empty()) + build = L"latest"; + + force_tests_ = cmd->HasSwitch(L"force"); + + if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA || + force_tests_) { CleanTheSystem(); + // Separate the test output from cleaning output + printf("\nBEGIN test----------------------------------------\n"); + + // Create a few differently configured installers that are used in + // the tests, for convenience. + user_inst_.reset(new ChromeMiniInstaller(kUserInstall)); + user_inst_->SetBuildUnderTest(build); + sys_inst_.reset(new ChromeMiniInstaller(kSystemInstall)); + sys_inst_->SetBuildUnderTest(build); + } else { - printf("These tests don't run on Vista\n"); - exit(0); + printf("These tests don't run on this platform.\n"); + exit(1); } } }; }; -// TODO(nsylvain): Change this for GOOGLE_CHROME_BUILD when we have the -// previous installers accessible from our Google Chrome continuous buildbot. -#if defined(OFFICIAL_BUILD) -TEST_F(MiniInstallTest, InstallLatestDevFullInstallerTest) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.InstallFullInstaller(false, - mini_installer_constants::kDevChannelBuild); -} +#if defined(GOOGLE_CHROME_BUILD) +// Could use a parameterized gtest to slim down this list of tests, but since +// these tests will often be run manually, don't want to have obscure test +// names. -TEST_F(MiniInstallTest, InstallLatestDevFullInstallerTestSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.InstallFullInstaller(false, - mini_installer_constants::kDevChannelBuild); +// Install full installer. +TEST_F(MiniInstallTest, FullInstallerUser) { + user_inst_->InstallFullInstaller(false); } - -TEST_F(MiniInstallTest, InstallLatestStableFullInstallerTest) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.InstallFullInstaller(false, - mini_installer_constants::kStableChannelBuild); +TEST_F(MiniInstallTest, FullInstallerSys) { + sys_inst_->InstallFullInstaller(false); } -TEST_F(MiniInstallTest, InstallLatestStableFullInstallerTestSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.InstallFullInstaller(false, - mini_installer_constants::kStableChannelBuild); +// Overinstall full installer. +TEST_F(MiniInstallTest, FullOverPreviousFullUser) { + user_inst_->OverInstallOnFullInstaller(kFullInstall); } - -TEST_F(MiniInstallTest, - InstallLatestDevFullInstallerOverPreviousFullDevInstaller) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.OverInstallOnFullInstaller(mini_installer_constants::kFullInstall, - mini_installer_constants::kDevChannelBuild); -} - -TEST_F(MiniInstallTest, - InstallLatestDevFullInstallerOverPreviousFullDevInstallerSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.OverInstallOnFullInstaller(mini_installer_constants::kFullInstall, - mini_installer_constants::kDevChannelBuild); +TEST_F(MiniInstallTest, FullOverPreviousFullSys) { + sys_inst_->OverInstallOnFullInstaller(kFullInstall); } -TEST_F(MiniInstallTest, - InstallLatestDevDiffInstallerOverPreviousFullDevInstaller) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.OverInstallOnFullInstaller(mini_installer_constants::kDiffInstall, - mini_installer_constants::kDevChannelBuild); +// Overinstall diff installer. +TEST_F(MiniInstallTest, DiffOverPreviousFullUser) { + user_inst_->OverInstallOnFullInstaller(kDiffInstall); } - -TEST_F(MiniInstallTest, - InstallLatestDevDiffInstallerOverPreviousFullDevInstallerSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.OverInstallOnFullInstaller(mini_installer_constants::kDiffInstall, - mini_installer_constants::kDevChannelBuild); +TEST_F(MiniInstallTest, DiffOverPreviousFullSys) { + sys_inst_->OverInstallOnFullInstaller(kDiffInstall); } -TEST_F(MiniInstallTest, - InstallLatestFullStableInstallerOverPreviousFullStableInstaller) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.OverInstallOnFullInstaller(mini_installer_constants::kFullInstall, - mini_installer_constants::kStableChannelBuild); +// Repair version folder. +TEST_F(MiniInstallTest, RepairFolderOnFullUser) { + user_inst_->Repair(ChromeMiniInstaller::VERSION_FOLDER); } - -TEST_F(MiniInstallTest, - InstallLatestFullStableInstallerOverPreviousFullStableInstallerSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.OverInstallOnFullInstaller(mini_installer_constants::kFullInstall, - mini_installer_constants::kStableChannelBuild); +TEST_F(MiniInstallTest, RepairFolderOnFullSys) { + sys_inst_->Repair(ChromeMiniInstaller::VERSION_FOLDER); } -TEST_F(MiniInstallTest, - InstallLatestDiffStableInstallerOverPreviousFullStableInstaller) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.OverInstallOnFullInstaller(mini_installer_constants::kDiffInstall, - mini_installer_constants::kStableChannelBuild); +// Repair registry. +TEST_F(MiniInstallTest, RepairRegistryOnFullUser) { + user_inst_->Repair(ChromeMiniInstaller::REGISTRY); } - -TEST_F(MiniInstallTest, - InstallLatestDiffStableInstallerOverPreviousFullStableInstallerSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.OverInstallOnFullInstaller(mini_installer_constants::kDiffInstall, - mini_installer_constants::kStableChannelBuild); +TEST_F(MiniInstallTest, RepairRegistryOnFullSys) { + sys_inst_->Repair(ChromeMiniInstaller::REGISTRY); } -TEST_F(MiniInstallTest, StandaloneInstallerTest) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.InstallStandaloneInstaller(); +// Install standalone. +TEST_F(MiniInstallTest, InstallStandaloneUser) { + user_inst_->InstallStandaloneInstaller(); } // This test doesn't make sense. Disabling for now. TEST_F(MiniInstallTest, DISABLED_MiniInstallerOverChromeMetaInstallerTest) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.OverInstall(mini_installer_constants::kDevChannelBuild); + user_inst_->OverInstall(); } // Encountering issue 9593. Disabling temporarily. TEST_F(MiniInstallTest, DISABLED_InstallLatestStableFullInstallerOverChromeMetaInstaller) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.OverInstall(mini_installer_constants::kStableChannelBuild); + user_inst_->OverInstall(); } // Encountering issue 9593. Disabling temporarily. TEST_F(MiniInstallTest, DISABLED_InstallLatestDevFullInstallerOverChromeMetaInstallerTest) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.OverInstall(mini_installer_constants::kDevChannelBuild); -} - -// Repair testcases - -TEST_F(MiniInstallTest, RepairFolderTestOnLatestDevFullInstaller) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.Repair(ChromeMiniInstaller::VERSION_FOLDER, - mini_installer_constants::kDevChannelBuild); -} - -TEST_F(MiniInstallTest, RepairFolderTestOnLatestDevFullInstallerSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.Repair(ChromeMiniInstaller::VERSION_FOLDER, - mini_installer_constants::kDevChannelBuild); -} - -TEST_F(MiniInstallTest, RepairRegistryTestOnLatestDevFullInstaller) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.Repair(ChromeMiniInstaller::REGISTRY, - mini_installer_constants::kDevChannelBuild); -} - -TEST_F(MiniInstallTest, RepairRegistryTestOnLatestDevFullInstallerSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.Repair(ChromeMiniInstaller::REGISTRY, - mini_installer_constants::kDevChannelBuild); + user_inst_->OverInstall(); } #endif -TEST_F(MiniInstallTest, InstallLatestMiniInstallerAtSystemLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kSystemInstall); - installer.Install(); +TEST_F(MiniInstallTest, InstallMiniInstallerSys) { + sys_inst_->Install(); } -TEST_F(MiniInstallTest, InstallLatestMiniInstallerAtUserLevel) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.Install(); +TEST_F(MiniInstallTest, InstallMiniInstallerUser) { + user_inst_->Install(); } -TEST(InstallUtilTests, MiniInstallTestValidWindowsVersion) { +TEST_F(MiniInstallTest, MiniInstallTestValidWindowsVersion) { // We run the tests on all supported OSes. // Make sure the code agrees. EXPECT_TRUE(InstallUtil::IsOSSupported()); |