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