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

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

Issue 100573002: Move directory creation functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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
« no previous file with comments | « chrome/installer/util/install_util_unittest.cc ('k') | chrome/installer/util/lzma_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 wchar_t text_content_1[] = L"delete me"; 90 wchar_t text_content_1[] = L"delete me";
91 wchar_t text_content_2[] = L"delete me as well"; 91 wchar_t text_content_2[] = L"delete me as well";
92 92
93 // Delete version directories. Everything lower than the given version 93 // Delete version directories. Everything lower than the given version
94 // should be deleted. 94 // should be deleted.
95 TEST_F(InstallerStateTest, Delete) { 95 TEST_F(InstallerStateTest, Delete) {
96 // TODO(grt): move common stuff into the test fixture. 96 // TODO(grt): move common stuff into the test fixture.
97 // Create a Chrome dir 97 // Create a Chrome dir
98 base::FilePath chrome_dir(test_dir_.path()); 98 base::FilePath chrome_dir(test_dir_.path());
99 chrome_dir = chrome_dir.AppendASCII("chrome"); 99 chrome_dir = chrome_dir.AppendASCII("chrome");
100 file_util::CreateDirectory(chrome_dir); 100 base::CreateDirectory(chrome_dir);
101 ASSERT_TRUE(base::PathExists(chrome_dir)); 101 ASSERT_TRUE(base::PathExists(chrome_dir));
102 102
103 base::FilePath chrome_dir_1(chrome_dir); 103 base::FilePath chrome_dir_1(chrome_dir);
104 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0"); 104 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0");
105 file_util::CreateDirectory(chrome_dir_1); 105 base::CreateDirectory(chrome_dir_1);
106 ASSERT_TRUE(base::PathExists(chrome_dir_1)); 106 ASSERT_TRUE(base::PathExists(chrome_dir_1));
107 107
108 base::FilePath chrome_dir_2(chrome_dir); 108 base::FilePath chrome_dir_2(chrome_dir);
109 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0"); 109 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0");
110 file_util::CreateDirectory(chrome_dir_2); 110 base::CreateDirectory(chrome_dir_2);
111 ASSERT_TRUE(base::PathExists(chrome_dir_2)); 111 ASSERT_TRUE(base::PathExists(chrome_dir_2));
112 112
113 base::FilePath chrome_dir_3(chrome_dir); 113 base::FilePath chrome_dir_3(chrome_dir);
114 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0"); 114 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0");
115 file_util::CreateDirectory(chrome_dir_3); 115 base::CreateDirectory(chrome_dir_3);
116 ASSERT_TRUE(base::PathExists(chrome_dir_3)); 116 ASSERT_TRUE(base::PathExists(chrome_dir_3));
117 117
118 base::FilePath chrome_dir_4(chrome_dir); 118 base::FilePath chrome_dir_4(chrome_dir);
119 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0"); 119 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0");
120 file_util::CreateDirectory(chrome_dir_4); 120 base::CreateDirectory(chrome_dir_4);
121 ASSERT_TRUE(base::PathExists(chrome_dir_4)); 121 ASSERT_TRUE(base::PathExists(chrome_dir_4));
122 122
123 base::FilePath chrome_dll_1(chrome_dir_1); 123 base::FilePath chrome_dll_1(chrome_dir_1);
124 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll"); 124 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll");
125 CreateTextFile(chrome_dll_1.value(), text_content_1); 125 CreateTextFile(chrome_dll_1.value(), text_content_1);
126 ASSERT_TRUE(base::PathExists(chrome_dll_1)); 126 ASSERT_TRUE(base::PathExists(chrome_dll_1));
127 127
128 base::FilePath chrome_dll_2(chrome_dir_2); 128 base::FilePath chrome_dll_2(chrome_dir_2);
129 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll"); 129 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll");
130 CreateTextFile(chrome_dll_2.value(), text_content_1); 130 CreateTextFile(chrome_dll_2.value(), text_content_1);
(...skipping 25 matching lines...) Expand all
156 EXPECT_FALSE(base::PathExists(chrome_dir_3)); 156 EXPECT_FALSE(base::PathExists(chrome_dir_3));
157 // the latest version should stay 157 // the latest version should stay
158 EXPECT_TRUE(base::PathExists(chrome_dll_4)); 158 EXPECT_TRUE(base::PathExists(chrome_dll_4));
159 } 159 }
160 160
161 // Delete older version directories, keeping the one in used intact. 161 // Delete older version directories, keeping the one in used intact.
162 TEST_F(InstallerStateTest, DeleteInUsed) { 162 TEST_F(InstallerStateTest, DeleteInUsed) {
163 // Create a Chrome dir 163 // Create a Chrome dir
164 base::FilePath chrome_dir(test_dir_.path()); 164 base::FilePath chrome_dir(test_dir_.path());
165 chrome_dir = chrome_dir.AppendASCII("chrome"); 165 chrome_dir = chrome_dir.AppendASCII("chrome");
166 file_util::CreateDirectory(chrome_dir); 166 base::CreateDirectory(chrome_dir);
167 ASSERT_TRUE(base::PathExists(chrome_dir)); 167 ASSERT_TRUE(base::PathExists(chrome_dir));
168 168
169 base::FilePath chrome_dir_1(chrome_dir); 169 base::FilePath chrome_dir_1(chrome_dir);
170 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0"); 170 chrome_dir_1 = chrome_dir_1.AppendASCII("1.0.1.0");
171 file_util::CreateDirectory(chrome_dir_1); 171 base::CreateDirectory(chrome_dir_1);
172 ASSERT_TRUE(base::PathExists(chrome_dir_1)); 172 ASSERT_TRUE(base::PathExists(chrome_dir_1));
173 173
174 base::FilePath chrome_dir_2(chrome_dir); 174 base::FilePath chrome_dir_2(chrome_dir);
175 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0"); 175 chrome_dir_2 = chrome_dir_2.AppendASCII("1.0.2.0");
176 file_util::CreateDirectory(chrome_dir_2); 176 base::CreateDirectory(chrome_dir_2);
177 ASSERT_TRUE(base::PathExists(chrome_dir_2)); 177 ASSERT_TRUE(base::PathExists(chrome_dir_2));
178 178
179 base::FilePath chrome_dir_3(chrome_dir); 179 base::FilePath chrome_dir_3(chrome_dir);
180 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0"); 180 chrome_dir_3 = chrome_dir_3.AppendASCII("1.0.3.0");
181 file_util::CreateDirectory(chrome_dir_3); 181 base::CreateDirectory(chrome_dir_3);
182 ASSERT_TRUE(base::PathExists(chrome_dir_3)); 182 ASSERT_TRUE(base::PathExists(chrome_dir_3));
183 183
184 base::FilePath chrome_dir_4(chrome_dir); 184 base::FilePath chrome_dir_4(chrome_dir);
185 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0"); 185 chrome_dir_4 = chrome_dir_4.AppendASCII("1.0.4.0");
186 file_util::CreateDirectory(chrome_dir_4); 186 base::CreateDirectory(chrome_dir_4);
187 ASSERT_TRUE(base::PathExists(chrome_dir_4)); 187 ASSERT_TRUE(base::PathExists(chrome_dir_4));
188 188
189 base::FilePath chrome_dll_1(chrome_dir_1); 189 base::FilePath chrome_dll_1(chrome_dir_1);
190 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll"); 190 chrome_dll_1 = chrome_dll_1.AppendASCII("chrome.dll");
191 CreateTextFile(chrome_dll_1.value(), text_content_1); 191 CreateTextFile(chrome_dll_1.value(), text_content_1);
192 ASSERT_TRUE(base::PathExists(chrome_dll_1)); 192 ASSERT_TRUE(base::PathExists(chrome_dll_1));
193 193
194 base::FilePath chrome_dll_2(chrome_dir_2); 194 base::FilePath chrome_dll_2(chrome_dir_2);
195 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll"); 195 chrome_dll_2 = chrome_dll_2.AppendASCII("chrome.dll");
196 CreateTextFile(chrome_dll_2.value(), text_content_1); 196 CreateTextFile(chrome_dll_2.value(), text_content_1);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 base::FilePath new_version_dir(installer_state.target_path().Append( 278 base::FilePath new_version_dir(installer_state.target_path().Append(
279 UTF8ToWide(new_version.GetString()))); 279 UTF8ToWide(new_version.GetString())));
280 base::FilePath old_version_dir(installer_state.target_path().Append( 280 base::FilePath old_version_dir(installer_state.target_path().Append(
281 UTF8ToWide(old_version.GetString()))); 281 UTF8ToWide(old_version.GetString())));
282 282
283 EXPECT_FALSE(base::PathExists(new_version_dir)); 283 EXPECT_FALSE(base::PathExists(new_version_dir));
284 EXPECT_FALSE(base::PathExists(old_version_dir)); 284 EXPECT_FALSE(base::PathExists(old_version_dir));
285 285
286 EXPECT_FALSE(base::PathExists(installer_dir)); 286 EXPECT_FALSE(base::PathExists(installer_dir));
287 file_util::CreateDirectory(installer_dir); 287 base::CreateDirectory(installer_dir);
288 EXPECT_TRUE(base::PathExists(new_version_dir)); 288 EXPECT_TRUE(base::PathExists(new_version_dir));
289 289
290 file_util::CreateDirectory(old_version_dir); 290 base::CreateDirectory(old_version_dir);
291 EXPECT_TRUE(base::PathExists(old_version_dir)); 291 EXPECT_TRUE(base::PathExists(old_version_dir));
292 292
293 // Create a fake chrome.dll key file in the old version directory. This 293 // Create a fake chrome.dll key file in the old version directory. This
294 // should prevent the old version directory from getting deleted. 294 // should prevent the old version directory from getting deleted.
295 base::FilePath old_chrome_dll(old_version_dir.Append(installer::kChromeDll)); 295 base::FilePath old_chrome_dll(old_version_dir.Append(installer::kChromeDll));
296 EXPECT_FALSE(base::PathExists(old_chrome_dll)); 296 EXPECT_FALSE(base::PathExists(old_chrome_dll));
297 297
298 // Hold on to the file exclusively to prevent the directory from 298 // Hold on to the file exclusively to prevent the directory from
299 // being deleted. 299 // being deleted.
300 base::win::ScopedHandle file( 300 base::win::ScopedHandle file(
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 installer_state.target_path().Append(ASCIIToWide(kOldVersion)), 527 installer_state.target_path().Append(ASCIIToWide(kOldVersion)),
528 installer_state.target_path().Append(ASCIIToWide(kOldChromeExeVersion)), 528 installer_state.target_path().Append(ASCIIToWide(kOldChromeExeVersion)),
529 installer_state.target_path().Append(L"2.1.1.0"), 529 installer_state.target_path().Append(L"2.1.1.0"),
530 installer_state.target_path().Append(ASCIIToWide(kChromeExeVersion)), 530 installer_state.target_path().Append(ASCIIToWide(kChromeExeVersion)),
531 installer_state.target_path().Append(ASCIIToWide(kNewVersion)), 531 installer_state.target_path().Append(ASCIIToWide(kNewVersion)),
532 installer_state.target_path().Append(L"3.9.1.1"), 532 installer_state.target_path().Append(L"3.9.1.1"),
533 }; 533 };
534 534
535 // Create the version directories. 535 // Create the version directories.
536 for (int i = 0; i < arraysize(version_dirs); i++) { 536 for (int i = 0; i < arraysize(version_dirs); i++) {
537 file_util::CreateDirectory(version_dirs[i]); 537 base::CreateDirectory(version_dirs[i]);
538 EXPECT_TRUE(base::PathExists(version_dirs[i])); 538 EXPECT_TRUE(base::PathExists(version_dirs[i]));
539 } 539 }
540 540
541 // Create exes with the appropriate version resource. 541 // Create exes with the appropriate version resource.
542 // Use the current test exe as a baseline. 542 // Use the current test exe as a baseline.
543 base::FilePath exe_path; 543 base::FilePath exe_path;
544 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path)); 544 ASSERT_TRUE(PathService::Get(base::FILE_EXE, &exe_path));
545 545
546 struct target_info { 546 struct target_info {
547 base::FilePath target_file; 547 base::FilePath target_file;
(...skipping 200 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/install_util_unittest.cc ('k') | chrome/installer/util/lzma_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698