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

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

Issue 11820020: Removed few methods from CallbackHelper in drive_file_system_unittest.cc (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove GetEntryInfoCallback method Created 7 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/drive_file_system.h" 5 #include "chrome/browser/chromeos/drive/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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 const std::string& md5) { 351 const std::string& md5) {
352 return cache_->GetCacheFilePath(resource_id, 352 return cache_->GetCacheFilePath(resource_id,
353 md5, 353 md5,
354 DriveCache::CACHE_TYPE_TMP, 354 DriveCache::CACHE_TYPE_TMP,
355 DriveCache::CACHED_FILE_FROM_SERVER); 355 DriveCache::CACHED_FILE_FROM_SERVER);
356 } 356 }
357 357
358 // Gets entry info by path synchronously. 358 // Gets entry info by path synchronously.
359 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync( 359 scoped_ptr<DriveEntryProto> GetEntryInfoByPathSync(
360 const FilePath& file_path) { 360 const FilePath& file_path) {
361 DriveFileError error;
362 scoped_ptr<DriveEntryProto> entry_proto;
361 file_system_->GetEntryInfoByPath( 363 file_system_->GetEntryInfoByPath(
362 file_path, 364 file_path,
363 base::Bind(&CallbackHelper::GetEntryInfoCallback, 365 base::Bind(&test_util::CopyResultsFromGetEntryInfoCallback,
364 callback_helper_.get())); 366 &error, &entry_proto));
365 google_apis::test_util::RunBlockingPoolTask(); 367 google_apis::test_util::RunBlockingPoolTask();
366 368
367 return callback_helper_->entry_proto_.Pass(); 369 return entry_proto.Pass();
368 } 370 }
369 371
370 // Gets directory info by path synchronously. 372 // Gets directory info by path synchronously.
371 scoped_ptr<DriveEntryProtoVector> ReadDirectoryByPathSync( 373 scoped_ptr<DriveEntryProtoVector> ReadDirectoryByPathSync(
372 const FilePath& file_path) { 374 const FilePath& file_path) {
373 file_system_->ReadDirectoryByPath( 375 file_system_->ReadDirectoryByPath(
374 file_path, 376 file_path,
375 base::Bind(&CallbackHelper::ReadDirectoryCallback, 377 base::Bind(&CallbackHelper::ReadDirectoryCallback,
376 callback_helper_.get())); 378 callback_helper_.get()));
377 google_apis::test_util::RunBlockingPoolTask(); 379 google_apis::test_util::RunBlockingPoolTask();
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 virtual void GetFileCallback(DriveFileError error, 753 virtual void GetFileCallback(DriveFileError error,
752 const FilePath& file_path, 754 const FilePath& file_path,
753 const std::string& mime_type, 755 const std::string& mime_type,
754 DriveFileType file_type) { 756 DriveFileType file_type) {
755 last_error_ = error; 757 last_error_ = error;
756 download_path_ = file_path; 758 download_path_ = file_path;
757 mime_type_ = mime_type; 759 mime_type_ = mime_type;
758 file_type_ = file_type; 760 file_type_ = file_type;
759 } 761 }
760 762
761 virtual void FileOperationCallback(DriveFileError error) {
762 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
763
764 last_error_ = error;
765 }
766
767 virtual void GetAvailableSpaceCallback(DriveFileError error, 763 virtual void GetAvailableSpaceCallback(DriveFileError error,
768 int64 bytes_total, 764 int64 bytes_total,
769 int64 bytes_used) { 765 int64 bytes_used) {
770 last_error_ = error; 766 last_error_ = error;
771 quota_bytes_total_ = bytes_total; 767 quota_bytes_total_ = bytes_total;
772 quota_bytes_used_ = bytes_used; 768 quota_bytes_used_ = bytes_used;
773 } 769 }
774 770
775 virtual void OpenFileCallback(DriveFileError error, 771 virtual void OpenFileCallback(DriveFileError error,
776 const FilePath& file_path) { 772 const FilePath& file_path) {
777 last_error_ = error; 773 last_error_ = error;
778 opened_file_path_ = file_path; 774 opened_file_path_ = file_path;
779 MessageLoop::current()->Quit(); 775 MessageLoop::current()->Quit();
780 } 776 }
781 777
782 virtual void CloseFileCallback(DriveFileError error) { 778 virtual void CloseFileCallback(DriveFileError error) {
783 last_error_ = error; 779 last_error_ = error;
784 MessageLoop::current()->Quit(); 780 MessageLoop::current()->Quit();
785 } 781 }
786 782
787 virtual void GetEntryInfoCallback(
788 DriveFileError error,
789 scoped_ptr<DriveEntryProto> entry_proto) {
790 last_error_ = error;
791 entry_proto_ = entry_proto.Pass();
792 }
793
794 virtual void ReadDirectoryCallback( 783 virtual void ReadDirectoryCallback(
795 DriveFileError error, 784 DriveFileError error,
796 bool /* hide_hosted_documents */, 785 bool /* hide_hosted_documents */,
797 scoped_ptr<DriveEntryProtoVector> entries) { 786 scoped_ptr<DriveEntryProtoVector> entries) {
798 last_error_ = error; 787 last_error_ = error;
799 directory_entries_ = entries.Pass(); 788 directory_entries_ = entries.Pass();
800 } 789 }
801 790
802 DriveFileError last_error_; 791 DriveFileError last_error_;
803 FilePath download_path_; 792 FilePath download_path_;
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 1251
1263 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { 1252 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_RegularFile) {
1264 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace); 1253 fake_free_disk_space_getter_->set_fake_free_disk_space(kLotsOfSpace);
1265 1254
1266 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1255 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1267 1256
1268 // We'll add a file to the Drive root directory. 1257 // We'll add a file to the Drive root directory.
1269 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1258 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1270 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1259 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1271 1260
1272 FileOperationCallback callback =
1273 base::Bind(&CallbackHelper::FileOperationCallback,
1274 callback_helper_.get());
1275
1276 // Prepare a local file. 1261 // Prepare a local file.
1277 base::ScopedTempDir temp_dir; 1262 base::ScopedTempDir temp_dir;
1278 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1263 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1279 const FilePath local_src_file_path = temp_dir.path().Append("local.txt"); 1264 const FilePath local_src_file_path = temp_dir.path().Append("local.txt");
1280 const std::string kContent = "hello"; 1265 const std::string kContent = "hello";
1281 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size()); 1266 file_util::WriteFile(local_src_file_path, kContent.data(), kContent.size());
1282 1267
1283 // Confirm that the remote file does not exist. 1268 // Confirm that the remote file does not exist.
1284 const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt")); 1269 const FilePath remote_dest_file_path(FILE_PATH_LITERAL("drive/remote.txt"));
1285 EXPECT_FALSE(EntryExists(remote_dest_file_path)); 1270 EXPECT_FALSE(EntryExists(remote_dest_file_path));
1286 1271
1287 scoped_ptr<base::Value> value = 1272 scoped_ptr<base::Value> value =
1288 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json"); 1273 google_apis::test_util::LoadJSONFile("gdata/document_to_download.json");
1289 scoped_ptr<google_apis::ResourceEntry> resource_entry( 1274 scoped_ptr<google_apis::ResourceEntry> resource_entry(
1290 google_apis::ResourceEntry::ExtractAndParse(*value)); 1275 google_apis::ResourceEntry::ExtractAndParse(*value));
1291 1276
1292 // Transfer the local file to Drive. 1277 // Transfer the local file to Drive.
1278 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1293 file_system_->TransferFileFromLocalToRemote( 1279 file_system_->TransferFileFromLocalToRemote(
1294 local_src_file_path, remote_dest_file_path, callback); 1280 local_src_file_path,
1281 remote_dest_file_path,
1282 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1295 google_apis::test_util::RunBlockingPoolTask(); 1283 google_apis::test_util::RunBlockingPoolTask();
1296 1284
1297 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1285 EXPECT_EQ(DRIVE_FILE_OK, error);
1298 1286
1299 // Now the remote file should exist. 1287 // Now the remote file should exist.
1300 EXPECT_TRUE(EntryExists(remote_dest_file_path)); 1288 EXPECT_TRUE(EntryExists(remote_dest_file_path));
1301 } 1289 }
1302 1290
1303 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) { 1291 TEST_F(DriveFileSystemTest, TransferFileFromLocalToRemote_HostedDocument) {
1304 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1292 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1305 1293
1306 // Prepare a local file, which is a json file of a hosted document, which 1294 // Prepare a local file, which is a json file of a hosted document, which
1307 // matches "Document 1" in root_feed.json. 1295 // matches "Document 1" in root_feed.json.
(...skipping 26 matching lines...) Expand all
1334 EXPECT_CALL(*mock_drive_service_, 1322 EXPECT_CALL(*mock_drive_service_,
1335 CopyHostedDocument(kResourceId, 1323 CopyHostedDocument(kResourceId,
1336 FILE_PATH_LITERAL("Document 1"), 1324 FILE_PATH_LITERAL("Document 1"),
1337 _)) 1325 _))
1338 .WillOnce(MockCopyHostedDocument(google_apis::HTTP_SUCCESS, 1326 .WillOnce(MockCopyHostedDocument(google_apis::HTTP_SUCCESS,
1339 &resource_entry)); 1327 &resource_entry));
1340 // We'll then add the hosted document to the destination directory. 1328 // We'll then add the hosted document to the destination directory.
1341 EXPECT_CALL(*mock_drive_service_, 1329 EXPECT_CALL(*mock_drive_service_,
1342 AddResourceToDirectory(_, _, _)).Times(1); 1330 AddResourceToDirectory(_, _, _)).Times(1);
1343 1331
1344 FileOperationCallback callback =
1345 base::Bind(&CallbackHelper::FileOperationCallback,
1346 callback_helper_.get());
1347 1332
1348 // Transfer the local file to Drive. 1333 // Transfer the local file to Drive.
1334 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1349 file_system_->TransferFileFromLocalToRemote( 1335 file_system_->TransferFileFromLocalToRemote(
1350 local_src_file_path, remote_dest_file_path, callback); 1336 local_src_file_path,
1337 remote_dest_file_path,
1338 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1351 google_apis::test_util::RunBlockingPoolTask(); 1339 google_apis::test_util::RunBlockingPoolTask();
1352 1340
1353 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1341 EXPECT_EQ(DRIVE_FILE_OK, error);
1354 1342
1355 // Now the remote file should exist. 1343 // Now the remote file should exist.
1356 EXPECT_TRUE(EntryExists(remote_dest_file_path)); 1344 EXPECT_TRUE(EntryExists(remote_dest_file_path));
1357 } 1345 }
1358 1346
1359 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) { 1347 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_RegularFile) {
1360 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1348 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1361 1349
1362 FileOperationCallback callback =
1363 base::Bind(&CallbackHelper::FileOperationCallback,
1364 callback_helper_.get());
1365
1366 base::ScopedTempDir temp_dir; 1350 base::ScopedTempDir temp_dir;
1367 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1351 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1368 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); 1352 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt");
1369 1353
1370 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1354 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/File 1.txt"));
1371 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync( 1355 scoped_ptr<DriveEntryProto> file = GetEntryInfoByPathSync(
1372 remote_src_file_path); 1356 remote_src_file_path);
1373 FilePath cache_file = GetCachePathForFile( 1357 FilePath cache_file = GetCachePathForFile(
1374 file->resource_id(), 1358 file->resource_id(),
1375 file->file_specific_info().file_md5()); 1359 file->file_specific_info().file_md5());
(...skipping 13 matching lines...) Expand all
1389 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id"); 1373 SetExpectationsForGetResourceEntry(*document, "file:2_file_resource_id");
1390 1374
1391 // The file is obtained with the mock DriveService. 1375 // The file is obtained with the mock DriveService.
1392 EXPECT_CALL(*mock_drive_service_, 1376 EXPECT_CALL(*mock_drive_service_,
1393 DownloadFile(remote_src_file_path, 1377 DownloadFile(remote_src_file_path,
1394 cache_file, 1378 cache_file,
1395 GURL("https://file_content_url_changed/"), 1379 GURL("https://file_content_url_changed/"),
1396 _, _)) 1380 _, _))
1397 .Times(1); 1381 .Times(1);
1398 1382
1383 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1399 file_system_->TransferFileFromRemoteToLocal( 1384 file_system_->TransferFileFromRemoteToLocal(
1400 remote_src_file_path, local_dest_file_path, callback); 1385 remote_src_file_path,
1386 local_dest_file_path,
1387 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1401 google_apis::test_util::RunBlockingPoolTask(); 1388 google_apis::test_util::RunBlockingPoolTask();
1402 1389
1403 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1390 EXPECT_EQ(DRIVE_FILE_OK, error);
1404 1391
1405 std::string cache_file_data; 1392 std::string cache_file_data;
1406 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data)); 1393 EXPECT_TRUE(file_util::ReadFileToString(cache_file, &cache_file_data));
1407 EXPECT_EQ(remote_src_file_data, cache_file_data); 1394 EXPECT_EQ(remote_src_file_data, cache_file_data);
1408 1395
1409 std::string local_dest_file_data; 1396 std::string local_dest_file_data;
1410 EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path, 1397 EXPECT_TRUE(file_util::ReadFileToString(local_dest_file_path,
1411 &local_dest_file_data)); 1398 &local_dest_file_data));
1412 EXPECT_EQ(remote_src_file_data, local_dest_file_data); 1399 EXPECT_EQ(remote_src_file_data, local_dest_file_data);
1413 } 1400 }
1414 1401
1415 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) { 1402 TEST_F(DriveFileSystemTest, TransferFileFromRemoteToLocal_HostedDocument) {
1416 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1403 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1417 1404
1418 FileOperationCallback callback =
1419 base::Bind(&CallbackHelper::FileOperationCallback,
1420 callback_helper_.get());
1421
1422 base::ScopedTempDir temp_dir; 1405 base::ScopedTempDir temp_dir;
1423 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 1406 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1424 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt"); 1407 FilePath local_dest_file_path = temp_dir.path().Append("local_copy.txt");
1425 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); 1408 FilePath remote_src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc"));
1409 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1426 file_system_->TransferFileFromRemoteToLocal( 1410 file_system_->TransferFileFromRemoteToLocal(
1427 remote_src_file_path, local_dest_file_path, callback); 1411 remote_src_file_path,
1412 local_dest_file_path,
1413 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1428 google_apis::test_util::RunBlockingPoolTask(); 1414 google_apis::test_util::RunBlockingPoolTask();
1429 1415
1430 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1416 EXPECT_EQ(DRIVE_FILE_OK, error);
1431 1417
1432 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync( 1418 scoped_ptr<DriveEntryProto> entry_proto = GetEntryInfoByPathSync(
1433 remote_src_file_path); 1419 remote_src_file_path);
1434 ASSERT_TRUE(entry_proto.get()); 1420 ASSERT_TRUE(entry_proto.get());
1435 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path); 1421 VerifyHostedDocumentJSONFile(*entry_proto, local_dest_file_path);
1436 } 1422 }
1437 1423
1438 TEST_F(DriveFileSystemTest, CopyNotExistingFile) { 1424 TEST_F(DriveFileSystemTest, CopyNotExistingFile) {
1439 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); 1425 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt"));
1440 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); 1426 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log"));
1441 1427
1442 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1428 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1443 1429
1444 EXPECT_FALSE(EntryExists(src_file_path)); 1430 EXPECT_FALSE(EntryExists(src_file_path));
1445 1431
1446 FileOperationCallback callback = 1432 DriveFileError error = DRIVE_FILE_OK;
1447 base::Bind(&CallbackHelper::FileOperationCallback, 1433 file_system_->Copy(
1448 callback_helper_.get()); 1434 src_file_path,
1449 1435 dest_file_path,
1450 file_system_->Copy(src_file_path, dest_file_path, callback); 1436 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1451 google_apis::test_util::RunBlockingPoolTask(); 1437 google_apis::test_util::RunBlockingPoolTask();
1452 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 1438 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1453 1439
1454 EXPECT_FALSE(EntryExists(src_file_path)); 1440 EXPECT_FALSE(EntryExists(src_file_path));
1455 EXPECT_FALSE(EntryExists(dest_file_path)); 1441 EXPECT_FALSE(EntryExists(dest_file_path));
1456 } 1442 }
1457 1443
1458 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) { 1444 TEST_F(DriveFileSystemTest, CopyFileToNonExistingDirectory) {
1459 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1445 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt"));
1460 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); 1446 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy"));
1461 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); 1447 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log"));
1462 1448
1463 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1449 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1464 1450
1465 ASSERT_TRUE(EntryExists(src_file_path)); 1451 ASSERT_TRUE(EntryExists(src_file_path));
1466 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1452 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1467 src_file_path); 1453 src_file_path);
1468 ASSERT_TRUE(src_entry_proto.get()); 1454 ASSERT_TRUE(src_entry_proto.get());
1469 std::string src_file_path_resource_id = 1455 std::string src_file_path_resource_id =
1470 src_entry_proto->resource_id(); 1456 src_entry_proto->resource_id();
1471 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1457 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1472 1458
1473 EXPECT_FALSE(EntryExists(dest_parent_path)); 1459 EXPECT_FALSE(EntryExists(dest_parent_path));
1474 1460
1475 FileOperationCallback callback = 1461 DriveFileError error = DRIVE_FILE_OK;
1476 base::Bind(&CallbackHelper::FileOperationCallback, 1462 file_system_->Move(
1477 callback_helper_.get()); 1463 src_file_path,
1464 dest_file_path,
1465 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1478 1466
1479 file_system_->Move(src_file_path, dest_file_path, callback);
1480 google_apis::test_util::RunBlockingPoolTask(); 1467 google_apis::test_util::RunBlockingPoolTask();
1481 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 1468 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1482 1469
1483 EXPECT_TRUE(EntryExists(src_file_path)); 1470 EXPECT_TRUE(EntryExists(src_file_path));
1484 EXPECT_FALSE(EntryExists(dest_parent_path)); 1471 EXPECT_FALSE(EntryExists(dest_parent_path));
1485 EXPECT_FALSE(EntryExists(dest_file_path)); 1472 EXPECT_FALSE(EntryExists(dest_file_path));
1486 } 1473 }
1487 1474
1488 // Test the case where the parent of |dest_file_path| is an existing file, 1475 // Test the case where the parent of |dest_file_path| is an existing file,
1489 // not a directory. 1476 // not a directory.
1490 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) { 1477 TEST_F(DriveFileSystemTest, CopyFileToInvalidPath) {
1491 FilePath src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc")); 1478 FilePath src_file_path(FILE_PATH_LITERAL("drive/Document 1.gdoc"));
1492 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Duplicate Name.txt")); 1479 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Duplicate Name.txt"));
1493 FilePath dest_file_path(FILE_PATH_LITERAL( 1480 FilePath dest_file_path(FILE_PATH_LITERAL(
1494 "drive/Duplicate Name.txt/Document 1.gdoc")); 1481 "drive/Duplicate Name.txt/Document 1.gdoc"));
1495 1482
1496 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1483 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1497 1484
1498 ASSERT_TRUE(EntryExists(src_file_path)); 1485 ASSERT_TRUE(EntryExists(src_file_path));
1499 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1486 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1500 src_file_path); 1487 src_file_path);
1501 ASSERT_TRUE(src_entry_proto.get()); 1488 ASSERT_TRUE(src_entry_proto.get());
1502 std::string src_file_resource_id = 1489 std::string src_file_resource_id =
1503 src_entry_proto->resource_id(); 1490 src_entry_proto->resource_id();
1504 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1491 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1505 1492
1506 ASSERT_TRUE(EntryExists(dest_parent_path)); 1493 ASSERT_TRUE(EntryExists(dest_parent_path));
1507 scoped_ptr<DriveEntryProto> dest_entry_proto = GetEntryInfoByPathSync( 1494 scoped_ptr<DriveEntryProto> dest_entry_proto = GetEntryInfoByPathSync(
1508 dest_parent_path); 1495 dest_parent_path);
1509 ASSERT_TRUE(dest_entry_proto.get()); 1496 ASSERT_TRUE(dest_entry_proto.get());
1510 1497
1511 FileOperationCallback callback = 1498 DriveFileError error = DRIVE_FILE_OK;
1512 base::Bind(&CallbackHelper::FileOperationCallback, 1499 file_system_->Copy(
1513 callback_helper_.get()); 1500 src_file_path,
1514 1501 dest_file_path,
1515 file_system_->Copy(src_file_path, dest_file_path, callback); 1502 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1516 google_apis::test_util::RunBlockingPoolTask(); 1503 google_apis::test_util::RunBlockingPoolTask();
1517 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, 1504 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error);
1518 callback_helper_->last_error_);
1519 1505
1520 EXPECT_TRUE(EntryExists(src_file_path)); 1506 EXPECT_TRUE(EntryExists(src_file_path));
1521 EXPECT_TRUE(EntryExists(src_file_path)); 1507 EXPECT_TRUE(EntryExists(src_file_path));
1522 EXPECT_TRUE(EntryExists(dest_parent_path)); 1508 EXPECT_TRUE(EntryExists(dest_parent_path));
1523 1509
1524 EXPECT_FALSE(EntryExists(dest_file_path)); 1510 EXPECT_FALSE(EntryExists(dest_file_path));
1525 } 1511 }
1526 1512
1527 TEST_F(DriveFileSystemTest, RenameFile) { 1513 TEST_F(DriveFileSystemTest, RenameFile) {
1528 const FilePath src_file_path( 1514 const FilePath src_file_path(
1529 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1515 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt"));
1530 const FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1516 const FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1"));
1531 const FilePath dest_file_path( 1517 const FilePath dest_file_path(
1532 FILE_PATH_LITERAL("drive/Directory 1/Test.log")); 1518 FILE_PATH_LITERAL("drive/Directory 1/Test.log"));
1533 1519
1534 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1520 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1535 1521
1536 ASSERT_TRUE(EntryExists(src_file_path)); 1522 ASSERT_TRUE(EntryExists(src_file_path));
1537 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1523 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1538 src_file_path); 1524 src_file_path);
1539 ASSERT_TRUE(src_entry_proto.get()); 1525 ASSERT_TRUE(src_entry_proto.get());
1540 std::string src_file_resource_id = 1526 std::string src_file_resource_id =
1541 src_entry_proto->resource_id(); 1527 src_entry_proto->resource_id();
1542 1528
1543 EXPECT_CALL(*mock_drive_service_, 1529 EXPECT_CALL(*mock_drive_service_,
1544 RenameResource(GURL(src_entry_proto->edit_url()), 1530 RenameResource(GURL(src_entry_proto->edit_url()),
1545 FILE_PATH_LITERAL("Test.log"), _)); 1531 FILE_PATH_LITERAL("Test.log"), _));
1546 1532
1547 FileOperationCallback callback =
1548 base::Bind(&CallbackHelper::FileOperationCallback,
1549 callback_helper_.get());
1550
1551 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1533 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1552 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1534 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1);
1553 1535
1554 file_system_->Move(src_file_path, dest_file_path, callback); 1536 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1537 file_system_->Move(
1538 src_file_path,
1539 dest_file_path,
1540 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1555 google_apis::test_util::RunBlockingPoolTask(); 1541 google_apis::test_util::RunBlockingPoolTask();
1556 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1542 EXPECT_EQ(DRIVE_FILE_OK, error);
1557 1543
1558 EXPECT_FALSE(EntryExists(src_file_path)); 1544 EXPECT_FALSE(EntryExists(src_file_path));
1559 EXPECT_TRUE(EntryExists(dest_file_path)); 1545 EXPECT_TRUE(EntryExists(dest_file_path));
1560 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); 1546 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1561 } 1547 }
1562 1548
1563 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) { 1549 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) {
1564 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1550 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt"));
1565 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1551 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1"));
1566 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Directory 1/Test.log")); 1552 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Directory 1/Test.log"));
(...skipping 16 matching lines...) Expand all
1583 EXPECT_FALSE(dest_parent_proto->content_url().empty()); 1569 EXPECT_FALSE(dest_parent_proto->content_url().empty());
1584 1570
1585 EXPECT_CALL(*mock_drive_service_, 1571 EXPECT_CALL(*mock_drive_service_,
1586 RenameResource(GURL(src_entry_proto->edit_url()), 1572 RenameResource(GURL(src_entry_proto->edit_url()),
1587 FILE_PATH_LITERAL("Test.log"), _)); 1573 FILE_PATH_LITERAL("Test.log"), _));
1588 EXPECT_CALL(*mock_drive_service_, 1574 EXPECT_CALL(*mock_drive_service_,
1589 AddResourceToDirectory( 1575 AddResourceToDirectory(
1590 GURL(dest_parent_proto->content_url()), 1576 GURL(dest_parent_proto->content_url()),
1591 GURL(src_entry_proto->edit_url()), _)); 1577 GURL(src_entry_proto->edit_url()), _));
1592 1578
1593 FileOperationCallback callback =
1594 base::Bind(&CallbackHelper::FileOperationCallback,
1595 callback_helper_.get());
1596
1597 // Expect notification for both source and destination directories. 1579 // Expect notification for both source and destination directories.
1598 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1580 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1599 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1581 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1600 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1582 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1601 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1583 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1);
1602 1584
1603 file_system_->Move(src_file_path, dest_file_path, callback); 1585 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1586 file_system_->Move(
1587 src_file_path,
1588 dest_file_path,
1589 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1604 google_apis::test_util::RunBlockingPoolTask(); 1590 google_apis::test_util::RunBlockingPoolTask();
1605 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1591 EXPECT_EQ(DRIVE_FILE_OK, error);
1606 1592
1607 EXPECT_FALSE(EntryExists(src_file_path)); 1593 EXPECT_FALSE(EntryExists(src_file_path));
1608 EXPECT_TRUE(EntryExists(dest_file_path)); 1594 EXPECT_TRUE(EntryExists(dest_file_path));
1609 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); 1595 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1610 } 1596 }
1611 1597
1612 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) { 1598 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) {
1613 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1599 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1"));
1614 FilePath src_file_path( 1600 FilePath src_file_path(
1615 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1601 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt"));
(...skipping 17 matching lines...) Expand all
1633 EXPECT_FALSE(src_parent_proto->content_url().empty()); 1619 EXPECT_FALSE(src_parent_proto->content_url().empty());
1634 1620
1635 EXPECT_CALL(*mock_drive_service_, 1621 EXPECT_CALL(*mock_drive_service_,
1636 RenameResource(GURL(src_entry_proto->edit_url()), 1622 RenameResource(GURL(src_entry_proto->edit_url()),
1637 FILE_PATH_LITERAL("Test.log"), _)); 1623 FILE_PATH_LITERAL("Test.log"), _));
1638 EXPECT_CALL(*mock_drive_service_, 1624 EXPECT_CALL(*mock_drive_service_,
1639 RemoveResourceFromDirectory( 1625 RemoveResourceFromDirectory(
1640 GURL(src_parent_proto->content_url()), 1626 GURL(src_parent_proto->content_url()),
1641 src_file_resource_id, _)); 1627 src_file_resource_id, _));
1642 1628
1643 FileOperationCallback callback =
1644 base::Bind(&CallbackHelper::FileOperationCallback,
1645 callback_helper_.get());
1646
1647 // Expect notification for both source and destination directories. 1629 // Expect notification for both source and destination directories.
1648 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1630 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1649 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1631 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1650 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1632 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1651 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1633 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1);
1652 1634
1653 file_system_->Move(src_file_path, dest_file_path, callback); 1635 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1636 file_system_->Move(
1637 src_file_path,
1638 dest_file_path,
1639 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1654 google_apis::test_util::RunBlockingPoolTask(); 1640 google_apis::test_util::RunBlockingPoolTask();
1655 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1641 EXPECT_EQ(DRIVE_FILE_OK, error);
1656 1642
1657 EXPECT_FALSE(EntryExists(src_file_path)); 1643 EXPECT_FALSE(EntryExists(src_file_path));
1658 ASSERT_TRUE(EntryExists(dest_file_path)); 1644 ASSERT_TRUE(EntryExists(dest_file_path));
1659 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); 1645 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1660 } 1646 }
1661 1647
1662 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) { 1648 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) {
1663 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); 1649 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1"));
1664 FilePath src_file_path( 1650 FilePath src_file_path(
1665 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt")); 1651 FILE_PATH_LITERAL("drive/Directory 1/SubDirectory File 1.txt"));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 EXPECT_CALL(*mock_drive_service_, 1690 EXPECT_CALL(*mock_drive_service_,
1705 RemoveResourceFromDirectory( 1691 RemoveResourceFromDirectory(
1706 GURL(src_parent_proto->content_url()), 1692 GURL(src_parent_proto->content_url()),
1707 src_file_resource_id, _)); 1693 src_file_resource_id, _));
1708 EXPECT_CALL(*mock_drive_service_, 1694 EXPECT_CALL(*mock_drive_service_,
1709 AddResourceToDirectory( 1695 AddResourceToDirectory(
1710 GURL(dest_parent_proto->content_url()), 1696 GURL(dest_parent_proto->content_url()),
1711 GURL(src_entry_proto->edit_url()), 1697 GURL(src_entry_proto->edit_url()),
1712 _)); 1698 _));
1713 1699
1714 FileOperationCallback callback =
1715 base::Bind(&CallbackHelper::FileOperationCallback,
1716 callback_helper_.get());
1717
1718 // Expect notification for both source and destination directories plus 1700 // Expect notification for both source and destination directories plus
1719 // interim file path. 1701 // interim file path.
1720 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1702 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1721 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); 1703 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1);
1722 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1704 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1723 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1705 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1724 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1706 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1725 Eq(FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); 1707 Eq(FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1);
1726 1708
1727 file_system_->Move(src_file_path, dest_file_path, callback); 1709 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1710 file_system_->Move(
1711 src_file_path,
1712 dest_file_path,
1713 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1728 google_apis::test_util::RunBlockingPoolTask(); 1714 google_apis::test_util::RunBlockingPoolTask();
1729 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_); 1715 EXPECT_EQ(DRIVE_FILE_OK, error);
1730 1716
1731 EXPECT_FALSE(EntryExists(src_file_path)); 1717 EXPECT_FALSE(EntryExists(src_file_path));
1732 EXPECT_FALSE(EntryExists(interim_file_path)); 1718 EXPECT_FALSE(EntryExists(interim_file_path));
1733 1719
1734 EXPECT_FALSE(EntryExists(src_file_path)); 1720 EXPECT_FALSE(EntryExists(src_file_path));
1735 EXPECT_TRUE(EntryExists(dest_file_path)); 1721 EXPECT_TRUE(EntryExists(dest_file_path));
1736 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); 1722 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1737 } 1723 }
1738 1724
1739 TEST_F(DriveFileSystemTest, MoveNotExistingFile) { 1725 TEST_F(DriveFileSystemTest, MoveNotExistingFile) {
1740 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); 1726 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt"));
1741 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); 1727 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log"));
1742 1728
1743 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1729 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1744 1730
1745 EXPECT_FALSE(EntryExists(src_file_path)); 1731 EXPECT_FALSE(EntryExists(src_file_path));
1746 1732
1747 FileOperationCallback callback = 1733 DriveFileError error = DRIVE_FILE_OK;
1748 base::Bind(&CallbackHelper::FileOperationCallback, 1734 file_system_->Move(
1749 callback_helper_.get()); 1735 src_file_path,
1750 1736 dest_file_path,
1751 file_system_->Move(src_file_path, dest_file_path, callback); 1737 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1752 google_apis::test_util::RunBlockingPoolTask(); 1738 google_apis::test_util::RunBlockingPoolTask();
1753 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 1739 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1754 1740
1755 EXPECT_FALSE(EntryExists(src_file_path)); 1741 EXPECT_FALSE(EntryExists(src_file_path));
1756 EXPECT_FALSE(EntryExists(dest_file_path)); 1742 EXPECT_FALSE(EntryExists(dest_file_path));
1757 } 1743 }
1758 1744
1759 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) { 1745 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) {
1760 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1746 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt"));
1761 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); 1747 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy"));
1762 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); 1748 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log"));
1763 1749
1764 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1750 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1765 1751
1766 ASSERT_TRUE(EntryExists(src_file_path)); 1752 ASSERT_TRUE(EntryExists(src_file_path));
1767 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1753 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1768 src_file_path); 1754 src_file_path);
1769 ASSERT_TRUE(src_entry_proto.get()); 1755 ASSERT_TRUE(src_entry_proto.get());
1770 std::string src_file_resource_id = 1756 std::string src_file_resource_id =
1771 src_entry_proto->resource_id(); 1757 src_entry_proto->resource_id();
1772 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1758 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1773 1759
1774 EXPECT_FALSE(EntryExists(dest_parent_path)); 1760 EXPECT_FALSE(EntryExists(dest_parent_path));
1775 1761
1776 FileOperationCallback callback = 1762 DriveFileError error = DRIVE_FILE_OK;
1777 base::Bind(&CallbackHelper::FileOperationCallback, 1763 file_system_->Move(
1778 callback_helper_.get()); 1764 src_file_path,
1779 1765 dest_file_path,
1780 file_system_->Move(src_file_path, dest_file_path, callback); 1766 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1781 google_apis::test_util::RunBlockingPoolTask(); 1767 google_apis::test_util::RunBlockingPoolTask();
1782 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 1768 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
1783
1784 1769
1785 EXPECT_FALSE(EntryExists(dest_parent_path)); 1770 EXPECT_FALSE(EntryExists(dest_parent_path));
1786 EXPECT_FALSE(EntryExists(dest_file_path)); 1771 EXPECT_FALSE(EntryExists(dest_file_path));
1787 } 1772 }
1788 1773
1789 // Test the case where the parent of |dest_file_path| is a existing file, 1774 // Test the case where the parent of |dest_file_path| is a existing file,
1790 // not a directory. 1775 // not a directory.
1791 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) { 1776 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) {
1792 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); 1777 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt"));
1793 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Duplicate Name.txt")); 1778 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Duplicate Name.txt"));
1794 FilePath dest_file_path(FILE_PATH_LITERAL( 1779 FilePath dest_file_path(FILE_PATH_LITERAL(
1795 "drive/Duplicate Name.txt/Test.log")); 1780 "drive/Duplicate Name.txt/Test.log"));
1796 1781
1797 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1782 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1798 1783
1799 ASSERT_TRUE(EntryExists(src_file_path)); 1784 ASSERT_TRUE(EntryExists(src_file_path));
1800 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( 1785 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync(
1801 src_file_path); 1786 src_file_path);
1802 ASSERT_TRUE(src_entry_proto.get()); 1787 ASSERT_TRUE(src_entry_proto.get());
1803 std::string src_file_resource_id = 1788 std::string src_file_resource_id =
1804 src_entry_proto->resource_id(); 1789 src_entry_proto->resource_id();
1805 EXPECT_FALSE(src_entry_proto->edit_url().empty()); 1790 EXPECT_FALSE(src_entry_proto->edit_url().empty());
1806 1791
1807 ASSERT_TRUE(EntryExists(dest_parent_path)); 1792 ASSERT_TRUE(EntryExists(dest_parent_path));
1808 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync( 1793 scoped_ptr<DriveEntryProto> dest_parent_proto = GetEntryInfoByPathSync(
1809 dest_parent_path); 1794 dest_parent_path);
1810 ASSERT_TRUE(dest_parent_proto.get()); 1795 ASSERT_TRUE(dest_parent_proto.get());
1811 1796
1812 FileOperationCallback callback = 1797 DriveFileError error = DRIVE_FILE_OK;
1813 base::Bind(&CallbackHelper::FileOperationCallback, 1798 file_system_->Move(
1814 callback_helper_.get()); 1799 src_file_path,
1815 1800 dest_file_path,
1816 file_system_->Move(src_file_path, dest_file_path, callback); 1801 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1817 google_apis::test_util::RunBlockingPoolTask(); 1802 google_apis::test_util::RunBlockingPoolTask();
1818 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, 1803 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, error);
1819 callback_helper_->last_error_);
1820 1804
1821 EXPECT_TRUE(EntryExists(src_file_path)); 1805 EXPECT_TRUE(EntryExists(src_file_path));
1822 EXPECT_TRUE(EntryExists(dest_parent_path)); 1806 EXPECT_TRUE(EntryExists(dest_parent_path));
1823 EXPECT_FALSE(EntryExists(dest_file_path)); 1807 EXPECT_FALSE(EntryExists(dest_file_path));
1824 } 1808 }
1825 1809
1826 TEST_F(DriveFileSystemTest, RemoveEntries) { 1810 TEST_F(DriveFileSystemTest, RemoveEntries) {
1827 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1811 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1828 1812
1829 FilePath nonexisting_file(FILE_PATH_LITERAL("drive/Dummy file.txt")); 1813 FilePath nonexisting_file(FILE_PATH_LITERAL("drive/Dummy file.txt"));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 } 1943 }
1960 1944
1961 // Create a directory through the document service 1945 // Create a directory through the document service
1962 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { 1946 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) {
1963 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1947 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1964 EXPECT_CALL(*mock_drive_service_, 1948 EXPECT_CALL(*mock_drive_service_,
1965 AddNewDirectory(_, "Sample Directory Title", _)).Times(1); 1949 AddNewDirectory(_, "Sample Directory Title", _)).Times(1);
1966 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( 1950 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1967 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); 1951 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1);
1968 1952
1969 // Set last error so it's not a valid error code. 1953 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
1970 callback_helper_->last_error_ = static_cast<DriveFileError>(1);
1971 file_system_->CreateDirectory( 1954 file_system_->CreateDirectory(
1972 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), 1955 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")),
1973 false, // is_exclusive 1956 false, // is_exclusive
1974 true, // is_recursive 1957 true, // is_recursive
1975 base::Bind(&CallbackHelper::FileOperationCallback, 1958 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
1976 callback_helper_.get()));
1977 google_apis::test_util::RunBlockingPoolTask(); 1959 google_apis::test_util::RunBlockingPoolTask();
1978 // TODO(gspencer): Uncomment this when we get a blob that 1960
1979 // works that can be returned from the mock. 1961 EXPECT_EQ(DRIVE_FILE_OK, error);
1980 // EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_);
1981 } 1962 }
1982 1963
1983 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { 1964 TEST_F(DriveFileSystemTest, GetFileByPath_FromGData_EnoughSpace) {
1984 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 1965 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
1985 1966
1986 GetFileCallback callback = 1967 GetFileCallback callback =
1987 base::Bind(&CallbackHelper::GetFileCallback, 1968 base::Bind(&CallbackHelper::GetFileCallback,
1988 callback_helper_.get()); 1969 callback_helper_.get());
1989 1970
1990 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt")); 1971 FilePath file_in_root(FILE_PATH_LITERAL("drive/File 1.txt"));
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 DriveCache::GetCacheRootPath(profile_.get()) 2374 DriveCache::GetCacheRootPath(profile_.get())
2394 .AppendASCII("outgoing") 2375 .AppendASCII("outgoing")
2395 .AppendASCII(kResourceId); 2376 .AppendASCII(kResourceId);
2396 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path)); 2377 ASSERT_TRUE(file_util::PathExists(dirty_cache_file_path));
2397 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path)); 2378 ASSERT_TRUE(file_util::PathExists(outgoing_symlink_path));
2398 2379
2399 // We'll notify the directory change to the observer upon completion. 2380 // We'll notify the directory change to the observer upon completion.
2400 EXPECT_CALL(*mock_directory_observer_, 2381 EXPECT_CALL(*mock_directory_observer_,
2401 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1); 2382 OnDirectoryChanged(Eq(FilePath(kDriveRootDirectory)))).Times(1);
2402 2383
2403 // The callback will be called upon completion of
2404 // UpdateFileByResourceId().
2405 FileOperationCallback callback =
2406 base::Bind(&CallbackHelper::FileOperationCallback,
2407 callback_helper_.get());
2408
2409 // Check the number of files in the root directory. We'll compare the 2384 // Check the number of files in the root directory. We'll compare the
2410 // number after updating a file. 2385 // number after updating a file.
2411 scoped_ptr<DriveEntryProtoVector> root_directory_entries( 2386 scoped_ptr<DriveEntryProtoVector> root_directory_entries(
2412 ReadDirectoryByPathSync(FilePath::FromUTF8Unsafe("drive"))); 2387 ReadDirectoryByPathSync(FilePath::FromUTF8Unsafe("drive")));
2413 ASSERT_TRUE(root_directory_entries.get()); 2388 ASSERT_TRUE(root_directory_entries.get());
2414 const int num_files_in_root = CountFiles(*root_directory_entries); 2389 const int num_files_in_root = CountFiles(*root_directory_entries);
2415 2390
2416 file_system_->UpdateFileByResourceId(kResourceId, callback); 2391 // The callback will be called upon completion of
2392 // UpdateFileByResourceId().
2393 DriveFileError error = DRIVE_FILE_ERROR_FAILED;
2394 file_system_->UpdateFileByResourceId(
2395 kResourceId,
2396 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
2417 google_apis::test_util::RunBlockingPoolTask(); 2397 google_apis::test_util::RunBlockingPoolTask();
2398 EXPECT_EQ(DRIVE_FILE_OK, error);
2418 2399
2419 EXPECT_EQ(DRIVE_FILE_OK, callback_helper_->last_error_);
2420 // Make sure that the number of files did not change (i.e. we updated an 2400 // Make sure that the number of files did not change (i.e. we updated an
2421 // existing file, rather than adding a new file. The number of files 2401 // existing file, rather than adding a new file. The number of files
2422 // increases if we don't handle the file update right). 2402 // increases if we don't handle the file update right).
2423 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries)); 2403 EXPECT_EQ(num_files_in_root, CountFiles(*root_directory_entries));
2424 // After the file is updated, the dirty bit is cleared, hence the symlink 2404 // After the file is updated, the dirty bit is cleared, hence the symlink
2425 // should be gone. 2405 // should be gone.
2426 ASSERT_FALSE(file_util::PathExists(outgoing_symlink_path)); 2406 ASSERT_FALSE(file_util::PathExists(outgoing_symlink_path));
2427 } 2407 }
2428 2408
2429 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) { 2409 TEST_F(DriveFileSystemTest, UpdateFileByResourceId_NonexistentFile) {
2430 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 2410 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
2431 2411
2432 // This is nonexistent in root_feed.json. 2412 // This is nonexistent in root_feed.json.
2433 const FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt")); 2413 const FilePath kFilePath(FILE_PATH_LITERAL("drive/Nonexistent.txt"));
2434 const std::string kResourceId("file:nonexistent_resource_id"); 2414 const std::string kResourceId("file:nonexistent_resource_id");
2435 const std::string kMd5("nonexistent_md5"); 2415 const std::string kMd5("nonexistent_md5");
2436 2416
2437 // The callback will be called upon completion of 2417 // The callback will be called upon completion of
2438 // UpdateFileByResourceId(). 2418 // UpdateFileByResourceId().
2439 FileOperationCallback callback = 2419 DriveFileError error = DRIVE_FILE_OK;
2440 base::Bind(&CallbackHelper::FileOperationCallback, 2420 file_system_->UpdateFileByResourceId(
2441 callback_helper_.get()); 2421 kResourceId,
2442 2422 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error));
2443 file_system_->UpdateFileByResourceId(kResourceId, callback);
2444 google_apis::test_util::RunBlockingPoolTask(); 2423 google_apis::test_util::RunBlockingPoolTask();
2445 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); 2424 EXPECT_EQ(DRIVE_FILE_ERROR_NOT_FOUND, error);
2446 } 2425 }
2447 2426
2448 TEST_F(DriveFileSystemTest, ContentSearch) { 2427 TEST_F(DriveFileSystemTest, ContentSearch) {
2449 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json")); 2428 ASSERT_TRUE(LoadRootFeedDocument("gdata/root_feed.json"));
2450 2429
2451 mock_drive_service_->set_search_result("gdata/search_result_feed.json"); 2430 mock_drive_service_->set_search_result("gdata/search_result_feed.json");
2452 2431
2453 // There should be only one GetResourceList request, even though search result 2432 // There should be only one GetResourceList request, even though search result
2454 // feed has next feed url. 2433 // feed has next feed url.
2455 EXPECT_CALL(*mock_drive_service_, GetResourceList(Eq(GURL()), _, "foo", _, _, 2434 EXPECT_CALL(*mock_drive_service_, GetResourceList(Eq(GURL()), _, "foo", _, _,
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
2679 2658
2680 // An app for foo.ext_1 should now be found, as the registry was loaded. 2659 // An app for foo.ext_1 should now be found, as the registry was loaded.
2681 drive_webapps_registry_->GetWebAppsForFile( 2660 drive_webapps_registry_->GetWebAppsForFile(
2682 FilePath(FILE_PATH_LITERAL("foo.ext_1")), 2661 FilePath(FILE_PATH_LITERAL("foo.ext_1")),
2683 "" /* mime_type */, 2662 "" /* mime_type */,
2684 &apps); 2663 &apps);
2685 EXPECT_EQ(1U, apps.size()); 2664 EXPECT_EQ(1U, apps.size());
2686 } 2665 }
2687 2666
2688 } // namespace drive 2667 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698