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

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

Issue 6793008: Replacing base::DIR_TEMP with ScopedTempDir when appropriate. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: About a third of the way done. Created 9 years, 8 months 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) 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/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/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/string_util.h" 16 #include "base/string_util.h"
16 #include "base/threading/platform_thread.h" 17 #include "base/threading/platform_thread.h"
17 #include "chrome/installer/util/work_item.h" 18 #include "chrome/installer/util/work_item.h"
18 #include "chrome/installer/util/copy_tree_work_item.h" 19 #include "chrome/installer/util/copy_tree_work_item.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace { 22 namespace {
22 class CopyTreeWorkItemTest : public testing::Test { 23 class CopyTreeWorkItemTest : public testing::Test {
23 protected: 24 protected:
24 virtual void SetUp() { 25 virtual void SetUp() {
25 // Name a subdirectory of the user temp directory. 26 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
26 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_)); 27 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
27 test_dir_ = test_dir_.AppendASCII("CopyTreeWorkItemTest");
28
29 // Create a fresh, empty copy of this test directory.
30 file_util::Delete(test_dir_, true);
31 file_util::CreateDirectoryW(test_dir_);
32
33 // Create a tempory directory under the test directory.
34 temp_dir_ = test_dir_.AppendASCII("temp");
35 file_util::CreateDirectoryW(temp_dir_);
36
37 ASSERT_TRUE(file_util::PathExists(test_dir_));
38 ASSERT_TRUE(file_util::PathExists(temp_dir_));
39 } 28 }
40 29
41 virtual void TearDown() { 30 virtual void TearDown() {
42 logging::CloseLogFile(); 31 logging::CloseLogFile();
43 // Clean up test directory
44 ASSERT_TRUE(file_util::Delete(test_dir_, true));
45 ASSERT_FALSE(file_util::PathExists(test_dir_));
46 } 32 }
47 33
48 // the path to temporary directory used to contain the test operations 34 // the path to temporary directory used to contain the test operations
49 FilePath test_dir_; 35 ScopedTempDir test_dir_;
50 FilePath temp_dir_; 36 ScopedTempDir temp_dir_;
51 }; 37 };
52 38
53 // Simple function to dump some text into a new file. 39 // Simple function to dump some text into a new file.
54 void CreateTextFile(const std::wstring& filename, 40 void CreateTextFile(const std::wstring& filename,
55 const std::wstring& contents) { 41 const std::wstring& contents) {
56 std::ofstream file; 42 std::ofstream file;
57 file.open(filename.c_str()); 43 file.open(filename.c_str());
58 ASSERT_TRUE(file.is_open()); 44 ASSERT_TRUE(file.is_open());
59 file << contents; 45 file << contents;
60 file.close(); 46 file.close();
(...skipping 23 matching lines...) Expand all
84 return std::wstring(contents); 70 return std::wstring(contents);
85 } 71 }
86 72
87 wchar_t text_content_1[] = L"Gooooooooooooooooooooogle"; 73 wchar_t text_content_1[] = L"Gooooooooooooooooooooogle";
88 wchar_t text_content_2[] = L"Overwrite Me"; 74 wchar_t text_content_2[] = L"Overwrite Me";
89 }; 75 };
90 76
91 // Copy one file from source to destination. 77 // Copy one file from source to destination.
92 TEST_F(CopyTreeWorkItemTest, CopyFile) { 78 TEST_F(CopyTreeWorkItemTest, CopyFile) {
93 // Create source file 79 // Create source file
94 FilePath file_name_from(test_dir_); 80 FilePath file_name_from(test_dir_.path());
95 file_name_from = file_name_from.AppendASCII("File_From.txt"); 81 file_name_from = file_name_from.AppendASCII("File_From.txt");
96 CreateTextFile(file_name_from.value(), text_content_1); 82 CreateTextFile(file_name_from.value(), text_content_1);
97 ASSERT_TRUE(file_util::PathExists(file_name_from)); 83 ASSERT_TRUE(file_util::PathExists(file_name_from));
98 84
99 // Create destination path 85 // Create destination path
100 FilePath dir_name_to(test_dir_); 86 FilePath dir_name_to(test_dir_.path());
101 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 87 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
102 file_util::CreateDirectory(dir_name_to); 88 file_util::CreateDirectory(dir_name_to);
103 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 89 ASSERT_TRUE(file_util::PathExists(dir_name_to));
104 90
105 FilePath file_name_to(dir_name_to); 91 FilePath file_name_to(dir_name_to);
106 file_name_to = file_name_to.AppendASCII("File_To.txt"); 92 file_name_to = file_name_to.AppendASCII("File_To.txt");
107 93
108 // test Do() 94 // test Do()
109 scoped_ptr<CopyTreeWorkItem> work_item( 95 scoped_ptr<CopyTreeWorkItem> work_item(
110 WorkItem::CreateCopyTreeWorkItem(file_name_from, 96 WorkItem::CreateCopyTreeWorkItem(file_name_from,
111 file_name_to, 97 file_name_to,
112 temp_dir_, 98 temp_dir_.path(),
113 WorkItem::ALWAYS, 99 WorkItem::ALWAYS,
114 FilePath())); 100 FilePath()));
115 101
116 EXPECT_TRUE(work_item->Do()); 102 EXPECT_TRUE(work_item->Do());
117 103
118 EXPECT_TRUE(file_util::PathExists(file_name_from)); 104 EXPECT_TRUE(file_util::PathExists(file_name_from));
119 EXPECT_TRUE(file_util::PathExists(file_name_to)); 105 EXPECT_TRUE(file_util::PathExists(file_name_to));
120 EXPECT_TRUE(file_util::ContentsEqual(file_name_from, file_name_to)); 106 EXPECT_TRUE(file_util::ContentsEqual(file_name_from, file_name_to));
121 107
122 // test rollback() 108 // test rollback()
123 work_item->Rollback(); 109 work_item->Rollback();
124 110
125 EXPECT_FALSE(file_util::PathExists(file_name_to)); 111 EXPECT_FALSE(file_util::PathExists(file_name_to));
126 EXPECT_TRUE(file_util::PathExists(file_name_from)); 112 EXPECT_TRUE(file_util::PathExists(file_name_from));
127 } 113 }
128 114
129 // Copy one file, overwriting the existing one in destination. 115 // Copy one file, overwriting the existing one in destination.
130 // Test with always_overwrite being true or false. The file is overwritten 116 // Test with always_overwrite being true or false. The file is overwritten
131 // regardless since the content at destination file is different from source. 117 // regardless since the content at destination file is different from source.
132 TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) { 118 TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
133 // Create source file 119 // Create source file
134 FilePath file_name_from(test_dir_); 120 FilePath file_name_from(test_dir_.path());
135 file_name_from = file_name_from.AppendASCII("File_From.txt"); 121 file_name_from = file_name_from.AppendASCII("File_From.txt");
136 CreateTextFile(file_name_from.value(), text_content_1); 122 CreateTextFile(file_name_from.value(), text_content_1);
137 ASSERT_TRUE(file_util::PathExists(file_name_from)); 123 ASSERT_TRUE(file_util::PathExists(file_name_from));
138 124
139 // Create destination file 125 // Create destination file
140 FilePath dir_name_to(test_dir_); 126 FilePath dir_name_to(test_dir_.path());
141 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 127 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
142 file_util::CreateDirectory(dir_name_to); 128 file_util::CreateDirectory(dir_name_to);
143 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 129 ASSERT_TRUE(file_util::PathExists(dir_name_to));
144 130
145 FilePath file_name_to(dir_name_to); 131 FilePath file_name_to(dir_name_to);
146 file_name_to = file_name_to.AppendASCII("File_To.txt"); 132 file_name_to = file_name_to.AppendASCII("File_To.txt");
147 CreateTextFile(file_name_to.value(), text_content_2); 133 CreateTextFile(file_name_to.value(), text_content_2);
148 ASSERT_TRUE(file_util::PathExists(file_name_to)); 134 ASSERT_TRUE(file_util::PathExists(file_name_to));
149 135
150 // test Do() with always_overwrite being true. 136 // test Do() with always_overwrite being true.
151 scoped_ptr<CopyTreeWorkItem> work_item( 137 scoped_ptr<CopyTreeWorkItem> work_item(
152 WorkItem::CreateCopyTreeWorkItem(file_name_from, 138 WorkItem::CreateCopyTreeWorkItem(file_name_from,
153 file_name_to, 139 file_name_to,
154 temp_dir_, 140 temp_dir_.path(),
155 WorkItem::ALWAYS, 141 WorkItem::ALWAYS,
156 FilePath())); 142 FilePath()));
157 143
158 EXPECT_TRUE(work_item->Do()); 144 EXPECT_TRUE(work_item->Do());
159 145
160 EXPECT_TRUE(file_util::PathExists(file_name_from)); 146 EXPECT_TRUE(file_util::PathExists(file_name_from));
161 EXPECT_TRUE(file_util::PathExists(file_name_to)); 147 EXPECT_TRUE(file_util::PathExists(file_name_to));
162 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 148 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
163 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 149 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
164 150
165 // test rollback() 151 // test rollback()
166 work_item->Rollback(); 152 work_item->Rollback();
167 153
168 EXPECT_TRUE(file_util::PathExists(file_name_from)); 154 EXPECT_TRUE(file_util::PathExists(file_name_from));
169 EXPECT_TRUE(file_util::PathExists(file_name_to)); 155 EXPECT_TRUE(file_util::PathExists(file_name_to));
170 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 156 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
171 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2)); 157 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2));
172 158
173 // test Do() with always_overwrite being false. 159 // test Do() with always_overwrite being false.
174 // the file is still overwritten since the content is different. 160 // the file is still overwritten since the content is different.
175 work_item.reset( 161 work_item.reset(
176 WorkItem::CreateCopyTreeWorkItem(file_name_from, 162 WorkItem::CreateCopyTreeWorkItem(file_name_from,
177 file_name_to, 163 file_name_to,
178 temp_dir_, 164 temp_dir_.path(),
179 WorkItem::IF_DIFFERENT, 165 WorkItem::IF_DIFFERENT,
180 FilePath())); 166 FilePath()));
181 167
182 EXPECT_TRUE(work_item->Do()); 168 EXPECT_TRUE(work_item->Do());
183 169
184 EXPECT_TRUE(file_util::PathExists(file_name_from)); 170 EXPECT_TRUE(file_util::PathExists(file_name_from));
185 EXPECT_TRUE(file_util::PathExists(file_name_to)); 171 EXPECT_TRUE(file_util::PathExists(file_name_to));
186 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 172 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
187 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 173 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
188 174
189 // test rollback() 175 // test rollback()
190 work_item->Rollback(); 176 work_item->Rollback();
191 177
192 EXPECT_TRUE(file_util::PathExists(file_name_from)); 178 EXPECT_TRUE(file_util::PathExists(file_name_from));
193 EXPECT_TRUE(file_util::PathExists(file_name_to)); 179 EXPECT_TRUE(file_util::PathExists(file_name_to));
194 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 180 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
195 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2)); 181 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_2));
196 } 182 }
197 183
198 // Copy one file, with the existing one in destination having the same 184 // Copy one file, with the existing one in destination having the same
199 // content. 185 // content.
200 // If always_overwrite being true, the file is overwritten. 186 // If always_overwrite being true, the file is overwritten.
201 // If always_overwrite being false, the file is unchanged. 187 // If always_overwrite being false, the file is unchanged.
202 TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) { 188 TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
203 // Create source file 189 // Create source file
204 FilePath file_name_from(test_dir_); 190 FilePath file_name_from(test_dir_.path());
205 file_name_from = file_name_from.AppendASCII("File_From.txt"); 191 file_name_from = file_name_from.AppendASCII("File_From.txt");
206 CreateTextFile(file_name_from.value(), text_content_1); 192 CreateTextFile(file_name_from.value(), text_content_1);
207 ASSERT_TRUE(file_util::PathExists(file_name_from)); 193 ASSERT_TRUE(file_util::PathExists(file_name_from));
208 194
209 // Create destination file 195 // Create destination file
210 FilePath dir_name_to(test_dir_); 196 FilePath dir_name_to(test_dir_.path());
211 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 197 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
212 file_util::CreateDirectory(dir_name_to); 198 file_util::CreateDirectory(dir_name_to);
213 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 199 ASSERT_TRUE(file_util::PathExists(dir_name_to));
214 200
215 FilePath file_name_to(dir_name_to); 201 FilePath file_name_to(dir_name_to);
216 file_name_to = file_name_to.AppendASCII("File_To.txt"); 202 file_name_to = file_name_to.AppendASCII("File_To.txt");
217 CreateTextFile(file_name_to.value(), text_content_1); 203 CreateTextFile(file_name_to.value(), text_content_1);
218 ASSERT_TRUE(file_util::PathExists(file_name_to)); 204 ASSERT_TRUE(file_util::PathExists(file_name_to));
219 205
220 // test Do() with always_overwrite being true. 206 // test Do() with always_overwrite being true.
221 scoped_ptr<CopyTreeWorkItem> work_item( 207 scoped_ptr<CopyTreeWorkItem> work_item(
222 WorkItem::CreateCopyTreeWorkItem(file_name_from, 208 WorkItem::CreateCopyTreeWorkItem(file_name_from,
223 file_name_to, 209 file_name_to,
224 temp_dir_, 210 temp_dir_.path(),
225 WorkItem::ALWAYS, 211 WorkItem::ALWAYS,
226 FilePath())); 212 FilePath()));
227 213
228 EXPECT_TRUE(work_item->Do()); 214 EXPECT_TRUE(work_item->Do());
229 215
230 // Get the path of backup file 216 // Get the path of backup file
231 FilePath backup_file(work_item->backup_path_.path()); 217 FilePath backup_file(work_item->backup_path_.path());
232 EXPECT_FALSE(backup_file.empty()); 218 EXPECT_FALSE(backup_file.empty());
233 backup_file = backup_file.AppendASCII("File_To.txt"); 219 backup_file = backup_file.AppendASCII("File_To.txt");
234 220
(...skipping 13 matching lines...) Expand all
248 EXPECT_TRUE(file_util::PathExists(file_name_to)); 234 EXPECT_TRUE(file_util::PathExists(file_name_to));
249 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 235 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
250 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 236 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
251 // the backup file should be gone after rollback 237 // the backup file should be gone after rollback
252 EXPECT_FALSE(file_util::PathExists(backup_file)); 238 EXPECT_FALSE(file_util::PathExists(backup_file));
253 239
254 // test Do() with always_overwrite being false. nothing should change. 240 // test Do() with always_overwrite being false. nothing should change.
255 work_item.reset( 241 work_item.reset(
256 WorkItem::CreateCopyTreeWorkItem(file_name_from, 242 WorkItem::CreateCopyTreeWorkItem(file_name_from,
257 file_name_to, 243 file_name_to,
258 temp_dir_, 244 temp_dir_.path(),
259 WorkItem::IF_DIFFERENT, 245 WorkItem::IF_DIFFERENT,
260 FilePath())); 246 FilePath()));
261 247
262 EXPECT_TRUE(work_item->Do()); 248 EXPECT_TRUE(work_item->Do());
263 249
264 EXPECT_TRUE(file_util::PathExists(file_name_from)); 250 EXPECT_TRUE(file_util::PathExists(file_name_from));
265 EXPECT_TRUE(file_util::PathExists(file_name_to)); 251 EXPECT_TRUE(file_util::PathExists(file_name_to));
266 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 252 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
267 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 253 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
268 // we verify the file is not overwritten by checking that the backup 254 // we verify the file is not overwritten by checking that the backup
269 // file does not exist. 255 // file does not exist.
270 EXPECT_FALSE(file_util::PathExists(backup_file)); 256 EXPECT_FALSE(file_util::PathExists(backup_file));
271 257
272 // test rollback(). nothing should happen here. 258 // test rollback(). nothing should happen here.
273 work_item->Rollback(); 259 work_item->Rollback();
274 260
275 EXPECT_TRUE(file_util::PathExists(file_name_from)); 261 EXPECT_TRUE(file_util::PathExists(file_name_from));
276 EXPECT_TRUE(file_util::PathExists(file_name_to)); 262 EXPECT_TRUE(file_util::PathExists(file_name_to));
277 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 263 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
278 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 264 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
279 EXPECT_FALSE(file_util::PathExists(backup_file)); 265 EXPECT_FALSE(file_util::PathExists(backup_file));
280 } 266 }
281 267
282 // Copy one file and without rollback. Verify all temporary files are deleted. 268 // Copy one file and without rollback. Verify all temporary files are deleted.
283 TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) { 269 TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
284 // Create source file 270 // Create source file
285 FilePath file_name_from(test_dir_); 271 FilePath file_name_from(test_dir_.path());
286 file_name_from = file_name_from.AppendASCII("File_From.txt"); 272 file_name_from = file_name_from.AppendASCII("File_From.txt");
287 CreateTextFile(file_name_from.value(), text_content_1); 273 CreateTextFile(file_name_from.value(), text_content_1);
288 ASSERT_TRUE(file_util::PathExists(file_name_from)); 274 ASSERT_TRUE(file_util::PathExists(file_name_from));
289 275
290 // Create destination file 276 // Create destination file
291 FilePath dir_name_to(test_dir_); 277 FilePath dir_name_to(test_dir_.path());
292 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 278 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
293 file_util::CreateDirectory(dir_name_to); 279 file_util::CreateDirectory(dir_name_to);
294 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 280 ASSERT_TRUE(file_util::PathExists(dir_name_to));
295 281
296 FilePath file_name_to(dir_name_to); 282 FilePath file_name_to(dir_name_to);
297 file_name_to = file_name_to.AppendASCII("File_To.txt"); 283 file_name_to = file_name_to.AppendASCII("File_To.txt");
298 CreateTextFile(file_name_to.value(), text_content_2); 284 CreateTextFile(file_name_to.value(), text_content_2);
299 ASSERT_TRUE(file_util::PathExists(file_name_to)); 285 ASSERT_TRUE(file_util::PathExists(file_name_to));
300 286
301 FilePath backup_file; 287 FilePath backup_file;
302 288
303 { 289 {
304 // test Do(). 290 // test Do().
305 scoped_ptr<CopyTreeWorkItem> work_item( 291 scoped_ptr<CopyTreeWorkItem> work_item(
306 WorkItem::CreateCopyTreeWorkItem(file_name_from, 292 WorkItem::CreateCopyTreeWorkItem(file_name_from,
307 file_name_to, 293 file_name_to,
308 temp_dir_, 294 temp_dir_.path(),
309 WorkItem::IF_DIFFERENT, 295 WorkItem::IF_DIFFERENT,
310 FilePath())); 296 FilePath()));
311 297
312 EXPECT_TRUE(work_item->Do()); 298 EXPECT_TRUE(work_item->Do());
313 299
314 // Get the path of backup file 300 // Get the path of backup file
315 backup_file = work_item->backup_path_.path(); 301 backup_file = work_item->backup_path_.path();
316 EXPECT_FALSE(backup_file.empty()); 302 EXPECT_FALSE(backup_file.empty());
317 backup_file = backup_file.AppendASCII("File_To.txt"); 303 backup_file = backup_file.AppendASCII("File_To.txt");
318 304
319 EXPECT_TRUE(file_util::PathExists(file_name_from)); 305 EXPECT_TRUE(file_util::PathExists(file_name_from));
320 EXPECT_TRUE(file_util::PathExists(file_name_to)); 306 EXPECT_TRUE(file_util::PathExists(file_name_to));
321 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 307 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
322 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 308 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
323 // verify the file is moved to backup place. 309 // verify the file is moved to backup place.
324 EXPECT_TRUE(file_util::PathExists(backup_file)); 310 EXPECT_TRUE(file_util::PathExists(backup_file));
325 EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_2)); 311 EXPECT_EQ(0, ReadTextFile(backup_file.value()).compare(text_content_2));
326 } 312 }
327 313
328 // verify the backup file is cleaned up as well. 314 // verify the backup file is cleaned up as well.
329 EXPECT_FALSE(file_util::PathExists(backup_file)); 315 EXPECT_FALSE(file_util::PathExists(backup_file));
330 } 316 }
331 317
332 // Copy one file, with the existing one in destination being used with 318 // Copy one file, with the existing one in destination being used with
333 // overwrite option as IF_DIFFERENT. This destination-file-in-use should 319 // overwrite option as IF_DIFFERENT. This destination-file-in-use should
334 // be moved to backup location after Do() and moved back after Rollback(). 320 // be moved to backup location after Do() and moved back after Rollback().
335 TEST_F(CopyTreeWorkItemTest, CopyFileInUse) { 321 TEST_F(CopyTreeWorkItemTest, CopyFileInUse) {
336 // Create source file 322 // Create source file
337 FilePath file_name_from(test_dir_); 323 FilePath file_name_from(test_dir_.path());
338 file_name_from = file_name_from.AppendASCII("File_From"); 324 file_name_from = file_name_from.AppendASCII("File_From");
339 CreateTextFile(file_name_from.value(), text_content_1); 325 CreateTextFile(file_name_from.value(), text_content_1);
340 ASSERT_TRUE(file_util::PathExists(file_name_from)); 326 ASSERT_TRUE(file_util::PathExists(file_name_from));
341 327
342 // Create an executable in destination path by copying ourself to it. 328 // Create an executable in destination path by copying ourself to it.
343 wchar_t exe_full_path_str[MAX_PATH]; 329 wchar_t exe_full_path_str[MAX_PATH];
344 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 330 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
345 FilePath exe_full_path(exe_full_path_str); 331 FilePath exe_full_path(exe_full_path_str);
346 332
347 FilePath dir_name_to(test_dir_); 333 FilePath dir_name_to(test_dir_.path());
348 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 334 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
349 file_util::CreateDirectory(dir_name_to); 335 file_util::CreateDirectory(dir_name_to);
350 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 336 ASSERT_TRUE(file_util::PathExists(dir_name_to));
351 337
352 FilePath file_name_to(dir_name_to); 338 FilePath file_name_to(dir_name_to);
353 file_name_to = file_name_to.AppendASCII("File_To"); 339 file_name_to = file_name_to.AppendASCII("File_To");
354 file_util::CopyFile(exe_full_path, file_name_to); 340 file_util::CopyFile(exe_full_path, file_name_to);
355 ASSERT_TRUE(file_util::PathExists(file_name_to)); 341 ASSERT_TRUE(file_util::PathExists(file_name_to));
356 342
357 VLOG(1) << "copy ourself from " << exe_full_path.value() 343 VLOG(1) << "copy ourself from " << exe_full_path.value()
358 << " to " << file_name_to.value(); 344 << " to " << file_name_to.value();
359 345
360 // Run the executable in destination path 346 // Run the executable in destination path
361 STARTUPINFOW si = {sizeof(si)}; 347 STARTUPINFOW si = {sizeof(si)};
362 PROCESS_INFORMATION pi = {0}; 348 PROCESS_INFORMATION pi = {0};
363 ASSERT_TRUE( 349 ASSERT_TRUE(
364 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()), 350 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
365 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED, 351 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
366 NULL, NULL, &si, &pi)); 352 NULL, NULL, &si, &pi));
367 353
368 // test Do(). 354 // test Do().
369 scoped_ptr<CopyTreeWorkItem> work_item( 355 scoped_ptr<CopyTreeWorkItem> work_item(
370 WorkItem::CreateCopyTreeWorkItem(file_name_from, 356 WorkItem::CreateCopyTreeWorkItem(file_name_from,
371 file_name_to, 357 file_name_to,
372 temp_dir_, 358 temp_dir_.path(),
373 WorkItem::IF_DIFFERENT, 359 WorkItem::IF_DIFFERENT,
374 FilePath())); 360 FilePath()));
375 361
376 EXPECT_TRUE(work_item->Do()); 362 EXPECT_TRUE(work_item->Do());
377 363
378 // Get the path of backup file 364 // Get the path of backup file
379 FilePath backup_file(work_item->backup_path_.path()); 365 FilePath backup_file(work_item->backup_path_.path());
380 EXPECT_FALSE(backup_file.empty()); 366 EXPECT_FALSE(backup_file.empty());
381 backup_file = backup_file.AppendASCII("File_To"); 367 backup_file = backup_file.AppendASCII("File_To");
382 368
(...skipping 23 matching lines...) Expand all
406 } 392 }
407 393
408 // Test overwrite option NEW_NAME_IF_IN_USE: 394 // Test overwrite option NEW_NAME_IF_IN_USE:
409 // 1. If destination file is in use, the source should be copied with the 395 // 1. If destination file is in use, the source should be copied with the
410 // new name after Do() and this new name file should be deleted 396 // new name after Do() and this new name file should be deleted
411 // after rollback. 397 // after rollback.
412 // 2. If destination file is not in use, the source should be copied in the 398 // 2. If destination file is not in use, the source should be copied in the
413 // destination folder after Do() and should be rolled back after Rollback(). 399 // destination folder after Do() and should be rolled back after Rollback().
414 TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) { 400 TEST_F(CopyTreeWorkItemTest, NewNameAndCopyTest) {
415 // Create source file 401 // Create source file
416 FilePath file_name_from(test_dir_); 402 FilePath file_name_from(test_dir_.path());
417 file_name_from = file_name_from.AppendASCII("File_From"); 403 file_name_from = file_name_from.AppendASCII("File_From");
418 CreateTextFile(file_name_from.value(), text_content_1); 404 CreateTextFile(file_name_from.value(), text_content_1);
419 ASSERT_TRUE(file_util::PathExists(file_name_from)); 405 ASSERT_TRUE(file_util::PathExists(file_name_from));
420 406
421 // Create an executable in destination path by copying ourself to it. 407 // Create an executable in destination path by copying ourself to it.
422 wchar_t exe_full_path_str[MAX_PATH]; 408 wchar_t exe_full_path_str[MAX_PATH];
423 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 409 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
424 FilePath exe_full_path(exe_full_path_str); 410 FilePath exe_full_path(exe_full_path_str);
425 411
426 FilePath dir_name_to(test_dir_); 412 FilePath dir_name_to(test_dir_.path());
427 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 413 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
428 file_util::CreateDirectory(dir_name_to); 414 file_util::CreateDirectory(dir_name_to);
429 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 415 ASSERT_TRUE(file_util::PathExists(dir_name_to));
430 416
431 FilePath file_name_to(dir_name_to), alternate_to(dir_name_to); 417 FilePath file_name_to(dir_name_to), alternate_to(dir_name_to);
432 file_name_to = file_name_to.AppendASCII("File_To"); 418 file_name_to = file_name_to.AppendASCII("File_To");
433 alternate_to = alternate_to.AppendASCII("Alternate_To"); 419 alternate_to = alternate_to.AppendASCII("Alternate_To");
434 file_util::CopyFile(exe_full_path, file_name_to); 420 file_util::CopyFile(exe_full_path, file_name_to);
435 ASSERT_TRUE(file_util::PathExists(file_name_to)); 421 ASSERT_TRUE(file_util::PathExists(file_name_to));
436 422
437 VLOG(1) << "copy ourself from " << exe_full_path.value() 423 VLOG(1) << "copy ourself from " << exe_full_path.value()
438 << " to " << file_name_to.value(); 424 << " to " << file_name_to.value();
439 425
440 // Run the executable in destination path 426 // Run the executable in destination path
441 STARTUPINFOW si = {sizeof(si)}; 427 STARTUPINFOW si = {sizeof(si)};
442 PROCESS_INFORMATION pi = {0}; 428 PROCESS_INFORMATION pi = {0};
443 ASSERT_TRUE( 429 ASSERT_TRUE(
444 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()), 430 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
445 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED, 431 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
446 NULL, NULL, &si, &pi)); 432 NULL, NULL, &si, &pi));
447 433
448 // test Do(). 434 // test Do().
449 scoped_ptr<CopyTreeWorkItem> work_item( 435 scoped_ptr<CopyTreeWorkItem> work_item(
450 WorkItem::CreateCopyTreeWorkItem(file_name_from, 436 WorkItem::CreateCopyTreeWorkItem(file_name_from,
451 file_name_to, 437 file_name_to,
452 temp_dir_, 438 temp_dir_.path(),
453 WorkItem::NEW_NAME_IF_IN_USE, 439 WorkItem::NEW_NAME_IF_IN_USE,
454 alternate_to)); 440 alternate_to));
455 441
456 EXPECT_TRUE(work_item->Do()); 442 EXPECT_TRUE(work_item->Do());
457 443
458 EXPECT_TRUE(file_util::PathExists(file_name_from)); 444 EXPECT_TRUE(file_util::PathExists(file_name_from));
459 EXPECT_TRUE(file_util::PathExists(file_name_to)); 445 EXPECT_TRUE(file_util::PathExists(file_name_to));
460 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 446 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
461 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, file_name_to)); 447 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, file_name_to));
462 // verify that the backup path does not exist 448 // verify that the backup path does not exist
(...skipping 13 matching lines...) Expand all
476 462
477 TerminateProcess(pi.hProcess, 0); 463 TerminateProcess(pi.hProcess, 0);
478 // make sure the handle is closed. 464 // make sure the handle is closed.
479 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); 465 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
480 CloseHandle(pi.hProcess); 466 CloseHandle(pi.hProcess);
481 CloseHandle(pi.hThread); 467 CloseHandle(pi.hThread);
482 468
483 // Now the process has terminated, lets try overwriting the file again 469 // Now the process has terminated, lets try overwriting the file again
484 work_item.reset(WorkItem::CreateCopyTreeWorkItem( 470 work_item.reset(WorkItem::CreateCopyTreeWorkItem(
485 file_name_from, file_name_to, 471 file_name_from, file_name_to,
486 temp_dir_, WorkItem::NEW_NAME_IF_IN_USE, 472 temp_dir_.path(), WorkItem::NEW_NAME_IF_IN_USE,
487 alternate_to)); 473 alternate_to));
488 if (IsFileInUse(file_name_to)) 474 if (IsFileInUse(file_name_to))
489 base::PlatformThread::Sleep(2000); 475 base::PlatformThread::Sleep(2000);
490 // If file is still in use, the rest of the test will fail. 476 // If file is still in use, the rest of the test will fail.
491 ASSERT_FALSE(IsFileInUse(file_name_to)); 477 ASSERT_FALSE(IsFileInUse(file_name_to));
492 EXPECT_TRUE(work_item->Do()); 478 EXPECT_TRUE(work_item->Do());
493 479
494 // Get the path of backup file 480 // Get the path of backup file
495 FilePath backup_file(work_item->backup_path_.path()); 481 FilePath backup_file(work_item->backup_path_.path());
496 EXPECT_FALSE(backup_file.empty()); 482 EXPECT_FALSE(backup_file.empty());
(...skipping 20 matching lines...) Expand all
517 } 503 }
518 504
519 // Test overwrite option IF_NOT_PRESENT: 505 // Test overwrite option IF_NOT_PRESENT:
520 // 1. If destination file/directory exist, the source should not be copied 506 // 1. If destination file/directory exist, the source should not be copied
521 // 2. If destination file/directory do not exist, the source should be copied 507 // 2. If destination file/directory do not exist, the source should be copied
522 // in the destination folder after Do() and should be rolled back after 508 // in the destination folder after Do() and should be rolled back after
523 // Rollback(). 509 // Rollback().
524 // Flaky, http://crbug.com/59785. 510 // Flaky, http://crbug.com/59785.
525 TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) { 511 TEST_F(CopyTreeWorkItemTest, FLAKY_IfNotPresentTest) {
526 // Create source file 512 // Create source file
527 FilePath file_name_from(test_dir_); 513 FilePath file_name_from(test_dir_.path());
528 file_name_from = file_name_from.AppendASCII("File_From"); 514 file_name_from = file_name_from.AppendASCII("File_From");
529 CreateTextFile(file_name_from.value(), text_content_1); 515 CreateTextFile(file_name_from.value(), text_content_1);
530 ASSERT_TRUE(file_util::PathExists(file_name_from)); 516 ASSERT_TRUE(file_util::PathExists(file_name_from));
531 517
532 // Create an executable in destination path by copying ourself to it. 518 // Create an executable in destination path by copying ourself to it.
533 wchar_t exe_full_path_str[MAX_PATH]; 519 wchar_t exe_full_path_str[MAX_PATH];
534 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 520 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
535 FilePath exe_full_path(exe_full_path_str); 521 FilePath exe_full_path(exe_full_path_str);
536 522
537 FilePath dir_name_to(test_dir_); 523 FilePath dir_name_to(test_dir_.path());
538 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 524 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
539 file_util::CreateDirectory(dir_name_to); 525 file_util::CreateDirectory(dir_name_to);
540 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 526 ASSERT_TRUE(file_util::PathExists(dir_name_to));
541 FilePath file_name_to(dir_name_to); 527 FilePath file_name_to(dir_name_to);
542 file_name_to = file_name_to.AppendASCII("File_To"); 528 file_name_to = file_name_to.AppendASCII("File_To");
543 file_util::CopyFile(exe_full_path, file_name_to); 529 file_util::CopyFile(exe_full_path, file_name_to);
544 ASSERT_TRUE(file_util::PathExists(file_name_to)); 530 ASSERT_TRUE(file_util::PathExists(file_name_to));
545 531
546 // Get the path of backup file 532 // Get the path of backup file
547 FilePath backup_file(temp_dir_); 533 FilePath backup_file(temp_dir_.path());
548 backup_file = backup_file.AppendASCII("File_To"); 534 backup_file = backup_file.AppendASCII("File_To");
549 535
550 // test Do(). 536 // test Do().
551 scoped_ptr<CopyTreeWorkItem> work_item( 537 scoped_ptr<CopyTreeWorkItem> work_item(
552 WorkItem::CreateCopyTreeWorkItem( 538 WorkItem::CreateCopyTreeWorkItem(
553 file_name_from, 539 file_name_from,
554 file_name_to, temp_dir_, 540 file_name_to, temp_dir_.path(),
555 WorkItem::IF_NOT_PRESENT, 541 WorkItem::IF_NOT_PRESENT,
556 FilePath())); 542 FilePath()));
557 EXPECT_TRUE(work_item->Do()); 543 EXPECT_TRUE(work_item->Do());
558 544
559 // verify that the source, destination have not changed and backup path 545 // verify that the source, destination have not changed and backup path
560 // does not exist 546 // does not exist
561 EXPECT_TRUE(file_util::PathExists(file_name_from)); 547 EXPECT_TRUE(file_util::PathExists(file_name_from));
562 EXPECT_TRUE(file_util::PathExists(file_name_to)); 548 EXPECT_TRUE(file_util::PathExists(file_name_to));
563 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 549 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
564 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, file_name_to)); 550 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, file_name_to));
565 EXPECT_FALSE(file_util::PathExists(backup_file)); 551 EXPECT_FALSE(file_util::PathExists(backup_file));
566 552
567 // test rollback() 553 // test rollback()
568 work_item->Rollback(); 554 work_item->Rollback();
569 555
570 // verify that the source, destination have not changed and backup path 556 // verify that the source, destination have not changed and backup path
571 // does not exist after rollback also 557 // does not exist after rollback also
572 EXPECT_TRUE(file_util::PathExists(file_name_from)); 558 EXPECT_TRUE(file_util::PathExists(file_name_from));
573 EXPECT_TRUE(file_util::PathExists(file_name_to)); 559 EXPECT_TRUE(file_util::PathExists(file_name_to));
574 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 560 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
575 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, file_name_to)); 561 EXPECT_TRUE(file_util::ContentsEqual(exe_full_path, file_name_to));
576 EXPECT_FALSE(file_util::PathExists(backup_file)); 562 EXPECT_FALSE(file_util::PathExists(backup_file));
577 563
578 // Now delete the destination and try copying the file again. 564 // Now delete the destination and try copying the file again.
579 file_util::Delete(file_name_to, true); 565 file_util::Delete(file_name_to, true);
580 work_item.reset(WorkItem::CreateCopyTreeWorkItem( 566 work_item.reset(WorkItem::CreateCopyTreeWorkItem(
581 file_name_from, file_name_to, 567 file_name_from, file_name_to,
582 temp_dir_, WorkItem::IF_NOT_PRESENT, 568 temp_dir_.path(), WorkItem::IF_NOT_PRESENT,
583 FilePath())); 569 FilePath()));
584 EXPECT_TRUE(work_item->Do()); 570 EXPECT_TRUE(work_item->Do());
585 571
586 // verify that the source, destination are the same and backup path 572 // verify that the source, destination are the same and backup path
587 // does not exist 573 // does not exist
588 EXPECT_TRUE(file_util::PathExists(file_name_from)); 574 EXPECT_TRUE(file_util::PathExists(file_name_from));
589 EXPECT_TRUE(file_util::PathExists(file_name_to)); 575 EXPECT_TRUE(file_util::PathExists(file_name_to));
590 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 576 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
591 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1)); 577 EXPECT_EQ(0, ReadTextFile(file_name_to.value()).compare(text_content_1));
592 EXPECT_FALSE(file_util::PathExists(backup_file)); 578 EXPECT_FALSE(file_util::PathExists(backup_file));
593 579
594 // test rollback() 580 // test rollback()
595 work_item->Rollback(); 581 work_item->Rollback();
596 582
597 // verify that the destination does not exist anymore 583 // verify that the destination does not exist anymore
598 EXPECT_TRUE(file_util::PathExists(file_name_from)); 584 EXPECT_TRUE(file_util::PathExists(file_name_from));
599 EXPECT_FALSE(file_util::PathExists(file_name_to)); 585 EXPECT_FALSE(file_util::PathExists(file_name_to));
600 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1)); 586 EXPECT_EQ(0, ReadTextFile(file_name_from.value()).compare(text_content_1));
601 EXPECT_FALSE(file_util::PathExists(backup_file)); 587 EXPECT_FALSE(file_util::PathExists(backup_file));
602 } 588 }
603 589
604 // Copy one file without rollback. The existing one in destination is in use. 590 // Copy one file without rollback. The existing one in destination is in use.
605 // Verify it is moved to backup location and stays there. 591 // Verify it is moved to backup location and stays there.
606 // Flaky, http://crbug.com/59783. 592 // Flaky, http://crbug.com/59783.
607 TEST_F(CopyTreeWorkItemTest, FLAKY_CopyFileInUseAndCleanup) { 593 TEST_F(CopyTreeWorkItemTest, FLAKY_CopyFileInUseAndCleanup) {
608 // Create source file 594 // Create source file
609 FilePath file_name_from(test_dir_); 595 FilePath file_name_from(test_dir_.path());
610 file_name_from = file_name_from.AppendASCII("File_From"); 596 file_name_from = file_name_from.AppendASCII("File_From");
611 CreateTextFile(file_name_from.value(), text_content_1); 597 CreateTextFile(file_name_from.value(), text_content_1);
612 ASSERT_TRUE(file_util::PathExists(file_name_from)); 598 ASSERT_TRUE(file_util::PathExists(file_name_from));
613 599
614 // Create an executable in destination path by copying ourself to it. 600 // Create an executable in destination path by copying ourself to it.
615 wchar_t exe_full_path_str[MAX_PATH]; 601 wchar_t exe_full_path_str[MAX_PATH];
616 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 602 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
617 FilePath exe_full_path(exe_full_path_str); 603 FilePath exe_full_path(exe_full_path_str);
618 604
619 FilePath dir_name_to(test_dir_); 605 FilePath dir_name_to(test_dir_.path());
620 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 606 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
621 file_util::CreateDirectory(dir_name_to); 607 file_util::CreateDirectory(dir_name_to);
622 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 608 ASSERT_TRUE(file_util::PathExists(dir_name_to));
623 609
624 FilePath file_name_to(dir_name_to); 610 FilePath file_name_to(dir_name_to);
625 file_name_to = file_name_to.AppendASCII("File_To"); 611 file_name_to = file_name_to.AppendASCII("File_To");
626 file_util::CopyFile(exe_full_path, file_name_to); 612 file_util::CopyFile(exe_full_path, file_name_to);
627 ASSERT_TRUE(file_util::PathExists(file_name_to)); 613 ASSERT_TRUE(file_util::PathExists(file_name_to));
628 614
629 VLOG(1) << "copy ourself from " << exe_full_path.value() 615 VLOG(1) << "copy ourself from " << exe_full_path.value()
630 << " to " << file_name_to.value(); 616 << " to " << file_name_to.value();
631 617
632 // Run the executable in destination path 618 // Run the executable in destination path
633 STARTUPINFOW si = {sizeof(si)}; 619 STARTUPINFOW si = {sizeof(si)};
634 PROCESS_INFORMATION pi = {0}; 620 PROCESS_INFORMATION pi = {0};
635 ASSERT_TRUE( 621 ASSERT_TRUE(
636 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()), 622 ::CreateProcess(NULL, const_cast<wchar_t*>(file_name_to.value().c_str()),
637 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED, 623 NULL, NULL, FALSE, CREATE_NO_WINDOW | CREATE_SUSPENDED,
638 NULL, NULL, &si, &pi)); 624 NULL, NULL, &si, &pi));
639 625
640 FilePath backup_file; 626 FilePath backup_file;
641 627
642 // test Do(). 628 // test Do().
643 { 629 {
644 scoped_ptr<CopyTreeWorkItem> work_item( 630 scoped_ptr<CopyTreeWorkItem> work_item(
645 WorkItem::CreateCopyTreeWorkItem(file_name_from, 631 WorkItem::CreateCopyTreeWorkItem(file_name_from,
646 file_name_to, 632 file_name_to,
647 temp_dir_, 633 temp_dir_.path(),
648 WorkItem::IF_DIFFERENT, 634 WorkItem::IF_DIFFERENT,
649 FilePath())); 635 FilePath()));
650 636
651 EXPECT_TRUE(work_item->Do()); 637 EXPECT_TRUE(work_item->Do());
652 638
653 // Get the path of backup file 639 // Get the path of backup file
654 backup_file = work_item->backup_path_.path(); 640 backup_file = work_item->backup_path_.path();
655 EXPECT_FALSE(backup_file.empty()); 641 EXPECT_FALSE(backup_file.empty());
656 backup_file = backup_file.AppendASCII("File_To"); 642 backup_file = backup_file.AppendASCII("File_To");
657 643
(...skipping 14 matching lines...) Expand all
672 // make sure the handle is closed. 658 // make sure the handle is closed.
673 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0); 659 EXPECT_TRUE(WaitForSingleObject(pi.hProcess, 10000) == WAIT_OBJECT_0);
674 CloseHandle(pi.hProcess); 660 CloseHandle(pi.hProcess);
675 CloseHandle(pi.hThread); 661 CloseHandle(pi.hThread);
676 } 662 }
677 663
678 // Copy a tree from source to destination. 664 // Copy a tree from source to destination.
679 // Flaky, http://crbug.com/59784. 665 // Flaky, http://crbug.com/59784.
680 TEST_F(CopyTreeWorkItemTest, FLAKY_CopyTree) { 666 TEST_F(CopyTreeWorkItemTest, FLAKY_CopyTree) {
681 // Create source tree 667 // Create source tree
682 FilePath dir_name_from(test_dir_); 668 FilePath dir_name_from(test_dir_.path());
683 dir_name_from = dir_name_from.AppendASCII("from"); 669 dir_name_from = dir_name_from.AppendASCII("from");
684 file_util::CreateDirectory(dir_name_from); 670 file_util::CreateDirectory(dir_name_from);
685 ASSERT_TRUE(file_util::PathExists(dir_name_from)); 671 ASSERT_TRUE(file_util::PathExists(dir_name_from));
686 672
687 FilePath dir_name_from_1(dir_name_from); 673 FilePath dir_name_from_1(dir_name_from);
688 dir_name_from_1 = dir_name_from_1.AppendASCII("1"); 674 dir_name_from_1 = dir_name_from_1.AppendASCII("1");
689 file_util::CreateDirectory(dir_name_from_1); 675 file_util::CreateDirectory(dir_name_from_1);
690 ASSERT_TRUE(file_util::PathExists(dir_name_from_1)); 676 ASSERT_TRUE(file_util::PathExists(dir_name_from_1));
691 677
692 FilePath dir_name_from_2(dir_name_from); 678 FilePath dir_name_from_2(dir_name_from);
693 dir_name_from_2 = dir_name_from_2.AppendASCII("2"); 679 dir_name_from_2 = dir_name_from_2.AppendASCII("2");
694 file_util::CreateDirectory(dir_name_from_2); 680 file_util::CreateDirectory(dir_name_from_2);
695 ASSERT_TRUE(file_util::PathExists(dir_name_from_2)); 681 ASSERT_TRUE(file_util::PathExists(dir_name_from_2));
696 682
697 FilePath file_name_from_1(dir_name_from_1); 683 FilePath file_name_from_1(dir_name_from_1);
698 file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt"); 684 file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt");
699 CreateTextFile(file_name_from_1.value(), text_content_1); 685 CreateTextFile(file_name_from_1.value(), text_content_1);
700 ASSERT_TRUE(file_util::PathExists(file_name_from_1)); 686 ASSERT_TRUE(file_util::PathExists(file_name_from_1));
701 687
702 FilePath file_name_from_2(dir_name_from_2); 688 FilePath file_name_from_2(dir_name_from_2);
703 file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt"); 689 file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt");
704 CreateTextFile(file_name_from_2.value(), text_content_1); 690 CreateTextFile(file_name_from_2.value(), text_content_1);
705 ASSERT_TRUE(file_util::PathExists(file_name_from_2)); 691 ASSERT_TRUE(file_util::PathExists(file_name_from_2));
706 692
707 FilePath dir_name_to(test_dir_); 693 FilePath dir_name_to(test_dir_.path());
708 dir_name_to = dir_name_to.AppendASCII("to"); 694 dir_name_to = dir_name_to.AppendASCII("to");
709 695
710 // test Do() 696 // test Do()
711 { 697 {
712 scoped_ptr<CopyTreeWorkItem> work_item( 698 scoped_ptr<CopyTreeWorkItem> work_item(
713 WorkItem::CreateCopyTreeWorkItem(dir_name_from, 699 WorkItem::CreateCopyTreeWorkItem(dir_name_from,
714 dir_name_to, 700 dir_name_to,
715 temp_dir_, 701 temp_dir_.path(),
716 WorkItem::ALWAYS, 702 WorkItem::ALWAYS,
717 FilePath())); 703 FilePath()));
718 704
719 EXPECT_TRUE(work_item->Do()); 705 EXPECT_TRUE(work_item->Do());
720 } 706 }
721 707
722 FilePath file_name_to_1(dir_name_to); 708 FilePath file_name_to_1(dir_name_to);
723 file_name_to_1 = file_name_to_1.AppendASCII("1"); 709 file_name_to_1 = file_name_to_1.AppendASCII("1");
724 file_name_to_1 = file_name_to_1.AppendASCII("File_1.txt"); 710 file_name_to_1 = file_name_to_1.AppendASCII("File_1.txt");
725 EXPECT_TRUE(file_util::PathExists(file_name_to_1)); 711 EXPECT_TRUE(file_util::PathExists(file_name_to_1));
726 VLOG(1) << "compare " << file_name_from_1.value() 712 VLOG(1) << "compare " << file_name_from_1.value()
727 << " and " << file_name_to_1.value(); 713 << " and " << file_name_to_1.value();
728 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_1, file_name_to_1)); 714 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_1, file_name_to_1));
729 715
730 FilePath file_name_to_2(dir_name_to); 716 FilePath file_name_to_2(dir_name_to);
731 file_name_to_2 = file_name_to_2.AppendASCII("2"); 717 file_name_to_2 = file_name_to_2.AppendASCII("2");
732 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt"); 718 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt");
733 EXPECT_TRUE(file_util::PathExists(file_name_to_2)); 719 EXPECT_TRUE(file_util::PathExists(file_name_to_2));
734 VLOG(1) << "compare " << file_name_from_2.value() 720 VLOG(1) << "compare " << file_name_from_2.value()
735 << " and " << file_name_to_2.value(); 721 << " and " << file_name_to_2.value();
736 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_2, file_name_to_2)); 722 EXPECT_TRUE(file_util::ContentsEqual(file_name_from_2, file_name_to_2));
737 } 723 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698