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

Side by Side Diff: chrome/browser/google_apis/gdata_wapi_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: Remove unneeded #include 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <map> 6 #include <map>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/message_loop/message_loop_proxy.h" 13 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/google_apis/auth_service.h" 17 #include "chrome/browser/google_apis/auth_service.h"
18 #include "chrome/browser/google_apis/gdata_wapi_parser.h" 18 #include "chrome/browser/google_apis/gdata_wapi_parser.h"
19 #include "chrome/browser/google_apis/gdata_wapi_requests.h" 19 #include "chrome/browser/google_apis/gdata_wapi_requests.h"
20 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h" 20 #include "chrome/browser/google_apis/gdata_wapi_url_generator.h"
21 #include "chrome/browser/google_apis/request_sender.h" 21 #include "chrome/browser/google_apis/request_sender.h"
22 #include "chrome/browser/google_apis/task_util.h"
23 #include "chrome/browser/google_apis/test_util.h" 22 #include "chrome/browser/google_apis/test_util.h"
24 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
25 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
26 #include "content/public/test/test_browser_thread_bundle.h" 25 #include "content/public/test/test_browser_thread_bundle.h"
27 #include "net/base/escape.h" 26 #include "net/base/escape.h"
28 #include "net/test/embedded_test_server/embedded_test_server.h" 27 #include "net/test/embedded_test_server/embedded_test_server.h"
29 #include "net/test/embedded_test_server/http_request.h" 28 #include "net/test/embedded_test_server/http_request.h"
30 #include "net/test/embedded_test_server/http_response.h" 29 #include "net/test/embedded_test_server/http_response.h"
31 #include "net/url_request/url_request_test_util.h" 30 #include "net/url_request/url_request_test_util.h"
32 #include "testing/gtest/include/gtest/gtest.h" 31 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 // instead of GET). 332 // instead of GET).
334 net::test_server::HttpRequest http_request_; 333 net::test_server::HttpRequest http_request_;
335 }; 334 };
336 335
337 } // namespace 336 } // namespace
338 337
339 TEST_F(GDataWapiRequestsTest, GetResourceListRequest_DefaultFeed) { 338 TEST_F(GDataWapiRequestsTest, GetResourceListRequest_DefaultFeed) {
340 GDataErrorCode result_code = GDATA_OTHER_ERROR; 339 GDataErrorCode result_code = GDATA_OTHER_ERROR;
341 scoped_ptr<ResourceList> result_data; 340 scoped_ptr<ResourceList> result_data;
342 341
343 GetResourceListRequest* request = new GetResourceListRequest( 342 {
344 request_sender_.get(), 343 base::RunLoop run_loop;
345 request_context_getter_.get(), 344 GetResourceListRequest* request = new GetResourceListRequest(
346 *url_generator_, 345 request_sender_.get(),
347 GURL(), // Pass an empty URL to use the default feed 346 request_context_getter_.get(),
348 0, // start changestamp 347 *url_generator_,
349 std::string(), // search string 348 GURL(), // Pass an empty URL to use the default feed
350 std::string(), // directory resource ID 349 0, // start changestamp
351 CreateComposedCallback( 350 std::string(), // search string
352 base::Bind(&test_util::RunAndQuit), 351 std::string(), // directory resource ID
353 test_util::CreateCopyResultCallback(&result_code, &result_data))); 352 test_util::CreateQuitCallback(
354 request_sender_->StartRequestWithRetry(request); 353 &run_loop,
355 base::MessageLoop::current()->Run(); 354 test_util::CreateCopyResultCallback(&result_code, &result_data)));
355 request_sender_->StartRequestWithRetry(request);
356 run_loop.Run();
357 }
356 358
357 EXPECT_EQ(HTTP_SUCCESS, result_code); 359 EXPECT_EQ(HTTP_SUCCESS, result_code);
358 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 360 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
359 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&" 361 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&"
360 "showfolders=true&include-shared=true&max-results=500", 362 "showfolders=true&include-shared=true&max-results=500",
361 http_request_.relative_url); 363 http_request_.relative_url);
362 364
363 // Sanity check of the result. 365 // Sanity check of the result.
364 scoped_ptr<ResourceList> expected( 366 scoped_ptr<ResourceList> expected(
365 ResourceList::ExtractAndParse( 367 ResourceList::ExtractAndParse(
366 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json"))); 368 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json")));
367 ASSERT_TRUE(result_data); 369 ASSERT_TRUE(result_data);
368 EXPECT_EQ(expected->title(), result_data->title()); 370 EXPECT_EQ(expected->title(), result_data->title());
369 } 371 }
370 372
371 TEST_F(GDataWapiRequestsTest, GetResourceListRequest_ValidFeed) { 373 TEST_F(GDataWapiRequestsTest, GetResourceListRequest_ValidFeed) {
372 GDataErrorCode result_code = GDATA_OTHER_ERROR; 374 GDataErrorCode result_code = GDATA_OTHER_ERROR;
373 scoped_ptr<ResourceList> result_data; 375 scoped_ptr<ResourceList> result_data;
374 376
375 GetResourceListRequest* request = new GetResourceListRequest( 377 {
376 request_sender_.get(), 378 base::RunLoop run_loop;
377 request_context_getter_.get(), 379 GetResourceListRequest* request = new GetResourceListRequest(
378 *url_generator_, 380 request_sender_.get(),
379 test_server_.GetURL("/files/chromeos/gdata/root_feed.json"), 381 request_context_getter_.get(),
380 0, // start changestamp 382 *url_generator_,
381 std::string(), // search string 383 test_server_.GetURL("/files/chromeos/gdata/root_feed.json"),
382 std::string(), // directory resource ID 384 0, // start changestamp
383 CreateComposedCallback( 385 std::string(), // search string
384 base::Bind(&test_util::RunAndQuit), 386 std::string(), // directory resource ID
385 test_util::CreateCopyResultCallback(&result_code, &result_data))); 387 test_util::CreateQuitCallback(
386 request_sender_->StartRequestWithRetry(request); 388 &run_loop,
387 base::MessageLoop::current()->Run(); 389 test_util::CreateCopyResultCallback(&result_code, &result_data)));
390 request_sender_->StartRequestWithRetry(request);
391 run_loop.Run();
392 }
388 393
389 EXPECT_EQ(HTTP_SUCCESS, result_code); 394 EXPECT_EQ(HTTP_SUCCESS, result_code);
390 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 395 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
391 EXPECT_EQ("/files/chromeos/gdata/root_feed.json?v=3&alt=json&showroot=true&" 396 EXPECT_EQ("/files/chromeos/gdata/root_feed.json?v=3&alt=json&showroot=true&"
392 "showfolders=true&include-shared=true&max-results=500", 397 "showfolders=true&include-shared=true&max-results=500",
393 http_request_.relative_url); 398 http_request_.relative_url);
394 399
395 scoped_ptr<ResourceList> expected( 400 scoped_ptr<ResourceList> expected(
396 ResourceList::ExtractAndParse( 401 ResourceList::ExtractAndParse(
397 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json"))); 402 *test_util::LoadJSONFile("chromeos/gdata/root_feed.json")));
398 ASSERT_TRUE(result_data); 403 ASSERT_TRUE(result_data);
399 EXPECT_EQ(expected->title(), result_data->title()); 404 EXPECT_EQ(expected->title(), result_data->title());
400 } 405 }
401 406
402 TEST_F(GDataWapiRequestsTest, GetResourceListRequest_InvalidFeed) { 407 TEST_F(GDataWapiRequestsTest, GetResourceListRequest_InvalidFeed) {
403 // testfile.txt exists but the response is not JSON, so it should 408 // testfile.txt exists but the response is not JSON, so it should
404 // emit a parse error instead. 409 // emit a parse error instead.
405 GDataErrorCode result_code = GDATA_OTHER_ERROR; 410 GDataErrorCode result_code = GDATA_OTHER_ERROR;
406 scoped_ptr<ResourceList> result_data; 411 scoped_ptr<ResourceList> result_data;
407 412
408 GetResourceListRequest* request = new GetResourceListRequest( 413 {
409 request_sender_.get(), 414 base::RunLoop run_loop;
410 request_context_getter_.get(), 415 GetResourceListRequest* request = new GetResourceListRequest(
411 *url_generator_, 416 request_sender_.get(),
412 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"), 417 request_context_getter_.get(),
413 0, // start changestamp 418 *url_generator_,
414 std::string(), // search string 419 test_server_.GetURL("/files/chromeos/gdata/testfile.txt"),
415 std::string(), // directory resource ID 420 0, // start changestamp
416 CreateComposedCallback( 421 std::string(), // search string
417 base::Bind(&test_util::RunAndQuit), 422 std::string(), // directory resource ID
418 test_util::CreateCopyResultCallback(&result_code, &result_data))); 423 test_util::CreateQuitCallback(
419 request_sender_->StartRequestWithRetry(request); 424 &run_loop,
420 base::MessageLoop::current()->Run(); 425 test_util::CreateCopyResultCallback(&result_code, &result_data)));
426 request_sender_->StartRequestWithRetry(request);
427 run_loop.Run();
428 }
421 429
422 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); 430 EXPECT_EQ(GDATA_PARSE_ERROR, result_code);
423 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 431 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
424 EXPECT_EQ("/files/chromeos/gdata/testfile.txt?v=3&alt=json&showroot=true&" 432 EXPECT_EQ("/files/chromeos/gdata/testfile.txt?v=3&alt=json&showroot=true&"
425 "showfolders=true&include-shared=true&max-results=500", 433 "showfolders=true&include-shared=true&max-results=500",
426 http_request_.relative_url); 434 http_request_.relative_url);
427 EXPECT_FALSE(result_data); 435 EXPECT_FALSE(result_data);
428 } 436 }
429 437
430 TEST_F(GDataWapiRequestsTest, SearchByTitleRequest) { 438 TEST_F(GDataWapiRequestsTest, SearchByTitleRequest) {
431 GDataErrorCode result_code = GDATA_OTHER_ERROR; 439 GDataErrorCode result_code = GDATA_OTHER_ERROR;
432 scoped_ptr<ResourceList> result_data; 440 scoped_ptr<ResourceList> result_data;
433 441
434 SearchByTitleRequest* request = new SearchByTitleRequest( 442 {
435 request_sender_.get(), 443 base::RunLoop run_loop;
436 request_context_getter_.get(), 444 SearchByTitleRequest* request = new SearchByTitleRequest(
437 *url_generator_, 445 request_sender_.get(),
438 "search-title", 446 request_context_getter_.get(),
439 std::string(), // directory resource id 447 *url_generator_,
440 CreateComposedCallback( 448 "search-title",
441 base::Bind(&test_util::RunAndQuit), 449 std::string(), // directory resource id
442 test_util::CreateCopyResultCallback(&result_code, &result_data))); 450 test_util::CreateQuitCallback(
443 request_sender_->StartRequestWithRetry(request); 451 &run_loop,
444 base::MessageLoop::current()->Run(); 452 test_util::CreateCopyResultCallback(&result_code, &result_data)));
453 request_sender_->StartRequestWithRetry(request);
454 run_loop.Run();
455 }
445 456
446 EXPECT_EQ(HTTP_SUCCESS, result_code); 457 EXPECT_EQ(HTTP_SUCCESS, result_code);
447 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 458 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
448 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&" 459 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&"
449 "showfolders=true&include-shared=true&max-results=500" 460 "showfolders=true&include-shared=true&max-results=500"
450 "&title=search-title&title-exact=true", 461 "&title=search-title&title-exact=true",
451 http_request_.relative_url); 462 http_request_.relative_url);
452 EXPECT_TRUE(result_data); 463 EXPECT_TRUE(result_data);
453 } 464 }
454 465
455 TEST_F(GDataWapiRequestsTest, GetResourceEntryRequest_ValidResourceId) { 466 TEST_F(GDataWapiRequestsTest, GetResourceEntryRequest_ValidResourceId) {
456 GDataErrorCode result_code = GDATA_OTHER_ERROR; 467 GDataErrorCode result_code = GDATA_OTHER_ERROR;
457 scoped_ptr<base::Value> result_data; 468 scoped_ptr<base::Value> result_data;
458 469
459 GetResourceEntryRequest* request = new GetResourceEntryRequest( 470 {
460 request_sender_.get(), 471 base::RunLoop run_loop;
461 request_context_getter_.get(), 472 GetResourceEntryRequest* request = new GetResourceEntryRequest(
462 *url_generator_, 473 request_sender_.get(),
463 "file:2_file_resource_id", // resource ID 474 request_context_getter_.get(),
464 CreateComposedCallback( 475 *url_generator_,
465 base::Bind(&test_util::RunAndQuit), 476 "file:2_file_resource_id", // resource ID
466 test_util::CreateCopyResultCallback(&result_code, &result_data))); 477 test_util::CreateQuitCallback(
467 request_sender_->StartRequestWithRetry(request); 478 &run_loop,
468 base::MessageLoop::current()->Run(); 479 test_util::CreateCopyResultCallback(&result_code, &result_data)));
480 request_sender_->StartRequestWithRetry(request);
481 run_loop.Run();
482 }
469 483
470 EXPECT_EQ(HTTP_SUCCESS, result_code); 484 EXPECT_EQ(HTTP_SUCCESS, result_code);
471 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 485 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
472 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" 486 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id"
473 "?v=3&alt=json&showroot=true", 487 "?v=3&alt=json&showroot=true",
474 http_request_.relative_url); 488 http_request_.relative_url);
475 EXPECT_TRUE(test_util::VerifyJsonData( 489 EXPECT_TRUE(test_util::VerifyJsonData(
476 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"), 490 test_util::GetTestFilePath("chromeos/gdata/file_entry.json"),
477 result_data.get())); 491 result_data.get()));
478 } 492 }
479 493
480 TEST_F(GDataWapiRequestsTest, GetResourceEntryRequest_InvalidResourceId) { 494 TEST_F(GDataWapiRequestsTest, GetResourceEntryRequest_InvalidResourceId) {
481 GDataErrorCode result_code = GDATA_OTHER_ERROR; 495 GDataErrorCode result_code = GDATA_OTHER_ERROR;
482 scoped_ptr<base::Value> result_data; 496 scoped_ptr<base::Value> result_data;
483 497
484 GetResourceEntryRequest* request = new GetResourceEntryRequest( 498 {
485 request_sender_.get(), 499 base::RunLoop run_loop;
486 request_context_getter_.get(), 500 GetResourceEntryRequest* request = new GetResourceEntryRequest(
487 *url_generator_, 501 request_sender_.get(),
488 "<invalid>", // resource ID 502 request_context_getter_.get(),
489 CreateComposedCallback( 503 *url_generator_,
490 base::Bind(&test_util::RunAndQuit), 504 "<invalid>", // resource ID
491 test_util::CreateCopyResultCallback(&result_code, &result_data))); 505 test_util::CreateQuitCallback(
492 request_sender_->StartRequestWithRetry(request); 506 &run_loop,
493 base::MessageLoop::current()->Run(); 507 test_util::CreateCopyResultCallback(&result_code, &result_data)));
508 request_sender_->StartRequestWithRetry(request);
509 run_loop.Run();
510 }
494 511
495 EXPECT_EQ(HTTP_NOT_FOUND, result_code); 512 EXPECT_EQ(HTTP_NOT_FOUND, result_code);
496 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 513 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
497 EXPECT_EQ("/feeds/default/private/full/%3Cinvalid%3E?v=3&alt=json" 514 EXPECT_EQ("/feeds/default/private/full/%3Cinvalid%3E?v=3&alt=json"
498 "&showroot=true", 515 "&showroot=true",
499 http_request_.relative_url); 516 http_request_.relative_url);
500 ASSERT_FALSE(result_data); 517 ASSERT_FALSE(result_data);
501 } 518 }
502 519
503 TEST_F(GDataWapiRequestsTest, GetAccountMetadataRequest) { 520 TEST_F(GDataWapiRequestsTest, GetAccountMetadataRequest) {
504 GDataErrorCode result_code = GDATA_OTHER_ERROR; 521 GDataErrorCode result_code = GDATA_OTHER_ERROR;
505 scoped_ptr<AccountMetadata> result_data; 522 scoped_ptr<AccountMetadata> result_data;
506 523
507 GetAccountMetadataRequest* request = new GetAccountMetadataRequest( 524 {
508 request_sender_.get(), 525 base::RunLoop run_loop;
509 request_context_getter_.get(), 526 GetAccountMetadataRequest* request = new GetAccountMetadataRequest(
510 *url_generator_, 527 request_sender_.get(),
511 CreateComposedCallback( 528 request_context_getter_.get(),
512 base::Bind(&test_util::RunAndQuit), 529 *url_generator_,
513 test_util::CreateCopyResultCallback(&result_code, &result_data)), 530 test_util::CreateQuitCallback(
514 true); // Include installed apps. 531 &run_loop,
515 request_sender_->StartRequestWithRetry(request); 532 test_util::CreateCopyResultCallback(&result_code, &result_data)),
516 base::MessageLoop::current()->Run(); 533 true); // Include installed apps.
534 request_sender_->StartRequestWithRetry(request);
535 run_loop.Run();
536 }
517 537
518 EXPECT_EQ(HTTP_SUCCESS, result_code); 538 EXPECT_EQ(HTTP_SUCCESS, result_code);
519 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 539 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
520 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true" 540 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true"
521 "&include-installed-apps=true", 541 "&include-installed-apps=true",
522 http_request_.relative_url); 542 http_request_.relative_url);
523 543
524 scoped_ptr<AccountMetadata> expected( 544 scoped_ptr<AccountMetadata> expected(
525 AccountMetadata::CreateFrom( 545 AccountMetadata::CreateFrom(
526 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json"))); 546 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json")));
527 547
528 ASSERT_TRUE(result_data.get()); 548 ASSERT_TRUE(result_data.get());
529 EXPECT_EQ(expected->largest_changestamp(), 549 EXPECT_EQ(expected->largest_changestamp(),
530 result_data->largest_changestamp()); 550 result_data->largest_changestamp());
531 EXPECT_EQ(expected->quota_bytes_total(), 551 EXPECT_EQ(expected->quota_bytes_total(),
532 result_data->quota_bytes_total()); 552 result_data->quota_bytes_total());
533 EXPECT_EQ(expected->quota_bytes_used(), 553 EXPECT_EQ(expected->quota_bytes_used(),
534 result_data->quota_bytes_used()); 554 result_data->quota_bytes_used());
535 555
536 // Sanity check for installed apps. 556 // Sanity check for installed apps.
537 EXPECT_EQ(expected->installed_apps().size(), 557 EXPECT_EQ(expected->installed_apps().size(),
538 result_data->installed_apps().size()); 558 result_data->installed_apps().size());
539 } 559 }
540 560
541 TEST_F(GDataWapiRequestsTest, 561 TEST_F(GDataWapiRequestsTest,
542 GetAccountMetadataRequestWithoutInstalledApps) { 562 GetAccountMetadataRequestWithoutInstalledApps) {
543 GDataErrorCode result_code = GDATA_OTHER_ERROR; 563 GDataErrorCode result_code = GDATA_OTHER_ERROR;
544 scoped_ptr<AccountMetadata> result_data; 564 scoped_ptr<AccountMetadata> result_data;
545 565
546 GetAccountMetadataRequest* request = new GetAccountMetadataRequest( 566 {
547 request_sender_.get(), 567 base::RunLoop run_loop;
548 request_context_getter_.get(), 568 GetAccountMetadataRequest* request = new GetAccountMetadataRequest(
549 *url_generator_, 569 request_sender_.get(),
550 CreateComposedCallback( 570 request_context_getter_.get(),
551 base::Bind(&test_util::RunAndQuit), 571 *url_generator_,
552 test_util::CreateCopyResultCallback(&result_code, &result_data)), 572 test_util::CreateQuitCallback(
553 false); // Exclude installed apps. 573 &run_loop,
554 request_sender_->StartRequestWithRetry(request); 574 test_util::CreateCopyResultCallback(&result_code, &result_data)),
555 base::MessageLoop::current()->Run(); 575 false); // Exclude installed apps.
576 request_sender_->StartRequestWithRetry(request);
577 run_loop.Run();
578 }
556 579
557 EXPECT_EQ(HTTP_SUCCESS, result_code); 580 EXPECT_EQ(HTTP_SUCCESS, result_code);
558 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); 581 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method);
559 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true", 582 EXPECT_EQ("/feeds/metadata/default?v=3&alt=json&showroot=true",
560 http_request_.relative_url); 583 http_request_.relative_url);
561 584
562 scoped_ptr<AccountMetadata> expected( 585 scoped_ptr<AccountMetadata> expected(
563 AccountMetadata::CreateFrom( 586 AccountMetadata::CreateFrom(
564 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json"))); 587 *test_util::LoadJSONFile("chromeos/gdata/account_metadata.json")));
565 588
566 ASSERT_TRUE(result_data.get()); 589 ASSERT_TRUE(result_data.get());
567 EXPECT_EQ(expected->largest_changestamp(), 590 EXPECT_EQ(expected->largest_changestamp(),
568 result_data->largest_changestamp()); 591 result_data->largest_changestamp());
569 EXPECT_EQ(expected->quota_bytes_total(), 592 EXPECT_EQ(expected->quota_bytes_total(),
570 result_data->quota_bytes_total()); 593 result_data->quota_bytes_total());
571 EXPECT_EQ(expected->quota_bytes_used(), 594 EXPECT_EQ(expected->quota_bytes_used(),
572 result_data->quota_bytes_used()); 595 result_data->quota_bytes_used());
573 596
574 // Installed apps shouldn't be included. 597 // Installed apps shouldn't be included.
575 EXPECT_EQ(0U, result_data->installed_apps().size()); 598 EXPECT_EQ(0U, result_data->installed_apps().size());
576 } 599 }
577 600
578 TEST_F(GDataWapiRequestsTest, DeleteResourceRequest) { 601 TEST_F(GDataWapiRequestsTest, DeleteResourceRequest) {
579 GDataErrorCode result_code = GDATA_OTHER_ERROR; 602 GDataErrorCode result_code = GDATA_OTHER_ERROR;
580 603
581 DeleteResourceRequest* request = new DeleteResourceRequest( 604 {
582 request_sender_.get(), 605 base::RunLoop run_loop;
583 request_context_getter_.get(), 606 DeleteResourceRequest* request = new DeleteResourceRequest(
584 *url_generator_, 607 request_sender_.get(),
585 CreateComposedCallback(base::Bind(&test_util::RunAndQuit), 608 request_context_getter_.get(),
586 test_util::CreateCopyResultCallback(&result_code)), 609 *url_generator_,
587 "file:2_file_resource_id", 610 test_util::CreateQuitCallback(
588 std::string()); 611 &run_loop,
612 test_util::CreateCopyResultCallback(&result_code)),
613 "file:2_file_resource_id",
614 std::string());
589 615
590 request_sender_->StartRequestWithRetry(request); 616 request_sender_->StartRequestWithRetry(request);
591 base::MessageLoop::current()->Run(); 617 run_loop.Run();
618 }
592 619
593 EXPECT_EQ(HTTP_SUCCESS, result_code); 620 EXPECT_EQ(HTTP_SUCCESS, result_code);
594 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); 621 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
595 EXPECT_EQ( 622 EXPECT_EQ(
596 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" 623 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json"
597 "&showroot=true", 624 "&showroot=true",
598 http_request_.relative_url); 625 http_request_.relative_url);
599 EXPECT_EQ("*", http_request_.headers["If-Match"]); 626 EXPECT_EQ("*", http_request_.headers["If-Match"]);
600 } 627 }
601 628
602 TEST_F(GDataWapiRequestsTest, DeleteResourceRequestWithETag) { 629 TEST_F(GDataWapiRequestsTest, DeleteResourceRequestWithETag) {
603 GDataErrorCode result_code = GDATA_OTHER_ERROR; 630 GDataErrorCode result_code = GDATA_OTHER_ERROR;
604 631
605 DeleteResourceRequest* request = new DeleteResourceRequest( 632 {
606 request_sender_.get(), 633 base::RunLoop run_loop;
607 request_context_getter_.get(), 634 DeleteResourceRequest* request = new DeleteResourceRequest(
608 *url_generator_, 635 request_sender_.get(),
609 CreateComposedCallback( 636 request_context_getter_.get(),
610 base::Bind(&test_util::RunAndQuit), 637 *url_generator_,
611 test_util::CreateCopyResultCallback(&result_code)), 638 test_util::CreateQuitCallback(
612 "file:2_file_resource_id", 639 &run_loop,
613 "etag"); 640 test_util::CreateCopyResultCallback(&result_code)),
641 "file:2_file_resource_id",
642 "etag");
614 643
615 request_sender_->StartRequestWithRetry(request); 644 request_sender_->StartRequestWithRetry(request);
616 base::MessageLoop::current()->Run(); 645 run_loop.Run();
646 }
617 647
618 EXPECT_EQ(HTTP_SUCCESS, result_code); 648 EXPECT_EQ(HTTP_SUCCESS, result_code);
619 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); 649 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
620 EXPECT_EQ( 650 EXPECT_EQ(
621 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" 651 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json"
622 "&showroot=true", 652 "&showroot=true",
623 http_request_.relative_url); 653 http_request_.relative_url);
624 EXPECT_EQ("etag", http_request_.headers["If-Match"]); 654 EXPECT_EQ("etag", http_request_.headers["If-Match"]);
625 } 655 }
626 656
627 TEST_F(GDataWapiRequestsTest, CreateDirectoryRequest) { 657 TEST_F(GDataWapiRequestsTest, CreateDirectoryRequest) {
628 GDataErrorCode result_code = GDATA_OTHER_ERROR; 658 GDataErrorCode result_code = GDATA_OTHER_ERROR;
629 scoped_ptr<base::Value> result_data; 659 scoped_ptr<base::Value> result_data;
630 660
631 // Create "new directory" in the root directory. 661 // Create "new directory" in the root directory.
632 CreateDirectoryRequest* request = new CreateDirectoryRequest( 662 {
633 request_sender_.get(), 663 base::RunLoop run_loop;
634 request_context_getter_.get(), 664 CreateDirectoryRequest* request = new CreateDirectoryRequest(
635 *url_generator_, 665 request_sender_.get(),
636 CreateComposedCallback( 666 request_context_getter_.get(),
637 base::Bind(&test_util::RunAndQuit), 667 *url_generator_,
638 test_util::CreateCopyResultCallback(&result_code, &result_data)), 668 test_util::CreateQuitCallback(
639 "folder:root", 669 &run_loop,
640 "new directory"); 670 test_util::CreateCopyResultCallback(&result_code, &result_data)),
671 "folder:root",
672 "new directory");
641 673
642 request_sender_->StartRequestWithRetry(request); 674 request_sender_->StartRequestWithRetry(request);
643 base::MessageLoop::current()->Run(); 675 run_loop.Run();
676 }
644 677
645 EXPECT_EQ(HTTP_SUCCESS, result_code); 678 EXPECT_EQ(HTTP_SUCCESS, result_code);
646 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 679 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
647 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json" 680 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json"
648 "&showroot=true", 681 "&showroot=true",
649 http_request_.relative_url); 682 http_request_.relative_url);
650 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 683 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
651 684
652 EXPECT_TRUE(http_request_.has_content); 685 EXPECT_TRUE(http_request_.has_content);
653 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 686 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
654 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" 687 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
655 " <category scheme=\"http://schemas.google.com/g/2005#kind\" " 688 " <category scheme=\"http://schemas.google.com/g/2005#kind\" "
656 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n" 689 "term=\"http://schemas.google.com/docs/2007#folder\"/>\n"
657 " <title>new directory</title>\n" 690 " <title>new directory</title>\n"
658 "</entry>\n", 691 "</entry>\n",
659 http_request_.content); 692 http_request_.content);
660 } 693 }
661 694
662 TEST_F(GDataWapiRequestsTest, CopyHostedDocumentRequest) { 695 TEST_F(GDataWapiRequestsTest, CopyHostedDocumentRequest) {
663 GDataErrorCode result_code = GDATA_OTHER_ERROR; 696 GDataErrorCode result_code = GDATA_OTHER_ERROR;
664 scoped_ptr<base::Value> result_data; 697 scoped_ptr<base::Value> result_data;
665 698
666 // Copy a document with a new name "New Document". 699 // Copy a document with a new name "New Document".
667 CopyHostedDocumentRequest* request = new CopyHostedDocumentRequest( 700 {
668 request_sender_.get(), 701 base::RunLoop run_loop;
669 request_context_getter_.get(), 702 CopyHostedDocumentRequest* request = new CopyHostedDocumentRequest(
670 *url_generator_, 703 request_sender_.get(),
671 CreateComposedCallback( 704 request_context_getter_.get(),
672 base::Bind(&test_util::RunAndQuit), 705 *url_generator_,
673 test_util::CreateCopyResultCallback(&result_code, &result_data)), 706 test_util::CreateQuitCallback(
674 "document:5_document_resource_id", // source resource ID 707 &run_loop,
675 "New Document"); 708 test_util::CreateCopyResultCallback(&result_code, &result_data)),
709 "document:5_document_resource_id", // source resource ID
710 "New Document");
676 711
677 request_sender_->StartRequestWithRetry(request); 712 request_sender_->StartRequestWithRetry(request);
678 base::MessageLoop::current()->Run(); 713 run_loop.Run();
714 }
679 715
680 EXPECT_EQ(HTTP_SUCCESS, result_code); 716 EXPECT_EQ(HTTP_SUCCESS, result_code);
681 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 717 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
682 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true", 718 EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true",
683 http_request_.relative_url); 719 http_request_.relative_url);
684 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 720 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
685 721
686 EXPECT_TRUE(http_request_.has_content); 722 EXPECT_TRUE(http_request_.has_content);
687 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 723 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
688 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" 724 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
689 " <id>document:5_document_resource_id</id>\n" 725 " <id>document:5_document_resource_id</id>\n"
690 " <title>New Document</title>\n" 726 " <title>New Document</title>\n"
691 "</entry>\n", 727 "</entry>\n",
692 http_request_.content); 728 http_request_.content);
693 } 729 }
694 730
695 TEST_F(GDataWapiRequestsTest, RenameResourceRequest) { 731 TEST_F(GDataWapiRequestsTest, RenameResourceRequest) {
696 GDataErrorCode result_code = GDATA_OTHER_ERROR; 732 GDataErrorCode result_code = GDATA_OTHER_ERROR;
697 733
698 // Rename a file with a new name "New File". 734 // Rename a file with a new name "New File".
699 RenameResourceRequest* request = new RenameResourceRequest( 735 {
700 request_sender_.get(), 736 base::RunLoop run_loop;
701 request_context_getter_.get(), 737 RenameResourceRequest* request = new RenameResourceRequest(
702 *url_generator_, 738 request_sender_.get(),
703 CreateComposedCallback( 739 request_context_getter_.get(),
704 base::Bind(&test_util::RunAndQuit), 740 *url_generator_,
705 test_util::CreateCopyResultCallback(&result_code)), 741 test_util::CreateQuitCallback(
706 "file:2_file_resource_id", 742 &run_loop,
707 "New File"); 743 test_util::CreateCopyResultCallback(&result_code)),
744 "file:2_file_resource_id",
745 "New File");
708 746
709 request_sender_->StartRequestWithRetry(request); 747 request_sender_->StartRequestWithRetry(request);
710 base::MessageLoop::current()->Run(); 748 run_loop.Run();
749 }
711 750
712 EXPECT_EQ(HTTP_SUCCESS, result_code); 751 EXPECT_EQ(HTTP_SUCCESS, result_code);
713 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 752 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
714 EXPECT_EQ( 753 EXPECT_EQ(
715 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json" 754 "/feeds/default/private/full/file%3A2_file_resource_id?v=3&alt=json"
716 "&showroot=true", 755 "&showroot=true",
717 http_request_.relative_url); 756 http_request_.relative_url);
718 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 757 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
719 EXPECT_EQ("*", http_request_.headers["If-Match"]); 758 EXPECT_EQ("*", http_request_.headers["If-Match"]);
720 759
721 EXPECT_TRUE(http_request_.has_content); 760 EXPECT_TRUE(http_request_.has_content);
722 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 761 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
723 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" 762 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
724 " <title>New File</title>\n" 763 " <title>New File</title>\n"
725 "</entry>\n", 764 "</entry>\n",
726 http_request_.content); 765 http_request_.content);
727 } 766 }
728 767
729 TEST_F(GDataWapiRequestsTest, AuthorizeAppRequest_ValidFeed) { 768 TEST_F(GDataWapiRequestsTest, AuthorizeAppRequest_ValidFeed) {
730 GDataErrorCode result_code = GDATA_OTHER_ERROR; 769 GDataErrorCode result_code = GDATA_OTHER_ERROR;
731 GURL result_data; 770 GURL result_data;
732 771
733 // Authorize an app with APP_ID to access to a document. 772 // Authorize an app with APP_ID to access to a document.
734 AuthorizeAppRequest* request = new AuthorizeAppRequest( 773 {
735 request_sender_.get(), 774 base::RunLoop run_loop;
736 request_context_getter_.get(), 775 AuthorizeAppRequest* request = new AuthorizeAppRequest(
737 *url_generator_, 776 request_sender_.get(),
738 CreateComposedCallback( 777 request_context_getter_.get(),
739 base::Bind(&test_util::RunAndQuit), 778 *url_generator_,
740 test_util::CreateCopyResultCallback(&result_code, &result_data)), 779 test_util::CreateQuitCallback(
741 "file:2_file_resource_id", 780 &run_loop,
742 "the_app_id"); 781 test_util::CreateCopyResultCallback(&result_code, &result_data)),
782 "file:2_file_resource_id",
783 "the_app_id");
743 784
744 request_sender_->StartRequestWithRetry(request); 785 request_sender_->StartRequestWithRetry(request);
745 base::MessageLoop::current()->Run(); 786 run_loop.Run();
787 }
746 788
747 EXPECT_EQ(HTTP_SUCCESS, result_code); 789 EXPECT_EQ(HTTP_SUCCESS, result_code);
748 EXPECT_EQ(GURL("https://entry1_open_with_link/"), result_data); 790 EXPECT_EQ(GURL("https://entry1_open_with_link/"), result_data);
749 791
750 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 792 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
751 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" 793 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id"
752 "?v=3&alt=json&showroot=true", 794 "?v=3&alt=json&showroot=true",
753 http_request_.relative_url); 795 http_request_.relative_url);
754 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 796 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
755 EXPECT_EQ("*", http_request_.headers["If-Match"]); 797 EXPECT_EQ("*", http_request_.headers["If-Match"]);
756 798
757 EXPECT_TRUE(http_request_.has_content); 799 EXPECT_TRUE(http_request_.has_content);
758 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 800 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
759 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " 801 "<entry xmlns=\"http://www.w3.org/2005/Atom\" "
760 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" 802 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n"
761 " <docs:authorizedApp>the_app_id</docs:authorizedApp>\n" 803 " <docs:authorizedApp>the_app_id</docs:authorizedApp>\n"
762 "</entry>\n", 804 "</entry>\n",
763 http_request_.content); 805 http_request_.content);
764 } 806 }
765 807
766 TEST_F(GDataWapiRequestsTest, AuthorizeAppRequest_NotFound) { 808 TEST_F(GDataWapiRequestsTest, AuthorizeAppRequest_NotFound) {
767 GDataErrorCode result_code = GDATA_OTHER_ERROR; 809 GDataErrorCode result_code = GDATA_OTHER_ERROR;
768 GURL result_data; 810 GURL result_data;
769 811
770 // Authorize an app with APP_ID to access to a document. 812 // Authorize an app with APP_ID to access to a document.
771 AuthorizeAppRequest* request = new AuthorizeAppRequest( 813 {
772 request_sender_.get(), 814 base::RunLoop run_loop;
773 request_context_getter_.get(), 815 AuthorizeAppRequest* request = new AuthorizeAppRequest(
774 *url_generator_, 816 request_sender_.get(),
775 CreateComposedCallback( 817 request_context_getter_.get(),
776 base::Bind(&test_util::RunAndQuit), 818 *url_generator_,
777 test_util::CreateCopyResultCallback(&result_code, &result_data)), 819 test_util::CreateQuitCallback(
778 "file:2_file_resource_id", 820 &run_loop,
779 "unauthorized_app_id"); 821 test_util::CreateCopyResultCallback(&result_code, &result_data)),
822 "file:2_file_resource_id",
823 "unauthorized_app_id");
780 824
781 request_sender_->StartRequestWithRetry(request); 825 request_sender_->StartRequestWithRetry(request);
782 base::MessageLoop::current()->Run(); 826 run_loop.Run();
827 }
783 828
784 EXPECT_EQ(GDATA_OTHER_ERROR, result_code); 829 EXPECT_EQ(GDATA_OTHER_ERROR, result_code);
785 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 830 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
786 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id" 831 EXPECT_EQ("/feeds/default/private/full/file%3A2_file_resource_id"
787 "?v=3&alt=json&showroot=true", 832 "?v=3&alt=json&showroot=true",
788 http_request_.relative_url); 833 http_request_.relative_url);
789 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 834 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
790 EXPECT_EQ("*", http_request_.headers["If-Match"]); 835 EXPECT_EQ("*", http_request_.headers["If-Match"]);
791 836
792 EXPECT_TRUE(http_request_.has_content); 837 EXPECT_TRUE(http_request_.has_content);
793 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 838 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
794 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " 839 "<entry xmlns=\"http://www.w3.org/2005/Atom\" "
795 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" 840 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n"
796 " <docs:authorizedApp>unauthorized_app_id</docs:authorizedApp>\n" 841 " <docs:authorizedApp>unauthorized_app_id</docs:authorizedApp>\n"
797 "</entry>\n", 842 "</entry>\n",
798 http_request_.content); 843 http_request_.content);
799 } 844 }
800 845
801 TEST_F(GDataWapiRequestsTest, AuthorizeAppRequest_InvalidFeed) { 846 TEST_F(GDataWapiRequestsTest, AuthorizeAppRequest_InvalidFeed) {
802 GDataErrorCode result_code = GDATA_OTHER_ERROR; 847 GDataErrorCode result_code = GDATA_OTHER_ERROR;
803 GURL result_data; 848 GURL result_data;
804 849
805 // Authorize an app with APP_ID to access to a document but an invalid feed. 850 // Authorize an app with APP_ID to access to a document but an invalid feed.
806 AuthorizeAppRequest* request = new AuthorizeAppRequest( 851 {
807 request_sender_.get(), 852 base::RunLoop run_loop;
808 request_context_getter_.get(), 853 AuthorizeAppRequest* request = new AuthorizeAppRequest(
809 *url_generator_, 854 request_sender_.get(),
810 CreateComposedCallback( 855 request_context_getter_.get(),
811 base::Bind(&test_util::RunAndQuit), 856 *url_generator_,
812 test_util::CreateCopyResultCallback(&result_code, &result_data)), 857 test_util::CreateQuitCallback(
813 "invalid_resource_id", 858 &run_loop,
814 "APP_ID"); 859 test_util::CreateCopyResultCallback(&result_code, &result_data)),
860 "invalid_resource_id",
861 "APP_ID");
815 862
816 request_sender_->StartRequestWithRetry(request); 863 request_sender_->StartRequestWithRetry(request);
817 base::MessageLoop::current()->Run(); 864 run_loop.Run();
865 }
818 866
819 EXPECT_EQ(GDATA_PARSE_ERROR, result_code); 867 EXPECT_EQ(GDATA_PARSE_ERROR, result_code);
820 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 868 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
821 EXPECT_EQ("/feeds/default/private/full/invalid_resource_id" 869 EXPECT_EQ("/feeds/default/private/full/invalid_resource_id"
822 "?v=3&alt=json&showroot=true", 870 "?v=3&alt=json&showroot=true",
823 http_request_.relative_url); 871 http_request_.relative_url);
824 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 872 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
825 EXPECT_EQ("*", http_request_.headers["If-Match"]); 873 EXPECT_EQ("*", http_request_.headers["If-Match"]);
826 874
827 EXPECT_TRUE(http_request_.has_content); 875 EXPECT_TRUE(http_request_.has_content);
828 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 876 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
829 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " 877 "<entry xmlns=\"http://www.w3.org/2005/Atom\" "
830 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" 878 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n"
831 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n" 879 " <docs:authorizedApp>APP_ID</docs:authorizedApp>\n"
832 "</entry>\n", 880 "</entry>\n",
833 http_request_.content); 881 http_request_.content);
834 } 882 }
835 883
836 TEST_F(GDataWapiRequestsTest, AddResourceToDirectoryRequest) { 884 TEST_F(GDataWapiRequestsTest, AddResourceToDirectoryRequest) {
837 GDataErrorCode result_code = GDATA_OTHER_ERROR; 885 GDataErrorCode result_code = GDATA_OTHER_ERROR;
838 886
839 // Add a file to the root directory. 887 // Add a file to the root directory.
840 AddResourceToDirectoryRequest* request = 888 {
841 new AddResourceToDirectoryRequest( 889 base::RunLoop run_loop;
842 request_sender_.get(), 890 AddResourceToDirectoryRequest* request =
843 request_context_getter_.get(), 891 new AddResourceToDirectoryRequest(
844 *url_generator_, 892 request_sender_.get(),
845 CreateComposedCallback( 893 request_context_getter_.get(),
846 base::Bind(&test_util::RunAndQuit), 894 *url_generator_,
847 test_util::CreateCopyResultCallback(&result_code)), 895 test_util::CreateQuitCallback(
848 "folder:root", 896 &run_loop,
849 "file:2_file_resource_id"); 897 test_util::CreateCopyResultCallback(&result_code)),
898 "folder:root",
899 "file:2_file_resource_id");
850 900
851 request_sender_->StartRequestWithRetry(request); 901 request_sender_->StartRequestWithRetry(request);
852 base::MessageLoop::current()->Run(); 902 run_loop.Run();
903 }
853 904
854 EXPECT_EQ(HTTP_SUCCESS, result_code); 905 EXPECT_EQ(HTTP_SUCCESS, result_code);
855 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 906 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
856 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json" 907 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents?v=3&alt=json"
857 "&showroot=true", 908 "&showroot=true",
858 http_request_.relative_url); 909 http_request_.relative_url);
859 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 910 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
860 911
861 EXPECT_TRUE(http_request_.has_content); 912 EXPECT_TRUE(http_request_.has_content);
862 EXPECT_EQ(base::StringPrintf("<?xml version=\"1.0\"?>\n" 913 EXPECT_EQ(base::StringPrintf("<?xml version=\"1.0\"?>\n"
863 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n" 914 "<entry xmlns=\"http://www.w3.org/2005/Atom\">\n"
864 " <id>%sfeeds/default/private/full/" 915 " <id>%sfeeds/default/private/full/"
865 "file%%3A2_file_resource_id</id>\n" 916 "file%%3A2_file_resource_id</id>\n"
866 "</entry>\n", 917 "</entry>\n",
867 test_server_.base_url().spec().c_str()), 918 test_server_.base_url().spec().c_str()),
868 http_request_.content); 919 http_request_.content);
869 } 920 }
870 921
871 TEST_F(GDataWapiRequestsTest, RemoveResourceFromDirectoryRequest) { 922 TEST_F(GDataWapiRequestsTest, RemoveResourceFromDirectoryRequest) {
872 GDataErrorCode result_code = GDATA_OTHER_ERROR; 923 GDataErrorCode result_code = GDATA_OTHER_ERROR;
873 924
874 // Remove a file from the root directory. 925 // Remove a file from the root directory.
875 RemoveResourceFromDirectoryRequest* request = 926 {
876 new RemoveResourceFromDirectoryRequest( 927 base::RunLoop run_loop;
877 request_sender_.get(), 928 RemoveResourceFromDirectoryRequest* request =
878 request_context_getter_.get(), 929 new RemoveResourceFromDirectoryRequest(
879 *url_generator_, 930 request_sender_.get(),
880 CreateComposedCallback( 931 request_context_getter_.get(),
881 base::Bind(&test_util::RunAndQuit), 932 *url_generator_,
882 test_util::CreateCopyResultCallback(&result_code)), 933 test_util::CreateQuitCallback(
883 "folder:root", 934 &run_loop,
884 "file:2_file_resource_id"); 935 test_util::CreateCopyResultCallback(&result_code)),
936 "folder:root",
937 "file:2_file_resource_id");
885 938
886 request_sender_->StartRequestWithRetry(request); 939 request_sender_->StartRequestWithRetry(request);
887 base::MessageLoop::current()->Run(); 940 run_loop.Run();
941 }
888 942
889 EXPECT_EQ(HTTP_SUCCESS, result_code); 943 EXPECT_EQ(HTTP_SUCCESS, result_code);
890 // DELETE method should be used, without the body content. 944 // DELETE method should be used, without the body content.
891 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method); 945 EXPECT_EQ(net::test_server::METHOD_DELETE, http_request_.method);
892 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents/" 946 EXPECT_EQ("/feeds/default/private/full/folder%3Aroot/contents/"
893 "file%3A2_file_resource_id?v=3&alt=json&showroot=true", 947 "file%3A2_file_resource_id?v=3&alt=json&showroot=true",
894 http_request_.relative_url); 948 http_request_.relative_url);
895 EXPECT_EQ("*", http_request_.headers["If-Match"]); 949 EXPECT_EQ("*", http_request_.headers["If-Match"]);
896 EXPECT_FALSE(http_request_.has_content); 950 EXPECT_FALSE(http_request_.has_content);
897 } 951 }
898 952
899 // This test exercises InitiateUploadNewFileRequest and 953 // This test exercises InitiateUploadNewFileRequest and
900 // ResumeUploadRequest for a scenario of uploading a new file. 954 // ResumeUploadRequest for a scenario of uploading a new file.
901 TEST_F(GDataWapiRequestsTest, UploadNewFile) { 955 TEST_F(GDataWapiRequestsTest, UploadNewFile) {
902 const std::string kUploadContent = "hello"; 956 const std::string kUploadContent = "hello";
903 const base::FilePath kTestFilePath = 957 const base::FilePath kTestFilePath =
904 temp_dir_.path().AppendASCII("upload_file.txt"); 958 temp_dir_.path().AppendASCII("upload_file.txt");
905 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); 959 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent));
906 960
907 GDataErrorCode result_code = GDATA_OTHER_ERROR; 961 GDataErrorCode result_code = GDATA_OTHER_ERROR;
908 GURL upload_url; 962 GURL upload_url;
909 963
910 // 1) Get the upload URL for uploading a new file. 964 // 1) Get the upload URL for uploading a new file.
911 InitiateUploadNewFileRequest* initiate_request = 965 {
912 new InitiateUploadNewFileRequest( 966 base::RunLoop run_loop;
913 request_sender_.get(), 967 InitiateUploadNewFileRequest* initiate_request =
914 request_context_getter_.get(), 968 new InitiateUploadNewFileRequest(
915 *url_generator_, 969 request_sender_.get(),
916 CreateComposedCallback( 970 request_context_getter_.get(),
917 base::Bind(&test_util::RunAndQuit), 971 *url_generator_,
918 test_util::CreateCopyResultCallback(&result_code, &upload_url)), 972 test_util::CreateQuitCallback(
919 "text/plain", 973 &run_loop,
920 kUploadContent.size(), 974 test_util::CreateCopyResultCallback(&result_code, &upload_url)),
921 "folder:id", 975 "text/plain",
922 "New file"); 976 kUploadContent.size(),
923 977 "folder:id",
924 request_sender_->StartRequestWithRetry(initiate_request); 978 "New file");
925 base::MessageLoop::current()->Run(); 979 request_sender_->StartRequestWithRetry(initiate_request);
980 run_loop.Run();
981 }
926 982
927 EXPECT_EQ(HTTP_SUCCESS, result_code); 983 EXPECT_EQ(HTTP_SUCCESS, result_code);
928 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); 984 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url);
929 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 985 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
930 // convert=false should be passed as files should be uploaded as-is. 986 // convert=false should be passed as files should be uploaded as-is.
931 EXPECT_EQ( 987 EXPECT_EQ(
932 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" 988 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents"
933 "?convert=false&v=3&alt=json&showroot=true", 989 "?convert=false&v=3&alt=json&showroot=true",
934 http_request_.relative_url); 990 http_request_.relative_url);
935 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 991 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
936 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 992 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
937 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 993 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
938 http_request_.headers["X-Upload-Content-Length"]); 994 http_request_.headers["X-Upload-Content-Length"]);
939 995
940 EXPECT_TRUE(http_request_.has_content); 996 EXPECT_TRUE(http_request_.has_content);
941 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 997 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
942 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " 998 "<entry xmlns=\"http://www.w3.org/2005/Atom\" "
943 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" 999 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n"
944 " <title>New file</title>\n" 1000 " <title>New file</title>\n"
945 "</entry>\n", 1001 "</entry>\n",
946 http_request_.content); 1002 http_request_.content);
947 1003
948 // 2) Upload the content to the upload URL. 1004 // 2) Upload the content to the upload URL.
949 UploadRangeResponse response; 1005 UploadRangeResponse response;
950 scoped_ptr<ResourceEntry> new_entry; 1006 scoped_ptr<ResourceEntry> new_entry;
951 1007
952 ResumeUploadRequest* resume_request = new ResumeUploadRequest( 1008 {
953 request_sender_.get(), 1009 base::RunLoop run_loop;
954 request_context_getter_.get(), 1010 ResumeUploadRequest* resume_request = new ResumeUploadRequest(
955 CreateComposedCallback( 1011 request_sender_.get(),
956 base::Bind(&test_util::RunAndQuit), 1012 request_context_getter_.get(),
957 test_util::CreateCopyResultCallback(&response, &new_entry)), 1013 test_util::CreateQuitCallback(
958 ProgressCallback(), 1014 &run_loop,
959 upload_url, 1015 test_util::CreateCopyResultCallback(&response, &new_entry)),
960 0, // start_position 1016 ProgressCallback(),
961 kUploadContent.size(), // end_position (exclusive) 1017 upload_url,
962 kUploadContent.size(), // content_length, 1018 0, // start_position
963 "text/plain", // content_type 1019 kUploadContent.size(), // end_position (exclusive)
964 kTestFilePath); 1020 kUploadContent.size(), // content_length,
1021 "text/plain", // content_type
1022 kTestFilePath);
965 1023
966 request_sender_->StartRequestWithRetry(resume_request); 1024 request_sender_->StartRequestWithRetry(resume_request);
967 base::MessageLoop::current()->Run(); 1025 run_loop.Run();
1026 }
968 1027
969 // METHOD_PUT should be used to upload data. 1028 // METHOD_PUT should be used to upload data.
970 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1029 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
971 // Request should go to the upload URL. 1030 // Request should go to the upload URL.
972 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1031 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
973 // Content-Range header should be added. 1032 // Content-Range header should be added.
974 EXPECT_EQ("bytes 0-" + 1033 EXPECT_EQ("bytes 0-" +
975 base::Int64ToString(kUploadContent.size() -1) + "/" + 1034 base::Int64ToString(kUploadContent.size() -1) + "/" +
976 base::Int64ToString(kUploadContent.size()), 1035 base::Int64ToString(kUploadContent.size()),
977 http_request_.headers["Content-Range"]); 1036 http_request_.headers["Content-Range"]);
(...skipping 20 matching lines...) Expand all
998 // ResumeUploadRequests, which are start, middle and last requests. 1057 // ResumeUploadRequests, which are start, middle and last requests.
999 const std::string kUploadContent(kMaxNumBytes * 2 + 1, 'a'); 1058 const std::string kUploadContent(kMaxNumBytes * 2 + 1, 'a');
1000 const base::FilePath kTestFilePath = 1059 const base::FilePath kTestFilePath =
1001 temp_dir_.path().AppendASCII("upload_file.txt"); 1060 temp_dir_.path().AppendASCII("upload_file.txt");
1002 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); 1061 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent));
1003 1062
1004 GDataErrorCode result_code = GDATA_OTHER_ERROR; 1063 GDataErrorCode result_code = GDATA_OTHER_ERROR;
1005 GURL upload_url; 1064 GURL upload_url;
1006 1065
1007 // 1) Get the upload URL for uploading a new file. 1066 // 1) Get the upload URL for uploading a new file.
1008 InitiateUploadNewFileRequest* initiate_request = 1067 {
1009 new InitiateUploadNewFileRequest( 1068 base::RunLoop run_loop;
1010 request_sender_.get(), 1069 InitiateUploadNewFileRequest* initiate_request =
1011 request_context_getter_.get(), 1070 new InitiateUploadNewFileRequest(
1012 *url_generator_, 1071 request_sender_.get(),
1013 CreateComposedCallback( 1072 request_context_getter_.get(),
1014 base::Bind(&test_util::RunAndQuit), 1073 *url_generator_,
1015 test_util::CreateCopyResultCallback(&result_code, &upload_url)), 1074 test_util::CreateQuitCallback(
1016 "text/plain", 1075 &run_loop,
1017 kUploadContent.size(), 1076 test_util::CreateCopyResultCallback(&result_code, &upload_url)),
1018 "folder:id", 1077 "text/plain",
1019 "New file"); 1078 kUploadContent.size(),
1020 1079 "folder:id",
1021 request_sender_->StartRequestWithRetry(initiate_request); 1080 "New file");
1022 base::MessageLoop::current()->Run(); 1081 request_sender_->StartRequestWithRetry(initiate_request);
1082 run_loop.Run();
1083 }
1023 1084
1024 EXPECT_EQ(HTTP_SUCCESS, result_code); 1085 EXPECT_EQ(HTTP_SUCCESS, result_code);
1025 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); 1086 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url);
1026 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 1087 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
1027 // convert=false should be passed as files should be uploaded as-is. 1088 // convert=false should be passed as files should be uploaded as-is.
1028 EXPECT_EQ( 1089 EXPECT_EQ(
1029 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" 1090 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents"
1030 "?convert=false&v=3&alt=json&showroot=true", 1091 "?convert=false&v=3&alt=json&showroot=true",
1031 http_request_.relative_url); 1092 http_request_.relative_url);
1032 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1093 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
(...skipping 10 matching lines...) Expand all
1043 http_request_.content); 1104 http_request_.content);
1044 1105
1045 // 2) Before sending any data, check the current status. 1106 // 2) Before sending any data, check the current status.
1046 // This is an edge case test for GetUploadStatusRequest 1107 // This is an edge case test for GetUploadStatusRequest
1047 // (UploadRangeRequestBase). 1108 // (UploadRangeRequestBase).
1048 { 1109 {
1049 UploadRangeResponse response; 1110 UploadRangeResponse response;
1050 scoped_ptr<ResourceEntry> new_entry; 1111 scoped_ptr<ResourceEntry> new_entry;
1051 1112
1052 // Check the response by GetUploadStatusRequest. 1113 // Check the response by GetUploadStatusRequest.
1053 GetUploadStatusRequest* get_upload_status_request = 1114 {
1054 new GetUploadStatusRequest( 1115 base::RunLoop run_loop;
1055 request_sender_.get(), 1116 GetUploadStatusRequest* get_upload_status_request =
1056 request_context_getter_.get(), 1117 new GetUploadStatusRequest(
1057 CreateComposedCallback( 1118 request_sender_.get(),
1058 base::Bind(&test_util::RunAndQuit), 1119 request_context_getter_.get(),
1059 test_util::CreateCopyResultCallback(&response, &new_entry)), 1120 test_util::CreateQuitCallback(
1060 upload_url, 1121 &run_loop,
1061 kUploadContent.size()); 1122 test_util::CreateCopyResultCallback(&response, &new_entry)),
1062 request_sender_->StartRequestWithRetry(get_upload_status_request); 1123 upload_url,
1063 base::MessageLoop::current()->Run(); 1124 kUploadContent.size());
1125 request_sender_->StartRequestWithRetry(get_upload_status_request);
1126 run_loop.Run();
1127 }
1064 1128
1065 // METHOD_PUT should be used to upload data. 1129 // METHOD_PUT should be used to upload data.
1066 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1130 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1067 // Request should go to the upload URL. 1131 // Request should go to the upload URL.
1068 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1132 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1069 // Content-Range header should be added. 1133 // Content-Range header should be added.
1070 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), 1134 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()),
1071 http_request_.headers["Content-Range"]); 1135 http_request_.headers["Content-Range"]);
1072 EXPECT_TRUE(http_request_.has_content); 1136 EXPECT_TRUE(http_request_.has_content);
1073 EXPECT_TRUE(http_request_.content.empty()); 1137 EXPECT_TRUE(http_request_.content.empty());
(...skipping 14 matching lines...) Expand all
1088 const size_t remaining_size = kUploadContent.size() - start_position; 1152 const size_t remaining_size = kUploadContent.size() - start_position;
1089 const std::string payload = kUploadContent.substr( 1153 const std::string payload = kUploadContent.substr(
1090 start_position, std::min(kMaxNumBytes, remaining_size)); 1154 start_position, std::min(kMaxNumBytes, remaining_size));
1091 num_bytes_consumed += payload.size(); 1155 num_bytes_consumed += payload.size();
1092 // The end position is exclusive. 1156 // The end position is exclusive.
1093 const size_t end_position = start_position + payload.size(); 1157 const size_t end_position = start_position + payload.size();
1094 1158
1095 UploadRangeResponse response; 1159 UploadRangeResponse response;
1096 scoped_ptr<ResourceEntry> new_entry; 1160 scoped_ptr<ResourceEntry> new_entry;
1097 1161
1098 ResumeUploadRequest* resume_request = new ResumeUploadRequest( 1162 {
1099 request_sender_.get(), 1163 base::RunLoop run_loop;
1100 request_context_getter_.get(), 1164 ResumeUploadRequest* resume_request = new ResumeUploadRequest(
1101 CreateComposedCallback( 1165 request_sender_.get(),
1102 base::Bind(&test_util::RunAndQuit), 1166 request_context_getter_.get(),
1103 test_util::CreateCopyResultCallback(&response, &new_entry)), 1167 test_util::CreateQuitCallback(
1104 ProgressCallback(), 1168 &run_loop,
1105 upload_url, 1169 test_util::CreateCopyResultCallback(&response, &new_entry)),
1106 start_position, 1170 ProgressCallback(),
1107 end_position, 1171 upload_url,
1108 kUploadContent.size(), // content_length, 1172 start_position,
1109 "text/plain", // content_type 1173 end_position,
1110 kTestFilePath); 1174 kUploadContent.size(), // content_length,
1111 1175 "text/plain", // content_type
1112 request_sender_->StartRequestWithRetry(resume_request); 1176 kTestFilePath);
1113 base::MessageLoop::current()->Run(); 1177 request_sender_->StartRequestWithRetry(resume_request);
1178 run_loop.Run();
1179 }
1114 1180
1115 // METHOD_PUT should be used to upload data. 1181 // METHOD_PUT should be used to upload data.
1116 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1182 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1117 // Request should go to the upload URL. 1183 // Request should go to the upload URL.
1118 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1184 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1119 // Content-Range header should be added. 1185 // Content-Range header should be added.
1120 EXPECT_EQ("bytes " + 1186 EXPECT_EQ("bytes " +
1121 base::Int64ToString(start_position) + "-" + 1187 base::Int64ToString(start_position) + "-" +
1122 base::Int64ToString(end_position - 1) + "/" + 1188 base::Int64ToString(end_position - 1) + "/" +
1123 base::Int64ToString(kUploadContent.size()), 1189 base::Int64ToString(kUploadContent.size()),
(...skipping 12 matching lines...) Expand all
1136 // The upload process is completed, so exit from the loop. 1202 // The upload process is completed, so exit from the loop.
1137 break; 1203 break;
1138 } 1204 }
1139 1205
1140 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code); 1206 EXPECT_EQ(HTTP_RESUME_INCOMPLETE, response.code);
1141 EXPECT_EQ(0, response.start_position_received); 1207 EXPECT_EQ(0, response.start_position_received);
1142 EXPECT_EQ(static_cast<int64>(end_position), 1208 EXPECT_EQ(static_cast<int64>(end_position),
1143 response.end_position_received); 1209 response.end_position_received);
1144 1210
1145 // Check the response by GetUploadStatusRequest. 1211 // Check the response by GetUploadStatusRequest.
1146 GetUploadStatusRequest* get_upload_status_request = 1212 {
1147 new GetUploadStatusRequest( 1213 base::RunLoop run_loop;
1148 request_sender_.get(), 1214 GetUploadStatusRequest* get_upload_status_request =
1149 request_context_getter_.get(), 1215 new GetUploadStatusRequest(
1150 CreateComposedCallback( 1216 request_sender_.get(),
1151 base::Bind(&test_util::RunAndQuit), 1217 request_context_getter_.get(),
1152 test_util::CreateCopyResultCallback(&response, &new_entry)), 1218 test_util::CreateQuitCallback(
1153 upload_url, 1219 &run_loop,
1154 kUploadContent.size()); 1220 test_util::CreateCopyResultCallback(&response, &new_entry)),
1155 request_sender_->StartRequestWithRetry(get_upload_status_request); 1221 upload_url,
1156 base::MessageLoop::current()->Run(); 1222 kUploadContent.size());
1223 request_sender_->StartRequestWithRetry(get_upload_status_request);
1224 run_loop.Run();
1225 }
1157 1226
1158 // METHOD_PUT should be used to upload data. 1227 // METHOD_PUT should be used to upload data.
1159 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1228 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1160 // Request should go to the upload URL. 1229 // Request should go to the upload URL.
1161 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1230 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1162 // Content-Range header should be added. 1231 // Content-Range header should be added.
1163 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()), 1232 EXPECT_EQ("bytes */" + base::Int64ToString(kUploadContent.size()),
1164 http_request_.headers["Content-Range"]); 1233 http_request_.headers["Content-Range"]);
1165 EXPECT_TRUE(http_request_.has_content); 1234 EXPECT_TRUE(http_request_.has_content);
1166 EXPECT_TRUE(http_request_.content.empty()); 1235 EXPECT_TRUE(http_request_.content.empty());
(...skipping 16 matching lines...) Expand all
1183 TEST_F(GDataWapiRequestsTest, UploadNewEmptyFile) { 1252 TEST_F(GDataWapiRequestsTest, UploadNewEmptyFile) {
1184 const std::string kUploadContent; 1253 const std::string kUploadContent;
1185 const base::FilePath kTestFilePath = 1254 const base::FilePath kTestFilePath =
1186 temp_dir_.path().AppendASCII("empty_file.txt"); 1255 temp_dir_.path().AppendASCII("empty_file.txt");
1187 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); 1256 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent));
1188 1257
1189 GDataErrorCode result_code = GDATA_OTHER_ERROR; 1258 GDataErrorCode result_code = GDATA_OTHER_ERROR;
1190 GURL upload_url; 1259 GURL upload_url;
1191 1260
1192 // 1) Get the upload URL for uploading a new file. 1261 // 1) Get the upload URL for uploading a new file.
1193 InitiateUploadNewFileRequest* initiate_request = 1262 {
1194 new InitiateUploadNewFileRequest( 1263 base::RunLoop run_loop;
1195 request_sender_.get(), 1264 InitiateUploadNewFileRequest* initiate_request =
1196 request_context_getter_.get(), 1265 new InitiateUploadNewFileRequest(
1197 *url_generator_, 1266 request_sender_.get(),
1198 CreateComposedCallback( 1267 request_context_getter_.get(),
1199 base::Bind(&test_util::RunAndQuit), 1268 *url_generator_,
1200 test_util::CreateCopyResultCallback(&result_code, &upload_url)), 1269 test_util::CreateQuitCallback(
1201 "text/plain", 1270 &run_loop,
1202 kUploadContent.size(), 1271 test_util::CreateCopyResultCallback(&result_code, &upload_url)),
1203 "folder:id", 1272 "text/plain",
1204 "New file"); 1273 kUploadContent.size(),
1205 1274 "folder:id",
1206 request_sender_->StartRequestWithRetry(initiate_request); 1275 "New file");
1207 base::MessageLoop::current()->Run(); 1276 request_sender_->StartRequestWithRetry(initiate_request);
1277 run_loop.Run();
1278 }
1208 1279
1209 EXPECT_EQ(HTTP_SUCCESS, result_code); 1280 EXPECT_EQ(HTTP_SUCCESS, result_code);
1210 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url); 1281 EXPECT_EQ(test_server_.GetURL("/upload_new_file"), upload_url);
1211 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); 1282 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method);
1212 // convert=false should be passed as files should be uploaded as-is. 1283 // convert=false should be passed as files should be uploaded as-is.
1213 EXPECT_EQ( 1284 EXPECT_EQ(
1214 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents" 1285 "/feeds/upload/create-session/default/private/full/folder%3Aid/contents"
1215 "?convert=false&v=3&alt=json&showroot=true", 1286 "?convert=false&v=3&alt=json&showroot=true",
1216 http_request_.relative_url); 1287 http_request_.relative_url);
1217 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1288 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
1218 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]); 1289 EXPECT_EQ("application/atom+xml", http_request_.headers["Content-Type"]);
1219 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1290 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1220 http_request_.headers["X-Upload-Content-Length"]); 1291 http_request_.headers["X-Upload-Content-Length"]);
1221 1292
1222 EXPECT_TRUE(http_request_.has_content); 1293 EXPECT_TRUE(http_request_.has_content);
1223 EXPECT_EQ("<?xml version=\"1.0\"?>\n" 1294 EXPECT_EQ("<?xml version=\"1.0\"?>\n"
1224 "<entry xmlns=\"http://www.w3.org/2005/Atom\" " 1295 "<entry xmlns=\"http://www.w3.org/2005/Atom\" "
1225 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n" 1296 "xmlns:docs=\"http://schemas.google.com/docs/2007\">\n"
1226 " <title>New file</title>\n" 1297 " <title>New file</title>\n"
1227 "</entry>\n", 1298 "</entry>\n",
1228 http_request_.content); 1299 http_request_.content);
1229 1300
1230 // 2) Upload the content to the upload URL. 1301 // 2) Upload the content to the upload URL.
1231 UploadRangeResponse response; 1302 UploadRangeResponse response;
1232 scoped_ptr<ResourceEntry> new_entry; 1303 scoped_ptr<ResourceEntry> new_entry;
1233 1304
1234 ResumeUploadRequest* resume_request = new ResumeUploadRequest( 1305 {
1235 request_sender_.get(), 1306 base::RunLoop run_loop;
1236 request_context_getter_.get(), 1307 ResumeUploadRequest* resume_request = new ResumeUploadRequest(
1237 CreateComposedCallback( 1308 request_sender_.get(),
1238 base::Bind(&test_util::RunAndQuit), 1309 request_context_getter_.get(),
1239 test_util::CreateCopyResultCallback(&response, &new_entry)), 1310 test_util::CreateQuitCallback(
1240 ProgressCallback(), 1311 &run_loop,
1241 upload_url, 1312 test_util::CreateCopyResultCallback(&response, &new_entry)),
1242 0, // start_position 1313 ProgressCallback(),
1243 kUploadContent.size(), // end_position (exclusive) 1314 upload_url,
1244 kUploadContent.size(), // content_length, 1315 0, // start_position
1245 "text/plain", // content_type 1316 kUploadContent.size(), // end_position (exclusive)
1246 kTestFilePath); 1317 kUploadContent.size(), // content_length,
1247 1318 "text/plain", // content_type
1248 request_sender_->StartRequestWithRetry(resume_request); 1319 kTestFilePath);
1249 base::MessageLoop::current()->Run(); 1320 request_sender_->StartRequestWithRetry(resume_request);
1321 run_loop.Run();
1322 }
1250 1323
1251 // METHOD_PUT should be used to upload data. 1324 // METHOD_PUT should be used to upload data.
1252 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1325 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1253 // Request should go to the upload URL. 1326 // Request should go to the upload URL.
1254 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1327 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1255 // Content-Range header should not exit if the content is empty. 1328 // Content-Range header should not exit if the content is empty.
1256 // We should not generate the header with an invalid value "bytes 0--1/0". 1329 // We should not generate the header with an invalid value "bytes 0--1/0".
1257 EXPECT_EQ(0U, http_request_.headers.count("Content-Range")); 1330 EXPECT_EQ(0U, http_request_.headers.count("Content-Range"));
1258 // The upload content should be set in the HTTP request. 1331 // The upload content should be set in the HTTP request.
1259 EXPECT_TRUE(http_request_.has_content); 1332 EXPECT_TRUE(http_request_.has_content);
(...skipping 11 matching lines...) Expand all
1271 TEST_F(GDataWapiRequestsTest, UploadExistingFile) { 1344 TEST_F(GDataWapiRequestsTest, UploadExistingFile) {
1272 const std::string kUploadContent = "hello"; 1345 const std::string kUploadContent = "hello";
1273 const base::FilePath kTestFilePath = 1346 const base::FilePath kTestFilePath =
1274 temp_dir_.path().AppendASCII("upload_file.txt"); 1347 temp_dir_.path().AppendASCII("upload_file.txt");
1275 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); 1348 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent));
1276 1349
1277 GDataErrorCode result_code = GDATA_OTHER_ERROR; 1350 GDataErrorCode result_code = GDATA_OTHER_ERROR;
1278 GURL upload_url; 1351 GURL upload_url;
1279 1352
1280 // 1) Get the upload URL for uploading an existing file. 1353 // 1) Get the upload URL for uploading an existing file.
1281 InitiateUploadExistingFileRequest* initiate_request = 1354 {
1282 new InitiateUploadExistingFileRequest( 1355 base::RunLoop run_loop;
1283 request_sender_.get(), 1356 InitiateUploadExistingFileRequest* initiate_request =
1284 request_context_getter_.get(), 1357 new InitiateUploadExistingFileRequest(
1285 *url_generator_, 1358 request_sender_.get(),
1286 CreateComposedCallback( 1359 request_context_getter_.get(),
1287 base::Bind(&test_util::RunAndQuit), 1360 *url_generator_,
1288 test_util::CreateCopyResultCallback(&result_code, &upload_url)), 1361 test_util::CreateQuitCallback(
1289 "text/plain", 1362 &run_loop,
1290 kUploadContent.size(), 1363 test_util::CreateCopyResultCallback(&result_code, &upload_url)),
1291 "file:foo", 1364 "text/plain",
1292 std::string() /* etag */); 1365 kUploadContent.size(),
1293 1366 "file:foo",
1294 request_sender_->StartRequestWithRetry(initiate_request); 1367 std::string() /* etag */);
1295 base::MessageLoop::current()->Run(); 1368 request_sender_->StartRequestWithRetry(initiate_request);
1369 run_loop.Run();
1370 }
1296 1371
1297 EXPECT_EQ(HTTP_SUCCESS, result_code); 1372 EXPECT_EQ(HTTP_SUCCESS, result_code);
1298 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); 1373 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url);
1299 // For updating an existing file, METHOD_PUT should be used. 1374 // For updating an existing file, METHOD_PUT should be used.
1300 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1375 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1301 // convert=false should be passed as files should be uploaded as-is. 1376 // convert=false should be passed as files should be uploaded as-is.
1302 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" 1377 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo"
1303 "?convert=false&v=3&alt=json&showroot=true", 1378 "?convert=false&v=3&alt=json&showroot=true",
1304 http_request_.relative_url); 1379 http_request_.relative_url);
1305 // Even though the body is empty, the content type should be set to 1380 // Even though the body is empty, the content type should be set to
1306 // "text/plain". 1381 // "text/plain".
1307 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); 1382 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]);
1308 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1383 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
1309 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1384 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1310 http_request_.headers["X-Upload-Content-Length"]); 1385 http_request_.headers["X-Upload-Content-Length"]);
1311 // For updating an existing file, an empty body should be attached (PUT 1386 // For updating an existing file, an empty body should be attached (PUT
1312 // requires a body) 1387 // requires a body)
1313 EXPECT_TRUE(http_request_.has_content); 1388 EXPECT_TRUE(http_request_.has_content);
1314 EXPECT_EQ("", http_request_.content); 1389 EXPECT_EQ("", http_request_.content);
1315 EXPECT_EQ("*", http_request_.headers["If-Match"]); 1390 EXPECT_EQ("*", http_request_.headers["If-Match"]);
1316 1391
1317 // 2) Upload the content to the upload URL. 1392 // 2) Upload the content to the upload URL.
1318 UploadRangeResponse response; 1393 UploadRangeResponse response;
1319 scoped_ptr<ResourceEntry> new_entry; 1394 scoped_ptr<ResourceEntry> new_entry;
1320 1395
1321 ResumeUploadRequest* resume_request = new ResumeUploadRequest( 1396 {
1322 request_sender_.get(), 1397 base::RunLoop run_loop;
1323 request_context_getter_.get(), 1398 ResumeUploadRequest* resume_request = new ResumeUploadRequest(
1324 CreateComposedCallback( 1399 request_sender_.get(),
1325 base::Bind(&test_util::RunAndQuit), 1400 request_context_getter_.get(),
1326 test_util::CreateCopyResultCallback(&response, &new_entry)), 1401 test_util::CreateQuitCallback(
1327 ProgressCallback(), 1402 &run_loop,
1328 upload_url, 1403 test_util::CreateCopyResultCallback(&response, &new_entry)),
1329 0, // start_position 1404 ProgressCallback(),
1330 kUploadContent.size(), // end_position (exclusive) 1405 upload_url,
1331 kUploadContent.size(), // content_length, 1406 0, // start_position
1332 "text/plain", // content_type 1407 kUploadContent.size(), // end_position (exclusive)
1333 kTestFilePath); 1408 kUploadContent.size(), // content_length,
1409 "text/plain", // content_type
1410 kTestFilePath);
1334 1411
1335 request_sender_->StartRequestWithRetry(resume_request); 1412 request_sender_->StartRequestWithRetry(resume_request);
1336 base::MessageLoop::current()->Run(); 1413 run_loop.Run();
1414 }
1337 1415
1338 // METHOD_PUT should be used to upload data. 1416 // METHOD_PUT should be used to upload data.
1339 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1417 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1340 // Request should go to the upload URL. 1418 // Request should go to the upload URL.
1341 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1419 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1342 // Content-Range header should be added. 1420 // Content-Range header should be added.
1343 EXPECT_EQ("bytes 0-" + 1421 EXPECT_EQ("bytes 0-" +
1344 base::Int64ToString(kUploadContent.size() -1) + "/" + 1422 base::Int64ToString(kUploadContent.size() -1) + "/" +
1345 base::Int64ToString(kUploadContent.size()), 1423 base::Int64ToString(kUploadContent.size()),
1346 http_request_.headers["Content-Range"]); 1424 http_request_.headers["Content-Range"]);
(...skipping 13 matching lines...) Expand all
1360 TEST_F(GDataWapiRequestsTest, UploadExistingFileWithETag) { 1438 TEST_F(GDataWapiRequestsTest, UploadExistingFileWithETag) {
1361 const std::string kUploadContent = "hello"; 1439 const std::string kUploadContent = "hello";
1362 const base::FilePath kTestFilePath = 1440 const base::FilePath kTestFilePath =
1363 temp_dir_.path().AppendASCII("upload_file.txt"); 1441 temp_dir_.path().AppendASCII("upload_file.txt");
1364 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent)); 1442 ASSERT_TRUE(test_util::WriteStringToFile(kTestFilePath, kUploadContent));
1365 1443
1366 GDataErrorCode result_code = GDATA_OTHER_ERROR; 1444 GDataErrorCode result_code = GDATA_OTHER_ERROR;
1367 GURL upload_url; 1445 GURL upload_url;
1368 1446
1369 // 1) Get the upload URL for uploading an existing file. 1447 // 1) Get the upload URL for uploading an existing file.
1370 InitiateUploadExistingFileRequest* initiate_request = 1448 {
1371 new InitiateUploadExistingFileRequest( 1449 base::RunLoop run_loop;
1372 request_sender_.get(), 1450 InitiateUploadExistingFileRequest* initiate_request =
1373 request_context_getter_.get(), 1451 new InitiateUploadExistingFileRequest(
1374 *url_generator_, 1452 request_sender_.get(),
1375 CreateComposedCallback( 1453 request_context_getter_.get(),
1376 base::Bind(&test_util::RunAndQuit), 1454 *url_generator_,
1377 test_util::CreateCopyResultCallback(&result_code, &upload_url)), 1455 test_util::CreateQuitCallback(
1378 "text/plain", 1456 &run_loop,
1379 kUploadContent.size(), 1457 test_util::CreateCopyResultCallback(&result_code, &upload_url)),
1380 "file:foo", 1458 "text/plain",
1381 kTestETag); 1459 kUploadContent.size(),
1382 1460 "file:foo",
1383 request_sender_->StartRequestWithRetry(initiate_request); 1461 kTestETag);
1384 base::MessageLoop::current()->Run(); 1462 request_sender_->StartRequestWithRetry(initiate_request);
1463 run_loop.Run();
1464 }
1385 1465
1386 EXPECT_EQ(HTTP_SUCCESS, result_code); 1466 EXPECT_EQ(HTTP_SUCCESS, result_code);
1387 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url); 1467 EXPECT_EQ(test_server_.GetURL("/upload_existing_file"), upload_url);
1388 // For updating an existing file, METHOD_PUT should be used. 1468 // For updating an existing file, METHOD_PUT should be used.
1389 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1469 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1390 // convert=false should be passed as files should be uploaded as-is. 1470 // convert=false should be passed as files should be uploaded as-is.
1391 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" 1471 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo"
1392 "?convert=false&v=3&alt=json&showroot=true", 1472 "?convert=false&v=3&alt=json&showroot=true",
1393 http_request_.relative_url); 1473 http_request_.relative_url);
1394 // Even though the body is empty, the content type should be set to 1474 // Even though the body is empty, the content type should be set to
1395 // "text/plain". 1475 // "text/plain".
1396 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); 1476 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]);
1397 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1477 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
1398 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1478 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1399 http_request_.headers["X-Upload-Content-Length"]); 1479 http_request_.headers["X-Upload-Content-Length"]);
1400 // For updating an existing file, an empty body should be attached (PUT 1480 // For updating an existing file, an empty body should be attached (PUT
1401 // requires a body) 1481 // requires a body)
1402 EXPECT_TRUE(http_request_.has_content); 1482 EXPECT_TRUE(http_request_.has_content);
1403 EXPECT_EQ("", http_request_.content); 1483 EXPECT_EQ("", http_request_.content);
1404 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]); 1484 EXPECT_EQ(kTestETag, http_request_.headers["If-Match"]);
1405 1485
1406 // 2) Upload the content to the upload URL. 1486 // 2) Upload the content to the upload URL.
1407 UploadRangeResponse response; 1487 UploadRangeResponse response;
1408 scoped_ptr<ResourceEntry> new_entry; 1488 scoped_ptr<ResourceEntry> new_entry;
1409 1489
1410 ResumeUploadRequest* resume_request = new ResumeUploadRequest( 1490 {
1411 request_sender_.get(), 1491 base::RunLoop run_loop;
1412 request_context_getter_.get(), 1492 ResumeUploadRequest* resume_request = new ResumeUploadRequest(
1413 CreateComposedCallback( 1493 request_sender_.get(),
1414 base::Bind(&test_util::RunAndQuit), 1494 request_context_getter_.get(),
1415 test_util::CreateCopyResultCallback(&response, &new_entry)), 1495 test_util::CreateQuitCallback(
1416 ProgressCallback(), 1496 &run_loop,
1417 upload_url, 1497 test_util::CreateCopyResultCallback(&response, &new_entry)),
1418 0, // start_position 1498 ProgressCallback(),
1419 kUploadContent.size(), // end_position (exclusive) 1499 upload_url,
1420 kUploadContent.size(), // content_length, 1500 0, // start_position
1421 "text/plain", // content_type 1501 kUploadContent.size(), // end_position (exclusive)
1422 kTestFilePath); 1502 kUploadContent.size(), // content_length,
1423 1503 "text/plain", // content_type
1424 request_sender_->StartRequestWithRetry(resume_request); 1504 kTestFilePath);
1425 base::MessageLoop::current()->Run(); 1505 request_sender_->StartRequestWithRetry(resume_request);
1506 run_loop.Run();
1507 }
1426 1508
1427 // METHOD_PUT should be used to upload data. 1509 // METHOD_PUT should be used to upload data.
1428 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1510 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1429 // Request should go to the upload URL. 1511 // Request should go to the upload URL.
1430 EXPECT_EQ(upload_url.path(), http_request_.relative_url); 1512 EXPECT_EQ(upload_url.path(), http_request_.relative_url);
1431 // Content-Range header should be added. 1513 // Content-Range header should be added.
1432 EXPECT_EQ("bytes 0-" + 1514 EXPECT_EQ("bytes 0-" +
1433 base::Int64ToString(kUploadContent.size() -1) + "/" + 1515 base::Int64ToString(kUploadContent.size() -1) + "/" +
1434 base::Int64ToString(kUploadContent.size()), 1516 base::Int64ToString(kUploadContent.size()),
1435 http_request_.headers["Content-Range"]); 1517 http_request_.headers["Content-Range"]);
1436 // The upload content should be set in the HTTP request. 1518 // The upload content should be set in the HTTP request.
1437 EXPECT_TRUE(http_request_.has_content); 1519 EXPECT_TRUE(http_request_.has_content);
1438 EXPECT_EQ(kUploadContent, http_request_.content); 1520 EXPECT_EQ(kUploadContent, http_request_.content);
1439 1521
1440 // Check the response. 1522 // Check the response.
1441 EXPECT_EQ(HTTP_SUCCESS, response.code); // Because it's an existing file. 1523 EXPECT_EQ(HTTP_SUCCESS, response.code); // Because it's an existing file.
1442 // The start and end positions should be set to -1, if an upload is complete. 1524 // The start and end positions should be set to -1, if an upload is complete.
1443 EXPECT_EQ(-1, response.start_position_received); 1525 EXPECT_EQ(-1, response.start_position_received);
1444 EXPECT_EQ(-1, response.end_position_received); 1526 EXPECT_EQ(-1, response.end_position_received);
1445 } 1527 }
1446 1528
1447 // This test exercises InitiateUploadExistingFileRequest for a scenario of 1529 // This test exercises InitiateUploadExistingFileRequest for a scenario of
1448 // confliction on updating an existing file. 1530 // confliction on updating an existing file.
1449 TEST_F(GDataWapiRequestsTest, UploadExistingFileWithETagConflict) { 1531 TEST_F(GDataWapiRequestsTest, UploadExistingFileWithETagConflict) {
1450 const std::string kUploadContent = "hello"; 1532 const std::string kUploadContent = "hello";
1451 const std::string kWrongETag = "wrong_etag"; 1533 const std::string kWrongETag = "wrong_etag";
1452 GDataErrorCode result_code = GDATA_OTHER_ERROR; 1534 GDataErrorCode result_code = GDATA_OTHER_ERROR;
1453 GURL upload_url; 1535 GURL upload_url;
1454 1536
1455 InitiateUploadExistingFileRequest* initiate_request = 1537 {
1456 new InitiateUploadExistingFileRequest( 1538 base::RunLoop run_loop;
1457 request_sender_.get(), 1539 InitiateUploadExistingFileRequest* initiate_request =
1458 request_context_getter_.get(), 1540 new InitiateUploadExistingFileRequest(
1459 *url_generator_, 1541 request_sender_.get(),
1460 CreateComposedCallback( 1542 request_context_getter_.get(),
1461 base::Bind(&test_util::RunAndQuit), 1543 *url_generator_,
1462 test_util::CreateCopyResultCallback(&result_code, &upload_url)), 1544 test_util::CreateQuitCallback(
1463 "text/plain", 1545 &run_loop,
1464 kUploadContent.size(), 1546 test_util::CreateCopyResultCallback(&result_code, &upload_url)),
1465 "file:foo", 1547 "text/plain",
1466 kWrongETag); 1548 kUploadContent.size(),
1467 1549 "file:foo",
1468 request_sender_->StartRequestWithRetry(initiate_request); 1550 kWrongETag);
1469 base::MessageLoop::current()->Run(); 1551 request_sender_->StartRequestWithRetry(initiate_request);
1552 run_loop.Run();
1553 }
1470 1554
1471 EXPECT_EQ(HTTP_PRECONDITION, result_code); 1555 EXPECT_EQ(HTTP_PRECONDITION, result_code);
1472 // For updating an existing file, METHOD_PUT should be used. 1556 // For updating an existing file, METHOD_PUT should be used.
1473 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); 1557 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method);
1474 // convert=false should be passed as files should be uploaded as-is. 1558 // convert=false should be passed as files should be uploaded as-is.
1475 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo" 1559 EXPECT_EQ("/feeds/upload/create-session/default/private/full/file%3Afoo"
1476 "?convert=false&v=3&alt=json&showroot=true", 1560 "?convert=false&v=3&alt=json&showroot=true",
1477 http_request_.relative_url); 1561 http_request_.relative_url);
1478 // Even though the body is empty, the content type should be set to 1562 // Even though the body is empty, the content type should be set to
1479 // "text/plain". 1563 // "text/plain".
1480 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]); 1564 EXPECT_EQ("text/plain", http_request_.headers["Content-Type"]);
1481 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]); 1565 EXPECT_EQ("text/plain", http_request_.headers["X-Upload-Content-Type"]);
1482 EXPECT_EQ(base::Int64ToString(kUploadContent.size()), 1566 EXPECT_EQ(base::Int64ToString(kUploadContent.size()),
1483 http_request_.headers["X-Upload-Content-Length"]); 1567 http_request_.headers["X-Upload-Content-Length"]);
1484 // For updating an existing file, an empty body should be attached (PUT 1568 // For updating an existing file, an empty body should be attached (PUT
1485 // requires a body) 1569 // requires a body)
1486 EXPECT_TRUE(http_request_.has_content); 1570 EXPECT_TRUE(http_request_.has_content);
1487 EXPECT_EQ("", http_request_.content); 1571 EXPECT_EQ("", http_request_.content);
1488 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]); 1572 EXPECT_EQ(kWrongETag, http_request_.headers["If-Match"]);
1489 } 1573 }
1490 1574
1491 } // namespace google_apis 1575 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/drive_api_requests_unittest.cc ('k') | chrome/browser/google_apis/test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698