diff options
author | hnguyen@google.com <hnguyen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-16 22:55:55 +0000 |
---|---|---|
committer | hnguyen@google.com <hnguyen@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-16 22:55:55 +0000 |
commit | 850049d51f508697fc3bce0476d738d786eb4abe (patch) | |
tree | a08b09d01d55ddb8500ce8415b4b81a7d42e2818 /chrome/test/mini_installer_test | |
parent | 4354b4fbdbe591ddd4c0e06633170c32c5288d78 (diff) | |
download | chromium_src-850049d51f508697fc3bce0476d738d786eb4abe.zip chromium_src-850049d51f508697fc3bce0476d738d786eb4abe.tar.gz chromium_src-850049d51f508697fc3bce0476d738d786eb4abe.tar.bz2 |
Change the routine to find latest build dir and installer file.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7818012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101591 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/mini_installer_test')
7 files changed, 240 insertions, 342 deletions
diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.cc b/chrome/test/mini_installer_test/chrome_mini_installer.cc index d57668b..08d8ec6 100644 --- a/chrome/test/mini_installer_test/chrome_mini_installer.cc +++ b/chrome/test/mini_installer_test/chrome_mini_installer.cc @@ -4,6 +4,8 @@ #include "chrome/test/mini_installer_test/chrome_mini_installer.h" +#include <algorithm> + #include "base/command_line.h" #include "base/file_util.h" #include "base/path_service.h" @@ -23,58 +25,86 @@ using base::win::RegKey; -ChromeMiniInstaller::ChromeMiniInstaller(const std::wstring& install_type, - bool is_chrome_frame) - : is_chrome_frame_(is_chrome_frame), - install_type_(install_type), - has_diff_installer_(false), - has_full_installer_(false), - has_prev_installer_(false) { - installer_name_ = base::StringPrintf(L"%ls (%ls)", - mini_installer_constants::kChromeBuildType, install_type_.c_str()); -} - -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(); +namespace { - // 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, is_chrome_frame_); - has_diff_installer_ = MiniInstallerTestUtil::GetInstaller( - mini_installer_constants::kDiffInstallerPattern, - &diff_installer_, build_prefix, is_chrome_frame_); +struct FilePathInfo { + file_util::FileEnumerator::FindInfo info; + FilePath path; +}; + +bool CompareDate(const FilePathInfo& a, + const FilePathInfo& b) { +#if defined(OS_POSIX) + return a.info.stat.st_mtime > b.info.stat.st_mtime; +#elif defined(OS_WIN) + if (a.info.ftLastWriteTime.dwHighDateTime == + b.info.ftLastWriteTime.dwHighDateTime) { + return a.info.ftLastWriteTime.dwLowDateTime > + b.info.ftLastWriteTime.dwLowDateTime; + } else { + return a.info.ftLastWriteTime.dwHighDateTime > + b.info.ftLastWriteTime.dwHighDateTime; + } +#endif +} + +// Get list of file |type| matching |pattern| in |root|. +// The list is sorted in last modified date order. +// Return true if files/directories are found. +bool FindMatchingFiles(const FilePath& root, + const FilePath::StringType& pattern, + file_util::FileEnumerator::FileType type, + std::vector<FilePath>* paths) { + file_util::FileEnumerator files(root, false, type, pattern); + std::vector<FilePathInfo> matches; + for (FilePath current = files.Next(); !current.empty(); + current = files.Next()) { + FilePathInfo entry; + files.GetFindInfo(&entry.info); + entry.path = current; + matches.push_back(entry); + } + + if (matches.empty()) + return false; - if (has_diff_installer_) { - has_prev_installer_ = MiniInstallerTestUtil::GetPreviousFullInstaller( - diff_installer_, &prev_installer_, is_chrome_frame_); + std::sort(matches.begin(), matches.end(), CompareDate); + std::vector<FilePathInfo>::iterator current; + for (current = matches.begin(); current != matches.end(); ++current) { + paths->push_back(current->path); } + return true; +} - // 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(); +bool FindNewestMatchingFile(const FilePath& root, + const FilePath::StringType& pattern, + file_util::FileEnumerator::FileType type, + FilePath* path) { + std::vector<FilePath> paths; + if (FindMatchingFiles(root, pattern, type, &paths)) { + *path = paths[0]; + return true; } - if (has_prev_installer_) { - FilePath folder = FilePath(prev_installer_).DirName().DirName(); - prev_version_ = folder.BaseName().value(); + return false; +} + +} // namespace + +ChromeMiniInstaller::ChromeMiniInstaller(const std::wstring& install_type, + bool is_chrome_frame) + : is_chrome_frame_(is_chrome_frame), + install_type_(install_type) {} + +void ChromeMiniInstaller::SetBuildUnderTest( + const std::wstring& build) { + if (!LocateInstallers(build)) { + LOG(WARNING) << "Could not find one or more installers."; } } // Installs Chrome. void ChromeMiniInstaller::Install() { - std::wstring installer_path = MiniInstallerTestUtil::GetFilePath( + FilePath installer_path = MiniInstallerTestUtil::GetFilePath( mini_installer_constants::kChromeMiniInstallerExecutable); InstallMiniInstaller(false, installer_path); } @@ -83,13 +113,13 @@ void ChromeMiniInstaller::Install() { // nightly location, install it and over install with specified install_type. void ChromeMiniInstaller::OverInstallOnFullInstaller( const std::wstring& install_type, bool should_start_ie) { - ASSERT_TRUE(has_full_installer_ && has_diff_installer_ && - has_prev_installer_); + ASSERT_TRUE(!full_installer_.empty() && !diff_installer_.empty() && + !previous_installer_.empty()); if (should_start_ie) LaunchIE(L"http://www.google.com"); - InstallMiniInstaller(false, prev_installer_); + InstallMiniInstaller(false, previous_installer_); std::wstring got_prev_version; GetChromeVersionFromRegistry(&got_prev_version); @@ -97,29 +127,29 @@ void ChromeMiniInstaller::OverInstallOnFullInstaller( if (install_type == mini_installer_constants::kDiffInstall) { printf("\nOver installing with latest differential installer: %ls\n", - diff_installer_.c_str()); + diff_installer_.value()); InstallMiniInstaller(true, diff_installer_); } else if (install_type == mini_installer_constants::kFullInstall) { printf("\nOver installing with latest full insatller: %ls\n", - full_installer_.c_str()); + full_installer_.value()); InstallMiniInstaller(true, full_installer_); } 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", - prev_version_.c_str(), curr_version_.c_str()); + if (got_prev_version == previous_build_ && + got_curr_version == current_build_) { + LOG(INFO) << "The over install was successful.\n" + << "Full installer: " << previous_build_; + LOG(INFO) << "Diff installer: " << current_build_; } else { - 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", - prev_version_.c_str(), got_prev_version.c_str()); - printf("\n Expected diff installer value: %ls and actual value is %ls\n", - curr_version_.c_str(), got_curr_version.c_str()); + LOG(INFO) << "The over install was not successful.\n" + << "Expected full installer value: " << previous_build_; + LOG(INFO) << "Actual value is: " << got_prev_version; + LOG(INFO) << "Expected diff: " << current_build_ + << "Actual value is: " << got_curr_version; FAIL(); } } @@ -127,20 +157,21 @@ void ChromeMiniInstaller::OverInstallOnFullInstaller( // This method will get the latest full installer from nightly location // and installs it. void ChromeMiniInstaller::InstallFullInstaller(bool over_install) { - ASSERT_TRUE(has_full_installer_); - InstallMiniInstaller(over_install, full_installer_); + if (!full_installer_.empty()) + InstallMiniInstaller(over_install, full_installer_); } // Installs the Chrome mini-installer, checks the registry and shortcuts. void ChromeMiniInstaller::InstallMiniInstaller(bool over_install, - const std::wstring& path) { - printf("\nChrome will be installed at %ls level\n", install_type_.c_str()); - printf("\nWill proceed with the test only if this path exists: %ls\n\n", - path.c_str()); - - FilePath exe_path(path); - ASSERT_TRUE(file_util::PathExists(exe_path)) << path << " does not exist."; - LaunchInstaller(path, exe_path.BaseName().value().c_str()); + const FilePath& path) { + LOG(INFO) << "Chrome will be installed at " + << install_type_ << "level."; + LOG(INFO) << "Will proceed with the test only if this path exists: " + << path.value(); + + ASSERT_TRUE(file_util::PathExists(path)) << path.value() + << " does not exist."; + LaunchInstaller(path, path.BaseName().value().c_str()); BrowserDistribution* dist = BrowserDistribution::GetDistribution(); ASSERT_TRUE(CheckRegistryKey(dist->GetVersionKey())) << dist->GetVersionKey() << " does not exist."; @@ -155,24 +186,39 @@ void ChromeMiniInstaller::InstallMiniInstaller(bool over_install, // that the installed version is correct. void ChromeMiniInstaller::InstallStandaloneInstaller() { file_util::Delete(mini_installer_constants::kStandaloneInstaller, true); - std::wstring tag_installer_command; - ASSERT_TRUE(MiniInstallerTestUtil::GetCommandForTagging( - &tag_installer_command)); + CommandLine tag_installer_command = + ChromeMiniInstaller::GetCommandForTagging(); + ASSERT_FALSE(tag_installer_command.GetCommandLineString().empty()); base::LaunchOptions options; options.wait = true; base::LaunchProcess(tag_installer_command, options, NULL); - std::wstring installer_path = MiniInstallerTestUtil::GetFilePath( + FilePath installer_path = MiniInstallerTestUtil::GetFilePath( mini_installer_constants::kStandaloneInstaller); InstallMiniInstaller(false, installer_path); ASSERT_TRUE(VerifyStandaloneInstall()); file_util::Delete(mini_installer_constants::kStandaloneInstaller, true); } +CommandLine ChromeMiniInstaller::GetCommandForTagging() { + FilePath tagged_installer = MiniInstallerTestUtil::GetFilePath( + mini_installer_constants::kStandaloneInstaller); + if (standalone_installer_.empty()) + return CommandLine::FromString(L""); + CommandLine command = CommandLine::FromString( + base::StringPrintf(L"%ls %ls %ls %ls", + mini_installer_constants::kChromeApplyTagExe, + standalone_installer_.value().c_str(), + tagged_installer.value().c_str(), + mini_installer_constants::kChromeApplyTagParameters)); + LOG(INFO) << "Tagging command: " << command.GetCommandLineString(); + return command; +} + // Installs chromesetup.exe, waits for the install to finish and then // checks the registry and shortcuts. void ChromeMiniInstaller::InstallMetaInstaller() { // Install Google Chrome through meta installer. - LaunchInstaller(mini_installer_constants::kChromeMetaInstallerExe, + LaunchInstaller(FilePath(mini_installer_constants::kChromeMetaInstallerExe), mini_installer_constants::kChromeSetupExecutable); ASSERT_TRUE(MiniInstallerTestUtil::VerifyProcessClose( mini_installer_constants::kChromeMetaInstallerExecutable)); @@ -590,9 +636,9 @@ HKEY ChromeMiniInstaller::GetRootRegistryKey() { } // Launches the chrome installer and waits for it to end. -void ChromeMiniInstaller::LaunchInstaller(const std::wstring& path, +void ChromeMiniInstaller::LaunchInstaller(const FilePath& path, const wchar_t* process_name) { - ASSERT_TRUE(file_util::PathExists(FilePath(path))); + ASSERT_TRUE(file_util::PathExists(path)); std::wstring launch_args; if (is_chrome_frame_) { launch_args.append(L" --do-not-create-shortcuts"); @@ -605,8 +651,8 @@ void ChromeMiniInstaller::LaunchInstaller(const std::wstring& path, } base::ProcessHandle app_handle; - base::LaunchProcess(L"\"" + path + L"\"" + launch_args, base::LaunchOptions(), - &app_handle); + base::LaunchProcess(L"\"" + path.value() + L"\"" + launch_args, + base::LaunchOptions(), &app_handle); printf("Waiting while this process is running %ls ....\n", process_name); MiniInstallerTestUtil::VerifyProcessLaunch(process_name, true); @@ -614,13 +660,13 @@ void ChromeMiniInstaller::LaunchInstaller(const std::wstring& path, } // Gets the path to launch Chrome. -bool ChromeMiniInstaller::GetChromeLaunchPath(std::wstring* launch_path) { +bool ChromeMiniInstaller::GetChromeLaunchPath(FilePath* launch_path) { std::wstring path; path = GetChromeInstallDirectoryLocation(); file_util::AppendToPath(&path, mini_installer_constants::kChromeAppDir); file_util::AppendToPath(&path, installer::kChromeExe); - launch_path->assign(path); - return file_util::PathExists(FilePath(path)); + *launch_path = FilePath(path); + return file_util::PathExists(*launch_path); } // Launch Chrome to see if it works after overinstall. Then close it. @@ -636,9 +682,9 @@ void ChromeMiniInstaller::LaunchAndCloseChrome(bool over_install) { // This method will get Chrome exe path and launch it. void ChromeMiniInstaller::VerifyChromeLaunch(bool expected_status) { - std::wstring launch_path; + FilePath launch_path; GetChromeLaunchPath(&launch_path); - LaunchBrowser(launch_path, L"", installer::kChromeExe, expected_status); + LaunchBrowser(launch_path, L"", expected_status); } // Verifies Chrome/Chrome Frame install. @@ -698,14 +744,18 @@ void ChromeMiniInstaller::LaunchIE(const std::wstring& navigate_url) { } // This method will launch any requested browser. -void ChromeMiniInstaller::LaunchBrowser(const std::wstring& launch_path, - const std::wstring& launch_args, - const std::wstring& process_name, +void ChromeMiniInstaller::LaunchBrowser(const FilePath& path, + const std::wstring& args, bool expected_status) { - base::LaunchProcess(L"\"" + launch_path + L"\"" + L" " + launch_args, - base::LaunchOptions(), NULL); + LOG(INFO) << "Browser executable: " << path.value(); + bool launched = base::LaunchProcess( + L"\"" + path.value() + L"\"" + L" " + args, + base::LaunchOptions(), NULL); + if (!launched) { + LOG(ERROR) << "Could not launch process: " << path.BaseName().value(); + } base::PlatformThread::Sleep(1000); - MiniInstallerTestUtil::VerifyProcessLaunch(process_name.c_str(), + MiniInstallerTestUtil::VerifyProcessLaunch(path.BaseName().value().c_str(), expected_status); } @@ -734,11 +784,84 @@ bool ChromeMiniInstaller::VerifyOverInstall( // This method will verify if the installed build is correct. bool ChromeMiniInstaller::VerifyStandaloneInstall() { - std::wstring reg_key_value_returned, standalone_installer_version; - MiniInstallerTestUtil::GetStandaloneVersion(&standalone_installer_version); + std::wstring reg_key_value_returned; GetChromeVersionFromRegistry(®_key_value_returned); - if (standalone_installer_version.compare(reg_key_value_returned) == 0) + if (current_build_.compare(reg_key_value_returned) == 0) return true; else return false; } + +// Search all the specified |build| directory to find the latest +// diff and full installers. |build| can be empty. +bool ChromeMiniInstaller::LocateInstallers( + const std::wstring& build) { + FilePath::StringType full_installer_pattern = + FILE_PATH_LITERAL("*_chrome_installer*"); + FilePath::StringType diff_installer_pattern = FILE_PATH_LITERAL("*_from_*"); + FilePath root(mini_installer_constants::kChromeInstallersLocation); + std::vector<FilePath> paths; + if (!FindMatchingFiles(root, build, + file_util::FileEnumerator::DIRECTORIES, &paths)) { + return false; + } + + // Find full and diff installers; + std::vector<FilePath>::const_iterator dir; + for (dir = paths.begin(); dir != paths.end(); ++dir) { + FilePath windir = dir->Append( + mini_installer_constants::kWinFolder); + if (FindNewestMatchingFile(windir, full_installer_pattern, + file_util::FileEnumerator::FILES, &full_installer_) && + FindNewestMatchingFile(windir, diff_installer_pattern, + file_util::FileEnumerator::FILES, &diff_installer_)) { + break; + } + } + + // Set current build directory. + if (full_installer_.empty() || diff_installer_.empty()) + return false; + + current_build_ = + full_installer_.DirName().DirName().BaseName().value(); + + // Find previous full installer. + std::vector<std::wstring> tokenized_name; + Tokenize(diff_installer_.BaseName().value(), + L"_", &tokenized_name); + std::wstring build_pattern = base::StringPrintf( + L"*%ls", tokenized_name[2].c_str()); + std::vector<FilePath> previous_build; + if (FindMatchingFiles(diff_installer_.DirName().DirName().DirName(), + build_pattern, file_util::FileEnumerator::DIRECTORIES, + &previous_build)) { + FilePath windir = previous_build.at(0).Append( + mini_installer_constants::kWinFolder); + FindNewestMatchingFile(windir, full_installer_pattern, + file_util::FileEnumerator::FILES, &previous_installer_); + } + + if (previous_installer_.empty()) + return false; + previous_build_ = + previous_installer_.DirName().DirName().BaseName().value(); + + // Get standalone installer. + FilePath standalone_installer( + mini_installer_constants::kChromeStandAloneInstallerLocation); + + // Get the file name. + std::vector<std::wstring> tokenizedBuildNumber; + Tokenize(current_build_, L".", &tokenizedBuildNumber); + std::wstring standalone_installer_filename = base::StringPrintf( + L"%ls%ls_%ls.exe", mini_installer_constants::kUntaggedInstallerPattern, + tokenizedBuildNumber[2].c_str(), tokenizedBuildNumber[3].c_str()); + standalone_installer = standalone_installer.Append(current_build_) + .Append(mini_installer_constants::kWinFolder) + .Append(standalone_installer_filename); + + standalone_installer_ = standalone_installer; + + return !standalone_installer_.empty(); +} diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.h b/chrome/test/mini_installer_test/chrome_mini_installer.h index b48209e..6808f38 100644 --- a/chrome/test/mini_installer_test/chrome_mini_installer.h +++ b/chrome/test/mini_installer_test/chrome_mini_installer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 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. @@ -10,14 +10,13 @@ #include <string> #include "base/basictypes.h" - -class FilePath; +#include "base/file_path.h" +#include "base/command_line.h" // This class has methods to install and uninstall Chrome mini installer. class ChromeMiniInstaller { public: ChromeMiniInstaller(const std::wstring& install_type, bool is_chrome_frame); - ~ChromeMiniInstaller() {} enum RepairChrome { @@ -46,8 +45,7 @@ class ChromeMiniInstaller { void InstallMetaInstaller(); // Installs Chrome Mini Installer. - void InstallMiniInstaller(bool over_install = false, - const std::wstring& path = L""); + void InstallMiniInstaller(bool over_install, const FilePath& path); // This will test the standalone installer. void InstallStandaloneInstaller(); @@ -111,7 +109,7 @@ class ChromeMiniInstaller { FilePath GetUserDataDirPath(); // Gets the path to launch Chrome. - bool GetChromeLaunchPath(std::wstring* launch_path); + bool GetChromeLaunchPath(FilePath* launch_path); // This method will get Chrome.exe path and launch it. void VerifyChromeLaunch(bool expected_status); @@ -131,16 +129,15 @@ class ChromeMiniInstaller { void LaunchIE(const std::wstring& navigate_url); // Launches the chrome installer and waits for it to end. - void LaunchInstaller(const std::wstring& install_path, + void LaunchInstaller(const FilePath& path, const wchar_t* process_name); // Verifies if Chrome launches after install. void LaunchAndCloseChrome(bool over_install); // Launches any requested browser. - void LaunchBrowser(const std::wstring& launch_path, - const std::wstring& launch_arg, - const std::wstring& process_name, + void LaunchBrowser(const FilePath& path, + const std::wstring& args, bool expected_status); // Compares the registry key values after overinstall. @@ -150,25 +147,25 @@ class ChromeMiniInstaller { // This method will verify if the installed build is correct. bool VerifyStandaloneInstall(); + // Get all the latest installers base on last modified date. + bool LocateInstallers(const std::wstring& build); + + // This method will create a command line to run apply tag. + CommandLine GetCommandForTagging(); + // This variable holds the install type. // Install type can be either system or user level. std::wstring install_type_; bool is_chrome_frame_; - // 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_; + FilePath full_installer_; + FilePath diff_installer_; + FilePath previous_installer_; + FilePath standalone_installer_; - // The version string of the current and previous builds. - std::wstring curr_version_, prev_version_; + // Build numbers. + std::wstring current_build_, previous_build_; DISALLOW_COPY_AND_ASSIGN(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 f108f42..e15d795 100644 --- a/chrome/test/mini_installer_test/mini_installer_test_constants.cc +++ b/chrome/test/mini_installer_test/mini_installer_test_constants.cc @@ -64,7 +64,7 @@ const wchar_t kChromeApplyTagExe[] = const wchar_t kChromeApplyTagParameters[] = L"\"appguid={8A69D345-D564-463C-AFF1-A69D9E530F96}" L"&appname=Chrome&needsadmin=false\""; -const wchar_t kChromeDiffInstallerLocation[] = +const wchar_t kChromeInstallersLocation[] = L"\\\\172.24.6.7\\shares\\chromeclient\\builds\\chrome\\"; } // namespace mini_installer_constants 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 2f9810d..ecb5502 100644 --- a/chrome/test/mini_installer_test/mini_installer_test_constants.h +++ b/chrome/test/mini_installer_test/mini_installer_test_constants.h @@ -56,7 +56,7 @@ extern const wchar_t kIEProcessName[]; // Google Chrome meta installer location. extern const wchar_t kChromeApplyTagExe[]; extern const wchar_t kChromeApplyTagParameters[]; -extern const wchar_t kChromeDiffInstallerLocation[]; +extern const wchar_t kChromeInstallersLocation[]; extern const wchar_t kChromeMetaInstallerExe[]; extern const wchar_t kChromeStandAloneInstallerLocation[]; } // namespace mini_installer_constants 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 904f556..722c701 100644 --- a/chrome/test/mini_installer_test/mini_installer_test_util.cc +++ b/chrome/test/mini_installer_test/mini_installer_test_util.cc @@ -22,6 +22,7 @@ #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" #include "testing/gtest/include/gtest/gtest.h" + // Change current directory so that chrome.dll from current folder // will not be used as fall back. bool MiniInstallerTestUtil::ChangeCurrentDirectory(FilePath* current_path) { @@ -69,196 +70,11 @@ bool IsNewer(const FileInfo& file_rbegin, const FileInfo& file_rend) { return (file_rbegin.creation_time_ > file_rend.creation_time_); } -bool MiniInstallerTestUtil::GetCommandForTagging( - std::wstring *return_command) { - std::wstring tagged_installer_path = MiniInstallerTestUtil::GetFilePath( - mini_installer_constants::kStandaloneInstaller); - FilePath standalone_installer_path; - if (!MiniInstallerTestUtil::GetStandaloneInstallerPath( - &standalone_installer_path)) { - return false; - } - - *return_command = base::StringPrintf(L"%ls %ls %ls %ls", - mini_installer_constants::kChromeApplyTagExe, - standalone_installer_path.value().c_str(), - tagged_installer_path.c_str(), - mini_installer_constants::kChromeApplyTagParameters); - VLOG(1) << "Command to run Apply tag: " << *return_command; - return true; -} - -std::wstring MiniInstallerTestUtil::GetFilePath(const wchar_t* exe_name) { +FilePath MiniInstallerTestUtil::GetFilePath(const wchar_t* exe_name) { FilePath installer_path; PathService::Get(base::DIR_EXE, &installer_path); installer_path = installer_path.Append(exe_name); - return installer_path.value(); -} - -// 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 MiniInstallerTestUtil::GetInstaller(const wchar_t* pattern, - std::wstring *path, const wchar_t* channel_type, bool chrome_frame) { - FileInfoList builds_list; - 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_); - file_util::AppendToPath(path, mini_installer_constants::kWinFolder); - std::wstring installer_path(path->c_str()); - file_util::AppendToPath(&installer_path, L"*.exe"); - if (!GetLatestFile(installer_path.c_str(), pattern, &exe_list)) { - ++builds_list_size; - } else { - file_util::AppendToPath(path, exe_list.at(0).name_.c_str()); - if (!file_util::PathExists(FilePath::FromWStringHack(*path))) { - ++builds_list_size; - } else { - break; - } - } - } - return file_util::PathExists(FilePath::FromWStringHack(*path)); -} - -// 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) { - VLOG(1) << "Handle is invalid."; - return false; - } - BOOL ret = TRUE; - bool return_val = false; - while (ret) { - std::wstring search_path = find_file_data.cFileName; - size_t position_found = search_path.find(pattern); - if (position_found != -1) { - std::wstring extension = FilePath(file_name).Extension(); - if ((base::strcasecmp(WideToUTF8(extension).c_str(), ".exe")) == 0) { - file_details->push_back(FileInfo(find_file_data.cFileName, 0)); - return_val = true; - break; - } else { - FILETIME file_time = find_file_data.ftCreationTime; - base::Time creation_time = base::Time::FromFileTime(file_time); - file_details->push_back(FileInfo(find_file_data.cFileName, - static_cast<int>(creation_time.ToDoubleT()))); - return_val = true; - } - } - ret = FindNextFile(file_handle, &find_file_data); - } - std::sort(file_details->rbegin(), file_details->rend(), &IsNewer); - FindClose(file_handle); - return return_val; -} - -// 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 = FilePath(path).BaseName().value(); - // 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().value()); - 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_path, std::wstring *previous, bool chrome_frame) { - std::wstring build_no; - - if (!GetPreviousBuildNumber(diff_path, &build_no)) - return false; - - std::vector<std::wstring> build_version; - base::SplitString(build_no, '.', &build_version); - if (build_version.size() < 4) - return false; - - std::wstring name = build_version[2] + L"." + build_version[3] + - mini_installer_constants::kFullInstallerPattern + L".exe"; - - // Create the full installer path. - FilePath installer = FilePath( - mini_installer_constants::kChromeDiffInstallerLocation); - installer = - installer.Append(build_no) - .Append(mini_installer_constants::kWinFolder).Append(name); - previous->assign(installer.value()); - - return file_util::PathExists(installer); -} - -bool MiniInstallerTestUtil::GetStandaloneInstallerPath(FilePath* path) { - const CommandLine* cmd = CommandLine::ForCurrentProcess(); - std::wstring build = - cmd->GetSwitchValueNative(switches::kInstallerTestBuild); - std::wstring standalone_installer( - mini_installer_constants::kChromeStandAloneInstallerLocation); - standalone_installer.append(L"\\" + build + L"\\win\\"); - - // Get the file name. - std::vector<std::wstring> tokenizedBuildNumber; - Tokenize(build, L".", &tokenizedBuildNumber); - std::wstring standalone_installer_filename = base::StringPrintf( - L"%ls%ls_%ls.exe", mini_installer_constants::kUntaggedInstallerPattern, - tokenizedBuildNumber[2].c_str(), tokenizedBuildNumber[3].c_str()); - standalone_installer.append(standalone_installer_filename); - - FilePath filename(standalone_installer); - if (!file_util::PathExists(filename)) - return false; - *path = filename; - return true; -} - -bool MiniInstallerTestUtil::GetStandaloneVersion( - std::wstring* version) { - const CommandLine* cmd = CommandLine::ForCurrentProcess(); - std::wstring build = - cmd->GetSwitchValueNative(switches::kInstallerTestBuild); - if (build.empty()) - return false; - *version = build; - VLOG(1) << "Standalone installer version: " << *version; - return true; + return installer_path; } void MiniInstallerTestUtil::SendEnterKeyToWindow() { @@ -297,7 +113,7 @@ bool MiniInstallerTestUtil::VerifyProcessClose( const wchar_t* process_name) { int timer = 0; if (base::GetProcessCount(process_name, NULL) > 0) { - VLOG(1) << "Waiting for this process to end: " << process_name; + LOG(INFO) << "Waiting for this process to end: " << process_name; while ((base::GetProcessCount(process_name, NULL) > 0) && (timer < TestTimeouts::large_test_timeout_ms())) { base::PlatformThread::Sleep(200); 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 df7cae7..5fbf4b3 100644 --- a/chrome/test/mini_installer_test/mini_installer_test_util.h +++ b/chrome/test/mini_installer_test/mini_installer_test_util.h @@ -10,7 +10,6 @@ #define CHROME_TEST_MINI_INSTALLER_TEST_MINI_INSTALLER_TEST_UTIL_H_ #pragma once -#include <windows.h> #include <vector> #include "base/basictypes.h" @@ -51,43 +50,8 @@ class MiniInstallerTestUtil { // 'message' to it. static bool CloseWindow(const wchar_t* window_name, UINT message); - // This method will get the latest installer based on the passed 'pattern' and - // 'channel_type' arguments. The 'pattern' argument decides if the requested - // installer is full or differential. The 'channel_type' parameter decides if - // the build is stable/dev/beta. - static bool GetInstaller(const wchar_t* pattern, std::wstring *name, - const wchar_t* channel_type, bool chrome_frame); - - // This method will create a command line to run apply tag. - static bool GetCommandForTagging(std::wstring *return_command); - // 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 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, bool chrome_frame); - - // Find stand alone installer path. - static bool GetStandaloneInstallerPath(FilePath* path); - - // This method will get the version number from the filename. - static bool GetStandaloneVersion(std::wstring* version); + static FilePath GetFilePath(const wchar_t* exe_name); // This method will send enter key to window in the foreground. static void SendEnterKeyToWindow(); diff --git a/chrome/test/mini_installer_test/test.cc b/chrome/test/mini_installer_test/test.cc index 75343db..b5b2a2a 100644 --- a/chrome/test/mini_installer_test/test.cc +++ b/chrome/test/mini_installer_test/test.cc @@ -45,8 +45,6 @@ class MiniInstallTest : public testing::Test { const CommandLine* cmd = CommandLine::ForCurrentProcess(); std::wstring build = cmd->GetSwitchValueNative(switches::kInstallerTestBuild); - if (build.empty()) - build = L"latest"; chrome_frame_ = cmd->HasSwitch(installer::switches::kChromeFrame); CleanTheSystem(); |