| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <fstream> | 9 #include <fstream> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 // file_util winds up using autoreleased objects on the Mac, so this needs | 186 // file_util winds up using autoreleased objects on the Mac, so this needs |
| 187 // to be a PlatformTest | 187 // to be a PlatformTest |
| 188 class FileUtilTest : public PlatformTest { | 188 class FileUtilTest : public PlatformTest { |
| 189 protected: | 189 protected: |
| 190 void SetUp() override { | 190 void SetUp() override { |
| 191 PlatformTest::SetUp(); | 191 PlatformTest::SetUp(); |
| 192 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 192 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // Sets the file to read-only. |
| 196 static void SetReadOnly(const FilePath& path, bool read_only) { |
| 197 #if defined(OS_WIN) |
| 198 // On Windows, it involves setting/removing the 'readonly' bit. |
| 199 DWORD attrs = GetFileAttributes(path.value().c_str()); |
| 200 ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs); |
| 201 ASSERT_TRUE(SetFileAttributes( |
| 202 path.value().c_str(), read_only ? (attrs | FILE_ATTRIBUTE_READONLY) |
| 203 : (attrs & ~FILE_ATTRIBUTE_READONLY))); |
| 204 |
| 205 DWORD expected = |
| 206 read_only |
| 207 ? ((attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)) | |
| 208 FILE_ATTRIBUTE_READONLY) |
| 209 : (attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)); |
| 210 |
| 211 // Ignore FILE_ATTRIBUTE_NOT_CONTENT_INDEXED if present. |
| 212 attrs = GetFileAttributes(path.value().c_str()) & |
| 213 ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; |
| 214 ASSERT_EQ(expected, attrs); |
| 215 #else |
| 216 // On all other platforms, it involves removing/setting the write bit. |
| 217 mode_t mode = read_only ? S_IRUSR : (S_IRUSR | S_IWUSR); |
| 218 EXPECT_TRUE(SetPosixFilePermissions( |
| 219 path, DirectoryExists(path) ? (mode | S_IXUSR) : mode)); |
| 220 #endif |
| 221 } |
| 222 |
| 223 static bool IsReadOnly(const FilePath& path) { |
| 224 #if defined(OS_WIN) |
| 225 DWORD attrs = GetFileAttributes(path.value().c_str()); |
| 226 EXPECT_NE(INVALID_FILE_ATTRIBUTES, attrs); |
| 227 return attrs & FILE_ATTRIBUTE_READONLY; |
| 228 #else |
| 229 int mode = 0; |
| 230 EXPECT_TRUE(GetPosixFilePermissions(path, &mode)); |
| 231 return !(mode & S_IWUSR); |
| 232 #endif |
| 233 } |
| 234 |
| 195 ScopedTempDir temp_dir_; | 235 ScopedTempDir temp_dir_; |
| 196 }; | 236 }; |
| 197 | 237 |
| 198 // Collects all the results from the given file enumerator, and provides an | 238 // Collects all the results from the given file enumerator, and provides an |
| 199 // interface to query whether a given file is present. | 239 // interface to query whether a given file is present. |
| 200 class FindResultCollector { | 240 class FindResultCollector { |
| 201 public: | 241 public: |
| 202 explicit FindResultCollector(FileEnumerator* enumerator) { | 242 explicit FindResultCollector(FileEnumerator* enumerator) { |
| 203 FilePath cur_file; | 243 FilePath cur_file; |
| 204 while (!(cur_file = enumerator->Next()).value().empty()) { | 244 while (!(cur_file = enumerator->Next()).value().empty()) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 EXPECT_TRUE(file.is_open()); | 283 EXPECT_TRUE(file.is_open()); |
| 244 file.getline(contents, arraysize(contents)); | 284 file.getline(contents, arraysize(contents)); |
| 245 file.close(); | 285 file.close(); |
| 246 return std::wstring(contents); | 286 return std::wstring(contents); |
| 247 } | 287 } |
| 248 | 288 |
| 249 TEST_F(FileUtilTest, FileAndDirectorySize) { | 289 TEST_F(FileUtilTest, FileAndDirectorySize) { |
| 250 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize | 290 // Create three files of 20, 30 and 3 chars (utf8). ComputeDirectorySize |
| 251 // should return 53 bytes. | 291 // should return 53 bytes. |
| 252 FilePath file_01 = temp_dir_.GetPath().Append(FPL("The file 01.txt")); | 292 FilePath file_01 = temp_dir_.GetPath().Append(FPL("The file 01.txt")); |
| 253 CreateTextFile(file_01, L"12345678901234567890"); | 293 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_01, L"12345678901234567890")); |
| 254 int64_t size_f1 = 0; | 294 int64_t size_f1 = 0; |
| 255 ASSERT_TRUE(GetFileSize(file_01, &size_f1)); | 295 ASSERT_TRUE(GetFileSize(file_01, &size_f1)); |
| 256 EXPECT_EQ(20ll, size_f1); | 296 EXPECT_EQ(20ll, size_f1); |
| 257 | 297 |
| 258 FilePath subdir_path = temp_dir_.GetPath().Append(FPL("Level2")); | 298 FilePath subdir_path = temp_dir_.GetPath().Append(FPL("Level2")); |
| 259 CreateDirectory(subdir_path); | 299 CreateDirectory(subdir_path); |
| 260 | 300 |
| 261 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); | 301 FilePath file_02 = subdir_path.Append(FPL("The file 02.txt")); |
| 262 CreateTextFile(file_02, L"123456789012345678901234567890"); | 302 ASSERT_NO_FATAL_FAILURE( |
| 303 CreateTextFile(file_02, L"123456789012345678901234567890")); |
| 263 int64_t size_f2 = 0; | 304 int64_t size_f2 = 0; |
| 264 ASSERT_TRUE(GetFileSize(file_02, &size_f2)); | 305 ASSERT_TRUE(GetFileSize(file_02, &size_f2)); |
| 265 EXPECT_EQ(30ll, size_f2); | 306 EXPECT_EQ(30ll, size_f2); |
| 266 | 307 |
| 267 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); | 308 FilePath subsubdir_path = subdir_path.Append(FPL("Level3")); |
| 268 CreateDirectory(subsubdir_path); | 309 CreateDirectory(subsubdir_path); |
| 269 | 310 |
| 270 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); | 311 FilePath file_03 = subsubdir_path.Append(FPL("The file 03.txt")); |
| 271 CreateTextFile(file_03, L"123"); | 312 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_03, L"123")); |
| 272 | 313 |
| 273 int64_t computed_size = ComputeDirectorySize(temp_dir_.GetPath()); | 314 int64_t computed_size = ComputeDirectorySize(temp_dir_.GetPath()); |
| 274 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); | 315 EXPECT_EQ(size_f1 + size_f2 + 3, computed_size); |
| 275 } | 316 } |
| 276 | 317 |
| 277 TEST_F(FileUtilTest, NormalizeFilePathBasic) { | 318 TEST_F(FileUtilTest, NormalizeFilePathBasic) { |
| 278 // Create a directory under the test dir. Because we create it, | 319 // Create a directory under the test dir. Because we create it, |
| 279 // we know it is not a link. | 320 // we know it is not a link. |
| 280 FilePath file_a_path = temp_dir_.GetPath().Append(FPL("file_a")); | 321 FilePath file_a_path = temp_dir_.GetPath().Append(FPL("file_a")); |
| 281 FilePath dir_path = temp_dir_.GetPath().Append(FPL("dir")); | 322 FilePath dir_path = temp_dir_.GetPath().Append(FPL("dir")); |
| 282 FilePath file_b_path = dir_path.Append(FPL("file_b")); | 323 FilePath file_b_path = dir_path.Append(FPL("file_b")); |
| 283 CreateDirectory(dir_path); | 324 CreateDirectory(dir_path); |
| 284 | 325 |
| 285 FilePath normalized_file_a_path, normalized_file_b_path; | 326 FilePath normalized_file_a_path, normalized_file_b_path; |
| 286 ASSERT_FALSE(PathExists(file_a_path)); | 327 ASSERT_FALSE(PathExists(file_a_path)); |
| 287 ASSERT_FALSE(NormalizeFilePath(file_a_path, &normalized_file_a_path)) | 328 ASSERT_FALSE(NormalizeFilePath(file_a_path, &normalized_file_a_path)) |
| 288 << "NormalizeFilePath() should fail on nonexistent paths."; | 329 << "NormalizeFilePath() should fail on nonexistent paths."; |
| 289 | 330 |
| 290 CreateTextFile(file_a_path, bogus_content); | 331 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_a_path, bogus_content)); |
| 291 ASSERT_TRUE(PathExists(file_a_path)); | 332 ASSERT_TRUE(PathExists(file_a_path)); |
| 292 ASSERT_TRUE(NormalizeFilePath(file_a_path, &normalized_file_a_path)); | 333 ASSERT_TRUE(NormalizeFilePath(file_a_path, &normalized_file_a_path)); |
| 293 | 334 |
| 294 CreateTextFile(file_b_path, bogus_content); | 335 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_b_path, bogus_content)); |
| 295 ASSERT_TRUE(PathExists(file_b_path)); | 336 ASSERT_TRUE(PathExists(file_b_path)); |
| 296 ASSERT_TRUE(NormalizeFilePath(file_b_path, &normalized_file_b_path)); | 337 ASSERT_TRUE(NormalizeFilePath(file_b_path, &normalized_file_b_path)); |
| 297 | 338 |
| 298 // Beacuse this test created |dir_path|, we know it is not a link | 339 // Beacuse this test created |dir_path|, we know it is not a link |
| 299 // or junction. So, the real path of the directory holding file a | 340 // or junction. So, the real path of the directory holding file a |
| 300 // must be the parent of the path holding file b. | 341 // must be the parent of the path holding file b. |
| 301 ASSERT_TRUE(normalized_file_a_path.DirName() | 342 ASSERT_TRUE(normalized_file_a_path.DirName() |
| 302 .IsParent(normalized_file_b_path.DirName())); | 343 .IsParent(normalized_file_b_path.DirName())); |
| 303 } | 344 } |
| 304 | 345 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 326 ASSERT_FALSE(temp_base_a.empty()); | 367 ASSERT_FALSE(temp_base_a.empty()); |
| 327 *temp_base_a.begin() = ToUpperASCII(*temp_base_a.begin()); | 368 *temp_base_a.begin() = ToUpperASCII(*temp_base_a.begin()); |
| 328 base_a = FilePath(temp_base_a); | 369 base_a = FilePath(temp_base_a); |
| 329 #endif | 370 #endif |
| 330 ASSERT_TRUE(CreateDirectory(base_a)); | 371 ASSERT_TRUE(CreateDirectory(base_a)); |
| 331 | 372 |
| 332 FilePath sub_a = base_a.Append(FPL("sub_a")); | 373 FilePath sub_a = base_a.Append(FPL("sub_a")); |
| 333 ASSERT_TRUE(CreateDirectory(sub_a)); | 374 ASSERT_TRUE(CreateDirectory(sub_a)); |
| 334 | 375 |
| 335 FilePath file_txt = sub_a.Append(FPL("file.txt")); | 376 FilePath file_txt = sub_a.Append(FPL("file.txt")); |
| 336 CreateTextFile(file_txt, bogus_content); | 377 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_txt, bogus_content)); |
| 337 | 378 |
| 338 // Want a directory whose name is long enough to make the path to the file | 379 // Want a directory whose name is long enough to make the path to the file |
| 339 // inside just under MAX_PATH chars. This will be used to test that when | 380 // inside just under MAX_PATH chars. This will be used to test that when |
| 340 // a junction expands to a path over MAX_PATH chars in length, | 381 // a junction expands to a path over MAX_PATH chars in length, |
| 341 // NormalizeFilePath() fails without crashing. | 382 // NormalizeFilePath() fails without crashing. |
| 342 FilePath sub_long_rel(FPL("sub_long")); | 383 FilePath sub_long_rel(FPL("sub_long")); |
| 343 FilePath deep_txt(FPL("deep.txt")); | 384 FilePath deep_txt(FPL("deep.txt")); |
| 344 | 385 |
| 345 int target_length = MAX_PATH; | 386 int target_length = MAX_PATH; |
| 346 target_length -= (sub_a.value().length() + 1); // +1 for the sepperator '\'. | 387 target_length -= (sub_a.value().length() + 1); // +1 for the sepperator '\'. |
| 347 target_length -= (sub_long_rel.Append(deep_txt).value().length() + 1); | 388 target_length -= (sub_long_rel.Append(deep_txt).value().length() + 1); |
| 348 // Without making the path a bit shorter, CreateDirectory() fails. | 389 // Without making the path a bit shorter, CreateDirectory() fails. |
| 349 // the resulting path is still long enough to hit the failing case in | 390 // the resulting path is still long enough to hit the failing case in |
| 350 // NormalizePath(). | 391 // NormalizePath(). |
| 351 const int kCreateDirLimit = 4; | 392 const int kCreateDirLimit = 4; |
| 352 target_length -= kCreateDirLimit; | 393 target_length -= kCreateDirLimit; |
| 353 FilePath::StringType long_name_str = FPL("long_name_"); | 394 FilePath::StringType long_name_str = FPL("long_name_"); |
| 354 long_name_str.resize(target_length, '_'); | 395 long_name_str.resize(target_length, '_'); |
| 355 | 396 |
| 356 FilePath long_name = sub_a.Append(FilePath(long_name_str)); | 397 FilePath long_name = sub_a.Append(FilePath(long_name_str)); |
| 357 FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt); | 398 FilePath deep_file = long_name.Append(sub_long_rel).Append(deep_txt); |
| 358 ASSERT_EQ(static_cast<size_t>(MAX_PATH - kCreateDirLimit), | 399 ASSERT_EQ(static_cast<size_t>(MAX_PATH - kCreateDirLimit), |
| 359 deep_file.value().length()); | 400 deep_file.value().length()); |
| 360 | 401 |
| 361 FilePath sub_long = deep_file.DirName(); | 402 FilePath sub_long = deep_file.DirName(); |
| 362 ASSERT_TRUE(CreateDirectory(sub_long)); | 403 ASSERT_TRUE(CreateDirectory(sub_long)); |
| 363 CreateTextFile(deep_file, bogus_content); | 404 ASSERT_NO_FATAL_FAILURE(CreateTextFile(deep_file, bogus_content)); |
| 364 | 405 |
| 365 FilePath base_b = temp_dir_.GetPath().Append(FPL("base_b")); | 406 FilePath base_b = temp_dir_.GetPath().Append(FPL("base_b")); |
| 366 ASSERT_TRUE(CreateDirectory(base_b)); | 407 ASSERT_TRUE(CreateDirectory(base_b)); |
| 367 | 408 |
| 368 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); | 409 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); |
| 369 ASSERT_TRUE(CreateDirectory(to_sub_a)); | 410 ASSERT_TRUE(CreateDirectory(to_sub_a)); |
| 370 FilePath normalized_path; | 411 FilePath normalized_path; |
| 371 { | 412 { |
| 372 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); | 413 ReparsePoint reparse_to_sub_a(to_sub_a, sub_a); |
| 373 ASSERT_TRUE(reparse_to_sub_a.IsValid()); | 414 ASSERT_TRUE(reparse_to_sub_a.IsValid()); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 EXPECT_EQ(DWORD(0), path_buffer_length); | 587 EXPECT_EQ(DWORD(0), path_buffer_length); |
| 547 } | 588 } |
| 548 | 589 |
| 549 #endif // defined(OS_WIN) | 590 #endif // defined(OS_WIN) |
| 550 | 591 |
| 551 #if defined(OS_POSIX) | 592 #if defined(OS_POSIX) |
| 552 | 593 |
| 553 TEST_F(FileUtilTest, CreateAndReadSymlinks) { | 594 TEST_F(FileUtilTest, CreateAndReadSymlinks) { |
| 554 FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file")); | 595 FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file")); |
| 555 FilePath link_to = temp_dir_.GetPath().Append(FPL("to_file")); | 596 FilePath link_to = temp_dir_.GetPath().Append(FPL("to_file")); |
| 556 CreateTextFile(link_to, bogus_content); | 597 ASSERT_NO_FATAL_FAILURE(CreateTextFile(link_to, bogus_content)); |
| 557 | 598 |
| 558 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 599 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 559 << "Failed to create file symlink."; | 600 << "Failed to create file symlink."; |
| 560 | 601 |
| 561 // If we created the link properly, we should be able to read the contents | 602 // If we created the link properly, we should be able to read the contents |
| 562 // through it. | 603 // through it. |
| 563 std::wstring contents = ReadTextFile(link_from); | 604 std::wstring contents = ReadTextFile(link_from); |
| 564 EXPECT_EQ(bogus_content, contents); | 605 EXPECT_EQ(bogus_content, contents); |
| 565 | 606 |
| 566 FilePath result; | 607 FilePath result; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 583 | 624 |
| 584 // The following test of NormalizeFilePath() require that we create a symlink. | 625 // The following test of NormalizeFilePath() require that we create a symlink. |
| 585 // This can not be done on Windows before Vista. On Vista, creating a symlink | 626 // This can not be done on Windows before Vista. On Vista, creating a symlink |
| 586 // requires privilege "SeCreateSymbolicLinkPrivilege". | 627 // requires privilege "SeCreateSymbolicLinkPrivilege". |
| 587 // TODO(skerner): Investigate the possibility of giving base_unittests the | 628 // TODO(skerner): Investigate the possibility of giving base_unittests the |
| 588 // privileges required to create a symlink. | 629 // privileges required to create a symlink. |
| 589 TEST_F(FileUtilTest, NormalizeFilePathSymlinks) { | 630 TEST_F(FileUtilTest, NormalizeFilePathSymlinks) { |
| 590 // Link one file to another. | 631 // Link one file to another. |
| 591 FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file")); | 632 FilePath link_from = temp_dir_.GetPath().Append(FPL("from_file")); |
| 592 FilePath link_to = temp_dir_.GetPath().Append(FPL("to_file")); | 633 FilePath link_to = temp_dir_.GetPath().Append(FPL("to_file")); |
| 593 CreateTextFile(link_to, bogus_content); | 634 ASSERT_NO_FATAL_FAILURE(CreateTextFile(link_to, bogus_content)); |
| 594 | 635 |
| 595 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) | 636 ASSERT_TRUE(CreateSymbolicLink(link_to, link_from)) |
| 596 << "Failed to create file symlink."; | 637 << "Failed to create file symlink."; |
| 597 | 638 |
| 598 // Check that NormalizeFilePath sees the link. | 639 // Check that NormalizeFilePath sees the link. |
| 599 FilePath normalized_path; | 640 FilePath normalized_path; |
| 600 ASSERT_TRUE(NormalizeFilePath(link_from, &normalized_path)); | 641 ASSERT_TRUE(NormalizeFilePath(link_from, &normalized_path)); |
| 601 EXPECT_NE(link_from, link_to); | 642 EXPECT_NE(link_from, link_to); |
| 602 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); | 643 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); |
| 603 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); | 644 EXPECT_EQ(link_to.BaseName().value(), normalized_path.BaseName().value()); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 684 |
| 644 EXPECT_TRUE(DeleteFile(non_existent, false)); | 685 EXPECT_TRUE(DeleteFile(non_existent, false)); |
| 645 ASSERT_FALSE(PathExists(non_existent)); | 686 ASSERT_FALSE(PathExists(non_existent)); |
| 646 EXPECT_TRUE(DeleteFile(non_existent, true)); | 687 EXPECT_TRUE(DeleteFile(non_existent, true)); |
| 647 ASSERT_FALSE(PathExists(non_existent)); | 688 ASSERT_FALSE(PathExists(non_existent)); |
| 648 } | 689 } |
| 649 | 690 |
| 650 TEST_F(FileUtilTest, DeleteFile) { | 691 TEST_F(FileUtilTest, DeleteFile) { |
| 651 // Create a file | 692 // Create a file |
| 652 FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 1.txt")); | 693 FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 1.txt")); |
| 653 CreateTextFile(file_name, bogus_content); | 694 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
| 654 ASSERT_TRUE(PathExists(file_name)); | 695 ASSERT_TRUE(PathExists(file_name)); |
| 655 | 696 |
| 656 // Make sure it's deleted | 697 // Make sure it's deleted |
| 657 EXPECT_TRUE(DeleteFile(file_name, false)); | 698 EXPECT_TRUE(DeleteFile(file_name, false)); |
| 658 EXPECT_FALSE(PathExists(file_name)); | 699 EXPECT_FALSE(PathExists(file_name)); |
| 659 | 700 |
| 660 // Test recursive case, create a new file | 701 // Test recursive case, create a new file |
| 661 file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); | 702 file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); |
| 662 CreateTextFile(file_name, bogus_content); | 703 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
| 663 ASSERT_TRUE(PathExists(file_name)); | 704 ASSERT_TRUE(PathExists(file_name)); |
| 664 | 705 |
| 665 // Make sure it's deleted | 706 // Make sure it's deleted |
| 666 EXPECT_TRUE(DeleteFile(file_name, true)); | 707 EXPECT_TRUE(DeleteFile(file_name, true)); |
| 667 EXPECT_FALSE(PathExists(file_name)); | 708 EXPECT_FALSE(PathExists(file_name)); |
| 668 } | 709 } |
| 669 | 710 |
| 711 TEST_F(FileUtilTest, DeleteReadOnlyFile) { |
| 712 // Create a read-only file. |
| 713 FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 1.txt")); |
| 714 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
| 715 ASSERT_TRUE(PathExists(file_name)); |
| 716 ASSERT_NO_FATAL_FAILURE(SetReadOnly(file_name, true)); |
| 717 ASSERT_TRUE(IsReadOnly(file_name)); |
| 718 |
| 719 // Make sure it's deleted. |
| 720 EXPECT_TRUE(DeleteFile(file_name, false)); |
| 721 EXPECT_FALSE(PathExists(file_name)); |
| 722 |
| 723 // Test recursive case: create a new file. |
| 724 file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); |
| 725 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
| 726 ASSERT_TRUE(PathExists(file_name)); |
| 727 ASSERT_NO_FATAL_FAILURE(SetReadOnly(file_name, true)); |
| 728 ASSERT_TRUE(IsReadOnly(file_name)); |
| 729 |
| 730 // Make sure it's deleted. |
| 731 EXPECT_TRUE(DeleteFile(file_name, true)); |
| 732 EXPECT_FALSE(PathExists(file_name)); |
| 733 } |
| 734 |
| 670 #if defined(OS_POSIX) | 735 #if defined(OS_POSIX) |
| 671 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { | 736 TEST_F(FileUtilTest, DeleteSymlinkToExistentFile) { |
| 672 // Create a file. | 737 // Create a file. |
| 673 FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); | 738 FilePath file_name = temp_dir_.GetPath().Append(FPL("Test DeleteFile 2.txt")); |
| 674 CreateTextFile(file_name, bogus_content); | 739 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
| 675 ASSERT_TRUE(PathExists(file_name)); | 740 ASSERT_TRUE(PathExists(file_name)); |
| 676 | 741 |
| 677 // Create a symlink to the file. | 742 // Create a symlink to the file. |
| 678 FilePath file_link = temp_dir_.GetPath().Append("file_link_2"); | 743 FilePath file_link = temp_dir_.GetPath().Append("file_link_2"); |
| 679 ASSERT_TRUE(CreateSymbolicLink(file_name, file_link)) | 744 ASSERT_TRUE(CreateSymbolicLink(file_name, file_link)) |
| 680 << "Failed to create symlink."; | 745 << "Failed to create symlink."; |
| 681 | 746 |
| 682 // Delete the symbolic link. | 747 // Delete the symbolic link. |
| 683 EXPECT_TRUE(DeleteFile(file_link, false)); | 748 EXPECT_TRUE(DeleteFile(file_link, false)); |
| 684 | 749 |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 ASSERT_TRUE(SetPosixFilePermissions(dir1.Append(kExeFileName), | 940 ASSERT_TRUE(SetPosixFilePermissions(dir1.Append(kExeFileName), |
| 876 FILE_PERMISSION_EXECUTE_BY_USER)); | 941 FILE_PERMISSION_EXECUTE_BY_USER)); |
| 877 | 942 |
| 878 EXPECT_TRUE(ExecutableExistsInPath(env.get(), kExeFileName)); | 943 EXPECT_TRUE(ExecutableExistsInPath(env.get(), kExeFileName)); |
| 879 EXPECT_FALSE(ExecutableExistsInPath(env.get(), kRegularFileName)); | 944 EXPECT_FALSE(ExecutableExistsInPath(env.get(), kRegularFileName)); |
| 880 EXPECT_FALSE(ExecutableExistsInPath(env.get(), kDneFileName)); | 945 EXPECT_FALSE(ExecutableExistsInPath(env.get(), kDneFileName)); |
| 881 } | 946 } |
| 882 | 947 |
| 883 #endif // defined(OS_POSIX) | 948 #endif // defined(OS_POSIX) |
| 884 | 949 |
| 885 #if defined(OS_WIN) | |
| 886 // Tests that the Delete function works for wild cards, especially | |
| 887 // with the recursion flag. Also coincidentally tests PathExists. | |
| 888 // TODO(erikkay): see if anyone's actually using this feature of the API | |
| 889 TEST_F(FileUtilTest, DeleteWildCard) { | |
| 890 // Create a file and a directory | |
| 891 FilePath file_name = | |
| 892 temp_dir_.GetPath().Append(FPL("Test DeleteWildCard.txt")); | |
| 893 CreateTextFile(file_name, bogus_content); | |
| 894 ASSERT_TRUE(PathExists(file_name)); | |
| 895 | |
| 896 FilePath subdir_path = temp_dir_.GetPath().Append(FPL("DeleteWildCardDir")); | |
| 897 CreateDirectory(subdir_path); | |
| 898 ASSERT_TRUE(PathExists(subdir_path)); | |
| 899 | |
| 900 // Create the wildcard path | |
| 901 FilePath directory_contents = temp_dir_.GetPath(); | |
| 902 directory_contents = directory_contents.Append(FPL("*")); | |
| 903 | |
| 904 // Delete non-recursively and check that only the file is deleted | |
| 905 EXPECT_TRUE(DeleteFile(directory_contents, false)); | |
| 906 EXPECT_FALSE(PathExists(file_name)); | |
| 907 EXPECT_TRUE(PathExists(subdir_path)); | |
| 908 | |
| 909 // Delete recursively and make sure all contents are deleted | |
| 910 EXPECT_TRUE(DeleteFile(directory_contents, true)); | |
| 911 EXPECT_FALSE(PathExists(file_name)); | |
| 912 EXPECT_FALSE(PathExists(subdir_path)); | |
| 913 } | |
| 914 | |
| 915 // TODO(erikkay): see if anyone's actually using this feature of the API | |
| 916 TEST_F(FileUtilTest, DeleteNonExistantWildCard) { | |
| 917 // Create a file and a directory | |
| 918 FilePath subdir_path = | |
| 919 temp_dir_.GetPath().Append(FPL("DeleteNonExistantWildCard")); | |
| 920 CreateDirectory(subdir_path); | |
| 921 ASSERT_TRUE(PathExists(subdir_path)); | |
| 922 | |
| 923 // Create the wildcard path | |
| 924 FilePath directory_contents = subdir_path; | |
| 925 directory_contents = directory_contents.Append(FPL("*")); | |
| 926 | |
| 927 // Delete non-recursively and check nothing got deleted | |
| 928 EXPECT_TRUE(DeleteFile(directory_contents, false)); | |
| 929 EXPECT_TRUE(PathExists(subdir_path)); | |
| 930 | |
| 931 // Delete recursively and check nothing got deleted | |
| 932 EXPECT_TRUE(DeleteFile(directory_contents, true)); | |
| 933 EXPECT_TRUE(PathExists(subdir_path)); | |
| 934 } | |
| 935 #endif | |
| 936 | |
| 937 // Tests non-recursive Delete() for a directory. | 950 // Tests non-recursive Delete() for a directory. |
| 938 TEST_F(FileUtilTest, DeleteDirNonRecursive) { | 951 TEST_F(FileUtilTest, DeleteDirNonRecursive) { |
| 939 // Create a subdirectory and put a file and two directories inside. | 952 // Create a subdirectory and put a file and two directories inside. |
| 940 FilePath test_subdir = | 953 FilePath test_subdir = |
| 941 temp_dir_.GetPath().Append(FPL("DeleteDirNonRecursive")); | 954 temp_dir_.GetPath().Append(FPL("DeleteDirNonRecursive")); |
| 942 CreateDirectory(test_subdir); | 955 CreateDirectory(test_subdir); |
| 943 ASSERT_TRUE(PathExists(test_subdir)); | 956 ASSERT_TRUE(PathExists(test_subdir)); |
| 944 | 957 |
| 945 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); | 958 FilePath file_name = test_subdir.Append(FPL("Test DeleteDir.txt")); |
| 946 CreateTextFile(file_name, bogus_content); | 959 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
| 947 ASSERT_TRUE(PathExists(file_name)); | 960 ASSERT_TRUE(PathExists(file_name)); |
| 948 | 961 |
| 949 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 962 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
| 950 CreateDirectory(subdir_path1); | 963 CreateDirectory(subdir_path1); |
| 951 ASSERT_TRUE(PathExists(subdir_path1)); | 964 ASSERT_TRUE(PathExists(subdir_path1)); |
| 952 | 965 |
| 953 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 966 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
| 954 CreateDirectory(subdir_path2); | 967 CreateDirectory(subdir_path2); |
| 955 ASSERT_TRUE(PathExists(subdir_path2)); | 968 ASSERT_TRUE(PathExists(subdir_path2)); |
| 956 | 969 |
| 957 // Delete non-recursively and check that the empty dir got deleted | 970 // Delete non-recursively and check that the empty dir got deleted |
| 958 EXPECT_TRUE(DeleteFile(subdir_path2, false)); | 971 EXPECT_TRUE(DeleteFile(subdir_path2, false)); |
| 959 EXPECT_FALSE(PathExists(subdir_path2)); | 972 EXPECT_FALSE(PathExists(subdir_path2)); |
| 960 | 973 |
| 961 // Delete non-recursively and check that nothing got deleted | 974 // Delete non-recursively and check that nothing got deleted |
| 962 EXPECT_FALSE(DeleteFile(test_subdir, false)); | 975 EXPECT_FALSE(DeleteFile(test_subdir, false)); |
| 963 EXPECT_TRUE(PathExists(test_subdir)); | 976 EXPECT_TRUE(PathExists(test_subdir)); |
| 964 EXPECT_TRUE(PathExists(file_name)); | 977 EXPECT_TRUE(PathExists(file_name)); |
| 965 EXPECT_TRUE(PathExists(subdir_path1)); | 978 EXPECT_TRUE(PathExists(subdir_path1)); |
| 966 } | 979 } |
| 967 | 980 |
| 968 // Tests recursive Delete() for a directory. | 981 // Tests recursive Delete() for a directory. |
| 969 TEST_F(FileUtilTest, DeleteDirRecursive) { | 982 TEST_F(FileUtilTest, DeleteDirRecursive) { |
| 970 // Create a subdirectory and put a file and two directories inside. | 983 // Create a subdirectory and put a file and two directories inside. |
| 971 FilePath test_subdir = temp_dir_.GetPath().Append(FPL("DeleteDirRecursive")); | 984 FilePath test_subdir = temp_dir_.GetPath().Append(FPL("DeleteDirRecursive")); |
| 972 CreateDirectory(test_subdir); | 985 CreateDirectory(test_subdir); |
| 973 ASSERT_TRUE(PathExists(test_subdir)); | 986 ASSERT_TRUE(PathExists(test_subdir)); |
| 974 | 987 |
| 975 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); | 988 FilePath file_name = test_subdir.Append(FPL("Test DeleteDirRecursive.txt")); |
| 976 CreateTextFile(file_name, bogus_content); | 989 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name, bogus_content)); |
| 977 ASSERT_TRUE(PathExists(file_name)); | 990 ASSERT_TRUE(PathExists(file_name)); |
| 978 | 991 |
| 979 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); | 992 FilePath subdir_path1 = test_subdir.Append(FPL("TestSubDir1")); |
| 980 CreateDirectory(subdir_path1); | 993 CreateDirectory(subdir_path1); |
| 981 ASSERT_TRUE(PathExists(subdir_path1)); | 994 ASSERT_TRUE(PathExists(subdir_path1)); |
| 982 | 995 |
| 983 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); | 996 FilePath subdir_path2 = test_subdir.Append(FPL("TestSubDir2")); |
| 984 CreateDirectory(subdir_path2); | 997 CreateDirectory(subdir_path2); |
| 985 ASSERT_TRUE(PathExists(subdir_path2)); | 998 ASSERT_TRUE(PathExists(subdir_path2)); |
| 986 | 999 |
| 987 // Delete recursively and check that the empty dir got deleted | 1000 // Delete recursively and check that the empty dir got deleted |
| 988 EXPECT_TRUE(DeleteFile(subdir_path2, true)); | 1001 EXPECT_TRUE(DeleteFile(subdir_path2, true)); |
| 989 EXPECT_FALSE(PathExists(subdir_path2)); | 1002 EXPECT_FALSE(PathExists(subdir_path2)); |
| 990 | 1003 |
| 991 // Delete recursively and check that everything got deleted | 1004 // Delete recursively and check that everything got deleted |
| 992 EXPECT_TRUE(DeleteFile(test_subdir, true)); | 1005 EXPECT_TRUE(DeleteFile(test_subdir, true)); |
| 993 EXPECT_FALSE(PathExists(file_name)); | 1006 EXPECT_FALSE(PathExists(file_name)); |
| 994 EXPECT_FALSE(PathExists(subdir_path1)); | 1007 EXPECT_FALSE(PathExists(subdir_path1)); |
| 995 EXPECT_FALSE(PathExists(test_subdir)); | 1008 EXPECT_FALSE(PathExists(test_subdir)); |
| 996 } | 1009 } |
| 997 | 1010 |
| 998 TEST_F(FileUtilTest, MoveFileNew) { | 1011 TEST_F(FileUtilTest, MoveFileNew) { |
| 999 // Create a file | 1012 // Create a file |
| 1000 FilePath file_name_from = | 1013 FilePath file_name_from = |
| 1001 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1014 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1002 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1015 ASSERT_NO_FATAL_FAILURE( |
| 1016 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1003 ASSERT_TRUE(PathExists(file_name_from)); | 1017 ASSERT_TRUE(PathExists(file_name_from)); |
| 1004 | 1018 |
| 1005 // The destination. | 1019 // The destination. |
| 1006 FilePath file_name_to = temp_dir_.GetPath().Append( | 1020 FilePath file_name_to = temp_dir_.GetPath().Append( |
| 1007 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); | 1021 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
| 1008 ASSERT_FALSE(PathExists(file_name_to)); | 1022 ASSERT_FALSE(PathExists(file_name_to)); |
| 1009 | 1023 |
| 1010 EXPECT_TRUE(Move(file_name_from, file_name_to)); | 1024 EXPECT_TRUE(Move(file_name_from, file_name_to)); |
| 1011 | 1025 |
| 1012 // Check everything has been moved. | 1026 // Check everything has been moved. |
| 1013 EXPECT_FALSE(PathExists(file_name_from)); | 1027 EXPECT_FALSE(PathExists(file_name_from)); |
| 1014 EXPECT_TRUE(PathExists(file_name_to)); | 1028 EXPECT_TRUE(PathExists(file_name_to)); |
| 1015 } | 1029 } |
| 1016 | 1030 |
| 1017 TEST_F(FileUtilTest, MoveFileExists) { | 1031 TEST_F(FileUtilTest, MoveFileExists) { |
| 1018 // Create a file | 1032 // Create a file |
| 1019 FilePath file_name_from = | 1033 FilePath file_name_from = |
| 1020 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1034 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1021 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1035 ASSERT_NO_FATAL_FAILURE( |
| 1036 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1022 ASSERT_TRUE(PathExists(file_name_from)); | 1037 ASSERT_TRUE(PathExists(file_name_from)); |
| 1023 | 1038 |
| 1024 // The destination name. | 1039 // The destination name. |
| 1025 FilePath file_name_to = temp_dir_.GetPath().Append( | 1040 FilePath file_name_to = temp_dir_.GetPath().Append( |
| 1026 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); | 1041 FILE_PATH_LITERAL("Move_Test_File_Destination.txt")); |
| 1027 CreateTextFile(file_name_to, L"Old file content"); | 1042 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name_to, L"Old file content")); |
| 1028 ASSERT_TRUE(PathExists(file_name_to)); | 1043 ASSERT_TRUE(PathExists(file_name_to)); |
| 1029 | 1044 |
| 1030 EXPECT_TRUE(Move(file_name_from, file_name_to)); | 1045 EXPECT_TRUE(Move(file_name_from, file_name_to)); |
| 1031 | 1046 |
| 1032 // Check everything has been moved. | 1047 // Check everything has been moved. |
| 1033 EXPECT_FALSE(PathExists(file_name_from)); | 1048 EXPECT_FALSE(PathExists(file_name_from)); |
| 1034 EXPECT_TRUE(PathExists(file_name_to)); | 1049 EXPECT_TRUE(PathExists(file_name_to)); |
| 1035 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); | 1050 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
| 1036 } | 1051 } |
| 1037 | 1052 |
| 1038 TEST_F(FileUtilTest, MoveFileDirExists) { | 1053 TEST_F(FileUtilTest, MoveFileDirExists) { |
| 1039 // Create a file | 1054 // Create a file |
| 1040 FilePath file_name_from = | 1055 FilePath file_name_from = |
| 1041 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1056 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1042 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1057 ASSERT_NO_FATAL_FAILURE( |
| 1058 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1043 ASSERT_TRUE(PathExists(file_name_from)); | 1059 ASSERT_TRUE(PathExists(file_name_from)); |
| 1044 | 1060 |
| 1045 // The destination directory | 1061 // The destination directory |
| 1046 FilePath dir_name_to = | 1062 FilePath dir_name_to = |
| 1047 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); | 1063 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); |
| 1048 CreateDirectory(dir_name_to); | 1064 CreateDirectory(dir_name_to); |
| 1049 ASSERT_TRUE(PathExists(dir_name_to)); | 1065 ASSERT_TRUE(PathExists(dir_name_to)); |
| 1050 | 1066 |
| 1051 EXPECT_FALSE(Move(file_name_from, dir_name_to)); | 1067 EXPECT_FALSE(Move(file_name_from, dir_name_to)); |
| 1052 } | 1068 } |
| 1053 | 1069 |
| 1054 | 1070 |
| 1055 TEST_F(FileUtilTest, MoveNew) { | 1071 TEST_F(FileUtilTest, MoveNew) { |
| 1056 // Create a directory | 1072 // Create a directory |
| 1057 FilePath dir_name_from = | 1073 FilePath dir_name_from = |
| 1058 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1074 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
| 1059 CreateDirectory(dir_name_from); | 1075 CreateDirectory(dir_name_from); |
| 1060 ASSERT_TRUE(PathExists(dir_name_from)); | 1076 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1061 | 1077 |
| 1062 // Create a file under the directory | 1078 // Create a file under the directory |
| 1063 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1079 FilePath txt_file_name(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1064 FilePath file_name_from = dir_name_from.Append(txt_file_name); | 1080 FilePath file_name_from = dir_name_from.Append(txt_file_name); |
| 1065 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1081 ASSERT_NO_FATAL_FAILURE( |
| 1082 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1066 ASSERT_TRUE(PathExists(file_name_from)); | 1083 ASSERT_TRUE(PathExists(file_name_from)); |
| 1067 | 1084 |
| 1068 // Move the directory. | 1085 // Move the directory. |
| 1069 FilePath dir_name_to = | 1086 FilePath dir_name_to = |
| 1070 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 1087 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
| 1071 FilePath file_name_to = | 1088 FilePath file_name_to = |
| 1072 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1089 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1073 | 1090 |
| 1074 ASSERT_FALSE(PathExists(dir_name_to)); | 1091 ASSERT_FALSE(PathExists(dir_name_to)); |
| 1075 | 1092 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1096 TEST_F(FileUtilTest, MoveExist) { | 1113 TEST_F(FileUtilTest, MoveExist) { |
| 1097 // Create a directory | 1114 // Create a directory |
| 1098 FilePath dir_name_from = | 1115 FilePath dir_name_from = |
| 1099 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_From_Subdir")); | 1116 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Move_From_Subdir")); |
| 1100 CreateDirectory(dir_name_from); | 1117 CreateDirectory(dir_name_from); |
| 1101 ASSERT_TRUE(PathExists(dir_name_from)); | 1118 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1102 | 1119 |
| 1103 // Create a file under the directory | 1120 // Create a file under the directory |
| 1104 FilePath file_name_from = | 1121 FilePath file_name_from = |
| 1105 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1122 dir_name_from.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| 1106 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1123 ASSERT_NO_FATAL_FAILURE( |
| 1124 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1107 ASSERT_TRUE(PathExists(file_name_from)); | 1125 ASSERT_TRUE(PathExists(file_name_from)); |
| 1108 | 1126 |
| 1109 // Move the directory | 1127 // Move the directory |
| 1110 FilePath dir_name_exists = | 1128 FilePath dir_name_exists = |
| 1111 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); | 1129 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); |
| 1112 | 1130 |
| 1113 FilePath dir_name_to = | 1131 FilePath dir_name_to = |
| 1114 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); | 1132 dir_name_exists.Append(FILE_PATH_LITERAL("Move_To_Subdir")); |
| 1115 FilePath file_name_to = | 1133 FilePath file_name_to = |
| 1116 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); | 1134 dir_name_to.Append(FILE_PATH_LITERAL("Move_Test_File.txt")); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1131 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { | 1149 TEST_F(FileUtilTest, CopyDirectoryRecursivelyNew) { |
| 1132 // Create a directory. | 1150 // Create a directory. |
| 1133 FilePath dir_name_from = | 1151 FilePath dir_name_from = |
| 1134 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1152 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1135 CreateDirectory(dir_name_from); | 1153 CreateDirectory(dir_name_from); |
| 1136 ASSERT_TRUE(PathExists(dir_name_from)); | 1154 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1137 | 1155 |
| 1138 // Create a file under the directory. | 1156 // Create a file under the directory. |
| 1139 FilePath file_name_from = | 1157 FilePath file_name_from = |
| 1140 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1158 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1141 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1159 ASSERT_NO_FATAL_FAILURE( |
| 1160 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1142 ASSERT_TRUE(PathExists(file_name_from)); | 1161 ASSERT_TRUE(PathExists(file_name_from)); |
| 1143 | 1162 |
| 1144 // Create a subdirectory. | 1163 // Create a subdirectory. |
| 1145 FilePath subdir_name_from = | 1164 FilePath subdir_name_from = |
| 1146 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1165 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1147 CreateDirectory(subdir_name_from); | 1166 CreateDirectory(subdir_name_from); |
| 1148 ASSERT_TRUE(PathExists(subdir_name_from)); | 1167 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1149 | 1168 |
| 1150 // Create a file under the subdirectory. | 1169 // Create a file under the subdirectory. |
| 1151 FilePath file_name2_from = | 1170 FilePath file_name2_from = |
| 1152 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1171 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1153 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1172 ASSERT_NO_FATAL_FAILURE( |
| 1173 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle")); |
| 1154 ASSERT_TRUE(PathExists(file_name2_from)); | 1174 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1155 | 1175 |
| 1156 // Copy the directory recursively. | 1176 // Copy the directory recursively. |
| 1157 FilePath dir_name_to = | 1177 FilePath dir_name_to = |
| 1158 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1178 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1159 FilePath file_name_to = | 1179 FilePath file_name_to = |
| 1160 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1180 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1161 FilePath subdir_name_to = | 1181 FilePath subdir_name_to = |
| 1162 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1182 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1163 FilePath file_name2_to = | 1183 FilePath file_name2_to = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1181 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { | 1201 TEST_F(FileUtilTest, CopyDirectoryRecursivelyExists) { |
| 1182 // Create a directory. | 1202 // Create a directory. |
| 1183 FilePath dir_name_from = | 1203 FilePath dir_name_from = |
| 1184 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1204 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1185 CreateDirectory(dir_name_from); | 1205 CreateDirectory(dir_name_from); |
| 1186 ASSERT_TRUE(PathExists(dir_name_from)); | 1206 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1187 | 1207 |
| 1188 // Create a file under the directory. | 1208 // Create a file under the directory. |
| 1189 FilePath file_name_from = | 1209 FilePath file_name_from = |
| 1190 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1210 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1191 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1211 ASSERT_NO_FATAL_FAILURE( |
| 1212 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1192 ASSERT_TRUE(PathExists(file_name_from)); | 1213 ASSERT_TRUE(PathExists(file_name_from)); |
| 1193 | 1214 |
| 1194 // Create a subdirectory. | 1215 // Create a subdirectory. |
| 1195 FilePath subdir_name_from = | 1216 FilePath subdir_name_from = |
| 1196 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1217 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1197 CreateDirectory(subdir_name_from); | 1218 CreateDirectory(subdir_name_from); |
| 1198 ASSERT_TRUE(PathExists(subdir_name_from)); | 1219 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1199 | 1220 |
| 1200 // Create a file under the subdirectory. | 1221 // Create a file under the subdirectory. |
| 1201 FilePath file_name2_from = | 1222 FilePath file_name2_from = |
| 1202 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1223 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1203 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1224 ASSERT_NO_FATAL_FAILURE( |
| 1225 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle")); |
| 1204 ASSERT_TRUE(PathExists(file_name2_from)); | 1226 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1205 | 1227 |
| 1206 // Copy the directory recursively. | 1228 // Copy the directory recursively. |
| 1207 FilePath dir_name_exists = | 1229 FilePath dir_name_exists = |
| 1208 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); | 1230 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); |
| 1209 | 1231 |
| 1210 FilePath dir_name_to = | 1232 FilePath dir_name_to = |
| 1211 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1233 dir_name_exists.Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1212 FilePath file_name_to = | 1234 FilePath file_name_to = |
| 1213 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1235 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1236 TEST_F(FileUtilTest, CopyDirectoryNew) { | 1258 TEST_F(FileUtilTest, CopyDirectoryNew) { |
| 1237 // Create a directory. | 1259 // Create a directory. |
| 1238 FilePath dir_name_from = | 1260 FilePath dir_name_from = |
| 1239 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1261 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1240 CreateDirectory(dir_name_from); | 1262 CreateDirectory(dir_name_from); |
| 1241 ASSERT_TRUE(PathExists(dir_name_from)); | 1263 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1242 | 1264 |
| 1243 // Create a file under the directory. | 1265 // Create a file under the directory. |
| 1244 FilePath file_name_from = | 1266 FilePath file_name_from = |
| 1245 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1267 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1246 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1268 ASSERT_NO_FATAL_FAILURE( |
| 1269 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1247 ASSERT_TRUE(PathExists(file_name_from)); | 1270 ASSERT_TRUE(PathExists(file_name_from)); |
| 1248 | 1271 |
| 1249 // Create a subdirectory. | 1272 // Create a subdirectory. |
| 1250 FilePath subdir_name_from = | 1273 FilePath subdir_name_from = |
| 1251 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1274 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1252 CreateDirectory(subdir_name_from); | 1275 CreateDirectory(subdir_name_from); |
| 1253 ASSERT_TRUE(PathExists(subdir_name_from)); | 1276 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1254 | 1277 |
| 1255 // Create a file under the subdirectory. | 1278 // Create a file under the subdirectory. |
| 1256 FilePath file_name2_from = | 1279 FilePath file_name2_from = |
| 1257 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1280 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1258 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1281 ASSERT_NO_FATAL_FAILURE( |
| 1282 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle")); |
| 1259 ASSERT_TRUE(PathExists(file_name2_from)); | 1283 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1260 | 1284 |
| 1261 // Copy the directory not recursively. | 1285 // Copy the directory not recursively. |
| 1262 FilePath dir_name_to = | 1286 FilePath dir_name_to = |
| 1263 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1287 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1264 FilePath file_name_to = | 1288 FilePath file_name_to = |
| 1265 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1289 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1266 FilePath subdir_name_to = | 1290 FilePath subdir_name_to = |
| 1267 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1291 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1268 | 1292 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1283 TEST_F(FileUtilTest, CopyDirectoryExists) { | 1307 TEST_F(FileUtilTest, CopyDirectoryExists) { |
| 1284 // Create a directory. | 1308 // Create a directory. |
| 1285 FilePath dir_name_from = | 1309 FilePath dir_name_from = |
| 1286 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1310 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1287 CreateDirectory(dir_name_from); | 1311 CreateDirectory(dir_name_from); |
| 1288 ASSERT_TRUE(PathExists(dir_name_from)); | 1312 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1289 | 1313 |
| 1290 // Create a file under the directory. | 1314 // Create a file under the directory. |
| 1291 FilePath file_name_from = | 1315 FilePath file_name_from = |
| 1292 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1316 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1293 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1317 ASSERT_NO_FATAL_FAILURE( |
| 1318 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1294 ASSERT_TRUE(PathExists(file_name_from)); | 1319 ASSERT_TRUE(PathExists(file_name_from)); |
| 1295 | 1320 |
| 1296 // Create a subdirectory. | 1321 // Create a subdirectory. |
| 1297 FilePath subdir_name_from = | 1322 FilePath subdir_name_from = |
| 1298 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); | 1323 dir_name_from.Append(FILE_PATH_LITERAL("Subdir")); |
| 1299 CreateDirectory(subdir_name_from); | 1324 CreateDirectory(subdir_name_from); |
| 1300 ASSERT_TRUE(PathExists(subdir_name_from)); | 1325 ASSERT_TRUE(PathExists(subdir_name_from)); |
| 1301 | 1326 |
| 1302 // Create a file under the subdirectory. | 1327 // Create a file under the subdirectory. |
| 1303 FilePath file_name2_from = | 1328 FilePath file_name2_from = |
| 1304 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1329 subdir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1305 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle"); | 1330 ASSERT_NO_FATAL_FAILURE( |
| 1331 CreateTextFile(file_name2_from, L"Gooooooooooooooooooooogle")); |
| 1306 ASSERT_TRUE(PathExists(file_name2_from)); | 1332 ASSERT_TRUE(PathExists(file_name2_from)); |
| 1307 | 1333 |
| 1308 // Copy the directory not recursively. | 1334 // Copy the directory not recursively. |
| 1309 FilePath dir_name_to = | 1335 FilePath dir_name_to = |
| 1310 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1336 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1311 FilePath file_name_to = | 1337 FilePath file_name_to = |
| 1312 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1338 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1313 FilePath subdir_name_to = | 1339 FilePath subdir_name_to = |
| 1314 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); | 1340 dir_name_to.Append(FILE_PATH_LITERAL("Subdir")); |
| 1315 | 1341 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1326 EXPECT_TRUE(PathExists(file_name2_from)); | 1352 EXPECT_TRUE(PathExists(file_name2_from)); |
| 1327 EXPECT_TRUE(PathExists(dir_name_to)); | 1353 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1328 EXPECT_TRUE(PathExists(file_name_to)); | 1354 EXPECT_TRUE(PathExists(file_name_to)); |
| 1329 EXPECT_FALSE(PathExists(subdir_name_to)); | 1355 EXPECT_FALSE(PathExists(subdir_name_to)); |
| 1330 } | 1356 } |
| 1331 | 1357 |
| 1332 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { | 1358 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToNew) { |
| 1333 // Create a file | 1359 // Create a file |
| 1334 FilePath file_name_from = | 1360 FilePath file_name_from = |
| 1335 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1361 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1336 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1362 ASSERT_NO_FATAL_FAILURE( |
| 1363 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1337 ASSERT_TRUE(PathExists(file_name_from)); | 1364 ASSERT_TRUE(PathExists(file_name_from)); |
| 1338 | 1365 |
| 1339 // The destination name | 1366 // The destination name |
| 1340 FilePath file_name_to = temp_dir_.GetPath().Append( | 1367 FilePath file_name_to = temp_dir_.GetPath().Append( |
| 1341 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); | 1368 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
| 1342 ASSERT_FALSE(PathExists(file_name_to)); | 1369 ASSERT_FALSE(PathExists(file_name_to)); |
| 1343 | 1370 |
| 1344 EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); | 1371 EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); |
| 1345 | 1372 |
| 1346 // Check the has been copied | 1373 // Check the has been copied |
| 1347 EXPECT_TRUE(PathExists(file_name_to)); | 1374 EXPECT_TRUE(PathExists(file_name_to)); |
| 1348 } | 1375 } |
| 1349 | 1376 |
| 1350 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { | 1377 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExisting) { |
| 1351 // Create a file | 1378 // Create a file |
| 1352 FilePath file_name_from = | 1379 FilePath file_name_from = |
| 1353 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1380 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1354 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1381 ASSERT_NO_FATAL_FAILURE( |
| 1382 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1355 ASSERT_TRUE(PathExists(file_name_from)); | 1383 ASSERT_TRUE(PathExists(file_name_from)); |
| 1356 | 1384 |
| 1357 // The destination name | 1385 // The destination name |
| 1358 FilePath file_name_to = temp_dir_.GetPath().Append( | 1386 FilePath file_name_to = temp_dir_.GetPath().Append( |
| 1359 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); | 1387 FILE_PATH_LITERAL("Copy_Test_File_Destination.txt")); |
| 1360 CreateTextFile(file_name_to, L"Old file content"); | 1388 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name_to, L"Old file content")); |
| 1361 ASSERT_TRUE(PathExists(file_name_to)); | 1389 ASSERT_TRUE(PathExists(file_name_to)); |
| 1362 | 1390 |
| 1363 EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); | 1391 EXPECT_TRUE(CopyDirectory(file_name_from, file_name_to, true)); |
| 1364 | 1392 |
| 1365 // Check the has been copied | 1393 // Check the has been copied |
| 1366 EXPECT_TRUE(PathExists(file_name_to)); | 1394 EXPECT_TRUE(PathExists(file_name_to)); |
| 1367 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); | 1395 EXPECT_TRUE(L"Gooooooooooooooooooooogle" == ReadTextFile(file_name_to)); |
| 1368 } | 1396 } |
| 1369 | 1397 |
| 1370 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { | 1398 TEST_F(FileUtilTest, CopyFileWithCopyDirectoryRecursiveToExistingDirectory) { |
| 1371 // Create a file | 1399 // Create a file |
| 1372 FilePath file_name_from = | 1400 FilePath file_name_from = |
| 1373 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1401 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1374 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1402 ASSERT_NO_FATAL_FAILURE( |
| 1403 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1375 ASSERT_TRUE(PathExists(file_name_from)); | 1404 ASSERT_TRUE(PathExists(file_name_from)); |
| 1376 | 1405 |
| 1377 // The destination | 1406 // The destination |
| 1378 FilePath dir_name_to = | 1407 FilePath dir_name_to = |
| 1379 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); | 1408 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Destination")); |
| 1380 CreateDirectory(dir_name_to); | 1409 CreateDirectory(dir_name_to); |
| 1381 ASSERT_TRUE(PathExists(dir_name_to)); | 1410 ASSERT_TRUE(PathExists(dir_name_to)); |
| 1382 FilePath file_name_to = | 1411 FilePath file_name_to = |
| 1383 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1412 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1384 | 1413 |
| 1385 EXPECT_TRUE(CopyDirectory(file_name_from, dir_name_to, true)); | 1414 EXPECT_TRUE(CopyDirectory(file_name_from, dir_name_to, true)); |
| 1386 | 1415 |
| 1387 // Check the has been copied | 1416 // Check the has been copied |
| 1388 EXPECT_TRUE(PathExists(file_name_to)); | 1417 EXPECT_TRUE(PathExists(file_name_to)); |
| 1389 } | 1418 } |
| 1390 | 1419 |
| 1391 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { | 1420 TEST_F(FileUtilTest, CopyDirectoryWithTrailingSeparators) { |
| 1392 // Create a directory. | 1421 // Create a directory. |
| 1393 FilePath dir_name_from = | 1422 FilePath dir_name_from = |
| 1394 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1423 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1395 CreateDirectory(dir_name_from); | 1424 CreateDirectory(dir_name_from); |
| 1396 ASSERT_TRUE(PathExists(dir_name_from)); | 1425 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1397 | 1426 |
| 1398 // Create a file under the directory. | 1427 // Create a file under the directory. |
| 1399 FilePath file_name_from = | 1428 FilePath file_name_from = |
| 1400 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1429 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1401 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1430 ASSERT_NO_FATAL_FAILURE( |
| 1431 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1402 ASSERT_TRUE(PathExists(file_name_from)); | 1432 ASSERT_TRUE(PathExists(file_name_from)); |
| 1403 | 1433 |
| 1404 // Copy the directory recursively. | 1434 // Copy the directory recursively. |
| 1405 FilePath dir_name_to = | 1435 FilePath dir_name_to = |
| 1406 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); | 1436 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_To_Subdir")); |
| 1407 FilePath file_name_to = | 1437 FilePath file_name_to = |
| 1408 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1438 dir_name_to.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1409 | 1439 |
| 1410 // Create from path with trailing separators. | 1440 // Create from path with trailing separators. |
| 1411 #if defined(OS_WIN) | 1441 #if defined(OS_WIN) |
| 1412 FilePath from_path = | 1442 FilePath from_path = |
| 1413 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); | 1443 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir\\\\\\")); |
| 1414 #elif defined(OS_POSIX) | 1444 #elif defined(OS_POSIX) |
| 1415 FilePath from_path = | 1445 FilePath from_path = |
| 1416 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); | 1446 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir///")); |
| 1417 #endif | 1447 #endif |
| 1418 | 1448 |
| 1419 EXPECT_TRUE(CopyDirectory(from_path, dir_name_to, true)); | 1449 EXPECT_TRUE(CopyDirectory(from_path, dir_name_to, true)); |
| 1420 | 1450 |
| 1421 // Check everything has been copied. | 1451 // Check everything has been copied. |
| 1422 EXPECT_TRUE(PathExists(dir_name_from)); | 1452 EXPECT_TRUE(PathExists(dir_name_from)); |
| 1423 EXPECT_TRUE(PathExists(file_name_from)); | 1453 EXPECT_TRUE(PathExists(file_name_from)); |
| 1424 EXPECT_TRUE(PathExists(dir_name_to)); | 1454 EXPECT_TRUE(PathExists(dir_name_to)); |
| 1425 EXPECT_TRUE(PathExists(file_name_to)); | 1455 EXPECT_TRUE(PathExists(file_name_to)); |
| 1426 } | 1456 } |
| 1427 | 1457 |
| 1428 // Sets the source file to read-only. | |
| 1429 void SetReadOnly(const FilePath& path, bool read_only) { | |
| 1430 #if defined(OS_WIN) | |
| 1431 // On Windows, it involves setting/removing the 'readonly' bit. | |
| 1432 DWORD attrs = GetFileAttributes(path.value().c_str()); | |
| 1433 ASSERT_NE(INVALID_FILE_ATTRIBUTES, attrs); | |
| 1434 ASSERT_TRUE(SetFileAttributes( | |
| 1435 path.value().c_str(), | |
| 1436 read_only ? (attrs | FILE_ATTRIBUTE_READONLY) : | |
| 1437 (attrs & ~FILE_ATTRIBUTE_READONLY))); | |
| 1438 | |
| 1439 DWORD expected = read_only ? | |
| 1440 ((attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)) | | |
| 1441 FILE_ATTRIBUTE_READONLY) : | |
| 1442 (attrs & (FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_DIRECTORY)); | |
| 1443 | |
| 1444 // Ignore FILE_ATTRIBUTE_NOT_CONTENT_INDEXED if present. | |
| 1445 attrs = GetFileAttributes(path.value().c_str()) & | |
| 1446 ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED; | |
| 1447 ASSERT_EQ(expected, attrs); | |
| 1448 #else | |
| 1449 // On all other platforms, it involves removing/setting the write bit. | |
| 1450 mode_t mode = read_only ? S_IRUSR : (S_IRUSR | S_IWUSR); | |
| 1451 EXPECT_TRUE(SetPosixFilePermissions( | |
| 1452 path, DirectoryExists(path) ? (mode | S_IXUSR) : mode)); | |
| 1453 #endif | |
| 1454 } | |
| 1455 | |
| 1456 bool IsReadOnly(const FilePath& path) { | |
| 1457 #if defined(OS_WIN) | |
| 1458 DWORD attrs = GetFileAttributes(path.value().c_str()); | |
| 1459 EXPECT_NE(INVALID_FILE_ATTRIBUTES, attrs); | |
| 1460 return attrs & FILE_ATTRIBUTE_READONLY; | |
| 1461 #else | |
| 1462 int mode = 0; | |
| 1463 EXPECT_TRUE(GetPosixFilePermissions(path, &mode)); | |
| 1464 return !(mode & S_IWUSR); | |
| 1465 #endif | |
| 1466 } | |
| 1467 | |
| 1468 TEST_F(FileUtilTest, CopyDirectoryACL) { | 1458 TEST_F(FileUtilTest, CopyDirectoryACL) { |
| 1469 // Create source directories. | 1459 // Create source directories. |
| 1470 FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src")); | 1460 FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src")); |
| 1471 FilePath src_subdir = src.Append(FILE_PATH_LITERAL("subdir")); | 1461 FilePath src_subdir = src.Append(FILE_PATH_LITERAL("subdir")); |
| 1472 CreateDirectory(src_subdir); | 1462 CreateDirectory(src_subdir); |
| 1473 ASSERT_TRUE(PathExists(src_subdir)); | 1463 ASSERT_TRUE(PathExists(src_subdir)); |
| 1474 | 1464 |
| 1475 // Create a file under the directory. | 1465 // Create a file under the directory. |
| 1476 FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt")); | 1466 FilePath src_file = src.Append(FILE_PATH_LITERAL("src.txt")); |
| 1477 CreateTextFile(src_file, L"Gooooooooooooooooooooogle"); | 1467 ASSERT_NO_FATAL_FAILURE( |
| 1478 SetReadOnly(src_file, true); | 1468 CreateTextFile(src_file, L"Gooooooooooooooooooooogle")); |
| 1469 ASSERT_NO_FATAL_FAILURE(SetReadOnly(src_file, true)); |
| 1479 ASSERT_TRUE(IsReadOnly(src_file)); | 1470 ASSERT_TRUE(IsReadOnly(src_file)); |
| 1480 | 1471 |
| 1481 // Make directory read-only. | 1472 // Make directory read-only. |
| 1482 SetReadOnly(src_subdir, true); | 1473 ASSERT_NO_FATAL_FAILURE(SetReadOnly(src_subdir, true)); |
| 1483 ASSERT_TRUE(IsReadOnly(src_subdir)); | 1474 ASSERT_TRUE(IsReadOnly(src_subdir)); |
| 1484 | 1475 |
| 1485 // Copy the directory recursively. | 1476 // Copy the directory recursively. |
| 1486 FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst")); | 1477 FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst")); |
| 1487 FilePath dst_file = dst.Append(FILE_PATH_LITERAL("src.txt")); | 1478 FilePath dst_file = dst.Append(FILE_PATH_LITERAL("src.txt")); |
| 1488 EXPECT_TRUE(CopyDirectory(src, dst, true)); | 1479 EXPECT_TRUE(CopyDirectory(src, dst, true)); |
| 1489 | 1480 |
| 1490 FilePath dst_subdir = dst.Append(FILE_PATH_LITERAL("subdir")); | 1481 FilePath dst_subdir = dst.Append(FILE_PATH_LITERAL("subdir")); |
| 1491 ASSERT_FALSE(IsReadOnly(dst_subdir)); | 1482 ASSERT_FALSE(IsReadOnly(dst_subdir)); |
| 1492 ASSERT_FALSE(IsReadOnly(dst_file)); | 1483 ASSERT_FALSE(IsReadOnly(dst_file)); |
| 1493 | 1484 |
| 1494 // Give write permissions to allow deletion. | 1485 // Give write permissions to allow deletion. |
| 1495 SetReadOnly(src_subdir, false); | 1486 ASSERT_NO_FATAL_FAILURE(SetReadOnly(src_subdir, false)); |
| 1496 ASSERT_FALSE(IsReadOnly(src_subdir)); | 1487 ASSERT_FALSE(IsReadOnly(src_subdir)); |
| 1497 } | 1488 } |
| 1498 | 1489 |
| 1499 TEST_F(FileUtilTest, CopyFile) { | 1490 TEST_F(FileUtilTest, CopyFile) { |
| 1500 // Create a directory | 1491 // Create a directory |
| 1501 FilePath dir_name_from = | 1492 FilePath dir_name_from = |
| 1502 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); | 1493 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("Copy_From_Subdir")); |
| 1503 CreateDirectory(dir_name_from); | 1494 CreateDirectory(dir_name_from); |
| 1504 ASSERT_TRUE(PathExists(dir_name_from)); | 1495 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1505 | 1496 |
| 1506 // Create a file under the directory | 1497 // Create a file under the directory |
| 1507 FilePath file_name_from = | 1498 FilePath file_name_from = |
| 1508 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); | 1499 dir_name_from.Append(FILE_PATH_LITERAL("Copy_Test_File.txt")); |
| 1509 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 1500 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
| 1510 CreateTextFile(file_name_from, file_contents); | 1501 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file_name_from, file_contents)); |
| 1511 ASSERT_TRUE(PathExists(file_name_from)); | 1502 ASSERT_TRUE(PathExists(file_name_from)); |
| 1512 | 1503 |
| 1513 // Copy the file. | 1504 // Copy the file. |
| 1514 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt")); | 1505 FilePath dest_file = dir_name_from.Append(FILE_PATH_LITERAL("DestFile.txt")); |
| 1515 ASSERT_TRUE(CopyFile(file_name_from, dest_file)); | 1506 ASSERT_TRUE(CopyFile(file_name_from, dest_file)); |
| 1516 | 1507 |
| 1517 // Try to copy the file to another location using '..' in the path. | 1508 // Try to copy the file to another location using '..' in the path. |
| 1518 FilePath dest_file2(dir_name_from); | 1509 FilePath dest_file2(dir_name_from); |
| 1519 dest_file2 = dest_file2.AppendASCII(".."); | 1510 dest_file2 = dest_file2.AppendASCII(".."); |
| 1520 dest_file2 = dest_file2.AppendASCII("DestFile.txt"); | 1511 dest_file2 = dest_file2.AppendASCII("DestFile.txt"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1532 EXPECT_FALSE(PathExists(dest_file2_test)); | 1523 EXPECT_FALSE(PathExists(dest_file2_test)); |
| 1533 EXPECT_FALSE(PathExists(dest_file2)); | 1524 EXPECT_FALSE(PathExists(dest_file2)); |
| 1534 } | 1525 } |
| 1535 | 1526 |
| 1536 TEST_F(FileUtilTest, CopyFileACL) { | 1527 TEST_F(FileUtilTest, CopyFileACL) { |
| 1537 // While FileUtilTest.CopyFile asserts the content is correctly copied over, | 1528 // While FileUtilTest.CopyFile asserts the content is correctly copied over, |
| 1538 // this test case asserts the access control bits are meeting expectations in | 1529 // this test case asserts the access control bits are meeting expectations in |
| 1539 // CopyFile(). | 1530 // CopyFile(). |
| 1540 FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src.txt")); | 1531 FilePath src = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("src.txt")); |
| 1541 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); | 1532 const std::wstring file_contents(L"Gooooooooooooooooooooogle"); |
| 1542 CreateTextFile(src, file_contents); | 1533 ASSERT_NO_FATAL_FAILURE(CreateTextFile(src, file_contents)); |
| 1543 | 1534 |
| 1544 // Set the source file to read-only. | 1535 // Set the source file to read-only. |
| 1545 ASSERT_FALSE(IsReadOnly(src)); | 1536 ASSERT_FALSE(IsReadOnly(src)); |
| 1546 SetReadOnly(src, true); | 1537 ASSERT_NO_FATAL_FAILURE(SetReadOnly(src, true)); |
| 1547 ASSERT_TRUE(IsReadOnly(src)); | 1538 ASSERT_TRUE(IsReadOnly(src)); |
| 1548 | 1539 |
| 1549 // Copy the file. | 1540 // Copy the file. |
| 1550 FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst.txt")); | 1541 FilePath dst = temp_dir_.GetPath().Append(FILE_PATH_LITERAL("dst.txt")); |
| 1551 ASSERT_TRUE(CopyFile(src, dst)); | 1542 ASSERT_TRUE(CopyFile(src, dst)); |
| 1552 EXPECT_EQ(file_contents, ReadTextFile(dst)); | 1543 EXPECT_EQ(file_contents, ReadTextFile(dst)); |
| 1553 | 1544 |
| 1554 ASSERT_FALSE(IsReadOnly(dst)); | 1545 ASSERT_FALSE(IsReadOnly(dst)); |
| 1555 } | 1546 } |
| 1556 | 1547 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1654 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { | 1645 TEST_F(FileUtilTest, CopyAndDeleteDirectoryTest) { |
| 1655 // Create a directory | 1646 // Create a directory |
| 1656 FilePath dir_name_from = temp_dir_.GetPath().Append( | 1647 FilePath dir_name_from = temp_dir_.GetPath().Append( |
| 1657 FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); | 1648 FILE_PATH_LITERAL("CopyAndDelete_From_Subdir")); |
| 1658 CreateDirectory(dir_name_from); | 1649 CreateDirectory(dir_name_from); |
| 1659 ASSERT_TRUE(PathExists(dir_name_from)); | 1650 ASSERT_TRUE(PathExists(dir_name_from)); |
| 1660 | 1651 |
| 1661 // Create a file under the directory | 1652 // Create a file under the directory |
| 1662 FilePath file_name_from = | 1653 FilePath file_name_from = |
| 1663 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1654 dir_name_from.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
| 1664 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle"); | 1655 ASSERT_NO_FATAL_FAILURE( |
| 1656 CreateTextFile(file_name_from, L"Gooooooooooooooooooooogle")); |
| 1665 ASSERT_TRUE(PathExists(file_name_from)); | 1657 ASSERT_TRUE(PathExists(file_name_from)); |
| 1666 | 1658 |
| 1667 // Move the directory by using CopyAndDeleteDirectory | 1659 // Move the directory by using CopyAndDeleteDirectory |
| 1668 FilePath dir_name_to = | 1660 FilePath dir_name_to = |
| 1669 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("CopyAndDelete_To_Subdir")); | 1661 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("CopyAndDelete_To_Subdir")); |
| 1670 FilePath file_name_to = | 1662 FilePath file_name_to = |
| 1671 dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); | 1663 dir_name_to.Append(FILE_PATH_LITERAL("CopyAndDelete_Test_File.txt")); |
| 1672 | 1664 |
| 1673 ASSERT_FALSE(PathExists(dir_name_to)); | 1665 ASSERT_FALSE(PathExists(dir_name_to)); |
| 1674 | 1666 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1812 | 1804 |
| 1813 EXPECT_FALSE(PathExists(test_path)); | 1805 EXPECT_FALSE(PathExists(test_path)); |
| 1814 EXPECT_TRUE(CreateDirectory(test_path)); | 1806 EXPECT_TRUE(CreateDirectory(test_path)); |
| 1815 EXPECT_TRUE(PathExists(test_path)); | 1807 EXPECT_TRUE(PathExists(test_path)); |
| 1816 // CreateDirectory returns true if the DirectoryExists returns true. | 1808 // CreateDirectory returns true if the DirectoryExists returns true. |
| 1817 EXPECT_TRUE(CreateDirectory(test_path)); | 1809 EXPECT_TRUE(CreateDirectory(test_path)); |
| 1818 | 1810 |
| 1819 // Doesn't work to create it on top of a non-dir | 1811 // Doesn't work to create it on top of a non-dir |
| 1820 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); | 1812 test_path = test_path.Append(FILE_PATH_LITERAL("foobar.txt")); |
| 1821 EXPECT_FALSE(PathExists(test_path)); | 1813 EXPECT_FALSE(PathExists(test_path)); |
| 1822 CreateTextFile(test_path, L"test file"); | 1814 ASSERT_NO_FATAL_FAILURE(CreateTextFile(test_path, L"test file")); |
| 1823 EXPECT_TRUE(PathExists(test_path)); | 1815 EXPECT_TRUE(PathExists(test_path)); |
| 1824 EXPECT_FALSE(CreateDirectory(test_path)); | 1816 EXPECT_FALSE(CreateDirectory(test_path)); |
| 1825 | 1817 |
| 1826 EXPECT_TRUE(DeleteFile(test_root, true)); | 1818 EXPECT_TRUE(DeleteFile(test_root, true)); |
| 1827 EXPECT_FALSE(PathExists(test_root)); | 1819 EXPECT_FALSE(PathExists(test_root)); |
| 1828 EXPECT_FALSE(PathExists(test_path)); | 1820 EXPECT_FALSE(PathExists(test_path)); |
| 1829 | 1821 |
| 1830 // Verify assumptions made by the Windows implementation: | 1822 // Verify assumptions made by the Windows implementation: |
| 1831 // 1. The current directory always exists. | 1823 // 1. The current directory always exists. |
| 1832 // 2. The root directory always exists. | 1824 // 2. The root directory always exists. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1858 FilePath test_root = | 1850 FilePath test_root = |
| 1859 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("detect_directory_test")); | 1851 temp_dir_.GetPath().Append(FILE_PATH_LITERAL("detect_directory_test")); |
| 1860 EXPECT_FALSE(PathExists(test_root)); | 1852 EXPECT_FALSE(PathExists(test_root)); |
| 1861 EXPECT_TRUE(CreateDirectory(test_root)); | 1853 EXPECT_TRUE(CreateDirectory(test_root)); |
| 1862 EXPECT_TRUE(PathExists(test_root)); | 1854 EXPECT_TRUE(PathExists(test_root)); |
| 1863 EXPECT_TRUE(DirectoryExists(test_root)); | 1855 EXPECT_TRUE(DirectoryExists(test_root)); |
| 1864 // Check a file | 1856 // Check a file |
| 1865 FilePath test_path = | 1857 FilePath test_path = |
| 1866 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); | 1858 test_root.Append(FILE_PATH_LITERAL("foobar.txt")); |
| 1867 EXPECT_FALSE(PathExists(test_path)); | 1859 EXPECT_FALSE(PathExists(test_path)); |
| 1868 CreateTextFile(test_path, L"test file"); | 1860 ASSERT_NO_FATAL_FAILURE(CreateTextFile(test_path, L"test file")); |
| 1869 EXPECT_TRUE(PathExists(test_path)); | 1861 EXPECT_TRUE(PathExists(test_path)); |
| 1870 EXPECT_FALSE(DirectoryExists(test_path)); | 1862 EXPECT_FALSE(DirectoryExists(test_path)); |
| 1871 EXPECT_TRUE(DeleteFile(test_path, false)); | 1863 EXPECT_TRUE(DeleteFile(test_path, false)); |
| 1872 | 1864 |
| 1873 EXPECT_TRUE(DeleteFile(test_root, true)); | 1865 EXPECT_TRUE(DeleteFile(test_root, true)); |
| 1874 } | 1866 } |
| 1875 | 1867 |
| 1876 TEST_F(FileUtilTest, FileEnumeratorTest) { | 1868 TEST_F(FileUtilTest, FileEnumeratorTest) { |
| 1877 // Test an empty directory. | 1869 // Test an empty directory. |
| 1878 FileEnumerator f0(temp_dir_.GetPath(), true, FILES_AND_DIRECTORIES); | 1870 FileEnumerator f0(temp_dir_.GetPath(), true, FILES_AND_DIRECTORIES); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1890 // create the directories | 1882 // create the directories |
| 1891 FilePath dir1 = temp_dir_.GetPath().Append(FPL("dir1")); | 1883 FilePath dir1 = temp_dir_.GetPath().Append(FPL("dir1")); |
| 1892 EXPECT_TRUE(CreateDirectory(dir1)); | 1884 EXPECT_TRUE(CreateDirectory(dir1)); |
| 1893 FilePath dir2 = temp_dir_.GetPath().Append(FPL("dir2")); | 1885 FilePath dir2 = temp_dir_.GetPath().Append(FPL("dir2")); |
| 1894 EXPECT_TRUE(CreateDirectory(dir2)); | 1886 EXPECT_TRUE(CreateDirectory(dir2)); |
| 1895 FilePath dir2inner = dir2.Append(FPL("inner")); | 1887 FilePath dir2inner = dir2.Append(FPL("inner")); |
| 1896 EXPECT_TRUE(CreateDirectory(dir2inner)); | 1888 EXPECT_TRUE(CreateDirectory(dir2inner)); |
| 1897 | 1889 |
| 1898 // create the files | 1890 // create the files |
| 1899 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); | 1891 FilePath dir2file = dir2.Append(FPL("dir2file.txt")); |
| 1900 CreateTextFile(dir2file, std::wstring()); | 1892 ASSERT_NO_FATAL_FAILURE(CreateTextFile(dir2file, std::wstring())); |
| 1901 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); | 1893 FilePath dir2innerfile = dir2inner.Append(FPL("innerfile.txt")); |
| 1902 CreateTextFile(dir2innerfile, std::wstring()); | 1894 ASSERT_NO_FATAL_FAILURE(CreateTextFile(dir2innerfile, std::wstring())); |
| 1903 FilePath file1 = temp_dir_.GetPath().Append(FPL("file1.txt")); | 1895 FilePath file1 = temp_dir_.GetPath().Append(FPL("file1.txt")); |
| 1904 CreateTextFile(file1, std::wstring()); | 1896 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file1, std::wstring())); |
| 1905 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) | 1897 FilePath file2_rel = dir2.Append(FilePath::kParentDirectory) |
| 1906 .Append(FPL("file2.txt")); | 1898 .Append(FPL("file2.txt")); |
| 1907 CreateTextFile(file2_rel, std::wstring()); | 1899 ASSERT_NO_FATAL_FAILURE(CreateTextFile(file2_rel, std::wstring())); |
| 1908 FilePath file2_abs = temp_dir_.GetPath().Append(FPL("file2.txt")); | 1900 FilePath file2_abs = temp_dir_.GetPath().Append(FPL("file2.txt")); |
| 1909 | 1901 |
| 1910 // Only enumerate files. | 1902 // Only enumerate files. |
| 1911 FileEnumerator f1(temp_dir_.GetPath(), true, FileEnumerator::FILES); | 1903 FileEnumerator f1(temp_dir_.GetPath(), true, FileEnumerator::FILES); |
| 1912 FindResultCollector c1(&f1); | 1904 FindResultCollector c1(&f1); |
| 1913 EXPECT_TRUE(c1.HasFile(file1)); | 1905 EXPECT_TRUE(c1.HasFile(file1)); |
| 1914 EXPECT_TRUE(c1.HasFile(file2_abs)); | 1906 EXPECT_TRUE(c1.HasFile(file2_abs)); |
| 1915 EXPECT_TRUE(c1.HasFile(dir2file)); | 1907 EXPECT_TRUE(c1.HasFile(dir2file)); |
| 1916 EXPECT_TRUE(c1.HasFile(dir2innerfile)); | 1908 EXPECT_TRUE(c1.HasFile(dir2innerfile)); |
| 1917 EXPECT_EQ(4, c1.size()); | 1909 EXPECT_EQ(4, c1.size()); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2224 // |-> sub_dir_ | 2216 // |-> sub_dir_ |
| 2225 // |-> text_file_ | 2217 // |-> text_file_ |
| 2226 | 2218 |
| 2227 base_dir_ = temp_dir_.GetPath().AppendASCII("base_dir"); | 2219 base_dir_ = temp_dir_.GetPath().AppendASCII("base_dir"); |
| 2228 ASSERT_TRUE(CreateDirectory(base_dir_)); | 2220 ASSERT_TRUE(CreateDirectory(base_dir_)); |
| 2229 | 2221 |
| 2230 sub_dir_ = base_dir_.AppendASCII("sub_dir"); | 2222 sub_dir_ = base_dir_.AppendASCII("sub_dir"); |
| 2231 ASSERT_TRUE(CreateDirectory(sub_dir_)); | 2223 ASSERT_TRUE(CreateDirectory(sub_dir_)); |
| 2232 | 2224 |
| 2233 text_file_ = sub_dir_.AppendASCII("file.txt"); | 2225 text_file_ = sub_dir_.AppendASCII("file.txt"); |
| 2234 CreateTextFile(text_file_, L"This text file has some text in it."); | 2226 ASSERT_NO_FATAL_FAILURE( |
| 2227 CreateTextFile(text_file_, L"This text file has some text in it.")); |
| 2235 | 2228 |
| 2236 // Get the user and group files are created with from |base_dir_|. | 2229 // Get the user and group files are created with from |base_dir_|. |
| 2237 struct stat stat_buf; | 2230 struct stat stat_buf; |
| 2238 ASSERT_EQ(0, stat(base_dir_.value().c_str(), &stat_buf)); | 2231 ASSERT_EQ(0, stat(base_dir_.value().c_str(), &stat_buf)); |
| 2239 uid_ = stat_buf.st_uid; | 2232 uid_ = stat_buf.st_uid; |
| 2240 ok_gids_.insert(stat_buf.st_gid); | 2233 ok_gids_.insert(stat_buf.st_gid); |
| 2241 bad_gids_.insert(stat_buf.st_gid + 1); | 2234 bad_gids_.insert(stat_buf.st_gid + 1); |
| 2242 | 2235 |
| 2243 ASSERT_EQ(uid_, getuid()); // This process should be the owner. | 2236 ASSERT_EQ(uid_, getuid()); // This process should be the owner. |
| 2244 | 2237 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2568 // Trying to close it should crash. This is important for security. | 2561 // Trying to close it should crash. This is important for security. |
| 2569 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2562 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
| 2570 #endif | 2563 #endif |
| 2571 } | 2564 } |
| 2572 | 2565 |
| 2573 #endif // defined(OS_POSIX) | 2566 #endif // defined(OS_POSIX) |
| 2574 | 2567 |
| 2575 } // namespace | 2568 } // namespace |
| 2576 | 2569 |
| 2577 } // namespace base | 2570 } // namespace base |
| OLD | NEW |