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 | 9 |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
11 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/stl_util.h" |
12 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
13 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/google_apis/drive_api_parser.h" | 16 #include "chrome/browser/google_apis/drive_api_parser.h" |
15 #include "chrome/browser/google_apis/gdata_wapi_operations.h" | 17 #include "chrome/browser/google_apis/gdata_wapi_operations.h" |
16 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
17 #include "chrome/browser/google_apis/test_util.h" | 19 #include "chrome/browser/google_apis/test_util.h" |
18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
21 | 23 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 test_util::CreateCopyResultCallback(&error, &about_resource)); | 84 test_util::CreateCopyResultCallback(&error, &about_resource)); |
83 message_loop_.RunUntilIdle(); | 85 message_loop_.RunUntilIdle(); |
84 return about_resource->largest_change_id(); | 86 return about_resource->largest_change_id(); |
85 } | 87 } |
86 | 88 |
87 MessageLoopForUI message_loop_; | 89 MessageLoopForUI message_loop_; |
88 content::TestBrowserThread ui_thread_; | 90 content::TestBrowserThread ui_thread_; |
89 FakeDriveService fake_service_; | 91 FakeDriveService fake_service_; |
90 }; | 92 }; |
91 | 93 |
| 94 void AppendProgressCallbackResult(std::vector<int64>* values, int64 progress) { |
| 95 values->push_back(progress); |
| 96 } |
| 97 |
92 TEST_F(FakeDriveServiceTest, GetResourceList_All) { | 98 TEST_F(FakeDriveServiceTest, GetResourceList_All) { |
93 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 99 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
94 "chromeos/gdata/root_feed.json")); | 100 "chromeos/gdata/root_feed.json")); |
95 | 101 |
96 GDataErrorCode error = GDATA_OTHER_ERROR; | 102 GDataErrorCode error = GDATA_OTHER_ERROR; |
97 scoped_ptr<ResourceList> resource_list; | 103 scoped_ptr<ResourceList> resource_list; |
98 fake_service_.GetResourceList( | 104 fake_service_.GetResourceList( |
99 GURL(), | 105 GURL(), |
100 0, // start_changestamp | 106 0, // start_changestamp |
101 std::string(), // search_query | 107 std::string(), // search_query |
(...skipping 1784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1886 15, | 1892 15, |
1887 "file:2_file_resource_id", | 1893 "file:2_file_resource_id", |
1888 "\"HhMOFgxXHit7ImBr\"", | 1894 "\"HhMOFgxXHit7ImBr\"", |
1889 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1895 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1890 message_loop_.RunUntilIdle(); | 1896 message_loop_.RunUntilIdle(); |
1891 | 1897 |
1892 ASSERT_EQ(HTTP_SUCCESS, error); | 1898 ASSERT_EQ(HTTP_SUCCESS, error); |
1893 | 1899 |
1894 UploadRangeResponse response; | 1900 UploadRangeResponse response; |
1895 scoped_ptr<ResourceEntry> entry; | 1901 scoped_ptr<ResourceEntry> entry; |
| 1902 std::vector<int64> upload_progress_values; |
1896 fake_service_.ResumeUpload( | 1903 fake_service_.ResumeUpload( |
1897 UPLOAD_EXISTING_FILE, | 1904 UPLOAD_EXISTING_FILE, |
1898 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")), | 1905 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")), |
1899 upload_location, | 1906 upload_location, |
1900 0, 13, 15, "text/plain", | 1907 0, 13, 15, "text/plain", |
1901 scoped_refptr<net::IOBuffer>(), | 1908 scoped_refptr<net::IOBuffer>(), |
1902 test_util::CreateCopyResultCallback(&response, &entry), | 1909 test_util::CreateCopyResultCallback(&response, &entry), |
1903 ProgressCallback()); | 1910 base::Bind(&AppendProgressCallbackResult, &upload_progress_values)); |
1904 message_loop_.RunUntilIdle(); | 1911 message_loop_.RunUntilIdle(); |
1905 | 1912 |
1906 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1913 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
1907 EXPECT_FALSE(entry.get()); | 1914 EXPECT_FALSE(entry.get()); |
1908 | 1915 |
1909 fake_service_.ResumeUpload( | 1916 fake_service_.ResumeUpload( |
1910 UPLOAD_EXISTING_FILE, | 1917 UPLOAD_EXISTING_FILE, |
1911 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")), | 1918 base::FilePath(FILE_PATH_LITERAL("drive/File 1.txt")), |
1912 upload_location, | 1919 upload_location, |
1913 14, 15, 15, "text/plain", | 1920 14, 15, 15, "text/plain", |
1914 scoped_refptr<net::IOBuffer>(), | 1921 scoped_refptr<net::IOBuffer>(), |
1915 test_util::CreateCopyResultCallback(&response, &entry), | 1922 test_util::CreateCopyResultCallback(&response, &entry), |
1916 ProgressCallback()); | 1923 base::Bind(&AppendProgressCallbackResult, &upload_progress_values)); |
1917 message_loop_.RunUntilIdle(); | 1924 message_loop_.RunUntilIdle(); |
1918 | 1925 |
1919 EXPECT_EQ(HTTP_SUCCESS, response.code); | 1926 EXPECT_EQ(HTTP_SUCCESS, response.code); |
1920 EXPECT_TRUE(entry.get()); | 1927 EXPECT_TRUE(entry.get()); |
1921 EXPECT_EQ(15L, entry->file_size()); | 1928 EXPECT_EQ(15L, entry->file_size()); |
1922 EXPECT_TRUE(Exists(entry->resource_id())); | 1929 EXPECT_TRUE(Exists(entry->resource_id())); |
| 1930 ASSERT_TRUE(!upload_progress_values.empty()); |
| 1931 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); |
| 1932 EXPECT_GE(upload_progress_values.front(), 0); |
| 1933 EXPECT_LE(upload_progress_values.back(), entry->file_size()); |
1923 } | 1934 } |
1924 | 1935 |
1925 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) { | 1936 TEST_F(FakeDriveServiceTest, ResumeUpload_NewFile) { |
1926 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1937 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
1927 "chromeos/gdata/root_feed.json")); | 1938 "chromeos/gdata/root_feed.json")); |
1928 | 1939 |
1929 GDataErrorCode error = GDATA_OTHER_ERROR; | 1940 GDataErrorCode error = GDATA_OTHER_ERROR; |
1930 GURL upload_location; | 1941 GURL upload_location; |
1931 fake_service_.InitiateUploadNewFile( | 1942 fake_service_.InitiateUploadNewFile( |
1932 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), | 1943 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), |
1933 "test/foo", | 1944 "test/foo", |
1934 15, | 1945 15, |
1935 "folder:1_folder_resource_id", | 1946 "folder:1_folder_resource_id", |
1936 "new file.foo", | 1947 "new file.foo", |
1937 test_util::CreateCopyResultCallback(&error, &upload_location)); | 1948 test_util::CreateCopyResultCallback(&error, &upload_location)); |
1938 message_loop_.RunUntilIdle(); | 1949 message_loop_.RunUntilIdle(); |
1939 | 1950 |
1940 EXPECT_EQ(HTTP_SUCCESS, error); | 1951 EXPECT_EQ(HTTP_SUCCESS, error); |
1941 EXPECT_FALSE(upload_location.is_empty()); | 1952 EXPECT_FALSE(upload_location.is_empty()); |
1942 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), | 1953 EXPECT_NE(GURL("https://1_folder_resumable_create_media_link"), |
1943 upload_location); | 1954 upload_location); |
1944 | 1955 |
1945 UploadRangeResponse response; | 1956 UploadRangeResponse response; |
1946 scoped_ptr<ResourceEntry> entry; | 1957 scoped_ptr<ResourceEntry> entry; |
| 1958 std::vector<int64> upload_progress_values; |
1947 fake_service_.ResumeUpload( | 1959 fake_service_.ResumeUpload( |
1948 UPLOAD_NEW_FILE, | 1960 UPLOAD_NEW_FILE, |
1949 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), | 1961 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), |
1950 upload_location, | 1962 upload_location, |
1951 0, 13, 15, "test/foo", | 1963 0, 13, 15, "test/foo", |
1952 scoped_refptr<net::IOBuffer>(), | 1964 scoped_refptr<net::IOBuffer>(), |
1953 test_util::CreateCopyResultCallback(&response, &entry), | 1965 test_util::CreateCopyResultCallback(&response, &entry), |
1954 ProgressCallback()); | 1966 base::Bind(&AppendProgressCallbackResult, &upload_progress_values)); |
1955 message_loop_.RunUntilIdle(); | 1967 message_loop_.RunUntilIdle(); |
1956 | 1968 |
1957 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); | 1969 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); |
1958 EXPECT_FALSE(entry.get()); | 1970 EXPECT_FALSE(entry.get()); |
1959 | 1971 |
1960 fake_service_.ResumeUpload( | 1972 fake_service_.ResumeUpload( |
1961 UPLOAD_NEW_FILE, | 1973 UPLOAD_NEW_FILE, |
1962 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), | 1974 base::FilePath(FILE_PATH_LITERAL("drive/Directory 1/new file.foo")), |
1963 upload_location, | 1975 upload_location, |
1964 14, 15, 15, "test/foo", | 1976 14, 15, 15, "test/foo", |
1965 scoped_refptr<net::IOBuffer>(), | 1977 scoped_refptr<net::IOBuffer>(), |
1966 test_util::CreateCopyResultCallback(&response, &entry), | 1978 test_util::CreateCopyResultCallback(&response, &entry), |
1967 ProgressCallback()); | 1979 base::Bind(&AppendProgressCallbackResult, &upload_progress_values)); |
1968 message_loop_.RunUntilIdle(); | 1980 message_loop_.RunUntilIdle(); |
1969 | 1981 |
1970 EXPECT_EQ(HTTP_CREATED, response.code); | 1982 EXPECT_EQ(HTTP_CREATED, response.code); |
1971 EXPECT_TRUE(entry.get()); | 1983 EXPECT_TRUE(entry.get()); |
1972 EXPECT_EQ(15L, entry->file_size()); | 1984 EXPECT_EQ(15L, entry->file_size()); |
1973 EXPECT_TRUE(Exists(entry->resource_id())); | 1985 EXPECT_TRUE(Exists(entry->resource_id())); |
| 1986 ASSERT_TRUE(!upload_progress_values.empty()); |
| 1987 EXPECT_TRUE(base::STLIsSorted(upload_progress_values)); |
| 1988 EXPECT_GE(upload_progress_values.front(), 0); |
| 1989 EXPECT_LE(upload_progress_values.back(), entry->file_size()); |
1974 } | 1990 } |
1975 | 1991 |
1976 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) { | 1992 TEST_F(FakeDriveServiceTest, AddNewFile_ToRootDirectory) { |
1977 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( | 1993 ASSERT_TRUE(fake_service_.LoadResourceListForWapi( |
1978 "chromeos/gdata/root_feed.json")); | 1994 "chromeos/gdata/root_feed.json")); |
1979 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( | 1995 ASSERT_TRUE(fake_service_.LoadAccountMetadataForWapi( |
1980 "chromeos/gdata/account_metadata.json")); | 1996 "chromeos/gdata/account_metadata.json")); |
1981 | 1997 |
1982 int64 old_largest_change_id = GetLargestChangeByAboutResource(); | 1998 int64 old_largest_change_id = GetLargestChangeByAboutResource(); |
1983 | 1999 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2185 test_util::CreateCopyResultCallback(&error, &resource_entry)); | 2201 test_util::CreateCopyResultCallback(&error, &resource_entry)); |
2186 message_loop_.RunUntilIdle(); | 2202 message_loop_.RunUntilIdle(); |
2187 | 2203 |
2188 EXPECT_EQ(GDATA_NO_CONNECTION, error); | 2204 EXPECT_EQ(GDATA_NO_CONNECTION, error); |
2189 EXPECT_FALSE(resource_entry); | 2205 EXPECT_FALSE(resource_entry); |
2190 } | 2206 } |
2191 | 2207 |
2192 } // namespace | 2208 } // namespace |
2193 | 2209 |
2194 } // namespace google_apis | 2210 } // namespace google_apis |
OLD | NEW |