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