diff options
author | hnguyen@chromium.org <hnguyen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 01:52:47 +0000 |
---|---|---|
committer | hnguyen@chromium.org <hnguyen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-20 01:52:47 +0000 |
commit | 85630ddb424cf3e826e0aa11b20fa2c24ed8633a (patch) | |
tree | 7b83d1a9b57b57da8654d3932b8582f1f3909465 | |
parent | 6ef2f6b20e5feb4868a4d93cd4737fd523e0ff59 (diff) | |
download | chromium_src-85630ddb424cf3e826e0aa11b20fa2c24ed8633a.zip chromium_src-85630ddb424cf3e826e0aa11b20fa2c24ed8633a.tar.gz chromium_src-85630ddb424cf3e826e0aa11b20fa2c24ed8633a.tar.bz2 |
A few things in this rewrite:
1) Move test logics into the tests
2) Simplify test installer
3) Separate code to locate installers into a new class
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/8464001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115066 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/chrome_installer.gypi | 12 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/chrome_mini_installer.cc | 917 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/chrome_mini_installer.h | 162 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/installer_path_provider.cc | 249 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/installer_path_provider.h | 50 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/installer_test_util.cc | 306 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/installer_test_util.h | 88 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/mini_installer_test_util.cc | 114 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/mini_installer_test_util.h | 51 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/run_all_unittests.cc | 6 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/switch_builder.cc | 48 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/switch_builder.h | 35 | ||||
-rw-r--r-- | chrome/test/mini_installer_test/test.cc | 369 |
13 files changed, 1089 insertions, 1318 deletions
diff --git a/chrome/chrome_installer.gypi b/chrome/chrome_installer.gypi index e08ab25..9c35d6e 100644 --- a/chrome/chrome_installer.gypi +++ b/chrome/chrome_installer.gypi @@ -187,13 +187,15 @@ '<(SHARED_INTERMEDIATE_DIR)/installer_util_strings/installer_util_strings.rc', 'installer/util/installation_validation_helper.cc', 'installer/util/installation_validation_helper.h', - 'test/mini_installer_test/run_all_unittests.cc', - 'test/mini_installer_test/chrome_mini_installer.cc', - 'test/mini_installer_test/chrome_mini_installer.h', + 'test/mini_installer_test/installer_path_provider.cc', + 'test/mini_installer_test/installer_path_provider.h', + 'test/mini_installer_test/installer_test_util.cc', + 'test/mini_installer_test/installer_test_util.h', 'test/mini_installer_test/mini_installer_test_constants.cc', 'test/mini_installer_test/mini_installer_test_constants.h', - 'test/mini_installer_test/mini_installer_test_util.cc', - 'test/mini_installer_test/mini_installer_test_util.h', + 'test/mini_installer_test/run_all_unittests.cc', + 'test/mini_installer_test/switch_builder.cc', + 'test/mini_installer_test/switch_builder.h', 'test/mini_installer_test/test.cc', ], 'msvs_settings': { diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.cc b/chrome/test/mini_installer_test/chrome_mini_installer.cc deleted file mode 100644 index e100368..0000000 --- a/chrome/test/mini_installer_test/chrome_mini_installer.cc +++ /dev/null @@ -1,917 +0,0 @@ -// 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. - -#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" -#include "base/process.h" -#include "base/process_util.h" -#include "base/string_number_conversions.h" -#include "base/string_util.h" -#include "base/stringprintf.h" -#include "base/threading/platform_thread.h" -#include "base/win/registry.h" -#include "chrome/installer/util/google_update_constants.h" -#include "chrome/installer/util/helper.h" -#include "chrome/installer/util/install_util.h" -#include "chrome/installer/util/installation_validation_helper.h" -#include "chrome/installer/util/util_constants.h" -#include "chrome/test/base/chrome_process_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" - -using base::win::RegKey; -using installer::InstallationValidator; - -namespace { - -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 std::string& pattern, - file_util::FileEnumerator::FileType type, - std::vector<FilePath>* paths) { - file_util::FileEnumerator files(root, false, type, - FilePath().AppendASCII(pattern).value()); - 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; - - 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; -} - -bool FindNewestMatchingFile(const FilePath& root, - const std::string& pattern, - file_util::FileEnumerator::FileType type, - FilePath* path) { - std::vector<FilePath> paths; - if (FindMatchingFiles(root, pattern, type, &paths)) { - *path = paths[0]; - return true; - } - return false; -} -} // namespace - -ChromeMiniInstaller::ChromeMiniInstaller(bool system_install, - bool is_chrome_frame, - const std::string& build) - : is_chrome_frame_(is_chrome_frame), - system_install_(system_install), - build_(build) { - FilePath full_installer; - FilePath previous_installer; - if (!GetFullInstaller(&full_installer) || - !GetPreviousInstaller(&previous_installer)) - return; - current_build_ = - full_installer.DirName().DirName().BaseName().MaybeAsASCII(); - previous_build_ = - previous_installer.DirName().DirName().BaseName().MaybeAsASCII(); -} - -// Installs Chrome. -void ChromeMiniInstaller::Install() { - FilePath mini_installer; - ASSERT_TRUE(GetMiniInstaller(&mini_installer)); - InstallMiniInstaller(false, mini_installer); -} - -// 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, bool should_start_ie) { - FilePath full_installer; - FilePath diff_installer; - FilePath previous_installer; - ASSERT_TRUE(GetFullInstaller(&full_installer) && - GetDiffInstaller(&diff_installer) && - GetPreviousInstaller(&previous_installer)); - - if (should_start_ie) - LaunchIE(L"http://www.google.com"); - - InstallMiniInstaller(false, previous_installer); - - std::string got_prev_version; - ASSERT_TRUE(GetChromeVersionFromRegistry(&got_prev_version)); - - std::string expected_version; - if (install_type == mini_installer_constants::kDiffInstall) { - LOG(INFO) << "Over installing with latest differential installer: " - << diff_installer.value(); - expected_version = current_diff_build_; - InstallMiniInstaller(true, diff_installer); - - } else if (install_type == mini_installer_constants::kFullInstall) { - LOG(INFO) << "Over installing with latest full installer: " - << full_installer.value(); - expected_version = current_build_; - InstallMiniInstaller(true, full_installer); - } - - std::string got_curr_version; - ASSERT_TRUE(GetChromeVersionFromRegistry(&got_curr_version)); - - if (got_prev_version == previous_build_ && - got_curr_version == expected_version) { - LOG(INFO) << "The over install was successful.\n" - << "Previously installed version: " << got_prev_version; - LOG(INFO) << "Currently installed: " << expected_version; - } else { - LOG(INFO) << "The over install was not successful.\n" - << "Expected previous version: " << previous_build_; - LOG(INFO) << "Actual previous version: " << got_prev_version; - LOG(INFO) << "Expected new version: " << expected_version - << "\nActual new version: " << got_curr_version; - FAIL(); - } -} - -// This method will get the latest full installer from nightly location -// and installs it. -void ChromeMiniInstaller::InstallFullInstaller(bool over_install) { - FilePath full_installer; - ASSERT_TRUE(GetFullInstaller(&full_installer)); - InstallMiniInstaller(over_install, full_installer); -} - -// Installs the Chrome mini-installer, checks the registry and shortcuts. -void ChromeMiniInstaller::InstallMiniInstaller(bool over_install, - const FilePath& path) { - LOG(INFO) << "Install level is: " - << (system_install_ ? "system" : "user"); - ASSERT_TRUE(file_util::PathExists(path)); - CommandLine installer(path); - if (is_chrome_frame_) { - installer.AppendSwitch(installer::switches::kDoNotCreateShortcuts); - installer.AppendSwitch(installer::switches::kDoNotLaunchChrome); - installer.AppendSwitch(installer::switches::kDoNotRegisterForUpdateLaunch); - installer.AppendSwitch(installer::switches::kChromeFrame); - } - RunInstaller(installer); - std::string version; - ASSERT_TRUE(GetChromeVersionFromRegistry(&version)) - << "Install failed: unable to get version."; - VerifyInstall(over_install); -} - -CommandLine ChromeMiniInstaller::GetBaseMultiInstallCommand() { - FilePath mini_installer; - if (!GetMiniInstaller(&mini_installer)) - return CommandLine(CommandLine::NO_PROGRAM); - CommandLine cmd(mini_installer); - cmd.AppendSwitch(installer::switches::kMultiInstall); - return cmd; -} - -void ChromeMiniInstaller::InstallChromeUsingMultiInstall() { - CommandLine cmd = GetBaseMultiInstallCommand(); - cmd.AppendSwitch(installer::switches::kChrome); - RunInstaller(cmd); - - // Verify installation. - InstallationValidator::InstallationType type; - InstallationValidator::ValidateInstallationType(system_install_, &type); - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - ASSERT_TRUE(InstallUtil::IsMultiInstall(dist, system_install_)); - EXPECT_TRUE(type & InstallationValidator::ProductBits::CHROME_MULTI); - FindChromeShortcut(); - LaunchChrome(true); -} - -void ChromeMiniInstaller::InstallChromeFrameUsingMultiInstall() { - CommandLine cmd = GetBaseMultiInstallCommand(); - cmd.AppendSwitch(installer::switches::kDoNotCreateShortcuts); - cmd.AppendSwitch(installer::switches::kDoNotLaunchChrome); - cmd.AppendSwitch(installer::switches::kDoNotRegisterForUpdateLaunch); - cmd.AppendSwitch(installer::switches::kChromeFrame); - RunInstaller(cmd); - - // Verify installation. - InstallationValidator::InstallationType type = - installer::ExpectValidInstallation(system_install_); - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - ASSERT_TRUE(InstallUtil::IsMultiInstall(dist, system_install_)); - EXPECT_TRUE(type & InstallationValidator::ProductBits::CHROME_FRAME_MULTI); - // Launch IE - LaunchIE(L"gcf:about:version"); - if (system_install_) { - MiniInstallerTestUtil::VerifyProcessLaunch(installer::kChromeExe, true); - } else { - MiniInstallerTestUtil::VerifyProcessLaunch( - installer::kChromeFrameHelperExe, true); - } - FindChromeShortcut(); -} - -void ChromeMiniInstaller::InstallChromeAndChromeFrame(bool ready_mode) { - CommandLine cmd = GetBaseMultiInstallCommand(); - cmd.AppendSwitch(installer::switches::kChrome); - cmd.AppendSwitch(installer::switches::kChromeFrame); - if (ready_mode) - cmd.AppendSwitch(installer::switches::kChromeFrameReadyMode); - RunInstaller(cmd); - // Verify installation. - InstallationValidator::InstallationType type = - installer::ExpectValidInstallation(system_install_); - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - ASSERT_TRUE(InstallUtil::IsMultiInstall(dist, system_install_)); - EXPECT_TRUE(type & InstallationValidator::ProductBits::CHROME_MULTI); - if (ready_mode) { - EXPECT_TRUE(type & - InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE); - } - FindChromeShortcut(); - LaunchChrome(true); - LaunchIE(L"gcf:about:version"); - // Check if Chrome process got spawned. - MiniInstallerTestUtil::VerifyProcessLaunch(L"chrome_frame.exe", false); -} - -// This method tests the standalone installer by verifying the steps listed at: -// https://sites.google.com/a/google.com/chrome-pmo/ -// standalone-installers/testing-standalone-installers -// This method applies appropriate tags to standalone installer and deletes -// old installer before running the new tagged installer. It also verifies -// that the installed version is correct. -void ChromeMiniInstaller::InstallStandaloneInstaller() { - file_util::Delete(mini_installer_constants::kStandaloneInstaller, true); - 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); - 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); - FilePath standalone_installer; - if (!GetStandaloneInstaller(&standalone_installer)) - 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. - CommandLine installer(FilePath::FromWStringHack( - mini_installer_constants::kChromeMetaInstallerExe)); - ASSERT_TRUE(file_util::PathExists(installer.GetProgram())); - if (is_chrome_frame_) { - installer.AppendSwitch(installer::switches::kDoNotCreateShortcuts); - installer.AppendSwitch(installer::switches::kDoNotLaunchChrome); - installer.AppendSwitch(installer::switches::kDoNotRegisterForUpdateLaunch); - installer.AppendSwitch(installer::switches::kChromeFrame); - } - RunInstaller(installer); - - ASSERT_TRUE(MiniInstallerTestUtil::VerifyProcessClose( - mini_installer_constants::kChromeMetaInstallerExecutable)); - - std::wstring chrome_google_update_state_key( - google_update::kRegPathClients); - chrome_google_update_state_key.append(L"\\"); - - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - chrome_google_update_state_key.append(dist->GetAppGuid()); - - ASSERT_TRUE(CheckRegistryKey(chrome_google_update_state_key)); - ASSERT_TRUE(CheckRegistryKey(dist->GetVersionKey())); - FindChromeShortcut(); - LaunchChrome(true); -} - -// 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() { - InstallMetaInstaller(); - std::string reg_key_value_returned; - // gets the registry key value before overinstall. - ASSERT_TRUE(GetChromeVersionFromRegistry(®_key_value_returned)); - printf("\n\nPreparing to overinstall...\n"); - InstallFullInstaller(true); - std::string reg_key_value_after_overinstall; - // Get the registry key value after over install - ASSERT_TRUE(GetChromeVersionFromRegistry(®_key_value_after_overinstall)); - ASSERT_TRUE(VerifyOverInstall(reg_key_value_returned, - reg_key_value_after_overinstall)); -} - -// This method will first install Chrome. Deletes either registry or -// folder based on the passed argument, then tries to launch Chrome. -// Then installs Chrome again to repair. -void ChromeMiniInstaller::Repair( - ChromeMiniInstaller::RepairChrome repair_type) { - InstallFullInstaller(false); - if (is_chrome_frame_) { - MiniInstallerTestUtil::CloseProcesses( - mini_installer_constants::kIEProcessName); - } else { - MiniInstallerTestUtil::CloseProcesses(installer::kNaClExe); - } - MiniInstallerTestUtil::CloseProcesses(installer::kChromeExe); - if (repair_type == ChromeMiniInstaller::VERSION_FOLDER) { - std::string build_number; - ASSERT_TRUE(GetChromeVersionFromRegistry(&build_number)); - FilePath install_path; - ASSERT_TRUE(GetInstallDirectory(&install_path)); - install_path = install_path.AppendASCII(build_number); - ASSERT_TRUE(file_util::Delete(install_path, true)); - } else if (repair_type == ChromeMiniInstaller::REGISTRY) { - DeletePvRegistryKey(); - printf("Deleted registry. Now trying to launch chrome\n"); - } - FilePath current_path; - ASSERT_TRUE(MiniInstallerTestUtil::ChangeCurrentDirectory(¤t_path)); - LaunchChrome(false); - LOG(INFO) << "Installing Chrome again to see if it can be repaired."; - InstallFullInstaller(true); - LOG(INFO) << "Chrome repair successful."; - // Set the current directory back to original path. - file_util::SetCurrentDirectory(current_path); -} - -// This method first checks if Chrome is running. -// If yes, will close all the processes. -// Then will find and spawn uninstall path. -// Handles uninstall confirm dialog. -// Waits until setup.exe ends. -// Checks if registry key exist even after uninstall. -// Deletes App dir. -// Closes feedback form. -void ChromeMiniInstaller::UnInstall() { - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - std::string version; - std::string result; - - if (!GetChromeVersionFromRegistry(&version)) - return; - - // Attempt to kill all Chrome/Chrome Frame related processes. - MiniInstallerTestUtil::CloseProcesses( - mini_installer_constants::kIEProcessName); - MiniInstallerTestUtil::CloseProcesses(installer::kNaClExe); - MiniInstallerTestUtil::CloseProcesses(installer::kChromeExe); - // Get uninstall command. - CommandLine cmd = InstallUtil::GetChromeUninstallCmd( - system_install_, dist->GetType()); - ASSERT_TRUE(file_util::PathExists(cmd.GetProgram())) - << "Uninstall executable does not exist."; - - cmd.AppendSwitch(installer::switches::kForceUninstall); - LOG(INFO) << "Uninstall command: " << cmd.GetCommandLineString(); - - base::ProcessHandle setup_handle; - ASSERT_TRUE(base::LaunchProcess(cmd, base::LaunchOptions(), &setup_handle)) - << "Failed to launch uninstall command."; - - LOG(INFO) << (CloseUninstallWindow() ? "Succeeded " : "Failed ") - << "in attempt to closed uninstall window."; - ASSERT_TRUE(MiniInstallerTestUtil::VerifyProcessHandleClosed(setup_handle)); - ASSERT_FALSE(CheckRegistryKeyOnUninstall(dist->GetVersionKey())) - << "It appears Chrome was not completely uninstalled."; - - DeleteUserDataFolder(); - // Close IE survey window that gets launched on uninstall. - MiniInstallerTestUtil::CloseProcesses( - mini_installer_constants::kIEExecutable); -} - -void ChromeMiniInstaller::UnInstallChromeFrameWithIERunning() { - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - std::wstring product_name = - mini_installer_constants::kChromeFrameProductName; - if (!CheckRegistryKey(dist->GetVersionKey())) { - printf("%ls is not installed.\n", product_name.c_str()); - return; - } - - MiniInstallerTestUtil::CloseProcesses(installer::kChromeExe); - - CommandLine cmd = InstallUtil::GetChromeUninstallCmd( - system_install_, dist->GetType()); - - if (cmd.GetProgram().empty()) { - LOG(ERROR) << "Unable to get uninstall command."; - CleanChromeInstall(); - } - - ASSERT_TRUE(file_util::PathExists(cmd.GetProgram())); - - cmd.AppendSwitch(installer::switches::kUninstall); - cmd.AppendSwitch(installer::switches::kForceUninstall); - cmd.AppendSwitch(installer::switches::kChromeFrame); - - if (system_install_) - cmd.AppendSwitch(installer::switches::kSystemLevel); - - base::ProcessHandle setup_handle; - base::LaunchProcess(cmd, base::LaunchOptions(), &setup_handle); - - ASSERT_TRUE(CloseUninstallWindow()); - ASSERT_TRUE(MiniInstallerTestUtil::VerifyProcessHandleClosed(setup_handle)); - ASSERT_FALSE(CheckRegistryKeyOnUninstall(dist->GetVersionKey())); - - DeleteUserDataFolder(); - MiniInstallerTestUtil::CloseProcesses( - mini_installer_constants::kIEProcessName); -} - -// Will clean up the machine if Chrome install is messed up. -void ChromeMiniInstaller::CleanChromeInstall() { - DeletePvRegistryKey(); - FilePath install_path; - ASSERT_TRUE(GetInstallDirectory(&install_path)); - ASSERT_TRUE(file_util::Delete(install_path, true)); -} - -bool ChromeMiniInstaller::CloseUninstallWindow() { - HWND hndl = NULL; - int timer = 0; - std::wstring window_name; - if (is_chrome_frame_) - window_name = mini_installer_constants::kChromeFrameAppName; - else - window_name = mini_installer_constants::kChromeUninstallDialogName; - while (hndl == NULL && timer < 5000) { - hndl = FindWindow(NULL, window_name.c_str()); - base::PlatformThread::Sleep(200); - timer = timer + 200; - } - - if (!is_chrome_frame_) { - if (hndl == NULL) - hndl = FindWindow(NULL, mini_installer_constants::kChromeBuildType); - - if (hndl == NULL) - return false; - - SetForegroundWindow(hndl); - MiniInstallerTestUtil::SendEnterKeyToWindow(); - } - return true; -} - -// Closes Chrome browser. -bool ChromeMiniInstaller::CloseChromeBrowser() { - int timer = 0; - HWND handle = NULL; - // This loop iterates through all of the top-level Windows - // named Chrome_WidgetWin_0 and closes them - while ((base::GetProcessCount(installer::kChromeExe, NULL) > 0) && - (timer < 40000)) { - // Chrome may have been launched, but the window may not have appeared - // yet. Wait for it to appear for 10 seconds, but exit if it takes longer - // than that. - while (!handle && timer < 10000) { - handle = FindWindowEx(NULL, handle, L"Chrome_WidgetWin_0", NULL); - if (!handle) { - base::PlatformThread::Sleep(100); - timer = timer + 100; - } - } - if (!handle) - return false; - SetForegroundWindow(handle); - LRESULT _result = SendMessage(handle, WM_CLOSE, 1, 0); - if (_result != 0) - return false; - base::PlatformThread::Sleep(1000); - timer = timer + 1000; - } - if (base::GetProcessCount(installer::kChromeExe, NULL) > 0) { - printf("Chrome.exe is still running even after closing all windows\n"); - return false; - } - if (base::GetProcessCount(installer::kNaClExe, NULL) > 0) { - printf("NaCl.exe is still running even after closing all windows\n"); - return false; - } - return true; -} - -// Checks for Chrome registry keys. -bool ChromeMiniInstaller::CheckRegistryKey(const std::wstring& key_path) { - RegKey key; - LONG ret = key.Open(GetRootRegistryKey(), key_path.c_str(), KEY_ALL_ACCESS); - if (ret != ERROR_SUCCESS) { - printf("Cannot open reg key. error: %d\n", ret); - return false; - } - std::string reg_key_value_returned; - if (!GetChromeVersionFromRegistry(®_key_value_returned)) - return false; - return true; -} - -// Checks for Chrome registry keys on uninstall. -bool ChromeMiniInstaller::CheckRegistryKeyOnUninstall( - const std::wstring& key_path) { - RegKey key; - int timer = 0; - while ((key.Open(GetRootRegistryKey(), key_path.c_str(), - KEY_ALL_ACCESS) == ERROR_SUCCESS) && - (timer < 20000)) { - base::PlatformThread::Sleep(200); - timer = timer + 200; - } - return CheckRegistryKey(key_path); -} - -// Will delete user data profile. -void ChromeMiniInstaller::DeleteUserDataFolder() { - FilePath path = GetUserDataDirPath(); - if (file_util::PathExists(path)) - ASSERT_TRUE(file_util::Delete(path, true)); -} - -// Gets user data directory path -FilePath ChromeMiniInstaller::GetUserDataDirPath() { - FilePath path; - PathService::Get(base::DIR_LOCAL_APP_DATA, &path); - FilePath profile_path = path; - if (is_chrome_frame_) { - profile_path = profile_path.Append( - mini_installer_constants::kChromeFrameAppDir); - } else { - profile_path = profile_path.Append( - mini_installer_constants::kChromeAppDir); - } - profile_path = profile_path.DirName(); - profile_path = profile_path.Append( - mini_installer_constants::kChromeUserDataDir); - return profile_path; -} - -// Deletes pv key from Clients. -void ChromeMiniInstaller::DeletePvRegistryKey() { - std::wstring pv_key(google_update::kRegPathClients); - pv_key.append(L"\\"); - - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - pv_key.append(dist->GetAppGuid()); - - RegKey key; - if (key.Open(GetRootRegistryKey(), pv_key.c_str(), KEY_ALL_ACCESS) == - ERROR_SUCCESS) - ASSERT_EQ(ERROR_SUCCESS, key.DeleteValue(L"pv")); - printf("Deleted %ls key\n", pv_key.c_str()); -} - -// Verifies if Chrome shortcut exists. -void ChromeMiniInstaller::FindChromeShortcut() { - bool return_val = false; - FilePath uninstall_lnk; - FilePath path = GetStartMenuShortcutPath(); - path = path.Append(mini_installer_constants::kChromeBuildType); - // Verify if path exists. - if (file_util::PathExists(path)) { - return_val = true; - uninstall_lnk = path; - path = path.Append(mini_installer_constants::kChromeLaunchShortcut); - uninstall_lnk = uninstall_lnk.Append( - mini_installer_constants::kChromeUninstallShortcut); - ASSERT_TRUE(file_util::PathExists(path)); - ASSERT_TRUE(file_util::PathExists(uninstall_lnk)); - } - if (return_val) { - LOG(INFO) << "Found Chrome shortcuts:\n" - << path.value() << "\n" - << uninstall_lnk.value(); - } else { - LOG(INFO) << "No Chrome shortcuts found."; - } -} - -bool ChromeMiniInstaller::GetInstallDirectory(FilePath* path) { - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - *path = installer::GetChromeInstallPath(system_install_, dist); - FilePath parent; - if (system_install_) { - PathService::Get(base::DIR_PROGRAM_FILES, &parent); - return file_util::ContainsPath(parent, *path); - } else { - PathService::Get(base::DIR_LOCAL_APP_DATA, &parent); - return file_util::ContainsPath(parent, *path); - } -} - -FilePath ChromeMiniInstaller::GetStartMenuShortcutPath() { - FilePath path_name; - if (system_install_) - PathService::Get(base::DIR_COMMON_START_MENU, &path_name); - else - PathService::Get(base::DIR_START_MENU, &path_name); - return path_name; -} - -bool ChromeMiniInstaller::GetChromeVersionFromRegistry(std::string* value) { - BrowserDistribution* dist = GetCurrentBrowserDistribution(); - scoped_ptr<Version> version( - InstallUtil::GetChromeVersion(dist, system_install_)); - if (!version.get()) - return false; - *value = version->GetString(); - return !value->empty(); -} - -// Get HKEY based on install type. -HKEY ChromeMiniInstaller::GetRootRegistryKey() { - HKEY type = HKEY_CURRENT_USER; - if (system_install_) - type = HKEY_LOCAL_MACHINE; - return type; -} - -void ChromeMiniInstaller::RunInstaller(const CommandLine& command) { - ASSERT_TRUE(file_util::PathExists(command.GetProgram())); - CommandLine installer(command); - if (system_install_) { - installer.AppendSwitch(installer::switches::kSystemLevel); - } - - LOG(INFO) << "Running installer command: " - << installer.GetCommandLineString(); - base::ProcessHandle app_handle; - ASSERT_TRUE( - base::LaunchProcess(installer, base::LaunchOptions(), &app_handle)) - << "Installer failed."; - ASSERT_TRUE(base::WaitForSingleProcess(app_handle, 60 * 1000)) - << "Installer did not complete."; -} - -void ChromeMiniInstaller::LaunchChrome(bool kill) { - MiniInstallerTestUtil::CloseProcesses(installer::kChromeExe); - - FilePath install_path; - ASSERT_TRUE(GetInstallDirectory(&install_path)); - install_path = install_path.Append(installer::kChromeExe); - CommandLine browser(install_path); - - FilePath exe = browser.GetProgram(); - LOG(INFO) << "Browser launch command: " << browser.GetCommandLineString(); - base::ProcessHandle chrome; - ASSERT_TRUE(base::LaunchProcess(browser, base::LaunchOptions(), &chrome)) - << "Could not launch process: " << exe.value(); - - if (kill) { - ASSERT_TRUE(base::KillProcess(chrome, 0, true)) - << "Failed to kill chrome.exe"; - } -} - -// Verifies Chrome/Chrome Frame install. -void ChromeMiniInstaller::VerifyInstall(bool over_install) { - InstallationValidator::InstallationType type = - installer::ExpectValidInstallation(system_install_); - if (is_chrome_frame_) { - EXPECT_NE(0, - type & InstallationValidator::ProductBits::CHROME_FRAME_SINGLE); - } else { - EXPECT_NE(0, type & InstallationValidator::ProductBits::CHROME_SINGLE); - } - - if (is_chrome_frame_) - VerifyChromeFrameInstall(); - else if (!system_install_ && !over_install) - MiniInstallerTestUtil::VerifyProcessLaunch(installer::kChromeExe, true); - - base::PlatformThread::Sleep(800); - FindChromeShortcut(); - LaunchChrome(true); -} - -// This method will verify if ChromeFrame installed successfully. It will -// launch IE with cf:about:version, then check if -// chrome.exe process got spawned. -void ChromeMiniInstaller::VerifyChromeFrameInstall() { - // Launch IE - LaunchIE(L"gcf:about:version"); - - // Check if Chrome process got spawned. - MiniInstallerTestUtil::VerifyProcessLaunch(installer::kChromeExe, true); -} - -void ChromeMiniInstaller::LaunchIE(const std::wstring& navigate_url) { - FilePath browser_path; - PathService::Get(base::DIR_PROGRAM_FILES, &browser_path); - browser_path = browser_path.Append(mini_installer_constants::kIELocation); - browser_path = browser_path.Append(mini_installer_constants::kIEProcessName); - - CommandLine cmd_line(browser_path); - cmd_line.AppendArgNative(navigate_url); - ASSERT_TRUE(base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL)); -} - -// This method compares the registry keys after overinstall. -bool ChromeMiniInstaller::VerifyOverInstall( - const std::string& value_before_overinstall, - const std::string& value_after_overinstall) { - int64 reg_key_value_before_overinstall; - base::StringToInt64(value_before_overinstall, - ®_key_value_before_overinstall); - int64 reg_key_value_after_overinstall; - base::StringToInt64(value_after_overinstall, - ®_key_value_after_overinstall); - - // Compare to see if the version is less. - LOG(INFO) << "Reg Key value before overinstall is: " - << value_before_overinstall; - LOG(INFO) << "Reg Key value after overinstall is: " - << value_after_overinstall; - if (reg_key_value_before_overinstall > reg_key_value_after_overinstall) { - LOG(ERROR) << "FAIL: Overinstalled a lower version of Chrome."; - return false; - } - return true; -} - -// This method will verify if the installed build is correct. -bool ChromeMiniInstaller::VerifyStandaloneInstall() { - std::string reg_key_value_returned; - if (!GetChromeVersionFromRegistry(®_key_value_returned)) - return false; - if (current_build_.compare(reg_key_value_returned) == 0) - return true; - else - return false; -} - -BrowserDistribution* ChromeMiniInstaller::GetCurrentBrowserDistribution() { - return BrowserDistribution::GetSpecificDistribution( - is_chrome_frame_ ? - BrowserDistribution::CHROME_FRAME : - BrowserDistribution::CHROME_BROWSER); -} - -bool ChromeMiniInstaller::GetFullInstaller(FilePath* path) { - std::string full_installer_pattern("*_chrome_installer*"); - return GetInstaller(full_installer_pattern, path); -} - -bool ChromeMiniInstaller::GetDiffInstaller(FilePath* path) { - std::string diff_installer_pattern("*_from_*"); - bool retval = GetInstaller(diff_installer_pattern, path); - if (retval) - current_diff_build_ = path->DirName().DirName().BaseName().MaybeAsASCII(); - return retval; -} - -bool ChromeMiniInstaller::GetMiniInstaller(FilePath* path) { - // Use local copy of installer, else fall back to filer. - FilePath mini_installer = MiniInstallerTestUtil::GetFilePath( - mini_installer_constants::kChromeMiniInstallerExecutable); - if (file_util::PathExists(mini_installer)) { - *path = mini_installer; - return true; - } - std::string mini_installer_pattern("mini_installer.exe"); - return GetInstaller(mini_installer_pattern, path); -} - -bool ChromeMiniInstaller::GetPreviousInstaller(FilePath* path) { - std::string diff_installer_pattern("*_from_*"); - std::string full_installer_pattern("*_chrome_installer*"); - FilePath diff_installer; - if (!GetInstaller(diff_installer_pattern, &diff_installer)) - return false; - - FilePath previous_installer; - std::vector<std::string> tokenized_name; - Tokenize(diff_installer.BaseName().MaybeAsASCII(), - "_", &tokenized_name); - std::string build_pattern = base::StringPrintf( - "*%s", 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; - *path = previous_installer; - return true; -} - -bool ChromeMiniInstaller::GetStandaloneInstaller(FilePath* path) { - // Get standalone installer. - FilePath standalone_installer( - mini_installer_constants::kChromeStandAloneInstallerLocation); - - // Get the file name. - std::vector<std::string> tokenizedBuildNumber; - Tokenize(current_build_, ".", &tokenizedBuildNumber); - std::string standalone_installer_filename = base::StringPrintf( - "%s%s_%s.exe", - FilePath(mini_installer_constants::kUntaggedInstallerPattern) - .MaybeAsASCII().c_str(), - tokenizedBuildNumber[2].c_str(), - tokenizedBuildNumber[3].c_str()); - standalone_installer = standalone_installer.AppendASCII(current_build_) - .Append(mini_installer_constants::kWinFolder) - .AppendASCII(standalone_installer_filename); - *path = standalone_installer; - return file_util::PathExists(standalone_installer); -} - -bool ChromeMiniInstaller::GetInstaller(const std::string& pattern, - FilePath* path) { - FilePath installer; - - // Search directory where current exe is located. - FilePath dir_exe; - if (PathService::Get(base::DIR_EXE, &dir_exe) && - FindNewestMatchingFile(dir_exe, pattern, - file_util::FileEnumerator::FILES, &installer)) { - *path = installer; - return true; - } - // Fall back to filer. - FilePath root(mini_installer_constants::kChromeInstallersLocation); - std::vector<FilePath> paths; - if (!FindMatchingFiles(root, build_, - file_util::FileEnumerator::DIRECTORIES, &paths)) { - return false; - } - - 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, pattern, - file_util::FileEnumerator::FILES, &installer)) { - break; - } - } - - if (installer.empty()) { - LOG(WARNING) << "Failed to find installer with pattern: " << pattern; - return false; - } - - *path = installer; - return true; -} diff --git a/chrome/test/mini_installer_test/chrome_mini_installer.h b/chrome/test/mini_installer_test/chrome_mini_installer.h deleted file mode 100644 index 1972c2b..0000000 --- a/chrome/test/mini_installer_test/chrome_mini_installer.h +++ /dev/null @@ -1,162 +0,0 @@ -// 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. - -#ifndef CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H_ -#define CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H_ -#pragma once - -#include <windows.h> -#include <string> - -#include "base/basictypes.h" -#include "base/file_path.h" -#include "base/command_line.h" -#include "chrome/installer/util/browser_distribution.h" - -// This class has methods to install and uninstall Chrome mini installer. -class ChromeMiniInstaller { - public: - ChromeMiniInstaller(bool system_install, - bool is_chrome_frame, const std::string& build); - ~ChromeMiniInstaller() {} - - enum RepairChrome { - REGISTRY, - VERSION_FOLDER - }; - - // Get the location at which Chrome or Chrome Frame is installed. - bool GetInstallDirectory(FilePath* path); - - // Get the base multi-install command. - CommandLine GetBaseMultiInstallCommand(); - - // Installs the latest full installer. - void InstallFullInstaller(bool over_install); - - void InstallChromeUsingMultiInstall(); - void InstallChromeFrameUsingMultiInstall(); - void InstallChromeAndChromeFrame(bool ready_mode); - - // Installs chrome. - void Install(); - - // This method will first install the full installer and - // then over installs with diff installer. If |should_start_ie| is true, - // start IE browser before launch installer, and leave the process running - // through the installtions. - void OverInstallOnFullInstaller(const std::wstring& install_type, - bool should_start_ie); - - // Installs Google Chrome through meta installer. - void InstallMetaInstaller(); - - // Installs Chrome Mini Installer. - void InstallMiniInstaller(bool over_install, const FilePath& path); - - // This will test the standalone installer. - void InstallStandaloneInstaller(); - - // Repairs Chrome based on the passed argument. - void Repair(RepairChrome repair_type); - - // Uninstalls Chrome. - void UnInstall(); - - // This method uninstalls Chrome Frame without closing IE browser first. - // IE browser should be running before this method is called. - void UnInstallChromeFrameWithIERunning(); - - // This method will perform a over install - void OverInstall(); - - // Launch Chrome, assert process started. - // If |kill|, kill process after launch. - void LaunchChrome(bool kill); - - private: - // Will clean up the machine if Chrome install is messed up. - void CleanChromeInstall(); - - // Closes Chrome uninstall confirm dialog window. - bool CloseUninstallWindow(); - - // Closes Chrome browser. - bool CloseChromeBrowser(); - - // Checks for registry key. - bool CheckRegistryKey(const std::wstring& key_path); - - // Checks for registry key on uninstall. - bool CheckRegistryKeyOnUninstall(const std::wstring& key_path); - - // Will delete user data profile. - void DeleteUserDataFolder(); - - // This will delete pv key from client registry. - void DeletePvRegistryKey(); - - // This method verifies Chrome shortcut. - void FindChromeShortcut(); - - // Get HKEY based on install type. - HKEY GetRootRegistryKey(); - - // Returns Chrome pv registry key value. - bool GetChromeVersionFromRegistry(std::string* value); - - // This method gets the shortcut path from start menu based on install type. - FilePath GetStartMenuShortcutPath(); - - // Get user data directory path. - FilePath GetUserDataDirPath(); - - // This method verifies if Chrome/Chrome Frame installed correctly. - void VerifyInstall(bool over_install); - - // This method will verify if ChromeFrame got successfully installed on the - // machine. - void VerifyChromeFrameInstall(); - - // Launch IE with |navigate_url|. - void LaunchIE(const std::wstring& navigate_url); - - // Run installer with given |command|. If installer is - // system level append "--system-level" flag. - void RunInstaller(const CommandLine& command); - - // Compares the registry key values after overinstall. - bool VerifyOverInstall(const std::string& reg_key_value_before_overinstall, - const std::string& reg_key_value_after_overinstall); - - // This method will verify if the installed build is correct. - bool VerifyStandaloneInstall(); - - // This method will create a command line to run apply tag. - CommandLine GetCommandForTagging(); - - bool GetFullInstaller(FilePath* path); - bool GetDiffInstaller(FilePath* path); - bool GetMiniInstaller(FilePath* path); - bool GetPreviousInstaller(FilePath* path); - bool GetStandaloneInstaller(FilePath* path); - bool GetInstaller(const std::string& pattern, FilePath* path); - - // Get current browser distribution. - BrowserDistribution* GetCurrentBrowserDistribution(); - - // If true install system level. Otherwise install user level. - bool system_install_; - - bool is_chrome_frame_; - - // Build under test. - std::string build_; - // Build numbers. - std::string current_build_, current_diff_build_, previous_build_; - - DISALLOW_COPY_AND_ASSIGN(ChromeMiniInstaller); -}; - -#endif // CHROME_TEST_MINI_INSTALLER_TEST_CHROME_MINI_INSTALLER_H_ diff --git a/chrome/test/mini_installer_test/installer_path_provider.cc b/chrome/test/mini_installer_test/installer_path_provider.cc new file mode 100644 index 0000000..5ad8d05 --- /dev/null +++ b/chrome/test/mini_installer_test/installer_path_provider.cc @@ -0,0 +1,249 @@ +// 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. + +#include "chrome/test/mini_installer_test/installer_path_provider.h" + +#include <algorithm> + +#include "base/command_line.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/process_util.h" +#include "base/string_util.h" +#include "base/stringprintf.h" +#include "chrome/test/mini_installer_test/mini_installer_test_constants.h" +#include "chrome/test/mini_installer_test/installer_test_util.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +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 std::string& pattern, + file_util::FileEnumerator::FileType type, + std::vector<FilePath>* paths) { + file_util::FileEnumerator files(root, false, type, + FilePath().AppendASCII(pattern).value()); + 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; + + 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; +} + +bool FindNewestMatchingFile(const FilePath& root, + const std::string& pattern, + file_util::FileEnumerator::FileType type, + FilePath* path) { + std::vector<FilePath> paths; + if (FindMatchingFiles(root, pattern, type, &paths)) { + *path = paths[0]; + return true; + } + return false; +} + +} // namespace + +namespace installer_test { + +InstallerPathProvider::InstallerPathProvider() { + FilePath full_installer, previous_installer; + if (!GetFullInstaller(&full_installer) || + !GetPreviousInstaller(&previous_installer)) + return; + current_build_ = + full_installer.DirName().DirName().BaseName().MaybeAsASCII(); + previous_build_ = + previous_installer.DirName().DirName().BaseName().MaybeAsASCII(); +} + +InstallerPathProvider::InstallerPathProvider( + const std::string& build_under_test) : current_build_(build_under_test) { + FilePath full_installer, previous_installer; + if (!GetFullInstaller(&full_installer) || + !GetPreviousInstaller(&previous_installer)) + return; + previous_build_ = + previous_installer.DirName().DirName().BaseName().MaybeAsASCII(); +} + +InstallerPathProvider::~InstallerPathProvider() {} + +bool InstallerPathProvider::GetFullInstaller(FilePath* path) { + std::string full_installer_pattern("*_chrome_installer*"); + return GetInstaller(full_installer_pattern, path); +} + +bool InstallerPathProvider::GetDiffInstaller(FilePath* path) { + std::string diff_installer_pattern("*_from_*"); + return GetInstaller(diff_installer_pattern, path); +} + +bool InstallerPathProvider::GetMiniInstaller(FilePath* path) { + // Use local copy of installer, else fall back to filer. + FilePath mini_installer = PathFromExeDir( + mini_installer_constants::kChromeMiniInstallerExecutable); + if (file_util::PathExists(mini_installer)) { + *path = mini_installer; + return true; + } + std::string mini_installer_pattern("mini_installer.exe"); + return GetInstaller(mini_installer_pattern, path); +} + +bool InstallerPathProvider::GetPreviousInstaller(FilePath* path) { + std::string diff_installer_pattern("*_from_*"); + std::string full_installer_pattern("*_chrome_installer*"); + FilePath diff_installer; + if (!GetInstaller(diff_installer_pattern, &diff_installer)) + return false; + + FilePath previous_installer; + std::vector<std::string> tokenized_name; + Tokenize(diff_installer.BaseName().MaybeAsASCII(), + "_", &tokenized_name); + std::string build_pattern = base::StringPrintf( + "*%s", 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; + *path = previous_installer; + return true; +} + +bool InstallerPathProvider::GetStandaloneInstaller(FilePath* path) { + // Get standalone installer. + FilePath standalone_installer( + mini_installer_constants::kChromeStandAloneInstallerLocation); + // Get the file name. + std::vector<std::string> tokenized_build_number; + if (current_build_.empty()) + return false; + Tokenize(current_build_, ".", &tokenized_build_number); + std::string standalone_installer_filename = base::StringPrintf( + "%s%s_%s.exe", + FilePath(mini_installer_constants::kUntaggedInstallerPattern) + .MaybeAsASCII().c_str(), + tokenized_build_number[2].c_str(), + tokenized_build_number[3].c_str()); + standalone_installer = standalone_installer.AppendASCII(current_build_) + .Append(mini_installer_constants::kWinFolder) + .AppendASCII(standalone_installer_filename); + *path = standalone_installer; + return file_util::PathExists(standalone_installer); +} + +bool InstallerPathProvider::GetSignedStandaloneInstaller(FilePath* path) { + FilePath standalone_installer; + if (!GetStandaloneInstaller(&standalone_installer)) + return false; + FilePath tagged_installer = PathFromExeDir( + mini_installer_constants::kStandaloneInstaller); + CommandLine sign_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)); + + if (!installer_test::RunAndWaitForCommandToFinish(sign_command)) + return false; + + *path = PathFromExeDir(mini_installer_constants::kStandaloneInstaller); + return true; +} + +FilePath InstallerPathProvider::PathFromExeDir( + const FilePath::StringType& name) { + FilePath path; + PathService::Get(base::DIR_EXE, &path); + path = path.Append(name); + return path; +} + +bool InstallerPathProvider::GetInstaller(const std::string& pattern, + FilePath* path) { + FilePath installer; + // Search filer for installer binary. + FilePath root(mini_installer_constants::kChromeInstallersLocation); + std::vector<FilePath> paths; + if (!FindMatchingFiles(root, current_build_, + file_util::FileEnumerator::DIRECTORIES, &paths)) { + return false; + } + + 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, pattern, + file_util::FileEnumerator::FILES, &installer)) { + break; + } + } + + if (installer.empty()) { + LOG(WARNING) << "Failed to find installer with pattern: " << pattern; + return false; + } + + *path = installer; + return true; +} + +std::string InstallerPathProvider::GetCurrentBuild() { + return current_build_; +} + +std::string InstallerPathProvider::GetPreviousBuild() { + return previous_build_; +} + +} // namespace diff --git a/chrome/test/mini_installer_test/installer_path_provider.h b/chrome/test/mini_installer_test/installer_path_provider.h new file mode 100644 index 0000000..e7eb60f --- /dev/null +++ b/chrome/test/mini_installer_test/installer_path_provider.h @@ -0,0 +1,50 @@ +// 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. + +#ifndef CHROME_TEST_MINI_INSTALLER_TEST_INSTALLER_PATH_PROVIDER_H_ +#define CHROME_TEST_MINI_INSTALLER_TEST_INSTALLER_PATH_PROVIDER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/file_path.h" + +namespace installer_test { + +// Locate and provides path for installers. +// Search for latest installer binaries in the filer directory defined by +// mini_installer_constants::kChromeInstallersLocation. +class InstallerPathProvider { + public: + // Search for latest installer binaries in filer. + InstallerPathProvider(); + + explicit InstallerPathProvider(const std::string& build_under_test); + ~InstallerPathProvider(); + + bool GetFullInstaller(FilePath* path); + bool GetDiffInstaller(FilePath* path); + bool GetMiniInstaller(FilePath* path); + bool GetPreviousInstaller(FilePath* path); + bool GetStandaloneInstaller(FilePath* path); + bool GetSignedStandaloneInstaller(FilePath* path); + + std::string GetCurrentBuild(); + std::string GetPreviousBuild(); + + private: + // Returns the local file path for the given file |name|. + // Assumes file is located in the current working directory. + FilePath PathFromExeDir(const FilePath::StringType& name); + + bool GetInstaller(const std::string& pattern, FilePath* path); + + // Build numbers. + std::string current_build_, previous_build_; + + DISALLOW_COPY_AND_ASSIGN(InstallerPathProvider); +}; + +} // namespace + +#endif // CHROME_TEST_MINI_INSTALLER_TEST_INSTALLER_PATH_PROVIDER_H_ diff --git a/chrome/test/mini_installer_test/installer_test_util.cc b/chrome/test/mini_installer_test/installer_test_util.cc new file mode 100644 index 0000000..9559b61 --- /dev/null +++ b/chrome/test/mini_installer_test/installer_test_util.cc @@ -0,0 +1,306 @@ +// 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. + +#include "chrome/test/mini_installer_test/installer_test_util.h" + +#include "base/file_util.h" +#include "base/path_service.h" +#include "base/process.h" +#include "base/process_util.h" +#include "base/string_util.h" +#include "base/threading/platform_thread.h" +#include "chrome/common/chrome_result_codes.h" +#include "chrome/installer/util/google_update_constants.h" +#include "chrome/installer/util/helper.h" +#include "chrome/installer/util/install_util.h" +#include "chrome/installer/util/util_constants.h" +#include "chrome/test/mini_installer_test/mini_installer_test_constants.h" +#include "testing/gtest/include/gtest/gtest.h" + +using installer::InstallationValidator; + +namespace { + +BrowserDistribution::Type ToBrowserDistributionType( + InstallationValidator::InstallationType type) { + const int kChromeMask = + (InstallationValidator::ProductBits::CHROME_SINGLE | + InstallationValidator::ProductBits::CHROME_MULTI); + const int kChromeFrameMask = + (InstallationValidator::ProductBits::CHROME_FRAME_SINGLE | + InstallationValidator::ProductBits::CHROME_FRAME_MULTI | + InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE); + const int kBinariesMask = + (InstallationValidator::ProductBits::CHROME_MULTI | + InstallationValidator::ProductBits::CHROME_FRAME_MULTI | + InstallationValidator::ProductBits::CHROME_FRAME_READY_MODE); + // Default return is CHROME_BINARIES. + BrowserDistribution::Type ret_value = BrowserDistribution::CHROME_BINARIES; + if (type & kChromeMask) + ret_value = BrowserDistribution::CHROME_BROWSER; + if (type & kChromeFrameMask) + ret_value = BrowserDistribution::CHROME_FRAME; + if (type & kBinariesMask) + ret_value = BrowserDistribution::CHROME_BINARIES; + return ret_value; +} + +} // namespace + +namespace installer_test { + +bool DeleteInstallDirectory(bool system_level, + InstallationValidator::InstallationType type) { + std::string version = GetVersion(type); + if (version.empty()) + return false; + FilePath path; + if (!GetInstallDirectory(system_level, + ToBrowserDistributionType(type), &path) || + !file_util::PathExists(path)) + return false; + path = path.AppendASCII(version); + if (!file_util::Delete(path, true)) + return false; + return true; +} + +bool DeleteRegistryKey(bool system_level, + InstallationValidator::InstallationType type) { + FilePath::StringType key(google_update::kRegPathClients); + BrowserDistribution* dist = BrowserDistribution::GetSpecificDistribution( + ToBrowserDistributionType(type)); + file_util::AppendToPath(&key, dist->GetAppGuid()); + HKEY root = HKEY_CURRENT_USER; + if (system_level) + root = HKEY_LOCAL_MACHINE; + if (InstallUtil::DeleteRegistryKey(root, key)) + return true; + return false; +} + +bool GetChromeInstallDirectory(bool system_level, FilePath* path) { + return GetInstallDirectory(system_level, + BrowserDistribution::CHROME_BROWSER, path); +} + +bool GetInstallDirectory(bool system_level, + BrowserDistribution::Type type, FilePath* path) { + BrowserDistribution* dist = + BrowserDistribution::GetSpecificDistribution(type); + *path = installer::GetChromeInstallPath(system_level, dist); + FilePath parent; + if (system_level) { + PathService::Get(base::DIR_PROGRAM_FILES, &parent); + return file_util::ContainsPath(parent, *path); + } else { + PathService::Get(base::DIR_LOCAL_APP_DATA, &parent); + return file_util::ContainsPath(parent, *path); + } +} + +bool GetInstalledProducts( + std::vector<installer_test::InstalledProduct>* products) { + // Clear out the products list. + products->clear(); + // Check user-level and system-level for products. + BrowserDistribution* current_dist; + installer_test::InstalledProduct current_prod; + for (int i = 0; i < 2; ++i) { + const bool system_level = (i != 0); + InstallationValidator::InstallationType type = + InstallationValidator::NO_PRODUCTS; + bool is_valid = + InstallationValidator::ValidateInstallationType(system_level, &type); + if (type != InstallationValidator::NO_PRODUCTS) { + current_dist = BrowserDistribution::GetSpecificDistribution( + ToBrowserDistributionType(type)); + scoped_ptr<Version> version( + InstallUtil::GetChromeVersion(current_dist, system_level)); + if (version.get()) { + current_prod.type = type; + current_prod.version = version->GetString(); + current_prod.system = system_level; + products->push_back(current_prod); + } + } + } + return !products->empty(); +} + +bool ValidateInstall(bool system_level, + InstallationValidator::InstallationType expected, + const std::string& version) { + if (GetVersion(expected) != version) + return false; + InstallationValidator::InstallationType type; + InstallationValidator::ValidateInstallationType(system_level, &type); + if (type == InstallationValidator::NO_PRODUCTS) { + LOG(ERROR) << "No installed Chrome or Chrome Frame versions found."; + return false; + } + if ((type & expected) == 0) { + LOG(ERROR) << "Expected type: " << expected << "\n Actual type: " << type; + return false; + } + return true; +} + +std::string GetVersion(InstallationValidator::InstallationType product) { + std::vector<installer_test::InstalledProduct> installed; + if (GetInstalledProducts(&installed)) { + for (size_t i = 0; i < installed.size(); ++i) { + if ((installed[i].type & product) != 0) { + return installed[i].version; + } + } + } + return ""; +} + +bool Install(const FilePath& installer) { + if (!file_util::PathExists(installer)) { + LOG(ERROR) << "Installer does not exist: " << installer.MaybeAsASCII(); + return false; + } + CommandLine command(installer); + LOG(INFO) << "Running installer command: " + << command.GetCommandLineString(); + return installer_test::RunAndWaitForCommandToFinish(command); +} + +bool Install(const FilePath& installer, const SwitchBuilder& switches) { + if (!file_util::PathExists(installer)) { + LOG(ERROR) << "Installer does not exist: " << installer.MaybeAsASCII(); + return false; + } + CommandLine command(installer); + command.AppendArguments(switches.GetSwitches(), false); + LOG(INFO) << "Running installer command: " + << command.GetCommandLineString(); + return installer_test::RunAndWaitForCommandToFinish(command); +} + +bool LaunchChrome(bool close_after_launch, bool system_level) { + base::CleanupProcesses(installer::kChromeExe, 0, + content::RESULT_CODE_HUNG, NULL); + FilePath install_path; + if (!GetChromeInstallDirectory( + system_level, &install_path)) { + LOG(ERROR) << "Could not find Chrome install directory"; + return false; + } + install_path = install_path.Append(installer::kChromeExe); + CommandLine browser(install_path); + + FilePath exe = browser.GetProgram(); + LOG(INFO) << "Browser launch command: " << browser.GetCommandLineString(); + base::ProcessHandle chrome; + if (!base::LaunchProcess(browser, base::LaunchOptions(), &chrome)) { + LOG(ERROR) << "Could not launch process: " << exe.value(); + return false; + } + if (close_after_launch) { + if (base::KillProcess(chrome, 0, true)) { + LOG(ERROR) << "Failed to close chrome.exe after launch."; + return false; + } + } + return true; +} + +bool LaunchIE(const std::string& url) { + FilePath browser_path; + PathService::Get(base::DIR_PROGRAM_FILES, &browser_path); + browser_path = browser_path.Append(mini_installer_constants::kIELocation); + browser_path = browser_path.Append(mini_installer_constants::kIEProcessName); + + CommandLine cmd_line(browser_path); + cmd_line.AppendArg(url); + return base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL); +} + +bool UninstallAll() { + base::CleanupProcesses(installer::kChromeExe, 0, + content::RESULT_CODE_HUNG, NULL); + base::CleanupProcesses(installer::kChromeFrameHelperExe, 0, + content::RESULT_CODE_HUNG, NULL); + std::vector<installer_test::InstalledProduct> installed; + if (!GetInstalledProducts(&installed)) { + LOG(WARNING) << "No installed products to uninstall."; + return false; + } + bool ret_val = false; + for (size_t i = 0; i < installed.size(); ++i) { + if (!Uninstall(installed[i].system, installed[i].type)) + ret_val = false; + } + return ret_val; +} + +bool Uninstall(bool system_level, + InstallationValidator::InstallationType type) { + std::vector<BrowserDistribution::Type> products; + if (ToBrowserDistributionType(type) != + BrowserDistribution::CHROME_BINARIES) { + products.push_back(ToBrowserDistributionType(type)); + } else { + products.push_back(BrowserDistribution::CHROME_BROWSER); + products.push_back(BrowserDistribution::CHROME_FRAME); + } + bool ret_val = false; + for (size_t i = 0; i < products.size(); ++i) { + if (!Uninstall(system_level, products[i])) + ret_val = false; + } + return ret_val; +} + +bool Uninstall(bool system_level, + BrowserDistribution::Type product) { + static const int kMultiMask = + (InstallationValidator::ProductBits::CHROME_MULTI | + InstallationValidator::ProductBits::CHROME_FRAME_MULTI); + CommandLine uninstall_cmd(InstallUtil::GetChromeUninstallCmd(system_level, + product)); + CommandLine::StringType archive = + uninstall_cmd.GetProgram().DirName().AppendASCII("chrome.7z").value(); + uninstall_cmd.AppendSwitch(installer::switches::kUninstall); + uninstall_cmd.AppendSwitch(installer::switches::kForceUninstall); + uninstall_cmd.AppendSwitchNative( + installer::switches::kInstallArchive, archive); + if (system_level) + uninstall_cmd.AppendSwitch(installer::switches::kSystemLevel); + if ((product & kMultiMask) !=0) + uninstall_cmd.AppendSwitch(installer::switches::kMultiInstall); + LOG(INFO) << "Uninstall command: " << uninstall_cmd.GetCommandLineString(); + bool ret_val = RunAndWaitForCommandToFinish(uninstall_cmd); + // Close IE notification when uninstalling Chrome Frame. + base::CleanupProcesses(mini_installer_constants::kIEProcessName, 0, + content::RESULT_CODE_HUNG, NULL); + return ret_val; +} + + +bool RunAndWaitForCommandToFinish(CommandLine command) { + if (!file_util::PathExists(command.GetProgram())) { + LOG(ERROR) << "Command executable does not exist: " + << command.GetProgram().MaybeAsASCII(); + return false; + } + base::ProcessHandle process; + if (!base::LaunchProcess(command, base::LaunchOptions(), &process)) { + LOG(ERROR) << "Failed to launch command: " + << command.GetCommandLineString(); + return false; + } + if (!base::WaitForSingleProcess(process, 60 * 1000)) { + LOG(ERROR) << "Launched process did not complete."; + return false; + } + return true; +} + +} // namespace + diff --git a/chrome/test/mini_installer_test/installer_test_util.h b/chrome/test/mini_installer_test/installer_test_util.h new file mode 100644 index 0000000..4dac587 --- /dev/null +++ b/chrome/test/mini_installer_test/installer_test_util.h @@ -0,0 +1,88 @@ +// 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. + +#ifndef CHROME_TEST_MINI_INSTALLER_TEST_INSTALLER_TEST_UTIL_H_ +#define CHROME_TEST_MINI_INSTALLER_TEST_INSTALLER_TEST_UTIL_H_ +#pragma once + +#include <vector> + +#include "base/command_line.h" +#include "base/file_path.h" +#include "chrome/installer/util/installation_validator.h" +#include "chrome/test/mini_installer_test/switch_builder.h" + +namespace installer_test { + +struct InstalledProduct { + std::string version; + installer::InstallationValidator::InstallationType type; + bool system; +}; + +// Utility functions used to test Chrome installation. + +// Deletes the Chrome installation directory which is found at different +// locations depending on the |system_level| and |type|. +// Returns true if successful, otherwise false. +bool DeleteInstallDirectory( + bool system_level, + installer::InstallationValidator::InstallationType type); + +// Deletes the Chrome Windows registry entry. +// Returns true if successful, otherwise false. +bool DeleteRegistryKey( + bool system_level, + installer::InstallationValidator::InstallationType type); + +// Locates the Chrome installation directory based on the +// provided |system_level|. Returns true if successful, otherwise false. +// Returns true if successful, otherwise false. +bool GetChromeInstallDirectory(bool system_level, FilePath* path); + +// Gets the installation directory of either Chrome or Chrome Frame +// as specified by the |system_level| and |type|. +// Returns true if successful, otherwise false. +bool GetInstallDirectory(bool system_level, + BrowserDistribution::Type type, FilePath* path); + +// Returns the version of the specified |product|. +std::string GetVersion( + installer::InstallationValidator::InstallationType product); + +// Gets a list of installed products. +// Returns true if there are installed products. +bool GetInstalledProducts(std::vector<InstalledProduct>* products); + +bool Install(const FilePath& installer); +bool Install(const FilePath& installer, const SwitchBuilder& switches); +bool LaunchChrome(bool close_after_launch, bool system_level); +bool LaunchIE(const std::string& url); + +// Uninstall all Chrome or Chrome Frame installations. +bool UninstallAll(); + +// Uninstall the product specified by |system_level| and |type|. +bool Uninstall( + bool system_level, + installer::InstallationValidator::InstallationType type); + +// Uninstall the product specified by |system_level| and |product|. +bool Uninstall( + bool system_level, + BrowserDistribution::Type product); + +bool ValidateInstall( + bool system_level, + installer::InstallationValidator::InstallationType expected, + const std::string& version); + +// Run and wait for command to finish. +// Returns true if successful, otherwise false. +bool RunAndWaitForCommandToFinish(CommandLine command); + +} // namespace + +#endif // CHROME_TEST_MINI_INSTALLER_TEST_INSTALLER_TEST_UTIL_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 deleted file mode 100644 index a295984..0000000 --- a/chrome/test/mini_installer_test/mini_installer_test_util.cc +++ /dev/null @@ -1,114 +0,0 @@ -// 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. - -#include <algorithm> - -#include "chrome/test/mini_installer_test/mini_installer_test_util.h" - -#include "base/command_line.h" -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/path_service.h" -#include "base/process_util.h" -#include "base/stringprintf.h" -#include "base/string_split.h" -#include "base/string_util.h" -#include "base/test/test_timeouts.h" -#include "base/threading/platform_thread.h" -#include "base/time.h" -#include "base/utf_string_conversions.h" -#include "chrome/installer/util/logging_installer.h" -#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) { - FilePath backup_path; - if (!file_util::GetCurrentDirectory(&backup_path)) - return false; - - if (!file_util::SetCurrentDirectory(backup_path.DirName())) - return false; - *current_path = backup_path; - return true; -} - -// Checks for all requested running processes and kills them. -void MiniInstallerTestUtil::CloseProcesses( - const std::wstring& executable_name) { - int timer = 0; - while ((base::GetProcessCount(executable_name, NULL) > 0) && - (timer < 20000)) { - base::KillProcesses(executable_name, 1, NULL); - base::PlatformThread::Sleep(200); - timer = timer + 200; - } - ASSERT_EQ(0, base::GetProcessCount(executable_name, NULL)); -} - -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; -} - -void MiniInstallerTestUtil::SendEnterKeyToWindow() { - INPUT key; - key.type = INPUT_KEYBOARD; - key.ki.wVk = VK_RETURN; - key.ki.dwFlags = 0; - key.ki.time = 0; - key.ki.wScan = 0; - key.ki.dwExtraInfo = 0; - SendInput(1, &key, sizeof(INPUT)); - key.ki.dwExtraInfo = KEYEVENTF_KEYUP; - SendInput(1, &key, sizeof(INPUT)); -} - - -void MiniInstallerTestUtil::VerifyProcessLaunch( - const wchar_t* process_name, bool expected_status) { - LOG(INFO) << "Verifying process is launched: " << process_name; - int timer = 0, wait_time = 60000; - if (!expected_status) - wait_time = 8000; - - while ((base::GetProcessCount(process_name, NULL) == 0) && - (timer < wait_time)) { - base::PlatformThread::Sleep(200); - timer = timer + 200; - } - - if (expected_status) - ASSERT_NE(0, base::GetProcessCount(process_name, NULL)); - else - ASSERT_EQ(0, base::GetProcessCount(process_name, NULL)); -} - -bool MiniInstallerTestUtil::VerifyProcessClose( - const wchar_t* process_name) { - int timer = 0; - if (base::GetProcessCount(process_name, NULL) > 0) { - 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); - timer = timer + 200; - } - } else { - if (base::GetProcessCount(process_name, NULL) != 0) - return false; - } - return true; -} - -bool MiniInstallerTestUtil::VerifyProcessHandleClosed( - base::ProcessHandle handle) { - DWORD result = WaitForSingleObject(handle, - TestTimeouts::large_test_timeout_ms()); - return result == WAIT_OBJECT_0; -} diff --git a/chrome/test/mini_installer_test/mini_installer_test_util.h b/chrome/test/mini_installer_test/mini_installer_test_util.h deleted file mode 100644 index 79e6f56..0000000 --- a/chrome/test/mini_installer_test/mini_installer_test_util.h +++ /dev/null @@ -1,51 +0,0 @@ -// 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. -// -// This file declares utility functions for mini installer tests. -// The reason for putting these functions in different class is to separate out -// the critical logic from utility methods. - -#ifndef CHROME_TEST_MINI_INSTALLER_TEST_MINI_INSTALLER_TEST_UTIL_H_ -#define CHROME_TEST_MINI_INSTALLER_TEST_MINI_INSTALLER_TEST_UTIL_H_ -#pragma once - -#include <vector> - -#include "base/process.h" - -class FilePath; - -// This class maintains all the utility methods that are needed by mini -// installer test class. -class MiniInstallerTestUtil { - public: - // This method will change the current directory to one level up and - // return the new current path. - static bool ChangeCurrentDirectory(FilePath* current_path); - - // Closes specified process. - static void CloseProcesses(const std::wstring& executable_name); - - // Returns the directory containing exe_name. - static FilePath GetFilePath(const wchar_t* exe_name); - - // This method will send enter key to window in the foreground. - static void SendEnterKeyToWindow(); - - // Verifies if the given process starts running. - static void VerifyProcessLaunch(const wchar_t* process_name, - bool expected_status); - - // Verifies if the given process stops running. - static bool VerifyProcessClose(const wchar_t* process_name); - - // Waits on the given process name until it returns or until a timeout is - // reached. - static bool VerifyProcessHandleClosed(base::ProcessHandle handle); - - private: - DISALLOW_COPY_AND_ASSIGN(MiniInstallerTestUtil); -}; - -#endif // CHROME_TEST_MINI_INSTALLER_TEST_MINI_INSTALLER_TEST_UTIL_H_ diff --git a/chrome/test/mini_installer_test/run_all_unittests.cc b/chrome/test/mini_installer_test/run_all_unittests.cc index 978bb3b..adc31a7 100644 --- a/chrome/test/mini_installer_test/run_all_unittests.cc +++ b/chrome/test/mini_installer_test/run_all_unittests.cc @@ -10,7 +10,8 @@ #include "chrome/common/chrome_switches.h" #include "chrome/installer/util/util_constants.h" #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" -#include "chrome_mini_installer.h" +#include "chrome/test/mini_installer_test/installer_test_util.h" + void BackUpProfile(bool chrome_frame) { if (base::GetProcessCount(L"chrome.exe", NULL) > 0) { @@ -18,9 +19,8 @@ void BackUpProfile(bool chrome_frame) { "Please close Chrome and run the tests again.\n"); exit(1); } - ChromeMiniInstaller installer(false, chrome_frame, ""); FilePath path; - installer.GetInstallDirectory(&path); + installer_test::GetChromeInstallDirectory(false /* system_level */, &path); path = path.Append(mini_installer_constants::kChromeAppDir).DirName(); FilePath backup_path = path; // Will hold User Data path that needs to be backed-up. diff --git a/chrome/test/mini_installer_test/switch_builder.cc b/chrome/test/mini_installer_test/switch_builder.cc new file mode 100644 index 0000000..1c6149a --- /dev/null +++ b/chrome/test/mini_installer_test/switch_builder.cc @@ -0,0 +1,48 @@ +// 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. + +#include "chrome/test/mini_installer_test/switch_builder.h" + +#include "chrome/installer/util/install_util.h" + +namespace installer_test { + +SwitchBuilder::SwitchBuilder() + : switches_(CommandLine::NO_PROGRAM) {} + +SwitchBuilder::~SwitchBuilder() {} + +const CommandLine& SwitchBuilder::GetSwitches() const { + return switches_; +} + +SwitchBuilder& SwitchBuilder::AddChrome() { + switches_.AppendSwitch(installer::switches::kChrome); + return *this; +} + +SwitchBuilder& SwitchBuilder::AddChromeFrame() { + switches_.AppendSwitch(installer::switches::kChromeFrame); + switches_.AppendSwitch(installer::switches::kDoNotCreateShortcuts); + switches_.AppendSwitch(installer::switches::kDoNotLaunchChrome); + switches_.AppendSwitch(installer::switches::kDoNotRegisterForUpdateLaunch); + return *this; +} + +SwitchBuilder& SwitchBuilder::AddMultiInstall() { + switches_.AppendSwitch(installer::switches::kMultiInstall); + return *this; +} + +SwitchBuilder& SwitchBuilder::AddReadyMode() { + switches_.AppendSwitch(installer::switches::kChromeFrameReadyMode); + return *this; +} + +SwitchBuilder& SwitchBuilder::AddSystemInstall() { + switches_.AppendSwitch(installer::switches::kSystemLevel); + return *this; +} + +} // namespace diff --git a/chrome/test/mini_installer_test/switch_builder.h b/chrome/test/mini_installer_test/switch_builder.h new file mode 100644 index 0000000..c1bd691e --- /dev/null +++ b/chrome/test/mini_installer_test/switch_builder.h @@ -0,0 +1,35 @@ +// 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. + +#ifndef CHROME_TEST_MINI_INSTALLER_TEST_SWITCH_BUILDER_H_ +#define CHROME_TEST_MINI_INSTALLER_TEST_SWITCH_BUILDER_H_ +#pragma once + +#include "base/basictypes.h" +#include "base/command_line.h" + +namespace installer_test { + +// Builds commandline arguments for Chrome installation. +class SwitchBuilder { + public: + SwitchBuilder(); + ~SwitchBuilder(); + + const CommandLine& GetSwitches() const; + + SwitchBuilder& AddChrome(); + SwitchBuilder& AddChromeFrame(); + SwitchBuilder& AddMultiInstall(); + SwitchBuilder& AddReadyMode(); + SwitchBuilder& AddSystemInstall(); + + private: + CommandLine switches_; + DISALLOW_COPY_AND_ASSIGN(SwitchBuilder); +}; + +} // namespace + +#endif // CHROME_TEST_MINI_INSTALLER_TEST_SWITCH_BUILDER_H_ diff --git a/chrome/test/mini_installer_test/test.cc b/chrome/test/mini_installer_test/test.cc index 7a5c6e1..93306cc 100644 --- a/chrome/test/mini_installer_test/test.cc +++ b/chrome/test/mini_installer_test/test.cc @@ -5,46 +5,76 @@ #include "base/command_line.h" #include "base/file_path.h" #include "base/memory/scoped_ptr.h" +#include "base/process_util.h" +#include "base/string_util.h" +#include "chrome/common/chrome_result_codes.h" #include "chrome/common/chrome_switches.h" #include "chrome/installer/util/install_util.h" +#include "chrome/installer/util/installation_validator.h" #include "chrome/installer/util/util_constants.h" -#include "chrome/test/mini_installer_test/chrome_mini_installer.h" +#include "chrome/test/mini_installer_test/installer_path_provider.h" #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" -#include "chrome/test/mini_installer_test/mini_installer_test_util.h" +#include "chrome/test/mini_installer_test/installer_test_util.h" +#include "chrome/test/mini_installer_test/switch_builder.h" #include "testing/gtest/include/gtest/gtest.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; // NOLINT +using installer::InstallationValidator; +using installer_test::InstallerPathProvider; +using installer_test::SwitchBuilder; namespace { + class MiniInstallTest : public testing::Test { public: - MiniInstallTest() { - std::string build; - const CommandLine* cmd = CommandLine::ForCurrentProcess(); - build = cmd->GetSwitchValueASCII(switches::kInstallerTestBuild); - chrome_user_installer_.reset( - new ChromeMiniInstaller(false, false, build)); - chrome_sys_installer_.reset(new ChromeMiniInstaller(true, false, build)); - cf_user_installer_.reset(new ChromeMiniInstaller(false, true, build)); - cf_sys_installer_.reset(new ChromeMiniInstaller(true, true, build)); + virtual void SetUp() { + std::vector<installer_test::InstalledProduct> installed; + if (installer_test::GetInstalledProducts(&installed)) { + ASSERT_TRUE(installer_test::UninstallAll()); + } } virtual void TearDown() { - chrome_user_installer_->UnInstall(); - chrome_sys_installer_->UnInstall(); - cf_user_installer_->UnInstall(); - cf_sys_installer_->UnInstall(); + installer_test::UninstallAll(); } protected: - scoped_ptr<ChromeMiniInstaller> chrome_user_installer_; - scoped_ptr<ChromeMiniInstaller> chrome_sys_installer_; - scoped_ptr<ChromeMiniInstaller> cf_user_installer_; - scoped_ptr<ChromeMiniInstaller> cf_sys_installer_; + static void SetUpTestCase() { + std::string build_under_test; + const CommandLine* cmd = CommandLine::ForCurrentProcess(); + build_under_test = cmd->GetSwitchValueASCII(switches::kInstallerTestBuild); + if (build_under_test.empty()) + provider_ = new InstallerPathProvider(); + else + provider_ = new InstallerPathProvider(build_under_test); + ASSERT_FALSE(provider_->GetCurrentBuild().empty()); + ASSERT_TRUE(provider_->GetFullInstaller(&full_installer_)); + ASSERT_TRUE(provider_->GetPreviousInstaller(&previous_installer_)); + ASSERT_TRUE(provider_->GetDiffInstaller(&diff_installer_)); + ASSERT_TRUE( + provider_->GetSignedStandaloneInstaller(&standalone_installer_)); + ASSERT_TRUE(provider_->GetMiniInstaller(&mini_installer_)); + } + + static void TearDownTestCase() { + delete provider_; + provider_ = NULL; + } + + static InstallerPathProvider* provider_; + static FilePath full_installer_; + static FilePath previous_installer_; + static FilePath diff_installer_; + static FilePath standalone_installer_; + static FilePath mini_installer_; }; + +InstallerPathProvider* MiniInstallTest::provider_; +FilePath MiniInstallTest::full_installer_; +FilePath MiniInstallTest::previous_installer_; +FilePath MiniInstallTest::diff_installer_; +FilePath MiniInstallTest::standalone_installer_; +FilePath MiniInstallTest::mini_installer_; + } // namespace #if defined(GOOGLE_CHROME_BUILD) @@ -52,151 +82,355 @@ class MiniInstallTest : public testing::Test { // these tests will often be run manually, don't want to have obscure test // names. +// Install full installer at user level. +TEST_F(MiniInstallTest, FullInstallerUser) { + ASSERT_TRUE(installer_test::Install( + full_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); +} + // Install full installer at system level. TEST_F(MiniInstallTest, FullInstallerSys) { - chrome_sys_installer_->InstallFullInstaller(false); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } -// Install full installer at user level. -TEST_F(MiniInstallTest, FullInstallerUser) { - chrome_user_installer_->InstallFullInstaller(false); -} // Overinstall full installer. TEST_F(MiniInstallTest, FullOverPreviousFullUser) { - chrome_user_installer_->OverInstallOnFullInstaller(kFullInstall, false); + ASSERT_TRUE(installer_test::Install( + previous_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetPreviousBuild())); + ASSERT_TRUE(installer_test::Install( + full_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } + TEST_F(MiniInstallTest, FullOverPreviousFullSys) { - chrome_sys_installer_->OverInstallOnFullInstaller(kFullInstall, false); + ASSERT_TRUE(installer_test::Install(previous_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetPreviousBuild())); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); +} + +TEST_F(MiniInstallTest, FreshChromeFrameUser) { + ASSERT_TRUE(installer_test::Install( + full_installer_, SwitchBuilder().AddChromeFrame())); + ASSERT_TRUE(installer_test::ValidateInstall( + false, + InstallationValidator::CHROME_FRAME_SINGLE, + provider_->GetCurrentBuild())); } // Overinstall full Chrome Frame installer while IE browser is running. TEST_F(MiniInstallTest, FullFrameOverPreviousFullIERunningSys) { - cf_sys_installer_->OverInstallOnFullInstaller(kFullInstall, true); + installer_test::LaunchIE("http://www.google.com"); + ASSERT_TRUE(installer_test::Install(previous_installer_, + SwitchBuilder().AddChromeFrame().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_SINGLE, + provider_->GetPreviousBuild())); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChromeFrame().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_SINGLE, + provider_->GetCurrentBuild())); } // Overinstall diff installer. TEST_F(MiniInstallTest, DiffOverPreviousFullUser) { - chrome_user_installer_->OverInstallOnFullInstaller(kDiffInstall, false); + ASSERT_TRUE(installer_test::Install( + previous_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetPreviousBuild())); + ASSERT_TRUE(installer_test::Install( + diff_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, DiffOverPreviousFullSys) { - chrome_sys_installer_->OverInstallOnFullInstaller(kDiffInstall, false); + ASSERT_TRUE(installer_test::Install(previous_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetPreviousBuild())); + ASSERT_TRUE(installer_test::Install(diff_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } // Overinstall diff Chrome Frame installer while IE browser is running. TEST_F(MiniInstallTest, DiffFrameOverPreviousFullIERunningSys) { - cf_sys_installer_->OverInstallOnFullInstaller(kDiffInstall, true); + installer_test::LaunchIE("http://www.google.com"); + ASSERT_TRUE(installer_test::Install(previous_installer_, + SwitchBuilder().AddChromeFrame().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_SINGLE, + provider_->GetPreviousBuild())); + ASSERT_TRUE(installer_test::Install(diff_installer_, + SwitchBuilder().AddChromeFrame().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_SINGLE, + provider_->GetCurrentBuild())); +} + +TEST_F(MiniInstallTest, InstallChromeMultiOverChromeSys) { + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddSystemInstall().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); } // Repair version folder. TEST_F(MiniInstallTest, RepairFolderOnFullUser) { - chrome_user_installer_->Repair(ChromeMiniInstaller::VERSION_FOLDER); + ASSERT_TRUE(installer_test::Install( + full_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); + base::CleanupProcesses(installer::kChromeExe, 0, + content::RESULT_CODE_HUNG, NULL); + ASSERT_TRUE(installer_test::DeleteInstallDirectory( + false, // system level + InstallationValidator::CHROME_SINGLE)); + ASSERT_TRUE(installer_test::Install( + full_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, RepairFolderOnFullSys) { - chrome_sys_installer_->Repair(ChromeMiniInstaller::VERSION_FOLDER); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); + base::CleanupProcesses(installer::kChromeExe, 0, + content::RESULT_CODE_HUNG, NULL); + ASSERT_TRUE(installer_test::DeleteInstallDirectory( + true, // system level + InstallationValidator::CHROME_SINGLE)); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } // Repair registry. TEST_F(MiniInstallTest, RepairRegistryOnFullUser) { - chrome_user_installer_->Repair(ChromeMiniInstaller::REGISTRY); + ASSERT_TRUE(installer_test::Install( + full_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); + base::CleanupProcesses(installer::kChromeExe, 0, + content::RESULT_CODE_HUNG, NULL); + ASSERT_TRUE(installer_test::DeleteRegistryKey( + false, // system level + InstallationValidator::CHROME_SINGLE)); + ASSERT_TRUE( + installer_test::Install(full_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } + TEST_F(MiniInstallTest, RepairRegistryOnFullSys) { - chrome_sys_installer_->Repair(ChromeMiniInstaller::REGISTRY); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); + ASSERT_TRUE(installer_test::DeleteRegistryKey( + true, // system level + InstallationValidator::CHROME_SINGLE)); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } // Run full Chrome Frame install then uninstall it while IE browser is running. TEST_F(MiniInstallTest, FullInstallAndUnInstallChromeFrameWithIERunning) { - cf_sys_installer_->InstallFullInstaller(false); - cf_sys_installer_->UnInstallChromeFrameWithIERunning(); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChromeFrame().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_SINGLE, + provider_->GetCurrentBuild())); + // Launch IE and let TearDown step perform uninstall. + installer_test::LaunchIE("http://www.google.com"); } // Install standalone. TEST_F(MiniInstallTest, InstallStandaloneUser) { - chrome_user_installer_->InstallStandaloneInstaller(); + ASSERT_TRUE(installer_test::Install(standalone_installer_)); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); } // This test doesn't make sense. Disabling for now. TEST_F(MiniInstallTest, DISABLED_MiniInstallerOverChromeMetaInstallerTest) { - chrome_user_installer_->OverInstall(); } // Encountering issue 9593. Disabling temporarily. TEST_F(MiniInstallTest, DISABLED_InstallLatestStableFullInstallerOverChromeMetaInstaller) { - chrome_user_installer_->OverInstall(); } // Encountering issue 9593. Disabling temporarily. TEST_F(MiniInstallTest, DISABLED_InstallLatestDevFullInstallerOverChromeMetaInstallerTest) { - chrome_user_installer_->OverInstall(); } TEST_F(MiniInstallTest, InstallChromeUsingMultiInstallUser) { - chrome_user_installer_->InstallChromeUsingMultiInstall(); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, InstallChromeUsingMultiInstallSys) { - chrome_sys_installer_->InstallChromeUsingMultiInstall(); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddMultiInstall().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); } -TEST_F(MiniInstallTest, InstallChromeAndChromeFrameUser) { - chrome_user_installer_->InstallChromeAndChromeFrame(false); +TEST_F(MiniInstallTest, InstallChromeAndChromeFrameMultiInstallUser) { + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddChromeFrame().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + false, + InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI, + provider_->GetCurrentBuild())); } -TEST_F(MiniInstallTest, InstallChromeAndChromeFrameSys) { - chrome_sys_installer_->InstallChromeAndChromeFrame(false); +TEST_F(MiniInstallTest, InstallChromeAndChromeFrameMultiInstallSys) { + ASSERT_TRUE(installer_test::Install( + full_installer_, SwitchBuilder().AddChrome() + .AddChromeFrame().AddMultiInstall().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI, + provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, InstallChromeAndChromeFrameReadyModeUser) { - chrome_user_installer_->InstallChromeAndChromeFrame(true); + ASSERT_TRUE( + installer_test::Install(full_installer_,SwitchBuilder().AddChrome() + .AddChromeFrame().AddMultiInstall().AddReadyMode())); + ASSERT_TRUE(installer_test::ValidateInstall( + false, + InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI, + provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, InstallChromeAndChromeFrameReadyModeSys) { - chrome_sys_installer_->InstallChromeAndChromeFrame(true); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddChromeFrame().AddMultiInstall() + .AddReadyMode().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_READY_MODE_CHROME_MULTI, + provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, InstallChromeFrameUsingMultiInstallUser) { - cf_user_installer_->InstallChromeFrameUsingMultiInstall(); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChromeFrame().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + false, + InstallationValidator::CHROME_FRAME_MULTI, + provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, InstallChromeFrameUsingMultiInstallSys) { - cf_sys_installer_->InstallChromeFrameUsingMultiInstall(); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChromeFrame().AddMultiInstall().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_MULTI, + provider_->GetCurrentBuild())); } // Chrome Frame is in use while Chrome is install. TEST_F(MiniInstallTest, InstallChromeWithExistingChromeFrameMultiInstallUser) { - cf_user_installer_->InstallChromeFrameUsingMultiInstall(); - chrome_user_installer_->InstallChromeUsingMultiInstall(); + ASSERT_TRUE(installer_test::Install(previous_installer_, + SwitchBuilder().AddChromeFrame().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + false, + InstallationValidator::CHROME_FRAME_MULTI, + provider_->GetPreviousBuild())); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + false, + InstallationValidator::CHROME_FRAME_MULTI_CHROME_MULTI, + provider_->GetCurrentBuild())); } // Chrome Frame is in use while Chrome is install. TEST_F(MiniInstallTest, InstallChromeWithExistingChromeFrameMultiInstallSys) { - cf_sys_installer_->InstallChromeFrameUsingMultiInstall(); - chrome_sys_installer_->InstallChromeUsingMultiInstall(); + ASSERT_TRUE(installer_test::Install(previous_installer_, + SwitchBuilder().AddChromeFrame().AddMultiInstall().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall( + true, + InstallationValidator::CHROME_FRAME_MULTI, + provider_->GetPreviousBuild())); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, OverInstallChromeWhenInUseUser) { - chrome_user_installer_->InstallChromeUsingMultiInstall(); - chrome_user_installer_->LaunchChrome(false); - chrome_user_installer_->InstallChromeUsingMultiInstall(); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); + installer_test::LaunchChrome(false, false); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddMultiInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); } TEST_F(MiniInstallTest, OverInstallChromeWhenInUseSys) { - chrome_sys_installer_->InstallChromeUsingMultiInstall(); - chrome_sys_installer_->LaunchChrome(false); - chrome_sys_installer_->InstallChromeUsingMultiInstall(); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddMultiInstall().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); + installer_test::LaunchChrome(false, true); + ASSERT_TRUE(installer_test::Install(full_installer_, + SwitchBuilder().AddChrome().AddMultiInstall().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_MULTI, provider_->GetCurrentBuild())); } #endif TEST_F(MiniInstallTest, InstallMiniInstallerSys) { - chrome_sys_installer_->Install(); + ASSERT_TRUE(installer_test::Install(mini_installer_, + SwitchBuilder().AddChrome().AddSystemInstall())); + ASSERT_TRUE(installer_test::ValidateInstall(true, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } #if defined(OS_WIN) @@ -206,7 +440,10 @@ TEST_F(MiniInstallTest, InstallMiniInstallerSys) { #define MAYBE_InstallMiniInstallerUser InstallMiniInstallerUser #endif TEST_F(MiniInstallTest, MAYBE_InstallMiniInstallerUser) { - chrome_user_installer_->Install(); + ASSERT_TRUE( + installer_test::Install(mini_installer_, SwitchBuilder().AddChrome())); + ASSERT_TRUE(installer_test::ValidateInstall(false, + InstallationValidator::CHROME_SINGLE, provider_->GetCurrentBuild())); } TEST(GenericInstallTest, MiniInstallTestValidWindowsVersion) { |