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

Side by Side Diff: google_apis/drive/drive_api_requests_unittest.cc

Issue 1965963003: Use new API to download blobs from Google Drive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
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 "google_apis/drive/drive_api_requests.h" 5 #include "google_apis/drive/drive_api_requests.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 const char kTestPermissionResponse[] = 47 const char kTestPermissionResponse[] =
48 "{\n" 48 "{\n"
49 "\"kind\": \"drive#permission\",\n" 49 "\"kind\": \"drive#permission\",\n"
50 "\"id\": \"resource_id\",\n" 50 "\"id\": \"resource_id\",\n"
51 "\"selfLink\": \"self_link\",\n" 51 "\"selfLink\": \"self_link\",\n"
52 "}\n"; 52 "}\n";
53 53
54 const char kTestUploadExistingFilePath[] = "/upload/existingfile/path"; 54 const char kTestUploadExistingFilePath[] = "/upload/existingfile/path";
55 const char kTestUploadNewFilePath[] = "/upload/newfile/path"; 55 const char kTestUploadNewFilePath[] = "/upload/newfile/path";
56 const char kTestDownloadPathPrefix[] = "/host/"; 56 const char kTestDownloadPathPrefix[] = "/drive/v2/files/";
57 const char kTestDownloadFileQuery[] = "alt=media";
57 58
58 // Used as a GetContentCallback. 59 // Used as a GetContentCallback.
59 void AppendContent(std::string* out, 60 void AppendContent(std::string* out,
60 DriveApiErrorCode error, 61 DriveApiErrorCode error,
61 std::unique_ptr<std::string> content) { 62 std::unique_ptr<std::string> content) {
62 EXPECT_EQ(HTTP_SUCCESS, error); 63 EXPECT_EQ(HTTP_SUCCESS, error);
63 out->append(*content); 64 out->append(*content);
64 } 65 }
65 66
66 class TestBatchableDelegate : public BatchableDelegate { 67 class TestBatchableDelegate : public BatchableDelegate {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 base::Unretained(this))); 161 base::Unretained(this)));
161 test_server_.RegisterRequestHandler( 162 test_server_.RegisterRequestHandler(
162 base::Bind(&DriveApiRequestsTest::HandleDownloadRequest, 163 base::Bind(&DriveApiRequestsTest::HandleDownloadRequest,
163 base::Unretained(this))); 164 base::Unretained(this)));
164 test_server_.RegisterRequestHandler( 165 test_server_.RegisterRequestHandler(
165 base::Bind(&DriveApiRequestsTest::HandleBatchUploadRequest, 166 base::Bind(&DriveApiRequestsTest::HandleBatchUploadRequest,
166 base::Unretained(this))); 167 base::Unretained(this)));
167 168
168 GURL test_base_url = test_util::GetBaseUrlForTesting(test_server_.port()); 169 GURL test_base_url = test_util::GetBaseUrlForTesting(test_server_.port());
169 url_generator_.reset( 170 url_generator_.reset(
170 new DriveApiUrlGenerator(test_base_url, test_base_url, test_base_url)); 171 new DriveApiUrlGenerator(test_base_url, test_base_url));
171 172
172 // Reset the server's expected behavior just in case. 173 // Reset the server's expected behavior just in case.
173 ResetExpectedResponse(); 174 ResetExpectedResponse();
174 received_bytes_ = 0; 175 received_bytes_ = 0;
175 content_length_ = 0; 176 content_length_ = 0;
176 177
177 // Testing properties used by multiple test cases. 178 // Testing properties used by multiple test cases.
178 drive::Property private_property; 179 drive::Property private_property;
179 private_property.set_key("key1"); 180 private_property.set_key("key1");
180 private_property.set_value("value1"); 181 private_property.set_value("value1");
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 return std::move(response); 436 return std::move(response);
436 } 437 }
437 438
438 // Handles a request for downloading a file. 439 // Handles a request for downloading a file.
439 std::unique_ptr<net::test_server::HttpResponse> HandleDownloadRequest( 440 std::unique_ptr<net::test_server::HttpResponse> HandleDownloadRequest(
440 const net::test_server::HttpRequest& request) { 441 const net::test_server::HttpRequest& request) {
441 http_request_ = request; 442 http_request_ = request;
442 443
443 const GURL absolute_url = test_server_.GetURL(request.relative_url); 444 const GURL absolute_url = test_server_.GetURL(request.relative_url);
444 std::string id; 445 std::string id;
445 if (!test_util::RemovePrefix(absolute_url.path(), 446 if (!test_util::RemovePrefix(
446 kTestDownloadPathPrefix, 447 absolute_url.path(), kTestDownloadPathPrefix, &id) ||
447 &id)) { 448 absolute_url.query() != kTestDownloadFileQuery) {
448 return std::unique_ptr<net::test_server::HttpResponse>(); 449 return std::unique_ptr<net::test_server::HttpResponse>();
449 } 450 }
450 451
451 // For testing, returns a text with |id| repeated 3 times. 452 // For testing, returns a text with |id| repeated 3 times.
452 std::unique_ptr<net::test_server::BasicHttpResponse> response( 453 std::unique_ptr<net::test_server::BasicHttpResponse> response(
453 new net::test_server::BasicHttpResponse); 454 new net::test_server::BasicHttpResponse);
454 response->set_code(net::HTTP_OK); 455 response->set_code(net::HTTP_OK);
455 response->set_content(id + id + id); 456 response->set_content(id + id + id);
456 response->set_content_type("text/plain"); 457 response->set_content_type("text/plain");
457 return std::move(response); 458 return std::move(response);
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after
1870 request_sender_->StartRequestWithAuthRetry(request); 1871 request_sender_->StartRequestWithAuthRetry(request);
1871 run_loop.Run(); 1872 run_loop.Run();
1872 } 1873 }
1873 1874
1874 std::string contents; 1875 std::string contents;
1875 base::ReadFileToString(temp_file, &contents); 1876 base::ReadFileToString(temp_file, &contents);
1876 base::DeleteFile(temp_file, false); 1877 base::DeleteFile(temp_file, false);
1877 1878
1878 EXPECT_EQ(HTTP_SUCCESS, result_code); 1879 EXPECT_EQ(HTTP_SUCCESS, result_code);
1879 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 1880 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
1880 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); 1881 EXPECT_EQ(kTestDownloadPathPrefix + kTestId + "?" + kTestDownloadFileQuery,
1882 http_request_.relative_url);
1881 EXPECT_EQ(kDownloadedFilePath, temp_file); 1883 EXPECT_EQ(kDownloadedFilePath, temp_file);
1882 1884
1883 const std::string expected_contents = kTestId + kTestId + kTestId; 1885 const std::string expected_contents = kTestId + kTestId + kTestId;
1884 EXPECT_EQ(expected_contents, contents); 1886 EXPECT_EQ(expected_contents, contents);
1885 } 1887 }
1886 1888
1887 TEST_F(DriveApiRequestsTest, DownloadFileRequest_GetContentCallback) { 1889 TEST_F(DriveApiRequestsTest, DownloadFileRequest_GetContentCallback) {
1888 const base::FilePath kDownloadedFilePath = 1890 const base::FilePath kDownloadedFilePath =
1889 temp_dir_.path().AppendASCII("cache_file"); 1891 temp_dir_.path().AppendASCII("cache_file");
1890 const std::string kTestId("dummyId"); 1892 const std::string kTestId("dummyId");
(...skipping 14 matching lines...) Expand all
1905 base::Bind(&AppendContent, &contents), 1907 base::Bind(&AppendContent, &contents),
1906 ProgressCallback()); 1908 ProgressCallback());
1907 request_sender_->StartRequestWithAuthRetry(request); 1909 request_sender_->StartRequestWithAuthRetry(request);
1908 run_loop.Run(); 1910 run_loop.Run();
1909 } 1911 }
1910 1912
1911 base::DeleteFile(temp_file, false); 1913 base::DeleteFile(temp_file, false);
1912 1914
1913 EXPECT_EQ(HTTP_SUCCESS, result_code); 1915 EXPECT_EQ(HTTP_SUCCESS, result_code);
1914 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 1916 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
1915 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); 1917 EXPECT_EQ(kTestDownloadPathPrefix + kTestId + "?" + kTestDownloadFileQuery,
1918 http_request_.relative_url);
1916 EXPECT_EQ(kDownloadedFilePath, temp_file); 1919 EXPECT_EQ(kDownloadedFilePath, temp_file);
1917 1920
1918 const std::string expected_contents = kTestId + kTestId + kTestId; 1921 const std::string expected_contents = kTestId + kTestId + kTestId;
1919 EXPECT_EQ(expected_contents, contents); 1922 EXPECT_EQ(expected_contents, contents);
1920 } 1923 }
1921 1924
1922 TEST_F(DriveApiRequestsTest, PermissionsInsertRequest) { 1925 TEST_F(DriveApiRequestsTest, PermissionsInsertRequest) {
1923 expected_content_type_ = "application/json"; 1926 expected_content_type_ = "application/json";
1924 expected_content_ = kTestPermissionResponse; 1927 expected_content_ = kTestPermissionResponse;
1925 1928
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 "Header: value\r\n" 2291 "Header: value\r\n"
2289 "\r\n" 2292 "\r\n"
2290 "BODY\r\n" 2293 "BODY\r\n"
2291 "--BOUNDARY-- \t", 2294 "--BOUNDARY-- \t",
2292 &parts)); 2295 &parts));
2293 ASSERT_EQ(1u, parts.size()); 2296 ASSERT_EQ(1u, parts.size());
2294 EXPECT_EQ(HTTP_SUCCESS, parts[0].code); 2297 EXPECT_EQ(HTTP_SUCCESS, parts[0].code);
2295 EXPECT_EQ("BODY", parts[0].body); 2298 EXPECT_EQ("BODY", parts[0].body);
2296 } 2299 }
2297 } // namespace google_apis 2300 } // namespace google_apis
OLDNEW
« no previous file with comments | « components/drive/service/drive_api_service_unittest.cc ('k') | google_apis/drive/drive_api_url_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698