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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 16189010: drive: Add DownloadOperationTest (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase & fix a nit Created 7 years, 6 months 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 | Annotate | Revision Log
OLDNEW
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"
15 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
16 #include "base/message_loop.h" 15 #include "base/message_loop.h"
17 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
18 #include "base/threading/sequenced_worker_pool.h" 17 #include "base/threading/sequenced_worker_pool.h"
19 #include "base/values.h" 18 #include "base/values.h"
20 #include "chrome/browser/chromeos/drive/change_list_loader.h" 19 #include "chrome/browser/chromeos/drive/change_list_loader.h"
21 #include "chrome/browser/chromeos/drive/drive.pb.h" 20 #include "chrome/browser/chromeos/drive/drive.pb.h"
22 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 21 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
23 #include "chrome/browser/chromeos/drive/file_system_util.h" 22 #include "chrome/browser/chromeos/drive/file_system_util.h"
24 #include "chrome/browser/chromeos/drive/job_scheduler.h" 23 #include "chrome/browser/chromeos/drive/job_scheduler.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const std::string& md5, 209 const std::string& md5,
211 FileCacheEntry* cache_entry) { 210 FileCacheEntry* cache_entry) {
212 bool result = false; 211 bool result = false;
213 cache_->GetCacheEntryOnUIThread( 212 cache_->GetCacheEntryOnUIThread(
214 resource_id, md5, 213 resource_id, md5,
215 google_apis::test_util::CreateCopyResultCallback(&result, cache_entry)); 214 google_apis::test_util::CreateCopyResultCallback(&result, cache_entry));
216 google_apis::test_util::RunBlockingPoolTask(); 215 google_apis::test_util::RunBlockingPoolTask();
217 return result; 216 return result;
218 } 217 }
219 218
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. 219 // Flag for specifying the timestamp of the test filesystem cache.
228 enum SetUpTestFileSystemParam { 220 enum SetUpTestFileSystemParam {
229 USE_OLD_TIMESTAMP, 221 USE_OLD_TIMESTAMP,
230 USE_SERVER_TIMESTAMP, 222 USE_SERVER_TIMESTAMP,
231 }; 223 };
232 224
233 // Sets up a filesystem with directories: drive/root, drive/root/Dir1, 225 // 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, 226 // 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 227 // 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 228 // the changestamp to 654321, equal to that of "account_metadata.json" test
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 google_apis::test_util::RunBlockingPoolTask(); 333 google_apis::test_util::RunBlockingPoolTask();
342 if (error != FILE_ERROR_OK) 334 if (error != FILE_ERROR_OK)
343 return false; 335 return false;
344 336
345 // Recreate resource metadata. 337 // Recreate resource metadata.
346 SetUpResourceMetadataAndFileSystem(); 338 SetUpResourceMetadataAndFileSystem();
347 339
348 return true; 340 return true;
349 } 341 }
350 342
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_; 343 base::MessageLoopForUI message_loop_;
371 content::TestBrowserThread ui_thread_; 344 content::TestBrowserThread ui_thread_;
372 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_; 345 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
373 scoped_ptr<TestingProfile> profile_; 346 scoped_ptr<TestingProfile> profile_;
374 347
375 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_; 348 scoped_ptr<internal::FileCache, test_util::DestroyHelperForTests> cache_;
376 scoped_ptr<FileSystem> file_system_; 349 scoped_ptr<FileSystem> file_system_;
377 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_; 350 scoped_ptr<google_apis::FakeDriveService> fake_drive_service_;
378 scoped_ptr<JobScheduler> scheduler_; 351 scoped_ptr<JobScheduler> scheduler_;
379 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests> 352 scoped_ptr<internal::ResourceMetadata, test_util::DestroyHelperForTests>
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 remote_src_file_path, 1038 remote_src_file_path,
1066 local_dest_file_path, 1039 local_dest_file_path,
1067 google_apis::test_util::CreateCopyResultCallback(&error)); 1040 google_apis::test_util::CreateCopyResultCallback(&error));
1068 google_apis::test_util::RunBlockingPoolTask(); 1041 google_apis::test_util::RunBlockingPoolTask();
1069 1042
1070 EXPECT_EQ(FILE_ERROR_OK, error); 1043 EXPECT_EQ(FILE_ERROR_OK, error);
1071 1044
1072 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync( 1045 scoped_ptr<ResourceEntry> entry = GetResourceEntryByPathSync(
1073 remote_src_file_path); 1046 remote_src_file_path);
1074 ASSERT_TRUE(entry); 1047 ASSERT_TRUE(entry);
1075 VerifyHostedDocumentJSONFile(*entry, local_dest_file_path); 1048 EXPECT_EQ(GURL(entry->file_specific_info().alternate_url()),
1049 util::ReadUrlFromGDocFile(local_dest_file_path));
1050 EXPECT_EQ(entry->resource_id(),
1051 util::ReadResourceIdFromGDocFile(local_dest_file_path));
1076 } 1052 }
1077 1053
1078 TEST_F(FileSystemTest, CopyNotExistingFile) { 1054 TEST_F(FileSystemTest, CopyNotExistingFile) {
1079 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt")); 1055 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
1080 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); 1056 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1081 1057
1082 ASSERT_TRUE(LoadRootFeedDocument()); 1058 ASSERT_TRUE(LoadRootFeedDocument());
1083 1059
1084 EXPECT_FALSE(EntryExists(src_file_path)); 1060 EXPECT_FALSE(EntryExists(src_file_path));
1085 1061
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1202 error = FILE_ERROR_FAILED; 1178 error = FILE_ERROR_FAILED;
1203 EXPECT_CALL(*mock_cache_observer_, 1179 EXPECT_CALL(*mock_cache_observer_,
1204 OnCacheUnpinned(entry->resource_id(), 1180 OnCacheUnpinned(entry->resource_id(),
1205 entry->file_specific_info().file_md5())).Times(1); 1181 entry->file_specific_info().file_md5())).Times(1);
1206 file_system_->Unpin(file_path, 1182 file_system_->Unpin(file_path,
1207 google_apis::test_util::CreateCopyResultCallback(&error)); 1183 google_apis::test_util::CreateCopyResultCallback(&error));
1208 google_apis::test_util::RunBlockingPoolTask(); 1184 google_apis::test_util::RunBlockingPoolTask();
1209 EXPECT_EQ(FILE_ERROR_OK, error); 1185 EXPECT_EQ(FILE_ERROR_OK, error);
1210 } 1186 }
1211 1187
1212 TEST_F(FileSystemTest, GetFileByPath_FromGData_EnoughSpace) {
1213 ASSERT_TRUE(LoadRootFeedDocument());
1214
1215 // The transfered file is cached and the change of "offline available"
1216 // attribute is notified.
1217 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1218 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1219
1220 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1221 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1222 const int64 file_size = entry->file_info().size();
1223
1224 // Pretend we have enough space.
1225 fake_free_disk_space_getter_->set_fake_free_disk_space(
1226 file_size + internal::kMinFreeSpace);
1227
1228 FileError error = FILE_ERROR_FAILED;
1229 base::FilePath file_path;
1230 entry.reset();
1231 file_system_->GetFileByPath(file_in_root,
1232 google_apis::test_util::CreateCopyResultCallback(
1233 &error, &file_path, &entry));
1234 google_apis::test_util::RunBlockingPoolTask();
1235
1236 EXPECT_EQ(FILE_ERROR_OK, error);
1237 ASSERT_TRUE(entry);
1238 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1239
1240 // Verify that readable permission is set.
1241 int permission = 0;
1242 EXPECT_TRUE(file_util::GetPosixFilePermissions(file_path, &permission));
1243 EXPECT_EQ(file_util::FILE_PERMISSION_READ_BY_USER |
1244 file_util::FILE_PERMISSION_WRITE_BY_USER |
1245 file_util::FILE_PERMISSION_READ_BY_GROUP |
1246 file_util::FILE_PERMISSION_READ_BY_OTHERS, permission);
1247 }
1248
1249 TEST_F(FileSystemTest, GetFileByPath_FromGData_NoSpaceAtAll) {
1250 ASSERT_TRUE(LoadRootFeedDocument());
1251
1252 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1253
1254 // Pretend we have no space at all.
1255 fake_free_disk_space_getter_->set_fake_free_disk_space(0);
1256
1257 FileError error = FILE_ERROR_OK;
1258 base::FilePath file_path;
1259 scoped_ptr<ResourceEntry> entry;
1260 file_system_->GetFileByPath(file_in_root,
1261 google_apis::test_util::CreateCopyResultCallback(
1262 &error, &file_path, &entry));
1263 google_apis::test_util::RunBlockingPoolTask();
1264
1265 EXPECT_EQ(FILE_ERROR_NO_SPACE, error);
1266 }
1267
1268 TEST_F(FileSystemTest, GetFileByPath_FromGData_NoEnoughSpaceButCanFreeUp) {
1269 ASSERT_TRUE(LoadRootFeedDocument());
1270
1271 // The transfered file is cached and the change of "offline available"
1272 // attribute is notified.
1273 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1274 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1275
1276 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1277 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1278 const int64 file_size = entry->file_info().size();
1279
1280 // Pretend we have no space first (checked before downloading a file),
1281 // but then start reporting we have space. This is to emulate that
1282 // the disk space was freed up by removing temporary files.
1283 fake_free_disk_space_getter_->set_fake_free_disk_space(
1284 file_size + internal::kMinFreeSpace);
1285 fake_free_disk_space_getter_->set_fake_free_disk_space(0);
1286 fake_free_disk_space_getter_->set_fake_free_disk_space(
1287 file_size + internal::kMinFreeSpace);
1288 fake_free_disk_space_getter_->set_fake_free_disk_space(
1289 file_size + internal::kMinFreeSpace);
1290
1291 // Store something of the file size in the temporary cache directory.
1292 const std::string content(file_size, 'x');
1293 base::ScopedTempDir temp_dir;
1294 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1295 const base::FilePath tmp_file =
1296 temp_dir.path().AppendASCII("something.txt");
1297 ASSERT_TRUE(google_apis::test_util::WriteStringToFile(tmp_file, content));
1298
1299 FileError error = FILE_ERROR_FAILED;
1300 cache_->StoreOnUIThread(
1301 "<resource_id>", "<md5>", tmp_file,
1302 internal::FileCache::FILE_OPERATION_COPY,
1303 google_apis::test_util::CreateCopyResultCallback(&error));
1304 google_apis::test_util::RunBlockingPoolTask();
1305 EXPECT_EQ(FILE_ERROR_OK, error);
1306 ASSERT_TRUE(CacheEntryExists("<resource_id>", "<md5>"));
1307
1308 base::FilePath file_path;
1309 entry.reset();
1310 file_system_->GetFileByPath(file_in_root,
1311 google_apis::test_util::CreateCopyResultCallback(
1312 &error, &file_path, &entry));
1313 google_apis::test_util::RunBlockingPoolTask();
1314
1315 EXPECT_EQ(FILE_ERROR_OK, error);
1316 ASSERT_TRUE(entry);
1317 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1318
1319 // The cache entry should be removed in order to free up space.
1320 ASSERT_FALSE(CacheEntryExists("<resource_id>", "<md5>"));
1321 }
1322
1323 TEST_F(FileSystemTest, GetFileByPath_FromGData_EnoughSpaceButBecomeFull) {
1324 ASSERT_TRUE(LoadRootFeedDocument());
1325
1326 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1327 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1328 const int64 file_size = entry->file_info().size();
1329
1330 // Pretend we have enough space first (checked before downloading a file),
1331 // but then start reporting we have not enough space. This is to emulate that
1332 // the disk space becomes full after the file is downloaded for some reason
1333 // (ex. the actual file was larger than the expected size).
1334 fake_free_disk_space_getter_->set_fake_free_disk_space(
1335 file_size + internal::kMinFreeSpace);
1336 fake_free_disk_space_getter_->set_fake_free_disk_space(
1337 internal::kMinFreeSpace - 1);
1338 fake_free_disk_space_getter_->set_fake_free_disk_space(
1339 internal::kMinFreeSpace - 1);
1340
1341 FileError error = FILE_ERROR_OK;
1342 base::FilePath file_path;
1343 entry.reset();
1344 file_system_->GetFileByPath(file_in_root,
1345 google_apis::test_util::CreateCopyResultCallback(
1346 &error, &file_path, &entry));
1347 google_apis::test_util::RunBlockingPoolTask();
1348
1349 EXPECT_EQ(FILE_ERROR_NO_SPACE, error);
1350 }
1351
1352 TEST_F(FileSystemTest, GetFileByPath_FromCache) {
1353 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1354
1355 ASSERT_TRUE(LoadRootFeedDocument());
1356
1357 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1358 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1359
1360 // Store something as cached version of this file.
1361 FileError error = FILE_ERROR_OK;
1362 cache_->StoreOnUIThread(
1363 entry->resource_id(),
1364 entry->file_specific_info().file_md5(),
1365 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
1366 internal::FileCache::FILE_OPERATION_COPY,
1367 google_apis::test_util::CreateCopyResultCallback(&error));
1368 google_apis::test_util::RunBlockingPoolTask();
1369 EXPECT_EQ(FILE_ERROR_OK, error);
1370
1371 base::FilePath file_path;
1372 entry.reset();
1373 file_system_->GetFileByPath(file_in_root,
1374 google_apis::test_util::CreateCopyResultCallback(
1375 &error, &file_path, &entry));
1376 google_apis::test_util::RunBlockingPoolTask();
1377
1378 EXPECT_EQ(FILE_ERROR_OK, error);
1379 ASSERT_TRUE(entry);
1380 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1381 }
1382
1383 TEST_F(FileSystemTest, GetFileByPath_HostedDocument) {
1384 ASSERT_TRUE(LoadRootFeedDocument());
1385
1386 base::FilePath file_in_root(FILE_PATH_LITERAL(
1387 "drive/root/Document 1 excludeDir-test.gdoc"));
1388 scoped_ptr<ResourceEntry> src_entry =
1389 GetResourceEntryByPathSync(file_in_root);
1390 ASSERT_TRUE(src_entry);
1391
1392 FileError error = FILE_ERROR_FAILED;
1393 base::FilePath file_path;
1394 scoped_ptr<ResourceEntry> entry;
1395 file_system_->GetFileByPath(file_in_root,
1396 google_apis::test_util::CreateCopyResultCallback(
1397 &error, &file_path, &entry));
1398 google_apis::test_util::RunBlockingPoolTask();
1399
1400 EXPECT_EQ(FILE_ERROR_OK, error);
1401 ASSERT_TRUE(entry);
1402 EXPECT_TRUE(entry->file_specific_info().is_hosted_document());
1403 EXPECT_FALSE(file_path.empty());
1404
1405 ASSERT_TRUE(src_entry);
1406 VerifyHostedDocumentJSONFile(*src_entry, file_path);
1407 }
1408
1409 TEST_F(FileSystemTest, GetFileByResourceId) {
1410 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1411
1412 // The transfered file is cached and the change of "offline available"
1413 // attribute is notified.
1414 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1415 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1416
1417 ASSERT_TRUE(LoadRootFeedDocument());
1418
1419 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1420 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1421 std::string resource_id = entry->resource_id();
1422
1423 FileError error = FILE_ERROR_OK;
1424 base::FilePath file_path;
1425 entry.reset();
1426 file_system_->GetFileByResourceId(
1427 resource_id,
1428 ClientContext(USER_INITIATED),
1429 google_apis::test_util::CreateCopyResultCallback(
1430 &error, &file_path, &entry),
1431 google_apis::GetContentCallback());
1432 google_apis::test_util::RunBlockingPoolTask();
1433
1434 EXPECT_EQ(FILE_ERROR_OK, error);
1435 ASSERT_TRUE(entry);
1436 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1437 }
1438
1439 TEST_F(FileSystemTest, GetFileContentByPath) {
1440 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1441
1442 // The transfered file is cached and the change of "offline available"
1443 // attribute is notified.
1444 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1445 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1446
1447 ASSERT_TRUE(LoadRootFeedDocument());
1448
1449 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1450
1451 {
1452 FileError initialized_error = FILE_ERROR_FAILED;
1453 scoped_ptr<ResourceEntry> entry;
1454 base::FilePath local_path;
1455 base::Closure cancel_download;
1456 google_apis::test_util::TestGetContentCallback get_content_callback;
1457
1458 FileError completion_error = FILE_ERROR_FAILED;
1459
1460 file_system_->GetFileContentByPath(
1461 file_in_root,
1462 google_apis::test_util::CreateCopyResultCallback(
1463 &initialized_error, &entry, &local_path, &cancel_download),
1464 get_content_callback.callback(),
1465 google_apis::test_util::CreateCopyResultCallback(&completion_error));
1466 google_apis::test_util::RunBlockingPoolTask();
1467
1468 // For the first time, file is downloaded from the remote server.
1469 // In this case, |local_path| is empty while |cancel_download| is not.
1470 EXPECT_EQ(FILE_ERROR_OK, initialized_error);
1471 ASSERT_TRUE(entry);
1472 ASSERT_TRUE(local_path.empty());
1473 EXPECT_TRUE(!cancel_download.is_null());
1474 // Content is available through the second callback argument.
1475 EXPECT_EQ(static_cast<size_t>(entry->file_info().size()),
1476 get_content_callback.GetConcatenatedData().size());
1477 EXPECT_EQ(FILE_ERROR_OK, completion_error);
1478 }
1479
1480 {
1481 FileError initialized_error = FILE_ERROR_FAILED;
1482 scoped_ptr<ResourceEntry> entry;
1483 base::FilePath local_path;
1484 base::Closure cancel_download;
1485 google_apis::test_util::TestGetContentCallback get_content_callback;
1486
1487 FileError completion_error = FILE_ERROR_FAILED;
1488
1489 file_system_->GetFileContentByPath(
1490 file_in_root,
1491 google_apis::test_util::CreateCopyResultCallback(
1492 &initialized_error, &entry, &local_path, &cancel_download),
1493 get_content_callback.callback(),
1494 google_apis::test_util::CreateCopyResultCallback(&completion_error));
1495 google_apis::test_util::RunBlockingPoolTask();
1496
1497 // Try second download. In this case, the file should be cached, so
1498 // |local_path| should not be empty while |cancel_download| is empty.
1499 EXPECT_EQ(FILE_ERROR_OK, initialized_error);
1500 ASSERT_TRUE(entry);
1501 ASSERT_TRUE(!local_path.empty());
1502 EXPECT_TRUE(cancel_download.is_null());
1503 // The content is available from the cache file.
1504 EXPECT_TRUE(get_content_callback.data().empty());
1505 int64 local_file_size = 0;
1506 file_util::GetFileSize(local_path, &local_file_size);
1507 EXPECT_EQ(entry->file_info().size(), local_file_size);
1508 EXPECT_EQ(FILE_ERROR_OK, completion_error);
1509 }
1510 }
1511
1512 TEST_F(FileSystemTest, GetFileByResourceId_FromCache) {
1513 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1514
1515 ASSERT_TRUE(LoadRootFeedDocument());
1516
1517 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1518 scoped_ptr<ResourceEntry> entry(GetResourceEntryByPathSync(file_in_root));
1519
1520 // Store something as cached version of this file.
1521 FileError error = FILE_ERROR_FAILED;
1522 cache_->StoreOnUIThread(
1523 entry->resource_id(),
1524 entry->file_specific_info().file_md5(),
1525 google_apis::test_util::GetTestFilePath("chromeos/gdata/root_feed.json"),
1526 internal::FileCache::FILE_OPERATION_COPY,
1527 google_apis::test_util::CreateCopyResultCallback(&error));
1528 google_apis::test_util::RunBlockingPoolTask();
1529 EXPECT_EQ(FILE_ERROR_OK, error);
1530
1531 // The file is obtained from the cache.
1532 // Hence the downloading should work even if the drive service is offline.
1533 fake_drive_service_->set_offline(true);
1534
1535 std::string resource_id = entry->resource_id();
1536 base::FilePath file_path;
1537 entry.reset();
1538 file_system_->GetFileByResourceId(
1539 resource_id,
1540 ClientContext(USER_INITIATED),
1541 google_apis::test_util::CreateCopyResultCallback(
1542 &error, &file_path, &entry),
1543 google_apis::GetContentCallback());
1544 google_apis::test_util::RunBlockingPoolTask();
1545
1546 EXPECT_EQ(FILE_ERROR_OK, error);
1547 ASSERT_TRUE(entry);
1548 EXPECT_FALSE(entry->file_specific_info().is_hosted_document());
1549 }
1550
1551 TEST_F(FileSystemTest, GetAvailableSpace) { 1188 TEST_F(FileSystemTest, GetAvailableSpace) {
1552 FileError error = FILE_ERROR_OK; 1189 FileError error = FILE_ERROR_OK;
1553 int64 bytes_total; 1190 int64 bytes_total;
1554 int64 bytes_used; 1191 int64 bytes_used;
1555 file_system_->GetAvailableSpace( 1192 file_system_->GetAvailableSpace(
1556 google_apis::test_util::CreateCopyResultCallback( 1193 google_apis::test_util::CreateCopyResultCallback(
1557 &error, &bytes_total, &bytes_used)); 1194 &error, &bytes_total, &bytes_used));
1558 google_apis::test_util::RunBlockingPoolTask(); 1195 google_apis::test_util::RunBlockingPoolTask();
1559 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used); 1196 EXPECT_EQ(GG_LONGLONG(6789012345), bytes_used);
1560 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total); 1197 EXPECT_EQ(GG_LONGLONG(9876543210), bytes_total);
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 entry->resource_id(), 1355 entry->resource_id(),
1719 entry->file_specific_info().file_md5(), 1356 entry->file_specific_info().file_md5(),
1720 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); 1357 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry));
1721 google_apis::test_util::RunBlockingPoolTask(); 1358 google_apis::test_util::RunBlockingPoolTask();
1722 1359
1723 EXPECT_TRUE(success); 1360 EXPECT_TRUE(success);
1724 EXPECT_FALSE(cache_entry.is_mounted()); 1361 EXPECT_FALSE(cache_entry.is_mounted());
1725 } 1362 }
1726 1363
1727 } // namespace drive 1364 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/operation_test_base.h ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698