OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "storage/browser/fileapi/file_system_operation_impl.h" | 5 #include "storage/browser/fileapi/file_system_operation_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 operation_runner()->CreateDirectory( | 378 operation_runner()->CreateDirectory( |
379 url, | 379 url, |
380 exclusive, | 380 exclusive, |
381 recursive, | 381 recursive, |
382 RecordStatusCallback(run_loop.QuitClosure(), &status)); | 382 RecordStatusCallback(run_loop.QuitClosure(), &status)); |
383 run_loop.Run(); | 383 run_loop.Run(); |
384 update_observer_.Disable(); | 384 update_observer_.Disable(); |
385 return status; | 385 return status; |
386 } | 386 } |
387 | 387 |
388 base::File::Error GetMetadata(const FileSystemURL& url) { | 388 base::File::Error GetMetadata(const FileSystemURL& url, int fields) { |
389 base::File::Error status; | 389 base::File::Error status; |
390 base::RunLoop run_loop; | 390 base::RunLoop run_loop; |
391 update_observer_.Enable(); | 391 update_observer_.Enable(); |
392 operation_runner()->GetMetadata( | 392 operation_runner()->GetMetadata( |
393 url, RecordMetadataCallback(run_loop.QuitClosure(), &status)); | 393 url, fields, RecordMetadataCallback(run_loop.QuitClosure(), &status)); |
394 run_loop.Run(); | 394 run_loop.Run(); |
395 update_observer_.Disable(); | 395 update_observer_.Disable(); |
396 return status; | 396 return status; |
397 } | 397 } |
398 | 398 |
399 base::File::Error ReadDirectory(const FileSystemURL& url) { | 399 base::File::Error ReadDirectory(const FileSystemURL& url) { |
400 base::File::Error status; | 400 base::File::Error status; |
401 base::RunLoop run_loop; | 401 base::RunLoop run_loop; |
402 update_observer_.Enable(); | 402 update_observer_.Enable(); |
403 operation_runner()->ReadDirectory( | 403 operation_runner()->ReadDirectory( |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 // Dir doesn't exist. | 931 // Dir doesn't exist. |
932 EXPECT_EQ(base::File::FILE_OK, | 932 EXPECT_EQ(base::File::FILE_OK, |
933 CreateDirectory(URLForPath("new"), true, false)); | 933 CreateDirectory(URLForPath("new"), true, false)); |
934 EXPECT_TRUE(DirectoryExists("new")); | 934 EXPECT_TRUE(DirectoryExists("new")); |
935 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); | 935 EXPECT_EQ(1, change_observer()->get_and_reset_create_directory_count()); |
936 EXPECT_TRUE(change_observer()->HasNoChange()); | 936 EXPECT_TRUE(change_observer()->HasNoChange()); |
937 } | 937 } |
938 | 938 |
939 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { | 939 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataFailure) { |
940 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 940 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
941 GetMetadata(URLForPath("nonexistent"))); | 941 GetMetadata(URLForPath("nonexistent"), |
| 942 storage::FileSystemOperation::GET_METADATA_FIELD_NONE)); |
942 | 943 |
943 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 944 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
944 FileExists(URLForPath("nonexistent"))); | 945 FileExists(URLForPath("nonexistent"))); |
945 | 946 |
946 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, | 947 EXPECT_EQ(base::File::FILE_ERROR_NOT_FOUND, |
947 DirectoryExists(URLForPath("nonexistent"))); | 948 DirectoryExists(URLForPath("nonexistent"))); |
948 EXPECT_TRUE(change_observer()->HasNoChange()); | 949 EXPECT_TRUE(change_observer()->HasNoChange()); |
949 } | 950 } |
950 | 951 |
951 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { | 952 TEST_F(FileSystemOperationImplTest, TestExistsAndMetadataSuccess) { |
952 FileSystemURL dir(CreateDirectory("dir")); | 953 FileSystemURL dir(CreateDirectory("dir")); |
953 FileSystemURL file(CreateFile("dir/file")); | 954 FileSystemURL file(CreateFile("dir/file")); |
954 int read_access = 0; | 955 int read_access = 0; |
955 | 956 |
956 EXPECT_EQ(base::File::FILE_OK, DirectoryExists(dir)); | 957 EXPECT_EQ(base::File::FILE_OK, DirectoryExists(dir)); |
957 ++read_access; | 958 ++read_access; |
958 | 959 |
959 EXPECT_EQ(base::File::FILE_OK, GetMetadata(dir)); | 960 EXPECT_EQ( |
| 961 base::File::FILE_OK, |
| 962 GetMetadata( |
| 963 dir, storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY)); |
960 EXPECT_TRUE(info().is_directory); | 964 EXPECT_TRUE(info().is_directory); |
961 ++read_access; | 965 ++read_access; |
962 | 966 |
963 EXPECT_EQ(base::File::FILE_OK, FileExists(file)); | 967 EXPECT_EQ(base::File::FILE_OK, FileExists(file)); |
964 ++read_access; | 968 ++read_access; |
965 | 969 |
966 EXPECT_EQ(base::File::FILE_OK, GetMetadata(file)); | 970 EXPECT_EQ( |
| 971 base::File::FILE_OK, |
| 972 GetMetadata( |
| 973 file, storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY)); |
967 EXPECT_FALSE(info().is_directory); | 974 EXPECT_FALSE(info().is_directory); |
968 ++read_access; | 975 ++read_access; |
969 | 976 |
970 EXPECT_EQ(read_access, | 977 EXPECT_EQ(read_access, |
971 quota_manager_proxy()->notify_storage_accessed_count()); | 978 quota_manager_proxy()->notify_storage_accessed_count()); |
972 EXPECT_TRUE(change_observer()->HasNoChange()); | 979 EXPECT_TRUE(change_observer()->HasNoChange()); |
973 } | 980 } |
974 | 981 |
975 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { | 982 TEST_F(FileSystemOperationImplTest, TestTypeMismatchErrors) { |
976 FileSystemURL dir(CreateDirectory("dir")); | 983 FileSystemURL dir(CreateDirectory("dir")); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 TEST_F(FileSystemOperationImplTest, TestTruncate) { | 1077 TEST_F(FileSystemOperationImplTest, TestTruncate) { |
1071 FileSystemURL file(CreateFile("file")); | 1078 FileSystemURL file(CreateFile("file")); |
1072 base::FilePath platform_path = PlatformPath("file"); | 1079 base::FilePath platform_path = PlatformPath("file"); |
1073 | 1080 |
1074 char test_data[] = "test data"; | 1081 char test_data[] = "test data"; |
1075 int data_size = static_cast<int>(sizeof(test_data)); | 1082 int data_size = static_cast<int>(sizeof(test_data)); |
1076 EXPECT_EQ(data_size, | 1083 EXPECT_EQ(data_size, |
1077 base::WriteFile(platform_path, test_data, data_size)); | 1084 base::WriteFile(platform_path, test_data, data_size)); |
1078 | 1085 |
1079 // Check that its length is the size of the data written. | 1086 // Check that its length is the size of the data written. |
1080 EXPECT_EQ(base::File::FILE_OK, GetMetadata(file)); | 1087 EXPECT_EQ( |
| 1088 base::File::FILE_OK, |
| 1089 GetMetadata( |
| 1090 file, storage::FileSystemOperation::GET_METADATA_FIELD_IS_DIRECTORY | |
| 1091 storage::FileSystemOperation::GET_METADATA_FIELD_SIZE)); |
1081 EXPECT_FALSE(info().is_directory); | 1092 EXPECT_FALSE(info().is_directory); |
1082 EXPECT_EQ(data_size, info().size); | 1093 EXPECT_EQ(data_size, info().size); |
1083 | 1094 |
1084 // Extend the file by truncating it. | 1095 // Extend the file by truncating it. |
1085 int length = 17; | 1096 int length = 17; |
1086 EXPECT_EQ(base::File::FILE_OK, Truncate(file, length)); | 1097 EXPECT_EQ(base::File::FILE_OK, Truncate(file, length)); |
1087 | 1098 |
1088 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); | 1099 EXPECT_EQ(1, change_observer()->get_and_reset_modify_file_count()); |
1089 EXPECT_TRUE(change_observer()->HasNoChange()); | 1100 EXPECT_TRUE(change_observer()->HasNoChange()); |
1090 | 1101 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 FileSystemURL src_file(CreateFile("src")); | 1297 FileSystemURL src_file(CreateFile("src")); |
1287 FileSystemURL dest_file(CreateFile("dest")); | 1298 FileSystemURL dest_file(CreateFile("dest")); |
1288 | 1299 |
1289 EXPECT_EQ(base::File::FILE_OK, Truncate(dest_file, 6)); | 1300 EXPECT_EQ(base::File::FILE_OK, Truncate(dest_file, 6)); |
1290 EXPECT_EQ(base::File::FILE_OK, | 1301 EXPECT_EQ(base::File::FILE_OK, |
1291 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); | 1302 Copy(src_file, dest_file, FileSystemOperation::OPTION_NONE)); |
1292 EXPECT_EQ(0, GetFileSize("dest")); | 1303 EXPECT_EQ(0, GetFileSize("dest")); |
1293 } | 1304 } |
1294 | 1305 |
1295 } // namespace content | 1306 } // namespace content |
OLD | NEW |