| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/test/mini_installer_test/chrome_mini_installer.h" | 5 #include "chrome/test/mini_installer_test/chrome_mini_installer.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/platform_thread.h" | 9 #include "base/platform_thread.h" |
| 10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
| 11 #include "base/registry.h" | 11 #include "base/registry.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/installer/util/browser_distribution.h" | 13 #include "chrome/installer/util/browser_distribution.h" |
| 14 #include "chrome/installer/util/google_update_constants.h" | 14 #include "chrome/installer/util/google_update_constants.h" |
| 15 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" | 15 #include "chrome/test/mini_installer_test/mini_installer_test_constants.h" |
| 16 #include "chrome/test/mini_installer_test/mini_installer_test_util.h" | 16 #include "chrome/test/mini_installer_test/mini_installer_test_util.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 // Constructor. |
| 20 ChromeMiniInstaller::ChromeMiniInstaller(const std::wstring& install_type) { |
| 21 install_type_ = install_type; |
| 22 installer_name_ = StringPrintf(L"%ls (%ls)", |
| 23 mini_installer_constants::kChromeBuildType, install_type_.c_str()); |
| 24 |
| 25 has_diff_installer_ = false; |
| 26 has_full_installer_ = false; |
| 27 has_prev_installer_ = false; |
| 28 } |
| 29 |
| 30 void ChromeMiniInstaller::SetBuildUnderTest(const std::wstring& build) { |
| 31 // Locate the full, diff, and previous installers. |
| 32 const wchar_t * build_prefix; |
| 33 if (LowerCaseEqualsASCII(build, "dev")) |
| 34 build_prefix = mini_installer_constants::kDevChannelBuild; |
| 35 else if (LowerCaseEqualsASCII(build, "stable")) |
| 36 build_prefix = mini_installer_constants::kStableChannelBuild; |
| 37 else if (LowerCaseEqualsASCII(build, "latest")) |
| 38 build_prefix = L""; |
| 39 else |
| 40 build_prefix = build.c_str(); |
| 41 |
| 42 // Do not fail here if cannot find the installer. Set the bool and allow |
| 43 // to fail in the particular test. |
| 44 has_full_installer_ = MiniInstallerTestUtil::GetInstaller( |
| 45 mini_installer_constants::kFullInstallerPattern, |
| 46 &full_installer_, build_prefix); |
| 47 has_diff_installer_ = MiniInstallerTestUtil::GetInstaller( |
| 48 mini_installer_constants::kDiffInstallerPattern, |
| 49 &diff_installer_, build_prefix); |
| 50 |
| 51 if (has_diff_installer_) { |
| 52 has_prev_installer_ = MiniInstallerTestUtil::GetPreviousFullInstaller( |
| 53 diff_installer_, &prev_installer_); |
| 54 } |
| 55 |
| 56 // Find the version names. The folder two-levels up from the installer |
| 57 // is named this. |
| 58 if (has_full_installer_) { |
| 59 FilePath folder = FilePath(full_installer_).DirName().DirName(); |
| 60 curr_version_ = folder.BaseName().value(); |
| 61 } |
| 62 if (has_prev_installer_) { |
| 63 FilePath folder = FilePath(prev_installer_).DirName().DirName(); |
| 64 prev_version_ = folder.BaseName().value(); |
| 65 } |
| 66 } |
| 67 |
| 19 // Installs Chrome. | 68 // Installs Chrome. |
| 20 void ChromeMiniInstaller::Install() { | 69 void ChromeMiniInstaller::Install() { |
| 21 std::wstring installer_path = MiniInstallerTestUtil::GetFilePath( | 70 std::wstring installer_path = MiniInstallerTestUtil::GetFilePath( |
| 22 mini_installer_constants::kChromeMiniInstallerExecutable); | 71 mini_installer_constants::kChromeMiniInstallerExecutable); |
| 23 InstallMiniInstaller(false, installer_path); | 72 InstallMiniInstaller(false, installer_path); |
| 24 } | 73 } |
| 25 | 74 |
| 26 // This method will get the previous latest full installer from | 75 // This method will get the previous latest full installer from |
| 27 // nightly location, install it and over install with specified install_type. | 76 // nightly location, install it and over install with specified install_type. |
| 28 void ChromeMiniInstaller::OverInstallOnFullInstaller( | 77 void ChromeMiniInstaller::OverInstallOnFullInstaller( |
| 29 const std::wstring& install_type, const wchar_t* channel_type) { | 78 const std::wstring& install_type) { |
| 30 std::wstring diff_installer; | 79 ASSERT_TRUE(has_full_installer_ && has_diff_installer_ && |
| 31 ASSERT_TRUE(MiniInstallerTestUtil::GetInstaller( | 80 has_prev_installer_); |
| 32 mini_installer_constants::kDiffInstallerPattern, | 81 |
| 33 &diff_installer, channel_type)); | 82 InstallMiniInstaller(false, prev_installer_); |
| 34 std::wstring prev_full_installer; | 83 |
| 35 ASSERT_TRUE(MiniInstallerTestUtil::GetPreviousFullInstaller( | 84 std::wstring got_prev_version; |
| 36 diff_installer, &prev_full_installer, channel_type)); | 85 GetChromeVersionFromRegistry(&got_prev_version); |
| 37 printf("\nPrevious full installer name is %ls\n", | |
| 38 prev_full_installer.c_str()); | |
| 39 InstallMiniInstaller(false, prev_full_installer); | |
| 40 std::wstring full_installer_value; | |
| 41 GetChromeVersionFromRegistry(&full_installer_value); | |
| 42 printf("\n\nPreparing to overinstall...\n"); | 86 printf("\n\nPreparing to overinstall...\n"); |
| 87 |
| 43 if (install_type == mini_installer_constants::kDiffInstall) { | 88 if (install_type == mini_installer_constants::kDiffInstall) { |
| 44 printf("\nOver installing with latest differential installer: %ls\n", | 89 printf("\nOver installing with latest differential installer: %ls\n", |
| 45 diff_installer.c_str()); | 90 diff_installer_.c_str()); |
| 46 InstallMiniInstaller(true, diff_installer); | 91 InstallMiniInstaller(true, diff_installer_); |
| 92 |
| 47 } else if (install_type == mini_installer_constants::kFullInstall) { | 93 } else if (install_type == mini_installer_constants::kFullInstall) { |
| 48 std::wstring latest_full_installer; | |
| 49 ASSERT_TRUE(MiniInstallerTestUtil::GetInstaller( | |
| 50 mini_installer_constants::kFullInstallerPattern, | |
| 51 &latest_full_installer, channel_type)); | |
| 52 printf("\nOver installing with latest full insatller: %ls\n", | 94 printf("\nOver installing with latest full insatller: %ls\n", |
| 53 latest_full_installer.c_str()); | 95 full_installer_.c_str()); |
| 54 InstallMiniInstaller(true, latest_full_installer); | 96 InstallMiniInstaller(true, full_installer_); |
| 55 } | 97 } |
| 56 std::wstring diff_installer_value; | |
| 57 GetChromeVersionFromRegistry(&diff_installer_value); | |
| 58 ASSERT_TRUE(VerifyDifferentialInstall(full_installer_value, | |
| 59 diff_installer_value, diff_installer, channel_type)); | |
| 60 } | |
| 61 | 98 |
| 62 // This method will get the diff installer file name and | 99 std::wstring got_curr_version; |
| 63 // then derives the previous and latest build numbers. | 100 GetChromeVersionFromRegistry(&got_curr_version); |
| 64 bool ChromeMiniInstaller::VerifyDifferentialInstall( | 101 |
| 65 const std::wstring& full_installer_value, | 102 if (got_prev_version == prev_version_ && |
| 66 const std::wstring& diff_installer_value, | 103 got_curr_version == curr_version_) { |
| 67 const std::wstring& diff_path, | 104 printf("\n The over install was successful. Here are the values:\n"); |
| 68 const wchar_t* channel_type) { | |
| 69 std::wstring actual_full_installer_value; | |
| 70 std::wstring diff_installer_name = file_util::GetFilenameFromPath(diff_path); | |
| 71 MiniInstallerTestUtil::GetPreviousBuildNumber(diff_path, | |
| 72 &actual_full_installer_value, channel_type); | |
| 73 // This substring will give the full installer build number. | |
| 74 std::wstring actual_diff_installer_value; | |
| 75 actual_diff_installer_value.assign(channel_type); | |
| 76 // This substring will give the diff installer build number. | |
| 77 actual_diff_installer_value.append(diff_installer_name.substr(0, | |
| 78 diff_installer_name.find(L'_'))); | |
| 79 if ((actual_full_installer_value == full_installer_value) && | |
| 80 (actual_diff_installer_value == diff_installer_value)) { | |
| 81 printf("\n The diff installer is successful. Here are the values:\n"); | |
| 82 printf("\n full installer value: %ls and diff installer value is %ls\n", | 105 printf("\n full installer value: %ls and diff installer value is %ls\n", |
| 83 full_installer_value.c_str(), diff_installer_value.c_str()); | 106 prev_version_.c_str(), curr_version_.c_str()); |
| 84 return true; | |
| 85 } else { | 107 } else { |
| 86 printf("\n The diff installer is not successful. Here are the values:\n"); | 108 printf("\n The over install was not successful. Here are the values:\n"); |
| 87 printf("\n Expected full installer value: %ls and actual value is %ls\n", | 109 printf("\n Expected full installer value: %ls and actual value is %ls\n", |
| 88 full_installer_value.c_str(), actual_full_installer_value.c_str()); | 110 prev_version_.c_str(), got_prev_version.c_str()); |
| 89 printf("\n Expected diff installer value: %ls and actual value is %ls\n", | 111 printf("\n Expected diff installer value: %ls and actual value is %ls\n", |
| 90 diff_installer_value.c_str(), actual_diff_installer_value.c_str()); | 112 curr_version_.c_str(), got_curr_version.c_str()); |
| 91 return false; | 113 FAIL(); |
| 92 } | 114 } |
| 93 } | 115 } |
| 94 | 116 |
| 117 |
| 95 // This method will get the latest full installer from nightly location | 118 // This method will get the latest full installer from nightly location |
| 96 // and installs it. | 119 // and installs it. |
| 97 void ChromeMiniInstaller::InstallFullInstaller(bool over_install, | 120 void ChromeMiniInstaller::InstallFullInstaller(bool over_install) { |
| 98 const wchar_t* channel_type) { | 121 ASSERT_TRUE(has_full_installer_); |
| 99 std::wstring full_installer_file_name; | 122 InstallMiniInstaller(over_install, full_installer_); |
| 100 ASSERT_TRUE(MiniInstallerTestUtil::GetInstaller( | |
| 101 mini_installer_constants::kFullInstallerPattern, | |
| 102 &full_installer_file_name, channel_type)); | |
| 103 printf("The latest full installer is %ls\n\n", | |
| 104 full_installer_file_name.c_str()); | |
| 105 InstallMiniInstaller(over_install, full_installer_file_name); | |
| 106 } | 123 } |
| 107 | 124 |
| 108 // Installs the Chrome mini-installer, checks the registry and shortcuts. | 125 // Installs the Chrome mini-installer, checks the registry and shortcuts. |
| 109 void ChromeMiniInstaller::InstallMiniInstaller(bool over_install, | 126 void ChromeMiniInstaller::InstallMiniInstaller(bool over_install, |
| 110 const std::wstring& path) { | 127 const std::wstring& path) { |
| 111 std::wstring exe_name = file_util::GetFilenameFromPath(path); | 128 std::wstring exe_name = file_util::GetFilenameFromPath(path); |
| 112 printf("\nChrome will be installed at %ls level\n", install_type_.c_str()); | 129 printf("\nChrome will be installed at %ls level\n", install_type_.c_str()); |
| 113 printf("\nWill proceed with the test only if this path exists: %ls\n\n", | 130 printf("\nWill proceed with the test only if this path exists: %ls\n\n", |
| 114 path.c_str()); | 131 path.c_str()); |
| 115 ASSERT_TRUE(file_util::PathExists(FilePath::FromWStringHack(path))); | 132 ASSERT_TRUE(file_util::PathExists(FilePath::FromWStringHack(path))); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 ASSERT_TRUE(CheckRegistryKey(chrome_google_update_state_key)); | 177 ASSERT_TRUE(CheckRegistryKey(chrome_google_update_state_key)); |
| 161 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 178 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
| 162 ASSERT_TRUE(CheckRegistryKey(dist->GetVersionKey())); | 179 ASSERT_TRUE(CheckRegistryKey(dist->GetVersionKey())); |
| 163 FindChromeShortcut(); | 180 FindChromeShortcut(); |
| 164 LaunchAndCloseChrome(false); | 181 LaunchAndCloseChrome(false); |
| 165 } | 182 } |
| 166 | 183 |
| 167 // If the build type is Google Chrome, then it first installs meta installer | 184 // If the build type is Google Chrome, then it first installs meta installer |
| 168 // and then over installs with mini_installer. It also verifies if Chrome can | 185 // and then over installs with mini_installer. It also verifies if Chrome can |
| 169 // be launched successfully after overinstall. | 186 // be launched successfully after overinstall. |
| 170 void ChromeMiniInstaller::OverInstall(const wchar_t* channel_type) { | 187 void ChromeMiniInstaller::OverInstall() { |
| 171 InstallMetaInstaller(); | 188 InstallMetaInstaller(); |
| 172 std::wstring reg_key_value_returned; | 189 std::wstring reg_key_value_returned; |
| 173 // gets the registry key value before overinstall. | 190 // gets the registry key value before overinstall. |
| 174 GetChromeVersionFromRegistry(®_key_value_returned); | 191 GetChromeVersionFromRegistry(®_key_value_returned); |
| 175 printf("\n\nPreparing to overinstall...\n"); | 192 printf("\n\nPreparing to overinstall...\n"); |
| 176 InstallFullInstaller(true, channel_type); | 193 InstallFullInstaller(true); |
| 177 std::wstring reg_key_value_after_overinstall; | 194 std::wstring reg_key_value_after_overinstall; |
| 178 // Get the registry key value after over install | 195 // Get the registry key value after over install |
| 179 GetChromeVersionFromRegistry(®_key_value_after_overinstall); | 196 GetChromeVersionFromRegistry(®_key_value_after_overinstall); |
| 180 ASSERT_TRUE(VerifyOverInstall(reg_key_value_returned, | 197 ASSERT_TRUE(VerifyOverInstall(reg_key_value_returned, |
| 181 reg_key_value_after_overinstall)); | 198 reg_key_value_after_overinstall)); |
| 182 } | 199 } |
| 183 | 200 |
| 184 // This method will first install Chrome. Deletes either registry or | 201 // This method will first install Chrome. Deletes either registry or |
| 185 // folder based on the passed argument, then tries to launch Chrome. | 202 // folder based on the passed argument, then tries to launch Chrome. |
| 186 // Then installs Chrome again to repair. | 203 // Then installs Chrome again to repair. |
| 187 void ChromeMiniInstaller::Repair( | 204 void ChromeMiniInstaller::Repair( |
| 188 ChromeMiniInstaller::RepairChrome repair_type, | 205 ChromeMiniInstaller::RepairChrome repair_type) { |
| 189 const wchar_t* channel_type) { | 206 InstallFullInstaller(false); |
| 190 InstallFullInstaller(false, channel_type); | |
| 191 MiniInstallerTestUtil::CloseProcesses(installer_util::kChromeExe); | 207 MiniInstallerTestUtil::CloseProcesses(installer_util::kChromeExe); |
| 192 if (repair_type == ChromeMiniInstaller::VERSION_FOLDER) { | 208 if (repair_type == ChromeMiniInstaller::VERSION_FOLDER) { |
| 193 DeleteFolder(L"version_folder"); | 209 DeleteFolder(L"version_folder"); |
| 194 printf("Deleted folder. Now trying to launch chrome\n"); | 210 printf("Deleted folder. Now trying to launch chrome\n"); |
| 195 } else if (repair_type == ChromeMiniInstaller::REGISTRY) { | 211 } else if (repair_type == ChromeMiniInstaller::REGISTRY) { |
| 196 DeletePvRegistryKey(); | 212 DeletePvRegistryKey(); |
| 197 printf("Deleted registry. Now trying to launch chrome\n"); | 213 printf("Deleted registry. Now trying to launch chrome\n"); |
| 198 } | 214 } |
| 199 std::wstring current_path; | 215 std::wstring current_path; |
| 200 ASSERT_TRUE(MiniInstallerTestUtil::ChangeCurrentDirectory(¤t_path)); | 216 ASSERT_TRUE(MiniInstallerTestUtil::ChangeCurrentDirectory(¤t_path)); |
| 201 VerifyChromeLaunch(false); | 217 VerifyChromeLaunch(false); |
| 202 printf("\nInstalling Chrome again to see if it can be repaired\n\n"); | 218 printf("\nInstalling Chrome again to see if it can be repaired\n\n"); |
| 203 InstallFullInstaller(true, channel_type); | 219 InstallFullInstaller(true); |
| 204 printf("Chrome repair successful.\n"); | 220 printf("Chrome repair successful.\n"); |
| 205 // Set the current directory back to original path. | 221 // Set the current directory back to original path. |
| 206 ::SetCurrentDirectory(current_path.c_str()); | 222 ::SetCurrentDirectory(current_path.c_str()); |
| 207 } | 223 } |
| 208 | 224 |
| 209 // This method first checks if Chrome is running. | 225 // This method first checks if Chrome is running. |
| 210 // If yes, will close all the processes. | 226 // If yes, will close all the processes. |
| 211 // Then will find and spawn uninstall path. | 227 // Then will find and spawn uninstall path. |
| 212 // Handles uninstall confirm dialog. | 228 // Handles uninstall confirm dialog. |
| 213 // Waits until setup.exe ends. | 229 // Waits until setup.exe ends. |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 // This method will verify if the installed build is correct. | 565 // This method will verify if the installed build is correct. |
| 550 bool ChromeMiniInstaller::VerifyStandaloneInstall() { | 566 bool ChromeMiniInstaller::VerifyStandaloneInstall() { |
| 551 std::wstring reg_key_value_returned, standalone_installer_version; | 567 std::wstring reg_key_value_returned, standalone_installer_version; |
| 552 MiniInstallerTestUtil::GetStandaloneVersion(&standalone_installer_version); | 568 MiniInstallerTestUtil::GetStandaloneVersion(&standalone_installer_version); |
| 553 GetChromeVersionFromRegistry(®_key_value_returned); | 569 GetChromeVersionFromRegistry(®_key_value_returned); |
| 554 if (standalone_installer_version.compare(reg_key_value_returned) == 0) | 570 if (standalone_installer_version.compare(reg_key_value_returned) == 0) |
| 555 return true; | 571 return true; |
| 556 else | 572 else |
| 557 return false; | 573 return false; |
| 558 } | 574 } |
| OLD | NEW |