| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/drive/fake_drive_service.h" | 5 #include "chrome/browser/drive/fake_drive_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 // Adds a new directory at |parent_resource_id| with the given name. | 66 // Adds a new directory at |parent_resource_id| with the given name. |
| 67 // Returns true on success. | 67 // Returns true on success. |
| 68 bool AddNewDirectory(const std::string& parent_resource_id, | 68 bool AddNewDirectory(const std::string& parent_resource_id, |
| 69 const std::string& directory_title) { | 69 const std::string& directory_title) { |
| 70 GDataErrorCode error = GDATA_OTHER_ERROR; | 70 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 71 scoped_ptr<ResourceEntry> resource_entry; | 71 scoped_ptr<ResourceEntry> resource_entry; |
| 72 fake_service_.AddNewDirectory( | 72 fake_service_.AddNewDirectory( |
| 73 parent_resource_id, | 73 parent_resource_id, |
| 74 directory_title, | 74 directory_title, |
| 75 DriveServiceInterface::AddNewDirectoryOptions(), |
| 75 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 76 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 76 base::RunLoop().RunUntilIdle(); | 77 base::RunLoop().RunUntilIdle(); |
| 77 return error == HTTP_CREATED; | 78 return error == HTTP_CREATED; |
| 78 } | 79 } |
| 79 | 80 |
| 80 // Returns true if the resource identified by |resource_id| has a parent | 81 // Returns true if the resource identified by |resource_id| has a parent |
| 81 // identified by |parent_id|. | 82 // identified by |parent_id|. |
| 82 bool HasParent(const std::string& resource_id, const std::string& parent_id) { | 83 bool HasParent(const std::string& resource_id, const std::string& parent_id) { |
| 83 const GURL parent_url = FakeDriveService::GetFakeLinkUrl(parent_id); | 84 const GURL parent_url = FakeDriveService::GetFakeLinkUrl(parent_id); |
| 84 scoped_ptr<ResourceEntry> resource_entry = FindEntry(resource_id); | 85 scoped_ptr<ResourceEntry> resource_entry = FindEntry(resource_id); |
| (...skipping 1519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1604 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | 1605 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
| 1605 "gdata/account_metadata.json")); | 1606 "gdata/account_metadata.json")); |
| 1606 | 1607 |
| 1607 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1608 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1608 | 1609 |
| 1609 GDataErrorCode error = GDATA_OTHER_ERROR; | 1610 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1610 scoped_ptr<ResourceEntry> resource_entry; | 1611 scoped_ptr<ResourceEntry> resource_entry; |
| 1611 fake_service_.AddNewDirectory( | 1612 fake_service_.AddNewDirectory( |
| 1612 std::string(), | 1613 std::string(), |
| 1613 "new directory", | 1614 "new directory", |
| 1615 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1614 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1616 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1615 base::RunLoop().RunUntilIdle(); | 1617 base::RunLoop().RunUntilIdle(); |
| 1616 | 1618 |
| 1617 EXPECT_EQ(HTTP_CREATED, error); | 1619 EXPECT_EQ(HTTP_CREATED, error); |
| 1618 ASSERT_TRUE(resource_entry); | 1620 ASSERT_TRUE(resource_entry); |
| 1619 EXPECT_TRUE(resource_entry->is_folder()); | 1621 EXPECT_TRUE(resource_entry->is_folder()); |
| 1620 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1622 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
| 1621 EXPECT_EQ("new directory", resource_entry->title()); | 1623 EXPECT_EQ("new directory", resource_entry->title()); |
| 1622 EXPECT_TRUE(HasParent(resource_entry->resource_id(), | 1624 EXPECT_TRUE(HasParent(resource_entry->resource_id(), |
| 1623 fake_service_.GetRootResourceId())); | 1625 fake_service_.GetRootResourceId())); |
| 1624 // Should be incremented as a new directory was created. | 1626 // Should be incremented as a new directory was created. |
| 1625 EXPECT_EQ(old_largest_change_id + 1, | 1627 EXPECT_EQ(old_largest_change_id + 1, |
| 1626 fake_service_.about_resource().largest_change_id()); | 1628 fake_service_.about_resource().largest_change_id()); |
| 1627 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1629 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1628 } | 1630 } |
| 1629 | 1631 |
| 1630 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { | 1632 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectory) { |
| 1631 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1633 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 1632 "gdata/root_feed.json")); | 1634 "gdata/root_feed.json")); |
| 1633 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | 1635 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
| 1634 "gdata/account_metadata.json")); | 1636 "gdata/account_metadata.json")); |
| 1635 | 1637 |
| 1636 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1638 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1637 | 1639 |
| 1638 GDataErrorCode error = GDATA_OTHER_ERROR; | 1640 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1639 scoped_ptr<ResourceEntry> resource_entry; | 1641 scoped_ptr<ResourceEntry> resource_entry; |
| 1640 fake_service_.AddNewDirectory( | 1642 fake_service_.AddNewDirectory( |
| 1641 fake_service_.GetRootResourceId(), | 1643 fake_service_.GetRootResourceId(), |
| 1642 "new directory", | 1644 "new directory", |
| 1645 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1643 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1646 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1644 base::RunLoop().RunUntilIdle(); | 1647 base::RunLoop().RunUntilIdle(); |
| 1645 | 1648 |
| 1646 EXPECT_EQ(HTTP_CREATED, error); | 1649 EXPECT_EQ(HTTP_CREATED, error); |
| 1647 ASSERT_TRUE(resource_entry); | 1650 ASSERT_TRUE(resource_entry); |
| 1648 EXPECT_TRUE(resource_entry->is_folder()); | 1651 EXPECT_TRUE(resource_entry->is_folder()); |
| 1649 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1652 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
| 1650 EXPECT_EQ("new directory", resource_entry->title()); | 1653 EXPECT_EQ("new directory", resource_entry->title()); |
| 1651 EXPECT_TRUE(HasParent(resource_entry->resource_id(), | 1654 EXPECT_TRUE(HasParent(resource_entry->resource_id(), |
| 1652 fake_service_.GetRootResourceId())); | 1655 fake_service_.GetRootResourceId())); |
| 1653 // Should be incremented as a new directory was created. | 1656 // Should be incremented as a new directory was created. |
| 1654 EXPECT_EQ(old_largest_change_id + 1, | 1657 EXPECT_EQ(old_largest_change_id + 1, |
| 1655 fake_service_.about_resource().largest_change_id()); | 1658 fake_service_.about_resource().largest_change_id()); |
| 1656 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1659 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1657 } | 1660 } |
| 1658 | 1661 |
| 1659 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { | 1662 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToRootDirectoryOnEmptyFileSystem) { |
| 1660 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1663 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 1661 "gdata/empty_feed.json")); | 1664 "gdata/empty_feed.json")); |
| 1662 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | 1665 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
| 1663 "gdata/account_metadata.json")); | 1666 "gdata/account_metadata.json")); |
| 1664 | 1667 |
| 1665 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1668 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1666 | 1669 |
| 1667 GDataErrorCode error = GDATA_OTHER_ERROR; | 1670 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1668 scoped_ptr<ResourceEntry> resource_entry; | 1671 scoped_ptr<ResourceEntry> resource_entry; |
| 1669 fake_service_.AddNewDirectory( | 1672 fake_service_.AddNewDirectory( |
| 1670 fake_service_.GetRootResourceId(), | 1673 fake_service_.GetRootResourceId(), |
| 1671 "new directory", | 1674 "new directory", |
| 1675 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1672 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1676 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1673 base::RunLoop().RunUntilIdle(); | 1677 base::RunLoop().RunUntilIdle(); |
| 1674 | 1678 |
| 1675 EXPECT_EQ(HTTP_CREATED, error); | 1679 EXPECT_EQ(HTTP_CREATED, error); |
| 1676 ASSERT_TRUE(resource_entry); | 1680 ASSERT_TRUE(resource_entry); |
| 1677 EXPECT_TRUE(resource_entry->is_folder()); | 1681 EXPECT_TRUE(resource_entry->is_folder()); |
| 1678 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1682 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
| 1679 EXPECT_EQ("new directory", resource_entry->title()); | 1683 EXPECT_EQ("new directory", resource_entry->title()); |
| 1680 EXPECT_TRUE(HasParent(resource_entry->resource_id(), | 1684 EXPECT_TRUE(HasParent(resource_entry->resource_id(), |
| 1681 fake_service_.GetRootResourceId())); | 1685 fake_service_.GetRootResourceId())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1693 | 1697 |
| 1694 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1698 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1695 | 1699 |
| 1696 const std::string kParentResourceId = "folder:1_folder_resource_id"; | 1700 const std::string kParentResourceId = "folder:1_folder_resource_id"; |
| 1697 | 1701 |
| 1698 GDataErrorCode error = GDATA_OTHER_ERROR; | 1702 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1699 scoped_ptr<ResourceEntry> resource_entry; | 1703 scoped_ptr<ResourceEntry> resource_entry; |
| 1700 fake_service_.AddNewDirectory( | 1704 fake_service_.AddNewDirectory( |
| 1701 kParentResourceId, | 1705 kParentResourceId, |
| 1702 "new directory", | 1706 "new directory", |
| 1707 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1703 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1708 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1704 base::RunLoop().RunUntilIdle(); | 1709 base::RunLoop().RunUntilIdle(); |
| 1705 | 1710 |
| 1706 EXPECT_EQ(HTTP_CREATED, error); | 1711 EXPECT_EQ(HTTP_CREATED, error); |
| 1707 ASSERT_TRUE(resource_entry); | 1712 ASSERT_TRUE(resource_entry); |
| 1708 EXPECT_TRUE(resource_entry->is_folder()); | 1713 EXPECT_TRUE(resource_entry->is_folder()); |
| 1709 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1714 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
| 1710 EXPECT_EQ("new directory", resource_entry->title()); | 1715 EXPECT_EQ("new directory", resource_entry->title()); |
| 1711 EXPECT_TRUE(HasParent(resource_entry->resource_id(), kParentResourceId)); | 1716 EXPECT_TRUE(HasParent(resource_entry->resource_id(), kParentResourceId)); |
| 1712 // Should be incremented as a new directory was created. | 1717 // Should be incremented as a new directory was created. |
| 1713 EXPECT_EQ(old_largest_change_id + 1, | 1718 EXPECT_EQ(old_largest_change_id + 1, |
| 1714 fake_service_.about_resource().largest_change_id()); | 1719 fake_service_.about_resource().largest_change_id()); |
| 1715 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); | 1720 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1716 } | 1721 } |
| 1717 | 1722 |
| 1718 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { | 1723 TEST_F(FakeDriveServiceTest, AddNewDirectory_ToNonexistingDirectory) { |
| 1719 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1724 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 1720 "gdata/root_feed.json")); | 1725 "gdata/root_feed.json")); |
| 1721 | 1726 |
| 1722 const std::string kParentResourceId = "folder:nonexisting_resource_id"; | 1727 const std::string kParentResourceId = "folder:nonexisting_resource_id"; |
| 1723 | 1728 |
| 1724 GDataErrorCode error = GDATA_OTHER_ERROR; | 1729 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1725 scoped_ptr<ResourceEntry> resource_entry; | 1730 scoped_ptr<ResourceEntry> resource_entry; |
| 1726 fake_service_.AddNewDirectory( | 1731 fake_service_.AddNewDirectory( |
| 1727 kParentResourceId, | 1732 kParentResourceId, |
| 1728 "new directory", | 1733 "new directory", |
| 1734 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1729 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1735 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1730 base::RunLoop().RunUntilIdle(); | 1736 base::RunLoop().RunUntilIdle(); |
| 1731 | 1737 |
| 1732 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1738 EXPECT_EQ(HTTP_NOT_FOUND, error); |
| 1733 EXPECT_FALSE(resource_entry); | 1739 EXPECT_FALSE(resource_entry); |
| 1734 } | 1740 } |
| 1735 | 1741 |
| 1736 TEST_F(FakeDriveServiceTest, AddNewDirectory_Offline) { | 1742 TEST_F(FakeDriveServiceTest, AddNewDirectory_Offline) { |
| 1737 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1743 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 1738 "gdata/root_feed.json")); | 1744 "gdata/root_feed.json")); |
| 1739 fake_service_.set_offline(true); | 1745 fake_service_.set_offline(true); |
| 1740 | 1746 |
| 1741 GDataErrorCode error = GDATA_OTHER_ERROR; | 1747 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1742 scoped_ptr<ResourceEntry> resource_entry; | 1748 scoped_ptr<ResourceEntry> resource_entry; |
| 1743 fake_service_.AddNewDirectory( | 1749 fake_service_.AddNewDirectory( |
| 1744 fake_service_.GetRootResourceId(), | 1750 fake_service_.GetRootResourceId(), |
| 1745 "new directory", | 1751 "new directory", |
| 1752 DriveServiceInterface::AddNewDirectoryOptions(), |
| 1746 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1753 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1747 base::RunLoop().RunUntilIdle(); | 1754 base::RunLoop().RunUntilIdle(); |
| 1748 | 1755 |
| 1749 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1756 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 1750 EXPECT_FALSE(resource_entry); | 1757 EXPECT_FALSE(resource_entry); |
| 1751 } | 1758 } |
| 1752 | 1759 |
| 1753 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) { | 1760 TEST_F(FakeDriveServiceTest, InitiateUploadNewFile_Offline) { |
| 1754 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1761 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 1755 "gdata/root_feed.json")); | 1762 "gdata/root_feed.json")); |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2362 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 2369 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 2363 base::RunLoop().RunUntilIdle(); | 2370 base::RunLoop().RunUntilIdle(); |
| 2364 | 2371 |
| 2365 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 2372 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
| 2366 EXPECT_FALSE(resource_entry); | 2373 EXPECT_FALSE(resource_entry); |
| 2367 } | 2374 } |
| 2368 | 2375 |
| 2369 } // namespace | 2376 } // namespace |
| 2370 | 2377 |
| 2371 } // namespace drive | 2378 } // namespace drive |
| OLD | NEW |