OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 | 8 |
9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/process_util.h" | 13 #include "base/process_util.h" |
| 14 #include "base/scoped_temp_dir.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
16 #include "base/version.h" | 17 #include "base/version.h" |
17 #include "base/win/registry.h" | 18 #include "base/win/registry.h" |
18 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
19 #include "chrome/installer/util/google_update_constants.h" | 20 #include "chrome/installer/util/google_update_constants.h" |
20 #include "chrome/installer/util/helper.h" | 21 #include "chrome/installer/util/helper.h" |
21 #include "chrome/installer/util/installation_state.h" | 22 #include "chrome/installer/util/installation_state.h" |
22 #include "chrome/installer/util/installer_state.h" | 23 #include "chrome/installer/util/installer_state.h" |
23 #include "chrome/installer/util/master_preferences.h" | 24 #include "chrome/installer/util/master_preferences.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 ASSERT_TRUE(file_util::PathExists(chrome_dll_3)); | 112 ASSERT_TRUE(file_util::PathExists(chrome_dll_3)); |
112 | 113 |
113 FilePath chrome_dll_4(chrome_dir_4); | 114 FilePath chrome_dll_4(chrome_dir_4); |
114 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); | 115 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); |
115 CreateTextFile(chrome_dll_4.value(), text_content_1); | 116 CreateTextFile(chrome_dll_4.value(), text_content_1); |
116 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); | 117 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); |
117 | 118 |
118 MockInstallerState installer_state; | 119 MockInstallerState installer_state; |
119 BuildSingleChromeState(chrome_dir, &installer_state); | 120 BuildSingleChromeState(chrome_dir, &installer_state); |
120 scoped_ptr<Version> latest_version(Version::GetVersionFromString("1.0.4.0")); | 121 scoped_ptr<Version> latest_version(Version::GetVersionFromString("1.0.4.0")); |
121 installer_state.RemoveOldVersionDirectories(*latest_version.get()); | 122 { |
| 123 ScopedTempDir temp_dir; |
| 124 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 125 installer_state.RemoveOldVersionDirectories(*latest_version.get(), |
| 126 temp_dir.path()); |
| 127 } |
122 | 128 |
123 // old versions should be gone | 129 // old versions should be gone |
124 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); | 130 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); |
125 EXPECT_FALSE(file_util::PathExists(chrome_dir_2)); | 131 EXPECT_FALSE(file_util::PathExists(chrome_dir_2)); |
126 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); | 132 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); |
127 // the latest version should stay | 133 // the latest version should stay |
128 EXPECT_TRUE(file_util::PathExists(chrome_dll_4)); | 134 EXPECT_TRUE(file_util::PathExists(chrome_dll_4)); |
129 } | 135 } |
130 | 136 |
131 // Delete older version directories, keeping the one in used intact. | 137 // Delete older version directories, keeping the one in used intact. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 ASSERT_TRUE(file_util::PathExists(chrome_dll_3)); | 192 ASSERT_TRUE(file_util::PathExists(chrome_dll_3)); |
187 | 193 |
188 FilePath chrome_dll_4(chrome_dir_4); | 194 FilePath chrome_dll_4(chrome_dir_4); |
189 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); | 195 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); |
190 CreateTextFile(chrome_dll_4.value(), text_content_1); | 196 CreateTextFile(chrome_dll_4.value(), text_content_1); |
191 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); | 197 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); |
192 | 198 |
193 MockInstallerState installer_state; | 199 MockInstallerState installer_state; |
194 BuildSingleChromeState(chrome_dir, &installer_state); | 200 BuildSingleChromeState(chrome_dir, &installer_state); |
195 scoped_ptr<Version> latest_version(Version::GetVersionFromString("1.0.4.0")); | 201 scoped_ptr<Version> latest_version(Version::GetVersionFromString("1.0.4.0")); |
196 installer_state.RemoveOldVersionDirectories(*latest_version.get()); | 202 { |
| 203 ScopedTempDir temp_dir; |
| 204 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 205 installer_state.RemoveOldVersionDirectories(*latest_version.get(), |
| 206 temp_dir.path()); |
| 207 } |
197 | 208 |
198 // old versions not in used should be gone | 209 // old versions not in used should be gone |
199 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); | 210 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); |
200 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); | 211 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); |
201 // every thing under in used version should stay | 212 // every thing under in used version should stay |
202 EXPECT_TRUE(file_util::PathExists(chrome_dir_2)); | 213 EXPECT_TRUE(file_util::PathExists(chrome_dir_2)); |
203 EXPECT_TRUE(file_util::PathExists(chrome_dll_2)); | 214 EXPECT_TRUE(file_util::PathExists(chrome_dll_2)); |
204 EXPECT_TRUE(file_util::PathExists(chrome_othera_2)); | 215 EXPECT_TRUE(file_util::PathExists(chrome_othera_2)); |
205 EXPECT_TRUE(file_util::PathExists(chrome_otherb_2)); | 216 EXPECT_TRUE(file_util::PathExists(chrome_otherb_2)); |
206 // the latest version should stay | 217 // the latest version should stay |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); | 269 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); |
259 | 270 |
260 // Hold on to the file exclusively to prevent the directory from | 271 // Hold on to the file exclusively to prevent the directory from |
261 // being deleted. | 272 // being deleted. |
262 base::win::ScopedHandle file( | 273 base::win::ScopedHandle file( |
263 ::CreateFile(old_chrome_dll.value().c_str(), GENERIC_READ, | 274 ::CreateFile(old_chrome_dll.value().c_str(), GENERIC_READ, |
264 0, NULL, OPEN_ALWAYS, 0, NULL)); | 275 0, NULL, OPEN_ALWAYS, 0, NULL)); |
265 EXPECT_TRUE(file.IsValid()); | 276 EXPECT_TRUE(file.IsValid()); |
266 EXPECT_TRUE(file_util::PathExists(old_chrome_dll)); | 277 EXPECT_TRUE(file_util::PathExists(old_chrome_dll)); |
267 | 278 |
268 installer_state.RemoveOldVersionDirectories(*new_version.get()); | 279 ScopedTempDir temp_dir; |
| 280 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 281 |
| 282 installer_state.RemoveOldVersionDirectories(*new_version.get(), |
| 283 temp_dir.path()); |
| 284 |
269 // The old directory should still exist. | 285 // The old directory should still exist. |
270 EXPECT_TRUE(file_util::PathExists(old_version_dir)); | 286 EXPECT_TRUE(file_util::PathExists(old_version_dir)); |
271 EXPECT_TRUE(file_util::PathExists(new_version_dir)); | 287 EXPECT_TRUE(file_util::PathExists(new_version_dir)); |
272 | 288 |
273 // Now close the file handle to make it possible to delete our key file. | 289 // Now close the file handle to make it possible to delete our key file. |
274 file.Close(); | 290 file.Close(); |
275 | 291 |
276 installer_state.RemoveOldVersionDirectories(*new_version.get()); | 292 installer_state.RemoveOldVersionDirectories(*new_version.get(), |
| 293 temp_dir.path()); |
277 // The new directory should still exist. | 294 // The new directory should still exist. |
278 EXPECT_TRUE(file_util::PathExists(new_version_dir)); | 295 EXPECT_TRUE(file_util::PathExists(new_version_dir)); |
279 | 296 |
280 // Now, the old directory and key file should be gone. | 297 // Now, the old directory and key file should be gone. |
281 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); | 298 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); |
282 EXPECT_FALSE(file_util::PathExists(old_version_dir)); | 299 EXPECT_FALSE(file_util::PathExists(old_version_dir)); |
283 } | 300 } |
284 | 301 |
285 TEST_F(InstallerStateTest, WithProduct) { | 302 TEST_F(InstallerStateTest, WithProduct) { |
286 const bool multi_install = false; | 303 const bool multi_install = false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 // TODO(tommi): Also test for when there exists a new_chrome.exe. | 335 // TODO(tommi): Also test for when there exists a new_chrome.exe. |
319 scoped_ptr<Version> found_version(installer_state.GetCurrentVersion( | 336 scoped_ptr<Version> found_version(installer_state.GetCurrentVersion( |
320 machine_state)); | 337 machine_state)); |
321 EXPECT_TRUE(found_version.get() != NULL); | 338 EXPECT_TRUE(found_version.get() != NULL); |
322 if (found_version.get()) { | 339 if (found_version.get()) { |
323 EXPECT_TRUE(current_version->Equals(*found_version)); | 340 EXPECT_TRUE(current_version->Equals(*found_version)); |
324 } | 341 } |
325 } | 342 } |
326 } | 343 } |
327 } | 344 } |
OLD | NEW |