Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/installer/util/installer_state_unittest.cc

Issue 11359217: Move scoped_temp_dir from base to base/files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <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_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/files/scoped_temp_dir.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
14 #include "base/process_util.h" 15 #include "base/process_util.h"
15 #include "base/scoped_temp_dir.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/test/test_reg_util_win.h" 17 #include "base/test/test_reg_util_win.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "base/version.h" 19 #include "base/version.h"
20 #include "base/win/registry.h" 20 #include "base/win/registry.h"
21 #include "base/win/scoped_handle.h" 21 #include "base/win/scoped_handle.h"
22 #include "chrome/common/chrome_constants.h" 22 #include "chrome/common/chrome_constants.h"
23 #include "chrome/installer/test/alternate_version_generator.h" 23 #include "chrome/installer/test/alternate_version_generator.h"
24 #include "chrome/installer/util/fake_installation_state.h" 24 #include "chrome/installer/util/fake_installation_state.h"
25 #include "chrome/installer/util/fake_product_state.h" 25 #include "chrome/installer/util/fake_product_state.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 137
138 FilePath chrome_dll_4(chrome_dir_4); 138 FilePath chrome_dll_4(chrome_dir_4);
139 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); 139 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll");
140 CreateTextFile(chrome_dll_4.value(), text_content_1); 140 CreateTextFile(chrome_dll_4.value(), text_content_1);
141 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); 141 ASSERT_TRUE(file_util::PathExists(chrome_dll_4));
142 142
143 MockInstallerState installer_state; 143 MockInstallerState installer_state;
144 BuildSingleChromeState(chrome_dir, &installer_state); 144 BuildSingleChromeState(chrome_dir, &installer_state);
145 Version latest_version("1.0.4.0"); 145 Version latest_version("1.0.4.0");
146 { 146 {
147 ScopedTempDir temp_dir; 147 base::ScopedTempDir temp_dir;
148 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 148 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
149 installer_state.RemoveOldVersionDirectories(latest_version, NULL, 149 installer_state.RemoveOldVersionDirectories(latest_version, NULL,
150 temp_dir.path()); 150 temp_dir.path());
151 } 151 }
152 152
153 // old versions should be gone 153 // old versions should be gone
154 EXPECT_FALSE(file_util::PathExists(chrome_dir_1)); 154 EXPECT_FALSE(file_util::PathExists(chrome_dir_1));
155 EXPECT_FALSE(file_util::PathExists(chrome_dir_2)); 155 EXPECT_FALSE(file_util::PathExists(chrome_dir_2));
156 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); 156 EXPECT_FALSE(file_util::PathExists(chrome_dir_3));
157 // the latest version should stay 157 // the latest version should stay
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 FilePath chrome_dll_4(chrome_dir_4); 218 FilePath chrome_dll_4(chrome_dir_4);
219 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll"); 219 chrome_dll_4 = chrome_dll_4.AppendASCII("chrome.dll");
220 CreateTextFile(chrome_dll_4.value(), text_content_1); 220 CreateTextFile(chrome_dll_4.value(), text_content_1);
221 ASSERT_TRUE(file_util::PathExists(chrome_dll_4)); 221 ASSERT_TRUE(file_util::PathExists(chrome_dll_4));
222 222
223 MockInstallerState installer_state; 223 MockInstallerState installer_state;
224 BuildSingleChromeState(chrome_dir, &installer_state); 224 BuildSingleChromeState(chrome_dir, &installer_state);
225 Version latest_version("1.0.4.0"); 225 Version latest_version("1.0.4.0");
226 Version existing_version("1.0.1.0"); 226 Version existing_version("1.0.1.0");
227 { 227 {
228 ScopedTempDir temp_dir; 228 base::ScopedTempDir temp_dir;
229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
230 installer_state.RemoveOldVersionDirectories(latest_version, 230 installer_state.RemoveOldVersionDirectories(latest_version,
231 &existing_version, 231 &existing_version,
232 temp_dir.path()); 232 temp_dir.path());
233 } 233 }
234 234
235 // the version defined as the existing version should stay 235 // the version defined as the existing version should stay
236 EXPECT_TRUE(file_util::PathExists(chrome_dir_1)); 236 EXPECT_TRUE(file_util::PathExists(chrome_dir_1));
237 // old versions not in used should be gone 237 // old versions not in used should be gone
238 EXPECT_FALSE(file_util::PathExists(chrome_dir_3)); 238 EXPECT_FALSE(file_util::PathExists(chrome_dir_3));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 EXPECT_FALSE(file_util::PathExists(old_chrome_dll)); 295 EXPECT_FALSE(file_util::PathExists(old_chrome_dll));
296 296
297 // Hold on to the file exclusively to prevent the directory from 297 // Hold on to the file exclusively to prevent the directory from
298 // being deleted. 298 // being deleted.
299 base::win::ScopedHandle file( 299 base::win::ScopedHandle file(
300 ::CreateFile(old_chrome_dll.value().c_str(), GENERIC_READ, 300 ::CreateFile(old_chrome_dll.value().c_str(), GENERIC_READ,
301 0, NULL, OPEN_ALWAYS, 0, NULL)); 301 0, NULL, OPEN_ALWAYS, 0, NULL));
302 EXPECT_TRUE(file.IsValid()); 302 EXPECT_TRUE(file.IsValid());
303 EXPECT_TRUE(file_util::PathExists(old_chrome_dll)); 303 EXPECT_TRUE(file_util::PathExists(old_chrome_dll));
304 304
305 ScopedTempDir temp_dir; 305 base::ScopedTempDir temp_dir;
306 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 306 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
307 307
308 // Don't explicitly tell the directory cleanup logic not to delete the 308 // Don't explicitly tell the directory cleanup logic not to delete the
309 // old version, rely on the key files to keep it around. 309 // old version, rely on the key files to keep it around.
310 installer_state.RemoveOldVersionDirectories(new_version, 310 installer_state.RemoveOldVersionDirectories(new_version,
311 NULL, 311 NULL,
312 temp_dir.path()); 312 temp_dir.path());
313 313
314 // The old directory should still exist. 314 // The old directory should still exist.
315 EXPECT_TRUE(file_util::PathExists(old_version_dir)); 315 EXPECT_TRUE(file_util::PathExists(old_version_dir));
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 MasterPreferences prefs(cmd_line); 462 MasterPreferences prefs(cmd_line);
463 InstallerState installer_state; 463 InstallerState installer_state;
464 installer_state.Initialize(cmd_line, prefs, machine_state); 464 installer_state.Initialize(cmd_line, prefs, machine_state);
465 465
466 // Is the Chrome version picked up? 466 // Is the Chrome version picked up?
467 scoped_ptr<Version> version(installer_state.GetCurrentVersion(machine_state)); 467 scoped_ptr<Version> version(installer_state.GetCurrentVersion(machine_state));
468 EXPECT_TRUE(version.get() != NULL); 468 EXPECT_TRUE(version.get() != NULL);
469 } 469 }
470 470
471 TEST_F(InstallerStateTest, IsFileInUse) { 471 TEST_F(InstallerStateTest, IsFileInUse) {
472 ScopedTempDir temp_dir; 472 base::ScopedTempDir temp_dir;
473 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 473 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
474 474
475 FilePath temp_file; 475 FilePath temp_file;
476 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), &temp_file)); 476 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir.path(), &temp_file));
477 477
478 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file)); 478 EXPECT_FALSE(MockInstallerState::IsFileInUse(temp_file));
479 479
480 { 480 {
481 // Open a handle to the file with the same access mode and sharing options 481 // Open a handle to the file with the same access mode and sharing options
482 // as the loader. 482 // as the loader.
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 // Critical update newer than the new version. 748 // Critical update newer than the new version.
749 EXPECT_FALSE( 749 EXPECT_FALSE(
750 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid()); 750 installer_state.DetermineCriticalVersion(NULL, *pv_version_).IsValid());
751 EXPECT_FALSE( 751 EXPECT_FALSE(
752 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_) 752 installer_state.DetermineCriticalVersion(opv_version_, *pv_version_)
753 .IsValid()); 753 .IsValid());
754 EXPECT_FALSE( 754 EXPECT_FALSE(
755 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_) 755 installer_state.DetermineCriticalVersion(pv_version_, *pv_version_)
756 .IsValid()); 756 .IsValid());
757 } 757 }
OLDNEW
« no previous file with comments | « chrome/installer/util/duplicate_tree_detector_unittest.cc ('k') | chrome/installer/util/logging_installer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698