Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: components/filesystem/file_impl_unittest.cc

Issue 2539383002: Replace base::File wrapping with typemapping. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/public/cpp/bindings/interface_request.h" 12 #include "mojo/public/cpp/bindings/interface_request.h"
13 #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 14
16 namespace filesystem { 15 namespace filesystem {
17 namespace { 16 namespace {
18 17
19 using FileImplTest = FilesTestBase; 18 using FileImplTest = FilesTestBase;
20 19
21 TEST_F(FileImplTest, CreateWriteCloseRenameOpenRead) { 20 TEST_F(FileImplTest, CreateWriteCloseRenameOpenRead) {
22 mojom::DirectoryPtr directory; 21 mojom::DirectoryPtr directory;
23 GetTemporaryRoot(&directory); 22 GetTemporaryRoot(&directory);
24 mojom::FileError error; 23 mojom::FileError error;
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 { 655 {
657 // Create my_file. 656 // Create my_file.
658 mojom::FilePtr file1; 657 mojom::FilePtr file1;
659 error = mojom::FileError::FAILED; 658 error = mojom::FileError::FAILED;
660 bool handled = directory->OpenFile( 659 bool handled = directory->OpenFile(
661 "my_file", GetProxy(&file1), 660 "my_file", GetProxy(&file1),
662 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error); 661 mojom::kFlagRead | mojom::kFlagWrite | mojom::kFlagCreate, &error);
663 ASSERT_TRUE(handled); 662 ASSERT_TRUE(handled);
664 EXPECT_EQ(mojom::FileError::OK, error); 663 EXPECT_EQ(mojom::FileError::OK, error);
665 664
666 // Fetch the handle 665 // Fetch the file.
667 error = mojom::FileError::FAILED; 666 error = mojom::FileError::FAILED;
668 mojo::ScopedHandle handle; 667 base::File raw_file;
669 handled = file1->AsHandle(&error, &handle); 668 handled = file1->AsHandle(&error, &raw_file);
670 ASSERT_TRUE(handled); 669 ASSERT_TRUE(handled);
671 EXPECT_EQ(mojom::FileError::OK, error); 670 EXPECT_EQ(mojom::FileError::OK, error);
672 671
673 // Pull a file descriptor out of the scoped handle.
674 base::PlatformFile platform_file;
675 MojoResult unwrap_result = mojo::UnwrapPlatformFile(std::move(handle),
676 &platform_file);
677 EXPECT_EQ(MOJO_RESULT_OK, unwrap_result);
678
679 // Pass this raw file descriptor to a base::File.
680 base::File raw_file(platform_file);
681 ASSERT_TRUE(raw_file.IsValid()); 672 ASSERT_TRUE(raw_file.IsValid());
682 EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5)); 673 EXPECT_EQ(5, raw_file.WriteAtCurrentPos("hello", 5));
683 } 674 }
684 675
685 { 676 {
686 // Reopen my_file. 677 // Reopen my_file.
687 mojom::FilePtr file2; 678 mojom::FilePtr file2;
688 error = mojom::FileError::FAILED; 679 error = mojom::FileError::FAILED;
689 bool handled = 680 bool handled =
690 directory->OpenFile("my_file", GetProxy(&file2), 681 directory->OpenFile("my_file", GetProxy(&file2),
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 // The file shouldn't be locked (and we check by trying to lock it). 788 // The file shouldn't be locked (and we check by trying to lock it).
798 error = mojom::FileError::FAILED; 789 error = mojom::FileError::FAILED;
799 handled = file->Lock(&error); 790 handled = file->Lock(&error);
800 ASSERT_TRUE(handled); 791 ASSERT_TRUE(handled);
801 EXPECT_EQ(mojom::FileError::OK, error); 792 EXPECT_EQ(mojom::FileError::OK, error);
802 } 793 }
803 } 794 }
804 795
805 } // namespace 796 } // namespace
806 } // namespace filesystem 797 } // namespace filesystem
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698