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

Side by Side Diff: base/file_util_unittest.cc

Issue 11773018: Fix creating target paths in file_util_posix CopyDirectory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: support trailing separators in windows file_util::CopyDirectory Created 7 years, 10 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
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
(...skipping 1448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1459 ASSERT_TRUE(file_util::PathExists(dir_name_to)); 1459 ASSERT_TRUE(file_util::PathExists(dir_name_to));
1460 FilePath file_name_to = 1460 FilePath file_name_to =
1461 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); 1461 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
1462 1462
1463 EXPECT_TRUE(file_util::CopyDirectory(file_name_from, dir_name_to, true)); 1463 EXPECT_TRUE(file_util::CopyDirectory(file_name_from, dir_name_to, true));
1464 1464
1465 // Check the has been copied 1465 // Check the has been copied
1466 EXPECT_TRUE(file_util::PathExists(file_name_to)); 1466 EXPECT_TRUE(file_util::PathExists(file_name_to));
1467 } 1467 }
1468 1468
1469 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) {
1470 // Create a directory.
1471 FilePath dir_name_from =
1472 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir"));
1473 file_util::CreateDirectory(dir_name_from);
1474 ASSERT_TRUE(file_util::PathExists(dir_name_from));
1475
1476 // Create a file under the directory.
1477 FilePath file_name_from =
1478 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
1479 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle");
1480 ASSERT_TRUE(file_util::PathExists(file_name_from));
1481
1482 // Copy the directory recursively.
1483 FilePath dir_name_to =
1484 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir"));
1485 FilePath file_name_to =
1486 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
1487
1488 // Create from path with trailing separators.
1489 #if defined(OS_WIN)
1490 FilePath from_path =
1491 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\"));
1492 #elif defined (OS_POSIX)
1493 FilePath from_path =
1494 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir///"));
1495 #endif
1496
1497 EXPECT_TRUE(file_util::CopyDirectory(from_path, dir_name_to, true));
1498
1499 // Check everything has been copied.
1500 EXPECT_TRUE(file_util::PathExists(dir_name_from));
1501 EXPECT_TRUE(file_util::PathExists(file_name_from));
1502 EXPECT_TRUE(file_util::PathExists(dir_name_to));
1503 EXPECT_TRUE(file_util::PathExists(file_name_to));
1504 }
1505
1469 TEST_F(FileUtilTest, CopyFile) { 1506 TEST_F(FileUtilTest, CopyFile) {
1470 // Create a directory 1507 // Create a directory
1471 FilePath dir_name_from = 1508 FilePath dir_name_from =
1472 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); 1509 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir"));
1473 file_util::CreateDirectory(dir_name_from); 1510 file_util::CreateDirectory(dir_name_from);
1474 ASSERT_TRUE(file_util::PathExists(dir_name_from)); 1511 ASSERT_TRUE(file_util::PathExists(dir_name_from));
1475 1512
1476 // Create a file under the directory 1513 // Create a file under the directory
1477 FilePath file_name_from = 1514 FilePath file_name_from =
1478 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); 1515 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt"));
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 file_util::VerifyPathControlledByUser( 2442 file_util::VerifyPathControlledByUser(
2406 base_dir_, text_file_, uid_, ok_gids_)); 2443 base_dir_, text_file_, uid_, ok_gids_));
2407 EXPECT_TRUE( 2444 EXPECT_TRUE(
2408 file_util::VerifyPathControlledByUser( 2445 file_util::VerifyPathControlledByUser(
2409 sub_dir_, text_file_, uid_, ok_gids_)); 2446 sub_dir_, text_file_, uid_, ok_gids_));
2410 } 2447 }
2411 2448
2412 #endif // defined(OS_POSIX) 2449 #endif // defined(OS_POSIX)
2413 2450
2414 } // namespace 2451 } // namespace
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | base/file_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698