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 "chrome/browser/chromeos/drive/file_system.h" | 5 #include "chrome/browser/chromeos/drive/file_system.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 FileError error = FILE_ERROR_FAILED; | 165 FileError error = FILE_ERROR_FAILED; |
166 file_system_->CreateDirectory( | 166 file_system_->CreateDirectory( |
167 directory_path, | 167 directory_path, |
168 false, // is_exclusive | 168 false, // is_exclusive |
169 false, // is_recursive | 169 false, // is_recursive |
170 google_apis::test_util::CreateCopyResultCallback(&error)); | 170 google_apis::test_util::CreateCopyResultCallback(&error)); |
171 google_apis::test_util::RunBlockingPoolTask(); | 171 google_apis::test_util::RunBlockingPoolTask(); |
172 return error; | 172 return error; |
173 } | 173 } |
174 | 174 |
175 bool RemoveEntry(const base::FilePath& file_path) { | |
176 FileError error = FILE_ERROR_FAILED; | |
177 file_system_->Remove( | |
178 file_path, false, | |
179 google_apis::test_util::CreateCopyResultCallback(&error)); | |
180 google_apis::test_util::RunBlockingPoolTask(); | |
181 return error == FILE_ERROR_OK; | |
182 } | |
183 | |
184 // Gets resource entry by path synchronously. | 175 // Gets resource entry by path synchronously. |
185 scoped_ptr<ResourceEntry> GetResourceEntryByPathSync( | 176 scoped_ptr<ResourceEntry> GetResourceEntryByPathSync( |
186 const base::FilePath& file_path) { | 177 const base::FilePath& file_path) { |
187 FileError error = FILE_ERROR_FAILED; | 178 FileError error = FILE_ERROR_FAILED; |
188 scoped_ptr<ResourceEntry> entry; | 179 scoped_ptr<ResourceEntry> entry; |
189 file_system_->GetResourceEntryByPath( | 180 file_system_->GetResourceEntryByPath( |
190 file_path, | 181 file_path, |
191 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 182 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
192 google_apis::test_util::RunBlockingPoolTask(); | 183 google_apis::test_util::RunBlockingPoolTask(); |
193 | 184 |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1129 google_apis::test_util::RunBlockingPoolTask(); | 1120 google_apis::test_util::RunBlockingPoolTask(); |
1130 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 1121 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
1131 | 1122 |
1132 EXPECT_TRUE(EntryExists(src_file_path)); | 1123 EXPECT_TRUE(EntryExists(src_file_path)); |
1133 EXPECT_TRUE(EntryExists(src_file_path)); | 1124 EXPECT_TRUE(EntryExists(src_file_path)); |
1134 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1125 EXPECT_TRUE(EntryExists(dest_parent_path)); |
1135 | 1126 |
1136 EXPECT_FALSE(EntryExists(dest_file_path)); | 1127 EXPECT_FALSE(EntryExists(dest_file_path)); |
1137 } | 1128 } |
1138 | 1129 |
1139 TEST_F(FileSystemTest, RemoveEntries) { | |
1140 ASSERT_TRUE(LoadRootFeedDocument()); | |
1141 | |
1142 base::FilePath nonexisting_file( | |
1143 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | |
1144 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1145 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/root/Directory 1")); | |
1146 base::FilePath file_in_subdir( | |
1147 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); | |
1148 | |
1149 ASSERT_TRUE(EntryExists(file_in_root)); | |
1150 scoped_ptr<ResourceEntry> file_in_root_proto = GetResourceEntryByPathSync( | |
1151 file_in_root); | |
1152 ASSERT_TRUE(file_in_root_proto); | |
1153 | |
1154 ASSERT_TRUE(EntryExists(dir_in_root)); | |
1155 scoped_ptr<ResourceEntry> dir_in_root_proto = GetResourceEntryByPathSync( | |
1156 dir_in_root); | |
1157 ASSERT_TRUE(dir_in_root_proto); | |
1158 ASSERT_TRUE(dir_in_root_proto->file_info().is_directory()); | |
1159 | |
1160 ASSERT_TRUE(EntryExists(file_in_subdir)); | |
1161 scoped_ptr<ResourceEntry> file_in_subdir_proto = GetResourceEntryByPathSync( | |
1162 file_in_subdir); | |
1163 ASSERT_TRUE(file_in_subdir_proto); | |
1164 | |
1165 // Once for file in root and once for file... | |
1166 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | |
1167 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(2); | |
1168 | |
1169 // Remove first file in root. | |
1170 EXPECT_TRUE(RemoveEntry(file_in_root)); | |
1171 EXPECT_FALSE(EntryExists(file_in_root)); | |
1172 EXPECT_TRUE(EntryExists(dir_in_root)); | |
1173 EXPECT_TRUE(EntryExists(file_in_subdir)); | |
1174 | |
1175 // Remove directory. | |
1176 EXPECT_TRUE(RemoveEntry(dir_in_root)); | |
1177 EXPECT_FALSE(EntryExists(file_in_root)); | |
1178 EXPECT_FALSE(EntryExists(dir_in_root)); | |
1179 EXPECT_FALSE(EntryExists(file_in_subdir)); | |
1180 | |
1181 // Try removing file in already removed subdirectory. | |
1182 EXPECT_FALSE(RemoveEntry(file_in_subdir)); | |
1183 | |
1184 // Try removing non-existing file. | |
1185 EXPECT_FALSE(RemoveEntry(nonexisting_file)); | |
1186 | |
1187 // Try removing root file element. | |
1188 EXPECT_FALSE(RemoveEntry(base::FilePath(FILE_PATH_LITERAL("drive/root")))); | |
1189 | |
1190 // Need this to ensure OnDirectoryChanged() is run. | |
1191 google_apis::test_util::RunBlockingPoolTask(); | |
1192 } | |
1193 | |
1194 TEST_F(FileSystemTest, CreateDirectory) { | 1130 TEST_F(FileSystemTest, CreateDirectory) { |
1195 ASSERT_TRUE(LoadRootFeedDocument()); | 1131 ASSERT_TRUE(LoadRootFeedDocument()); |
1196 | 1132 |
1197 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1133 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
1198 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | 1134 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
1199 | 1135 |
1200 // Create directory in root. | 1136 // Create directory in root. |
1201 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); | 1137 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); |
1202 EXPECT_FALSE(EntryExists(dir_path)); | 1138 EXPECT_FALSE(EntryExists(dir_path)); |
1203 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(dir_path)); | 1139 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(dir_path)); |
(...skipping 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1772 entry->resource_id(), | 1708 entry->resource_id(), |
1773 entry->file_specific_info().file_md5(), | 1709 entry->file_specific_info().file_md5(), |
1774 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); | 1710 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); |
1775 google_apis::test_util::RunBlockingPoolTask(); | 1711 google_apis::test_util::RunBlockingPoolTask(); |
1776 | 1712 |
1777 EXPECT_TRUE(success); | 1713 EXPECT_TRUE(success); |
1778 EXPECT_FALSE(cache_entry.is_mounted()); | 1714 EXPECT_FALSE(cache_entry.is_mounted()); |
1779 } | 1715 } |
1780 | 1716 |
1781 } // namespace drive | 1717 } // namespace drive |
OLD | NEW |