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/google_apis/fake_drive_service.h" | 5 #include "chrome/browser/google_apis/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 1753 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1764 const int64 kContentSize = 123; | 1764 const int64 kContentSize = 123; |
1765 const std::string kTitle = "new file"; | 1765 const std::string kTitle = "new file"; |
1766 | 1766 |
1767 GDataErrorCode error = GDATA_OTHER_ERROR; | 1767 GDataErrorCode error = GDATA_OTHER_ERROR; |
1768 scoped_ptr<ResourceEntry> resource_entry; | 1768 scoped_ptr<ResourceEntry> resource_entry; |
1769 fake_service_.AddNewFile( | 1769 fake_service_.AddNewFile( |
1770 kContentType, | 1770 kContentType, |
1771 kContentSize, | 1771 kContentSize, |
1772 fake_service_.GetRootResourceId(), | 1772 fake_service_.GetRootResourceId(), |
1773 kTitle, | 1773 kTitle, |
| 1774 false, // shared_with_me |
1774 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1775 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1775 message_loop_.RunUntilIdle(); | 1776 message_loop_.RunUntilIdle(); |
1776 | 1777 |
1777 EXPECT_EQ(HTTP_CREATED, error); | 1778 EXPECT_EQ(HTTP_CREATED, error); |
1778 ASSERT_TRUE(resource_entry); | 1779 ASSERT_TRUE(resource_entry); |
1779 EXPECT_TRUE(resource_entry->is_file()); | 1780 EXPECT_TRUE(resource_entry->is_file()); |
1780 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); | 1781 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); |
1781 EXPECT_EQ(kContentSize, resource_entry->file_size()); | 1782 EXPECT_EQ(kContentSize, resource_entry->file_size()); |
1782 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1783 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
1783 EXPECT_EQ(kTitle, resource_entry->title()); | 1784 EXPECT_EQ(kTitle, resource_entry->title()); |
(...skipping 16 matching lines...) Expand all Loading... |
1800 const int64 kContentSize = 123; | 1801 const int64 kContentSize = 123; |
1801 const std::string kTitle = "new file"; | 1802 const std::string kTitle = "new file"; |
1802 | 1803 |
1803 GDataErrorCode error = GDATA_OTHER_ERROR; | 1804 GDataErrorCode error = GDATA_OTHER_ERROR; |
1804 scoped_ptr<ResourceEntry> resource_entry; | 1805 scoped_ptr<ResourceEntry> resource_entry; |
1805 fake_service_.AddNewFile( | 1806 fake_service_.AddNewFile( |
1806 kContentType, | 1807 kContentType, |
1807 kContentSize, | 1808 kContentSize, |
1808 fake_service_.GetRootResourceId(), | 1809 fake_service_.GetRootResourceId(), |
1809 kTitle, | 1810 kTitle, |
| 1811 false, // shared_with_me |
1810 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1812 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1811 message_loop_.RunUntilIdle(); | 1813 message_loop_.RunUntilIdle(); |
1812 | 1814 |
1813 EXPECT_EQ(HTTP_CREATED, error); | 1815 EXPECT_EQ(HTTP_CREATED, error); |
1814 ASSERT_TRUE(resource_entry); | 1816 ASSERT_TRUE(resource_entry); |
1815 EXPECT_TRUE(resource_entry->is_file()); | 1817 EXPECT_TRUE(resource_entry->is_file()); |
1816 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); | 1818 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); |
1817 EXPECT_EQ(kContentSize, resource_entry->file_size()); | 1819 EXPECT_EQ(kContentSize, resource_entry->file_size()); |
1818 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1820 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
1819 EXPECT_EQ(kTitle, resource_entry->title()); | 1821 EXPECT_EQ(kTitle, resource_entry->title()); |
(...skipping 17 matching lines...) Expand all Loading... |
1837 const std::string kTitle = "new file"; | 1839 const std::string kTitle = "new file"; |
1838 const std::string kParentResourceId = "folder:1_folder_resource_id"; | 1840 const std::string kParentResourceId = "folder:1_folder_resource_id"; |
1839 | 1841 |
1840 GDataErrorCode error = GDATA_OTHER_ERROR; | 1842 GDataErrorCode error = GDATA_OTHER_ERROR; |
1841 scoped_ptr<ResourceEntry> resource_entry; | 1843 scoped_ptr<ResourceEntry> resource_entry; |
1842 fake_service_.AddNewFile( | 1844 fake_service_.AddNewFile( |
1843 kContentType, | 1845 kContentType, |
1844 kContentSize, | 1846 kContentSize, |
1845 kParentResourceId, | 1847 kParentResourceId, |
1846 kTitle, | 1848 kTitle, |
| 1849 false, // shared_with_me |
1847 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1850 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1848 message_loop_.RunUntilIdle(); | 1851 message_loop_.RunUntilIdle(); |
1849 | 1852 |
1850 EXPECT_EQ(HTTP_CREATED, error); | 1853 EXPECT_EQ(HTTP_CREATED, error); |
1851 ASSERT_TRUE(resource_entry); | 1854 ASSERT_TRUE(resource_entry); |
1852 EXPECT_TRUE(resource_entry->is_file()); | 1855 EXPECT_TRUE(resource_entry->is_file()); |
1853 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); | 1856 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); |
1854 EXPECT_EQ(kContentSize, resource_entry->file_size()); | 1857 EXPECT_EQ(kContentSize, resource_entry->file_size()); |
1855 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); | 1858 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
1856 EXPECT_EQ(kTitle, resource_entry->title()); | 1859 EXPECT_EQ(kTitle, resource_entry->title()); |
(...skipping 12 matching lines...) Expand all Loading... |
1869 const std::string kTitle = "new file"; | 1872 const std::string kTitle = "new file"; |
1870 const std::string kParentResourceId = "folder:nonexisting_resource_id"; | 1873 const std::string kParentResourceId = "folder:nonexisting_resource_id"; |
1871 | 1874 |
1872 GDataErrorCode error = GDATA_OTHER_ERROR; | 1875 GDataErrorCode error = GDATA_OTHER_ERROR; |
1873 scoped_ptr<ResourceEntry> resource_entry; | 1876 scoped_ptr<ResourceEntry> resource_entry; |
1874 fake_service_.AddNewFile( | 1877 fake_service_.AddNewFile( |
1875 kContentType, | 1878 kContentType, |
1876 kContentSize, | 1879 kContentSize, |
1877 kParentResourceId, | 1880 kParentResourceId, |
1878 kTitle, | 1881 kTitle, |
| 1882 false, // shared_with_me |
1879 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1883 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1880 message_loop_.RunUntilIdle(); | 1884 message_loop_.RunUntilIdle(); |
1881 | 1885 |
1882 EXPECT_EQ(HTTP_NOT_FOUND, error); | 1886 EXPECT_EQ(HTTP_NOT_FOUND, error); |
1883 EXPECT_FALSE(resource_entry); | 1887 EXPECT_FALSE(resource_entry); |
1884 } | 1888 } |
1885 | 1889 |
1886 TEST_F(FakeDriveServiceTest, AddNewFile_Offline) { | 1890 TEST_F(FakeDriveServiceTest, AddNewFile_Offline) { |
1887 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1891 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
1888 "chromeos/gdata/root_feed.json")); | 1892 "chromeos/gdata/root_feed.json")); |
1889 fake_service_.set_offline(true); | 1893 fake_service_.set_offline(true); |
1890 | 1894 |
1891 const std::string kContentType = "text/plain"; | 1895 const std::string kContentType = "text/plain"; |
1892 const int64 kContentSize = 123; | 1896 const int64 kContentSize = 123; |
1893 const std::string kTitle = "new file"; | 1897 const std::string kTitle = "new file"; |
1894 | 1898 |
1895 GDataErrorCode error = GDATA_OTHER_ERROR; | 1899 GDataErrorCode error = GDATA_OTHER_ERROR; |
1896 scoped_ptr<ResourceEntry> resource_entry; | 1900 scoped_ptr<ResourceEntry> resource_entry; |
1897 fake_service_.AddNewFile( | 1901 fake_service_.AddNewFile( |
1898 kContentType, | 1902 kContentType, |
1899 kContentSize, | 1903 kContentSize, |
1900 fake_service_.GetRootResourceId(), | 1904 fake_service_.GetRootResourceId(), |
1901 kTitle, | 1905 kTitle, |
| 1906 false, // shared_with_me |
1902 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 1907 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1903 message_loop_.RunUntilIdle(); | 1908 message_loop_.RunUntilIdle(); |
1904 | 1909 |
1905 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 1910 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1906 EXPECT_FALSE(resource_entry); | 1911 EXPECT_FALSE(resource_entry); |
1907 } | 1912 } |
1908 | 1913 |
| 1914 TEST_F(FakeDriveServiceTest, AddNewFile_SharedWithMeLabel) { |
| 1915 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
| 1916 "chromeos/gdata/root_feed.json")); |
| 1917 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
| 1918 "chromeos/gdata/account_metadata.json")); |
| 1919 |
| 1920 const std::string kContentType = "text/plain"; |
| 1921 const int64 kContentSize = 123; |
| 1922 const std::string kTitle = "new file"; |
| 1923 |
| 1924 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
| 1925 |
| 1926 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 1927 scoped_ptr<ResourceEntry> resource_entry; |
| 1928 fake_service_.AddNewFile( |
| 1929 kContentType, |
| 1930 kContentSize, |
| 1931 fake_service_.GetRootResourceId(), |
| 1932 kTitle, |
| 1933 true, // shared_with_me |
| 1934 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
| 1935 message_loop_.RunUntilIdle(); |
| 1936 |
| 1937 EXPECT_EQ(HTTP_CREATED, error); |
| 1938 ASSERT_TRUE(resource_entry); |
| 1939 EXPECT_TRUE(resource_entry->is_file()); |
| 1940 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); |
| 1941 EXPECT_EQ(kContentSize, resource_entry->file_size()); |
| 1942 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); |
| 1943 EXPECT_EQ(kTitle, resource_entry->title()); |
| 1944 EXPECT_TRUE(HasParent(resource_entry->resource_id(), |
| 1945 fake_service_.GetRootResourceId())); |
| 1946 ASSERT_EQ(1U, resource_entry->labels().size()); |
| 1947 EXPECT_EQ("shared-with-me", resource_entry->labels()[0]); |
| 1948 // Should be incremented as a new directory was created. |
| 1949 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); |
| 1950 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); |
| 1951 } |
| 1952 |
1909 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_ExistingFile) { | 1953 TEST_F(FakeDriveServiceTest, SetLastModifiedTime_ExistingFile) { |
1910 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1954 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
1911 "chromeos/gdata/root_feed.json")); | 1955 "chromeos/gdata/root_feed.json")); |
1912 | 1956 |
1913 const std::string kResourceId = "file:2_file_resource_id"; | 1957 const std::string kResourceId = "file:2_file_resource_id"; |
1914 base::Time time; | 1958 base::Time time; |
1915 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); | 1959 ASSERT_TRUE(base::Time::FromString("1 April 2013 12:34:56", &time)); |
1916 | 1960 |
1917 GDataErrorCode error = GDATA_OTHER_ERROR; | 1961 GDataErrorCode error = GDATA_OTHER_ERROR; |
1918 scoped_ptr<ResourceEntry> resource_entry; | 1962 scoped_ptr<ResourceEntry> resource_entry; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1964 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 2008 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
1965 message_loop_.RunUntilIdle(); | 2009 message_loop_.RunUntilIdle(); |
1966 | 2010 |
1967 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 2011 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
1968 EXPECT_FALSE(resource_entry); | 2012 EXPECT_FALSE(resource_entry); |
1969 } | 2013 } |
1970 | 2014 |
1971 } // namespace | 2015 } // namespace |
1972 | 2016 |
1973 } // namespace google_apis | 2017 } // namespace google_apis |
OLD | NEW |