OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "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 <winioctl.h> | 9 #include <winioctl.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
11 #include <shlobj.h> | 11 #include <shlobj.h> |
12 #include <tchar.h> | 12 #include <tchar.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include <fstream> | 15 #include <fstream> |
16 #include <set> | 16 #include <set> |
17 | 17 |
18 #include "base/base_paths.h" | 18 #include "base/base_paths.h" |
19 #include "base/file_path.h" | 19 #include "base/file_path.h" |
20 #include "base/file_util.h" | 20 #include "base/file_util.h" |
21 #include "base/path_service.h" | 21 #include "base/path_service.h" |
22 #include "base/scoped_handle.h" | |
23 #include "base/scoped_temp_dir.h" | 22 #include "base/scoped_temp_dir.h" |
24 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
25 #include "base/time.h" | 24 #include "base/time.h" |
26 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
28 #include "testing/platform_test.h" | 27 #include "testing/platform_test.h" |
29 | 28 |
| 29 #if defined(OS_WIN) |
| 30 #include "base/win/scoped_handle.h" |
| 31 #endif |
| 32 |
30 // This macro helps avoid wrapped lines in the test structs. | 33 // This macro helps avoid wrapped lines in the test structs. |
31 #define FPL(x) FILE_PATH_LITERAL(x) | 34 #define FPL(x) FILE_PATH_LITERAL(x) |
32 | 35 |
33 namespace { | 36 namespace { |
34 | 37 |
35 // To test that file_util::Normalize FilePath() deals with NTFS reparse points | 38 // To test that file_util::Normalize FilePath() deals with NTFS reparse points |
36 // correctly, we need functions to create and delete reparse points. | 39 // correctly, we need functions to create and delete reparse points. |
37 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
38 typedef struct _REPARSE_DATA_BUFFER { | 41 typedef struct _REPARSE_DATA_BUFFER { |
39 ULONG ReparseTag; | 42 ULONG ReparseTag; |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 467 |
465 FilePath sub_long = deep_file.DirName(); | 468 FilePath sub_long = deep_file.DirName(); |
466 ASSERT_TRUE(file_util::CreateDirectory(sub_long)); | 469 ASSERT_TRUE(file_util::CreateDirectory(sub_long)); |
467 CreateTextFile(deep_file, bogus_content); | 470 CreateTextFile(deep_file, bogus_content); |
468 | 471 |
469 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); | 472 FilePath base_b = temp_dir_.path().Append(FPL("base_b")); |
470 ASSERT_TRUE(file_util::CreateDirectory(base_b)); | 473 ASSERT_TRUE(file_util::CreateDirectory(base_b)); |
471 | 474 |
472 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); | 475 FilePath to_sub_a = base_b.Append(FPL("to_sub_a")); |
473 ASSERT_TRUE(file_util::CreateDirectory(to_sub_a)); | 476 ASSERT_TRUE(file_util::CreateDirectory(to_sub_a)); |
474 ScopedHandle reparse_to_sub_a( | 477 base::win::ScopedHandle reparse_to_sub_a( |
475 ::CreateFile(to_sub_a.value().c_str(), | 478 ::CreateFile(to_sub_a.value().c_str(), |
476 FILE_ALL_ACCESS, | 479 FILE_ALL_ACCESS, |
477 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 480 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
478 NULL, | 481 NULL, |
479 OPEN_EXISTING, | 482 OPEN_EXISTING, |
480 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 483 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
481 NULL)); | 484 NULL)); |
482 ASSERT_TRUE(reparse_to_sub_a.IsValid()); | 485 ASSERT_TRUE(reparse_to_sub_a.IsValid()); |
483 ASSERT_TRUE(SetReparsePoint(reparse_to_sub_a, sub_a)); | 486 ASSERT_TRUE(SetReparsePoint(reparse_to_sub_a, sub_a)); |
484 | 487 |
485 FilePath to_base_b = base_b.Append(FPL("to_base_b")); | 488 FilePath to_base_b = base_b.Append(FPL("to_base_b")); |
486 ASSERT_TRUE(file_util::CreateDirectory(to_base_b)); | 489 ASSERT_TRUE(file_util::CreateDirectory(to_base_b)); |
487 ScopedHandle reparse_to_base_b( | 490 base::win::ScopedHandle reparse_to_base_b( |
488 ::CreateFile(to_base_b.value().c_str(), | 491 ::CreateFile(to_base_b.value().c_str(), |
489 FILE_ALL_ACCESS, | 492 FILE_ALL_ACCESS, |
490 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 493 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
491 NULL, | 494 NULL, |
492 OPEN_EXISTING, | 495 OPEN_EXISTING, |
493 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 496 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
494 NULL)); | 497 NULL)); |
495 ASSERT_TRUE(reparse_to_base_b.IsValid()); | 498 ASSERT_TRUE(reparse_to_base_b.IsValid()); |
496 ASSERT_TRUE(SetReparsePoint(reparse_to_base_b, base_b)); | 499 ASSERT_TRUE(SetReparsePoint(reparse_to_base_b, base_b)); |
497 | 500 |
498 FilePath to_sub_long = base_b.Append(FPL("to_sub_long")); | 501 FilePath to_sub_long = base_b.Append(FPL("to_sub_long")); |
499 ASSERT_TRUE(file_util::CreateDirectory(to_sub_long)); | 502 ASSERT_TRUE(file_util::CreateDirectory(to_sub_long)); |
500 ScopedHandle reparse_to_sub_long( | 503 base::win::ScopedHandle reparse_to_sub_long( |
501 ::CreateFile(to_sub_long.value().c_str(), | 504 ::CreateFile(to_sub_long.value().c_str(), |
502 FILE_ALL_ACCESS, | 505 FILE_ALL_ACCESS, |
503 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 506 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
504 NULL, | 507 NULL, |
505 OPEN_EXISTING, | 508 OPEN_EXISTING, |
506 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. | 509 FILE_FLAG_BACKUP_SEMANTICS, // Needed to open a directory. |
507 NULL)); | 510 NULL)); |
508 ASSERT_TRUE(reparse_to_sub_long.IsValid()); | 511 ASSERT_TRUE(reparse_to_sub_long.IsValid()); |
509 ASSERT_TRUE(SetReparsePoint(reparse_to_sub_long, sub_long)); | 512 ASSERT_TRUE(SetReparsePoint(reparse_to_sub_long, sub_long)); |
510 | 513 |
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); | 1807 EXPECT_TRUE(file_util::IsDirectoryEmpty(empty_dir)); |
1805 | 1808 |
1806 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); | 1809 FilePath foo(empty_dir.Append(FILE_PATH_LITERAL("foo.txt"))); |
1807 std::string bar("baz"); | 1810 std::string bar("baz"); |
1808 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); | 1811 ASSERT_TRUE(file_util::WriteFile(foo, bar.c_str(), bar.length())); |
1809 | 1812 |
1810 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); | 1813 EXPECT_FALSE(file_util::IsDirectoryEmpty(empty_dir)); |
1811 } | 1814 } |
1812 | 1815 |
1813 } // namespace | 1816 } // namespace |
OLD | NEW |