| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/files_list_request_runner.h" | 5 #include "google_apis/drive/files_list_request_runner.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 10 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 13 #include "google_apis/drive/base_requests.h" | 15 #include "google_apis/drive/base_requests.h" |
| 14 #include "google_apis/drive/dummy_auth_service.h" | 16 #include "google_apis/drive/dummy_auth_service.h" |
| 15 #include "google_apis/drive/request_sender.h" | 17 #include "google_apis/drive/request_sender.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 18 #include "net/test/embedded_test_server/embedded_test_server.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 on_completed_callback_ = base::Closure(); | 88 on_completed_callback_ = base::Closure(); |
| 87 http_request_.reset(); | 89 http_request_.reset(); |
| 88 response_error_.reset(); | 90 response_error_.reset(); |
| 89 response_entry_.reset(); | 91 response_entry_.reset(); |
| 90 } | 92 } |
| 91 | 93 |
| 92 // Called when the request is completed and no more backoff retries will | 94 // Called when the request is completed and no more backoff retries will |
| 93 // happen. | 95 // happen. |
| 94 void OnCompleted(DriveApiErrorCode error, scoped_ptr<FileList> entry) { | 96 void OnCompleted(DriveApiErrorCode error, scoped_ptr<FileList> entry) { |
| 95 response_error_.reset(new DriveApiErrorCode(error)); | 97 response_error_.reset(new DriveApiErrorCode(error)); |
| 96 response_entry_ = entry.Pass(); | 98 response_entry_ = std::move(entry); |
| 97 on_completed_callback_.Run(); | 99 on_completed_callback_.Run(); |
| 98 } | 100 } |
| 99 | 101 |
| 100 protected: | 102 protected: |
| 101 // Sets a fake Drive API server response to be returned for the upcoming HTTP | 103 // Sets a fake Drive API server response to be returned for the upcoming HTTP |
| 102 // request. | 104 // request. |
| 103 void SetFakeServerResponse(net::HttpStatusCode code, | 105 void SetFakeServerResponse(net::HttpStatusCode code, |
| 104 const std::string& content) { | 106 const std::string& content) { |
| 105 fake_server_response_.reset(new net::test_server::BasicHttpResponse); | 107 fake_server_response_.reset(new net::test_server::BasicHttpResponse); |
| 106 fake_server_response_->set_code(code); | 108 fake_server_response_->set_code(code); |
| 107 fake_server_response_->set_content(content); | 109 fake_server_response_->set_content(content); |
| 108 fake_server_response_->set_content_type("application/json"); | 110 fake_server_response_->set_content_type("application/json"); |
| 109 } | 111 } |
| 110 | 112 |
| 111 // Handles a HTTP request to the Drive API server and returns a fake response. | 113 // Handles a HTTP request to the Drive API server and returns a fake response. |
| 112 scoped_ptr<net::test_server::HttpResponse> OnFilesListRequest( | 114 scoped_ptr<net::test_server::HttpResponse> OnFilesListRequest( |
| 113 const GURL& base_url, | 115 const GURL& base_url, |
| 114 const net::test_server::HttpRequest& request) { | 116 const net::test_server::HttpRequest& request) { |
| 115 http_request_.reset(new net::test_server::HttpRequest(request)); | 117 http_request_.reset(new net::test_server::HttpRequest(request)); |
| 116 return fake_server_response_.Pass(); | 118 return std::move(fake_server_response_); |
| 117 } | 119 } |
| 118 | 120 |
| 119 base::MessageLoopForIO message_loop_; // Test server needs IO thread. | 121 base::MessageLoopForIO message_loop_; // Test server needs IO thread. |
| 120 scoped_ptr<RequestSender> request_sender_; | 122 scoped_ptr<RequestSender> request_sender_; |
| 121 net::EmbeddedTestServer test_server_; | 123 net::EmbeddedTestServer test_server_; |
| 122 scoped_ptr<FilesListRequestRunner> runner_; | 124 scoped_ptr<FilesListRequestRunner> runner_; |
| 123 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; | 125 scoped_refptr<net::TestURLRequestContextGetter> request_context_getter_; |
| 124 base::Closure on_completed_callback_; | 126 base::Closure on_completed_callback_; |
| 125 | 127 |
| 126 // Response set by test cases to be returned from the HTTP server. | 128 // Response set by test cases to be returned from the HTTP server. |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 http_request_->relative_url); | 267 http_request_->relative_url); |
| 266 | 268 |
| 267 // There must be no backoff in case of an error different than | 269 // There must be no backoff in case of an error different than |
| 268 // DRIVE_RESPONSE_TOO_LARGE. | 270 // DRIVE_RESPONSE_TOO_LARGE. |
| 269 ASSERT_TRUE(response_error_.get()); | 271 ASSERT_TRUE(response_error_.get()); |
| 270 EXPECT_EQ(DRIVE_NO_SPACE, *response_error_); | 272 EXPECT_EQ(DRIVE_NO_SPACE, *response_error_); |
| 271 EXPECT_FALSE(response_entry_.get()); | 273 EXPECT_FALSE(response_entry_.get()); |
| 272 } | 274 } |
| 273 | 275 |
| 274 } // namespace google_apis | 276 } // namespace google_apis |
| OLD | NEW |