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

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

Issue 1547233002: Convert Pass()→std::move() in //google_apis (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « google_apis/drive/drive_api_requests.cc ('k') | google_apis/drive/files_list_request_runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
6
5 #include <stddef.h> 7 #include <stddef.h>
6 #include <stdint.h> 8 #include <stdint.h>
9 #include <utility>
7 10
8 #include "base/bind.h" 11 #include "base/bind.h"
9 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
11 #include "base/files/scoped_temp_dir.h" 14 #include "base/files/scoped_temp_dir.h"
12 #include "base/json/json_reader.h" 15 #include "base/json/json_reader.h"
13 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 17 #include "base/run_loop.h"
15 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
17 #include "base/values.h" 20 #include "base/values.h"
18 #include "google_apis/drive/drive_api_parser.h" 21 #include "google_apis/drive/drive_api_parser.h"
19 #include "google_apis/drive/drive_api_requests.h"
20 #include "google_apis/drive/drive_api_url_generator.h" 22 #include "google_apis/drive/drive_api_url_generator.h"
21 #include "google_apis/drive/dummy_auth_service.h" 23 #include "google_apis/drive/dummy_auth_service.h"
22 #include "google_apis/drive/request_sender.h" 24 #include "google_apis/drive/request_sender.h"
23 #include "google_apis/drive/test_util.h" 25 #include "google_apis/drive/test_util.h"
24 #include "net/test/embedded_test_server/embedded_test_server.h" 26 #include "net/test/embedded_test_server/embedded_test_server.h"
25 #include "net/test/embedded_test_server/http_request.h" 27 #include "net/test/embedded_test_server/http_request.h"
26 #include "net/test/embedded_test_server/http_response.h" 28 #include "net/test/embedded_test_server/http_response.h"
27 #include "net/url_request/url_request_test_util.h" 29 #include "net/url_request/url_request_test_util.h"
28 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
29 31
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // processing to the next handler. 239 // processing to the next handler.
238 return scoped_ptr<net::test_server::HttpResponse>(); 240 return scoped_ptr<net::test_server::HttpResponse>();
239 } 241 }
240 242
241 http_request_ = request; 243 http_request_ = request;
242 244
243 // Return the response with just "204 No Content" status code. 245 // Return the response with just "204 No Content" status code.
244 scoped_ptr<net::test_server::BasicHttpResponse> http_response( 246 scoped_ptr<net::test_server::BasicHttpResponse> http_response(
245 new net::test_server::BasicHttpResponse); 247 new net::test_server::BasicHttpResponse);
246 http_response->set_code(net::HTTP_NO_CONTENT); 248 http_response->set_code(net::HTTP_NO_CONTENT);
247 return http_response.Pass(); 249 return std::move(http_response);
248 } 250 }
249 251
250 // Reads the data file of |expected_data_file_path_| and returns its content 252 // Reads the data file of |expected_data_file_path_| and returns its content
251 // for the request. 253 // for the request.
252 // To use this method, it is necessary to set |expected_data_file_path_| 254 // To use this method, it is necessary to set |expected_data_file_path_|
253 // to the appropriate file path before sending the request to the server. 255 // to the appropriate file path before sending the request to the server.
254 scoped_ptr<net::test_server::HttpResponse> HandleDataFileRequest( 256 scoped_ptr<net::test_server::HttpResponse> HandleDataFileRequest(
255 const net::test_server::HttpRequest& request) { 257 const net::test_server::HttpRequest& request) {
256 if (expected_data_file_path_.empty()) { 258 if (expected_data_file_path_.empty()) {
257 // The file is not specified. Delegate the processing to the next 259 // The file is not specified. Delegate the processing to the next
(...skipping 17 matching lines...) Expand all
275 // next handler. 277 // next handler.
276 return scoped_ptr<net::test_server::HttpResponse>(); 278 return scoped_ptr<net::test_server::HttpResponse>();
277 } 279 }
278 280
279 http_request_ = request; 281 http_request_ = request;
280 282
281 scoped_ptr<net::test_server::BasicHttpResponse> response( 283 scoped_ptr<net::test_server::BasicHttpResponse> response(
282 new net::test_server::BasicHttpResponse); 284 new net::test_server::BasicHttpResponse);
283 response->set_code(net::HTTP_NO_CONTENT); 285 response->set_code(net::HTTP_NO_CONTENT);
284 286
285 return response.Pass(); 287 return std::move(response);
286 } 288 }
287 289
288 // Returns PRECONDITION_FAILED response for ETag mismatching with error JSON 290 // Returns PRECONDITION_FAILED response for ETag mismatching with error JSON
289 // content specified by |expected_precondition_failed_file_path_|. 291 // content specified by |expected_precondition_failed_file_path_|.
290 // To use this method, it is necessary to set the variable to the appropriate 292 // To use this method, it is necessary to set the variable to the appropriate
291 // file path before sending the request to the server. 293 // file path before sending the request to the server.
292 scoped_ptr<net::test_server::HttpResponse> HandlePreconditionFailedRequest( 294 scoped_ptr<net::test_server::HttpResponse> HandlePreconditionFailedRequest(
293 const net::test_server::HttpRequest& request) { 295 const net::test_server::HttpRequest& request) {
294 if (expected_precondition_failed_file_path_.empty()) { 296 if (expected_precondition_failed_file_path_.empty()) {
295 // The file is not specified. Delegate the process to the next handler. 297 // The file is not specified. Delegate the process to the next handler.
296 return scoped_ptr<net::test_server::HttpResponse>(); 298 return scoped_ptr<net::test_server::HttpResponse>();
297 } 299 }
298 300
299 http_request_ = request; 301 http_request_ = request;
300 302
301 scoped_ptr<net::test_server::BasicHttpResponse> response( 303 scoped_ptr<net::test_server::BasicHttpResponse> response(
302 new net::test_server::BasicHttpResponse); 304 new net::test_server::BasicHttpResponse);
303 response->set_code(net::HTTP_PRECONDITION_FAILED); 305 response->set_code(net::HTTP_PRECONDITION_FAILED);
304 306
305 std::string content; 307 std::string content;
306 if (base::ReadFileToString(expected_precondition_failed_file_path_, 308 if (base::ReadFileToString(expected_precondition_failed_file_path_,
307 &content)) { 309 &content)) {
308 response->set_content(content); 310 response->set_content(content);
309 response->set_content_type("application/json"); 311 response->set_content_type("application/json");
310 } 312 }
311 313
312 return response.Pass(); 314 return std::move(response);
313 } 315 }
314 316
315 // Returns the response based on set expected upload url. 317 // Returns the response based on set expected upload url.
316 // The response contains the url in its "Location: " header. Also, it doesn't 318 // The response contains the url in its "Location: " header. Also, it doesn't
317 // have any content. 319 // have any content.
318 // To use this method, it is necessary to set |expected_upload_path_| 320 // To use this method, it is necessary to set |expected_upload_path_|
319 // to the string representation of the url to be returned. 321 // to the string representation of the url to be returned.
320 scoped_ptr<net::test_server::HttpResponse> HandleInitiateUploadRequest( 322 scoped_ptr<net::test_server::HttpResponse> HandleInitiateUploadRequest(
321 const net::test_server::HttpRequest& request) { 323 const net::test_server::HttpRequest& request) {
322 if (request.relative_url == expected_upload_path_ || 324 if (request.relative_url == expected_upload_path_ ||
(...skipping 14 matching lines...) Expand all
337 if (found == request.headers.end() || 339 if (found == request.headers.end() ||
338 !base::StringToInt64(found->second, &content_length_)) { 340 !base::StringToInt64(found->second, &content_length_)) {
339 return scoped_ptr<net::test_server::HttpResponse>(); 341 return scoped_ptr<net::test_server::HttpResponse>();
340 } 342 }
341 received_bytes_ = 0; 343 received_bytes_ = 0;
342 344
343 response->set_code(net::HTTP_OK); 345 response->set_code(net::HTTP_OK);
344 response->AddCustomHeader( 346 response->AddCustomHeader(
345 "Location", 347 "Location",
346 test_server_.base_url().Resolve(expected_upload_path_).spec()); 348 test_server_.base_url().Resolve(expected_upload_path_).spec());
347 return response.Pass(); 349 return std::move(response);
348 } 350 }
349 351
350 scoped_ptr<net::test_server::HttpResponse> HandleResumeUploadRequest( 352 scoped_ptr<net::test_server::HttpResponse> HandleResumeUploadRequest(
351 const net::test_server::HttpRequest& request) { 353 const net::test_server::HttpRequest& request) {
352 if (request.relative_url != expected_upload_path_) { 354 if (request.relative_url != expected_upload_path_) {
353 // The request path is different from the expected path for uploading. 355 // The request path is different from the expected path for uploading.
354 // Delegate the processing to the next handler. 356 // Delegate the processing to the next handler.
355 return scoped_ptr<net::test_server::HttpResponse>(); 357 return scoped_ptr<net::test_server::HttpResponse>();
356 } 358 }
357 359
(...skipping 29 matching lines...) Expand all
387 response->set_code(static_cast<net::HttpStatusCode>(308)); 389 response->set_code(static_cast<net::HttpStatusCode>(308));
388 390
389 // Add Range header to the response, based on the values of 391 // Add Range header to the response, based on the values of
390 // Content-Range header in the request. 392 // Content-Range header in the request.
391 // The header is annotated only when at least one byte is received. 393 // The header is annotated only when at least one byte is received.
392 if (received_bytes_ > 0) { 394 if (received_bytes_ > 0) {
393 response->AddCustomHeader( 395 response->AddCustomHeader(
394 "Range", "bytes=0-" + base::Int64ToString(received_bytes_ - 1)); 396 "Range", "bytes=0-" + base::Int64ToString(received_bytes_ - 1));
395 } 397 }
396 398
397 return response.Pass(); 399 return std::move(response);
398 } 400 }
399 401
400 // All bytes are received. Return the "success" response with the file's 402 // All bytes are received. Return the "success" response with the file's
401 // (dummy) metadata. 403 // (dummy) metadata.
402 scoped_ptr<net::test_server::BasicHttpResponse> response = 404 scoped_ptr<net::test_server::BasicHttpResponse> response =
403 test_util::CreateHttpResponseFromFile( 405 test_util::CreateHttpResponseFromFile(
404 test_util::GetTestFilePath("drive/file_entry.json")); 406 test_util::GetTestFilePath("drive/file_entry.json"));
405 407
406 // The response code is CREATED if it is new file uploading. 408 // The response code is CREATED if it is new file uploading.
407 if (http_request_.relative_url == kTestUploadNewFilePath) { 409 if (http_request_.relative_url == kTestUploadNewFilePath) {
408 response->set_code(net::HTTP_CREATED); 410 response->set_code(net::HTTP_CREATED);
409 } 411 }
410 412
411 return response.Pass(); 413 return std::move(response);
412 } 414 }
413 415
414 // Returns the response based on set expected content and its type. 416 // Returns the response based on set expected content and its type.
415 // To use this method, both |expected_content_type_| and |expected_content_| 417 // To use this method, both |expected_content_type_| and |expected_content_|
416 // must be set in advance. 418 // must be set in advance.
417 scoped_ptr<net::test_server::HttpResponse> HandleContentResponse( 419 scoped_ptr<net::test_server::HttpResponse> HandleContentResponse(
418 const net::test_server::HttpRequest& request) { 420 const net::test_server::HttpRequest& request) {
419 if (expected_content_type_.empty() || expected_content_.empty()) { 421 if (expected_content_type_.empty() || expected_content_.empty()) {
420 // Expected content is not set. Delegate the processing to the next 422 // Expected content is not set. Delegate the processing to the next
421 // handler. 423 // handler.
422 return scoped_ptr<net::test_server::HttpResponse>(); 424 return scoped_ptr<net::test_server::HttpResponse>();
423 } 425 }
424 426
425 http_request_ = request; 427 http_request_ = request;
426 428
427 scoped_ptr<net::test_server::BasicHttpResponse> response( 429 scoped_ptr<net::test_server::BasicHttpResponse> response(
428 new net::test_server::BasicHttpResponse); 430 new net::test_server::BasicHttpResponse);
429 response->set_code(net::HTTP_OK); 431 response->set_code(net::HTTP_OK);
430 response->set_content_type(expected_content_type_); 432 response->set_content_type(expected_content_type_);
431 response->set_content(expected_content_); 433 response->set_content(expected_content_);
432 return response.Pass(); 434 return std::move(response);
433 } 435 }
434 436
435 // Handles a request for downloading a file. 437 // Handles a request for downloading a file.
436 scoped_ptr<net::test_server::HttpResponse> HandleDownloadRequest( 438 scoped_ptr<net::test_server::HttpResponse> HandleDownloadRequest(
437 const net::test_server::HttpRequest& request) { 439 const net::test_server::HttpRequest& request) {
438 http_request_ = request; 440 http_request_ = request;
439 441
440 const GURL absolute_url = test_server_.GetURL(request.relative_url); 442 const GURL absolute_url = test_server_.GetURL(request.relative_url);
441 std::string id; 443 std::string id;
442 if (!test_util::RemovePrefix(absolute_url.path(), 444 if (!test_util::RemovePrefix(absolute_url.path(),
443 kTestDownloadPathPrefix, 445 kTestDownloadPathPrefix,
444 &id)) { 446 &id)) {
445 return scoped_ptr<net::test_server::HttpResponse>(); 447 return scoped_ptr<net::test_server::HttpResponse>();
446 } 448 }
447 449
448 // For testing, returns a text with |id| repeated 3 times. 450 // For testing, returns a text with |id| repeated 3 times.
449 scoped_ptr<net::test_server::BasicHttpResponse> response( 451 scoped_ptr<net::test_server::BasicHttpResponse> response(
450 new net::test_server::BasicHttpResponse); 452 new net::test_server::BasicHttpResponse);
451 response->set_code(net::HTTP_OK); 453 response->set_code(net::HTTP_OK);
452 response->set_content(id + id + id); 454 response->set_content(id + id + id);
453 response->set_content_type("text/plain"); 455 response->set_content_type("text/plain");
454 return response.Pass(); 456 return std::move(response);
455 } 457 }
456 458
457 scoped_ptr<net::test_server::HttpResponse> HandleBatchUploadRequest( 459 scoped_ptr<net::test_server::HttpResponse> HandleBatchUploadRequest(
458 const net::test_server::HttpRequest& request) { 460 const net::test_server::HttpRequest& request) {
459 http_request_ = request; 461 http_request_ = request;
460 462
461 const GURL absolute_url = test_server_.GetURL(request.relative_url); 463 const GURL absolute_url = test_server_.GetURL(request.relative_url);
462 std::string id; 464 std::string id;
463 if (absolute_url.path() != "/upload/drive") 465 if (absolute_url.path() != "/upload/drive")
464 return scoped_ptr<net::test_server::HttpResponse>(); 466 return scoped_ptr<net::test_server::HttpResponse>();
(...skipping 17 matching lines...) Expand all
482 "--BOUNDARY\r\n" 484 "--BOUNDARY\r\n"
483 "Content-Type: application/http\r\n" 485 "Content-Type: application/http\r\n"
484 "\r\n" 486 "\r\n"
485 "HTTP/1.1 403 Forbidden\r\n" 487 "HTTP/1.1 403 Forbidden\r\n"
486 "Content-Type: application/json; charset=UTF-8\r\n" 488 "Content-Type: application/json; charset=UTF-8\r\n"
487 "\r\n" 489 "\r\n"
488 "{\"error\":{\"errors\": [" 490 "{\"error\":{\"errors\": ["
489 " {\"reason\": \"userRateLimitExceeded\"}]}}\r\n" 491 " {\"reason\": \"userRateLimitExceeded\"}]}}\r\n"
490 "\r\n" 492 "\r\n"
491 "--BOUNDARY--\r\n"); 493 "--BOUNDARY--\r\n");
492 return response.Pass(); 494 return std::move(response);
493 } 495 }
494 496
495 // These are for the current upload file status. 497 // These are for the current upload file status.
496 int64_t received_bytes_; 498 int64_t received_bytes_;
497 int64_t content_length_; 499 int64_t content_length_;
498 }; 500 };
499 501
500 TEST_F(DriveApiRequestsTest, DriveApiDataRequest_Fields) { 502 TEST_F(DriveApiRequestsTest, DriveApiDataRequest_Fields) {
501 // Make sure that "fields" query param is supported by using its subclass, 503 // Make sure that "fields" query param is supported by using its subclass,
502 // AboutGetRequest. 504 // AboutGetRequest.
(...skipping 1785 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 "Header: value\r\n" 2290 "Header: value\r\n"
2289 "\r\n" 2291 "\r\n"
2290 "BODY\r\n" 2292 "BODY\r\n"
2291 "--BOUNDARY-- \t", 2293 "--BOUNDARY-- \t",
2292 &parts)); 2294 &parts));
2293 ASSERT_EQ(1u, parts.size()); 2295 ASSERT_EQ(1u, parts.size());
2294 EXPECT_EQ(HTTP_SUCCESS, parts[0].code); 2296 EXPECT_EQ(HTTP_SUCCESS, parts[0].code);
2295 EXPECT_EQ("BODY", parts[0].body); 2297 EXPECT_EQ("BODY", parts[0].body);
2296 } 2298 }
2297 } // namespace google_apis 2299 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/drive_api_requests.cc ('k') | google_apis/drive/files_list_request_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698