| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/installer/util/installer_state.h" | 5 #include "chrome/installer/util/installer_state.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <fstream> | 10 #include <fstream> |
| 11 | 11 |
| 12 #include "base/base_paths.h" | 12 #include "base/base_paths.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_enumerator.h" | |
| 15 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 16 #include "base/files/file_util.h" | 15 #include "base/files/file_util.h" |
| 17 #include "base/files/scoped_temp_dir.h" | 16 #include "base/files/scoped_temp_dir.h" |
| 18 #include "base/macros.h" | 17 #include "base/macros.h" |
| 19 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 20 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/test/scoped_path_override.h" | 21 #include "base/test/scoped_path_override.h" |
| 23 #include "base/test/test_reg_util_win.h" | 22 #include "base/test/test_reg_util_win.h" |
| 24 #include "base/version.h" | 23 #include "base/version.h" |
| 25 #include "base/win/registry.h" | 24 #include "base/win/registry.h" |
| 26 #include "base/win/scoped_handle.h" | 25 #include "base/win/scoped_handle.h" |
| 27 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/installer/test/alternate_version_generator.h" | |
| 29 #include "chrome/installer/util/fake_installation_state.h" | 27 #include "chrome/installer/util/fake_installation_state.h" |
| 30 #include "chrome/installer/util/fake_product_state.h" | 28 #include "chrome/installer/util/fake_product_state.h" |
| 31 #include "chrome/installer/util/google_update_constants.h" | 29 #include "chrome/installer/util/google_update_constants.h" |
| 32 #include "chrome/installer/util/helper.h" | 30 #include "chrome/installer/util/helper.h" |
| 33 #include "chrome/installer/util/installation_state.h" | 31 #include "chrome/installer/util/installation_state.h" |
| 34 #include "chrome/installer/util/installer_util_strings.h" | 32 #include "chrome/installer/util/installer_util_strings.h" |
| 35 #include "chrome/installer/util/master_preferences.h" | 33 #include "chrome/installer/util/master_preferences.h" |
| 36 #include "chrome/installer/util/util_constants.h" | 34 #include "chrome/installer/util/util_constants.h" |
| 37 #include "chrome/installer/util/work_item.h" | 35 #include "chrome/installer/util/work_item.h" |
| 38 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 MockInstallerState() : InstallerState() { } | 61 MockInstallerState() : InstallerState() { } |
| 64 void set_target_path(const base::FilePath& target_path) { | 62 void set_target_path(const base::FilePath& target_path) { |
| 65 target_path_ = target_path; | 63 target_path_ = target_path; |
| 66 } | 64 } |
| 67 static bool IsFileInUse(const base::FilePath& file) { | 65 static bool IsFileInUse(const base::FilePath& file) { |
| 68 return InstallerState::IsFileInUse(file); | 66 return InstallerState::IsFileInUse(file); |
| 69 } | 67 } |
| 70 const base::Version& critical_update_version() const { | 68 const base::Version& critical_update_version() const { |
| 71 return critical_update_version_; | 69 return critical_update_version_; |
| 72 } | 70 } |
| 73 void GetExistingExeVersions(std::set<std::string>* existing_version_strings) { | |
| 74 return InstallerState::GetExistingExeVersions(existing_version_strings); | |
| 75 } | |
| 76 }; | 71 }; |
| 77 | 72 |
| 78 // Simple function to dump some text into a new file. | |
| 79 void CreateTextFile(const std::wstring& filename, | |
| 80 const std::wstring& contents) { | |
| 81 std::ofstream file; | |
| 82 file.open(filename.c_str()); | |
| 83 ASSERT_TRUE(file.is_open()); | |
| 84 file << contents; | |
| 85 file.close(); | |
| 86 } | |
| 87 | |
| 88 void BuildSingleChromeState(const base::FilePath& target_dir, | |
| 89 MockInstallerState* installer_state) { | |
| 90 base::CommandLine cmd_line = base::CommandLine::FromString(L"setup.exe"); | |
| 91 MasterPreferences prefs(cmd_line); | |
| 92 InstallationState machine_state; | |
| 93 machine_state.Initialize(); | |
| 94 installer_state->Initialize(cmd_line, prefs, machine_state); | |
| 95 installer_state->set_target_path(target_dir); | |
| 96 EXPECT_TRUE(installer_state->FindProduct(BrowserDistribution::CHROME_BROWSER) | |
| 97 != NULL); | |
| 98 } | |
| 99 | |
| 100 wchar_t text_content_1[] = L"delete me"; | |
| 101 wchar_t text_content_2[] = L"delete me as well"; | |
| 102 | |
| 103 // Delete version directories. Everything lower than the given version | |
| 104 // should be deleted. | |
| 105 TEST_F(InstallerStateTest, Delete) { | |
| 106 // TODO(grt): move common stuff into the test fixture. | |
| 107 // Create a Chrome dir | |
| 108 base::FilePath chrome_dir(test_dir_.path()); | |
| 109 chrome_dir = chrome_dir.AppendASCII("chrome"); | |
| 110 base::CreateDirectory(chrome_dir); | |
| 111 ASSERT_TRUE(base::PathExists(chrome_dir)); | |
| 112 | |
| 113 base::FilePath chrome_dir_1(chrome_dir); | |
| 114 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0"); | |
| 115 base::CreateDirectory(chrome_dir_1); | |
| 116 ASSERT_TRUE(base::PathExists(chrome_dir_1)); | |
| 117 | |
| 118 base::FilePath chrome_dir_2(chrome_dir); | |
| 119 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0"); | |
| 120 base::CreateDirectory(chrome_dir_2); | |
| 121 ASSERT_TRUE(base::PathExists(chrome_dir_2)); | |
| 122 | |
| 123 base::FilePath chrome_dir_3(chrome_dir); | |
| 124 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0"); | |
| 125 base::CreateDirectory(chrome_dir_3); | |
| 126 ASSERT_TRUE(base::PathExists(chrome_dir_3)); | |
| 127 | |
| 128 base::FilePath chrome_dir_4(chrome_dir); | |
| 129 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0"); | |
| 130 base::CreateDirectory(chrome_dir_4); | |
| 131 ASSERT_TRUE(base::PathExists(chrome_dir_4)); | |
| 132 | |
| 133 base::FilePath chrome_dll_1(chrome_dir_1); | |
| 134 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll"); | |
| 135 CreateTextFile(chrome_dll_1.value(), text_content_1); | |
| 136 ASSERT_TRUE(base::PathExists(chrome_dll_1)); | |
| 137 | |
| 138 base::FilePath chrome_dll_2(chrome_dir_2); | |
| 139 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll"); | |
| 140 CreateTextFile(chrome_dll_2.value(), text_content_1); | |
| 141 ASSERT_TRUE(base::PathExists(chrome_dll_2)); | |
| 142 | |
| 143 base::FilePath chrome_dll_3(chrome_dir_3); | |
| 144 chrome_dll_3 = chrome_dll_3.AppendASCII("chrome.dll"); | |
| 145 CreateTextFile(chrome_dll_3.value(), text_content_1); | |
| 146 ASSERT_TRUE(base::PathExists(chrome_dll_3)); | |
| 147 | |
| 148 base::FilePath chrome_dll_4(chrome_dir_4); | |
| 149 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); | |
| 150 CreateTextFile(chrome_dll_4.value(), text_content_1); | |
| 151 ASSERT_TRUE(base::PathExists(chrome_dll_4)); | |
| 152 | |
| 153 MockInstallerState installer_state; | |
| 154 BuildSingleChromeState(chrome_dir, &installer_state); | |
| 155 base::Version latest_version("1.0.4.0"); | |
| 156 { | |
| 157 base::ScopedTempDir temp_dir; | |
| 158 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 159 installer_state.RemoveOldVersionDirectories(latest_version, NULL, | |
| 160 temp_dir.path()); | |
| 161 } | |
| 162 | |
| 163 // old versions should be gone | |
| 164 EXPECT_FALSE(base::PathExists(chrome_dir_1)); | |
| 165 EXPECT_FALSE(base::PathExists(chrome_dir_2)); | |
| 166 EXPECT_FALSE(base::PathExists(chrome_dir_3)); | |
| 167 // the latest version should stay | |
| 168 EXPECT_TRUE(base::PathExists(chrome_dll_4)); | |
| 169 } | |
| 170 | |
| 171 // Delete older version directories, keeping the one in used intact. | |
| 172 TEST_F(InstallerStateTest, DeleteInUsed) { | |
| 173 // Create a Chrome dir | |
| 174 base::FilePath chrome_dir(test_dir_.path()); | |
| 175 chrome_dir = chrome_dir.AppendASCII("chrome"); | |
| 176 base::CreateDirectory(chrome_dir); | |
| 177 ASSERT_TRUE(base::PathExists(chrome_dir)); | |
| 178 | |
| 179 base::FilePath chrome_dir_1(chrome_dir); | |
| 180 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0"); | |
| 181 base::CreateDirectory(chrome_dir_1); | |
| 182 ASSERT_TRUE(base::PathExists(chrome_dir_1)); | |
| 183 | |
| 184 base::FilePath chrome_dir_2(chrome_dir); | |
| 185 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0"); | |
| 186 base::CreateDirectory(chrome_dir_2); | |
| 187 ASSERT_TRUE(base::PathExists(chrome_dir_2)); | |
| 188 | |
| 189 base::FilePath chrome_dir_3(chrome_dir); | |
| 190 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0"); | |
| 191 base::CreateDirectory(chrome_dir_3); | |
| 192 ASSERT_TRUE(base::PathExists(chrome_dir_3)); | |
| 193 | |
| 194 base::FilePath chrome_dir_4(chrome_dir); | |
| 195 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0"); | |
| 196 base::CreateDirectory(chrome_dir_4); | |
| 197 ASSERT_TRUE(base::PathExists(chrome_dir_4)); | |
| 198 | |
| 199 base::FilePath chrome_dll_1(chrome_dir_1); | |
| 200 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll"); | |
| 201 CreateTextFile(chrome_dll_1.value(), text_content_1); | |
| 202 ASSERT_TRUE(base::PathExists(chrome_dll_1)); | |
| 203 | |
| 204 base::FilePath chrome_dll_2(chrome_dir_2); | |
| 205 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll"); | |
| 206 CreateTextFile(chrome_dll_2.value(), text_content_1); | |
| 207 ASSERT_TRUE(base::PathExists(chrome_dll_2)); | |
| 208 | |
| 209 // Open the file to make it in use. | |
| 210 std::ofstream file; | |
| 211 file.open(chrome_dll_2.value().c_str()); | |
| 212 | |
| 213 base::FilePath chrome_othera_2(chrome_dir_2); | |
| 214 chrome_othera_2 = chrome_othera_2.AppendASCII("othera.dll"); | |
| 215 CreateTextFile(chrome_othera_2.value(), text_content_2); | |
| 216 ASSERT_TRUE(base::PathExists(chrome_othera_2)); | |
| 217 | |
| 218 base::FilePath chrome_otherb_2(chrome_dir_2); | |
| 219 chrome_otherb_2 = chrome_otherb_2.AppendASCII("otherb.dll"); | |
| 220 CreateTextFile(chrome_otherb_2.value(), text_content_2); | |
| 221 ASSERT_TRUE(base::PathExists(chrome_otherb_2)); | |
| 222 | |
| 223 base::FilePath chrome_dll_3(chrome_dir_3); | |
| 224 chrome_dll_3 = chrome_dll_3.AppendASCII("chrome.dll"); | |
| 225 CreateTextFile(chrome_dll_3.value(), text_content_1); | |
| 226 ASSERT_TRUE(base::PathExists(chrome_dll_3)); | |
| 227 | |
| 228 base::FilePath chrome_dll_4(chrome_dir_4); | |
| 229 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); | |
| 230 CreateTextFile(chrome_dll_4.value(), text_content_1); | |
| 231 ASSERT_TRUE(base::PathExists(chrome_dll_4)); | |
| 232 | |
| 233 MockInstallerState installer_state; | |
| 234 BuildSingleChromeState(chrome_dir, &installer_state); | |
| 235 base::Version latest_version("1.0.4.0"); | |
| 236 base::Version existing_version("1.0.1.0"); | |
| 237 { | |
| 238 base::ScopedTempDir temp_dir; | |
| 239 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 240 installer_state.RemoveOldVersionDirectories(latest_version, | |
| 241 &existing_version, | |
| 242 temp_dir.path()); | |
| 243 } | |
| 244 | |
| 245 // the version defined as the existing version should stay | |
| 246 EXPECT_TRUE(base::PathExists(chrome_dir_1)); | |
| 247 // old versions not in used should be gone | |
| 248 EXPECT_FALSE(base::PathExists(chrome_dir_3)); | |
| 249 // every thing under in used version should stay | |
| 250 EXPECT_TRUE(base::PathExists(chrome_dir_2)); | |
| 251 EXPECT_TRUE(base::PathExists(chrome_dll_2)); | |
| 252 EXPECT_TRUE(base::PathExists(chrome_othera_2)); | |
| 253 EXPECT_TRUE(base::PathExists(chrome_otherb_2)); | |
| 254 // the latest version should stay | |
| 255 EXPECT_TRUE(base::PathExists(chrome_dll_4)); | |
| 256 } | |
| 257 | |
| 258 // Tests a few basic things of the Package class. Makes sure that the path | |
| 259 // operations are correct | |
| 260 TEST_F(InstallerStateTest, Basic) { | |
| 261 const bool multi_install = false; | |
| 262 const bool system_level = true; | |
| 263 base::CommandLine cmd_line = base::CommandLine::FromString( | |
| 264 std::wstring(L"setup.exe") + | |
| 265 (multi_install ? L" --multi-install --chrome" : L"") + | |
| 266 (system_level ? L" --system-level" : L"")); | |
| 267 MasterPreferences prefs(cmd_line); | |
| 268 InstallationState machine_state; | |
| 269 machine_state.Initialize(); | |
| 270 MockInstallerState installer_state; | |
| 271 installer_state.Initialize(cmd_line, prefs, machine_state); | |
| 272 installer_state.set_target_path(test_dir_.path()); | |
| 273 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); | |
| 274 EXPECT_EQ(1U, installer_state.products().size()); | |
| 275 | |
| 276 const char kOldVersion[] = "1.2.3.4"; | |
| 277 const char kNewVersion[] = "2.3.4.5"; | |
| 278 | |
| 279 base::Version new_version(kNewVersion); | |
| 280 base::Version old_version(kOldVersion); | |
| 281 ASSERT_TRUE(new_version.IsValid()); | |
| 282 ASSERT_TRUE(old_version.IsValid()); | |
| 283 | |
| 284 base::FilePath installer_dir( | |
| 285 installer_state.GetInstallerDirectory(new_version)); | |
| 286 EXPECT_FALSE(installer_dir.empty()); | |
| 287 | |
| 288 base::FilePath new_version_dir(installer_state.target_path().Append( | |
| 289 base::UTF8ToWide(new_version.GetString()))); | |
| 290 base::FilePath old_version_dir(installer_state.target_path().Append( | |
| 291 base::UTF8ToWide(old_version.GetString()))); | |
| 292 | |
| 293 EXPECT_FALSE(base::PathExists(new_version_dir)); | |
| 294 EXPECT_FALSE(base::PathExists(old_version_dir)); | |
| 295 | |
| 296 EXPECT_FALSE(base::PathExists(installer_dir)); | |
| 297 base::CreateDirectory(installer_dir); | |
| 298 EXPECT_TRUE(base::PathExists(new_version_dir)); | |
| 299 | |
| 300 base::CreateDirectory(old_version_dir); | |
| 301 EXPECT_TRUE(base::PathExists(old_version_dir)); | |
| 302 | |
| 303 // Create a fake chrome.dll key file in the old version directory. This | |
| 304 // should prevent the old version directory from getting deleted. | |
| 305 base::FilePath old_chrome_dll(old_version_dir.Append(installer::kChromeDll)); | |
| 306 EXPECT_FALSE(base::PathExists(old_chrome_dll)); | |
| 307 | |
| 308 // Hold on to the file exclusively to prevent the directory from | |
| 309 // being deleted. | |
| 310 base::win::ScopedHandle file( | |
| 311 ::CreateFile(old_chrome_dll.value().c_str(), GENERIC_READ, | |
| 312 0, NULL, OPEN_ALWAYS, 0, NULL)); | |
| 313 EXPECT_TRUE(file.IsValid()); | |
| 314 EXPECT_TRUE(base::PathExists(old_chrome_dll)); | |
| 315 | |
| 316 base::ScopedTempDir temp_dir; | |
| 317 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
| 318 | |
| 319 // Don't explicitly tell the directory cleanup logic not to delete the | |
| 320 // old version, rely on the key files to keep it around. | |
| 321 installer_state.RemoveOldVersionDirectories(new_version, | |
| 322 NULL, | |
| 323 temp_dir.path()); | |
| 324 | |
| 325 // The old directory should still exist. | |
| 326 EXPECT_TRUE(base::PathExists(old_version_dir)); | |
| 327 EXPECT_TRUE(base::PathExists(new_version_dir)); | |
| 328 | |
| 329 // Now close the file handle to make it possible to delete our key file. | |
| 330 file.Close(); | |
| 331 | |
| 332 installer_state.RemoveOldVersionDirectories(new_version, | |
| 333 NULL, | |
| 334 temp_dir.path()); | |
| 335 // The new directory should still exist. | |
| 336 EXPECT_TRUE(base::PathExists(new_version_dir)); | |
| 337 | |
| 338 // Now, the old directory and key file should be gone. | |
| 339 EXPECT_FALSE(base::PathExists(old_chrome_dll)); | |
| 340 EXPECT_FALSE(base::PathExists(old_version_dir)); | |
| 341 } | |
| 342 | |
| 343 TEST_F(InstallerStateTest, WithProduct) { | 73 TEST_F(InstallerStateTest, WithProduct) { |
| 344 const bool multi_install = false; | 74 const bool multi_install = false; |
| 345 const bool system_level = true; | 75 const bool system_level = true; |
| 346 base::CommandLine cmd_line = base::CommandLine::FromString( | 76 base::CommandLine cmd_line = base::CommandLine::FromString( |
| 347 std::wstring(L"setup.exe") + | 77 std::wstring(L"setup.exe") + |
| 348 (multi_install ? L" --multi-install --chrome" : L"") + | 78 (multi_install ? L" --multi-install --chrome" : L"") + |
| 349 (system_level ? L" --system-level" : L"")); | 79 (system_level ? L" --system-level" : L"")); |
| 350 MasterPreferences prefs(cmd_line); | 80 MasterPreferences prefs(cmd_line); |
| 351 InstallationState machine_state; | 81 InstallationState machine_state; |
| 352 machine_state.Initialize(); | 82 machine_state.Initialize(); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 217 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 488 | 218 |
| 489 base::FilePath temp_file; | 219 base::FilePath temp_file; |
| 490 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); | 220 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); |
| 491 | 221 |
| 492 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); | 222 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); |
| 493 | 223 |
| 494 { | 224 { |
| 495 // Open a handle to the file with the same access mode and sharing options | 225 // Open a handle to the file with the same access mode and sharing options |
| 496 // as the loader. | 226 // as the loader. |
| 497 base::win::ScopedHandle temp_handle( | 227 base::win::ScopedHandle temp_handle(CreateFile( |
| 498 CreateFile(temp_file.value().c_str(), | 228 temp_file.value().c_str(), SYNCHRONIZE | FILE_EXECUTE, |
| 499 SYNCHRONIZE | FILE_EXECUTE, | 229 FILE_SHARE_DELETE | FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0)); |
| 500 FILE_SHARE_DELETE | FILE_SHARE_READ, | |
| 501 NULL, OPEN_EXISTING, 0, 0)); | |
| 502 ASSERT_TRUE(temp_handle.IsValid()); | 230 ASSERT_TRUE(temp_handle.IsValid()); |
| 503 | 231 |
| 504 // The file should now be in use. | 232 // The file should now be in use. |
| 505 EXPECT_TRUE(MockInstallerState::IsFileInUse(temp_file)); | 233 EXPECT_TRUE(MockInstallerState::IsFileInUse(temp_file)); |
| 506 } | 234 } |
| 507 | 235 |
| 508 // And once the handle is gone, it should no longer be in use. | 236 // And once the handle is gone, it should no longer be in use. |
| 509 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); | 237 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); |
| 510 } | 238 } |
| 511 | 239 |
| 512 TEST_F(InstallerStateTest, RemoveOldVersionDirs) { | |
| 513 MockInstallerState installer_state; | |
| 514 installer_state.set_target_path(test_dir_.path()); | |
| 515 EXPECT_EQ(test_dir_.path().value(), installer_state.target_path().value()); | |
| 516 | |
| 517 const char kOldVersion[] = "2.0.0.0"; | |
| 518 const char kNewVersion[] = "3.0.0.0"; | |
| 519 const char kOldChromeExeVersion[] = "2.1.0.0"; | |
| 520 const char kChromeExeVersion[] = "2.1.1.1"; | |
| 521 const char kNewChromeExeVersion[] = "3.0.0.0"; | |
| 522 | |
| 523 base::Version new_version(kNewVersion); | |
| 524 base::Version old_version(kOldVersion); | |
| 525 base::Version old_chrome_exe_version(kOldChromeExeVersion); | |
| 526 base::Version chrome_exe_version(kChromeExeVersion); | |
| 527 base::Version new_chrome_exe_version(kNewChromeExeVersion); | |
| 528 | |
| 529 ASSERT_TRUE(new_version.IsValid()); | |
| 530 ASSERT_TRUE(old_version.IsValid()); | |
| 531 ASSERT_TRUE(old_chrome_exe_version.IsValid()); | |
| 532 ASSERT_TRUE(chrome_exe_version.IsValid()); | |
| 533 ASSERT_TRUE(new_chrome_exe_version.IsValid()); | |
| 534 | |
| 535 // Set up a bunch of version dir paths. | |
| 536 base::FilePath version_dirs[] = { | |
| 537 installer_state.target_path().Append(L"1.2.3.4"), | |
| 538 installer_state.target_path().Append(L"1.2.3.5"), | |
| 539 installer_state.target_path().Append(L"1.2.3.6"), | |
| 540 installer_state.target_path().AppendASCII(kOldVersion), | |
| 541 installer_state.target_path().AppendASCII(kOldChromeExeVersion), | |
| 542 installer_state.target_path().Append(L"2.1.1.0"), | |
| 543 installer_state.target_path().AppendASCII(kChromeExeVersion), | |
| 544 installer_state.target_path().AppendASCII(kNewVersion), | |
| 545 installer_state.target_path().Append(L"3.9.1.1"), | |
| 546 }; | |
| 547 | |
| 548 // Create the version directories. | |
| 549 for (size_t i = 0; i < arraysize(version_dirs); i++) { | |
| 550 base::CreateDirectory(version_dirs[i]); | |
| 551 EXPECT_TRUE(base::PathExists(version_dirs[i])); | |
| 552 } | |
| 553 | |
| 554 // Create exes with the appropriate version resource. | |
| 555 // Use the current test exe as a baseline. | |
| 556 base::FilePath exe_path; | |
| 557 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); | |
| 558 | |
| 559 struct target_info { | |
| 560 base::FilePath target_file; | |
| 561 const base::Version& target_version; | |
| 562 } targets[] = { | |
| 563 { installer_state.target_path().Append(installer::kChromeOldExe), | |
| 564 old_chrome_exe_version }, | |
| 565 { installer_state.target_path().Append(installer::kChromeExe), | |
| 566 chrome_exe_version }, | |
| 567 { installer_state.target_path().Append(installer::kChromeNewExe), | |
| 568 new_chrome_exe_version }, | |
| 569 }; | |
| 570 for (size_t i = 0; i < arraysize(targets); ++i) { | |
| 571 ASSERT_TRUE(upgrade_test::GenerateSpecificPEFileVersion( | |
| 572 exe_path, targets[i].target_file, targets[i].target_version)); | |
| 573 } | |
| 574 | |
| 575 // Call GetExistingExeVersions, validate that picks up the | |
| 576 // exe resources. | |
| 577 std::set<std::string> expected_exe_versions; | |
| 578 expected_exe_versions.insert(kOldChromeExeVersion); | |
| 579 expected_exe_versions.insert(kChromeExeVersion); | |
| 580 expected_exe_versions.insert(kNewChromeExeVersion); | |
| 581 | |
| 582 std::set<std::string> actual_exe_versions; | |
| 583 installer_state.GetExistingExeVersions(&actual_exe_versions); | |
| 584 EXPECT_EQ(expected_exe_versions, actual_exe_versions); | |
| 585 | |
| 586 // Call RemoveOldVersionDirectories | |
| 587 installer_state.RemoveOldVersionDirectories(new_version, | |
| 588 &old_version, | |
| 589 installer_state.target_path()); | |
| 590 | |
| 591 // What we expect to have left. | |
| 592 std::set<std::string> expected_remaining_dirs; | |
| 593 expected_remaining_dirs.insert(kOldVersion); | |
| 594 expected_remaining_dirs.insert(kNewVersion); | |
| 595 expected_remaining_dirs.insert(kOldChromeExeVersion); | |
| 596 expected_remaining_dirs.insert(kChromeExeVersion); | |
| 597 expected_remaining_dirs.insert(kNewChromeExeVersion); | |
| 598 | |
| 599 // Enumerate dirs in target_path(), ensure only desired remain. | |
| 600 base::FileEnumerator version_enum(installer_state.target_path(), false, | |
| 601 base::FileEnumerator::DIRECTORIES); | |
| 602 for (base::FilePath next_version = version_enum.Next(); !next_version.empty(); | |
| 603 next_version = version_enum.Next()) { | |
| 604 base::FilePath dir_name(next_version.BaseName()); | |
| 605 base::Version version(base::UTF16ToASCII(dir_name.value())); | |
| 606 if (version.IsValid()) { | |
| 607 EXPECT_TRUE(expected_remaining_dirs.erase(version.GetString())) | |
| 608 << "Unexpected version dir found: " << version.GetString(); | |
| 609 } | |
| 610 } | |
| 611 | |
| 612 std::set<std::string>::const_iterator iter( | |
| 613 expected_remaining_dirs.begin()); | |
| 614 for (; iter != expected_remaining_dirs.end(); ++iter) | |
| 615 ADD_FAILURE() << "Expected to find version dir for " << *iter; | |
| 616 } | |
| 617 | |
| 618 TEST_F(InstallerStateTest, InitializeTwice) { | 240 TEST_F(InstallerStateTest, InitializeTwice) { |
| 619 // Override these paths so that they can be found after the registry override | 241 // Override these paths so that they can be found after the registry override |
| 620 // manager is in place. | 242 // manager is in place. |
| 621 base::FilePath temp; | 243 base::FilePath temp; |
| 622 PathService::Get(base::DIR_PROGRAM_FILES, &temp); | 244 PathService::Get(base::DIR_PROGRAM_FILES, &temp); |
| 623 base::ScopedPathOverride program_files_override(base::DIR_PROGRAM_FILES, | 245 base::ScopedPathOverride program_files_override(base::DIR_PROGRAM_FILES, |
| 624 temp); | 246 temp); |
| 625 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp); | 247 PathService::Get(base::DIR_PROGRAM_FILESX86, &temp); |
| 626 base::ScopedPathOverride program_filesx86_override(base::DIR_PROGRAM_FILESX86, | 248 base::ScopedPathOverride program_filesx86_override(base::DIR_PROGRAM_FILESX86, |
| 627 temp); | 249 temp); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 // Critical update newer than the new version. | 449 // Critical update newer than the new version. |
| 828 EXPECT_FALSE( | 450 EXPECT_FALSE( |
| 829 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); | 451 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); |
| 830 EXPECT_FALSE( | 452 EXPECT_FALSE( |
| 831 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) | 453 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) |
| 832 .IsValid()); | 454 .IsValid()); |
| 833 EXPECT_FALSE( | 455 EXPECT_FALSE( |
| 834 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) | 456 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) |
| 835 .IsValid()); | 457 .IsValid()); |
| 836 } | 458 } |
| OLD | NEW |