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

Side by Side Diff: chrome/browser/drive/fake_drive_service_unittest.cc

Issue 17140009: Support contents upload on FakeDriveService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: style fix Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/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"
11 #include "base/files/scoped_temp_dir.h" 11 #include "base/files/scoped_temp_dir.h"
12 #include "base/md5.h"
12 #include "base/run_loop.h" 13 #include "base/run_loop.h"
13 #include "base/stl_util.h" 14 #include "base/stl_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
16 #include "chrome/browser/google_apis/drive_api_parser.h" 17 #include "chrome/browser/google_apis/drive_api_parser.h"
17 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
18 #include "chrome/browser/google_apis/gdata_wapi_requests.h" 19 #include "chrome/browser/google_apis/gdata_wapi_requests.h"
19 #include "chrome/browser/google_apis/test_util.h" 20 #include "chrome/browser/google_apis/test_util.h"
20 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 base::FilePath(), 1704 base::FilePath(),
1704 test_util::CreateCopyResultCallback(&response, &entry), 1705 test_util::CreateCopyResultCallback(&response, &entry),
1705 ProgressCallback()); 1706 ProgressCallback());
1706 base::RunLoop().RunUntilIdle(); 1707 base::RunLoop().RunUntilIdle();
1707 1708
1708 EXPECT_EQ(HTTP_NOT_FOUND, response.code); 1709 EXPECT_EQ(HTTP_NOT_FOUND, response.code);
1709 EXPECT_FALSE(entry.get()); 1710 EXPECT_FALSE(entry.get());
1710 } 1711 }
1711 1712
1712 TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) { 1713 TEST_F(FakeDriveServiceTest, ResumeUpload_ExistingFile) {
1714 base::ScopedTempDir temp_dir;
1715 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1716 base::FilePath local_file_path =
1717 temp_dir.path().Append(FILE_PATH_LITERAL("File 1.txt"));
1718 std::string contents("hogefugapiyo");
1719 test_util::WriteStringToFile(local_file_path, contents);
hashimoto 2013/06/20 10:17:42 nit: Should better EXPECT_TRUE/ASSERT_TRUE the res
tzik 2013/06/20 13:37:22 Done.
1720
1713 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 1721 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1714 "chromeos/gdata/root_feed.json")); 1722 "chromeos/gdata/root_feed.json"));
1715 1723
1716 GDataErrorCode error = GDATA_OTHER_ERROR; 1724 GDataErrorCode error = GDATA_OTHER_ERROR;
1717 GURL upload_location; 1725 GURL upload_location;
1718 fake_service_.InitiateUploadExistingFile( 1726 fake_service_.InitiateUploadExistingFile(
1719 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")), 1727 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")),
1720 "text/plain", 1728 "text/plain",
1721 15, 1729 contents.size(),
1722 "file:2_file_resource_id", 1730 "file:2_file_resource_id",
1723 "\"HhMOFgxXHit7ImBr\"", 1731 "\"HhMOFgxXHit7ImBr\"",
1724 test_util::CreateCopyResultCallback(&error, &upload_location)); 1732 test_util::CreateCopyResultCallback(&error, &upload_location));
1725 base::RunLoop().RunUntilIdle(); 1733 base::RunLoop().RunUntilIdle();
1726 1734
1727 ASSERT_EQ(HTTP_SUCCESS, error); 1735 ASSERT_EQ(HTTP_SUCCESS, error);
1728 1736
1729 UploadRangeResponse response; 1737 UploadRangeResponse response;
1730 scoped_ptr<ResourceEntry> entry; 1738 scoped_ptr<ResourceEntry> entry;
1731 std::vector<test_util::ProgressInfo> upload_progress_values; 1739 std::vector<test_util::ProgressInfo> upload_progress_values;
1732 fake_service_.ResumeUpload( 1740 fake_service_.ResumeUpload(
1733 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")), 1741 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")),
1734 upload_location, 1742 upload_location,
1735 0, 13, 15, "text/plain", 1743 0, contents.size() / 2, contents.size(), "text/plain",
1736 base::FilePath(), 1744 local_file_path,
1737 test_util::CreateCopyResultCallback(&response, &entry), 1745 test_util::CreateCopyResultCallback(&response, &entry),
1738 base::Bind(&test_util::AppendProgressCallbackResult, 1746 base::Bind(&test_util::AppendProgressCallbackResult,
1739 &upload_progress_values)); 1747 &upload_progress_values));
1740 base::RunLoop().RunUntilIdle(); 1748 base::RunLoop().RunUntilIdle();
1741 1749
1742 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1750 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1743 EXPECT_FALSE(entry.get()); 1751 EXPECT_FALSE(entry.get());
1744 ASSERT_TRUE(!upload_progress_values.empty()); 1752 ASSERT_TRUE(!upload_progress_values.empty());
1745 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); 1753 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
1746 EXPECT_LE(0, upload_progress_values.front().first); 1754 EXPECT_LE(0, upload_progress_values.front().first);
1747 EXPECT_GE(13, upload_progress_values.back().first); 1755 EXPECT_GE(static_cast<int64>(contents.size() / 2),
1756 upload_progress_values.back().first);
1748 1757
1749 upload_progress_values.clear(); 1758 upload_progress_values.clear();
1750 fake_service_.ResumeUpload( 1759 fake_service_.ResumeUpload(
1751 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")), 1760 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")),
1752 upload_location, 1761 upload_location,
1753 13, 15, 15, "text/plain", 1762 contents.size() / 2, contents.size(), contents.size(), "text/plain",
1754 base::FilePath(), 1763 local_file_path,
1755 test_util::CreateCopyResultCallback(&response, &entry), 1764 test_util::CreateCopyResultCallback(&response, &entry),
1756 base::Bind(&test_util::AppendProgressCallbackResult, 1765 base::Bind(&test_util::AppendProgressCallbackResult,
1757 &upload_progress_values)); 1766 &upload_progress_values));
1758 base::RunLoop().RunUntilIdle(); 1767 base::RunLoop().RunUntilIdle();
1759 1768
1760 EXPECT_EQ(HTTP_SUCCESS, response.code); 1769 EXPECT_EQ(HTTP_SUCCESS, response.code);
1761 EXPECT_TRUE(entry.get()); 1770 EXPECT_TRUE(entry.get());
1762 EXPECT_EQ(15L, entry->file_size()); 1771 EXPECT_EQ(static_cast<int64>(contents.size()),
1772 entry->file_size());
1763 EXPECT_TRUE(Exists(entry->resource_id())); 1773 EXPECT_TRUE(Exists(entry->resource_id()));
1764 ASSERT_TRUE(!upload_progress_values.empty()); 1774 ASSERT_TRUE(!upload_progress_values.empty());
1765 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); 1775 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
1766 EXPECT_LE(0, upload_progress_values.front().first); 1776 EXPECT_LE(0, upload_progress_values.front().first);
1767 EXPECT_GE(2, upload_progress_values.back().first); 1777 EXPECT_GE(static_cast<int64>(contents.size() - contents.size() / 2),
1778 upload_progress_values.back().first);
1779 EXPECT_EQ(base::MD5String(contents), entry->file_md5());
1768 } 1780 }
1769 1781
1770 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) { 1782 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) {
1783 base::ScopedTempDir temp_dir;
1784 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
1785 base::FilePath local_file_path =
1786 temp_dir.path().Append(FILE_PATH_LITERAL("new file.foo"));
1787 std::string contents("hogefugapiyo");
1788 test_util::WriteStringToFile(local_file_path, contents);
1789
1771 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 1790 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1772 "chromeos/gdata/root_feed.json")); 1791 "chromeos/gdata/root_feed.json"));
1773 1792
1774 GDataErrorCode error = GDATA_OTHER_ERROR; 1793 GDataErrorCode error = GDATA_OTHER_ERROR;
1775 GURL upload_location; 1794 GURL upload_location;
1776 fake_service_.InitiateUploadNewFile( 1795 fake_service_.InitiateUploadNewFile(
1777 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), 1796 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")),
1778 "test/foo", 1797 "test/foo",
1779 15, 1798 contents.size(),
1780 "folder:1_folder_resource_id", 1799 "folder:1_folder_resource_id",
1781 "new file.foo", 1800 "new file.foo",
1782 test_util::CreateCopyResultCallback(&error, &upload_location)); 1801 test_util::CreateCopyResultCallback(&error, &upload_location));
1783 base::RunLoop().RunUntilIdle(); 1802 base::RunLoop().RunUntilIdle();
1784 1803
1785 EXPECT_EQ(HTTP_SUCCESS, error); 1804 EXPECT_EQ(HTTP_SUCCESS, error);
1786 EXPECT_FALSE(upload_location.is_empty()); 1805 EXPECT_FALSE(upload_location.is_empty());
1787 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), 1806 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"),
1788 upload_location); 1807 upload_location);
1789 1808
1790 UploadRangeResponse response; 1809 UploadRangeResponse response;
1791 scoped_ptr<ResourceEntry> entry; 1810 scoped_ptr<ResourceEntry> entry;
1792 std::vector<test_util::ProgressInfo> upload_progress_values; 1811 std::vector<test_util::ProgressInfo> upload_progress_values;
1793 fake_service_.ResumeUpload( 1812 fake_service_.ResumeUpload(
1794 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), 1813 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")),
1795 upload_location, 1814 upload_location,
1796 0, 13, 15, "test/foo", 1815 0, contents.size() / 2, contents.size(), "test/foo",
1797 base::FilePath(), 1816 local_file_path,
1798 test_util::CreateCopyResultCallback(&response, &entry), 1817 test_util::CreateCopyResultCallback(&response, &entry),
1799 base::Bind(&test_util::AppendProgressCallbackResult, 1818 base::Bind(&test_util::AppendProgressCallbackResult,
1800 &upload_progress_values)); 1819 &upload_progress_values));
1801 base::RunLoop().RunUntilIdle(); 1820 base::RunLoop().RunUntilIdle();
1802 1821
1803 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1822 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1804 EXPECT_FALSE(entry.get()); 1823 EXPECT_FALSE(entry.get());
1805 ASSERT_TRUE(!upload_progress_values.empty()); 1824 ASSERT_TRUE(!upload_progress_values.empty());
1806 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); 1825 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
1807 EXPECT_LE(0, upload_progress_values.front().first); 1826 EXPECT_LE(0, upload_progress_values.front().first);
1808 EXPECT_GE(13, upload_progress_values.back().first); 1827 EXPECT_GE(static_cast<int64>(contents.size() / 2),
1828 upload_progress_values.back().first);
1809 1829
1810 upload_progress_values.clear(); 1830 upload_progress_values.clear();
1811 fake_service_.ResumeUpload( 1831 fake_service_.ResumeUpload(
1812 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), 1832 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")),
1813 upload_location, 1833 upload_location,
1814 13, 15, 15, "test/foo", 1834 contents.size() / 2, contents.size(), contents.size(), "test/foo",
1815 base::FilePath(), 1835 local_file_path,
1816 test_util::CreateCopyResultCallback(&response, &entry), 1836 test_util::CreateCopyResultCallback(&response, &entry),
1817 base::Bind(&test_util::AppendProgressCallbackResult, 1837 base::Bind(&test_util::AppendProgressCallbackResult,
1818 &upload_progress_values)); 1838 &upload_progress_values));
1819 base::RunLoop().RunUntilIdle(); 1839 base::RunLoop().RunUntilIdle();
1820 1840
1821 EXPECT_EQ(HTTP_CREATED, response.code); 1841 EXPECT_EQ(HTTP_CREATED, response.code);
1822 EXPECT_TRUE(entry.get()); 1842 EXPECT_TRUE(entry.get());
1823 EXPECT_EQ(15L, entry->file_size()); 1843 EXPECT_EQ(static_cast<int64>(contents.size()), entry->file_size());
1824 EXPECT_TRUE(Exists(entry->resource_id())); 1844 EXPECT_TRUE(Exists(entry->resource_id()));
1825 ASSERT_TRUE(!upload_progress_values.empty()); 1845 ASSERT_TRUE(!upload_progress_values.empty());
1826 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); 1846 EXPECT_TRUE(base::STLIsSorted(upload_progress_values));
1827 EXPECT_LE(0, upload_progress_values.front().first); 1847 EXPECT_LE(0, upload_progress_values.front().first);
1828 EXPECT_GE(2, upload_progress_values.back().first); 1848 EXPECT_GE(static_cast<int64>(contents.size() - contents.size() / 2),
1849 upload_progress_values.back().first);
1850 EXPECT_EQ(base::MD5String(contents), entry->file_md5());
1829 } 1851 }
1830 1852
1831 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) { 1853 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) {
1832 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 1854 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1833 "chromeos/gdata/root_feed.json")); 1855 "chromeos/gdata/root_feed.json"));
1834 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( 1856 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1835 "chromeos/gdata/account_metadata.json")); 1857 "chromeos/gdata/account_metadata.json"));
1836 1858
1837 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1859 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1838 1860
(...skipping 17 matching lines...) Expand all
1856 EXPECT_TRUE(resource_entry->is_file()); 1878 EXPECT_TRUE(resource_entry->is_file());
1857 EXPECT_EQ(kContentType, resource_entry->content_mime_type()); 1879 EXPECT_EQ(kContentType, resource_entry->content_mime_type());
1858 EXPECT_EQ(static_cast<int64>(kContentData.size()), 1880 EXPECT_EQ(static_cast<int64>(kContentData.size()),
1859 resource_entry->file_size()); 1881 resource_entry->file_size());
1860 EXPECT_EQ("resource_id_1", resource_entry->resource_id()); 1882 EXPECT_EQ("resource_id_1", resource_entry->resource_id());
1861 EXPECT_EQ(kTitle, resource_entry->title()); 1883 EXPECT_EQ(kTitle, resource_entry->title());
1862 EXPECT_TRUE(HasParent(resource_entry->resource_id(), 1884 EXPECT_TRUE(HasParent(resource_entry->resource_id(),
1863 fake_service_.GetRootResourceId())); 1885 fake_service_.GetRootResourceId()));
1864 // Should be incremented as a new directory was created. 1886 // Should be incremented as a new directory was created.
1865 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp()); 1887 EXPECT_EQ(old_largest_change_id + 1, fake_service_.largest_changestamp());
1866 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource()); 1888 EXPECT_EQ(old_largest_change_id + 1, GetLargestChangeByAboutResource());
hashimoto 2013/06/20 10:17:42 Could you add MD5 checks for AddNewFile()?
tzik 2013/06/20 13:37:22 Done.
1867 } 1889 }
1868 1890
1869 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectoryOnEmptyFileSystem) { 1891 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectoryOnEmptyFileSystem) {
1870 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( 1892 ASSERT_TRUE(fake_service_.LoadResourceListForWapi(
1871 "chromeos/gdata/empty_feed.json")); 1893 "chromeos/gdata/empty_feed.json"));
1872 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( 1894 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi(
1873 "chromeos/gdata/account_metadata.json")); 1895 "chromeos/gdata/account_metadata.json"));
1874 1896
1875 int64 old_largest_change_id = GetLargestChangeByAboutResource(); 1897 int64 old_largest_change_id = GetLargestChangeByAboutResource();
1876 1898
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2088 test_util::CreateCopyResultCallback(&error, &resource_entry)); 2110 test_util::CreateCopyResultCallback(&error, &resource_entry));
2089 base::RunLoop().RunUntilIdle(); 2111 base::RunLoop().RunUntilIdle();
2090 2112
2091 EXPECT_EQ(GDATA_NO_CONNECTION, error); 2113 EXPECT_EQ(GDATA_NO_CONNECTION, error);
2092 EXPECT_FALSE(resource_entry); 2114 EXPECT_FALSE(resource_entry);
2093 } 2115 }
2094 2116
2095 } // namespace 2117 } // namespace
2096 2118
2097 } // namespace drive 2119 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698