| 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 "webkit/fileapi/local_file_system_operation.h" | 5 #include "webkit/fileapi/local_file_system_operation.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 MessageLoop::current()->RunUntilIdle(); | 539 MessageLoop::current()->RunUntilIdle(); |
| 540 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); | 540 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); |
| 541 EXPECT_TRUE(change_observer()->HasNoChange()); | 541 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 542 } | 542 } |
| 543 | 543 |
| 544 TEST_F(LocalFileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { | 544 TEST_F(LocalFileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { |
| 545 // Dest. parent path does not exist. | 545 // Dest. parent path does not exist. |
| 546 base::FilePath src_dir_path(CreateUniqueDir()); | 546 base::FilePath src_dir_path(CreateUniqueDir()); |
| 547 base::FilePath nonexisting_path = base::FilePath( | 547 base::FilePath nonexisting_path = base::FilePath( |
| 548 FILE_PATH_LITERAL("DontExistDir")); | 548 FILE_PATH_LITERAL("DontExistDir")); |
| 549 file_util::EnsureEndsWithSeparator(&nonexisting_path); | |
| 550 base::FilePath nonexisting_file_path(nonexisting_path.Append( | 549 base::FilePath nonexisting_file_path(nonexisting_path.Append( |
| 551 FILE_PATH_LITERAL("DontExistFile"))); | 550 FILE_PATH_LITERAL("DontExistFile"))); |
| 552 | 551 |
| 553 NewOperation()->Copy( | 552 NewOperation()->Copy( |
| 554 URLForPath(src_dir_path), | 553 URLForPath(src_dir_path), |
| 555 URLForPath(nonexisting_file_path), | 554 URLForPath(nonexisting_file_path), |
| 556 RecordStatusCallback()); | 555 RecordStatusCallback()); |
| 557 MessageLoop::current()->RunUntilIdle(); | 556 MessageLoop::current()->RunUntilIdle(); |
| 558 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 557 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 559 EXPECT_TRUE(change_observer()->HasNoChange()); | 558 EXPECT_TRUE(change_observer()->HasNoChange()); |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 URLForPath(nonexisting_dir_path), | 881 URLForPath(nonexisting_dir_path), |
| 883 RecordMetadataCallback()); | 882 RecordMetadataCallback()); |
| 884 MessageLoop::current()->RunUntilIdle(); | 883 MessageLoop::current()->RunUntilIdle(); |
| 885 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 884 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 886 | 885 |
| 887 NewOperation()->FileExists(URLForPath(nonexisting_dir_path), | 886 NewOperation()->FileExists(URLForPath(nonexisting_dir_path), |
| 888 RecordStatusCallback()); | 887 RecordStatusCallback()); |
| 889 MessageLoop::current()->RunUntilIdle(); | 888 MessageLoop::current()->RunUntilIdle(); |
| 890 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 889 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 891 | 890 |
| 892 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | 891 nonexisting_dir_path = nonexisting_dir_path.AsEndingWithSeparator(); |
| 893 NewOperation()->DirectoryExists(URLForPath(nonexisting_dir_path), | 892 NewOperation()->DirectoryExists(URLForPath(nonexisting_dir_path), |
| 894 RecordStatusCallback()); | 893 RecordStatusCallback()); |
| 895 MessageLoop::current()->RunUntilIdle(); | 894 MessageLoop::current()->RunUntilIdle(); |
| 896 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 895 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 897 EXPECT_TRUE(change_observer()->HasNoChange()); | 896 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 898 } | 897 } |
| 899 | 898 |
| 900 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataSuccess) { | 899 TEST_F(LocalFileSystemOperationTest, TestExistsAndMetadataSuccess) { |
| 901 base::FilePath dir_path(CreateUniqueDir()); | 900 base::FilePath dir_path(CreateUniqueDir()); |
| 902 int read_access = 0; | 901 int read_access = 0; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 942 ASSERT_FALSE(file_path.empty()); | 941 ASSERT_FALSE(file_path.empty()); |
| 943 NewOperation()->DirectoryExists(URLForPath(file_path), | 942 NewOperation()->DirectoryExists(URLForPath(file_path), |
| 944 RecordStatusCallback()); | 943 RecordStatusCallback()); |
| 945 MessageLoop::current()->RunUntilIdle(); | 944 MessageLoop::current()->RunUntilIdle(); |
| 946 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); | 945 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); |
| 947 } | 946 } |
| 948 | 947 |
| 949 TEST_F(LocalFileSystemOperationTest, TestReadDirFailure) { | 948 TEST_F(LocalFileSystemOperationTest, TestReadDirFailure) { |
| 950 // Path doesn't exist | 949 // Path doesn't exist |
| 951 base::FilePath nonexisting_dir_path(base::FilePath( | 950 base::FilePath nonexisting_dir_path(base::FilePath( |
| 952 FILE_PATH_LITERAL("NonExistingDir"))); | 951 FILE_PATH_LITERAL("NonExistingDir")).AsEndingWithSeparator()); |
| 953 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); | |
| 954 NewOperation()->ReadDirectory(URLForPath(nonexisting_dir_path), | 952 NewOperation()->ReadDirectory(URLForPath(nonexisting_dir_path), |
| 955 RecordReadDirectoryCallback()); | 953 RecordReadDirectoryCallback()); |
| 956 MessageLoop::current()->RunUntilIdle(); | 954 MessageLoop::current()->RunUntilIdle(); |
| 957 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 955 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 958 | 956 |
| 959 // File exists. | 957 // File exists. |
| 960 base::FilePath dir_path(CreateUniqueDir()); | 958 base::FilePath dir_path(CreateUniqueDir()); |
| 961 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); | 959 base::FilePath file_path(CreateUniqueFileInDir(dir_path)); |
| 962 NewOperation()->ReadDirectory(URLForPath(file_path), | 960 NewOperation()->ReadDirectory(URLForPath(file_path), |
| 963 RecordReadDirectoryCallback()); | 961 RecordReadDirectoryCallback()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 991 entries()[i].name); | 989 entries()[i].name); |
| 992 } | 990 } |
| 993 } | 991 } |
| 994 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); | 992 EXPECT_EQ(1, quota_manager_proxy()->notify_storage_accessed_count()); |
| 995 EXPECT_TRUE(change_observer()->HasNoChange()); | 993 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 996 } | 994 } |
| 997 | 995 |
| 998 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { | 996 TEST_F(LocalFileSystemOperationTest, TestRemoveFailure) { |
| 999 // Path doesn't exist. | 997 // Path doesn't exist. |
| 1000 base::FilePath nonexisting_path(base::FilePath( | 998 base::FilePath nonexisting_path(base::FilePath( |
| 1001 FILE_PATH_LITERAL("NonExistingDir"))); | 999 FILE_PATH_LITERAL("NonExistingDir")).AsEndingWithSeparator()); |
| 1002 file_util::EnsureEndsWithSeparator(&nonexisting_path); | |
| 1003 | 1000 |
| 1004 NewOperation()->Remove(URLForPath(nonexisting_path), false /* recursive */, | 1001 NewOperation()->Remove(URLForPath(nonexisting_path), false /* recursive */, |
| 1005 RecordStatusCallback()); | 1002 RecordStatusCallback()); |
| 1006 MessageLoop::current()->RunUntilIdle(); | 1003 MessageLoop::current()->RunUntilIdle(); |
| 1007 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); | 1004 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); |
| 1008 | 1005 |
| 1009 // It's an error to try to remove a non-empty directory if recursive flag | 1006 // It's an error to try to remove a non-empty directory if recursive flag |
| 1010 // is false. | 1007 // is false. |
| 1011 // parent_dir | 1008 // parent_dir |
| 1012 // | | | 1009 // | | |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 EXPECT_FALSE(info().is_directory); | 1210 EXPECT_FALSE(info().is_directory); |
| 1214 EXPECT_EQ(PlatformPath(file_path), path()); | 1211 EXPECT_EQ(PlatformPath(file_path), path()); |
| 1215 EXPECT_TRUE(change_observer()->HasNoChange()); | 1212 EXPECT_TRUE(change_observer()->HasNoChange()); |
| 1216 | 1213 |
| 1217 // The FileSystemOpration implementation does not create a | 1214 // The FileSystemOpration implementation does not create a |
| 1218 // shareable file reference. | 1215 // shareable file reference. |
| 1219 EXPECT_EQ(NULL, shareable_file_ref()); | 1216 EXPECT_EQ(NULL, shareable_file_ref()); |
| 1220 } | 1217 } |
| 1221 | 1218 |
| 1222 } // namespace fileapi | 1219 } // namespace fileapi |
| OLD | NEW |