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" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/scoped_temp_dir.h" | 13 #include "base/files/scoped_temp_dir.h" |
14 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
kinaba
2013/05/30 07:23:07
not used anymore.
hashimoto
2013/05/30 07:48:19
Good catch, done.
| |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/threading/sequenced_worker_pool.h" | 18 #include "base/threading/sequenced_worker_pool.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/chromeos/drive/change_list_loader.h" | 20 #include "chrome/browser/chromeos/drive/change_list_loader.h" |
21 #include "chrome/browser/chromeos/drive/drive.pb.h" | 21 #include "chrome/browser/chromeos/drive/drive.pb.h" |
22 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" | 22 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" |
23 #include "chrome/browser/chromeos/drive/file_system_util.h" | 23 #include "chrome/browser/chromeos/drive/file_system_util.h" |
24 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 24 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 const std::string& md5, | 210 const std::string& md5, |
211 FileCacheEntry* cache_entry) { | 211 FileCacheEntry* cache_entry) { |
212 bool result = false; | 212 bool result = false; |
213 cache_->GetCacheEntryOnUIThread( | 213 cache_->GetCacheEntryOnUIThread( |
214 resource_id, md5, | 214 resource_id, md5, |
215 google_apis::test_util::CreateCopyResultCallback(&result, cache_entry)); | 215 google_apis::test_util::CreateCopyResultCallback(&result, cache_entry)); |
216 google_apis::test_util::RunBlockingPoolTask(); | 216 google_apis::test_util::RunBlockingPoolTask(); |
217 return result; | 217 return result; |
218 } | 218 } |
219 | 219 |
220 // Returns true if the cache entry exists for the given resource ID and MD5. | |
221 bool CacheEntryExists(const std::string& resource_id, | |
222 const std::string& md5) { | |
223 FileCacheEntry cache_entry; | |
224 return GetCacheEntryFromOriginThread(resource_id, md5, &cache_entry); | |
225 } | |
226 | |
227 // Flag for specifying the timestamp of the test filesystem cache. | 220 // Flag for specifying the timestamp of the test filesystem cache. |
228 enum SetUpTestFileSystemParam { | 221 enum SetUpTestFileSystemParam { |
229 USE_OLD_TIMESTAMP, | 222 USE_OLD_TIMESTAMP, |
230 USE_SERVER_TIMESTAMP, | 223 USE_SERVER_TIMESTAMP, |
231 }; | 224 }; |
232 | 225 |
233 // Sets up a filesystem with directories: drive/root, drive/root/Dir1, | 226 // Sets up a filesystem with directories: drive/root, drive/root/Dir1, |
234 // drive/root/Dir1/SubDir2 and files drive/root/File1, drive/root/Dir1/File2, | 227 // drive/root/Dir1/SubDir2 and files drive/root/File1, drive/root/Dir1/File2, |
235 // drive/root/Dir1/SubDir2/File3. If |use_up_to_date_timestamp| is true, sets | 228 // drive/root/Dir1/SubDir2/File3. If |use_up_to_date_timestamp| is true, sets |
236 // the changestamp to 654321, equal to that of "account_metadata.json" test | 229 // the changestamp to 654321, equal to that of "account_metadata.json" test |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
341 google_apis::test_util::RunBlockingPoolTask(); | 334 google_apis::test_util::RunBlockingPoolTask(); |
342 if (error != FILE_ERROR_OK) | 335 if (error != FILE_ERROR_OK) |
343 return false; | 336 return false; |
344 | 337 |
345 // Recreate resource metadata. | 338 // Recreate resource metadata. |
346 SetUpResourceMetadataAndFileSystem(); | 339 SetUpResourceMetadataAndFileSystem(); |
347 | 340 |
348 return true; | 341 return true; |
349 } | 342 } |
350 | 343 |
351 // Verifies that |file_path| is a valid JSON file for the hosted document | |
352 // associated with |entry| (i.e. |url| and |resource_id| match). | |
353 void VerifyHostedDocumentJSONFile(const ResourceEntry& entry, | |
354 const base::FilePath& file_path) { | |
355 std::string error; | |
356 JSONFileValueSerializer serializer(file_path); | |
357 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error)); | |
358 ASSERT_TRUE(value) << "Parse error " << file_path.value() << ": " << error; | |
359 DictionaryValue* dict_value = NULL; | |
360 ASSERT_TRUE(value->GetAsDictionary(&dict_value)); | |
361 | |
362 std::string alternate_url, resource_id; | |
363 EXPECT_TRUE(dict_value->GetString("url", &alternate_url)); | |
364 EXPECT_TRUE(dict_value->GetString("resource_id", &resource_id)); | |
365 | |
366 EXPECT_EQ(entry.file_specific_info().alternate_url(), alternate_url); | |
367 EXPECT_EQ(entry.resource_id(), resource_id); | |
368 } | |
369 | |
370 base::MessageLoopForUI message_loop_; | 344 base::MessageLoopForUI message_loop_; |
371 content::TestBrowserThread ui_thread_; | 345 content::TestBrowserThread ui_thread_; |
372 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; | 346 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; |
373 scoped_ptr<TestingProfile> profile_; | 347 scoped_ptr<TestingProfile> profile_; |
374 | 348 |
375 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; | 349 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; |
376 scoped_ptr<FileSystem> file_system_; | 350 scoped_ptr<FileSystem> file_system_; |
377 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; | 351 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; |
378 scoped_ptr<JobScheduler> scheduler_; | 352 scoped_ptr<JobScheduler> scheduler_; |
379 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> | 353 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> |
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1021 remote_src_file_path, | 995 remote_src_file_path, |
1022 local_dest_file_path, | 996 local_dest_file_path, |
1023 google_apis::test_util::CreateCopyResultCallback(&error)); | 997 google_apis::test_util::CreateCopyResultCallback(&error)); |
1024 google_apis::test_util::RunBlockingPoolTask(); | 998 google_apis::test_util::RunBlockingPoolTask(); |
1025 | 999 |
1026 EXPECT_EQ(FILE_ERROR_OK, error); | 1000 EXPECT_EQ(FILE_ERROR_OK, error); |
1027 | 1001 |
1028 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync( | 1002 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync( |
1029 remote_src_file_path); | 1003 remote_src_file_path); |
1030 ASSERT_TRUE(entry); | 1004 ASSERT_TRUE(entry); |
1031 VerifyHostedDocumentJSONFile(*entry, local_dest_file_path); | 1005 EXPECT_EQ(GURL(entry->file_specific_info().alternate_url()), |
1006 util::ReadUrlFromGDocFile(local_dest_file_path)); | |
1007 EXPECT_EQ(entry->resource_id(), | |
1008 util::ReadResourceIdFromGDocFile(local_dest_file_path)); | |
1032 } | 1009 } |
1033 | 1010 |
1034 TEST_F(FileSystemTest, CopyNotExistingFile) { | 1011 TEST_F(FileSystemTest, CopyNotExistingFile) { |
1035 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); | 1012 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); |
1036 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); | 1013 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
1037 | 1014 |
1038 ASSERT_TRUE(LoadRootFeedDocument()); | 1015 ASSERT_TRUE(LoadRootFeedDocument()); |
1039 | 1016 |
1040 EXPECT_FALSE(EntryExists(src_file_path)); | 1017 EXPECT_FALSE(EntryExists(src_file_path)); |
1041 | 1018 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1158 error = FILE_ERROR_FAILED; | 1135 error = FILE_ERROR_FAILED; |
1159 EXPECT_CALL(*mock_cache_observer_, | 1136 EXPECT_CALL(*mock_cache_observer_, |
1160 OnCacheUnpinned(entry->resource_id(), | 1137 OnCacheUnpinned(entry->resource_id(), |
1161 entry->file_specific_info().file_md5())).Times(1); | 1138 entry->file_specific_info().file_md5())).Times(1); |
1162 file_system_->Unpin(file_path, | 1139 file_system_->Unpin(file_path, |
1163 google_apis::test_util::CreateCopyResultCallback(&error)); | 1140 google_apis::test_util::CreateCopyResultCallback(&error)); |
1164 google_apis::test_util::RunBlockingPoolTask(); | 1141 google_apis::test_util::RunBlockingPoolTask(); |
1165 EXPECT_EQ(FILE_ERROR_OK, error); | 1142 EXPECT_EQ(FILE_ERROR_OK, error); |
1166 } | 1143 } |
1167 | 1144 |
1168 TEST_F(FileSystemTest, GetFileByPath_FromGData_EnoughSpace) { | |
1169 ASSERT_TRUE(LoadRootFeedDocument()); | |
1170 | |
1171 // The transfered file is cached and the change of "offline available" | |
1172 // attribute is notified. | |
1173 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | |
1174 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | |
1175 | |
1176 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1177 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | |
1178 const int64 file_size = entry->file_info().size(); | |
1179 | |
1180 // Pretend we have enough space. | |
1181 fake_free_disk_space_getter_->set_fake_free_disk_space( | |
1182 file_size + internal::kMinFreeSpace); | |
1183 | |
1184 FileError error = FILE_ERROR_FAILED; | |
1185 base::FilePath file_path; | |
1186 entry.reset(); | |
1187 file_system_->GetFileByPath(file_in_root, | |
1188 google_apis::test_util::CreateCopyResultCallback( | |
1189 &error, &file_path, &entry)); | |
1190 google_apis::test_util::RunBlockingPoolTask(); | |
1191 | |
1192 EXPECT_EQ(FILE_ERROR_OK, error); | |
1193 ASSERT_TRUE(entry); | |
1194 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | |
1195 | |
1196 // Verify that readable permission is set. | |
1197 int permission = 0; | |
1198 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_path, &permission)); | |
1199 EXPECT_EQ(file_util::FILE_PERMISSION_READ_BY_USER | | |
1200 file_util::FILE_PERMISSION_WRITE_BY_USER | | |
1201 file_util::FILE_PERMISSION_READ_BY_GROUP | | |
1202 file_util::FILE_PERMISSION_READ_BY_OTHERS, permission); | |
1203 } | |
1204 | |
1205 TEST_F(FileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) { | |
1206 ASSERT_TRUE(LoadRootFeedDocument()); | |
1207 | |
1208 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1209 | |
1210 // Pretend we have no space at all. | |
1211 fake_free_disk_space_getter_->set_fake_free_disk_space(0); | |
1212 | |
1213 FileError error = FILE_ERROR_OK; | |
1214 base::FilePath file_path; | |
1215 scoped_ptr<ResourceEntry> entry; | |
1216 file_system_->GetFileByPath(file_in_root, | |
1217 google_apis::test_util::CreateCopyResultCallback( | |
1218 &error, &file_path, &entry)); | |
1219 google_apis::test_util::RunBlockingPoolTask(); | |
1220 | |
1221 EXPECT_EQ(FILE_ERROR_NO_SPACE, error); | |
1222 } | |
1223 | |
1224 TEST_F(FileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) { | |
1225 ASSERT_TRUE(LoadRootFeedDocument()); | |
1226 | |
1227 // The transfered file is cached and the change of "offline available" | |
1228 // attribute is notified. | |
1229 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | |
1230 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | |
1231 | |
1232 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1233 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | |
1234 const int64 file_size = entry->file_info().size(); | |
1235 | |
1236 // Pretend we have no space first (checked before downloading a file), | |
1237 // but then start reporting we have space. This is to emulate that | |
1238 // the disk space was freed up by removing temporary files. | |
1239 fake_free_disk_space_getter_->set_fake_free_disk_space( | |
1240 file_size + internal::kMinFreeSpace); | |
1241 fake_free_disk_space_getter_->set_fake_free_disk_space(0); | |
1242 fake_free_disk_space_getter_->set_fake_free_disk_space( | |
1243 file_size + internal::kMinFreeSpace); | |
1244 fake_free_disk_space_getter_->set_fake_free_disk_space( | |
1245 file_size + internal::kMinFreeSpace); | |
1246 | |
1247 // Store something of the file size in the temporary cache directory. | |
1248 const std::string content(file_size, 'x'); | |
1249 base::ScopedTempDir temp_dir; | |
1250 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | |
1251 const base::FilePath tmp_file = | |
1252 temp_dir.path().AppendASCII("something.txt"); | |
1253 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(tmp_file, content)); | |
1254 | |
1255 FileError error = FILE_ERROR_FAILED; | |
1256 cache_->StoreOnUIThread( | |
1257 "<resource_id>", "<md5>", tmp_file, | |
1258 internal::FileCache::FILE_OPERATION_COPY, | |
1259 google_apis::test_util::CreateCopyResultCallback(&error)); | |
1260 google_apis::test_util::RunBlockingPoolTask(); | |
1261 EXPECT_EQ(FILE_ERROR_OK, error); | |
1262 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>")); | |
1263 | |
1264 base::FilePath file_path; | |
1265 entry.reset(); | |
1266 file_system_->GetFileByPath(file_in_root, | |
1267 google_apis::test_util::CreateCopyResultCallback( | |
1268 &error, &file_path, &entry)); | |
1269 google_apis::test_util::RunBlockingPoolTask(); | |
1270 | |
1271 EXPECT_EQ(FILE_ERROR_OK, error); | |
1272 ASSERT_TRUE(entry); | |
1273 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | |
1274 | |
1275 // The cache entry should be removed in order to free up space. | |
1276 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>")); | |
1277 } | |
1278 | |
1279 TEST_F(FileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) { | |
1280 ASSERT_TRUE(LoadRootFeedDocument()); | |
1281 | |
1282 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1283 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | |
1284 const int64 file_size = entry->file_info().size(); | |
1285 | |
1286 // Pretend we have enough space first (checked before downloading a file), | |
1287 // but then start reporting we have not enough space. This is to emulate that | |
1288 // the disk space becomes full after the file is downloaded for some reason | |
1289 // (ex. the actual file was larger than the expected size). | |
1290 fake_free_disk_space_getter_->set_fake_free_disk_space( | |
1291 file_size + internal::kMinFreeSpace); | |
1292 fake_free_disk_space_getter_->set_fake_free_disk_space( | |
1293 internal::kMinFreeSpace - 1); | |
1294 fake_free_disk_space_getter_->set_fake_free_disk_space( | |
1295 internal::kMinFreeSpace - 1); | |
1296 | |
1297 FileError error = FILE_ERROR_OK; | |
1298 base::FilePath file_path; | |
1299 entry.reset(); | |
1300 file_system_->GetFileByPath(file_in_root, | |
1301 google_apis::test_util::CreateCopyResultCallback( | |
1302 &error, &file_path, &entry)); | |
1303 google_apis::test_util::RunBlockingPoolTask(); | |
1304 | |
1305 EXPECT_EQ(FILE_ERROR_NO_SPACE, error); | |
1306 } | |
1307 | |
1308 TEST_F(FileSystemTest, GetFileByPath_FromCache) { | |
1309 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | |
1310 | |
1311 ASSERT_TRUE(LoadRootFeedDocument()); | |
1312 | |
1313 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1314 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | |
1315 | |
1316 // Store something as cached version of this file. | |
1317 FileError error = FILE_ERROR_OK; | |
1318 cache_->StoreOnUIThread( | |
1319 entry->resource_id(), | |
1320 entry->file_specific_info().file_md5(), | |
1321 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"), | |
1322 internal::FileCache::FILE_OPERATION_COPY, | |
1323 google_apis::test_util::CreateCopyResultCallback(&error)); | |
1324 google_apis::test_util::RunBlockingPoolTask(); | |
1325 EXPECT_EQ(FILE_ERROR_OK, error); | |
1326 | |
1327 base::FilePath file_path; | |
1328 entry.reset(); | |
1329 file_system_->GetFileByPath(file_in_root, | |
1330 google_apis::test_util::CreateCopyResultCallback( | |
1331 &error, &file_path, &entry)); | |
1332 google_apis::test_util::RunBlockingPoolTask(); | |
1333 | |
1334 EXPECT_EQ(FILE_ERROR_OK, error); | |
1335 ASSERT_TRUE(entry); | |
1336 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | |
1337 } | |
1338 | |
1339 TEST_F(FileSystemTest, GetFileByPath_HostedDocument) { | |
1340 ASSERT_TRUE(LoadRootFeedDocument()); | |
1341 | |
1342 base::FilePath file_in_root(FILE_PATH_LITERAL( | |
1343 "drive/root/Document 1 excludeDir-test.gdoc")); | |
1344 scoped_ptr<ResourceEntry> src_entry = | |
1345 GetResourceEntryByPathSync(file_in_root); | |
1346 ASSERT_TRUE(src_entry); | |
1347 | |
1348 FileError error = FILE_ERROR_FAILED; | |
1349 base::FilePath file_path; | |
1350 scoped_ptr<ResourceEntry> entry; | |
1351 file_system_->GetFileByPath(file_in_root, | |
1352 google_apis::test_util::CreateCopyResultCallback( | |
1353 &error, &file_path, &entry)); | |
1354 google_apis::test_util::RunBlockingPoolTask(); | |
1355 | |
1356 EXPECT_EQ(FILE_ERROR_OK, error); | |
1357 ASSERT_TRUE(entry); | |
1358 EXPECT_TRUE(entry->file_specific_info().is_hosted_document()); | |
1359 EXPECT_FALSE(file_path.empty()); | |
1360 | |
1361 ASSERT_TRUE(src_entry); | |
1362 VerifyHostedDocumentJSONFile(*src_entry, file_path); | |
1363 } | |
1364 | |
1365 TEST_F(FileSystemTest, GetFileByResourceId) { | |
1366 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | |
1367 | |
1368 // The transfered file is cached and the change of "offline available" | |
1369 // attribute is notified. | |
1370 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | |
1371 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | |
1372 | |
1373 ASSERT_TRUE(LoadRootFeedDocument()); | |
1374 | |
1375 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1376 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | |
1377 std::string resource_id = entry->resource_id(); | |
1378 | |
1379 FileError error = FILE_ERROR_OK; | |
1380 base::FilePath file_path; | |
1381 entry.reset(); | |
1382 file_system_->GetFileByResourceId( | |
1383 resource_id, | |
1384 ClientContext(USER_INITIATED), | |
1385 google_apis::test_util::CreateCopyResultCallback( | |
1386 &error, &file_path, &entry), | |
1387 google_apis::GetContentCallback()); | |
1388 google_apis::test_util::RunBlockingPoolTask(); | |
1389 | |
1390 EXPECT_EQ(FILE_ERROR_OK, error); | |
1391 ASSERT_TRUE(entry); | |
1392 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | |
1393 } | |
1394 | |
1395 TEST_F(FileSystemTest, GetFileContentByPath) { | |
1396 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | |
1397 | |
1398 // The transfered file is cached and the change of "offline available" | |
1399 // attribute is notified. | |
1400 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | |
1401 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | |
1402 | |
1403 ASSERT_TRUE(LoadRootFeedDocument()); | |
1404 | |
1405 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1406 | |
1407 { | |
1408 FileError initialized_error = FILE_ERROR_FAILED; | |
1409 scoped_ptr<ResourceEntry> entry; | |
1410 base::FilePath local_path; | |
1411 base::Closure cancel_download; | |
1412 google_apis::test_util::TestGetContentCallback get_content_callback; | |
1413 | |
1414 FileError completion_error = FILE_ERROR_FAILED; | |
1415 | |
1416 file_system_->GetFileContentByPath( | |
1417 file_in_root, | |
1418 google_apis::test_util::CreateCopyResultCallback( | |
1419 &initialized_error, &entry, &local_path, &cancel_download), | |
1420 get_content_callback.callback(), | |
1421 google_apis::test_util::CreateCopyResultCallback(&completion_error)); | |
1422 google_apis::test_util::RunBlockingPoolTask(); | |
1423 | |
1424 // For the first time, file is downloaded from the remote server. | |
1425 // In this case, |local_path| is empty while |cancel_download| is not. | |
1426 EXPECT_EQ(FILE_ERROR_OK, initialized_error); | |
1427 ASSERT_TRUE(entry); | |
1428 ASSERT_TRUE(local_path.empty()); | |
1429 EXPECT_TRUE(!cancel_download.is_null()); | |
1430 // Content is available through the second callback argument. | |
1431 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()), | |
1432 get_content_callback.GetConcatenatedData().size()); | |
1433 EXPECT_EQ(FILE_ERROR_OK, completion_error); | |
1434 } | |
1435 | |
1436 { | |
1437 FileError initialized_error = FILE_ERROR_FAILED; | |
1438 scoped_ptr<ResourceEntry> entry; | |
1439 base::FilePath local_path; | |
1440 base::Closure cancel_download; | |
1441 google_apis::test_util::TestGetContentCallback get_content_callback; | |
1442 | |
1443 FileError completion_error = FILE_ERROR_FAILED; | |
1444 | |
1445 file_system_->GetFileContentByPath( | |
1446 file_in_root, | |
1447 google_apis::test_util::CreateCopyResultCallback( | |
1448 &initialized_error, &entry, &local_path, &cancel_download), | |
1449 get_content_callback.callback(), | |
1450 google_apis::test_util::CreateCopyResultCallback(&completion_error)); | |
1451 google_apis::test_util::RunBlockingPoolTask(); | |
1452 | |
1453 // Try second download. In this case, the file should be cached, so | |
1454 // |local_path| should not be empty while |cancel_download| is empty. | |
1455 EXPECT_EQ(FILE_ERROR_OK, initialized_error); | |
1456 ASSERT_TRUE(entry); | |
1457 ASSERT_TRUE(!local_path.empty()); | |
1458 EXPECT_TRUE(cancel_download.is_null()); | |
1459 // The content is available from the cache file. | |
1460 EXPECT_TRUE(get_content_callback.data().empty()); | |
1461 int64 local_file_size = 0; | |
1462 file_util::GetFileSize(local_path, &local_file_size); | |
1463 EXPECT_EQ(entry->file_info().size(), local_file_size); | |
1464 EXPECT_EQ(FILE_ERROR_OK, completion_error); | |
1465 } | |
1466 } | |
1467 | |
1468 TEST_F(FileSystemTest, GetFileByResourceId_FromCache) { | |
1469 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); | |
1470 | |
1471 ASSERT_TRUE(LoadRootFeedDocument()); | |
1472 | |
1473 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); | |
1474 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root)); | |
1475 | |
1476 // Store something as cached version of this file. | |
1477 FileError error = FILE_ERROR_FAILED; | |
1478 cache_->StoreOnUIThread( | |
1479 entry->resource_id(), | |
1480 entry->file_specific_info().file_md5(), | |
1481 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"), | |
1482 internal::FileCache::FILE_OPERATION_COPY, | |
1483 google_apis::test_util::CreateCopyResultCallback(&error)); | |
1484 google_apis::test_util::RunBlockingPoolTask(); | |
1485 EXPECT_EQ(FILE_ERROR_OK, error); | |
1486 | |
1487 // The file is obtained from the cache. | |
1488 // Hence the downloading should work even if the drive service is offline. | |
1489 fake_drive_service_->set_offline(true); | |
1490 | |
1491 std::string resource_id = entry->resource_id(); | |
1492 base::FilePath file_path; | |
1493 entry.reset(); | |
1494 file_system_->GetFileByResourceId( | |
1495 resource_id, | |
1496 ClientContext(USER_INITIATED), | |
1497 google_apis::test_util::CreateCopyResultCallback( | |
1498 &error, &file_path, &entry), | |
1499 google_apis::GetContentCallback()); | |
1500 google_apis::test_util::RunBlockingPoolTask(); | |
1501 | |
1502 EXPECT_EQ(FILE_ERROR_OK, error); | |
1503 ASSERT_TRUE(entry); | |
1504 EXPECT_FALSE(entry->file_specific_info().is_hosted_document()); | |
1505 } | |
1506 | |
1507 TEST_F(FileSystemTest, GetAvailableSpace) { | 1145 TEST_F(FileSystemTest, GetAvailableSpace) { |
1508 FileError error = FILE_ERROR_OK; | 1146 FileError error = FILE_ERROR_OK; |
1509 int64 bytes_total; | 1147 int64 bytes_total; |
1510 int64 bytes_used; | 1148 int64 bytes_used; |
1511 file_system_->GetAvailableSpace( | 1149 file_system_->GetAvailableSpace( |
1512 google_apis::test_util::CreateCopyResultCallback( | 1150 google_apis::test_util::CreateCopyResultCallback( |
1513 &error, &bytes_total, &bytes_used)); | 1151 &error, &bytes_total, &bytes_used)); |
1514 google_apis::test_util::RunBlockingPoolTask(); | 1152 google_apis::test_util::RunBlockingPoolTask(); |
1515 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used); | 1153 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used); |
1516 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total); | 1154 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1674 entry->resource_id(), | 1312 entry->resource_id(), |
1675 entry->file_specific_info().file_md5(), | 1313 entry->file_specific_info().file_md5(), |
1676 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); | 1314 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); |
1677 google_apis::test_util::RunBlockingPoolTask(); | 1315 google_apis::test_util::RunBlockingPoolTask(); |
1678 | 1316 |
1679 EXPECT_TRUE(success); | 1317 EXPECT_TRUE(success); |
1680 EXPECT_FALSE(cache_entry.is_mounted()); | 1318 EXPECT_FALSE(cache_entry.is_mounted()); |
1681 } | 1319 } |
1682 | 1320 |
1683 } // namespace drive | 1321 } // namespace drive |
OLD | NEW |