diff options
author | anantha@chromium.org <anantha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-26 23:14:34 +0000 |
---|---|---|
committer | anantha@chromium.org <anantha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-26 23:14:34 +0000 |
commit | 2dae546bbed097d2a690342bcadaed1011ce80ac (patch) | |
tree | 3f92e887e75bc7b87c7ee419d4cab54d45fa3e3c /chrome/test/mini_installer_test | |
parent | d555e4f9f90e27cf38f7f777504d7e4ffcdcccde (diff) | |
download | chromium_src-2dae546bbed097d2a690342bcadaed1011ce80ac.zip chromium_src-2dae546bbed097d2a690342bcadaed1011ce80ac.tar.gz chromium_src-2dae546bbed097d2a690342bcadaed1011ce80ac.tar.bz2 |
Added logic to get the latest diff installer, full installer, previous full installer from nightly location.
It will now be easy to automate more of the installer testing.
Review URL: http://codereview.chromium.org/49024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12617 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/mini_installer_test')
5 files changed, 213 insertions, 78 deletions
diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.cc b/chrome/test/mini_installer_test/chrome_mini_installer.cc index bca73d8..57a50b9 100644 --- a/chrome/test/mini_installer_test/chrome_mini_installer.cc +++ b/chrome/test/mini_installer_test/chrome_mini_installer.cc @@ -4,11 +4,14 @@ #include "chrome/test/mini_installer_test/chrome_mini_installer.h" +#include <algorithm> + #include "base/path_service.h" #include "base/platform_thread.h" #include "base/process_util.h" #include "base/registry.h" #include "base/string_util.h" +#include "base/time.h" #include "chrome/installer/setup/setup_constants.h" #include "chrome/installer/util/browser_distribution.h" #include "chrome/installer/util/install_util.h" @@ -19,10 +22,11 @@ // Installs the Chrome mini-installer, checks the registry and shortcuts. void ChromeMiniInstaller::InstallMiniInstaller(bool over_install, - const wchar_t exe_name[]) { + const wchar_t* exe_name) { std::wstring installer_path = GetInstallerExePath(exe_name); printf("\nChrome will be installed at %ls level\n", install_type_.c_str()); - printf("\nWill proceed with the test only if mini_installer.exe exists\n"); + printf("\nWill proceed with the test only if this path exists%ls\n", + installer_path.c_str()); ASSERT_TRUE(file_util::PathExists(installer_path)); printf("\ninstaller found at %ls\n", installer_path.c_str()); LaunchInstaller(installer_path, exe_name); @@ -31,7 +35,7 @@ void ChromeMiniInstaller::InstallMiniInstaller(bool over_install, FindChromeShortcut(); VerifyChromeLaunch(); CloseFirstRunUIDialog(over_install); - } +} // This method tests the standalone installer by verifying the steps listed at: // https://sites.google.com/a/google.com/chrome-pmo/ @@ -137,7 +141,8 @@ void ChromeMiniInstaller::UnInstall() { } // Takes care of Chrome uninstall dialog. -bool ChromeMiniInstaller::CloseWindow(LPCWSTR window_name, UINT message) { +bool ChromeMiniInstaller::CloseWindow(const wchar_t* window_name, + UINT message) { int timer = 0; bool return_val = false; HWND hndl = FindWindow(NULL, window_name); @@ -154,7 +159,7 @@ bool ChromeMiniInstaller::CloseWindow(LPCWSTR window_name, UINT message) { } // Closes Chrome browser. -void ChromeMiniInstaller::CloseChromeBrowser(LPCWSTR window_name) { +void ChromeMiniInstaller::CloseChromeBrowser(const wchar_t* window_name) { WaitUntilProcessStartsRunning(installer_util::kChromeExe); ASSERT_TRUE(CloseWindow(window_name, WM_CLOSE)); } @@ -184,7 +189,7 @@ void ChromeMiniInstaller::CloseProcesses(const std::wstring& executable_name) { } // Checks for Chrome registry keys. -bool ChromeMiniInstaller::CheckRegistryKey(std::wstring key_path) { +bool ChromeMiniInstaller::CheckRegistryKey(const std::wstring& key_path) { RegKey key; if (!key.Open(GetRootRegistryKey(), key_path.c_str(), KEY_ALL_ACCESS)) { printf("Cannot open reg key\n"); @@ -242,8 +247,33 @@ std::wstring ChromeMiniInstaller::GetChromeInstallDirectoryLocation() { return path; } +// This method will create a command line to run apply tag. +bool ChromeMiniInstaller::GetCommandForTagging(std::wstring *return_command) { + file_info_list file_details; + ChromeMiniInstaller::GetStandaloneInstallerFileName(&file_details); + std::wstring standalone_installer_name, standalone_installer_path; + if (file_details.empty()) + return false; + if (file_details.at(0).name_.empty()) + return false; + standalone_installer_name.append(file_details.at(0).name_); + standalone_installer_path.assign( + mini_installer_constants::kChromeStandAloneInstallerLocation); + standalone_installer_path.append(standalone_installer_name); + return_command->append( + mini_installer_constants::kChromeApplyTagExe); + return_command->append(L" "); + return_command->append(standalone_installer_path); + return_command->append(L" "); + return_command->append(mini_installer_constants::kStandaloneInstaller); + return_command->append(L" "); + return_command->append(mini_installer_constants::kChromeApplyTagParameters); + printf("Command to run Apply tag is %ls\n", return_command->c_str()); + return true; +} + // Get path for mini_installer.exe. -std::wstring ChromeMiniInstaller::GetInstallerExePath(const wchar_t name[]) { +std::wstring ChromeMiniInstaller::GetInstallerExePath(const wchar_t* name) { std::wstring installer_path; PathService::Get(base::DIR_EXE, &installer_path); file_util::AppendToPath(&installer_path, name); @@ -261,44 +291,125 @@ std::wstring ChromeMiniInstaller::GetStartMenuShortcutPath() { return path_name; } -// This method will get the standalone installer filename from the directory. -bool ChromeMiniInstaller::GetStandaloneInstallerFileName(std::wstring* name) { - std::wstring search_path, file_name; - size_t position_found; - file_name.append( - mini_installer_constants::kChromeStandAloneInstallerLocation); - file_name.append(L"*.exe"); +// This is a predicate to sort file_info. +bool IsNewer(const file_info& file_rbegin, const file_info& file_rend) { + return (file_rbegin.creation_time_ > file_rend.creation_time_); +} + +// This method will first call GetLatestFile to get the list of all +// builds, sorted on creation time. Then goes through each build folder +// until it finds the installer file that matches the pattern argument. +bool ChromeMiniInstaller::GetInstaller(const wchar_t* pattern, + std::wstring *path) { + file_info_list list; + std::wstring chrome_diff_installer( + mini_installer_constants::kChromeDiffInstallerLocation); + chrome_diff_installer.append(L"*"); + if (!GetLatestFile(chrome_diff_installer.c_str(), + mini_installer_constants::kDevChannelBuildPattern, &list)) + return false; + int list_size = (list.size())-1; + while (list_size > 0) { + path->assign(L""); + path->append(mini_installer_constants::kChromeDiffInstallerLocation); + file_util::AppendToPath(path, list.at(list_size).name_.c_str()); + std::wstring build_number; + build_number.assign(list.at(list_size).name_.c_str()); + std::wstring installer_path( + mini_installer_constants::kChromeDiffInstallerLocation); + installer_path.append(build_number.c_str()); + file_util::AppendToPath(&installer_path, L"*.exe"); + if (!GetLatestFile(installer_path.c_str(), pattern, &list)) + return false; + file_util::AppendToPath(path, list.at(0).name_.c_str()); + if (!file_util::PathExists(*path)) + list_size--; + break; + } + return (file_util::PathExists(path->c_str())); +} + +// This method will get the latest installer filename from the directory. +bool ChromeMiniInstaller::GetLatestFile(const wchar_t* file_name, + const wchar_t* pattern, + file_info_list *file_details) { WIN32_FIND_DATA find_file_data; - HANDLE file_handle = FindFirstFile(file_name.c_str(), &find_file_data); + HANDLE file_handle = FindFirstFile(file_name, &find_file_data); if (file_handle == INVALID_HANDLE_VALUE) { printf("Handle is invalid\n"); return false; } BOOL ret = TRUE; while (ret) { - search_path = find_file_data.cFileName; - position_found = search_path.find(L"ChromeStandaloneSetup_"); - if (position_found == 0) { - name->assign(find_file_data.cFileName); - printf("Untagged installer name is %ls\n", name->c_str()); - break; + std::wstring search_path = find_file_data.cFileName; + size_t position_found = search_path.find(pattern); + if (position_found != -1) { + std::wstring extension = file_util::GetFileExtensionFromPath(file_name); + if (extension.compare(L"exe") == 0) { + file_details->push_back(file_info(find_file_data.cFileName, 0)); + break; + } else { + FILETIME file_time = find_file_data.ftCreationTime; + base::Time creation_time = base::Time::FromFileTime(file_time); + file_details->push_back(file_info(find_file_data.cFileName, + static_cast<int>(creation_time.ToDoubleT()))); + } } ret = FindNextFile(file_handle, &find_file_data); } + std::sort(file_details->rbegin(), file_details->rend(), &IsNewer); FindClose(file_handle); 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 ChromeMiniInstaller::GetPreviousFullInstaller( + const std::wstring& diff_file_name, std::wstring *previous) { + std::wstring diff_file = diff_file_name; + std::wstring name = file_util::GetFilenameFromPath(diff_file); + file_util::UpOneDirectory(&diff_file); + file_util::UpOneDirectory(&diff_file); + std::wstring file_name = name.substr(11, 15); + std::wstring::size_type last_dot = file_name.find(L'_'); + file_name = file_name.substr(0, last_dot); + file_name = L"2.0." + file_name; + file_util::AppendToPath(&diff_file, file_name.c_str()); + previous->assign(diff_file); + file_util::AppendToPath(&diff_file, L"*.exe"); + file_info_list directory_list; + if (!GetLatestFile(diff_file.c_str(), + mini_installer_constants::kFullInstallerPattern, + &directory_list)) + return false; + file_util::AppendToPath(previous, directory_list.at(0).name_); + return (file_util::PathExists(previous->c_str())); +} + +// This method will return standalone installer file name. +bool ChromeMiniInstaller::GetStandaloneInstallerFileName( + file_info_list *file_name) { + std::wstring standalone_installer( + mini_installer_constants::kChromeStandAloneInstallerLocation); + standalone_installer.append(L"*.exe"); + return (GetLatestFile(standalone_installer.c_str(), + mini_installer_constants::kUntaggedInstallerPattern, + file_name)); +} + // This method will get the version number from the filename. bool ChromeMiniInstaller::GetStandaloneVersion(std::wstring* return_file_name) { - std::wstring file_name; - if (!GetStandaloneInstallerFileName(&file_name)) - return false; + file_info_list file_details; + ChromeMiniInstaller::GetStandaloneInstallerFileName(&file_details); + std::wstring file_name = file_details.at(0).name_; // Returned file name will have following convention: // ChromeStandaloneSetup_<build>_<patch>.exe // Following code will extract build, patch details from the file // and concatenate with 1.0 to form the build version. - // Patteren followed: 1.0.<build>.<patch> + // Patteren followed: 1.0.<build>.<patch>htt file_name = file_name.substr(22, 25); std::wstring::size_type last_dot = file_name.find(L'.'); file_name = file_name.substr(0, last_dot); @@ -354,8 +465,8 @@ bool ChromeMiniInstaller::IsChromiumBuild() { } // Launches the chrome installer and waits for it to end. -void ChromeMiniInstaller::LaunchInstaller(std::wstring path, - const wchar_t process_name[]) { +void ChromeMiniInstaller::LaunchInstaller(const std::wstring& path, + const wchar_t* process_name) { ASSERT_TRUE(file_util::PathExists(path)); if (install_type_ == mini_installer_constants::kSystemInstall) { std::wstring launch_args = L" -system-level"; @@ -365,35 +476,9 @@ void ChromeMiniInstaller::LaunchInstaller(std::wstring path, } printf("Waiting while this process is running %ls ....", process_name); WaitUntilProcessStartsRunning(process_name); - // This is a temporary workaround until thankyou dialog is supressed. - if (standalone_installer == true) { - WaitUntilProcessStartsRunning(installer_util::kChromeExe); - PlatformThread::Sleep(1200); - CloseProcesses(mini_installer_constants::kGoogleUpdateExecutable); - } WaitUntilProcessStopsRunning(process_name); } -// This method will create a command line to run apply tag. -bool ChromeMiniInstaller::GetCommandForTagging(std::wstring *return_command) { - std::wstring standalone_installer_name, standalone_installer_path; - if (!GetStandaloneInstallerFileName(&standalone_installer_name)) - return false; - standalone_installer_path.assign( - mini_installer_constants::kChromeStandAloneInstallerLocation); - standalone_installer_path.append(standalone_installer_name); - return_command->append( - mini_installer_constants::kChromeApplyTagExe); - return_command->append(L" "); - return_command->append(standalone_installer_path); - return_command->append(L" "); - return_command->append(mini_installer_constants::kStandaloneInstaller); - return_command->append(L" "); - return_command->append(mini_installer_constants::kChromeApplyTagParameters); - printf("Command to run Apply tag is %ls\n", return_command->c_str()); - return true; -} - // Launch Chrome to see if it works after overinstall. Then close it. void ChromeMiniInstaller::VerifyChromeLaunch() { std::wstring username, path, append_path; @@ -408,8 +493,8 @@ void ChromeMiniInstaller::VerifyChromeLaunch() { // This method compares the registry keys after overinstall. bool ChromeMiniInstaller::VerifyOverInstall( - std::wstring value_before_overinstall, - std::wstring value_after_overinstall) { + const std::wstring& value_before_overinstall, + const std::wstring& value_after_overinstall) { int64 reg_key_value_before_overinstall = StringToInt64( value_before_overinstall); int64 reg_key_value_after_overinstall = StringToInt64( @@ -438,7 +523,7 @@ bool ChromeMiniInstaller::VerifyStandaloneInstall() { } // Waits until the process starts running. void ChromeMiniInstaller::WaitUntilProcessStartsRunning( - const wchar_t process_name[]) { + const wchar_t* process_name) { int timer = 0; while ((base::GetProcessCount(process_name, NULL) == 0) && (timer < 60000)) { @@ -450,7 +535,7 @@ void ChromeMiniInstaller::WaitUntilProcessStartsRunning( // Waits until the process stops running. void ChromeMiniInstaller::WaitUntilProcessStopsRunning( - const wchar_t process_name[]) { + const wchar_t* process_name) { int timer = 0; printf("\nWaiting for this process to end... %ls\n", process_name); while ((base::GetProcessCount(process_name, NULL) > 0) && diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.h b/chrome/test/mini_installer_test/chrome_mini_installer.h index 61f0536..f692d5a 100644 --- a/chrome/test/mini_installer_test/chrome_mini_installer.h +++ b/chrome/test/mini_installer_test/chrome_mini_installer.h @@ -12,9 +12,28 @@ #include <tchar.h> #include <errno.h> #include <string> +#include <vector> #include "base/file_util.h" +// This structure holds the name and creation time +// details of all the chrome nightly builds. +class file_info { + public: + file_info() {} + file_info(const std::wstring& in_name, int in_creation_time) { + name_.assign(in_name); + creation_time_ = in_creation_time; + } + // This is a predicate to sort file information. + bool IsNewer(const file_info& creation_time_begin, + const file_info& creation_time_end); + + std::wstring name_; + int creation_time_; +}; +typedef std::vector<file_info> file_info_list; + // This class has methods to install and uninstall Chrome mini installer. class ChromeMiniInstaller { public: @@ -32,7 +51,7 @@ class ChromeMiniInstaller { // Installs Chrome Mini Installer. void InstallMiniInstaller(bool over_install = false, - const wchar_t exe_name[] = L""); + const wchar_t* exe_name = L""); // This will test the standalone installer. void InstallStandaloneIntaller(); @@ -47,19 +66,20 @@ class ChromeMiniInstaller { // This variable holds the install type. // Install type can be either system or user level. std::wstring install_type_; + bool standalone_installer; // Closes First Run UI dialog. void CloseFirstRunUIDialog(bool over_install); // Closes Chrome uninstall confirm dialog window. - bool CloseWindow(LPCWSTR window_name, UINT message); + bool CloseWindow(const wchar_t* window_name, UINT message); // Closes Chrome browser. - void CloseChromeBrowser(LPCWSTR window_name); + void CloseChromeBrowser(const wchar_t* window_name); // Checks for registry key. - bool CheckRegistryKey(std::wstring key_path); + bool CheckRegistryKey(const std::wstring& key_path); // Deletes App folder after uninstall. void DeleteAppFolder(); @@ -71,17 +91,38 @@ class ChromeMiniInstaller { // or documents and setting based on the install type. std::wstring GetChromeInstallDirectoryLocation(); + // This method will create a command line to run apply tag. + bool GetCommandForTagging(std::wstring *return_command); + + // This method will get the latest installer based + // on the pattern argument passed. + bool GetInstaller(const wchar_t* pattern, std::wstring *name); + + // Get path for mini_installer.exe. + std::wstring GetInstallerExePath(const wchar_t* installer_name); + + // This method will get the latest installer filename, + // based on the passed pattern argument. + bool GetLatestFile(const wchar_t* path, + const wchar_t* pattern, + file_info_list *file_name); + + // This method will get the previous full installer based on + // the diff installer file name argument. + bool GetPreviousFullInstaller(const std::wstring& diff_file, + std::wstring *previous); + // Get HKEY based on install type. HKEY GetRootRegistryKey(); - // Get path for mini_installer.exe. - std::wstring GetInstallerExePath(const wchar_t installer_name[]); + // Returns Chrome pv registry key value + bool GetRegistryKey(std::wstring *return_reg_key_value); // This method gets the shortcut path from start menu based on install type. std::wstring GetStartMenuShortcutPath(); - // This method will get the standalone installer filename. - bool GetStandaloneInstallerFileName(std::wstring* file_name); + // This method will return standalone installer file name. + bool GetStandaloneInstallerFileName(file_info_list *file_name); // This method will get the version number from the filename. bool GetStandaloneVersion(std::wstring* version); @@ -89,33 +130,28 @@ class ChromeMiniInstaller { // Get path for uninstall. std::wstring GetUninstallPath(); - // Returns Chrome pv registry key value - bool GetRegistryKey(std::wstring *return_reg_key_value); - // Checks for the build type bool IsChromiumBuild(); // Launches the chrome installer and waits for it to end. - void LaunchInstaller(std::wstring install_path, const wchar_t process_name[]); - - // This method will create a command line to run apply tag. - bool GetCommandForTagging(std::wstring *return_command); + void LaunchInstaller(const std::wstring& install_path, + const wchar_t* process_name); // Verifies if Chrome launches after install. void VerifyChromeLaunch(); // Compares the registry key values after overinstall. - bool VerifyOverInstall(std::wstring reg_key_value_before_overinstall, - std::wstring reg_key_value_after_overinstall); + bool VerifyOverInstall(const std::wstring& reg_key_value_before_overinstall, + const std::wstring& reg_key_value_after_overinstall); // This method will verify if the installed build is correct. bool VerifyStandaloneInstall(); // Waits until the given process starts running - void WaitUntilProcessStartsRunning(const wchar_t process_name[]); + void WaitUntilProcessStartsRunning(const wchar_t* process_name); // Waits until the given process stops running - void WaitUntilProcessStopsRunning(const wchar_t process_name[]); + void WaitUntilProcessStopsRunning(const wchar_t* process_name); DISALLOW_EVIL_CONSTRUCTORS(ChromeMiniInstaller); }; diff --git a/chrome/test/mini_installer_test/mini_installer_test_constants.cc b/chrome/test/mini_installer_test/mini_installer_test_constants.cc index 6e1571d..86cefe9 100644 --- a/chrome/test/mini_installer_test/mini_installer_test_constants.cc +++ b/chrome/test/mini_installer_test/mini_installer_test_constants.cc @@ -30,6 +30,10 @@ const wchar_t kSystemInstall[] = L"system"; const wchar_t kUserInstall[] = L"user"; const wchar_t kStandaloneInstaller[] = L"ChromeSetupTest.exe"; const wchar_t kGoogleUpdateExecutable[] = L"GoogleUpdate.exe"; +const wchar_t kUntaggedInstallerPattern[] = L"ChromeStandaloneSetup_"; +const wchar_t kDiffInstallerPattern[] = L"_from_"; +const wchar_t kFullInstallerPattern[] = L"_chrome_installer"; +const wchar_t kDevChannelBuildPattern[] = L"2.0."; // Google Chrome meta installer location. const wchar_t kChromeMetaInstallerExe[] = @@ -40,4 +44,6 @@ const wchar_t kChromeApplyTagExe[] = L"\\\\172.23.44.61\\shared\\chrome_autotest\\ApplyTag.exe"; const wchar_t kChromeApplyTagParameters[] = L"\"appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}&appname=Chrome&needsadmin=false\""; +const wchar_t kChromeDiffInstallerLocation[] = + L"\\\\172.24.6.7\\shares\\googleclient\\save\\builds\\chrome\\"; } diff --git a/chrome/test/mini_installer_test/mini_installer_test_constants.h b/chrome/test/mini_installer_test/mini_installer_test_constants.h index 1f16147..fe94062 100644 --- a/chrome/test/mini_installer_test/mini_installer_test_constants.h +++ b/chrome/test/mini_installer_test/mini_installer_test_constants.h @@ -32,12 +32,17 @@ extern const wchar_t kChromeUninstallShortcut[]; extern const wchar_t kSystemInstall[]; extern const wchar_t kStandaloneInstaller[]; extern const wchar_t kUserInstall[]; +extern const wchar_t kUntaggedInstallerPattern[]; +extern const wchar_t kDiffInstallerPattern[]; +extern const wchar_t kFullInstallerPattern[]; +extern const wchar_t kDevChannelBuildPattern[]; // Google Chrome meta installer location. extern const wchar_t kChromeApplyTagExe[]; extern const wchar_t kChromeMetaInstallerExe[]; extern const wchar_t kChromeStandAloneInstallerLocation[]; extern const wchar_t kChromeApplyTagParameters[]; +extern const wchar_t kChromeDiffInstallerLocation[]; } #endif // CHROME_TEST_MINI_INSTALLER_TEST_MINI_INSTALLER_TEST_CONSTANTS_H__ diff --git a/chrome/test/mini_installer_test/test.cc b/chrome/test/mini_installer_test/test.cc index f8a4f08..1a5c0ff 100644 --- a/chrome/test/mini_installer_test/test.cc +++ b/chrome/test/mini_installer_test/test.cc @@ -33,9 +33,12 @@ class MiniInstallTest : public testing::Test { }; TEST_F(MiniInstallTest, StandaloneInstallerTest) { - ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); - installer.InstallStandaloneIntaller(); + if (win_util::GetWinVersion() < win_util::WINVERSION_VISTA) { + ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); + installer.InstallStandaloneIntaller(); + } } + TEST_F(MiniInstallTest, MiniInstallerOverChromeMetaInstallerTest) { ChromeMiniInstaller installer(mini_installer_constants::kUserInstall); installer.OverInstall(); |