| 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 2431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2442 EXPECT_TRUE(path.IsContentUri()); | 2442 EXPECT_TRUE(path.IsContentUri()); |
| 2443 EXPECT_TRUE(PathExists(path)); | 2443 EXPECT_TRUE(PathExists(path)); |
| 2444 // The file size may not equal to the input image as MediaStore may convert | 2444 // The file size may not equal to the input image as MediaStore may convert |
| 2445 // the image. | 2445 // the image. |
| 2446 int64 content_uri_size; | 2446 int64 content_uri_size; |
| 2447 GetFileSize(path, &content_uri_size); | 2447 GetFileSize(path, &content_uri_size); |
| 2448 EXPECT_EQ(image_size, content_uri_size); | 2448 EXPECT_EQ(image_size, content_uri_size); |
| 2449 | 2449 |
| 2450 // We should be able to read the file. | 2450 // We should be able to read the file. |
| 2451 char* buffer = new char[image_size]; | 2451 char* buffer = new char[image_size]; |
| 2452 int fd = OpenContentUriForRead(path); | 2452 File file = OpenContentUriForRead(path); |
| 2453 EXPECT_LT(0, fd); | 2453 EXPECT_TRUE(file.IsValid()); |
| 2454 EXPECT_TRUE(ReadFromFD(fd, buffer, image_size)); | 2454 EXPECT_TRUE(file.ReadAtCurrentPos(buffer, image_size)); |
| 2455 delete[] buffer; | 2455 delete[] buffer; |
| 2456 } | 2456 } |
| 2457 | 2457 |
| 2458 TEST_F(FileUtilTest, NonExistentContentUriTest) { | 2458 TEST_F(FileUtilTest, NonExistentContentUriTest) { |
| 2459 FilePath path("content://foo.bar"); | 2459 FilePath path("content://foo.bar"); |
| 2460 EXPECT_TRUE(path.IsContentUri()); | 2460 EXPECT_TRUE(path.IsContentUri()); |
| 2461 EXPECT_FALSE(PathExists(path)); | 2461 EXPECT_FALSE(PathExists(path)); |
| 2462 // Size should be smaller than 0. | 2462 // Size should be smaller than 0. |
| 2463 int64 size; | 2463 int64 size; |
| 2464 EXPECT_FALSE(GetFileSize(path, &size)); | 2464 EXPECT_FALSE(GetFileSize(path, &size)); |
| 2465 | 2465 |
| 2466 // We should not be able to read the file. | 2466 // We should not be able to read the file. |
| 2467 int fd = OpenContentUriForRead(path); | 2467 File file = OpenContentUriForRead(path); |
| 2468 EXPECT_EQ(-1, fd); | 2468 EXPECT_FALSE(file.IsValid()); |
| 2469 } | 2469 } |
| 2470 #endif | 2470 #endif |
| 2471 | 2471 |
| 2472 TEST(ScopedFD, ScopedFDDoesClose) { | 2472 TEST(ScopedFD, ScopedFDDoesClose) { |
| 2473 int fds[2]; | 2473 int fds[2]; |
| 2474 char c = 0; | 2474 char c = 0; |
| 2475 ASSERT_EQ(0, pipe(fds)); | 2475 ASSERT_EQ(0, pipe(fds)); |
| 2476 const int write_end = fds[1]; | 2476 const int write_end = fds[1]; |
| 2477 base::ScopedFD read_end_closer(fds[0]); | 2477 base::ScopedFD read_end_closer(fds[0]); |
| 2478 { | 2478 { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2504 // Trying to close it should crash. This is important for security. | 2504 // Trying to close it should crash. This is important for security. |
| 2505 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); | 2505 EXPECT_DEATH(CloseWithScopedFD(fds[1]), ""); |
| 2506 #endif | 2506 #endif |
| 2507 } | 2507 } |
| 2508 | 2508 |
| 2509 #endif // defined(OS_POSIX) | 2509 #endif // defined(OS_POSIX) |
| 2510 | 2510 |
| 2511 } // namespace | 2511 } // namespace |
| 2512 | 2512 |
| 2513 } // namespace base | 2513 } // namespace base |
| OLD | NEW |