| 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 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 521 |
| 522 // Create a subdirectory of |long_test_dir| and make |long_test_dir| | 522 // Create a subdirectory of |long_test_dir| and make |long_test_dir| |
| 523 // unreadable. We should still be able to create a temp file in the | 523 // unreadable. We should still be able to create a temp file in the |
| 524 // subdirectory, but we won't be able to determine the long path for it. This | 524 // subdirectory, but we won't be able to determine the long path for it. This |
| 525 // mimics the environment that some users run where their user profiles reside | 525 // mimics the environment that some users run where their user profiles reside |
| 526 // in a location where the don't have full access to the higher level | 526 // in a location where the don't have full access to the higher level |
| 527 // directories. (Note that this assumption is true for NTFS, but not for some | 527 // directories. (Note that this assumption is true for NTFS, but not for some |
| 528 // network file systems. E.g. AFS). | 528 // network file systems. E.g. AFS). |
| 529 FilePath access_test_dir = long_test_dir.Append(kTestSubDirName); | 529 FilePath access_test_dir = long_test_dir.Append(kTestSubDirName); |
| 530 ASSERT_TRUE(CreateDirectory(access_test_dir)); | 530 ASSERT_TRUE(CreateDirectory(access_test_dir)); |
| 531 file_util::PermissionRestorer long_test_dir_restorer(long_test_dir); | 531 base::FilePermissionRestorer long_test_dir_restorer(long_test_dir); |
| 532 ASSERT_TRUE(file_util::MakeFileUnreadable(long_test_dir)); | 532 ASSERT_TRUE(base::MakeFileUnreadable(long_test_dir)); |
| 533 | 533 |
| 534 // Use the short form of the directory to create a temporary filename. | 534 // Use the short form of the directory to create a temporary filename. |
| 535 ASSERT_TRUE(CreateTemporaryFileInDir( | 535 ASSERT_TRUE(CreateTemporaryFileInDir( |
| 536 short_test_dir.Append(kTestSubDirName), &temp_file)); | 536 short_test_dir.Append(kTestSubDirName), &temp_file)); |
| 537 EXPECT_TRUE(PathExists(temp_file)); | 537 EXPECT_TRUE(PathExists(temp_file)); |
| 538 EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); | 538 EXPECT_TRUE(short_test_dir.IsParent(temp_file.DirName())); |
| 539 | 539 |
| 540 // Check that the long path can't be determined for |temp_file|. | 540 // Check that the long path can't be determined for |temp_file|. |
| 541 path_buffer_length = GetLongPathName(temp_file.value().c_str(), | 541 path_buffer_length = GetLongPathName(temp_file.value().c_str(), |
| 542 path_buffer, MAX_PATH); | 542 path_buffer, MAX_PATH); |
| (...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2514 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir)); | 2514 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &data_dir)); |
| 2515 data_dir = data_dir.AppendASCII("file_util"); | 2515 data_dir = data_dir.AppendASCII("file_util"); |
| 2516 ASSERT_TRUE(PathExists(data_dir)); | 2516 ASSERT_TRUE(PathExists(data_dir)); |
| 2517 FilePath image_file = data_dir.Append(FILE_PATH_LITERAL("red.png")); | 2517 FilePath image_file = data_dir.Append(FILE_PATH_LITERAL("red.png")); |
| 2518 int64 image_size; | 2518 int64 image_size; |
| 2519 GetFileSize(image_file, &image_size); | 2519 GetFileSize(image_file, &image_size); |
| 2520 EXPECT_LT(0, image_size); | 2520 EXPECT_LT(0, image_size); |
| 2521 | 2521 |
| 2522 // Insert the image into MediaStore. MediaStore will do some conversions, and | 2522 // Insert the image into MediaStore. MediaStore will do some conversions, and |
| 2523 // return the content URI. | 2523 // return the content URI. |
| 2524 FilePath path = file_util::InsertImageIntoMediaStore(image_file); | 2524 FilePath path = base::InsertImageIntoMediaStore(image_file); |
| 2525 EXPECT_TRUE(path.IsContentUri()); | 2525 EXPECT_TRUE(path.IsContentUri()); |
| 2526 EXPECT_TRUE(PathExists(path)); | 2526 EXPECT_TRUE(PathExists(path)); |
| 2527 // The file size may not equal to the input image as MediaStore may convert | 2527 // The file size may not equal to the input image as MediaStore may convert |
| 2528 // the image. | 2528 // the image. |
| 2529 int64 content_uri_size; | 2529 int64 content_uri_size; |
| 2530 GetFileSize(path, &content_uri_size); | 2530 GetFileSize(path, &content_uri_size); |
| 2531 EXPECT_EQ(image_size, content_uri_size); | 2531 EXPECT_EQ(image_size, content_uri_size); |
| 2532 | 2532 |
| 2533 // We should be able to read the file. | 2533 // We should be able to read the file. |
| 2534 char* buffer = new char[image_size]; | 2534 char* buffer = new char[image_size]; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2587 // Trying to close it should crash. This is important for security. | 2587 // Trying to close it should crash. This is important for security. |
| 2588 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2588 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
| 2589 #endif | 2589 #endif |
| 2590 } | 2590 } |
| 2591 | 2591 |
| 2592 #endif // defined(OS_POSIX) | 2592 #endif // defined(OS_POSIX) |
| 2593 | 2593 |
| 2594 } // namespace | 2594 } // namespace |
| 2595 | 2595 |
| 2596 } // namespace base | 2596 } // namespace base |
| OLD | NEW |