| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 http_request_ = request; | 403 http_request_ = request; |
| 404 | 404 |
| 405 const GURL absolute_url = test_server_.GetURL(request.relative_url); | 405 const GURL absolute_url = test_server_.GetURL(request.relative_url); |
| 406 std::string id; | 406 std::string id; |
| 407 if (absolute_url.path() != "/upload/drive") | 407 if (absolute_url.path() != "/upload/drive") |
| 408 return scoped_ptr<net::test_server::HttpResponse>(); | 408 return scoped_ptr<net::test_server::HttpResponse>(); |
| 409 | 409 |
| 410 scoped_ptr<net::test_server::BasicHttpResponse> response( | 410 scoped_ptr<net::test_server::BasicHttpResponse> response( |
| 411 new net::test_server::BasicHttpResponse); | 411 new net::test_server::BasicHttpResponse); |
| 412 response->set_code(net::HTTP_OK); | 412 response->set_code(net::HTTP_OK); |
| 413 response->set_content("{}"); |
| 414 response->set_content_type("text/plain"); |
| 415 response->set_content( |
| 416 "--BOUNDARY\r\n" |
| 417 "Content-Type: application/http\r\n" |
| 418 "\r\n" |
| 419 "HTTP/1.1 200 OK\r\n" |
| 420 "Content-Type: application/json; charset=UTF-8\r\n" |
| 421 "\r\n" |
| 422 "{\r\n" |
| 423 " \"kind\": \"drive#file\",\r\n" |
| 424 " \"id\": \"file_id_1\"\r\n" |
| 425 "}\r\n" |
| 426 "\r\n" |
| 427 "--BOUNDARY\r\n" |
| 428 "Content-Type: application/http\r\n" |
| 429 "\r\n" |
| 430 "HTTP/1.1 503 Service Unavailable\r\n" |
| 431 "Content-Type: application/json; charset=UTF-8\r\n" |
| 432 "\r\n" |
| 433 "{}\r\n" |
| 434 "\r\n" |
| 435 "--BOUNDARY--\r\n"); |
| 413 return response.Pass(); | 436 return response.Pass(); |
| 414 } | 437 } |
| 415 | 438 |
| 416 // These are for the current upload file status. | 439 // These are for the current upload file status. |
| 417 int64 received_bytes_; | 440 int64 received_bytes_; |
| 418 int64 content_length_; | 441 int64 content_length_; |
| 419 }; | 442 }; |
| 420 | 443 |
| 421 TEST_F(DriveApiRequestsTest, DriveApiDataRequest_Fields) { | 444 TEST_F(DriveApiRequestsTest, DriveApiDataRequest_Fields) { |
| 422 // Make sure that "fields" query param is supported by using its subclass, | 445 // Make sure that "fields" query param is supported by using its subclass, |
| (...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1909 | 1932 |
| 1910 TEST_F(DriveApiRequestsTest, BatchUploadRequest) { | 1933 TEST_F(DriveApiRequestsTest, BatchUploadRequest) { |
| 1911 // Preapre constants. | 1934 // Preapre constants. |
| 1912 const char kTestContentType[] = "text/plain"; | 1935 const char kTestContentType[] = "text/plain"; |
| 1913 const std::string kTestContent(10, 'a'); | 1936 const std::string kTestContent(10, 'a'); |
| 1914 const base::FilePath kTestFilePath = | 1937 const base::FilePath kTestFilePath = |
| 1915 temp_dir_.path().AppendASCII("upload_file.txt"); | 1938 temp_dir_.path().AppendASCII("upload_file.txt"); |
| 1916 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); | 1939 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); |
| 1917 | 1940 |
| 1918 // Create batch request. | 1941 // Create batch request. |
| 1919 drive::BatchUploadRequest* const request = new drive::BatchUploadRequest( | 1942 drive::BatchUploadRequest* const request = |
| 1920 request_sender_.get(), *url_generator_); | 1943 new drive::BatchUploadRequest(request_sender_.get(), *url_generator_); |
| 1921 request->SetBoundaryForTesting("OUTERBOUNDARY"); | 1944 request->SetBoundaryForTesting("OUTERBOUNDARY"); |
| 1922 request_sender_->StartRequestWithRetry(request); | 1945 request_sender_->StartRequestWithRetry(request); |
| 1923 | 1946 |
| 1924 // Create child request. | 1947 // Create child request. |
| 1925 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 1948 DriveApiErrorCode errors[] = {DRIVE_OTHER_ERROR, DRIVE_OTHER_ERROR}; |
| 1926 scoped_ptr<FileResource> file_resource; | 1949 scoped_ptr<FileResource> file_resources[2]; |
| 1927 base::RunLoop run_loop[2]; | 1950 base::RunLoop run_loop[2]; |
| 1928 for (int i = 0; i < 2; ++i) { | 1951 for (int i = 0; i < 2; ++i) { |
| 1929 const FileResourceCallback callback = test_util::CreateQuitCallback( | 1952 const FileResourceCallback callback = test_util::CreateQuitCallback( |
| 1930 &run_loop[i], | 1953 &run_loop[i], |
| 1931 test_util::CreateCopyResultCallback(&error, &file_resource)); | 1954 test_util::CreateCopyResultCallback(&errors[i], &file_resources[i])); |
| 1932 drive::MultipartUploadNewFileRequest* const child_request = | 1955 drive::MultipartUploadNewFileRequest* const child_request = |
| 1933 new drive::MultipartUploadNewFileRequest( | 1956 new drive::MultipartUploadNewFileRequest( |
| 1934 request_sender_.get(), | 1957 request_sender_.get(), base::StringPrintf("new file title %d", i), |
| 1935 base::StringPrintf("new file title %d", i), | 1958 "parent_resource_id", kTestContentType, kTestContent.size(), |
| 1936 "parent_resource_id", | 1959 base::Time(), base::Time(), kTestFilePath, drive::Properties(), |
| 1937 kTestContentType, | 1960 *url_generator_, callback, ProgressCallback()); |
| 1938 kTestContent.size(), | |
| 1939 base::Time(), | |
| 1940 base::Time(), | |
| 1941 kTestFilePath, | |
| 1942 drive::Properties(), | |
| 1943 *url_generator_, | |
| 1944 callback, | |
| 1945 ProgressCallback()); | |
| 1946 child_request->SetBoundaryForTesting("INNERBOUNDARY"); | 1961 child_request->SetBoundaryForTesting("INNERBOUNDARY"); |
| 1947 request->AddRequest(child_request); | 1962 request->AddRequest(child_request); |
| 1948 } | 1963 } |
| 1949 request->Commit(); | 1964 request->Commit(); |
| 1950 run_loop[0].Run(); | 1965 run_loop[0].Run(); |
| 1951 run_loop[1].Run(); | 1966 run_loop[1].Run(); |
| 1952 | 1967 |
| 1953 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1968 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
| 1954 EXPECT_EQ("batch", http_request_.headers["X-Goog-Upload-Protocol"]); | 1969 EXPECT_EQ("batch", http_request_.headers["X-Goog-Upload-Protocol"]); |
| 1955 EXPECT_EQ("multipart/mixed; boundary=OUTERBOUNDARY", | 1970 EXPECT_EQ("multipart/mixed; boundary=OUTERBOUNDARY", |
| 1956 http_request_.headers["Content-Type"]); | 1971 http_request_.headers["Content-Type"]); |
| 1957 EXPECT_EQ("--OUTERBOUNDARY\n" | 1972 EXPECT_EQ( |
| 1958 "Content-Type: application/http\n" | 1973 "--OUTERBOUNDARY\n" |
| 1959 "\n" | 1974 "Content-Type: application/http\n" |
| 1960 "POST /upload/drive/v2/files HTTP/1.1\n" | 1975 "\n" |
| 1961 "Host: 127.0.0.1\n" | 1976 "POST /upload/drive/v2/files HTTP/1.1\n" |
| 1962 "X-Goog-Upload-Protocol: multipart\n" | 1977 "Host: 127.0.0.1\n" |
| 1963 "Content-Type: multipart/related; boundary=INNERBOUNDARY\n" | 1978 "X-Goog-Upload-Protocol: multipart\n" |
| 1964 "\n" | 1979 "Content-Type: multipart/related; boundary=INNERBOUNDARY\n" |
| 1965 "--INNERBOUNDARY\n" | 1980 "\n" |
| 1966 "Content-Type: application/json\n" | 1981 "--INNERBOUNDARY\n" |
| 1967 "\n" | 1982 "Content-Type: application/json\n" |
| 1968 "{\"parents\":[{\"id\":\"parent_resource_id\"," | 1983 "\n" |
| 1969 "\"kind\":\"drive#fileLink\"}],\"title\":\"new file title 0\"}\n" | 1984 "{\"parents\":[{\"id\":\"parent_resource_id\"," |
| 1970 "--INNERBOUNDARY\n" | 1985 "\"kind\":\"drive#fileLink\"}],\"title\":\"new file title 0\"}\n" |
| 1971 "Content-Type: text/plain\n" | 1986 "--INNERBOUNDARY\n" |
| 1972 "\n" | 1987 "Content-Type: text/plain\n" |
| 1973 "aaaaaaaaaa\n" | 1988 "\n" |
| 1974 "--INNERBOUNDARY--\n" | 1989 "aaaaaaaaaa\n" |
| 1975 "--OUTERBOUNDARY\n" | 1990 "--INNERBOUNDARY--\n" |
| 1976 "Content-Type: application/http\n" | 1991 "--OUTERBOUNDARY\n" |
| 1977 "\n" | 1992 "Content-Type: application/http\n" |
| 1978 "POST /upload/drive/v2/files HTTP/1.1\n" | 1993 "\n" |
| 1979 "Host: 127.0.0.1\n" | 1994 "POST /upload/drive/v2/files HTTP/1.1\n" |
| 1980 "X-Goog-Upload-Protocol: multipart\n" | 1995 "Host: 127.0.0.1\n" |
| 1981 "Content-Type: multipart/related; boundary=INNERBOUNDARY\n" | 1996 "X-Goog-Upload-Protocol: multipart\n" |
| 1982 "\n" | 1997 "Content-Type: multipart/related; boundary=INNERBOUNDARY\n" |
| 1983 "--INNERBOUNDARY\n" | 1998 "\n" |
| 1984 "Content-Type: application/json\n" | 1999 "--INNERBOUNDARY\n" |
| 1985 "\n" | 2000 "Content-Type: application/json\n" |
| 1986 "{\"parents\":[{\"id\":\"parent_resource_id\"," | 2001 "\n" |
| 1987 "\"kind\":\"drive#fileLink\"}],\"title\":\"new file title 1\"}\n" | 2002 "{\"parents\":[{\"id\":\"parent_resource_id\"," |
| 1988 "--INNERBOUNDARY\n" | 2003 "\"kind\":\"drive#fileLink\"}],\"title\":\"new file title 1\"}\n" |
| 1989 "Content-Type: text/plain\n" | 2004 "--INNERBOUNDARY\n" |
| 1990 "\n" | 2005 "Content-Type: text/plain\n" |
| 1991 "aaaaaaaaaa\n" | 2006 "\n" |
| 1992 "--INNERBOUNDARY--\n" | 2007 "aaaaaaaaaa\n" |
| 1993 "--OUTERBOUNDARY--", | 2008 "--INNERBOUNDARY--\n" |
| 1994 http_request_.content); | 2009 "--OUTERBOUNDARY--", |
| 2010 http_request_.content); |
| 2011 EXPECT_EQ(HTTP_SUCCESS, errors[0]); |
| 2012 ASSERT_TRUE(file_resources[0]); |
| 2013 EXPECT_EQ("file_id_1", file_resources[0]->file_id()); |
| 2014 ASSERT_FALSE(file_resources[1]); |
| 2015 EXPECT_EQ(DRIVE_PARSE_ERROR, errors[1]); |
| 1995 } | 2016 } |
| 1996 | 2017 |
| 1997 TEST_F(DriveApiRequestsTest, EmptyBatchUploadRequest) { | 2018 TEST_F(DriveApiRequestsTest, EmptyBatchUploadRequest) { |
| 1998 drive::BatchUploadRequest* const request = new drive::BatchUploadRequest( | 2019 drive::BatchUploadRequest* const request = |
| 1999 request_sender_.get(), *url_generator_); | 2020 new drive::BatchUploadRequest(request_sender_.get(), *url_generator_); |
| 2000 EXPECT_DEATH(request->Commit(), "Check failed"); | 2021 EXPECT_DEATH(request->Commit(), "Check failed"); |
| 2001 } | 2022 } |
| 2002 | 2023 |
| 2003 } // namespace google_apis | 2024 } // namespace google_apis |
| OLD | NEW |