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

Side by Side Diff: chrome/browser/google_apis/drive_api_requests_unittest.cc

Issue 17315016: Use base::RunLoop instead of directly using MessageLoop in Drive related code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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 "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/message_loop/message_loop_proxy.h" 8 #include "base/message_loop/message_loop_proxy.h"
9 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "chrome/browser/google_apis/auth_service.h" 12 #include "chrome/browser/google_apis/auth_service.h"
12 #include "chrome/browser/google_apis/drive_api_parser.h" 13 #include "chrome/browser/google_apis/drive_api_parser.h"
13 #include "chrome/browser/google_apis/drive_api_requests.h" 14 #include "chrome/browser/google_apis/drive_api_requests.h"
14 #include "chrome/browser/google_apis/drive_api_url_generator.h" 15 #include "chrome/browser/google_apis/drive_api_url_generator.h"
15 #include "chrome/browser/google_apis/request_sender.h" 16 #include "chrome/browser/google_apis/request_sender.h"
16 #include "chrome/browser/google_apis/task_util.h" 17 #include "chrome/browser/google_apis/task_util.h"
17 #include "chrome/browser/google_apis/test_util.h" 18 #include "chrome/browser/google_apis/test_util.h"
18 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 }; 312 };
312 313
313 TEST_F(DriveApiRequestsTest, GetAboutRequest_ValidJson) { 314 TEST_F(DriveApiRequestsTest, GetAboutRequest_ValidJson) {
314 // Set an expected data file containing valid result. 315 // Set an expected data file containing valid result.
315 expected_data_file_path_ = test_util::GetTestFilePath( 316 expected_data_file_path_ = test_util::GetTestFilePath(
316 "chromeos/drive/about.json"); 317 "chromeos/drive/about.json");
317 318
318 GDataErrorCode error = GDATA_OTHER_ERROR; 319 GDataErrorCode error = GDATA_OTHER_ERROR;
319 scoped_ptr<AboutResource> about_resource; 320 scoped_ptr<AboutResource> about_resource;
320 321
321 GetAboutRequest* request = new GetAboutRequest( 322 {
322 request_sender_.get(), 323 base::RunLoop run_loop;
323 request_context_getter_.get(), 324 GetAboutRequest* request = new GetAboutRequest(
324 *url_generator_, 325 request_sender_.get(),
325 CreateComposedCallback( 326 request_context_getter_.get(),
326 base::Bind(&test_util::RunAndQuit), 327 *url_generator_,
327 test_util::CreateCopyResultCallback(&error, &about_resource))); 328 test_util::CreateQuitCallback(
328 request_sender_->StartRequestWithRetry(request); 329 &run_loop,
329 base::MessageLoop::current()->Run(); 330 test_util::CreateCopyResultCallback(&error, &about_resource)));
331 request_sender_->StartRequestWithRetry(request);
332 run_loop.Run();
333 }
330 334
331 EXPECT_EQ(HTTP_SUCCESS, error); 335 EXPECT_EQ(HTTP_SUCCESS, error);
332 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 336 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
333 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 337 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
334 338
335 scoped_ptr<AboutResource> expected( 339 scoped_ptr<AboutResource> expected(
336 AboutResource::CreateFrom( 340 AboutResource::CreateFrom(
337 *test_util::LoadJSONFile("chromeos/drive/about.json"))); 341 *test_util::LoadJSONFile("chromeos/drive/about.json")));
338 ASSERT_TRUE(about_resource.get()); 342 ASSERT_TRUE(about_resource.get());
339 EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id()); 343 EXPECT_EQ(expected->largest_change_id(), about_resource->largest_change_id());
340 EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total()); 344 EXPECT_EQ(expected->quota_bytes_total(), about_resource->quota_bytes_total());
341 EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used()); 345 EXPECT_EQ(expected->quota_bytes_used(), about_resource->quota_bytes_used());
342 EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id()); 346 EXPECT_EQ(expected->root_folder_id(), about_resource->root_folder_id());
343 } 347 }
344 348
345 TEST_F(DriveApiRequestsTest, GetAboutRequest_InvalidJson) { 349 TEST_F(DriveApiRequestsTest, GetAboutRequest_InvalidJson) {
346 // Set an expected data file containing invalid result. 350 // Set an expected data file containing invalid result.
347 expected_data_file_path_ = test_util::GetTestFilePath( 351 expected_data_file_path_ = test_util::GetTestFilePath(
348 "chromeos/gdata/testfile.txt"); 352 "chromeos/gdata/testfile.txt");
349 353
350 GDataErrorCode error = GDATA_OTHER_ERROR; 354 GDataErrorCode error = GDATA_OTHER_ERROR;
351 scoped_ptr<AboutResource> about_resource; 355 scoped_ptr<AboutResource> about_resource;
352 356
353 GetAboutRequest* request = new GetAboutRequest( 357 {
354 request_sender_.get(), 358 base::RunLoop run_loop;
355 request_context_getter_.get(), 359 GetAboutRequest* request = new GetAboutRequest(
356 *url_generator_, 360 request_sender_.get(),
357 CreateComposedCallback( 361 request_context_getter_.get(),
358 base::Bind(&test_util::RunAndQuit), 362 *url_generator_,
359 test_util::CreateCopyResultCallback(&error, &about_resource))); 363 test_util::CreateQuitCallback(
360 request_sender_->StartRequestWithRetry(request); 364 &run_loop,
361 base::MessageLoop::current()->Run(); 365 test_util::CreateCopyResultCallback(&error, &about_resource)));
366 request_sender_->StartRequestWithRetry(request);
367 run_loop.Run();
368 }
362 369
363 // "parse error" should be returned, and the about resource should be NULL. 370 // "parse error" should be returned, and the about resource should be NULL.
364 EXPECT_EQ(GDATA_PARSE_ERROR, error); 371 EXPECT_EQ(GDATA_PARSE_ERROR, error);
365 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 372 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
366 EXPECT_EQ("/drive/v2/about", http_request_.relative_url); 373 EXPECT_EQ("/drive/v2/about", http_request_.relative_url);
367 EXPECT_FALSE(about_resource.get()); 374 EXPECT_FALSE(about_resource.get());
368 } 375 }
369 376
370 TEST_F(DriveApiRequestsTest, GetApplistRequest) { 377 TEST_F(DriveApiRequestsTest, GetApplistRequest) {
371 // Set an expected data file containing valid result. 378 // Set an expected data file containing valid result.
372 expected_data_file_path_ = test_util::GetTestFilePath( 379 expected_data_file_path_ = test_util::GetTestFilePath(
373 "chromeos/drive/applist.json"); 380 "chromeos/drive/applist.json");
374 381
375 GDataErrorCode error = GDATA_OTHER_ERROR; 382 GDataErrorCode error = GDATA_OTHER_ERROR;
376 scoped_ptr<base::Value> result; 383 scoped_ptr<base::Value> result;
377 384
378 GetApplistRequest* request = new GetApplistRequest( 385 {
379 request_sender_.get(), 386 base::RunLoop run_loop;
380 request_context_getter_.get(), 387 GetApplistRequest* request = new GetApplistRequest(
381 *url_generator_, 388 request_sender_.get(),
382 CreateComposedCallback( 389 request_context_getter_.get(),
383 base::Bind(&test_util::RunAndQuit), 390 *url_generator_,
384 test_util::CreateCopyResultCallback(&error, &result))); 391 test_util::CreateQuitCallback(
385 request_sender_->StartRequestWithRetry(request); 392 &run_loop,
386 base::MessageLoop::current()->Run(); 393 test_util::CreateCopyResultCallback(&error, &result)));
394 request_sender_->StartRequestWithRetry(request);
395 run_loop.Run();
396 }
387 397
388 EXPECT_EQ(HTTP_SUCCESS, error); 398 EXPECT_EQ(HTTP_SUCCESS, error);
389 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 399 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
390 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url); 400 EXPECT_EQ("/drive/v2/apps", http_request_.relative_url);
391 EXPECT_TRUE(result); 401 EXPECT_TRUE(result);
392 } 402 }
393 403
394 TEST_F(DriveApiRequestsTest, GetChangelistRequest) { 404 TEST_F(DriveApiRequestsTest, GetChangelistRequest) {
395 // Set an expected data file containing valid result. 405 // Set an expected data file containing valid result.
396 expected_data_file_path_ = test_util::GetTestFilePath( 406 expected_data_file_path_ = test_util::GetTestFilePath(
397 "chromeos/drive/changelist.json"); 407 "chromeos/drive/changelist.json");
398 408
399 GDataErrorCode error = GDATA_OTHER_ERROR; 409 GDataErrorCode error = GDATA_OTHER_ERROR;
400 scoped_ptr<base::Value> result; 410 scoped_ptr<base::Value> result;
401 411
402 GetChangelistRequest* request = new GetChangelistRequest( 412 {
403 request_sender_.get(), 413 base::RunLoop run_loop;
404 request_context_getter_.get(), 414 GetChangelistRequest* request = new GetChangelistRequest(
405 *url_generator_, 415 request_sender_.get(),
406 true, // include deleted 416 request_context_getter_.get(),
407 100, // start changestamp 417 *url_generator_,
408 500, // max results 418 true, // include deleted
409 CreateComposedCallback( 419 100, // start changestamp
410 base::Bind(&test_util::RunAndQuit), 420 500, // max results
411 test_util::CreateCopyResultCallback(&error, &result))); 421 test_util::CreateQuitCallback(
412 request_sender_->StartRequestWithRetry(request); 422 &run_loop,
413 base::MessageLoop::current()->Run(); 423 test_util::CreateCopyResultCallback(&error, &result)));
424 request_sender_->StartRequestWithRetry(request);
425 run_loop.Run();
426 }
414 427
415 EXPECT_EQ(HTTP_SUCCESS, error); 428 EXPECT_EQ(HTTP_SUCCESS, error);
416 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 429 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
417 EXPECT_EQ("/drive/v2/changes?startChangeId=100&maxResults=500", 430 EXPECT_EQ("/drive/v2/changes?startChangeId=100&maxResults=500",
418 http_request_.relative_url); 431 http_request_.relative_url);
419 EXPECT_TRUE(result); 432 EXPECT_TRUE(result);
420 } 433 }
421 434
422 TEST_F(DriveApiRequestsTest, GetFilelistRequest) { 435 TEST_F(DriveApiRequestsTest, GetFilelistRequest) {
423 // Set an expected data file containing valid result. 436 // Set an expected data file containing valid result.
424 expected_data_file_path_ = test_util::GetTestFilePath( 437 expected_data_file_path_ = test_util::GetTestFilePath(
425 "chromeos/drive/filelist.json"); 438 "chromeos/drive/filelist.json");
426 439
427 GDataErrorCode error = GDATA_OTHER_ERROR; 440 GDataErrorCode error = GDATA_OTHER_ERROR;
428 scoped_ptr<base::Value> result; 441 scoped_ptr<base::Value> result;
429 442
430 GetFilelistRequest* request = new GetFilelistRequest( 443 {
431 request_sender_.get(), 444 base::RunLoop run_loop;
432 request_context_getter_.get(), 445 GetFilelistRequest* request = new GetFilelistRequest(
433 *url_generator_, 446 request_sender_.get(),
434 "\"abcde\" in parents", 447 request_context_getter_.get(),
435 50, // max results 448 *url_generator_,
436 CreateComposedCallback( 449 "\"abcde\" in parents",
437 base::Bind(&test_util::RunAndQuit), 450 50, // max results
438 test_util::CreateCopyResultCallback(&error, &result))); 451 test_util::CreateQuitCallback(
439 request_sender_->StartRequestWithRetry(request); 452 &run_loop,
440 base::MessageLoop::current()->Run(); 453 test_util::CreateCopyResultCallback(&error, &result)));
454 request_sender_->StartRequestWithRetry(request);
455 run_loop.Run();
456 }
441 457
442 EXPECT_EQ(HTTP_SUCCESS, error); 458 EXPECT_EQ(HTTP_SUCCESS, error);
443 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 459 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
444 EXPECT_EQ("/drive/v2/files?maxResults=50&q=%22abcde%22+in+parents", 460 EXPECT_EQ("/drive/v2/files?maxResults=50&q=%22abcde%22+in+parents",
445 http_request_.relative_url); 461 http_request_.relative_url);
446 EXPECT_TRUE(result); 462 EXPECT_TRUE(result);
447 } 463 }
448 464
449 TEST_F(DriveApiRequestsTest, ContinueGetFileListRequest) { 465 TEST_F(DriveApiRequestsTest, ContinueGetFileListRequest) {
450 // Set an expected data file containing valid result. 466 // Set an expected data file containing valid result.
451 expected_data_file_path_ = test_util::GetTestFilePath( 467 expected_data_file_path_ = test_util::GetTestFilePath(
452 "chromeos/drive/filelist.json"); 468 "chromeos/drive/filelist.json");
453 469
454 GDataErrorCode error = GDATA_OTHER_ERROR; 470 GDataErrorCode error = GDATA_OTHER_ERROR;
455 scoped_ptr<base::Value> result; 471 scoped_ptr<base::Value> result;
456 472
457 drive::ContinueGetFileListRequest* request = 473 {
458 new drive::ContinueGetFileListRequest( 474 base::RunLoop run_loop;
459 request_sender_.get(), 475 drive::ContinueGetFileListRequest* request =
460 request_context_getter_.get(), 476 new drive::ContinueGetFileListRequest(
461 test_server_.GetURL("/continue/get/file/list"), 477 request_sender_.get(),
462 CreateComposedCallback( 478 request_context_getter_.get(),
463 base::Bind(&test_util::RunAndQuit), 479 test_server_.GetURL("/continue/get/file/list"),
464 test_util::CreateCopyResultCallback(&error, &result))); 480 test_util::CreateQuitCallback(
465 request_sender_->StartRequestWithRetry(request); 481 &run_loop,
466 base::MessageLoop::current()->Run(); 482 test_util::CreateCopyResultCallback(&error, &result)));
483 request_sender_->StartRequestWithRetry(request);
484 run_loop.Run();
485 }
467 486
468 EXPECT_EQ(HTTP_SUCCESS, error); 487 EXPECT_EQ(HTTP_SUCCESS, error);
469 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 488 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
470 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url); 489 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url);
471 EXPECT_TRUE(result); 490 EXPECT_TRUE(result);
472 } 491 }
473 492
474 TEST_F(DriveApiRequestsTest, CreateDirectoryRequest) { 493 TEST_F(DriveApiRequestsTest, CreateDirectoryRequest) {
475 // Set an expected data file containing the directory's entry data. 494 // Set an expected data file containing the directory's entry data.
476 expected_data_file_path_ = 495 expected_data_file_path_ =
477 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); 496 test_util::GetTestFilePath("chromeos/drive/directory_entry.json");
478 497
479 GDataErrorCode error = GDATA_OTHER_ERROR; 498 GDataErrorCode error = GDATA_OTHER_ERROR;
480 scoped_ptr<FileResource> file_resource; 499 scoped_ptr<FileResource> file_resource;
481 500
482 // Create "new directory" in the root directory. 501 // Create "new directory" in the root directory.
483 drive::CreateDirectoryRequest* request = 502 {
484 new drive::CreateDirectoryRequest( 503 base::RunLoop run_loop;
485 request_sender_.get(), 504 drive::CreateDirectoryRequest* request =
486 request_context_getter_.get(), 505 new drive::CreateDirectoryRequest(
487 *url_generator_, 506 request_sender_.get(),
488 "root", 507 request_context_getter_.get(),
489 "new directory", 508 *url_generator_,
490 CreateComposedCallback( 509 "root",
491 base::Bind(&test_util::RunAndQuit), 510 "new directory",
492 test_util::CreateCopyResultCallback(&error, &file_resource))); 511 test_util::CreateQuitCallback(
493 request_sender_->StartRequestWithRetry(request); 512 &run_loop,
494 base::MessageLoop::current()->Run(); 513 test_util::CreateCopyResultCallback(&error, &file_resource)));
514 request_sender_->StartRequestWithRetry(request);
515 run_loop.Run();
516 }
495 517
496 EXPECT_EQ(HTTP_SUCCESS, error); 518 EXPECT_EQ(HTTP_SUCCESS, error);
497 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 519 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
498 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); 520 EXPECT_EQ("/drive/v2/files", http_request_.relative_url);
499 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 521 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
500 522
501 EXPECT_TRUE(http_request_.has_content); 523 EXPECT_TRUE(http_request_.has_content);
502 524
503 scoped_ptr<FileResource> expected( 525 scoped_ptr<FileResource> expected(
504 FileResource::CreateFrom( 526 FileResource::CreateFrom(
(...skipping 10 matching lines...) Expand all
515 537
516 TEST_F(DriveApiRequestsTest, RenameResourceRequest) { 538 TEST_F(DriveApiRequestsTest, RenameResourceRequest) {
517 // Set an expected data file containing the directory's entry data. 539 // Set an expected data file containing the directory's entry data.
518 // It'd be returned if we rename a directory. 540 // It'd be returned if we rename a directory.
519 expected_data_file_path_ = 541 expected_data_file_path_ =
520 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); 542 test_util::GetTestFilePath("chromeos/drive/directory_entry.json");
521 543
522 GDataErrorCode error = GDATA_OTHER_ERROR; 544 GDataErrorCode error = GDATA_OTHER_ERROR;
523 545
524 // Create "new directory" in the root directory. 546 // Create "new directory" in the root directory.
525 drive::RenameResourceRequest* request = 547 {
526 new drive::RenameResourceRequest( 548 base::RunLoop run_loop;
527 request_sender_.get(), 549 drive::RenameResourceRequest* request =
528 request_context_getter_.get(), 550 new drive::RenameResourceRequest(
529 *url_generator_, 551 request_sender_.get(),
530 "resource_id", 552 request_context_getter_.get(),
531 "new name", 553 *url_generator_,
532 CreateComposedCallback( 554 "resource_id",
533 base::Bind(&test_util::RunAndQuit), 555 "new name",
534 test_util::CreateCopyResultCallback(&error))); 556 test_util::CreateQuitCallback(
535 request_sender_->StartRequestWithRetry(request); 557 &run_loop,
536 base::MessageLoop::current()->Run(); 558 test_util::CreateCopyResultCallback(&error)));
559 request_sender_->StartRequestWithRetry(request);
560 run_loop.Run();
561 }
537 562
538 EXPECT_EQ(HTTP_SUCCESS, error); 563 EXPECT_EQ(HTTP_SUCCESS, error);
539 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); 564 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method);
540 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url); 565 EXPECT_EQ("/drive/v2/files/resource_id", http_request_.relative_url);
541 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 566 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
542 567
543 EXPECT_TRUE(http_request_.has_content); 568 EXPECT_TRUE(http_request_.has_content);
544 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content); 569 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content);
545 } 570 }
546 571
547 TEST_F(DriveApiRequestsTest, TouchResourceRequest) { 572 TEST_F(DriveApiRequestsTest, TouchResourceRequest) {
548 // Set an expected data file containing the directory's entry data. 573 // Set an expected data file containing the directory's entry data.
549 // It'd be returned if we rename a directory. 574 // It'd be returned if we rename a directory.
550 expected_data_file_path_ = 575 expected_data_file_path_ =
551 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); 576 test_util::GetTestFilePath("chromeos/drive/directory_entry.json");
552 577
553 GDataErrorCode error = GDATA_OTHER_ERROR; 578 GDataErrorCode error = GDATA_OTHER_ERROR;
554 scoped_ptr<FileResource> file_resource; 579 scoped_ptr<FileResource> file_resource;
555 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; 580 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123};
556 const base::Time::Exploded kLastViewedByMeDate = 581 const base::Time::Exploded kLastViewedByMeDate =
557 {2013, 7, 0, 19, 15, 59, 13, 123}; 582 {2013, 7, 0, 19, 15, 59, 13, 123};
558 583
559 // Touch a file with |resource_id|. 584 // Touch a file with |resource_id|.
560 drive::TouchResourceRequest* request = new drive::TouchResourceRequest( 585 {
561 request_sender_.get(), 586 base::RunLoop run_loop;
562 request_context_getter_.get(), 587 drive::TouchResourceRequest* request = new drive::TouchResourceRequest(
563 *url_generator_, 588 request_sender_.get(),
564 "resource_id", 589 request_context_getter_.get(),
565 base::Time::FromUTCExploded(kModifiedDate), 590 *url_generator_,
566 base::Time::FromUTCExploded(kLastViewedByMeDate), 591 "resource_id",
567 CreateComposedCallback( 592 base::Time::FromUTCExploded(kModifiedDate),
568 base::Bind(&test_util::RunAndQuit), 593 base::Time::FromUTCExploded(kLastViewedByMeDate),
569 test_util::CreateCopyResultCallback(&error, &file_resource))); 594 test_util::CreateQuitCallback(
570 request_sender_->StartRequestWithRetry(request); 595 &run_loop,
571 base::MessageLoop::current()->Run(); 596 test_util::CreateCopyResultCallback(&error, &file_resource)));
597 request_sender_->StartRequestWithRetry(request);
598 run_loop.Run();
599 }
572 600
573 EXPECT_EQ(HTTP_SUCCESS, error); 601 EXPECT_EQ(HTTP_SUCCESS, error);
574 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); 602 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method);
575 EXPECT_EQ("/drive/v2/files/resource_id" 603 EXPECT_EQ("/drive/v2/files/resource_id"
576 "?setModifiedDate=true&updateViewedDate=false", 604 "?setModifiedDate=true&updateViewedDate=false",
577 http_request_.relative_url); 605 http_request_.relative_url);
578 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 606 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
579 607
580 EXPECT_TRUE(http_request_.has_content); 608 EXPECT_TRUE(http_request_.has_content);
581 EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\"," 609 EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\","
582 "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\"}", 610 "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\"}",
583 http_request_.content); 611 http_request_.content);
584 } 612 }
585 613
586 TEST_F(DriveApiRequestsTest, CopyResourceRequest) { 614 TEST_F(DriveApiRequestsTest, CopyResourceRequest) {
587 // Set an expected data file containing the dummy file entry data. 615 // Set an expected data file containing the dummy file entry data.
588 // It'd be returned if we copy a file. 616 // It'd be returned if we copy a file.
589 expected_data_file_path_ = 617 expected_data_file_path_ =
590 test_util::GetTestFilePath("chromeos/drive/file_entry.json"); 618 test_util::GetTestFilePath("chromeos/drive/file_entry.json");
591 619
592 GDataErrorCode error = GDATA_OTHER_ERROR; 620 GDataErrorCode error = GDATA_OTHER_ERROR;
593 scoped_ptr<FileResource> file_resource; 621 scoped_ptr<FileResource> file_resource;
594 622
595 // Copy the file to a new file named "new name". 623 // Copy the file to a new file named "new name".
596 drive::CopyResourceRequest* request = 624 {
597 new drive::CopyResourceRequest( 625 base::RunLoop run_loop;
598 request_sender_.get(), 626 drive::CopyResourceRequest* request =
599 request_context_getter_.get(), 627 new drive::CopyResourceRequest(
600 *url_generator_, 628 request_sender_.get(),
601 "resource_id", 629 request_context_getter_.get(),
602 "parent_resource_id", 630 *url_generator_,
603 "new name", 631 "resource_id",
604 CreateComposedCallback( 632 "parent_resource_id",
605 base::Bind(&test_util::RunAndQuit), 633 "new name",
606 test_util::CreateCopyResultCallback(&error, &file_resource))); 634 test_util::CreateQuitCallback(
607 request_sender_->StartRequestWithRetry(request); 635 &run_loop,
608 base::MessageLoop::current()->Run(); 636 test_util::CreateCopyResultCallback(&error, &file_resource)));
637 request_sender_->StartRequestWithRetry(request);
638 run_loop.Run();
639 }
609 640
610 EXPECT_EQ(HTTP_SUCCESS, error); 641 EXPECT_EQ(HTTP_SUCCESS, error);
611 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 642 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
612 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); 643 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url);
613 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 644 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
614 645
615 EXPECT_TRUE(http_request_.has_content); 646 EXPECT_TRUE(http_request_.has_content);
616 EXPECT_EQ( 647 EXPECT_EQ(
617 "{\"parents\":[{\"id\":\"parent_resource_id\"}],\"title\":\"new name\"}", 648 "{\"parents\":[{\"id\":\"parent_resource_id\"}],\"title\":\"new name\"}",
618 http_request_.content); 649 http_request_.content);
619 EXPECT_TRUE(file_resource); 650 EXPECT_TRUE(file_resource);
620 } 651 }
621 652
622 TEST_F(DriveApiRequestsTest, CopyResourceRequest_EmptyParentResourceId) { 653 TEST_F(DriveApiRequestsTest, CopyResourceRequest_EmptyParentResourceId) {
623 // Set an expected data file containing the dummy file entry data. 654 // Set an expected data file containing the dummy file entry data.
624 // It'd be returned if we copy a file. 655 // It'd be returned if we copy a file.
625 expected_data_file_path_ = 656 expected_data_file_path_ =
626 test_util::GetTestFilePath("chromeos/drive/file_entry.json"); 657 test_util::GetTestFilePath("chromeos/drive/file_entry.json");
627 658
628 GDataErrorCode error = GDATA_OTHER_ERROR; 659 GDataErrorCode error = GDATA_OTHER_ERROR;
629 scoped_ptr<FileResource> file_resource; 660 scoped_ptr<FileResource> file_resource;
630 661
631 // Copy the file to a new file named "new name". 662 // Copy the file to a new file named "new name".
632 drive::CopyResourceRequest* request = 663 {
633 new drive::CopyResourceRequest( 664 base::RunLoop run_loop;
634 request_sender_.get(), 665 drive::CopyResourceRequest* request =
635 request_context_getter_.get(), 666 new drive::CopyResourceRequest(
636 *url_generator_, 667 request_sender_.get(),
637 "resource_id", 668 request_context_getter_.get(),
638 std::string(), // parent resource id. 669 *url_generator_,
639 "new name", 670 "resource_id",
640 CreateComposedCallback( 671 std::string(), // parent resource id.
641 base::Bind(&test_util::RunAndQuit), 672 "new name",
642 test_util::CreateCopyResultCallback(&error, &file_resource))); 673 test_util::CreateQuitCallback(
643 request_sender_->StartRequestWithRetry(request); 674 &run_loop,
644 base::MessageLoop::current()->Run(); 675 test_util::CreateCopyResultCallback(&error, &file_resource)));
676 request_sender_->StartRequestWithRetry(request);
677 run_loop.Run();
678 }
645 679
646 EXPECT_EQ(HTTP_SUCCESS, error); 680 EXPECT_EQ(HTTP_SUCCESS, error);
647 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 681 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
648 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url); 682 EXPECT_EQ("/drive/v2/files/resource_id/copy", http_request_.relative_url);
649 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 683 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
650 684
651 EXPECT_TRUE(http_request_.has_content); 685 EXPECT_TRUE(http_request_.has_content);
652 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content); 686 EXPECT_EQ("{\"title\":\"new name\"}", http_request_.content);
653 EXPECT_TRUE(file_resource); 687 EXPECT_TRUE(file_resource);
654 } 688 }
655 689
656 TEST_F(DriveApiRequestsTest, TrashResourceRequest) { 690 TEST_F(DriveApiRequestsTest, TrashResourceRequest) {
657 // Set data for the expected result. Directory entry should be returned 691 // Set data for the expected result. Directory entry should be returned
658 // if the trashing entry is a directory, so using it here should be fine. 692 // if the trashing entry is a directory, so using it here should be fine.
659 expected_data_file_path_ = 693 expected_data_file_path_ =
660 test_util::GetTestFilePath("chromeos/drive/directory_entry.json"); 694 test_util::GetTestFilePath("chromeos/drive/directory_entry.json");
661 695
662 GDataErrorCode error = GDATA_OTHER_ERROR; 696 GDataErrorCode error = GDATA_OTHER_ERROR;
663 697
664 // Trash a resource with the given resource id. 698 // Trash a resource with the given resource id.
665 drive::TrashResourceRequest* request = 699 {
666 new drive::TrashResourceRequest( 700 base::RunLoop run_loop;
667 request_sender_.get(), 701 drive::TrashResourceRequest* request =
668 request_context_getter_.get(), 702 new drive::TrashResourceRequest(
669 *url_generator_, 703 request_sender_.get(),
670 "resource_id", 704 request_context_getter_.get(),
671 CreateComposedCallback( 705 *url_generator_,
672 base::Bind(&test_util::RunAndQuit), 706 "resource_id",
673 test_util::CreateCopyResultCallback(&error))); 707 test_util::CreateQuitCallback(
674 request_sender_->StartRequestWithRetry(request); 708 &run_loop,
675 base::MessageLoop::current()->Run(); 709 test_util::CreateCopyResultCallback(&error)));
710 request_sender_->StartRequestWithRetry(request);
711 run_loop.Run();
712 }
676 713
677 EXPECT_EQ(HTTP_SUCCESS, error); 714 EXPECT_EQ(HTTP_SUCCESS, error);
678 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 715 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
679 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url); 716 EXPECT_EQ("/drive/v2/files/resource_id/trash", http_request_.relative_url);
680 EXPECT_TRUE(http_request_.has_content); 717 EXPECT_TRUE(http_request_.has_content);
681 EXPECT_TRUE(http_request_.content.empty()); 718 EXPECT_TRUE(http_request_.content.empty());
682 } 719 }
683 720
684 TEST_F(DriveApiRequestsTest, InsertResourceRequest) { 721 TEST_F(DriveApiRequestsTest, InsertResourceRequest) {
685 // Set an expected data file containing the children entry. 722 // Set an expected data file containing the children entry.
686 expected_content_type_ = "application/json"; 723 expected_content_type_ = "application/json";
687 expected_content_ = kTestChildrenResponse; 724 expected_content_ = kTestChildrenResponse;
688 725
689 GDataErrorCode error = GDATA_OTHER_ERROR; 726 GDataErrorCode error = GDATA_OTHER_ERROR;
690 727
691 // Add a resource with "resource_id" to a directory with 728 // Add a resource with "resource_id" to a directory with
692 // "parent_resource_id". 729 // "parent_resource_id".
693 drive::InsertResourceRequest* request = 730 {
694 new drive::InsertResourceRequest( 731 base::RunLoop run_loop;
695 request_sender_.get(), 732 drive::InsertResourceRequest* request =
696 request_context_getter_.get(), 733 new drive::InsertResourceRequest(
697 *url_generator_, 734 request_sender_.get(),
698 "parent_resource_id", 735 request_context_getter_.get(),
699 "resource_id", 736 *url_generator_,
700 CreateComposedCallback( 737 "parent_resource_id",
701 base::Bind(&test_util::RunAndQuit), 738 "resource_id",
702 test_util::CreateCopyResultCallback(&error))); 739 test_util::CreateQuitCallback(
703 request_sender_->StartRequestWithRetry(request); 740 &run_loop,
704 base::MessageLoop::current()->Run(); 741 test_util::CreateCopyResultCallback(&error)));
742 request_sender_->StartRequestWithRetry(request);
743 run_loop.Run();
744 }
705 745
706 EXPECT_EQ(HTTP_SUCCESS, error); 746 EXPECT_EQ(HTTP_SUCCESS, error);
707 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 747 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
708 EXPECT_EQ("/drive/v2/files/parent_resource_id/children", 748 EXPECT_EQ("/drive/v2/files/parent_resource_id/children",
709 http_request_.relative_url); 749 http_request_.relative_url);
710 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 750 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
711 751
712 EXPECT_TRUE(http_request_.has_content); 752 EXPECT_TRUE(http_request_.has_content);
713 EXPECT_EQ("{\"id\":\"resource_id\"}", http_request_.content); 753 EXPECT_EQ("{\"id\":\"resource_id\"}", http_request_.content);
714 } 754 }
715 755
716 TEST_F(DriveApiRequestsTest, DeleteResourceRequest) { 756 TEST_F(DriveApiRequestsTest, DeleteResourceRequest) {
717 GDataErrorCode error = GDATA_OTHER_ERROR; 757 GDataErrorCode error = GDATA_OTHER_ERROR;
718 758
719 // Remove a resource with "resource_id" from a directory with 759 // Remove a resource with "resource_id" from a directory with
720 // "parent_resource_id". 760 // "parent_resource_id".
721 drive::DeleteResourceRequest* request = 761 {
722 new drive::DeleteResourceRequest( 762 base::RunLoop run_loop;
723 request_sender_.get(), 763 drive::DeleteResourceRequest* request =
724 request_context_getter_.get(), 764 new drive::DeleteResourceRequest(
725 *url_generator_, 765 request_sender_.get(),
726 "parent_resource_id", 766 request_context_getter_.get(),
727 "resource_id", 767 *url_generator_,
728 CreateComposedCallback( 768 "parent_resource_id",
729 base::Bind(&test_util::RunAndQuit), 769 "resource_id",
730 test_util::CreateCopyResultCallback(&error))); 770 test_util::CreateQuitCallback(
731 request_sender_->StartRequestWithRetry(request); 771 &run_loop,
732 base::MessageLoop::current()->Run(); 772 test_util::CreateCopyResultCallback(&error)));
773 request_sender_->StartRequestWithRetry(request);
774 run_loop.Run();
775 }
733 776
734 EXPECT_EQ(HTTP_NO_CONTENT, error); 777 EXPECT_EQ(HTTP_NO_CONTENT, error);
735 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); 778 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
736 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id", 779 EXPECT_EQ("/drive/v2/files/parent_resource_id/children/resource_id",
737 http_request_.relative_url); 780 http_request_.relative_url);
738 EXPECT_FALSE(http_request_.has_content); 781 EXPECT_FALSE(http_request_.has_content);
739 } 782 }
740 783
741 TEST_F(DriveApiRequestsTest, UploadNewFileRequest) { 784 TEST_F(DriveApiRequestsTest, UploadNewFileRequest) {
742 // Set an expected url for uploading. 785 // Set an expected url for uploading.
743 expected_upload_path_ = kTestUploadNewFilePath; 786 expected_upload_path_ = kTestUploadNewFilePath;
744 787
745 const char kTestContentType[] = "text/plain"; 788 const char kTestContentType[] = "text/plain";
746 const std::string kTestContent(100, 'a'); 789 const std::string kTestContent(100, 'a');
747 const base::FilePath kTestFilePath = 790 const base::FilePath kTestFilePath =
748 temp_dir_.path().AppendASCII("upload_file.txt"); 791 temp_dir_.path().AppendASCII("upload_file.txt");
749 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); 792 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent));
750 793
751 GDataErrorCode error = GDATA_OTHER_ERROR; 794 GDataErrorCode error = GDATA_OTHER_ERROR;
752 GURL upload_url; 795 GURL upload_url;
753 796
754 // Initiate uploading a new file to the directory with 797 // Initiate uploading a new file to the directory with
755 // "parent_resource_id". 798 // "parent_resource_id".
756 drive::InitiateUploadNewFileRequest* request = 799 {
757 new drive::InitiateUploadNewFileRequest( 800 base::RunLoop run_loop;
758 request_sender_.get(), 801 drive::InitiateUploadNewFileRequest* request =
759 request_context_getter_.get(), 802 new drive::InitiateUploadNewFileRequest(
760 *url_generator_, 803 request_sender_.get(),
761 kTestContentType, 804 request_context_getter_.get(),
762 kTestContent.size(), 805 *url_generator_,
763 "parent_resource_id", // The resource id of the parent directory. 806 kTestContentType,
764 "new file title", // The title of the file being uploaded. 807 kTestContent.size(),
765 CreateComposedCallback( 808 "parent_resource_id", // The resource id of the parent directory.
766 base::Bind(&test_util::RunAndQuit), 809 "new file title", // The title of the file being uploaded.
767 test_util::CreateCopyResultCallback(&error, &upload_url))); 810 test_util::CreateQuitCallback(
768 request_sender_->StartRequestWithRetry(request); 811 &run_loop,
769 base::MessageLoop::current()->Run(); 812 test_util::CreateCopyResultCallback(&error, &upload_url)));
813 request_sender_->StartRequestWithRetry(request);
814 run_loop.Run();
815 }
770 816
771 EXPECT_EQ(HTTP_SUCCESS, error); 817 EXPECT_EQ(HTTP_SUCCESS, error);
772 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); 818 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
773 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 819 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
774 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 820 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
775 http_request_.headers["X-Upload-Content-Length"]); 821 http_request_.headers["X-Upload-Content-Length"]);
776 822
777 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 823 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
778 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", 824 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
779 http_request_.relative_url); 825 http_request_.relative_url);
780 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 826 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
781 EXPECT_TRUE(http_request_.has_content); 827 EXPECT_TRUE(http_request_.has_content);
782 EXPECT_EQ("{\"parents\":[{" 828 EXPECT_EQ("{\"parents\":[{"
783 "\"id\":\"parent_resource_id\"," 829 "\"id\":\"parent_resource_id\","
784 "\"kind\":\"drive#fileLink\"" 830 "\"kind\":\"drive#fileLink\""
785 "}]," 831 "}],"
786 "\"title\":\"new file title\"}", 832 "\"title\":\"new file title\"}",
787 http_request_.content); 833 http_request_.content);
788 834
789 // Upload the content to the upload URL. 835 // Upload the content to the upload URL.
790 UploadRangeResponse response; 836 UploadRangeResponse response;
791 scoped_ptr<FileResource> new_entry; 837 scoped_ptr<FileResource> new_entry;
792 838
793 drive::ResumeUploadRequest* resume_request = 839 {
794 new drive::ResumeUploadRequest( 840 base::RunLoop run_loop;
795 request_sender_.get(), 841 drive::ResumeUploadRequest* resume_request =
796 request_context_getter_.get(), 842 new drive::ResumeUploadRequest(
797 upload_url, 843 request_sender_.get(),
798 0, // start_position 844 request_context_getter_.get(),
799 kTestContent.size(), // end_position (exclusive) 845 upload_url,
800 kTestContent.size(), // content_length, 846 0, // start_position
801 kTestContentType, 847 kTestContent.size(), // end_position (exclusive)
802 kTestFilePath, 848 kTestContent.size(), // content_length,
803 CreateComposedCallback( 849 kTestContentType,
804 base::Bind(&test_util::RunAndQuit), 850 kTestFilePath,
805 test_util::CreateCopyResultCallback(&response, &new_entry)), 851 test_util::CreateQuitCallback(
806 ProgressCallback()); 852 &run_loop,
807 request_sender_->StartRequestWithRetry(resume_request); 853 test_util::CreateCopyResultCallback(&response, &new_entry)),
808 base::MessageLoop::current()->Run(); 854 ProgressCallback());
855 request_sender_->StartRequestWithRetry(resume_request);
856 run_loop.Run();
857 }
809 858
810 // METHOD_PUT should be used to upload data. 859 // METHOD_PUT should be used to upload data.
811 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 860 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
812 // Request should go to the upload URL. 861 // Request should go to the upload URL.
813 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 862 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
814 // Content-Range header should be added. 863 // Content-Range header should be added.
815 EXPECT_EQ("bytes 0-" + 864 EXPECT_EQ("bytes 0-" +
816 base::Int64ToString(kTestContent.size() - 1) + "/" + 865 base::Int64ToString(kTestContent.size() - 1) + "/" +
817 base::Int64ToString(kTestContent.size()), 866 base::Int64ToString(kTestContent.size()),
818 http_request_.headers["Content-Range"]); 867 http_request_.headers["Content-Range"]);
(...skipping 15 matching lines...) Expand all
834 const char kTestContentType[] = "text/plain"; 883 const char kTestContentType[] = "text/plain";
835 const char kTestContent[] = ""; 884 const char kTestContent[] = "";
836 const base::FilePath kTestFilePath = 885 const base::FilePath kTestFilePath =
837 temp_dir_.path().AppendASCII("empty_file.txt"); 886 temp_dir_.path().AppendASCII("empty_file.txt");
838 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); 887 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent));
839 888
840 GDataErrorCode error = GDATA_OTHER_ERROR; 889 GDataErrorCode error = GDATA_OTHER_ERROR;
841 GURL upload_url; 890 GURL upload_url;
842 891
843 // Initiate uploading a new file to the directory with "parent_resource_id". 892 // Initiate uploading a new file to the directory with "parent_resource_id".
844 drive::InitiateUploadNewFileRequest* request = 893 {
845 new drive::InitiateUploadNewFileRequest( 894 base::RunLoop run_loop;
846 request_sender_.get(), 895 drive::InitiateUploadNewFileRequest* request =
847 request_context_getter_.get(), 896 new drive::InitiateUploadNewFileRequest(
848 *url_generator_, 897 request_sender_.get(),
849 kTestContentType, 898 request_context_getter_.get(),
850 0, 899 *url_generator_,
851 "parent_resource_id", // The resource id of the parent directory. 900 kTestContentType,
852 "new file title", // The title of the file being uploaded. 901 0,
853 CreateComposedCallback( 902 "parent_resource_id", // The resource id of the parent directory.
854 base::Bind(&test_util::RunAndQuit), 903 "new file title", // The title of the file being uploaded.
855 test_util::CreateCopyResultCallback(&error, &upload_url))); 904 test_util::CreateQuitCallback(
856 request_sender_->StartRequestWithRetry(request); 905 &run_loop,
857 base::MessageLoop::current()->Run(); 906 test_util::CreateCopyResultCallback(&error, &upload_url)));
907 request_sender_->StartRequestWithRetry(request);
908 run_loop.Run();
909 }
858 910
859 EXPECT_EQ(HTTP_SUCCESS, error); 911 EXPECT_EQ(HTTP_SUCCESS, error);
860 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); 912 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
861 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 913 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
862 EXPECT_EQ("0", http_request_.headers["X-Upload-Content-Length"]); 914 EXPECT_EQ("0", http_request_.headers["X-Upload-Content-Length"]);
863 915
864 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 916 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
865 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", 917 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
866 http_request_.relative_url); 918 http_request_.relative_url);
867 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 919 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
868 EXPECT_TRUE(http_request_.has_content); 920 EXPECT_TRUE(http_request_.has_content);
869 EXPECT_EQ("{\"parents\":[{" 921 EXPECT_EQ("{\"parents\":[{"
870 "\"id\":\"parent_resource_id\"," 922 "\"id\":\"parent_resource_id\","
871 "\"kind\":\"drive#fileLink\"" 923 "\"kind\":\"drive#fileLink\""
872 "}]," 924 "}],"
873 "\"title\":\"new file title\"}", 925 "\"title\":\"new file title\"}",
874 http_request_.content); 926 http_request_.content);
875 927
876 // Upload the content to the upload URL. 928 // Upload the content to the upload URL.
877 UploadRangeResponse response; 929 UploadRangeResponse response;
878 scoped_ptr<FileResource> new_entry; 930 scoped_ptr<FileResource> new_entry;
879 931
880 drive::ResumeUploadRequest* resume_request = 932 {
881 new drive::ResumeUploadRequest( 933 base::RunLoop run_loop;
882 request_sender_.get(), 934 drive::ResumeUploadRequest* resume_request =
883 request_context_getter_.get(), 935 new drive::ResumeUploadRequest(
884 upload_url, 936 request_sender_.get(),
885 0, // start_position 937 request_context_getter_.get(),
886 0, // end_position (exclusive) 938 upload_url,
887 0, // content_length, 939 0, // start_position
888 kTestContentType, 940 0, // end_position (exclusive)
889 kTestFilePath, 941 0, // content_length,
890 CreateComposedCallback( 942 kTestContentType,
891 base::Bind(&test_util::RunAndQuit), 943 kTestFilePath,
892 test_util::CreateCopyResultCallback(&response, &new_entry)), 944 test_util::CreateQuitCallback(
893 ProgressCallback()); 945 &run_loop,
894 request_sender_->StartRequestWithRetry(resume_request); 946 test_util::CreateCopyResultCallback(&response, &new_entry)),
895 base::MessageLoop::current()->Run(); 947 ProgressCallback());
948 request_sender_->StartRequestWithRetry(resume_request);
949 run_loop.Run();
950 }
896 951
897 // METHOD_PUT should be used to upload data. 952 // METHOD_PUT should be used to upload data.
898 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 953 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
899 // Request should go to the upload URL. 954 // Request should go to the upload URL.
900 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 955 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
901 // Content-Range header should NOT be added. 956 // Content-Range header should NOT be added.
902 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); 957 EXPECT_EQ(0U, http_request_.headers.count("Content-Range"));
903 // The upload content should be set in the HTTP request. 958 // The upload content should be set in the HTTP request.
904 EXPECT_TRUE(http_request_.has_content); 959 EXPECT_TRUE(http_request_.has_content);
905 EXPECT_EQ(kTestContent, http_request_.content); 960 EXPECT_EQ(kTestContent, http_request_.content);
(...skipping 13 matching lines...) Expand all
919 const size_t kNumChunkBytes = 10; // Num bytes in a chunk. 974 const size_t kNumChunkBytes = 10; // Num bytes in a chunk.
920 const std::string kTestContent(100, 'a'); 975 const std::string kTestContent(100, 'a');
921 const base::FilePath kTestFilePath = 976 const base::FilePath kTestFilePath =
922 temp_dir_.path().AppendASCII("upload_file.txt"); 977 temp_dir_.path().AppendASCII("upload_file.txt");
923 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); 978 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent));
924 979
925 GDataErrorCode error = GDATA_OTHER_ERROR; 980 GDataErrorCode error = GDATA_OTHER_ERROR;
926 GURL upload_url; 981 GURL upload_url;
927 982
928 // Initiate uploading a new file to the directory with "parent_resource_id". 983 // Initiate uploading a new file to the directory with "parent_resource_id".
929 drive::InitiateUploadNewFileRequest* request = 984 {
930 new drive::InitiateUploadNewFileRequest( 985 base::RunLoop run_loop;
931 request_sender_.get(), 986 drive::InitiateUploadNewFileRequest* request =
932 request_context_getter_.get(), 987 new drive::InitiateUploadNewFileRequest(
933 *url_generator_, 988 request_sender_.get(),
934 kTestContentType, 989 request_context_getter_.get(),
935 kTestContent.size(), 990 *url_generator_,
936 "parent_resource_id", // The resource id of the parent directory. 991 kTestContentType,
937 "new file title", // The title of the file being uploaded. 992 kTestContent.size(),
938 CreateComposedCallback( 993 "parent_resource_id", // The resource id of the parent directory.
939 base::Bind(&test_util::RunAndQuit), 994 "new file title", // The title of the file being uploaded.
940 test_util::CreateCopyResultCallback(&error, &upload_url))); 995 test_util::CreateQuitCallback(
941 request_sender_->StartRequestWithRetry(request); 996 &run_loop,
942 base::MessageLoop::current()->Run(); 997 test_util::CreateCopyResultCallback(&error, &upload_url)));
998 request_sender_->StartRequestWithRetry(request);
999 run_loop.Run();
1000 }
943 1001
944 EXPECT_EQ(HTTP_SUCCESS, error); 1002 EXPECT_EQ(HTTP_SUCCESS, error);
945 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); 1003 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path());
946 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 1004 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
947 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 1005 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
948 http_request_.headers["X-Upload-Content-Length"]); 1006 http_request_.headers["X-Upload-Content-Length"]);
949 1007
950 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 1008 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
951 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", 1009 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable",
952 http_request_.relative_url); 1010 http_request_.relative_url);
953 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); 1011 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]);
954 EXPECT_TRUE(http_request_.has_content); 1012 EXPECT_TRUE(http_request_.has_content);
955 EXPECT_EQ("{\"parents\":[{" 1013 EXPECT_EQ("{\"parents\":[{"
956 "\"id\":\"parent_resource_id\"," 1014 "\"id\":\"parent_resource_id\","
957 "\"kind\":\"drive#fileLink\"" 1015 "\"kind\":\"drive#fileLink\""
958 "}]," 1016 "}],"
959 "\"title\":\"new file title\"}", 1017 "\"title\":\"new file title\"}",
960 http_request_.content); 1018 http_request_.content);
961 1019
962 // Before sending any data, check the current status. 1020 // Before sending any data, check the current status.
963 // This is an edge case test for GetUploadStatusRequest. 1021 // This is an edge case test for GetUploadStatusRequest.
964 { 1022 {
965 UploadRangeResponse response; 1023 UploadRangeResponse response;
966 scoped_ptr<FileResource> new_entry; 1024 scoped_ptr<FileResource> new_entry;
967 1025
968 // Check the response by GetUploadStatusRequest. 1026 // Check the response by GetUploadStatusRequest.
969 drive::GetUploadStatusRequest* get_upload_status_request = 1027 {
970 new drive::GetUploadStatusRequest( 1028 base::RunLoop run_loop;
971 request_sender_.get(), 1029 drive::GetUploadStatusRequest* get_upload_status_request =
972 request_context_getter_.get(), 1030 new drive::GetUploadStatusRequest(
973 upload_url, 1031 request_sender_.get(),
974 kTestContent.size(), 1032 request_context_getter_.get(),
975 CreateComposedCallback( 1033 upload_url,
976 base::Bind(&test_util::RunAndQuit), 1034 kTestContent.size(),
977 test_util::CreateCopyResultCallback(&response, &new_entry))); 1035 test_util::CreateQuitCallback(
978 request_sender_->StartRequestWithRetry(get_upload_status_request); 1036 &run_loop,
979 base::MessageLoop::current()->Run(); 1037 test_util::CreateCopyResultCallback(&response, &new_entry)));
1038 request_sender_->StartRequestWithRetry(get_upload_status_request);
1039 run_loop.Run();
1040 }
980 1041
981 // METHOD_PUT should be used to upload data. 1042 // METHOD_PUT should be used to upload data.
982 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1043 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
983 // Request should go to the upload URL. 1044 // Request should go to the upload URL.
984 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1045 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
985 // Content-Range header should be added. 1046 // Content-Range header should be added.
986 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), 1047 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()),
987 http_request_.headers["Content-Range"]); 1048 http_request_.headers["Content-Range"]);
988 EXPECT_TRUE(http_request_.has_content); 1049 EXPECT_TRUE(http_request_.has_content);
989 EXPECT_TRUE(http_request_.content.empty()); 1050 EXPECT_TRUE(http_request_.content.empty());
990 1051
991 // Check the response. 1052 // Check the response.
992 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1053 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
993 EXPECT_EQ(0, response.start_position_received); 1054 EXPECT_EQ(0, response.start_position_received);
994 EXPECT_EQ(0, response.end_position_received); 1055 EXPECT_EQ(0, response.end_position_received);
995 } 1056 }
996 1057
997 // Upload the content to the upload URL. 1058 // Upload the content to the upload URL.
998 for (size_t start_position = 0; start_position < kTestContent.size(); 1059 for (size_t start_position = 0; start_position < kTestContent.size();
999 start_position += kNumChunkBytes) { 1060 start_position += kNumChunkBytes) {
1000 const std::string payload = kTestContent.substr( 1061 const std::string payload = kTestContent.substr(
1001 start_position, 1062 start_position,
1002 std::min(kNumChunkBytes, kTestContent.size() - start_position)); 1063 std::min(kNumChunkBytes, kTestContent.size() - start_position));
1003 const size_t end_position = start_position + payload.size(); 1064 const size_t end_position = start_position + payload.size();
1004 1065
1005 UploadRangeResponse response; 1066 UploadRangeResponse response;
1006 scoped_ptr<FileResource> new_entry; 1067 scoped_ptr<FileResource> new_entry;
1007 1068
1008 drive::ResumeUploadRequest* resume_request = 1069 {
1009 new drive::ResumeUploadRequest( 1070 base::RunLoop run_loop;
1010 request_sender_.get(), 1071 drive::ResumeUploadRequest* resume_request =
1011 request_context_getter_.get(), 1072 new drive::ResumeUploadRequest(
1012 upload_url, 1073 request_sender_.get(),
1013 start_position, 1074 request_context_getter_.get(),
1014 end_position, 1075 upload_url,
1015 kTestContent.size(), // content_length, 1076 start_position,
1016 kTestContentType, 1077 end_position,
1017 kTestFilePath, 1078 kTestContent.size(), // content_length,
1018 CreateComposedCallback( 1079 kTestContentType,
1019 base::Bind(&test_util::RunAndQuit), 1080 kTestFilePath,
1020 test_util::CreateCopyResultCallback(&response, &new_entry)), 1081 test_util::CreateQuitCallback(
1021 ProgressCallback()); 1082 &run_loop,
1022 request_sender_->StartRequestWithRetry(resume_request); 1083 test_util::CreateCopyResultCallback(&response, &new_entry)),
1023 base::MessageLoop::current()->Run(); 1084 ProgressCallback());
1085 request_sender_->StartRequestWithRetry(resume_request);
1086 run_loop.Run();
1087 }
1024 1088
1025 // METHOD_PUT should be used to upload data. 1089 // METHOD_PUT should be used to upload data.
1026 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1090 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1027 // Request should go to the upload URL. 1091 // Request should go to the upload URL.
1028 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1092 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1029 // Content-Range header should be added. 1093 // Content-Range header should be added.
1030 EXPECT_EQ("bytes " + 1094 EXPECT_EQ("bytes " +
1031 base::Int64ToString(start_position) + "-" + 1095 base::Int64ToString(start_position) + "-" +
1032 base::Int64ToString(end_position - 1) + "/" + 1096 base::Int64ToString(end_position - 1) + "/" +
1033 base::Int64ToString(kTestContent.size()), 1097 base::Int64ToString(kTestContent.size()),
(...skipping 11 matching lines...) Expand all
1045 EXPECT_EQ(-1, response.end_position_received); 1109 EXPECT_EQ(-1, response.end_position_received);
1046 break; 1110 break;
1047 } 1111 }
1048 1112
1049 // Check the response. 1113 // Check the response.
1050 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1114 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1051 EXPECT_EQ(0, response.start_position_received); 1115 EXPECT_EQ(0, response.start_position_received);
1052 EXPECT_EQ(static_cast<int64>(end_position), response.end_position_received); 1116 EXPECT_EQ(static_cast<int64>(end_position), response.end_position_received);
1053 1117
1054 // Check the response by GetUploadStatusRequest. 1118 // Check the response by GetUploadStatusRequest.
1055 drive::GetUploadStatusRequest* get_upload_status_request = 1119 {
1056 new drive::GetUploadStatusRequest( 1120 base::RunLoop run_loop;
1057 request_sender_.get(), 1121 drive::GetUploadStatusRequest* get_upload_status_request =
1058 request_context_getter_.get(), 1122 new drive::GetUploadStatusRequest(
1059 upload_url, 1123 request_sender_.get(),
1060 kTestContent.size(), 1124 request_context_getter_.get(),
1061 CreateComposedCallback( 1125 upload_url,
1062 base::Bind(&test_util::RunAndQuit), 1126 kTestContent.size(),
1063 test_util::CreateCopyResultCallback(&response, &new_entry))); 1127 test_util::CreateQuitCallback(
1064 request_sender_->StartRequestWithRetry(get_upload_status_request); 1128 &run_loop,
1065 base::MessageLoop::current()->Run(); 1129 test_util::CreateCopyResultCallback(&response, &new_entry)));
1130 request_sender_->StartRequestWithRetry(get_upload_status_request);
1131 run_loop.Run();
1132 }
1066 1133
1067 // METHOD_PUT should be used to upload data. 1134 // METHOD_PUT should be used to upload data.
1068 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1135 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1069 // Request should go to the upload URL. 1136 // Request should go to the upload URL.
1070 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1137 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1071 // Content-Range header should be added. 1138 // Content-Range header should be added.
1072 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()), 1139 EXPECT_EQ("bytes */" + base::Int64ToString(kTestContent.size()),
1073 http_request_.headers["Content-Range"]); 1140 http_request_.headers["Content-Range"]);
1074 EXPECT_TRUE(http_request_.has_content); 1141 EXPECT_TRUE(http_request_.has_content);
1075 EXPECT_TRUE(http_request_.content.empty()); 1142 EXPECT_TRUE(http_request_.content.empty());
(...skipping 13 matching lines...) Expand all
1089 const char kTestContentType[] = "text/plain"; 1156 const char kTestContentType[] = "text/plain";
1090 const std::string kTestContent(100, 'a'); 1157 const std::string kTestContent(100, 'a');
1091 const base::FilePath kTestFilePath = 1158 const base::FilePath kTestFilePath =
1092 temp_dir_.path().AppendASCII("upload_file.txt"); 1159 temp_dir_.path().AppendASCII("upload_file.txt");
1093 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); 1160 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent));
1094 1161
1095 GDataErrorCode error = GDATA_OTHER_ERROR; 1162 GDataErrorCode error = GDATA_OTHER_ERROR;
1096 GURL upload_url; 1163 GURL upload_url;
1097 1164
1098 // Initiate uploading a new file to the directory with "parent_resource_id". 1165 // Initiate uploading a new file to the directory with "parent_resource_id".
1099 drive::InitiateUploadExistingFileRequest* request = 1166 {
1100 new drive::InitiateUploadExistingFileRequest( 1167 base::RunLoop run_loop;
1101 request_sender_.get(), 1168 drive::InitiateUploadExistingFileRequest* request =
1102 request_context_getter_.get(), 1169 new drive::InitiateUploadExistingFileRequest(
1103 *url_generator_, 1170 request_sender_.get(),
1104 kTestContentType, 1171 request_context_getter_.get(),
1105 kTestContent.size(), 1172 *url_generator_,
1106 "resource_id", // The resource id of the file to be overwritten. 1173 kTestContentType,
1107 std::string(), // No etag. 1174 kTestContent.size(),
1108 CreateComposedCallback( 1175 "resource_id", // The resource id of the file to be overwritten.
1109 base::Bind(&test_util::RunAndQuit), 1176 std::string(), // No etag.
1110 test_util::CreateCopyResultCallback(&error, &upload_url))); 1177 test_util::CreateQuitCallback(
1111 request_sender_->StartRequestWithRetry(request); 1178 &run_loop,
1112 base::MessageLoop::current()->Run(); 1179 test_util::CreateCopyResultCallback(&error, &upload_url)));
1180 request_sender_->StartRequestWithRetry(request);
1181 run_loop.Run();
1182 }
1113 1183
1114 EXPECT_EQ(HTTP_SUCCESS, error); 1184 EXPECT_EQ(HTTP_SUCCESS, error);
1115 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); 1185 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path());
1116 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 1186 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1117 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 1187 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1118 http_request_.headers["X-Upload-Content-Length"]); 1188 http_request_.headers["X-Upload-Content-Length"]);
1119 EXPECT_EQ("*", http_request_.headers["If-Match"]); 1189 EXPECT_EQ("*", http_request_.headers["If-Match"]);
1120 1190
1121 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1191 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1122 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", 1192 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
1123 http_request_.relative_url); 1193 http_request_.relative_url);
1124 EXPECT_TRUE(http_request_.has_content); 1194 EXPECT_TRUE(http_request_.has_content);
1125 EXPECT_TRUE(http_request_.content.empty()); 1195 EXPECT_TRUE(http_request_.content.empty());
1126 1196
1127 // Upload the content to the upload URL. 1197 // Upload the content to the upload URL.
1128 UploadRangeResponse response; 1198 UploadRangeResponse response;
1129 scoped_ptr<FileResource> new_entry; 1199 scoped_ptr<FileResource> new_entry;
1130 1200
1131 drive::ResumeUploadRequest* resume_request = 1201 {
1132 new drive::ResumeUploadRequest( 1202 base::RunLoop run_loop;
1133 request_sender_.get(), 1203 drive::ResumeUploadRequest* resume_request =
1134 request_context_getter_.get(), 1204 new drive::ResumeUploadRequest(
1135 upload_url, 1205 request_sender_.get(),
1136 0, // start_position 1206 request_context_getter_.get(),
1137 kTestContent.size(), // end_position (exclusive) 1207 upload_url,
1138 kTestContent.size(), // content_length, 1208 0, // start_position
1139 kTestContentType, 1209 kTestContent.size(), // end_position (exclusive)
1140 kTestFilePath, 1210 kTestContent.size(), // content_length,
1141 CreateComposedCallback( 1211 kTestContentType,
1142 base::Bind(&test_util::RunAndQuit), 1212 kTestFilePath,
1143 test_util::CreateCopyResultCallback(&response, &new_entry)), 1213 test_util::CreateQuitCallback(
1144 ProgressCallback()); 1214 &run_loop,
1145 request_sender_->StartRequestWithRetry(resume_request); 1215 test_util::CreateCopyResultCallback(&response, &new_entry)),
1146 base::MessageLoop::current()->Run(); 1216 ProgressCallback());
1217 request_sender_->StartRequestWithRetry(resume_request);
1218 run_loop.Run();
1219 }
1147 1220
1148 // METHOD_PUT should be used to upload data. 1221 // METHOD_PUT should be used to upload data.
1149 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1222 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1150 // Request should go to the upload URL. 1223 // Request should go to the upload URL.
1151 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1224 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1152 // Content-Range header should be added. 1225 // Content-Range header should be added.
1153 EXPECT_EQ("bytes 0-" + 1226 EXPECT_EQ("bytes 0-" +
1154 base::Int64ToString(kTestContent.size() - 1) + "/" + 1227 base::Int64ToString(kTestContent.size() - 1) + "/" +
1155 base::Int64ToString(kTestContent.size()), 1228 base::Int64ToString(kTestContent.size()),
1156 http_request_.headers["Content-Range"]); 1229 http_request_.headers["Content-Range"]);
(...skipping 15 matching lines...) Expand all
1172 const char kTestContentType[] = "text/plain"; 1245 const char kTestContentType[] = "text/plain";
1173 const std::string kTestContent(100, 'a'); 1246 const std::string kTestContent(100, 'a');
1174 const base::FilePath kTestFilePath = 1247 const base::FilePath kTestFilePath =
1175 temp_dir_.path().AppendASCII("upload_file.txt"); 1248 temp_dir_.path().AppendASCII("upload_file.txt");
1176 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent)); 1249 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kTestContent));
1177 1250
1178 GDataErrorCode error = GDATA_OTHER_ERROR; 1251 GDataErrorCode error = GDATA_OTHER_ERROR;
1179 GURL upload_url; 1252 GURL upload_url;
1180 1253
1181 // Initiate uploading a new file to the directory with "parent_resource_id". 1254 // Initiate uploading a new file to the directory with "parent_resource_id".
1182 drive::InitiateUploadExistingFileRequest* request = 1255 {
1183 new drive::InitiateUploadExistingFileRequest( 1256 base::RunLoop run_loop;
1184 request_sender_.get(), 1257 drive::InitiateUploadExistingFileRequest* request =
1185 request_context_getter_.get(), 1258 new drive::InitiateUploadExistingFileRequest(
1186 *url_generator_, 1259 request_sender_.get(),
1187 kTestContentType, 1260 request_context_getter_.get(),
1188 kTestContent.size(), 1261 *url_generator_,
1189 "resource_id", // The resource id of the file to be overwritten. 1262 kTestContentType,
1190 kTestETag, 1263 kTestContent.size(),
1191 CreateComposedCallback( 1264 "resource_id", // The resource id of the file to be overwritten.
1192 base::Bind(&test_util::RunAndQuit), 1265 kTestETag,
1193 test_util::CreateCopyResultCallback(&error, &upload_url))); 1266 test_util::CreateQuitCallback(
1194 request_sender_->StartRequestWithRetry(request); 1267 &run_loop,
1195 base::MessageLoop::current()->Run(); 1268 test_util::CreateCopyResultCallback(&error, &upload_url)));
1269 request_sender_->StartRequestWithRetry(request);
1270 run_loop.Run();
1271 }
1196 1272
1197 EXPECT_EQ(HTTP_SUCCESS, error); 1273 EXPECT_EQ(HTTP_SUCCESS, error);
1198 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); 1274 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path());
1199 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 1275 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1200 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 1276 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1201 http_request_.headers["X-Upload-Content-Length"]); 1277 http_request_.headers["X-Upload-Content-Length"]);
1202 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]); 1278 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]);
1203 1279
1204 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1280 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1205 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", 1281 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
1206 http_request_.relative_url); 1282 http_request_.relative_url);
1207 EXPECT_TRUE(http_request_.has_content); 1283 EXPECT_TRUE(http_request_.has_content);
1208 EXPECT_TRUE(http_request_.content.empty()); 1284 EXPECT_TRUE(http_request_.content.empty());
1209 1285
1210 // Upload the content to the upload URL. 1286 // Upload the content to the upload URL.
1211 UploadRangeResponse response; 1287 UploadRangeResponse response;
1212 scoped_ptr<FileResource> new_entry; 1288 scoped_ptr<FileResource> new_entry;
1213 1289
1214 drive::ResumeUploadRequest* resume_request = 1290 {
1215 new drive::ResumeUploadRequest( 1291 base::RunLoop run_loop;
1216 request_sender_.get(), 1292 drive::ResumeUploadRequest* resume_request =
1217 request_context_getter_.get(), 1293 new drive::ResumeUploadRequest(
1218 upload_url, 1294 request_sender_.get(),
1219 0, // start_position 1295 request_context_getter_.get(),
1220 kTestContent.size(), // end_position (exclusive) 1296 upload_url,
1221 kTestContent.size(), // content_length, 1297 0, // start_position
1222 kTestContentType, 1298 kTestContent.size(), // end_position (exclusive)
1223 kTestFilePath, 1299 kTestContent.size(), // content_length,
1224 CreateComposedCallback( 1300 kTestContentType,
1225 base::Bind(&test_util::RunAndQuit), 1301 kTestFilePath,
1226 test_util::CreateCopyResultCallback(&response, &new_entry)), 1302 test_util::CreateQuitCallback(
1227 ProgressCallback()); 1303 &run_loop,
1228 request_sender_->StartRequestWithRetry(resume_request); 1304 test_util::CreateCopyResultCallback(&response, &new_entry)),
1229 base::MessageLoop::current()->Run(); 1305 ProgressCallback());
1306 request_sender_->StartRequestWithRetry(resume_request);
1307 run_loop.Run();
1308 }
1230 1309
1231 // METHOD_PUT should be used to upload data. 1310 // METHOD_PUT should be used to upload data.
1232 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1311 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1233 // Request should go to the upload URL. 1312 // Request should go to the upload URL.
1234 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1313 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1235 // Content-Range header should be added. 1314 // Content-Range header should be added.
1236 EXPECT_EQ("bytes 0-" + 1315 EXPECT_EQ("bytes 0-" +
1237 base::Int64ToString(kTestContent.size() - 1) + "/" + 1316 base::Int64ToString(kTestContent.size() - 1) + "/" +
1238 base::Int64ToString(kTestContent.size()), 1317 base::Int64ToString(kTestContent.size()),
1239 http_request_.headers["Content-Range"]); 1318 http_request_.headers["Content-Range"]);
(...skipping 12 matching lines...) Expand all
1252 // Set an expected url for uploading. 1331 // Set an expected url for uploading.
1253 expected_upload_path_ = kTestUploadExistingFilePath; 1332 expected_upload_path_ = kTestUploadExistingFilePath;
1254 1333
1255 const char kTestContentType[] = "text/plain"; 1334 const char kTestContentType[] = "text/plain";
1256 const std::string kTestContent(100, 'a'); 1335 const std::string kTestContent(100, 'a');
1257 1336
1258 GDataErrorCode error = GDATA_OTHER_ERROR; 1337 GDataErrorCode error = GDATA_OTHER_ERROR;
1259 GURL upload_url; 1338 GURL upload_url;
1260 1339
1261 // Initiate uploading a new file to the directory with "parent_resource_id". 1340 // Initiate uploading a new file to the directory with "parent_resource_id".
1262 drive::InitiateUploadExistingFileRequest* request = 1341 {
1263 new drive::InitiateUploadExistingFileRequest( 1342 base::RunLoop run_loop;
1264 request_sender_.get(), 1343 drive::InitiateUploadExistingFileRequest* request =
1265 request_context_getter_.get(), 1344 new drive::InitiateUploadExistingFileRequest(
1266 *url_generator_, 1345 request_sender_.get(),
1267 kTestContentType, 1346 request_context_getter_.get(),
1268 kTestContent.size(), 1347 *url_generator_,
1269 "resource_id", // The resource id of the file to be overwritten. 1348 kTestContentType,
1270 "Conflicting-etag", 1349 kTestContent.size(),
1271 CreateComposedCallback( 1350 "resource_id", // The resource id of the file to be overwritten.
1272 base::Bind(&test_util::RunAndQuit), 1351 "Conflicting-etag",
1273 test_util::CreateCopyResultCallback(&error, &upload_url))); 1352 test_util::CreateQuitCallback(
1274 request_sender_->StartRequestWithRetry(request); 1353 &run_loop,
1275 base::MessageLoop::current()->Run(); 1354 test_util::CreateCopyResultCallback(&error, &upload_url)));
1355 request_sender_->StartRequestWithRetry(request);
1356 run_loop.Run();
1357 }
1276 1358
1277 EXPECT_EQ(HTTP_PRECONDITION, error); 1359 EXPECT_EQ(HTTP_PRECONDITION, error);
1278 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); 1360 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]);
1279 EXPECT_EQ(base::Int64ToString(kTestContent.size()), 1361 EXPECT_EQ(base::Int64ToString(kTestContent.size()),
1280 http_request_.headers["X-Upload-Content-Length"]); 1362 http_request_.headers["X-Upload-Content-Length"]);
1281 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]); 1363 EXPECT_EQ("Conflicting-etag", http_request_.headers["If-Match"]);
1282 1364
1283 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1365 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1284 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", 1366 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable",
1285 http_request_.relative_url); 1367 http_request_.relative_url);
1286 EXPECT_TRUE(http_request_.has_content); 1368 EXPECT_TRUE(http_request_.has_content);
1287 EXPECT_TRUE(http_request_.content.empty()); 1369 EXPECT_TRUE(http_request_.content.empty());
1288 } 1370 }
1289 1371
1290 } // namespace google_apis 1372 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698