| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 GDataCache::CACHED_FILE_FROM_SERVER); | 348 GDataCache::CACHED_FILE_FROM_SERVER); |
| 349 } | 349 } |
| 350 | 350 |
| 351 // Gets entry info by path synchronously. | 351 // Gets entry info by path synchronously. |
| 352 scoped_ptr<GDataEntryProto> GetEntryInfoByPathSync( | 352 scoped_ptr<GDataEntryProto> GetEntryInfoByPathSync( |
| 353 const FilePath& file_path) { | 353 const FilePath& file_path) { |
| 354 file_system_->GetEntryInfoByPath( | 354 file_system_->GetEntryInfoByPath( |
| 355 file_path, | 355 file_path, |
| 356 base::Bind(&CallbackHelper::GetEntryInfoCallback, | 356 base::Bind(&CallbackHelper::GetEntryInfoCallback, |
| 357 callback_helper_.get())); | 357 callback_helper_.get())); |
| 358 message_loop_.RunAllPending(); | 358 test_util::RunBlockingPoolTask(); |
| 359 | 359 |
| 360 return callback_helper_->entry_proto_.Pass(); | 360 return callback_helper_->entry_proto_.Pass(); |
| 361 } | 361 } |
| 362 | 362 |
| 363 // Gets directory info by path synchronously. | 363 // Gets directory info by path synchronously. |
| 364 scoped_ptr<GDataEntryProtoVector> ReadDirectoryByPathSync( | 364 scoped_ptr<GDataEntryProtoVector> ReadDirectoryByPathSync( |
| 365 const FilePath& file_path) { | 365 const FilePath& file_path) { |
| 366 file_system_->ReadDirectoryByPath( | 366 file_system_->ReadDirectoryByPath( |
| 367 file_path, | 367 file_path, |
| 368 base::Bind(&CallbackHelper::ReadDirectoryCallback, | 368 base::Bind(&CallbackHelper::ReadDirectoryCallback, |
| 369 callback_helper_.get())); | 369 callback_helper_.get())); |
| 370 message_loop_.RunAllPending(); | 370 test_util::RunBlockingPoolTask(); |
| 371 | 371 |
| 372 return callback_helper_->directory_entries_.Pass(); | 372 return callback_helper_->directory_entries_.Pass(); |
| 373 } | 373 } |
| 374 | 374 |
| 375 // Returns true if an entry exists at |file_path|. | 375 // Returns true if an entry exists at |file_path|. |
| 376 bool EntryExists(const FilePath& file_path) { | 376 bool EntryExists(const FilePath& file_path) { |
| 377 return GetEntryInfoByPathSync(file_path).get(); | 377 return GetEntryInfoByPathSync(file_path).get(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 | 380 |
| (...skipping 1000 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1381 | 1381 |
| 1382 LoadRootFeedDocument("root_feed.json"); | 1382 LoadRootFeedDocument("root_feed.json"); |
| 1383 | 1383 |
| 1384 EXPECT_FALSE(EntryExists(src_file_path)); | 1384 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1385 | 1385 |
| 1386 FileOperationCallback callback = | 1386 FileOperationCallback callback = |
| 1387 base::Bind(&CallbackHelper::FileOperationCallback, | 1387 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1388 callback_helper_.get()); | 1388 callback_helper_.get()); |
| 1389 | 1389 |
| 1390 file_system_->Copy(src_file_path, dest_file_path, callback); | 1390 file_system_->Copy(src_file_path, dest_file_path, callback); |
| 1391 message_loop_.RunAllPending(); // Wait to get our result | 1391 test_util::RunBlockingPoolTask(); |
| 1392 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1392 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 1393 | 1393 |
| 1394 EXPECT_FALSE(EntryExists(src_file_path)); | 1394 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1395 EXPECT_FALSE(EntryExists(dest_file_path)); | 1395 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1396 } | 1396 } |
| 1397 | 1397 |
| 1398 TEST_F(GDataFileSystemTest, CopyFileToNonExistingDirectory) { | 1398 TEST_F(GDataFileSystemTest, CopyFileToNonExistingDirectory) { |
| 1399 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1399 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 1400 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1400 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); |
| 1401 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1401 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); |
| 1402 | 1402 |
| 1403 LoadRootFeedDocument("root_feed.json"); | 1403 LoadRootFeedDocument("root_feed.json"); |
| 1404 | 1404 |
| 1405 ASSERT_TRUE(EntryExists(src_file_path)); | 1405 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1406 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1406 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1407 src_file_path); | 1407 src_file_path); |
| 1408 ASSERT_TRUE(src_entry_proto.get()); | 1408 ASSERT_TRUE(src_entry_proto.get()); |
| 1409 std::string src_file_path_resource_id = | 1409 std::string src_file_path_resource_id = |
| 1410 src_entry_proto->resource_id(); | 1410 src_entry_proto->resource_id(); |
| 1411 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1411 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1412 | 1412 |
| 1413 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1413 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1414 | 1414 |
| 1415 FileOperationCallback callback = | 1415 FileOperationCallback callback = |
| 1416 base::Bind(&CallbackHelper::FileOperationCallback, | 1416 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1417 callback_helper_.get()); | 1417 callback_helper_.get()); |
| 1418 | 1418 |
| 1419 file_system_->Move(src_file_path, dest_file_path, callback); | 1419 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1420 message_loop_.RunAllPending(); | 1420 test_util::RunBlockingPoolTask(); |
| 1421 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1421 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 1422 | 1422 |
| 1423 EXPECT_TRUE(EntryExists(src_file_path)); | 1423 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1424 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1424 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1425 EXPECT_FALSE(EntryExists(dest_file_path)); | 1425 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1426 } | 1426 } |
| 1427 | 1427 |
| 1428 // Test the case where the parent of |dest_file_path| is a existing file, | 1428 // Test the case where the parent of |dest_file_path| is a existing file, |
| 1429 // not a directory. | 1429 // not a directory. |
| 1430 TEST_F(GDataFileSystemTest, CopyFileToInvalidPath) { | 1430 TEST_F(GDataFileSystemTest, CopyFileToInvalidPath) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1446 ASSERT_TRUE(EntryExists(dest_parent_path)); | 1446 ASSERT_TRUE(EntryExists(dest_parent_path)); |
| 1447 scoped_ptr<GDataEntryProto> dest_entry_proto = GetEntryInfoByPathSync( | 1447 scoped_ptr<GDataEntryProto> dest_entry_proto = GetEntryInfoByPathSync( |
| 1448 dest_parent_path); | 1448 dest_parent_path); |
| 1449 ASSERT_TRUE(dest_entry_proto.get()); | 1449 ASSERT_TRUE(dest_entry_proto.get()); |
| 1450 | 1450 |
| 1451 FileOperationCallback callback = | 1451 FileOperationCallback callback = |
| 1452 base::Bind(&CallbackHelper::FileOperationCallback, | 1452 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1453 callback_helper_.get()); | 1453 callback_helper_.get()); |
| 1454 | 1454 |
| 1455 file_system_->Copy(src_file_path, dest_file_path, callback); | 1455 file_system_->Copy(src_file_path, dest_file_path, callback); |
| 1456 message_loop_.RunAllPending(); | 1456 test_util::RunBlockingPoolTask(); |
| 1457 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, | 1457 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, |
| 1458 callback_helper_->last_error_); | 1458 callback_helper_->last_error_); |
| 1459 | 1459 |
| 1460 EXPECT_TRUE(EntryExists(src_file_path)); | 1460 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1461 EXPECT_TRUE(EntryExists(src_file_path)); | 1461 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1462 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1462 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1463 | 1463 |
| 1464 EXPECT_FALSE(EntryExists(dest_file_path)); | 1464 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1465 } | 1465 } |
| 1466 | 1466 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1485 FILE_PATH_LITERAL("Test.log"), _)); | 1485 FILE_PATH_LITERAL("Test.log"), _)); |
| 1486 | 1486 |
| 1487 FileOperationCallback callback = | 1487 FileOperationCallback callback = |
| 1488 base::Bind(&CallbackHelper::FileOperationCallback, | 1488 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1489 callback_helper_.get()); | 1489 callback_helper_.get()); |
| 1490 | 1490 |
| 1491 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1491 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1492 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1492 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
| 1493 | 1493 |
| 1494 file_system_->Move(src_file_path, dest_file_path, callback); | 1494 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1495 message_loop_.RunAllPending(); | 1495 test_util::RunBlockingPoolTask(); |
| 1496 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1496 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); |
| 1497 | 1497 |
| 1498 EXPECT_FALSE(EntryExists(src_file_path)); | 1498 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1499 EXPECT_TRUE(EntryExists(dest_file_path)); | 1499 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1500 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1500 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1501 } | 1501 } |
| 1502 | 1502 |
| 1503 TEST_F(GDataFileSystemTest, MoveFileFromRootToSubDirectory) { | 1503 TEST_F(GDataFileSystemTest, MoveFileFromRootToSubDirectory) { |
| 1504 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1504 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 1505 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1505 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1534 base::Bind(&CallbackHelper::FileOperationCallback, | 1534 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1535 callback_helper_.get()); | 1535 callback_helper_.get()); |
| 1536 | 1536 |
| 1537 // Expect notification for both source and destination directories. | 1537 // Expect notification for both source and destination directories. |
| 1538 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1538 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1539 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1539 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 1540 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1540 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1541 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1541 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
| 1542 | 1542 |
| 1543 file_system_->Move(src_file_path, dest_file_path, callback); | 1543 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1544 message_loop_.RunAllPending(); | 1544 test_util::RunBlockingPoolTask(); |
| 1545 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1545 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); |
| 1546 | 1546 |
| 1547 EXPECT_FALSE(EntryExists(src_file_path)); | 1547 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1548 EXPECT_TRUE(EntryExists(dest_file_path)); | 1548 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1549 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1549 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1550 } | 1550 } |
| 1551 | 1551 |
| 1552 TEST_F(GDataFileSystemTest, MoveFileFromSubDirectoryToRoot) { | 1552 TEST_F(GDataFileSystemTest, MoveFileFromSubDirectoryToRoot) { |
| 1553 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1553 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
| 1554 FilePath src_file_path( | 1554 FilePath src_file_path( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1585 base::Bind(&CallbackHelper::FileOperationCallback, | 1585 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1586 callback_helper_.get()); | 1586 callback_helper_.get()); |
| 1587 | 1587 |
| 1588 // Expect notification for both source and destination directories. | 1588 // Expect notification for both source and destination directories. |
| 1589 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1589 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1590 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1590 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 1591 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1591 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1592 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1592 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
| 1593 | 1593 |
| 1594 file_system_->Move(src_file_path, dest_file_path, callback); | 1594 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1595 message_loop_.RunAllPending(); | 1595 test_util::RunBlockingPoolTask(); |
| 1596 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1596 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); |
| 1597 | 1597 |
| 1598 EXPECT_FALSE(EntryExists(src_file_path)); | 1598 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1599 ASSERT_TRUE(EntryExists(dest_file_path)); | 1599 ASSERT_TRUE(EntryExists(dest_file_path)); |
| 1600 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1600 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1601 } | 1601 } |
| 1602 | 1602 |
| 1603 TEST_F(GDataFileSystemTest, MoveFileBetweenSubDirectories) { | 1603 TEST_F(GDataFileSystemTest, MoveFileBetweenSubDirectories) { |
| 1604 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); | 1604 FilePath src_parent_path(FILE_PATH_LITERAL("drive/Directory 1")); |
| 1605 FilePath src_file_path( | 1605 FilePath src_file_path( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1660 // Expect notification for both source and destination directories plus | 1660 // Expect notification for both source and destination directories plus |
| 1661 // interim file path. | 1661 // interim file path. |
| 1662 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1662 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1663 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); | 1663 Eq(FilePath(FILE_PATH_LITERAL("drive/Directory 1"))))).Times(1); |
| 1664 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1664 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1665 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1665 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 1666 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1666 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1667 Eq(FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); | 1667 Eq(FilePath(FILE_PATH_LITERAL("drive/New Folder 1"))))).Times(1); |
| 1668 | 1668 |
| 1669 file_system_->Move(src_file_path, dest_file_path, callback); | 1669 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1670 message_loop_.RunAllPending(); | 1670 test_util::RunBlockingPoolTask(); |
| 1671 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1671 EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); |
| 1672 | 1672 |
| 1673 EXPECT_FALSE(EntryExists(src_file_path)); | 1673 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1674 EXPECT_FALSE(EntryExists(interim_file_path)); | 1674 EXPECT_FALSE(EntryExists(interim_file_path)); |
| 1675 | 1675 |
| 1676 EXPECT_FALSE(EntryExists(src_file_path)); | 1676 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1677 EXPECT_TRUE(EntryExists(dest_file_path)); | 1677 EXPECT_TRUE(EntryExists(dest_file_path)); |
| 1678 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); | 1678 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path)); |
| 1679 } | 1679 } |
| 1680 | 1680 |
| 1681 TEST_F(GDataFileSystemTest, MoveNotExistingFile) { | 1681 TEST_F(GDataFileSystemTest, MoveNotExistingFile) { |
| 1682 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); | 1682 FilePath src_file_path(FILE_PATH_LITERAL("drive/Dummy file.txt")); |
| 1683 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); | 1683 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Test.log")); |
| 1684 | 1684 |
| 1685 LoadRootFeedDocument("root_feed.json"); | 1685 LoadRootFeedDocument("root_feed.json"); |
| 1686 | 1686 |
| 1687 EXPECT_FALSE(EntryExists(src_file_path)); | 1687 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1688 | 1688 |
| 1689 FileOperationCallback callback = | 1689 FileOperationCallback callback = |
| 1690 base::Bind(&CallbackHelper::FileOperationCallback, | 1690 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1691 callback_helper_.get()); | 1691 callback_helper_.get()); |
| 1692 | 1692 |
| 1693 file_system_->Move(src_file_path, dest_file_path, callback); | 1693 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1694 message_loop_.RunAllPending(); // Wait to get our result | 1694 test_util::RunBlockingPoolTask(); |
| 1695 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1695 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 1696 | 1696 |
| 1697 EXPECT_FALSE(EntryExists(src_file_path)); | 1697 EXPECT_FALSE(EntryExists(src_file_path)); |
| 1698 EXPECT_FALSE(EntryExists(dest_file_path)); | 1698 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1699 } | 1699 } |
| 1700 | 1700 |
| 1701 TEST_F(GDataFileSystemTest, MoveFileToNonExistingDirectory) { | 1701 TEST_F(GDataFileSystemTest, MoveFileToNonExistingDirectory) { |
| 1702 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); | 1702 FilePath src_file_path(FILE_PATH_LITERAL("drive/File 1.txt")); |
| 1703 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); | 1703 FilePath dest_parent_path(FILE_PATH_LITERAL("drive/Dummy")); |
| 1704 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); | 1704 FilePath dest_file_path(FILE_PATH_LITERAL("drive/Dummy/Test.log")); |
| 1705 | 1705 |
| 1706 LoadRootFeedDocument("root_feed.json"); | 1706 LoadRootFeedDocument("root_feed.json"); |
| 1707 | 1707 |
| 1708 ASSERT_TRUE(EntryExists(src_file_path)); | 1708 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1709 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1709 scoped_ptr<GDataEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1710 src_file_path); | 1710 src_file_path); |
| 1711 ASSERT_TRUE(src_entry_proto.get()); | 1711 ASSERT_TRUE(src_entry_proto.get()); |
| 1712 std::string src_file_resource_id = | 1712 std::string src_file_resource_id = |
| 1713 src_entry_proto->resource_id(); | 1713 src_entry_proto->resource_id(); |
| 1714 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1714 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1715 | 1715 |
| 1716 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1716 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1717 | 1717 |
| 1718 FileOperationCallback callback = | 1718 FileOperationCallback callback = |
| 1719 base::Bind(&CallbackHelper::FileOperationCallback, | 1719 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1720 callback_helper_.get()); | 1720 callback_helper_.get()); |
| 1721 | 1721 |
| 1722 file_system_->Move(src_file_path, dest_file_path, callback); | 1722 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1723 message_loop_.RunAllPending(); | 1723 test_util::RunBlockingPoolTask(); |
| 1724 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 1724 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 1725 | 1725 |
| 1726 | 1726 |
| 1727 EXPECT_FALSE(EntryExists(dest_parent_path)); | 1727 EXPECT_FALSE(EntryExists(dest_parent_path)); |
| 1728 EXPECT_FALSE(EntryExists(dest_file_path)); | 1728 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1729 } | 1729 } |
| 1730 | 1730 |
| 1731 // Test the case where the parent of |dest_file_path| is a existing file, | 1731 // Test the case where the parent of |dest_file_path| is a existing file, |
| 1732 // not a directory. | 1732 // not a directory. |
| 1733 TEST_F(GDataFileSystemTest, MoveFileToInvalidPath) { | 1733 TEST_F(GDataFileSystemTest, MoveFileToInvalidPath) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1749 ASSERT_TRUE(EntryExists(dest_parent_path)); | 1749 ASSERT_TRUE(EntryExists(dest_parent_path)); |
| 1750 scoped_ptr<GDataEntryProto> dest_parent_proto = GetEntryInfoByPathSync( | 1750 scoped_ptr<GDataEntryProto> dest_parent_proto = GetEntryInfoByPathSync( |
| 1751 dest_parent_path); | 1751 dest_parent_path); |
| 1752 ASSERT_TRUE(dest_parent_proto.get()); | 1752 ASSERT_TRUE(dest_parent_proto.get()); |
| 1753 | 1753 |
| 1754 FileOperationCallback callback = | 1754 FileOperationCallback callback = |
| 1755 base::Bind(&CallbackHelper::FileOperationCallback, | 1755 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1756 callback_helper_.get()); | 1756 callback_helper_.get()); |
| 1757 | 1757 |
| 1758 file_system_->Move(src_file_path, dest_file_path, callback); | 1758 file_system_->Move(src_file_path, dest_file_path, callback); |
| 1759 message_loop_.RunAllPending(); | 1759 test_util::RunBlockingPoolTask(); |
| 1760 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, | 1760 EXPECT_EQ(GDATA_FILE_ERROR_NOT_A_DIRECTORY, |
| 1761 callback_helper_->last_error_); | 1761 callback_helper_->last_error_); |
| 1762 | 1762 |
| 1763 EXPECT_TRUE(EntryExists(src_file_path)); | 1763 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1764 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1764 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1765 EXPECT_FALSE(EntryExists(dest_file_path)); | 1765 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1766 } | 1766 } |
| 1767 | 1767 |
| 1768 TEST_F(GDataFileSystemTest, RemoveEntries) { | 1768 TEST_F(GDataFileSystemTest, RemoveEntries) { |
| 1769 LoadRootFeedDocument("root_feed.json"); | 1769 LoadRootFeedDocument("root_feed.json"); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1908 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); | 1908 Eq(FilePath(FILE_PATH_LITERAL("drive"))))).Times(1); |
| 1909 | 1909 |
| 1910 // Set last error so it's not a valid error code. | 1910 // Set last error so it's not a valid error code. |
| 1911 callback_helper_->last_error_ = static_cast<GDataFileError>(1); | 1911 callback_helper_->last_error_ = static_cast<GDataFileError>(1); |
| 1912 file_system_->CreateDirectory( | 1912 file_system_->CreateDirectory( |
| 1913 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), | 1913 FilePath(FILE_PATH_LITERAL("drive/Sample Directory Title")), |
| 1914 false, // is_exclusive | 1914 false, // is_exclusive |
| 1915 true, // is_recursive | 1915 true, // is_recursive |
| 1916 base::Bind(&CallbackHelper::FileOperationCallback, | 1916 base::Bind(&CallbackHelper::FileOperationCallback, |
| 1917 callback_helper_.get())); | 1917 callback_helper_.get())); |
| 1918 message_loop_.RunAllPending(); | 1918 test_util::RunBlockingPoolTask(); |
| 1919 // TODO(gspencer): Uncomment this when we get a blob that | 1919 // TODO(gspencer): Uncomment this when we get a blob that |
| 1920 // works that can be returned from the mock. | 1920 // works that can be returned from the mock. |
| 1921 // EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); | 1921 // EXPECT_EQ(GDATA_FILE_OK, callback_helper_->last_error_); |
| 1922 } | 1922 } |
| 1923 | 1923 |
| 1924 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { | 1924 TEST_F(GDataFileSystemTest, GetFileByPath_FromGData_EnoughSpace) { |
| 1925 LoadRootFeedDocument("root_feed.json"); | 1925 LoadRootFeedDocument("root_feed.json"); |
| 1926 | 1926 |
| 1927 GetFileCallback callback = | 1927 GetFileCallback callback = |
| 1928 base::Bind(&CallbackHelper::GetFileCallback, | 1928 base::Bind(&CallbackHelper::GetFileCallback, |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2445 } | 2445 } |
| 2446 | 2446 |
| 2447 TEST_F(GDataFileSystemTest, GetAvailableSpace) { | 2447 TEST_F(GDataFileSystemTest, GetAvailableSpace) { |
| 2448 GetAvailableSpaceCallback callback = | 2448 GetAvailableSpaceCallback callback = |
| 2449 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, | 2449 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, |
| 2450 callback_helper_.get()); | 2450 callback_helper_.get()); |
| 2451 | 2451 |
| 2452 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)); | 2452 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)); |
| 2453 | 2453 |
| 2454 file_system_->GetAvailableSpace(callback); | 2454 file_system_->GetAvailableSpace(callback); |
| 2455 message_loop_.RunAllPending(); | 2455 test_util::RunBlockingPoolTask(); |
| 2456 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); | 2456 EXPECT_EQ(GG_LONGLONG(6789012345), callback_helper_->quota_bytes_used_); |
| 2457 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); | 2457 EXPECT_EQ(GG_LONGLONG(9876543210), callback_helper_->quota_bytes_total_); |
| 2458 } | 2458 } |
| 2459 | 2459 |
| 2460 TEST_F(GDataFileSystemTest, RequestDirectoryRefresh) { | 2460 TEST_F(GDataFileSystemTest, RequestDirectoryRefresh) { |
| 2461 LoadRootFeedDocument("root_feed.json"); | 2461 LoadRootFeedDocument("root_feed.json"); |
| 2462 | 2462 |
| 2463 // We'll fetch documents in the root directory with its resource ID. | 2463 // We'll fetch documents in the root directory with its resource ID. |
| 2464 EXPECT_CALL(*mock_doc_service_, | 2464 EXPECT_CALL(*mock_doc_service_, |
| 2465 GetDocuments(Eq(GURL()), _, _, kGDataRootDirectoryResourceId, _)) | 2465 GetDocuments(Eq(GURL()), _, _, kGDataRootDirectoryResourceId, _)) |
| 2466 .Times(1); | 2466 .Times(1); |
| 2467 // We'll notify the directory change to the observer. | 2467 // We'll notify the directory change to the observer. |
| 2468 EXPECT_CALL(*mock_directory_observer_, | 2468 EXPECT_CALL(*mock_directory_observer_, |
| 2469 OnDirectoryChanged(Eq(FilePath(kGDataRootDirectory)))).Times(1); | 2469 OnDirectoryChanged(Eq(FilePath(kGDataRootDirectory)))).Times(1); |
| 2470 | 2470 |
| 2471 file_system_->RequestDirectoryRefresh(FilePath(kGDataRootDirectory)); | 2471 file_system_->RequestDirectoryRefresh(FilePath(kGDataRootDirectory)); |
| 2472 message_loop_.RunAllPending(); | 2472 test_util::RunBlockingPoolTask(); |
| 2473 } | 2473 } |
| 2474 | 2474 |
| 2475 TEST_F(GDataFileSystemTest, OpenAndCloseFile) { | 2475 TEST_F(GDataFileSystemTest, OpenAndCloseFile) { |
| 2476 LoadRootFeedDocument("root_feed.json"); | 2476 LoadRootFeedDocument("root_feed.json"); |
| 2477 | 2477 |
| 2478 OpenFileCallback callback = | 2478 OpenFileCallback callback = |
| 2479 base::Bind(&CallbackHelper::OpenFileCallback, | 2479 base::Bind(&CallbackHelper::OpenFileCallback, |
| 2480 callback_helper_.get()); | 2480 callback_helper_.get()); |
| 2481 FileOperationCallback close_file_callback = | 2481 FileOperationCallback close_file_callback = |
| 2482 base::Bind(&CallbackHelper::CloseFileCallback, | 2482 base::Bind(&CallbackHelper::CloseFileCallback, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2556 | 2556 |
| 2557 // Try to close the same file twice. | 2557 // Try to close the same file twice. |
| 2558 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2558 file_system_->CloseFile(kFileInRoot, close_file_callback); |
| 2559 message_loop_.Run(); | 2559 message_loop_.Run(); |
| 2560 | 2560 |
| 2561 // It must fail. | 2561 // It must fail. |
| 2562 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2562 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
| 2563 } | 2563 } |
| 2564 | 2564 |
| 2565 } // namespace gdata | 2565 } // namespace gdata |
| OLD | NEW |