| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
| 11 #include "components/filesystem/files_test_base.h" | 11 #include "components/filesystem/files_test_base.h" |
| 12 #include "mojo/platform_handle/platform_handle_functions.h" | |
| 13 #include "mojo/public/cpp/bindings/interface_request.h" | 12 #include "mojo/public/cpp/bindings/interface_request.h" |
| 14 #include "mojo/public/cpp/bindings/type_converter.h" | 13 #include "mojo/public/cpp/bindings/type_converter.h" |
| 14 #include "mojo/public/cpp/system/platform_handle.h" |
| 15 #include "mojo/util/capture_util.h" | 15 #include "mojo/util/capture_util.h" |
| 16 | 16 |
| 17 using mojo::Capture; | 17 using mojo::Capture; |
| 18 | 18 |
| 19 namespace filesystem { | 19 namespace filesystem { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 using FileImplTest = FilesTestBase; | 22 using FileImplTest = FilesTestBase; |
| 23 | 23 |
| 24 TEST_F(FileImplTest, CreateWriteCloseRenameOpenRead) { | 24 TEST_F(FileImplTest, CreateWriteCloseRenameOpenRead) { |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 EXPECT_EQ(mojom::FileError::OK, error); | 663 EXPECT_EQ(mojom::FileError::OK, error); |
| 664 | 664 |
| 665 // Fetch the handle | 665 // Fetch the handle |
| 666 error = mojom::FileError::FAILED; | 666 error = mojom::FileError::FAILED; |
| 667 mojo::ScopedHandle handle; | 667 mojo::ScopedHandle handle; |
| 668 file1->AsHandle(Capture(&error, &handle)); | 668 file1->AsHandle(Capture(&error, &handle)); |
| 669 ASSERT_TRUE(file1.WaitForIncomingResponse()); | 669 ASSERT_TRUE(file1.WaitForIncomingResponse()); |
| 670 EXPECT_EQ(mojom::FileError::OK, error); | 670 EXPECT_EQ(mojom::FileError::OK, error); |
| 671 | 671 |
| 672 // Pull a file descriptor out of the scoped handle. | 672 // Pull a file descriptor out of the scoped handle. |
| 673 MojoPlatformHandle platform_handle; | 673 base::PlatformFile platform_file; |
| 674 MojoResult extract_result = | 674 MojoResult unwrap_result = mojo::UnwrapPlatformFile(std::move(handle), |
| 675 MojoExtractPlatformHandle(handle.release().value(), &platform_handle); | 675 &platform_file); |
| 676 EXPECT_EQ(MOJO_RESULT_OK, extract_result); | 676 EXPECT_EQ(MOJO_RESULT_OK, unwrap_result); |
| 677 | 677 |
| 678 // Pass this raw file descriptor to a base::File. | 678 // Pass this raw file descriptor to a base::File. |
| 679 base::File raw_file(platform_handle); | 679 base::File raw_file(platform_file); |
| 680 ASSERT_TRUE(raw_file.IsValid()); | 680 ASSERT_TRUE(raw_file.IsValid()); |
| 681 EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5)); | 681 EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5)); |
| 682 } | 682 } |
| 683 | 683 |
| 684 { | 684 { |
| 685 // Reopen my_file. | 685 // Reopen my_file. |
| 686 mojom::FilePtr file2; | 686 mojom::FilePtr file2; |
| 687 error = mojom::FileError::FAILED; | 687 error = mojom::FileError::FAILED; |
| 688 directory->OpenFile("my_file", GetProxy(&file2), | 688 directory->OpenFile("my_file", GetProxy(&file2), |
| 689 mojom::kFlagRead | mojom::kFlagOpen, Capture(&error)); | 689 mojom::kFlagRead | mojom::kFlagOpen, Capture(&error)); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 // The file shouldn't be locked (and we check by trying to lock it). | 796 // The file shouldn't be locked (and we check by trying to lock it). |
| 797 error = mojom::FileError::FAILED; | 797 error = mojom::FileError::FAILED; |
| 798 file->Lock(Capture(&error)); | 798 file->Lock(Capture(&error)); |
| 799 ASSERT_TRUE(file.WaitForIncomingResponse()); | 799 ASSERT_TRUE(file.WaitForIncomingResponse()); |
| 800 EXPECT_EQ(mojom::FileError::OK, error); | 800 EXPECT_EQ(mojom::FileError::OK, error); |
| 801 } | 801 } |
| 802 } | 802 } |
| 803 | 803 |
| 804 } // namespace | 804 } // namespace |
| 805 } // namespace filesystem | 805 } // namespace filesystem |
| OLD | NEW |