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/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // The request is not the "Children: delete" request. Delegate the | 143 // The request is not the "Children: delete" request. Delegate the |
144 // processing to the next handler. | 144 // processing to the next handler. |
145 return scoped_ptr<net::test_server::HttpResponse>(); | 145 return scoped_ptr<net::test_server::HttpResponse>(); |
146 } | 146 } |
147 | 147 |
148 http_request_ = request; | 148 http_request_ = request; |
149 | 149 |
150 // Return the response with just "204 No Content" status code. | 150 // Return the response with just "204 No Content" status code. |
151 scoped_ptr<net::test_server::BasicHttpResponse> http_response( | 151 scoped_ptr<net::test_server::BasicHttpResponse> http_response( |
152 new net::test_server::BasicHttpResponse); | 152 new net::test_server::BasicHttpResponse); |
153 http_response->set_code(net::test_server::NO_CONTENT); | 153 http_response->set_code(net::HTTP_NO_CONTENT); |
154 return http_response.PassAs<net::test_server::HttpResponse>(); | 154 return http_response.PassAs<net::test_server::HttpResponse>(); |
155 } | 155 } |
156 | 156 |
157 // Reads the data file of |expected_data_file_path_| and returns its content | 157 // Reads the data file of |expected_data_file_path_| and returns its content |
158 // for the request. | 158 // for the request. |
159 // To use this method, it is necessary to set |expected_data_file_path_| | 159 // To use this method, it is necessary to set |expected_data_file_path_| |
160 // to the appropriate file path before sending the request to the server. | 160 // to the appropriate file path before sending the request to the server. |
161 scoped_ptr<net::test_server::HttpResponse> HandleDataFileRequest( | 161 scoped_ptr<net::test_server::HttpResponse> HandleDataFileRequest( |
162 const net::test_server::HttpRequest& request) { | 162 const net::test_server::HttpRequest& request) { |
163 if (expected_data_file_path_.empty()) { | 163 if (expected_data_file_path_.empty()) { |
(...skipping 27 matching lines...) Expand all Loading... |
191 | 191 |
192 scoped_ptr<net::test_server::BasicHttpResponse> response( | 192 scoped_ptr<net::test_server::BasicHttpResponse> response( |
193 new net::test_server::BasicHttpResponse); | 193 new net::test_server::BasicHttpResponse); |
194 | 194 |
195 // Check an ETag. | 195 // Check an ETag. |
196 std::map<std::string, std::string>::const_iterator found = | 196 std::map<std::string, std::string>::const_iterator found = |
197 request.headers.find("If-Match"); | 197 request.headers.find("If-Match"); |
198 if (found != request.headers.end() && | 198 if (found != request.headers.end() && |
199 found->second != "*" && | 199 found->second != "*" && |
200 found->second != kTestETag) { | 200 found->second != kTestETag) { |
201 response->set_code(net::test_server::PRECONDITION); | 201 response->set_code(net::HTTP_PRECONDITION_FAILED); |
202 return response.PassAs<net::test_server::HttpResponse>(); | 202 return response.PassAs<net::test_server::HttpResponse>(); |
203 } | 203 } |
204 | 204 |
205 // Check if the X-Upload-Content-Length is present. If yes, store the | 205 // Check if the X-Upload-Content-Length is present. If yes, store the |
206 // length of the file. | 206 // length of the file. |
207 found = request.headers.find("X-Upload-Content-Length"); | 207 found = request.headers.find("X-Upload-Content-Length"); |
208 if (found == request.headers.end() || | 208 if (found == request.headers.end() || |
209 !base::StringToInt64(found->second, &content_length_)) { | 209 !base::StringToInt64(found->second, &content_length_)) { |
210 return scoped_ptr<net::test_server::HttpResponse>(); | 210 return scoped_ptr<net::test_server::HttpResponse>(); |
211 } | 211 } |
212 received_bytes_ = 0; | 212 received_bytes_ = 0; |
213 | 213 |
214 response->set_code(net::test_server::SUCCESS); | 214 response->set_code(net::HTTP_OK); |
215 response->AddCustomHeader( | 215 response->AddCustomHeader( |
216 "Location", | 216 "Location", |
217 test_server_.base_url().Resolve(expected_upload_path_).spec()); | 217 test_server_.base_url().Resolve(expected_upload_path_).spec()); |
218 return response.PassAs<net::test_server::HttpResponse>(); | 218 return response.PassAs<net::test_server::HttpResponse>(); |
219 } | 219 } |
220 | 220 |
221 scoped_ptr<net::test_server::HttpResponse> HandleResumeUploadRequest( | 221 scoped_ptr<net::test_server::HttpResponse> HandleResumeUploadRequest( |
222 const net::test_server::HttpRequest& request) { | 222 const net::test_server::HttpRequest& request) { |
223 if (request.relative_url != expected_upload_path_) { | 223 if (request.relative_url != expected_upload_path_) { |
224 // The request path is different from the expected path for uploading. | 224 // The request path is different from the expected path for uploading. |
(...skipping 24 matching lines...) Expand all Loading... |
249 EXPECT_EQ(length, content_length_); | 249 EXPECT_EQ(length, content_length_); |
250 | 250 |
251 // end_position is inclusive, but so +1 to change the range to byte size. | 251 // end_position is inclusive, but so +1 to change the range to byte size. |
252 received_bytes_ = end_position + 1; | 252 received_bytes_ = end_position + 1; |
253 } | 253 } |
254 | 254 |
255 if (received_bytes_ < content_length_) { | 255 if (received_bytes_ < content_length_) { |
256 scoped_ptr<net::test_server::BasicHttpResponse> response( | 256 scoped_ptr<net::test_server::BasicHttpResponse> response( |
257 new net::test_server::BasicHttpResponse); | 257 new net::test_server::BasicHttpResponse); |
258 // Set RESUME INCOMPLETE (308) status code. | 258 // Set RESUME INCOMPLETE (308) status code. |
259 response->set_code(net::test_server::RESUME_INCOMPLETE); | 259 response->set_code(static_cast<net::HttpStatusCode>(308)); |
260 | 260 |
261 // Add Range header to the response, based on the values of | 261 // Add Range header to the response, based on the values of |
262 // Content-Range header in the request. | 262 // Content-Range header in the request. |
263 // The header is annotated only when at least one byte is received. | 263 // The header is annotated only when at least one byte is received. |
264 if (received_bytes_ > 0) { | 264 if (received_bytes_ > 0) { |
265 response->AddCustomHeader( | 265 response->AddCustomHeader( |
266 "Range", "bytes=0-" + base::Int64ToString(received_bytes_ - 1)); | 266 "Range", "bytes=0-" + base::Int64ToString(received_bytes_ - 1)); |
267 } | 267 } |
268 | 268 |
269 return response.PassAs<net::test_server::HttpResponse>(); | 269 return response.PassAs<net::test_server::HttpResponse>(); |
270 } | 270 } |
271 | 271 |
272 // All bytes are received. Return the "success" response with the file's | 272 // All bytes are received. Return the "success" response with the file's |
273 // (dummy) metadata. | 273 // (dummy) metadata. |
274 scoped_ptr<net::test_server::BasicHttpResponse> response = | 274 scoped_ptr<net::test_server::BasicHttpResponse> response = |
275 test_util::CreateHttpResponseFromFile( | 275 test_util::CreateHttpResponseFromFile( |
276 test_util::GetTestFilePath("chromeos/drive/file_entry.json")); | 276 test_util::GetTestFilePath("chromeos/drive/file_entry.json")); |
277 | 277 |
278 // The response code is CREATED if it is new file uploading. | 278 // The response code is CREATED if it is new file uploading. |
279 if (http_request_.relative_url == kTestUploadNewFilePath) { | 279 if (http_request_.relative_url == kTestUploadNewFilePath) { |
280 response->set_code(net::test_server::CREATED); | 280 response->set_code(net::HTTP_CREATED); |
281 } | 281 } |
282 | 282 |
283 return response.PassAs<net::test_server::HttpResponse>(); | 283 return response.PassAs<net::test_server::HttpResponse>(); |
284 } | 284 } |
285 | 285 |
286 // Returns the response based on set expected content and its type. | 286 // Returns the response based on set expected content and its type. |
287 // To use this method, both |expected_content_type_| and |expected_content_| | 287 // To use this method, both |expected_content_type_| and |expected_content_| |
288 // must be set in advance. | 288 // must be set in advance. |
289 scoped_ptr<net::test_server::HttpResponse> HandleContentResponse( | 289 scoped_ptr<net::test_server::HttpResponse> HandleContentResponse( |
290 const net::test_server::HttpRequest& request) { | 290 const net::test_server::HttpRequest& request) { |
291 if (expected_content_type_.empty() || expected_content_.empty()) { | 291 if (expected_content_type_.empty() || expected_content_.empty()) { |
292 // Expected content is not set. Delegate the processing to the next | 292 // Expected content is not set. Delegate the processing to the next |
293 // handler. | 293 // handler. |
294 return scoped_ptr<net::test_server::HttpResponse>(); | 294 return scoped_ptr<net::test_server::HttpResponse>(); |
295 } | 295 } |
296 | 296 |
297 http_request_ = request; | 297 http_request_ = request; |
298 | 298 |
299 scoped_ptr<net::test_server::BasicHttpResponse> response( | 299 scoped_ptr<net::test_server::BasicHttpResponse> response( |
300 new net::test_server::BasicHttpResponse); | 300 new net::test_server::BasicHttpResponse); |
301 response->set_code(net::test_server::SUCCESS); | 301 response->set_code(net::HTTP_OK); |
302 response->set_content_type(expected_content_type_); | 302 response->set_content_type(expected_content_type_); |
303 response->set_content(expected_content_); | 303 response->set_content(expected_content_); |
304 return response.PassAs<net::test_server::HttpResponse>(); | 304 return response.PassAs<net::test_server::HttpResponse>(); |
305 } | 305 } |
306 | 306 |
307 // These are for the current upload file status. | 307 // These are for the current upload file status. |
308 int64 received_bytes_; | 308 int64 received_bytes_; |
309 int64 content_length_; | 309 int64 content_length_; |
310 }; | 310 }; |
311 | 311 |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1361 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]); | 1361 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]); |
1362 | 1362 |
1363 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1363 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1364 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", | 1364 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", |
1365 http_request_.relative_url); | 1365 http_request_.relative_url); |
1366 EXPECT_TRUE(http_request_.has_content); | 1366 EXPECT_TRUE(http_request_.has_content); |
1367 EXPECT_TRUE(http_request_.content.empty()); | 1367 EXPECT_TRUE(http_request_.content.empty()); |
1368 } | 1368 } |
1369 | 1369 |
1370 } // namespace google_apis | 1370 } // namespace google_apis |
OLD | NEW |