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

Side by Side Diff: chrome/installer/util/copy_tree_work_item_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
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/file_util.h" 10 #include "base/file_util.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 TEST_F(CopyTreeWorkItemTest, CopyFile) { 77 TEST_F(CopyTreeWorkItemTest, CopyFile) {
78 // Create source file 78 // Create source file
79 base::FilePath file_name_from(test_dir_.path()); 79 base::FilePath file_name_from(test_dir_.path());
80 file_name_from = file_name_from.AppendASCII("File_From.txt"); 80 file_name_from = file_name_from.AppendASCII("File_From.txt");
81 CreateTextFile(file_name_from.value(), text_content_1); 81 CreateTextFile(file_name_from.value(), text_content_1);
82 ASSERT_TRUE(base::PathExists(file_name_from)); 82 ASSERT_TRUE(base::PathExists(file_name_from));
83 83
84 // Create destination path 84 // Create destination path
85 base::FilePath dir_name_to(test_dir_.path()); 85 base::FilePath dir_name_to(test_dir_.path());
86 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 86 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
87 file_util::CreateDirectory(dir_name_to); 87 base::CreateDirectory(dir_name_to);
88 ASSERT_TRUE(base::PathExists(dir_name_to)); 88 ASSERT_TRUE(base::PathExists(dir_name_to));
89 89
90 base::FilePath file_name_to(dir_name_to); 90 base::FilePath file_name_to(dir_name_to);
91 file_name_to = file_name_to.AppendASCII("File_To.txt"); 91 file_name_to = file_name_to.AppendASCII("File_To.txt");
92 92
93 // test Do() 93 // test Do()
94 scoped_ptr<CopyTreeWorkItem> work_item( 94 scoped_ptr<CopyTreeWorkItem> work_item(
95 WorkItem::CreateCopyTreeWorkItem(file_name_from, 95 WorkItem::CreateCopyTreeWorkItem(file_name_from,
96 file_name_to, 96 file_name_to,
97 temp_dir_.path(), 97 temp_dir_.path(),
(...skipping 19 matching lines...) Expand all
117 TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) { 117 TEST_F(CopyTreeWorkItemTest, CopyFileOverwrite) {
118 // Create source file 118 // Create source file
119 base::FilePath file_name_from(test_dir_.path()); 119 base::FilePath file_name_from(test_dir_.path());
120 file_name_from = file_name_from.AppendASCII("File_From.txt"); 120 file_name_from = file_name_from.AppendASCII("File_From.txt");
121 CreateTextFile(file_name_from.value(), text_content_1); 121 CreateTextFile(file_name_from.value(), text_content_1);
122 ASSERT_TRUE(base::PathExists(file_name_from)); 122 ASSERT_TRUE(base::PathExists(file_name_from));
123 123
124 // Create destination file 124 // Create destination file
125 base::FilePath dir_name_to(test_dir_.path()); 125 base::FilePath dir_name_to(test_dir_.path());
126 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 126 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
127 file_util::CreateDirectory(dir_name_to); 127 base::CreateDirectory(dir_name_to);
128 ASSERT_TRUE(base::PathExists(dir_name_to)); 128 ASSERT_TRUE(base::PathExists(dir_name_to));
129 129
130 base::FilePath file_name_to(dir_name_to); 130 base::FilePath file_name_to(dir_name_to);
131 file_name_to = file_name_to.AppendASCII("File_To.txt"); 131 file_name_to = file_name_to.AppendASCII("File_To.txt");
132 CreateTextFile(file_name_to.value(), text_content_2); 132 CreateTextFile(file_name_to.value(), text_content_2);
133 ASSERT_TRUE(base::PathExists(file_name_to)); 133 ASSERT_TRUE(base::PathExists(file_name_to));
134 134
135 // test Do() with always_overwrite being true. 135 // test Do() with always_overwrite being true.
136 scoped_ptr<CopyTreeWorkItem> work_item( 136 scoped_ptr<CopyTreeWorkItem> work_item(
137 WorkItem::CreateCopyTreeWorkItem(file_name_from, 137 WorkItem::CreateCopyTreeWorkItem(file_name_from,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) { 187 TEST_F(CopyTreeWorkItemTest, CopyFileSameContent) {
188 // Create source file 188 // Create source file
189 base::FilePath file_name_from(test_dir_.path()); 189 base::FilePath file_name_from(test_dir_.path());
190 file_name_from = file_name_from.AppendASCII("File_From.txt"); 190 file_name_from = file_name_from.AppendASCII("File_From.txt");
191 CreateTextFile(file_name_from.value(), text_content_1); 191 CreateTextFile(file_name_from.value(), text_content_1);
192 ASSERT_TRUE(base::PathExists(file_name_from)); 192 ASSERT_TRUE(base::PathExists(file_name_from));
193 193
194 // Create destination file 194 // Create destination file
195 base::FilePath dir_name_to(test_dir_.path()); 195 base::FilePath dir_name_to(test_dir_.path());
196 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 196 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
197 file_util::CreateDirectory(dir_name_to); 197 base::CreateDirectory(dir_name_to);
198 ASSERT_TRUE(base::PathExists(dir_name_to)); 198 ASSERT_TRUE(base::PathExists(dir_name_to));
199 199
200 base::FilePath file_name_to(dir_name_to); 200 base::FilePath file_name_to(dir_name_to);
201 file_name_to = file_name_to.AppendASCII("File_To.txt"); 201 file_name_to = file_name_to.AppendASCII("File_To.txt");
202 CreateTextFile(file_name_to.value(), text_content_1); 202 CreateTextFile(file_name_to.value(), text_content_1);
203 ASSERT_TRUE(base::PathExists(file_name_to)); 203 ASSERT_TRUE(base::PathExists(file_name_to));
204 204
205 // test Do() with always_overwrite being true. 205 // test Do() with always_overwrite being true.
206 scoped_ptr<CopyTreeWorkItem> work_item( 206 scoped_ptr<CopyTreeWorkItem> work_item(
207 WorkItem::CreateCopyTreeWorkItem(file_name_from, 207 WorkItem::CreateCopyTreeWorkItem(file_name_from,
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) { 268 TEST_F(CopyTreeWorkItemTest, CopyFileAndCleanup) {
269 // Create source file 269 // Create source file
270 base::FilePath file_name_from(test_dir_.path()); 270 base::FilePath file_name_from(test_dir_.path());
271 file_name_from = file_name_from.AppendASCII("File_From.txt"); 271 file_name_from = file_name_from.AppendASCII("File_From.txt");
272 CreateTextFile(file_name_from.value(), text_content_1); 272 CreateTextFile(file_name_from.value(), text_content_1);
273 ASSERT_TRUE(base::PathExists(file_name_from)); 273 ASSERT_TRUE(base::PathExists(file_name_from));
274 274
275 // Create destination file 275 // Create destination file
276 base::FilePath dir_name_to(test_dir_.path()); 276 base::FilePath dir_name_to(test_dir_.path());
277 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 277 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
278 file_util::CreateDirectory(dir_name_to); 278 base::CreateDirectory(dir_name_to);
279 ASSERT_TRUE(base::PathExists(dir_name_to)); 279 ASSERT_TRUE(base::PathExists(dir_name_to));
280 280
281 base::FilePath file_name_to(dir_name_to); 281 base::FilePath file_name_to(dir_name_to);
282 file_name_to = file_name_to.AppendASCII("File_To.txt"); 282 file_name_to = file_name_to.AppendASCII("File_To.txt");
283 CreateTextFile(file_name_to.value(), text_content_2); 283 CreateTextFile(file_name_to.value(), text_content_2);
284 ASSERT_TRUE(base::PathExists(file_name_to)); 284 ASSERT_TRUE(base::PathExists(file_name_to));
285 285
286 base::FilePath backup_file; 286 base::FilePath backup_file;
287 287
288 { 288 {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 CreateTextFile(file_name_from.value(), text_content_1); 324 CreateTextFile(file_name_from.value(), text_content_1);
325 ASSERT_TRUE(base::PathExists(file_name_from)); 325 ASSERT_TRUE(base::PathExists(file_name_from));
326 326
327 // Create an executable in destination path by copying ourself to it. 327 // Create an executable in destination path by copying ourself to it.
328 wchar_t exe_full_path_str[MAX_PATH]; 328 wchar_t exe_full_path_str[MAX_PATH];
329 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 329 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
330 base::FilePath exe_full_path(exe_full_path_str); 330 base::FilePath exe_full_path(exe_full_path_str);
331 331
332 base::FilePath dir_name_to(test_dir_.path()); 332 base::FilePath dir_name_to(test_dir_.path());
333 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 333 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
334 file_util::CreateDirectory(dir_name_to); 334 base::CreateDirectory(dir_name_to);
335 ASSERT_TRUE(base::PathExists(dir_name_to)); 335 ASSERT_TRUE(base::PathExists(dir_name_to));
336 336
337 base::FilePath file_name_to(dir_name_to); 337 base::FilePath file_name_to(dir_name_to);
338 file_name_to = file_name_to.AppendASCII("File_To"); 338 file_name_to = file_name_to.AppendASCII("File_To");
339 base::CopyFile(exe_full_path, file_name_to); 339 base::CopyFile(exe_full_path, file_name_to);
340 ASSERT_TRUE(base::PathExists(file_name_to)); 340 ASSERT_TRUE(base::PathExists(file_name_to));
341 341
342 VLOG(1) << "copy ourself from " << exe_full_path.value() 342 VLOG(1) << "copy ourself from " << exe_full_path.value()
343 << " to " << file_name_to.value(); 343 << " to " << file_name_to.value();
344 344
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 CreateTextFile(file_name_from.value(), text_content_1); 403 CreateTextFile(file_name_from.value(), text_content_1);
404 ASSERT_TRUE(base::PathExists(file_name_from)); 404 ASSERT_TRUE(base::PathExists(file_name_from));
405 405
406 // Create an executable in destination path by copying ourself to it. 406 // Create an executable in destination path by copying ourself to it.
407 wchar_t exe_full_path_str[MAX_PATH]; 407 wchar_t exe_full_path_str[MAX_PATH];
408 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 408 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
409 base::FilePath exe_full_path(exe_full_path_str); 409 base::FilePath exe_full_path(exe_full_path_str);
410 410
411 base::FilePath dir_name_to(test_dir_.path()); 411 base::FilePath dir_name_to(test_dir_.path());
412 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 412 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
413 file_util::CreateDirectory(dir_name_to); 413 base::CreateDirectory(dir_name_to);
414 ASSERT_TRUE(base::PathExists(dir_name_to)); 414 ASSERT_TRUE(base::PathExists(dir_name_to));
415 415
416 base::FilePath file_name_to(dir_name_to), alternate_to(dir_name_to); 416 base::FilePath file_name_to(dir_name_to), alternate_to(dir_name_to);
417 file_name_to = file_name_to.AppendASCII("File_To"); 417 file_name_to = file_name_to.AppendASCII("File_To");
418 alternate_to = alternate_to.AppendASCII("Alternate_To"); 418 alternate_to = alternate_to.AppendASCII("Alternate_To");
419 base::CopyFile(exe_full_path, file_name_to); 419 base::CopyFile(exe_full_path, file_name_to);
420 ASSERT_TRUE(base::PathExists(file_name_to)); 420 ASSERT_TRUE(base::PathExists(file_name_to));
421 421
422 VLOG(1) << "copy ourself from " << exe_full_path.value() 422 VLOG(1) << "copy ourself from " << exe_full_path.value()
423 << " to " << file_name_to.value(); 423 << " to " << file_name_to.value();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 CreateTextFile(file_name_from.value(), text_content_1); 514 CreateTextFile(file_name_from.value(), text_content_1);
515 ASSERT_TRUE(base::PathExists(file_name_from)); 515 ASSERT_TRUE(base::PathExists(file_name_from));
516 516
517 // Create an executable in destination path by copying ourself to it. 517 // Create an executable in destination path by copying ourself to it.
518 wchar_t exe_full_path_str[MAX_PATH]; 518 wchar_t exe_full_path_str[MAX_PATH];
519 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 519 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
520 base::FilePath exe_full_path(exe_full_path_str); 520 base::FilePath exe_full_path(exe_full_path_str);
521 521
522 base::FilePath dir_name_to(test_dir_.path()); 522 base::FilePath dir_name_to(test_dir_.path());
523 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 523 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
524 file_util::CreateDirectory(dir_name_to); 524 base::CreateDirectory(dir_name_to);
525 ASSERT_TRUE(base::PathExists(dir_name_to)); 525 ASSERT_TRUE(base::PathExists(dir_name_to));
526 base::FilePath file_name_to(dir_name_to); 526 base::FilePath file_name_to(dir_name_to);
527 file_name_to = file_name_to.AppendASCII("File_To"); 527 file_name_to = file_name_to.AppendASCII("File_To");
528 base::CopyFile(exe_full_path, file_name_to); 528 base::CopyFile(exe_full_path, file_name_to);
529 ASSERT_TRUE(base::PathExists(file_name_to)); 529 ASSERT_TRUE(base::PathExists(file_name_to));
530 530
531 // Get the path of backup file 531 // Get the path of backup file
532 base::FilePath backup_file(temp_dir_.path()); 532 base::FilePath backup_file(temp_dir_.path());
533 backup_file = backup_file.AppendASCII("File_To"); 533 backup_file = backup_file.AppendASCII("File_To");
534 534
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 CreateTextFile(file_name_from.value(), text_content_1); 596 CreateTextFile(file_name_from.value(), text_content_1);
597 ASSERT_TRUE(base::PathExists(file_name_from)); 597 ASSERT_TRUE(base::PathExists(file_name_from));
598 598
599 // Create an executable in destination path by copying ourself to it. 599 // Create an executable in destination path by copying ourself to it.
600 wchar_t exe_full_path_str[MAX_PATH]; 600 wchar_t exe_full_path_str[MAX_PATH];
601 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH); 601 ::GetModuleFileName(NULL, exe_full_path_str, MAX_PATH);
602 base::FilePath exe_full_path(exe_full_path_str); 602 base::FilePath exe_full_path(exe_full_path_str);
603 603
604 base::FilePath dir_name_to(test_dir_.path()); 604 base::FilePath dir_name_to(test_dir_.path());
605 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir"); 605 dir_name_to = dir_name_to.AppendASCII("Copy_To_Subdir");
606 file_util::CreateDirectory(dir_name_to); 606 base::CreateDirectory(dir_name_to);
607 ASSERT_TRUE(base::PathExists(dir_name_to)); 607 ASSERT_TRUE(base::PathExists(dir_name_to));
608 608
609 base::FilePath file_name_to(dir_name_to); 609 base::FilePath file_name_to(dir_name_to);
610 file_name_to = file_name_to.AppendASCII("File_To"); 610 file_name_to = file_name_to.AppendASCII("File_To");
611 base::CopyFile(exe_full_path, file_name_to); 611 base::CopyFile(exe_full_path, file_name_to);
612 ASSERT_TRUE(base::PathExists(file_name_to)); 612 ASSERT_TRUE(base::PathExists(file_name_to));
613 613
614 VLOG(1) << "copy ourself from " << exe_full_path.value() 614 VLOG(1) << "copy ourself from " << exe_full_path.value()
615 << " to " << file_name_to.value(); 615 << " to " << file_name_to.value();
616 616
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 CloseHandle(pi.hProcess); 659 CloseHandle(pi.hProcess);
660 CloseHandle(pi.hThread); 660 CloseHandle(pi.hThread);
661 } 661 }
662 662
663 // Copy a tree from source to destination. 663 // Copy a tree from source to destination.
664 // Flaky, http://crbug.com/59784. 664 // Flaky, http://crbug.com/59784.
665 TEST_F(CopyTreeWorkItemTest, DISABLED_CopyTree) { 665 TEST_F(CopyTreeWorkItemTest, DISABLED_CopyTree) {
666 // Create source tree 666 // Create source tree
667 base::FilePath dir_name_from(test_dir_.path()); 667 base::FilePath dir_name_from(test_dir_.path());
668 dir_name_from = dir_name_from.AppendASCII("from"); 668 dir_name_from = dir_name_from.AppendASCII("from");
669 file_util::CreateDirectory(dir_name_from); 669 base::CreateDirectory(dir_name_from);
670 ASSERT_TRUE(base::PathExists(dir_name_from)); 670 ASSERT_TRUE(base::PathExists(dir_name_from));
671 671
672 base::FilePath dir_name_from_1(dir_name_from); 672 base::FilePath dir_name_from_1(dir_name_from);
673 dir_name_from_1 = dir_name_from_1.AppendASCII("1"); 673 dir_name_from_1 = dir_name_from_1.AppendASCII("1");
674 file_util::CreateDirectory(dir_name_from_1); 674 base::CreateDirectory(dir_name_from_1);
675 ASSERT_TRUE(base::PathExists(dir_name_from_1)); 675 ASSERT_TRUE(base::PathExists(dir_name_from_1));
676 676
677 base::FilePath dir_name_from_2(dir_name_from); 677 base::FilePath dir_name_from_2(dir_name_from);
678 dir_name_from_2 = dir_name_from_2.AppendASCII("2"); 678 dir_name_from_2 = dir_name_from_2.AppendASCII("2");
679 file_util::CreateDirectory(dir_name_from_2); 679 base::CreateDirectory(dir_name_from_2);
680 ASSERT_TRUE(base::PathExists(dir_name_from_2)); 680 ASSERT_TRUE(base::PathExists(dir_name_from_2));
681 681
682 base::FilePath file_name_from_1(dir_name_from_1); 682 base::FilePath file_name_from_1(dir_name_from_1);
683 file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt"); 683 file_name_from_1 = file_name_from_1.AppendASCII("File_1.txt");
684 CreateTextFile(file_name_from_1.value(), text_content_1); 684 CreateTextFile(file_name_from_1.value(), text_content_1);
685 ASSERT_TRUE(base::PathExists(file_name_from_1)); 685 ASSERT_TRUE(base::PathExists(file_name_from_1));
686 686
687 base::FilePath file_name_from_2(dir_name_from_2); 687 base::FilePath file_name_from_2(dir_name_from_2);
688 file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt"); 688 file_name_from_2 = file_name_from_2.AppendASCII("File_2.txt");
689 CreateTextFile(file_name_from_2.value(), text_content_1); 689 CreateTextFile(file_name_from_2.value(), text_content_1);
(...skipping 23 matching lines...) Expand all
713 EXPECT_TRUE(base::ContentsEqual(file_name_from_1, file_name_to_1)); 713 EXPECT_TRUE(base::ContentsEqual(file_name_from_1, file_name_to_1));
714 714
715 base::FilePath file_name_to_2(dir_name_to); 715 base::FilePath file_name_to_2(dir_name_to);
716 file_name_to_2 = file_name_to_2.AppendASCII("2"); 716 file_name_to_2 = file_name_to_2.AppendASCII("2");
717 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt"); 717 file_name_to_2 = file_name_to_2.AppendASCII("File_2.txt");
718 EXPECT_TRUE(base::PathExists(file_name_to_2)); 718 EXPECT_TRUE(base::PathExists(file_name_to_2));
719 VLOG(1) << "compare " << file_name_from_2.value() 719 VLOG(1) << "compare " << file_name_from_2.value()
720 << " and " << file_name_to_2.value(); 720 << " and " << file_name_to_2.value();
721 EXPECT_TRUE(base::ContentsEqual(file_name_from_2, file_name_to_2)); 721 EXPECT_TRUE(base::ContentsEqual(file_name_from_2, file_name_to_2));
722 } 722 }
OLDNEW
« no previous file with comments | « chrome/installer/setup/setup_util_unittest.cc ('k') | chrome/installer/util/create_dir_work_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698