| OLD | NEW |
| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 TEST_F(FileUtilTest, FileAndDirectorySize) { | 247 TEST_F(FileUtilTest, FileAndDirectorySize) { |
| 248 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize | 248 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize |
| 249 // should return 53 bytes. | 249 // should return 53 bytes. |
| 250 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); | 250 FilePath file_01 = temp_dir_.path().Append(FPL("The file 01.txt")); |
| 251 CreateTextFile(file_01, L"12345678901234567890"); | 251 CreateTextFile(file_01, L"12345678901234567890"); |
| 252 int64 size_f1 = 0; | 252 int64 size_f1 = 0; |
| 253 ASSERT_TRUE(file_util::GetFileSize(file_01, &size_f1)); | 253 ASSERT_TRUE(file_util::GetFileSize(file_01, &size_f1)); |
| 254 EXPECT_EQ(20ll, size_f1); | 254 EXPECT_EQ(20ll, size_f1); |
| 255 | 255 |
| 256 FilePath subdir_path = temp_dir_.path().Append(FPL("Level2")); | 256 FilePath subdir_path = temp_dir_.path().Append(FPL("Level2")); |
| 257 file_util::CreateDirectory(subdir_path); | 257 base::CreateDirectory(subdir_path); |
| 258 | 258 |
| 259 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); | 259 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); |
| 260 CreateTextFile(file_02, L"123456789012345678901234567890"); | 260 CreateTextFile(file_02, L"123456789012345678901234567890"); |
| 261 int64 size_f2 = 0; | 261 int64 size_f2 = 0; |
| 262 ASSERT_TRUE(file_util::GetFileSize(file_02, &size_f2)); | 262 ASSERT_TRUE(file_util::GetFileSize(file_02, &size_f2)); |
| 263 EXPECT_EQ(30ll, size_f2); | 263 EXPECT_EQ(30ll, size_f2); |
| 264 | 264 |
| 265 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); | 265 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); |
| 266 file_util::CreateDirectory(subsubdir_path); | 266 base::CreateDirectory(subsubdir_path); |
| 267 | 267 |
| 268 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); | 268 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); |
| 269 CreateTextFile(file_03, L"123"); | 269 CreateTextFile(file_03, L"123"); |
| 270 | 270 |
| 271 int64 computed_size = ComputeDirectorySize(temp_dir_.path()); | 271 int64 computed_size = ComputeDirectorySize(temp_dir_.path()); |
| 272 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); | 272 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); |
| 273 } | 273 } |
| 274 | 274 |
| 275 TEST_F(FileUtilTest, NormalizeFilePathBasic) { | 275 TEST_F(FileUtilTest, NormalizeFilePathBasic) { |
| 276 // Create a directory under the test dir. Because we create it, | 276 // Create a directory under the test dir. Because we create it, |
| 277 // we know it is not a link. | 277 // we know it is not a link. |
| 278 FilePath file_a_path = temp_dir_.path().Append(FPL("file_a")); | 278 FilePath file_a_path = temp_dir_.path().Append(FPL("file_a")); |
| 279 FilePath dir_path = temp_dir_.path().Append(FPL("dir")); | 279 FilePath dir_path = temp_dir_.path().Append(FPL("dir")); |
| 280 FilePath file_b_path = dir_path.Append(FPL("file_b")); | 280 FilePath file_b_path = dir_path.Append(FPL("file_b")); |
| 281 file_util::CreateDirectory(dir_path); | 281 base::CreateDirectory(dir_path); |
| 282 | 282 |
| 283 FilePath normalized_file_a_path, normalized_file_b_path; | 283 FilePath normalized_file_a_path, normalized_file_b_path; |
| 284 ASSERT_FALSE(PathExists(file_a_path)); | 284 ASSERT_FALSE(PathExists(file_a_path)); |
| 285 ASSERT_FALSE(file_util::NormalizeFilePath(file_a_path, | 285 ASSERT_FALSE(file_util::NormalizeFilePath(file_a_path, |
| 286 &normalized_file_a_path)) | 286 &normalized_file_a_path)) |
| 287 << "NormalizeFilePath() should fail on nonexistent paths."; | 287 << "NormalizeFilePath() should fail on nonexistent paths."; |
| 288 | 288 |
| 289 CreateTextFile(file_a_path, bogus_content); | 289 CreateTextFile(file_a_path, bogus_content); |
| 290 ASSERT_TRUE(PathExists(file_a_path)); | 290 ASSERT_TRUE(PathExists(file_a_path)); |
| 291 ASSERT_TRUE(file_util::NormalizeFilePath(file_a_path, | 291 ASSERT_TRUE(file_util::NormalizeFilePath(file_a_path, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 314 // | |-> file.txt | 314 // | |-> file.txt |
| 315 // | |-> long_name___... (Very long name.) | 315 // | |-> long_name___... (Very long name.) |
| 316 // | |-> sub_long | 316 // | |-> sub_long |
| 317 // | |-> deep.txt | 317 // | |-> deep.txt |
| 318 // |-> base_b | 318 // |-> base_b |
| 319 // |-> to_sub_a (reparse point to temp_dir\base_a\sub_a) | 319 // |-> to_sub_a (reparse point to temp_dir\base_a\sub_a) |
| 320 // |-> to_base_b (reparse point to temp_dir\base_b) | 320 // |-> to_base_b (reparse point to temp_dir\base_b) |
| 321 // |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long) | 321 // |-> to_sub_long (reparse point to temp_dir\sub_a\long_name_\sub_long) |
| 322 | 322 |
| 323 FilePath base_a = temp_dir_.path().Append(FPL("base_a")); | 323 FilePath base_a = temp_dir_.path().Append(FPL("base_a")); |
| 324 ASSERT_TRUE(file_util::CreateDirectory(base_a)); | 324 ASSERT_TRUE(base::CreateDirectory(base_a)); |
| 325 | 325 |
| 326 FilePath sub_a = base_a.Append(FPL("sub_a")); | 326 FilePath sub_a = base_a.Append(FPL("sub_a")); |
| 327 ASSERT_TRUE(file_util::CreateDirectory(sub_a)); | 327 ASSERT_TRUE(base::CreateDirectory(sub_a)); |
| 328 | 328 |
| 329 FilePath file_txt = sub_a.Append(FPL("file.txt")); | 329 FilePath file_txt = sub_a.Append(FPL("file.txt")); |
| 330 CreateTextFile(file_txt, bogus_content); | 330 CreateTextFile(file_txt, bogus_content); |
| 331 | 331 |
| 332 // Want a directory whose name is long enough to make the path to the file | 332 // Want a directory whose name is long enough to make the path to the file |
| 333 // inside just under MAX_PATH chars. This will be used to test that when | 333 // inside just under MAX_PATH chars. This will be used to test that when |
| 334 // a junction expands to a path over MAX_PATH chars in length, | 334 // a junction expands to a path over MAX_PATH chars in length, |
| 335 // NormalizeFilePath() fails without crashing. | 335 // NormalizeFilePath() fails without crashing. |
| 336 FilePath sub_long_rel(FPL("sub_long")); | 336 FilePath sub_long_rel(FPL("sub_long")); |
| 337 FilePath deep_txt(FPL("deep.txt")); | 337 FilePath deep_txt(FPL("deep.txt")); |
| 338 | 338 |
| 339 int target_length = MAX_PATH; | 339 int target_length = MAX_PATH; |
| 340 target_length -= (sub_a.value().length() + 1); // +1 for the sepperator '\'. | 340 target_length -= (sub_a.value().length() + 1); // +1 for the sepperator '\'. |
| 341 target_length -= (sub_long_rel.Append(deep_txt).value().length() + 1); | 341 target_length -= (sub_long_rel.Append(deep_txt).value().length() + 1); |
| 342 // Without making the path a bit shorter, CreateDirectory() fails. | 342 // Without making the path a bit shorter, CreateDirectory() fails. |
| 343 // the resulting path is still long enough to hit the failing case in | 343 // the resulting path is still long enough to hit the failing case in |
| 344 // NormalizePath(). | 344 // NormalizePath(). |
| 345 const int kCreateDirLimit = 4; | 345 const int kCreateDirLimit = 4; |
| 346 target_length -= kCreateDirLimit; | 346 target_length -= kCreateDirLimit; |
| 347 FilePath::StringType long_name_str = FPL("long_name_"); | 347 FilePath::StringType long_name_str = FPL("long_name_"); |
| 348 long_name_str.resize(target_length, '_'); | 348 long_name_str.resize(target_length, '_'); |
| 349 | 349 |
| 350 FilePath long_name = sub_a.Append(FilePath(long_name_str)); | 350 FilePath long_name = sub_a.Append(FilePath(long_name_str)); |
| 351 FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt); | 351 FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt); |
| 352 ASSERT_EQ(MAX_PATH - kCreateDirLimit, deep_file.value().length()); | 352 ASSERT_EQ(MAX_PATH - kCreateDirLimit, deep_file.value().length()); |
| 353 | 353 |
| 354 FilePath sub_long = deep_file.DirName(); | 354 FilePath sub_long = deep_file.DirName(); |
| 355 ASSERT_TRUE(file_util::CreateDirectory(sub_long)); | 355 ASSERT_TRUE(base::CreateDirectory(sub_long)); |
| 356 CreateTextFile(deep_file, bogus_content); | 356 CreateTextFile(deep_file, bogus_content); |
| 357 | 357 |
| 358 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); | 358 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); |
| 359 ASSERT_TRUE(file_util::CreateDirectory(base_b)); | 359 ASSERT_TRUE(base::CreateDirectory(base_b)); |
| 360 | 360 |
| 361 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); | 361 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); |
| 362 ASSERT_TRUE(file_util::CreateDirectory(to_sub_a)); | 362 ASSERT_TRUE(base::CreateDirectory(to_sub_a)); |
| 363 FilePath normalized_path; | 363 FilePath normalized_path; |
| 364 { | 364 { |
| 365 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); | 365 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); |
| 366 ASSERT_TRUE(reparse_to_sub_a.IsValid()); | 366 ASSERT_TRUE(reparse_to_sub_a.IsValid()); |
| 367 | 367 |
| 368 FilePath to_base_b = base_b.Append(FPL("to_base_b")); | 368 FilePath to_base_b = base_b.Append(FPL("to_base_b")); |
| 369 ASSERT_TRUE(file_util::CreateDirectory(to_base_b)); | 369 ASSERT_TRUE(base::CreateDirectory(to_base_b)); |
| 370 ReparsePoint reparse_to_base_b(to_base_b, base_b); | 370 ReparsePoint reparse_to_base_b(to_base_b, base_b); |
| 371 ASSERT_TRUE(reparse_to_base_b.IsValid()); | 371 ASSERT_TRUE(reparse_to_base_b.IsValid()); |
| 372 | 372 |
| 373 FilePath to_sub_long = base_b.Append(FPL("to_sub_long")); | 373 FilePath to_sub_long = base_b.Append(FPL("to_sub_long")); |
| 374 ASSERT_TRUE(file_util::CreateDirectory(to_sub_long)); | 374 ASSERT_TRUE(base::CreateDirectory(to_sub_long)); |
| 375 ReparsePoint reparse_to_sub_long(to_sub_long, sub_long); | 375 ReparsePoint reparse_to_sub_long(to_sub_long, sub_long); |
| 376 ASSERT_TRUE(reparse_to_sub_long.IsValid()); | 376 ASSERT_TRUE(reparse_to_sub_long.IsValid()); |
| 377 | 377 |
| 378 // Normalize a junction free path: base_a\sub_a\file.txt . | 378 // Normalize a junction free path: base_a\sub_a\file.txt . |
| 379 ASSERT_TRUE(file_util::NormalizeFilePath(file_txt, &normalized_path)); | 379 ASSERT_TRUE(file_util::NormalizeFilePath(file_txt, &normalized_path)); |
| 380 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); | 380 ASSERT_STREQ(file_txt.value().c_str(), normalized_path.value().c_str()); |
| 381 | 381 |
| 382 // Check that the path base_b\to_sub_a\file.txt can be normalized to exclude | 382 // Check that the path base_b\to_sub_a\file.txt can be normalized to exclude |
| 383 // the junction to_sub_a. | 383 // the junction to_sub_a. |
| 384 ASSERT_TRUE(file_util::NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), | 384 ASSERT_TRUE(file_util::NormalizeFilePath(to_sub_a.Append(FPL("file.txt")), |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 real_device_path_plus_numbers, | 485 real_device_path_plus_numbers, |
| 486 &win32_path)); | 486 &win32_path)); |
| 487 | 487 |
| 488 ASSERT_FALSE(file_util::DevicePathToDriveLetterPath( | 488 ASSERT_FALSE(file_util::DevicePathToDriveLetterPath( |
| 489 real_device_path_plus_numbers.Append(kRelativePath), | 489 real_device_path_plus_numbers.Append(kRelativePath), |
| 490 &win32_path)); | 490 &win32_path)); |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST_F(FileUtilTest, GetPlatformFileInfoForDirectory) { | 493 TEST_F(FileUtilTest, GetPlatformFileInfoForDirectory) { |
| 494 FilePath empty_dir = temp_dir_.path().Append(FPL("gpfi_test")); | 494 FilePath empty_dir = temp_dir_.path().Append(FPL("gpfi_test")); |
| 495 ASSERT_TRUE(file_util::CreateDirectory(empty_dir)); | 495 ASSERT_TRUE(base::CreateDirectory(empty_dir)); |
| 496 win::ScopedHandle dir( | 496 win::ScopedHandle dir( |
| 497 ::CreateFile(empty_dir.value().c_str(), | 497 ::CreateFile(empty_dir.value().c_str(), |
| 498 FILE_ALL_ACCESS, | 498 FILE_ALL_ACCESS, |
| 499 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 499 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 500 NULL, | 500 NULL, |
| 501 OPEN_EXISTING, | 501 OPEN_EXISTING, |
| 502 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 502 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
| 503 NULL)); | 503 NULL)); |
| 504 ASSERT_TRUE(dir.IsValid()); | 504 ASSERT_TRUE(dir.IsValid()); |
| 505 PlatformFileInfo info; | 505 PlatformFileInfo info; |
| 506 EXPECT_TRUE(GetPlatformFileInfo(dir.Get(), &info)); | 506 EXPECT_TRUE(GetPlatformFileInfo(dir.Get(), &info)); |
| 507 EXPECT_TRUE(info.is_directory); | 507 EXPECT_TRUE(info.is_directory); |
| 508 EXPECT_FALSE(info.is_symbolic_link); | 508 EXPECT_FALSE(info.is_symbolic_link); |
| 509 EXPECT_EQ(0, info.size); | 509 EXPECT_EQ(0, info.size); |
| 510 } | 510 } |
| 511 | 511 |
| 512 TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { | 512 TEST_F(FileUtilTest, CreateTemporaryFileInDirLongPathTest) { |
| 513 // Test that CreateTemporaryFileInDir() creates a path and returns a long path | 513 // Test that CreateTemporaryFileInDir() creates a path and returns a long path |
| 514 // if it is available. This test requires that: | 514 // if it is available. This test requires that: |
| 515 // - the filesystem at |temp_dir_| supports long filenames. | 515 // - the filesystem at |temp_dir_| supports long filenames. |
| 516 // - the account has FILE_LIST_DIRECTORY permission for all ancestor | 516 // - the account has FILE_LIST_DIRECTORY permission for all ancestor |
| 517 // directories of |temp_dir_|. | 517 // directories of |temp_dir_|. |
| 518 const FilePath::CharType kLongDirName[] = FPL("A long path"); | 518 const FilePath::CharType kLongDirName[] = FPL("A long path"); |
| 519 const FilePath::CharType kTestSubDirName[] = FPL("test"); | 519 const FilePath::CharType kTestSubDirName[] = FPL("test"); |
| 520 FilePath long_test_dir = temp_dir_.path().Append(kLongDirName); | 520 FilePath long_test_dir = temp_dir_.path().Append(kLongDirName); |
| 521 ASSERT_TRUE(file_util::CreateDirectory(long_test_dir)); | 521 ASSERT_TRUE(base::CreateDirectory(long_test_dir)); |
| 522 | 522 |
| 523 // kLongDirName is not a 8.3 component. So GetShortName() should give us a | 523 // kLongDirName is not a 8.3 component. So GetShortName() should give us a |
| 524 // different short name. | 524 // different short name. |
| 525 WCHAR path_buffer[MAX_PATH]; | 525 WCHAR path_buffer[MAX_PATH]; |
| 526 DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(), | 526 DWORD path_buffer_length = GetShortPathName(long_test_dir.value().c_str(), |
| 527 path_buffer, MAX_PATH); | 527 path_buffer, MAX_PATH); |
| 528 ASSERT_LT(path_buffer_length, DWORD(MAX_PATH)); | 528 ASSERT_LT(path_buffer_length, DWORD(MAX_PATH)); |
| 529 ASSERT_NE(DWORD(0), path_buffer_length); | 529 ASSERT_NE(DWORD(0), path_buffer_length); |
| 530 FilePath short_test_dir(path_buffer); | 530 FilePath short_test_dir(path_buffer); |
| 531 ASSERT_STRNE(kLongDirName, short_test_dir.BaseName().value().c_str()); | 531 ASSERT_STRNE(kLongDirName, short_test_dir.BaseName().value().c_str()); |
| 532 | 532 |
| 533 FilePath temp_file; | 533 FilePath temp_file; |
| 534 ASSERT_TRUE(base::CreateTemporaryFileInDir(short_test_dir, &temp_file)); | 534 ASSERT_TRUE(base::CreateTemporaryFileInDir(short_test_dir, &temp_file)); |
| 535 EXPECT_STREQ(kLongDirName, temp_file.DirName().BaseName().value().c_str()); | 535 EXPECT_STREQ(kLongDirName, temp_file.DirName().BaseName().value().c_str()); |
| 536 EXPECT_TRUE(PathExists(temp_file)); | 536 EXPECT_TRUE(PathExists(temp_file)); |
| 537 | 537 |
| 538 // Create a subdirectory of |long_test_dir| and make |long_test_dir| | 538 // Create a subdirectory of |long_test_dir| and make |long_test_dir| |
| 539 // unreadable. We should still be able to create a temp file in the | 539 // unreadable. We should still be able to create a temp file in the |
| 540 // subdirectory, but we won't be able to determine the long path for it. This | 540 // subdirectory, but we won't be able to determine the long path for it. This |
| 541 // mimics the environment that some users run where their user profiles reside | 541 // mimics the environment that some users run where their user profiles reside |
| 542 // in a location where the don't have full access to the higher level | 542 // in a location where the don't have full access to the higher level |
| 543 // directories. (Note that this assumption is true for NTFS, but not for some | 543 // directories. (Note that this assumption is true for NTFS, but not for some |
| 544 // network file systems. E.g. AFS). | 544 // network file systems. E.g. AFS). |
| 545 FilePath access_test_dir = long_test_dir.Append(kTestSubDirName); | 545 FilePath access_test_dir = long_test_dir.Append(kTestSubDirName); |
| 546 ASSERT_TRUE(file_util::CreateDirectory(access_test_dir)); | 546 ASSERT_TRUE(base::CreateDirectory(access_test_dir)); |
| 547 file_util::PermissionRestorer long_test_dir_restorer(long_test_dir); | 547 file_util::PermissionRestorer long_test_dir_restorer(long_test_dir); |
| 548 ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir)); | 548 ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir)); |
| 549 | 549 |
| 550 // Use the short form of the directory to create a temporary filename. | 550 // Use the short form of the directory to create a temporary filename. |
| 551 ASSERT_TRUE(base::CreateTemporaryFileInDir( | 551 ASSERT_TRUE(base::CreateTemporaryFileInDir( |
| 552 short_test_dir.Append(kTestSubDirName), &temp_file)); | 552 short_test_dir.Append(kTestSubDirName), &temp_file)); |
| 553 EXPECT_TRUE(PathExists(temp_file)); | 553 EXPECT_TRUE(PathExists(temp_file)); |
| 554 EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); | 554 EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); |
| 555 | 555 |
| 556 // Check that the long path can't be determined for |temp_file|. | 556 // Check that the long path can't be determined for |temp_file|. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 576 std::wstring contents = ReadTextFile(link_from); | 576 std::wstring contents = ReadTextFile(link_from); |
| 577 EXPECT_EQ(bogus_content, contents); | 577 EXPECT_EQ(bogus_content, contents); |
| 578 | 578 |
| 579 FilePath result; | 579 FilePath result; |
| 580 ASSERT_TRUE(ReadSymbolicLink(link_from, &result)); | 580 ASSERT_TRUE(ReadSymbolicLink(link_from, &result)); |
| 581 EXPECT_EQ(link_to.value(), result.value()); | 581 EXPECT_EQ(link_to.value(), result.value()); |
| 582 | 582 |
| 583 // Link to a directory. | 583 // Link to a directory. |
| 584 link_from = temp_dir_.path().Append(FPL("from_dir")); | 584 link_from = temp_dir_.path().Append(FPL("from_dir")); |
| 585 link_to = temp_dir_.path().Append(FPL("to_dir")); | 585 link_to = temp_dir_.path().Append(FPL("to_dir")); |
| 586 ASSERT_TRUE(file_util::CreateDirectory(link_to)); | 586 ASSERT_TRUE(base::CreateDirectory(link_to)); |
| 587 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 587 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 588 << "Failed to create directory symlink."; | 588 << "Failed to create directory symlink."; |
| 589 | 589 |
| 590 // Test failures. | 590 // Test failures. |
| 591 EXPECT_FALSE(CreateSymbolicLink(link_to, link_to)); | 591 EXPECT_FALSE(CreateSymbolicLink(link_to, link_to)); |
| 592 EXPECT_FALSE(ReadSymbolicLink(link_to, &result)); | 592 EXPECT_FALSE(ReadSymbolicLink(link_to, &result)); |
| 593 FilePath missing = temp_dir_.path().Append(FPL("missing")); | 593 FilePath missing = temp_dir_.path().Append(FPL("missing")); |
| 594 EXPECT_FALSE(ReadSymbolicLink(missing, &result)); | 594 EXPECT_FALSE(ReadSymbolicLink(missing, &result)); |
| 595 } | 595 } |
| 596 | 596 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 611 // Check that NormalizeFilePath sees the link. | 611 // Check that NormalizeFilePath sees the link. |
| 612 FilePath normalized_path; | 612 FilePath normalized_path; |
| 613 ASSERT_TRUE(file_util::NormalizeFilePath(link_from, &normalized_path)); | 613 ASSERT_TRUE(file_util::NormalizeFilePath(link_from, &normalized_path)); |
| 614 EXPECT_NE(link_from, link_to); | 614 EXPECT_NE(link_from, link_to); |
| 615 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); | 615 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); |
| 616 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); | 616 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); |
| 617 | 617 |
| 618 // Link to a directory. | 618 // Link to a directory. |
| 619 link_from = temp_dir_.path().Append(FPL("from_dir")); | 619 link_from = temp_dir_.path().Append(FPL("from_dir")); |
| 620 link_to = temp_dir_.path().Append(FPL("to_dir")); | 620 link_to = temp_dir_.path().Append(FPL("to_dir")); |
| 621 ASSERT_TRUE(file_util::CreateDirectory(link_to)); | 621 ASSERT_TRUE(base::CreateDirectory(link_to)); |
| 622 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 622 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 623 << "Failed to create directory symlink."; | 623 << "Failed to create directory symlink."; |
| 624 | 624 |
| 625 EXPECT_FALSE(file_util::NormalizeFilePath(link_from, &normalized_path)) | 625 EXPECT_FALSE(file_util::NormalizeFilePath(link_from, &normalized_path)) |
| 626 << "Links to directories should return false."; | 626 << "Links to directories should return false."; |
| 627 | 627 |
| 628 // Test that a loop in the links causes NormalizeFilePath() to return false. | 628 // Test that a loop in the links causes NormalizeFilePath() to return false. |
| 629 link_from = temp_dir_.path().Append(FPL("link_a")); | 629 link_from = temp_dir_.path().Append(FPL("link_a")); |
| 630 link_to = temp_dir_.path().Append(FPL("link_b")); | 630 link_to = temp_dir_.path().Append(FPL("link_b")); |
| 631 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 631 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 | 790 |
| 791 // Delete the file. | 791 // Delete the file. |
| 792 EXPECT_TRUE(DeleteFile(file_name, false)); | 792 EXPECT_TRUE(DeleteFile(file_name, false)); |
| 793 EXPECT_FALSE(PathExists(file_name)); | 793 EXPECT_FALSE(PathExists(file_name)); |
| 794 } | 794 } |
| 795 | 795 |
| 796 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { | 796 TEST_F(FileUtilTest, ChangeDirectoryPermissionsAndEnumerate) { |
| 797 // Create a directory path. | 797 // Create a directory path. |
| 798 FilePath subdir_path = | 798 FilePath subdir_path = |
| 799 temp_dir_.path().Append(FPL("PermissionTest1")); | 799 temp_dir_.path().Append(FPL("PermissionTest1")); |
| 800 file_util::CreateDirectory(subdir_path); | 800 base::CreateDirectory(subdir_path); |
| 801 ASSERT_TRUE(PathExists(subdir_path)); | 801 ASSERT_TRUE(PathExists(subdir_path)); |
| 802 | 802 |
| 803 // Create a dummy file to enumerate. | 803 // Create a dummy file to enumerate. |
| 804 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); | 804 FilePath file_name = subdir_path.Append(FPL("Test Readable File.txt")); |
| 805 EXPECT_FALSE(PathExists(file_name)); | 805 EXPECT_FALSE(PathExists(file_name)); |
| 806 const std::string kData("hello"); | 806 const std::string kData("hello"); |
| 807 EXPECT_EQ(static_cast<int>(kData.length()), | 807 EXPECT_EQ(static_cast<int>(kData.length()), |
| 808 file_util::WriteFile(file_name, kData.data(), kData.length())); | 808 file_util::WriteFile(file_name, kData.data(), kData.length())); |
| 809 EXPECT_TRUE(PathExists(file_name)); | 809 EXPECT_TRUE(PathExists(file_name)); |
| 810 | 810 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 // Tests that the Delete function works for wild cards, especially | 847 // Tests that the Delete function works for wild cards, especially |
| 848 // with the recursion flag. Also coincidentally tests PathExists. | 848 // with the recursion flag. Also coincidentally tests PathExists. |
| 849 // TODO(erikkay): see if anyone's actually using this feature of the API | 849 // TODO(erikkay): see if anyone's actually using this feature of the API |
| 850 TEST_F(FileUtilTest, DeleteWildCard) { | 850 TEST_F(FileUtilTest, DeleteWildCard) { |
| 851 // Create a file and a directory | 851 // Create a file and a directory |
| 852 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); | 852 FilePath file_name = temp_dir_.path().Append(FPL("Test DeleteWildCard.txt")); |
| 853 CreateTextFile(file_name, bogus_content); | 853 CreateTextFile(file_name, bogus_content); |
| 854 ASSERT_TRUE(PathExists(file_name)); | 854 ASSERT_TRUE(PathExists(file_name)); |
| 855 | 855 |
| 856 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); | 856 FilePath subdir_path = temp_dir_.path().Append(FPL("DeleteWildCardDir")); |
| 857 file_util::CreateDirectory(subdir_path); | 857 base::CreateDirectory(subdir_path); |
| 858 ASSERT_TRUE(PathExists(subdir_path)); | 858 ASSERT_TRUE(PathExists(subdir_path)); |
| 859 | 859 |
| 860 // Create the wildcard path | 860 // Create the wildcard path |
| 861 FilePath directory_contents = temp_dir_.path(); | 861 FilePath directory_contents = temp_dir_.path(); |
| 862 directory_contents = directory_contents.Append(FPL("*")); | 862 directory_contents = directory_contents.Append(FPL("*")); |
| 863 | 863 |
| 864 // Delete non-recursively and check that only the file is deleted | 864 // Delete non-recursively and check that only the file is deleted |
| 865 EXPECT_TRUE(DeleteFile(directory_contents, false)); | 865 EXPECT_TRUE(DeleteFile(directory_contents, false)); |
| 866 EXPECT_FALSE(PathExists(file_name)); | 866 EXPECT_FALSE(PathExists(file_name)); |
| 867 EXPECT_TRUE(PathExists(subdir_path)); | 867 EXPECT_TRUE(PathExists(subdir_path)); |
| 868 | 868 |
| 869 // Delete recursively and make sure all contents are deleted | 869 // Delete recursively and make sure all contents are deleted |
| 870 EXPECT_TRUE(DeleteFile(directory_contents, true)); | 870 EXPECT_TRUE(DeleteFile(directory_contents, true)); |
| 871 EXPECT_FALSE(PathExists(file_name)); | 871 EXPECT_FALSE(PathExists(file_name)); |
| 872 EXPECT_FALSE(PathExists(subdir_path)); | 872 EXPECT_FALSE(PathExists(subdir_path)); |
| 873 } | 873 } |
| 874 | 874 |
| 875 // TODO(erikkay): see if anyone's actually using this feature of the API | 875 // TODO(erikkay): see if anyone's actually using this feature of the API |
| 876 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { | 876 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { |
| 877 // Create a file and a directory | 877 // Create a file and a directory |
| 878 FilePath subdir_path = | 878 FilePath subdir_path = |
| 879 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); | 879 temp_dir_.path().Append(FPL("DeleteNonExistantWildCard")); |
| 880 file_util::CreateDirectory(subdir_path); | 880 base::CreateDirectory(subdir_path); |
| 881 ASSERT_TRUE(PathExists(subdir_path)); | 881 ASSERT_TRUE(PathExists(subdir_path)); |
| 882 | 882 |
| 883 // Create the wildcard path | 883 // Create the wildcard path |
| 884 FilePath directory_contents = subdir_path; | 884 FilePath directory_contents = subdir_path; |
| 885 directory_contents = directory_contents.Append(FPL("*")); | 885 directory_contents = directory_contents.Append(FPL("*")); |
| 886 | 886 |
| 887 // Delete non-recursively and check nothing got deleted | 887 // Delete non-recursively and check nothing got deleted |
| 888 EXPECT_TRUE(DeleteFile(directory_contents, false)); | 888 EXPECT_TRUE(DeleteFile(directory_contents, false)); |
| 889 EXPECT_TRUE(PathExists(subdir_path)); | 889 EXPECT_TRUE(PathExists(subdir_path)); |
| 890 | 890 |
| 891 // Delete recursively and check nothing got deleted | 891 // Delete recursively and check nothing got deleted |
| 892 EXPECT_TRUE(DeleteFile(directory_contents, true)); | 892 EXPECT_TRUE(DeleteFile(directory_contents, true)); |
| 893 EXPECT_TRUE(PathExists(subdir_path)); | 893 EXPECT_TRUE(PathExists(subdir_path)); |
| 894 } | 894 } |
| 895 #endif | 895 #endif |
| 896 | 896 |
| 897 // Tests non-recursive Delete() for a directory. | 897 // Tests non-recursive Delete() for a directory. |
| 898 TEST_F(FileUtilTest, DeleteDirNonRecursive) { | 898 TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
| 899 // Create a subdirectory and put a file and two directories inside. | 899 // Create a subdirectory and put a file and two directories inside. |
| 900 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); | 900 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirNonRecursive")); |
| 901 file_util::CreateDirectory(test_subdir); | 901 base::CreateDirectory(test_subdir); |
| 902 ASSERT_TRUE(PathExists(test_subdir)); | 902 ASSERT_TRUE(PathExists(test_subdir)); |
| 903 | 903 |
| 904 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); | 904 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); |
| 905 CreateTextFile(file_name, bogus_content); | 905 CreateTextFile(file_name, bogus_content); |
| 906 ASSERT_TRUE(PathExists(file_name)); | 906 ASSERT_TRUE(PathExists(file_name)); |
| 907 | 907 |
| 908 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 908 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
| 909 file_util::CreateDirectory(subdir_path1); | 909 base::CreateDirectory(subdir_path1); |
| 910 ASSERT_TRUE(PathExists(subdir_path1)); | 910 ASSERT_TRUE(PathExists(subdir_path1)); |
| 911 | 911 |
| 912 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 912 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
| 913 file_util::CreateDirectory(subdir_path2); | 913 base::CreateDirectory(subdir_path2); |
| 914 ASSERT_TRUE(PathExists(subdir_path2)); | 914 ASSERT_TRUE(PathExists(subdir_path2)); |
| 915 | 915 |
| 916 // Delete non-recursively and check that the empty dir got deleted | 916 // Delete non-recursively and check that the empty dir got deleted |
| 917 EXPECT_TRUE(DeleteFile(subdir_path2, false)); | 917 EXPECT_TRUE(DeleteFile(subdir_path2, false)); |
| 918 EXPECT_FALSE(PathExists(subdir_path2)); | 918 EXPECT_FALSE(PathExists(subdir_path2)); |
| 919 | 919 |
| 920 // Delete non-recursively and check that nothing got deleted | 920 // Delete non-recursively and check that nothing got deleted |
| 921 EXPECT_FALSE(DeleteFile(test_subdir, false)); | 921 EXPECT_FALSE(DeleteFile(test_subdir, false)); |
| 922 EXPECT_TRUE(PathExists(test_subdir)); | 922 EXPECT_TRUE(PathExists(test_subdir)); |
| 923 EXPECT_TRUE(PathExists(file_name)); | 923 EXPECT_TRUE(PathExists(file_name)); |
| 924 EXPECT_TRUE(PathExists(subdir_path1)); | 924 EXPECT_TRUE(PathExists(subdir_path1)); |
| 925 } | 925 } |
| 926 | 926 |
| 927 // Tests recursive Delete() for a directory. | 927 // Tests recursive Delete() for a directory. |
| 928 TEST_F(FileUtilTest, DeleteDirRecursive) { | 928 TEST_F(FileUtilTest, DeleteDirRecursive) { |
| 929 // Create a subdirectory and put a file and two directories inside. | 929 // Create a subdirectory and put a file and two directories inside. |
| 930 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); | 930 FilePath test_subdir = temp_dir_.path().Append(FPL("DeleteDirRecursive")); |
| 931 file_util::CreateDirectory(test_subdir); | 931 base::CreateDirectory(test_subdir); |
| 932 ASSERT_TRUE(PathExists(test_subdir)); | 932 ASSERT_TRUE(PathExists(test_subdir)); |
| 933 | 933 |
| 934 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); | 934 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); |
| 935 CreateTextFile(file_name, bogus_content); | 935 CreateTextFile(file_name, bogus_content); |
| 936 ASSERT_TRUE(PathExists(file_name)); | 936 ASSERT_TRUE(PathExists(file_name)); |
| 937 | 937 |
| 938 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 938 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
| 939 file_util::CreateDirectory(subdir_path1); | 939 base::CreateDirectory(subdir_path1); |
| 940 ASSERT_TRUE(PathExists(subdir_path1)); | 940 ASSERT_TRUE(PathExists(subdir_path1)); |
| 941 | 941 |
| 942 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 942 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
| 943 file_util::CreateDirectory(subdir_path2); | 943 base::CreateDirectory(subdir_path2); |
| 944 ASSERT_TRUE(PathExists(subdir_path2)); | 944 ASSERT_TRUE(PathExists(subdir_path2)); |
| 945 | 945 |
| 946 // Delete recursively and check that the empty dir got deleted | 946 // Delete recursively and check that the empty dir got deleted |
| 947 EXPECT_TRUE(DeleteFile(subdir_path2, true)); | 947 EXPECT_TRUE(DeleteFile(subdir_path2, true)); |
| 948 EXPECT_FALSE(PathExists(subdir_path2)); | 948 EXPECT_FALSE(PathExists(subdir_path2)); |
| 949 | 949 |
| 950 // Delete recursively and check that everything got deleted | 950 // Delete recursively and check that everything got deleted |
| 951 EXPECT_TRUE(DeleteFile(test_subdir, true)); | 951 EXPECT_TRUE(DeleteFile(test_subdir, true)); |
| 952 EXPECT_FALSE(PathExists(file_name)); | 952 EXPECT_FALSE(PathExists(file_name)); |
| 953 EXPECT_FALSE(PathExists(subdir_path1)); | 953 EXPECT_FALSE(PathExists(subdir_path1)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 997 TEST_F(FileUtilTest, MoveFileDirExists) { | 997 TEST_F(FileUtilTest, MoveFileDirExists) { |
| 998 // Create a file | 998 // Create a file |
| 999 FilePath file_name_from = | 999 FilePath file_name_from = |
| 1000 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1000 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1001 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1001 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1002 ASSERT_TRUE(PathExists(file_name_from)); | 1002 ASSERT_TRUE(PathExists(file_name_from)); |
| 1003 | 1003 |
| 1004 // The destination directory | 1004 // The destination directory |
| 1005 FilePath dir_name_to = | 1005 FilePath dir_name_to = |
| 1006 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1006 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
| 1007 file_util::CreateDirectory(dir_name_to); | 1007 base::CreateDirectory(dir_name_to); |
| 1008 ASSERT_TRUE(PathExists(dir_name_to)); | 1008 ASSERT_TRUE(PathExists(dir_name_to)); |
| 1009 | 1009 |
| 1010 EXPECT_FALSE(Move(file_name_from, dir_name_to)); | 1010 EXPECT_FALSE(Move(file_name_from, dir_name_to)); |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 | 1013 |
| 1014 TEST_F(FileUtilTest, MoveNew) { | 1014 TEST_F(FileUtilTest, MoveNew) { |
| 1015 // Create a directory | 1015 // Create a directory |
| 1016 FilePath dir_name_from = | 1016 FilePath dir_name_from = |
| 1017 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1017 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
| 1018 file_util::CreateDirectory(dir_name_from); | 1018 base::CreateDirectory(dir_name_from); |
| 1019 ASSERT_TRUE(PathExists(dir_name_from)); | 1019 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1020 | 1020 |
| 1021 // Create a file under the directory | 1021 // Create a file under the directory |
| 1022 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1022 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1023 FilePath file_name_from = dir_name_from.Append(txt_file_name); | 1023 FilePath file_name_from = dir_name_from.Append(txt_file_name); |
| 1024 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1024 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1025 ASSERT_TRUE(PathExists(file_name_from)); | 1025 ASSERT_TRUE(PathExists(file_name_from)); |
| 1026 | 1026 |
| 1027 // Move the directory. | 1027 // Move the directory. |
| 1028 FilePath dir_name_to = | 1028 FilePath dir_name_to = |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1049 EXPECT_FALSE(PathExists(file_name_to)); | 1049 EXPECT_FALSE(PathExists(file_name_to)); |
| 1050 EXPECT_TRUE(internal::MoveUnsafe(file_name_from, file_name_to)); | 1050 EXPECT_TRUE(internal::MoveUnsafe(file_name_from, file_name_to)); |
| 1051 EXPECT_FALSE(PathExists(file_name_from)); | 1051 EXPECT_FALSE(PathExists(file_name_from)); |
| 1052 EXPECT_TRUE(PathExists(file_name_to)); | 1052 EXPECT_TRUE(PathExists(file_name_to)); |
| 1053 } | 1053 } |
| 1054 | 1054 |
| 1055 TEST_F(FileUtilTest, MoveExist) { | 1055 TEST_F(FileUtilTest, MoveExist) { |
| 1056 // Create a directory | 1056 // Create a directory |
| 1057 FilePath dir_name_from = | 1057 FilePath dir_name_from = |
| 1058 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1058 temp_dir_.path().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
| 1059 file_util::CreateDirectory(dir_name_from); | 1059 base::CreateDirectory(dir_name_from); |
| 1060 ASSERT_TRUE(PathExists(dir_name_from)); | 1060 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1061 | 1061 |
| 1062 // Create a file under the directory | 1062 // Create a file under the directory |
| 1063 FilePath file_name_from = | 1063 FilePath file_name_from = |
| 1064 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1064 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1065 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1065 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1066 ASSERT_TRUE(PathExists(file_name_from)); | 1066 ASSERT_TRUE(PathExists(file_name_from)); |
| 1067 | 1067 |
| 1068 // Move the directory | 1068 // Move the directory |
| 1069 FilePath dir_name_exists = | 1069 FilePath dir_name_exists = |
| 1070 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1070 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
| 1071 | 1071 |
| 1072 FilePath dir_name_to = | 1072 FilePath dir_name_to = |
| 1073 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 1073 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
| 1074 FilePath file_name_to = | 1074 FilePath file_name_to = |
| 1075 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1075 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1076 | 1076 |
| 1077 // Create the destination directory. | 1077 // Create the destination directory. |
| 1078 file_util::CreateDirectory(dir_name_exists); | 1078 base::CreateDirectory(dir_name_exists); |
| 1079 ASSERT_TRUE(PathExists(dir_name_exists)); | 1079 ASSERT_TRUE(PathExists(dir_name_exists)); |
| 1080 | 1080 |
| 1081 EXPECT_TRUE(Move(dir_name_from, dir_name_to)); | 1081 EXPECT_TRUE(Move(dir_name_from, dir_name_to)); |
| 1082 | 1082 |
| 1083 // Check everything has been moved. | 1083 // Check everything has been moved. |
| 1084 EXPECT_FALSE(PathExists(dir_name_from)); | 1084 EXPECT_FALSE(PathExists(dir_name_from)); |
| 1085 EXPECT_FALSE(PathExists(file_name_from)); | 1085 EXPECT_FALSE(PathExists(file_name_from)); |
| 1086 EXPECT_TRUE(PathExists(dir_name_to)); | 1086 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1087 EXPECT_TRUE(PathExists(file_name_to)); | 1087 EXPECT_TRUE(PathExists(file_name_to)); |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { | 1090 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
| 1091 // Create a directory. | 1091 // Create a directory. |
| 1092 FilePath dir_name_from = | 1092 FilePath dir_name_from = |
| 1093 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1093 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1094 file_util::CreateDirectory(dir_name_from); | 1094 base::CreateDirectory(dir_name_from); |
| 1095 ASSERT_TRUE(PathExists(dir_name_from)); | 1095 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1096 | 1096 |
| 1097 // Create a file under the directory. | 1097 // Create a file under the directory. |
| 1098 FilePath file_name_from = | 1098 FilePath file_name_from = |
| 1099 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1099 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1100 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1100 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1101 ASSERT_TRUE(PathExists(file_name_from)); | 1101 ASSERT_TRUE(PathExists(file_name_from)); |
| 1102 | 1102 |
| 1103 // Create a subdirectory. | 1103 // Create a subdirectory. |
| 1104 FilePath subdir_name_from = | 1104 FilePath subdir_name_from = |
| 1105 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1105 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1106 file_util::CreateDirectory(subdir_name_from); | 1106 base::CreateDirectory(subdir_name_from); |
| 1107 ASSERT_TRUE(PathExists(subdir_name_from)); | 1107 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1108 | 1108 |
| 1109 // Create a file under the subdirectory. | 1109 // Create a file under the subdirectory. |
| 1110 FilePath file_name2_from = | 1110 FilePath file_name2_from = |
| 1111 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1111 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1112 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1112 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 1113 ASSERT_TRUE(PathExists(file_name2_from)); | 1113 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1114 | 1114 |
| 1115 // Copy the directory recursively. | 1115 // Copy the directory recursively. |
| 1116 FilePath dir_name_to = | 1116 FilePath dir_name_to = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1134 EXPECT_TRUE(PathExists(dir_name_to)); | 1134 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1135 EXPECT_TRUE(PathExists(file_name_to)); | 1135 EXPECT_TRUE(PathExists(file_name_to)); |
| 1136 EXPECT_TRUE(PathExists(subdir_name_to)); | 1136 EXPECT_TRUE(PathExists(subdir_name_to)); |
| 1137 EXPECT_TRUE(PathExists(file_name2_to)); | 1137 EXPECT_TRUE(PathExists(file_name2_to)); |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { | 1140 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
| 1141 // Create a directory. | 1141 // Create a directory. |
| 1142 FilePath dir_name_from = | 1142 FilePath dir_name_from = |
| 1143 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1143 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1144 file_util::CreateDirectory(dir_name_from); | 1144 base::CreateDirectory(dir_name_from); |
| 1145 ASSERT_TRUE(PathExists(dir_name_from)); | 1145 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1146 | 1146 |
| 1147 // Create a file under the directory. | 1147 // Create a file under the directory. |
| 1148 FilePath file_name_from = | 1148 FilePath file_name_from = |
| 1149 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1149 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1150 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1150 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1151 ASSERT_TRUE(PathExists(file_name_from)); | 1151 ASSERT_TRUE(PathExists(file_name_from)); |
| 1152 | 1152 |
| 1153 // Create a subdirectory. | 1153 // Create a subdirectory. |
| 1154 FilePath subdir_name_from = | 1154 FilePath subdir_name_from = |
| 1155 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1155 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1156 file_util::CreateDirectory(subdir_name_from); | 1156 base::CreateDirectory(subdir_name_from); |
| 1157 ASSERT_TRUE(PathExists(subdir_name_from)); | 1157 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1158 | 1158 |
| 1159 // Create a file under the subdirectory. | 1159 // Create a file under the subdirectory. |
| 1160 FilePath file_name2_from = | 1160 FilePath file_name2_from = |
| 1161 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1161 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1162 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1162 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 1163 ASSERT_TRUE(PathExists(file_name2_from)); | 1163 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1164 | 1164 |
| 1165 // Copy the directory recursively. | 1165 // Copy the directory recursively. |
| 1166 FilePath dir_name_exists = | 1166 FilePath dir_name_exists = |
| 1167 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1167 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
| 1168 | 1168 |
| 1169 FilePath dir_name_to = | 1169 FilePath dir_name_to = |
| 1170 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1170 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1171 FilePath file_name_to = | 1171 FilePath file_name_to = |
| 1172 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1172 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1173 FilePath subdir_name_to = | 1173 FilePath subdir_name_to = |
| 1174 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1174 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1175 FilePath file_name2_to = | 1175 FilePath file_name2_to = |
| 1176 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1176 subdir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1177 | 1177 |
| 1178 // Create the destination directory. | 1178 // Create the destination directory. |
| 1179 file_util::CreateDirectory(dir_name_exists); | 1179 base::CreateDirectory(dir_name_exists); |
| 1180 ASSERT_TRUE(PathExists(dir_name_exists)); | 1180 ASSERT_TRUE(PathExists(dir_name_exists)); |
| 1181 | 1181 |
| 1182 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_exists, true)); | 1182 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_exists, true)); |
| 1183 | 1183 |
| 1184 // Check everything has been copied. | 1184 // Check everything has been copied. |
| 1185 EXPECT_TRUE(PathExists(dir_name_from)); | 1185 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1186 EXPECT_TRUE(PathExists(file_name_from)); | 1186 EXPECT_TRUE(PathExists(file_name_from)); |
| 1187 EXPECT_TRUE(PathExists(subdir_name_from)); | 1187 EXPECT_TRUE(PathExists(subdir_name_from)); |
| 1188 EXPECT_TRUE(PathExists(file_name2_from)); | 1188 EXPECT_TRUE(PathExists(file_name2_from)); |
| 1189 EXPECT_TRUE(PathExists(dir_name_to)); | 1189 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1190 EXPECT_TRUE(PathExists(file_name_to)); | 1190 EXPECT_TRUE(PathExists(file_name_to)); |
| 1191 EXPECT_TRUE(PathExists(subdir_name_to)); | 1191 EXPECT_TRUE(PathExists(subdir_name_to)); |
| 1192 EXPECT_TRUE(PathExists(file_name2_to)); | 1192 EXPECT_TRUE(PathExists(file_name2_to)); |
| 1193 } | 1193 } |
| 1194 | 1194 |
| 1195 TEST_F(FileUtilTest, CopyDirectoryNew) { | 1195 TEST_F(FileUtilTest, CopyDirectoryNew) { |
| 1196 // Create a directory. | 1196 // Create a directory. |
| 1197 FilePath dir_name_from = | 1197 FilePath dir_name_from = |
| 1198 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1198 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1199 file_util::CreateDirectory(dir_name_from); | 1199 base::CreateDirectory(dir_name_from); |
| 1200 ASSERT_TRUE(PathExists(dir_name_from)); | 1200 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1201 | 1201 |
| 1202 // Create a file under the directory. | 1202 // Create a file under the directory. |
| 1203 FilePath file_name_from = | 1203 FilePath file_name_from = |
| 1204 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1204 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1205 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1205 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1206 ASSERT_TRUE(PathExists(file_name_from)); | 1206 ASSERT_TRUE(PathExists(file_name_from)); |
| 1207 | 1207 |
| 1208 // Create a subdirectory. | 1208 // Create a subdirectory. |
| 1209 FilePath subdir_name_from = | 1209 FilePath subdir_name_from = |
| 1210 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1210 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1211 file_util::CreateDirectory(subdir_name_from); | 1211 base::CreateDirectory(subdir_name_from); |
| 1212 ASSERT_TRUE(PathExists(subdir_name_from)); | 1212 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1213 | 1213 |
| 1214 // Create a file under the subdirectory. | 1214 // Create a file under the subdirectory. |
| 1215 FilePath file_name2_from = | 1215 FilePath file_name2_from = |
| 1216 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1216 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1217 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1217 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 1218 ASSERT_TRUE(PathExists(file_name2_from)); | 1218 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1219 | 1219 |
| 1220 // Copy the directory not recursively. | 1220 // Copy the directory not recursively. |
| 1221 FilePath dir_name_to = | 1221 FilePath dir_name_to = |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1236 EXPECT_TRUE(PathExists(file_name2_from)); | 1236 EXPECT_TRUE(PathExists(file_name2_from)); |
| 1237 EXPECT_TRUE(PathExists(dir_name_to)); | 1237 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1238 EXPECT_TRUE(PathExists(file_name_to)); | 1238 EXPECT_TRUE(PathExists(file_name_to)); |
| 1239 EXPECT_FALSE(PathExists(subdir_name_to)); | 1239 EXPECT_FALSE(PathExists(subdir_name_to)); |
| 1240 } | 1240 } |
| 1241 | 1241 |
| 1242 TEST_F(FileUtilTest, CopyDirectoryExists) { | 1242 TEST_F(FileUtilTest, CopyDirectoryExists) { |
| 1243 // Create a directory. | 1243 // Create a directory. |
| 1244 FilePath dir_name_from = | 1244 FilePath dir_name_from = |
| 1245 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1245 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1246 file_util::CreateDirectory(dir_name_from); | 1246 base::CreateDirectory(dir_name_from); |
| 1247 ASSERT_TRUE(PathExists(dir_name_from)); | 1247 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1248 | 1248 |
| 1249 // Create a file under the directory. | 1249 // Create a file under the directory. |
| 1250 FilePath file_name_from = | 1250 FilePath file_name_from = |
| 1251 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1251 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1252 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1252 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1253 ASSERT_TRUE(PathExists(file_name_from)); | 1253 ASSERT_TRUE(PathExists(file_name_from)); |
| 1254 | 1254 |
| 1255 // Create a subdirectory. | 1255 // Create a subdirectory. |
| 1256 FilePath subdir_name_from = | 1256 FilePath subdir_name_from = |
| 1257 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1257 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1258 file_util::CreateDirectory(subdir_name_from); | 1258 base::CreateDirectory(subdir_name_from); |
| 1259 ASSERT_TRUE(PathExists(subdir_name_from)); | 1259 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1260 | 1260 |
| 1261 // Create a file under the subdirectory. | 1261 // Create a file under the subdirectory. |
| 1262 FilePath file_name2_from = | 1262 FilePath file_name2_from = |
| 1263 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1263 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1264 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1264 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); |
| 1265 ASSERT_TRUE(PathExists(file_name2_from)); | 1265 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1266 | 1266 |
| 1267 // Copy the directory not recursively. | 1267 // Copy the directory not recursively. |
| 1268 FilePath dir_name_to = | 1268 FilePath dir_name_to = |
| 1269 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1269 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1270 FilePath file_name_to = | 1270 FilePath file_name_to = |
| 1271 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1271 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1272 FilePath subdir_name_to = | 1272 FilePath subdir_name_to = |
| 1273 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1273 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1274 | 1274 |
| 1275 // Create the destination directory. | 1275 // Create the destination directory. |
| 1276 file_util::CreateDirectory(dir_name_to); | 1276 base::CreateDirectory(dir_name_to); |
| 1277 ASSERT_TRUE(PathExists(dir_name_to)); | 1277 ASSERT_TRUE(PathExists(dir_name_to)); |
| 1278 | 1278 |
| 1279 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); | 1279 EXPECT_TRUE(CopyDirectory(dir_name_from, dir_name_to, false)); |
| 1280 | 1280 |
| 1281 // Check everything has been copied. | 1281 // Check everything has been copied. |
| 1282 EXPECT_TRUE(PathExists(dir_name_from)); | 1282 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1283 EXPECT_TRUE(PathExists(file_name_from)); | 1283 EXPECT_TRUE(PathExists(file_name_from)); |
| 1284 EXPECT_TRUE(PathExists(subdir_name_from)); | 1284 EXPECT_TRUE(PathExists(subdir_name_from)); |
| 1285 EXPECT_TRUE(PathExists(file_name2_from)); | 1285 EXPECT_TRUE(PathExists(file_name2_from)); |
| 1286 EXPECT_TRUE(PathExists(dir_name_to)); | 1286 EXPECT_TRUE(PathExists(dir_name_to)); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { | 1329 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { |
| 1330 // Create a file | 1330 // Create a file |
| 1331 FilePath file_name_from = | 1331 FilePath file_name_from = |
| 1332 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1332 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1333 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1333 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1334 ASSERT_TRUE(PathExists(file_name_from)); | 1334 ASSERT_TRUE(PathExists(file_name_from)); |
| 1335 | 1335 |
| 1336 // The destination | 1336 // The destination |
| 1337 FilePath dir_name_to = | 1337 FilePath dir_name_to = |
| 1338 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); | 1338 temp_dir_.path().Append(FILE_PATH_LITERAL("Destination")); |
| 1339 file_util::CreateDirectory(dir_name_to); | 1339 base::CreateDirectory(dir_name_to); |
| 1340 ASSERT_TRUE(PathExists(dir_name_to)); | 1340 ASSERT_TRUE(PathExists(dir_name_to)); |
| 1341 FilePath file_name_to = | 1341 FilePath file_name_to = |
| 1342 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1342 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1343 | 1343 |
| 1344 EXPECT_TRUE(CopyDirectory(file_name_from, dir_name_to, true)); | 1344 EXPECT_TRUE(CopyDirectory(file_name_from, dir_name_to, true)); |
| 1345 | 1345 |
| 1346 // Check the has been copied | 1346 // Check the has been copied |
| 1347 EXPECT_TRUE(PathExists(file_name_to)); | 1347 EXPECT_TRUE(PathExists(file_name_to)); |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { | 1350 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { |
| 1351 // Create a directory. | 1351 // Create a directory. |
| 1352 FilePath dir_name_from = | 1352 FilePath dir_name_from = |
| 1353 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1353 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1354 file_util::CreateDirectory(dir_name_from); | 1354 base::CreateDirectory(dir_name_from); |
| 1355 ASSERT_TRUE(PathExists(dir_name_from)); | 1355 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1356 | 1356 |
| 1357 // Create a file under the directory. | 1357 // Create a file under the directory. |
| 1358 FilePath file_name_from = | 1358 FilePath file_name_from = |
| 1359 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1359 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1360 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1360 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1361 ASSERT_TRUE(PathExists(file_name_from)); | 1361 ASSERT_TRUE(PathExists(file_name_from)); |
| 1362 | 1362 |
| 1363 // Copy the directory recursively. | 1363 // Copy the directory recursively. |
| 1364 FilePath dir_name_to = | 1364 FilePath dir_name_to = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1381 EXPECT_TRUE(PathExists(dir_name_from)); | 1381 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1382 EXPECT_TRUE(PathExists(file_name_from)); | 1382 EXPECT_TRUE(PathExists(file_name_from)); |
| 1383 EXPECT_TRUE(PathExists(dir_name_to)); | 1383 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1384 EXPECT_TRUE(PathExists(file_name_to)); | 1384 EXPECT_TRUE(PathExists(file_name_to)); |
| 1385 } | 1385 } |
| 1386 | 1386 |
| 1387 TEST_F(FileUtilTest, CopyFile) { | 1387 TEST_F(FileUtilTest, CopyFile) { |
| 1388 // Create a directory | 1388 // Create a directory |
| 1389 FilePath dir_name_from = | 1389 FilePath dir_name_from = |
| 1390 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1390 temp_dir_.path().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1391 file_util::CreateDirectory(dir_name_from); | 1391 base::CreateDirectory(dir_name_from); |
| 1392 ASSERT_TRUE(PathExists(dir_name_from)); | 1392 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1393 | 1393 |
| 1394 // Create a file under the directory | 1394 // Create a file under the directory |
| 1395 FilePath file_name_from = | 1395 FilePath file_name_from = |
| 1396 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1396 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1397 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 1397 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
| 1398 CreateTextFile(file_name_from, file_contents); | 1398 CreateTextFile(file_name_from, file_contents); |
| 1399 ASSERT_TRUE(PathExists(file_name_from)); | 1399 ASSERT_TRUE(PathExists(file_name_from)); |
| 1400 | 1400 |
| 1401 // Copy the file. | 1401 // Copy the file. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 EXPECT_FALSE(TextContentsEqual(original_file, empty1_file)); | 1516 EXPECT_FALSE(TextContentsEqual(original_file, empty1_file)); |
| 1517 EXPECT_TRUE(TextContentsEqual(blank_line_file, blank_line_crlf_file)); | 1517 EXPECT_TRUE(TextContentsEqual(blank_line_file, blank_line_crlf_file)); |
| 1518 } | 1518 } |
| 1519 | 1519 |
| 1520 // We don't need equivalent functionality outside of Windows. | 1520 // We don't need equivalent functionality outside of Windows. |
| 1521 #if defined(OS_WIN) | 1521 #if defined(OS_WIN) |
| 1522 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { | 1522 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { |
| 1523 // Create a directory | 1523 // Create a directory |
| 1524 FilePath dir_name_from = | 1524 FilePath dir_name_from = |
| 1525 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); | 1525 temp_dir_.path().Append(FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); |
| 1526 file_util::CreateDirectory(dir_name_from); | 1526 base::CreateDirectory(dir_name_from); |
| 1527 ASSERT_TRUE(PathExists(dir_name_from)); | 1527 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1528 | 1528 |
| 1529 // Create a file under the directory | 1529 // Create a file under the directory |
| 1530 FilePath file_name_from = | 1530 FilePath file_name_from = |
| 1531 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1531 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
| 1532 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1532 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); |
| 1533 ASSERT_TRUE(PathExists(file_name_from)); | 1533 ASSERT_TRUE(PathExists(file_name_from)); |
| 1534 | 1534 |
| 1535 // Move the directory by using CopyAndDeleteDirectory | 1535 // Move the directory by using CopyAndDeleteDirectory |
| 1536 FilePath dir_name_to = temp_dir_.path().Append( | 1536 FilePath dir_name_to = temp_dir_.path().Append( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1645 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); | 1645 temp_dir_.path().Append(FILE_PATH_LITERAL("create_directory_test")); |
| 1646 #if defined(OS_WIN) | 1646 #if defined(OS_WIN) |
| 1647 FilePath test_path = | 1647 FilePath test_path = |
| 1648 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); | 1648 test_root.Append(FILE_PATH_LITERAL("dir\\tree\\likely\\doesnt\\exist\\")); |
| 1649 #elif defined(OS_POSIX) | 1649 #elif defined(OS_POSIX) |
| 1650 FilePath test_path = | 1650 FilePath test_path = |
| 1651 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); | 1651 test_root.Append(FILE_PATH_LITERAL("dir/tree/likely/doesnt/exist/")); |
| 1652 #endif | 1652 #endif |
| 1653 | 1653 |
| 1654 EXPECT_FALSE(PathExists(test_path)); | 1654 EXPECT_FALSE(PathExists(test_path)); |
| 1655 EXPECT_TRUE(file_util::CreateDirectory(test_path)); | 1655 EXPECT_TRUE(base::CreateDirectory(test_path)); |
| 1656 EXPECT_TRUE(PathExists(test_path)); | 1656 EXPECT_TRUE(PathExists(test_path)); |
| 1657 // CreateDirectory returns true if the DirectoryExists returns true. | 1657 // CreateDirectory returns true if the DirectoryExists returns true. |
| 1658 EXPECT_TRUE(file_util::CreateDirectory(test_path)); | 1658 EXPECT_TRUE(base::CreateDirectory(test_path)); |
| 1659 | 1659 |
| 1660 // Doesn't work to create it on top of a non-dir | 1660 // Doesn't work to create it on top of a non-dir |
| 1661 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); | 1661 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); |
| 1662 EXPECT_FALSE(PathExists(test_path)); | 1662 EXPECT_FALSE(PathExists(test_path)); |
| 1663 CreateTextFile(test_path, L"test file"); | 1663 CreateTextFile(test_path, L"test file"); |
| 1664 EXPECT_TRUE(PathExists(test_path)); | 1664 EXPECT_TRUE(PathExists(test_path)); |
| 1665 EXPECT_FALSE(file_util::CreateDirectory(test_path)); | 1665 EXPECT_FALSE(base::CreateDirectory(test_path)); |
| 1666 | 1666 |
| 1667 EXPECT_TRUE(DeleteFile(test_root, true)); | 1667 EXPECT_TRUE(DeleteFile(test_root, true)); |
| 1668 EXPECT_FALSE(PathExists(test_root)); | 1668 EXPECT_FALSE(PathExists(test_root)); |
| 1669 EXPECT_FALSE(PathExists(test_path)); | 1669 EXPECT_FALSE(PathExists(test_path)); |
| 1670 | 1670 |
| 1671 // Verify assumptions made by the Windows implementation: | 1671 // Verify assumptions made by the Windows implementation: |
| 1672 // 1. The current directory always exists. | 1672 // 1. The current directory always exists. |
| 1673 // 2. The root directory always exists. | 1673 // 2. The root directory always exists. |
| 1674 ASSERT_TRUE(DirectoryExists(FilePath(FilePath::kCurrentDirectory))); | 1674 ASSERT_TRUE(DirectoryExists(FilePath(FilePath::kCurrentDirectory))); |
| 1675 FilePath top_level = test_root; | 1675 FilePath top_level = test_root; |
| 1676 while (top_level != top_level.DirName()) { | 1676 while (top_level != top_level.DirName()) { |
| 1677 top_level = top_level.DirName(); | 1677 top_level = top_level.DirName(); |
| 1678 } | 1678 } |
| 1679 ASSERT_TRUE(DirectoryExists(top_level)); | 1679 ASSERT_TRUE(DirectoryExists(top_level)); |
| 1680 | 1680 |
| 1681 // Given these assumptions hold, it should be safe to | 1681 // Given these assumptions hold, it should be safe to |
| 1682 // test that "creating" these directories succeeds. | 1682 // test that "creating" these directories succeeds. |
| 1683 EXPECT_TRUE(file_util::CreateDirectory( | 1683 EXPECT_TRUE(base::CreateDirectory( |
| 1684 FilePath(FilePath::kCurrentDirectory))); | 1684 FilePath(FilePath::kCurrentDirectory))); |
| 1685 EXPECT_TRUE(file_util::CreateDirectory(top_level)); | 1685 EXPECT_TRUE(base::CreateDirectory(top_level)); |
| 1686 | 1686 |
| 1687 #if defined(OS_WIN) | 1687 #if defined(OS_WIN) |
| 1688 FilePath invalid_drive(FILE_PATH_LITERAL("o:\\")); | 1688 FilePath invalid_drive(FILE_PATH_LITERAL("o:\\")); |
| 1689 FilePath invalid_path = | 1689 FilePath invalid_path = |
| 1690 invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir")); | 1690 invalid_drive.Append(FILE_PATH_LITERAL("some\\inaccessible\\dir")); |
| 1691 if (!PathExists(invalid_drive)) { | 1691 if (!PathExists(invalid_drive)) { |
| 1692 EXPECT_FALSE(file_util::CreateDirectory(invalid_path)); | 1692 EXPECT_FALSE(base::CreateDirectory(invalid_path)); |
| 1693 } | 1693 } |
| 1694 #endif | 1694 #endif |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 TEST_F(FileUtilTest, DetectDirectoryTest) { | 1697 TEST_F(FileUtilTest, DetectDirectoryTest) { |
| 1698 // Check a directory | 1698 // Check a directory |
| 1699 FilePath test_root = | 1699 FilePath test_root = |
| 1700 temp_dir_.path().Append(FILE_PATH_LITERAL("detect_directory_test")); | 1700 temp_dir_.path().Append(FILE_PATH_LITERAL("detect_directory_test")); |
| 1701 EXPECT_FALSE(PathExists(test_root)); | 1701 EXPECT_FALSE(PathExists(test_root)); |
| 1702 EXPECT_TRUE(file_util::CreateDirectory(test_root)); | 1702 EXPECT_TRUE(base::CreateDirectory(test_root)); |
| 1703 EXPECT_TRUE(PathExists(test_root)); | 1703 EXPECT_TRUE(PathExists(test_root)); |
| 1704 EXPECT_TRUE(DirectoryExists(test_root)); | 1704 EXPECT_TRUE(DirectoryExists(test_root)); |
| 1705 // Check a file | 1705 // Check a file |
| 1706 FilePath test_path = | 1706 FilePath test_path = |
| 1707 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); | 1707 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); |
| 1708 EXPECT_FALSE(PathExists(test_path)); | 1708 EXPECT_FALSE(PathExists(test_path)); |
| 1709 CreateTextFile(test_path, L"test file"); | 1709 CreateTextFile(test_path, L"test file"); |
| 1710 EXPECT_TRUE(PathExists(test_path)); | 1710 EXPECT_TRUE(PathExists(test_path)); |
| 1711 EXPECT_FALSE(DirectoryExists(test_path)); | 1711 EXPECT_FALSE(DirectoryExists(test_path)); |
| 1712 EXPECT_TRUE(DeleteFile(test_path, false)); | 1712 EXPECT_TRUE(DeleteFile(test_path, false)); |
| 1713 | 1713 |
| 1714 EXPECT_TRUE(DeleteFile(test_root, true)); | 1714 EXPECT_TRUE(DeleteFile(test_root, true)); |
| 1715 } | 1715 } |
| 1716 | 1716 |
| 1717 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1717 TEST_F(FileUtilTest, FileEnumeratorTest) { |
| 1718 // Test an empty directory. | 1718 // Test an empty directory. |
| 1719 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); | 1719 FileEnumerator f0(temp_dir_.path(), true, FILES_AND_DIRECTORIES); |
| 1720 EXPECT_EQ(f0.Next().value(), FPL("")); | 1720 EXPECT_EQ(f0.Next().value(), FPL("")); |
| 1721 EXPECT_EQ(f0.Next().value(), FPL("")); | 1721 EXPECT_EQ(f0.Next().value(), FPL("")); |
| 1722 | 1722 |
| 1723 // Test an empty directory, non-recursively, including "..". | 1723 // Test an empty directory, non-recursively, including "..". |
| 1724 FileEnumerator f0_dotdot(temp_dir_.path(), false, | 1724 FileEnumerator f0_dotdot(temp_dir_.path(), false, |
| 1725 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); | 1725 FILES_AND_DIRECTORIES | FileEnumerator::INCLUDE_DOT_DOT); |
| 1726 EXPECT_EQ(temp_dir_.path().Append(FPL("..")).value(), | 1726 EXPECT_EQ(temp_dir_.path().Append(FPL("..")).value(), |
| 1727 f0_dotdot.Next().value()); | 1727 f0_dotdot.Next().value()); |
| 1728 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); | 1728 EXPECT_EQ(FPL(""), f0_dotdot.Next().value()); |
| 1729 | 1729 |
| 1730 // create the directories | 1730 // create the directories |
| 1731 FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); | 1731 FilePath dir1 = temp_dir_.path().Append(FPL("dir1")); |
| 1732 EXPECT_TRUE(file_util::CreateDirectory(dir1)); | 1732 EXPECT_TRUE(base::CreateDirectory(dir1)); |
| 1733 FilePath dir2 = temp_dir_.path().Append(FPL("dir2")); | 1733 FilePath dir2 = temp_dir_.path().Append(FPL("dir2")); |
| 1734 EXPECT_TRUE(file_util::CreateDirectory(dir2)); | 1734 EXPECT_TRUE(base::CreateDirectory(dir2)); |
| 1735 FilePath dir2inner = dir2.Append(FPL("inner")); | 1735 FilePath dir2inner = dir2.Append(FPL("inner")); |
| 1736 EXPECT_TRUE(file_util::CreateDirectory(dir2inner)); | 1736 EXPECT_TRUE(base::CreateDirectory(dir2inner)); |
| 1737 | 1737 |
| 1738 // create the files | 1738 // create the files |
| 1739 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); | 1739 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); |
| 1740 CreateTextFile(dir2file, std::wstring()); | 1740 CreateTextFile(dir2file, std::wstring()); |
| 1741 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); | 1741 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); |
| 1742 CreateTextFile(dir2innerfile, std::wstring()); | 1742 CreateTextFile(dir2innerfile, std::wstring()); |
| 1743 FilePath file1 = temp_dir_.path().Append(FPL("file1.txt")); | 1743 FilePath file1 = temp_dir_.path().Append(FPL("file1.txt")); |
| 1744 CreateTextFile(file1, std::wstring()); | 1744 CreateTextFile(file1, std::wstring()); |
| 1745 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) | 1745 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) |
| 1746 .Append(FPL("file2.txt")); | 1746 .Append(FPL("file2.txt")); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 } | 1863 } |
| 1864 | 1864 |
| 1865 TEST_F(FileUtilTest, AppendToFile) { | 1865 TEST_F(FileUtilTest, AppendToFile) { |
| 1866 FilePath data_dir = | 1866 FilePath data_dir = |
| 1867 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1867 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 1868 | 1868 |
| 1869 // Create a fresh, empty copy of this directory. | 1869 // Create a fresh, empty copy of this directory. |
| 1870 if (PathExists(data_dir)) { | 1870 if (PathExists(data_dir)) { |
| 1871 ASSERT_TRUE(DeleteFile(data_dir, true)); | 1871 ASSERT_TRUE(DeleteFile(data_dir, true)); |
| 1872 } | 1872 } |
| 1873 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1873 ASSERT_TRUE(base::CreateDirectory(data_dir)); |
| 1874 | 1874 |
| 1875 // Create a fresh, empty copy of this directory. | 1875 // Create a fresh, empty copy of this directory. |
| 1876 if (PathExists(data_dir)) { | 1876 if (PathExists(data_dir)) { |
| 1877 ASSERT_TRUE(DeleteFile(data_dir, true)); | 1877 ASSERT_TRUE(DeleteFile(data_dir, true)); |
| 1878 } | 1878 } |
| 1879 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1879 ASSERT_TRUE(base::CreateDirectory(data_dir)); |
| 1880 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 1880 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
| 1881 | 1881 |
| 1882 std::string data("hello"); | 1882 std::string data("hello"); |
| 1883 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1883 EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); |
| 1884 EXPECT_EQ(static_cast<int>(data.length()), | 1884 EXPECT_EQ(static_cast<int>(data.length()), |
| 1885 file_util::WriteFile(foobar, data.c_str(), data.length())); | 1885 file_util::WriteFile(foobar, data.c_str(), data.length())); |
| 1886 EXPECT_EQ(static_cast<int>(data.length()), | 1886 EXPECT_EQ(static_cast<int>(data.length()), |
| 1887 file_util::AppendToFile(foobar, data.c_str(), data.length())); | 1887 file_util::AppendToFile(foobar, data.c_str(), data.length())); |
| 1888 | 1888 |
| 1889 const std::wstring read_content = ReadTextFile(foobar); | 1889 const std::wstring read_content = ReadTextFile(foobar); |
| 1890 EXPECT_EQ(L"hellohello", read_content); | 1890 EXPECT_EQ(L"hellohello", read_content); |
| 1891 } | 1891 } |
| 1892 | 1892 |
| 1893 TEST_F(FileUtilTest, TouchFile) { | 1893 TEST_F(FileUtilTest, TouchFile) { |
| 1894 FilePath data_dir = | 1894 FilePath data_dir = |
| 1895 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); | 1895 temp_dir_.path().Append(FILE_PATH_LITERAL("FilePathTest")); |
| 1896 | 1896 |
| 1897 // Create a fresh, empty copy of this directory. | 1897 // Create a fresh, empty copy of this directory. |
| 1898 if (PathExists(data_dir)) { | 1898 if (PathExists(data_dir)) { |
| 1899 ASSERT_TRUE(DeleteFile(data_dir, true)); | 1899 ASSERT_TRUE(DeleteFile(data_dir, true)); |
| 1900 } | 1900 } |
| 1901 ASSERT_TRUE(file_util::CreateDirectory(data_dir)); | 1901 ASSERT_TRUE(base::CreateDirectory(data_dir)); |
| 1902 | 1902 |
| 1903 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); | 1903 FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); |
| 1904 std::string data("hello"); | 1904 std::string data("hello"); |
| 1905 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); | 1905 ASSERT_TRUE(file_util::WriteFile(foobar, data.c_str(), data.length())); |
| 1906 | 1906 |
| 1907 Time access_time; | 1907 Time access_time; |
| 1908 // This timestamp is divisible by one day (in local timezone), | 1908 // This timestamp is divisible by one day (in local timezone), |
| 1909 // to make it work on FAT too. | 1909 // to make it work on FAT too. |
| 1910 ASSERT_TRUE(Time::FromString("Wed, 16 Nov 1994, 00:00:00", | 1910 ASSERT_TRUE(Time::FromString("Wed, 16 Nov 1994, 00:00:00", |
| 1911 &access_time)); | 1911 &access_time)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1923 access_time.ToInternalValue()); | 1923 access_time.ToInternalValue()); |
| 1924 EXPECT_EQ(file_info.last_modified.ToInternalValue(), | 1924 EXPECT_EQ(file_info.last_modified.ToInternalValue(), |
| 1925 modification_time.ToInternalValue()); | 1925 modification_time.ToInternalValue()); |
| 1926 } | 1926 } |
| 1927 | 1927 |
| 1928 TEST_F(FileUtilTest, IsDirectoryEmpty) { | 1928 TEST_F(FileUtilTest, IsDirectoryEmpty) { |
| 1929 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); | 1929 FilePath empty_dir = temp_dir_.path().Append(FILE_PATH_LITERAL("EmptyDir")); |
| 1930 | 1930 |
| 1931 ASSERT_FALSE(PathExists(empty_dir)); | 1931 ASSERT_FALSE(PathExists(empty_dir)); |
| 1932 | 1932 |
| 1933 ASSERT_TRUE(file_util::CreateDirectory(empty_dir)); | 1933 ASSERT_TRUE(base::CreateDirectory(empty_dir)); |
| 1934 | 1934 |
| 1935 EXPECT_TRUE(base::IsDirectoryEmpty(empty_dir)); | 1935 EXPECT_TRUE(base::IsDirectoryEmpty(empty_dir)); |
| 1936 | 1936 |
| 1937 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 1937 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
| 1938 std::string bar("baz"); | 1938 std::string bar("baz"); |
| 1939 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); | 1939 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); |
| 1940 | 1940 |
| 1941 EXPECT_FALSE(base::IsDirectoryEmpty(empty_dir)); | 1941 EXPECT_FALSE(base::IsDirectoryEmpty(empty_dir)); |
| 1942 } | 1942 } |
| 1943 | 1943 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1955 protected: | 1955 protected: |
| 1956 virtual void SetUp() OVERRIDE { | 1956 virtual void SetUp() OVERRIDE { |
| 1957 FileUtilTest::SetUp(); | 1957 FileUtilTest::SetUp(); |
| 1958 | 1958 |
| 1959 // Create a basic structure used by each test. | 1959 // Create a basic structure used by each test. |
| 1960 // base_dir_ | 1960 // base_dir_ |
| 1961 // |-> sub_dir_ | 1961 // |-> sub_dir_ |
| 1962 // |-> text_file_ | 1962 // |-> text_file_ |
| 1963 | 1963 |
| 1964 base_dir_ = temp_dir_.path().AppendASCII("base_dir"); | 1964 base_dir_ = temp_dir_.path().AppendASCII("base_dir"); |
| 1965 ASSERT_TRUE(file_util::CreateDirectory(base_dir_)); | 1965 ASSERT_TRUE(base::CreateDirectory(base_dir_)); |
| 1966 | 1966 |
| 1967 sub_dir_ = base_dir_.AppendASCII("sub_dir"); | 1967 sub_dir_ = base_dir_.AppendASCII("sub_dir"); |
| 1968 ASSERT_TRUE(file_util::CreateDirectory(sub_dir_)); | 1968 ASSERT_TRUE(base::CreateDirectory(sub_dir_)); |
| 1969 | 1969 |
| 1970 text_file_ = sub_dir_.AppendASCII("file.txt"); | 1970 text_file_ = sub_dir_.AppendASCII("file.txt"); |
| 1971 CreateTextFile(text_file_, L"This text file has some text in it."); | 1971 CreateTextFile(text_file_, L"This text file has some text in it."); |
| 1972 | 1972 |
| 1973 // Get the user and group files are created with from |base_dir_|. | 1973 // Get the user and group files are created with from |base_dir_|. |
| 1974 struct stat stat_buf; | 1974 struct stat stat_buf; |
| 1975 ASSERT_EQ(0, stat(base_dir_.value().c_str(), &stat_buf)); | 1975 ASSERT_EQ(0, stat(base_dir_.value().c_str(), &stat_buf)); |
| 1976 uid_ = stat_buf.st_uid; | 1976 uid_ = stat_buf.st_uid; |
| 1977 ok_gids_.insert(stat_buf.st_gid); | 1977 ok_gids_.insert(stat_buf.st_gid); |
| 1978 bad_gids_.insert(stat_buf.st_gid + 1); | 1978 bad_gids_.insert(stat_buf.st_gid + 1); |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2352 int fd = OpenContentUriForRead(path); | 2352 int fd = OpenContentUriForRead(path); |
| 2353 EXPECT_EQ(-1, fd); | 2353 EXPECT_EQ(-1, fd); |
| 2354 } | 2354 } |
| 2355 #endif | 2355 #endif |
| 2356 | 2356 |
| 2357 #endif // defined(OS_POSIX) | 2357 #endif // defined(OS_POSIX) |
| 2358 | 2358 |
| 2359 } // namespace | 2359 } // namespace |
| 2360 | 2360 |
| 2361 } // namespace base | 2361 } // namespace base |
| OLD | NEW |