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/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 response->set_content(id + id + id); | 338 response->set_content(id + id + id); |
339 response->set_content_type("text/plain"); | 339 response->set_content_type("text/plain"); |
340 return response.PassAs<net::test_server::HttpResponse>(); | 340 return response.PassAs<net::test_server::HttpResponse>(); |
341 } | 341 } |
342 | 342 |
343 // These are for the current upload file status. | 343 // These are for the current upload file status. |
344 int64 received_bytes_; | 344 int64 received_bytes_; |
345 int64 content_length_; | 345 int64 content_length_; |
346 }; | 346 }; |
347 | 347 |
| 348 TEST_F(DriveApiRequestsTest, FilesInsertRequest) { |
| 349 // Set an expected data file containing the directory's entry data. |
| 350 expected_data_file_path_ = |
| 351 test_util::GetTestFilePath("drive/directory_entry.json"); |
| 352 |
| 353 GDataErrorCode error = GDATA_OTHER_ERROR; |
| 354 scoped_ptr<FileResource> file_resource; |
| 355 |
| 356 // Create "new directory" in the root directory. |
| 357 { |
| 358 base::RunLoop run_loop; |
| 359 drive::FilesInsertRequest* request = new drive::FilesInsertRequest( |
| 360 request_sender_.get(), |
| 361 *url_generator_, |
| 362 test_util::CreateQuitCallback( |
| 363 &run_loop, |
| 364 test_util::CreateCopyResultCallback(&error, &file_resource))); |
| 365 request->set_mime_type("application/vnd.google-apps.folder"); |
| 366 request->add_parent("root"); |
| 367 request->set_title("new directory"); |
| 368 request_sender_->StartRequestWithRetry(request); |
| 369 run_loop.Run(); |
| 370 } |
| 371 |
| 372 EXPECT_EQ(HTTP_SUCCESS, error); |
| 373 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
| 374 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); |
| 375 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
| 376 |
| 377 EXPECT_TRUE(http_request_.has_content); |
| 378 |
| 379 scoped_ptr<FileResource> expected( |
| 380 FileResource::CreateFrom( |
| 381 *test_util::LoadJSONFile("drive/directory_entry.json"))); |
| 382 |
| 383 // Sanity check. |
| 384 ASSERT_TRUE(file_resource.get()); |
| 385 |
| 386 EXPECT_EQ(expected->file_id(), file_resource->file_id()); |
| 387 EXPECT_EQ(expected->title(), file_resource->title()); |
| 388 EXPECT_EQ(expected->mime_type(), file_resource->mime_type()); |
| 389 EXPECT_EQ(expected->parents().size(), file_resource->parents().size()); |
| 390 } |
| 391 |
348 TEST_F(DriveApiRequestsTest, FilesPatchRequest) { | 392 TEST_F(DriveApiRequestsTest, FilesPatchRequest) { |
349 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; | 393 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
350 const base::Time::Exploded kLastViewedByMeDate = | 394 const base::Time::Exploded kLastViewedByMeDate = |
351 {2013, 7, 0, 19, 15, 59, 13, 123}; | 395 {2013, 7, 0, 19, 15, 59, 13, 123}; |
352 | 396 |
353 // Set an expected data file containing valid result. | 397 // Set an expected data file containing valid result. |
354 expected_data_file_path_ = | 398 expected_data_file_path_ = |
355 test_util::GetTestFilePath("drive/file_entry.json"); | 399 test_util::GetTestFilePath("drive/file_entry.json"); |
356 | 400 |
357 GDataErrorCode error = GDATA_OTHER_ERROR; | 401 GDataErrorCode error = GDATA_OTHER_ERROR; |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 request_sender_->StartRequestWithRetry(request); | 674 request_sender_->StartRequestWithRetry(request); |
631 run_loop.Run(); | 675 run_loop.Run(); |
632 } | 676 } |
633 | 677 |
634 EXPECT_EQ(HTTP_SUCCESS, error); | 678 EXPECT_EQ(HTTP_SUCCESS, error); |
635 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 679 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
636 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url); | 680 EXPECT_EQ("/continue/get/file/list", http_request_.relative_url); |
637 EXPECT_TRUE(result); | 681 EXPECT_TRUE(result); |
638 } | 682 } |
639 | 683 |
640 TEST_F(DriveApiRequestsTest, CreateDirectoryRequest) { | |
641 // Set an expected data file containing the directory's entry data. | |
642 expected_data_file_path_ = | |
643 test_util::GetTestFilePath("drive/directory_entry.json"); | |
644 | |
645 GDataErrorCode error = GDATA_OTHER_ERROR; | |
646 scoped_ptr<FileResource> file_resource; | |
647 | |
648 // Create "new directory" in the root directory. | |
649 { | |
650 base::RunLoop run_loop; | |
651 drive::CreateDirectoryRequest* request = | |
652 new drive::CreateDirectoryRequest( | |
653 request_sender_.get(), | |
654 *url_generator_, | |
655 "root", | |
656 "new directory", | |
657 test_util::CreateQuitCallback( | |
658 &run_loop, | |
659 test_util::CreateCopyResultCallback(&error, &file_resource))); | |
660 request_sender_->StartRequestWithRetry(request); | |
661 run_loop.Run(); | |
662 } | |
663 | |
664 EXPECT_EQ(HTTP_SUCCESS, error); | |
665 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | |
666 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); | |
667 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | |
668 | |
669 EXPECT_TRUE(http_request_.has_content); | |
670 | |
671 scoped_ptr<FileResource> expected( | |
672 FileResource::CreateFrom( | |
673 *test_util::LoadJSONFile("drive/directory_entry.json"))); | |
674 | |
675 // Sanity check. | |
676 ASSERT_TRUE(file_resource.get()); | |
677 | |
678 EXPECT_EQ(expected->file_id(), file_resource->file_id()); | |
679 EXPECT_EQ(expected->title(), file_resource->title()); | |
680 EXPECT_EQ(expected->mime_type(), file_resource->mime_type()); | |
681 EXPECT_EQ(expected->parents().size(), file_resource->parents().size()); | |
682 } | |
683 | |
684 TEST_F(DriveApiRequestsTest, TouchResourceRequest) { | 684 TEST_F(DriveApiRequestsTest, TouchResourceRequest) { |
685 // Set an expected data file containing the directory's entry data. | 685 // Set an expected data file containing the directory's entry data. |
686 // It'd be returned if we rename a directory. | 686 // It'd be returned if we rename a directory. |
687 expected_data_file_path_ = | 687 expected_data_file_path_ = |
688 test_util::GetTestFilePath("drive/directory_entry.json"); | 688 test_util::GetTestFilePath("drive/directory_entry.json"); |
689 | 689 |
690 GDataErrorCode error = GDATA_OTHER_ERROR; | 690 GDataErrorCode error = GDATA_OTHER_ERROR; |
691 scoped_ptr<FileResource> file_resource; | 691 scoped_ptr<FileResource> file_resource; |
692 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; | 692 const base::Time::Exploded kModifiedDate = {2012, 7, 0, 19, 15, 59, 13, 123}; |
693 const base::Time::Exploded kLastViewedByMeDate = | 693 const base::Time::Exploded kLastViewedByMeDate = |
(...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1594 EXPECT_EQ(HTTP_SUCCESS, result_code); | 1594 EXPECT_EQ(HTTP_SUCCESS, result_code); |
1595 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); | 1595 EXPECT_EQ(net::test_server::METHOD_GET, http_request_.method); |
1596 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); | 1596 EXPECT_EQ(kTestDownloadPathPrefix + kTestId, http_request_.relative_url); |
1597 EXPECT_EQ(kDownloadedFilePath, temp_file); | 1597 EXPECT_EQ(kDownloadedFilePath, temp_file); |
1598 | 1598 |
1599 const std::string expected_contents = kTestId + kTestId + kTestId; | 1599 const std::string expected_contents = kTestId + kTestId + kTestId; |
1600 EXPECT_EQ(expected_contents, contents); | 1600 EXPECT_EQ(expected_contents, contents); |
1601 } | 1601 } |
1602 | 1602 |
1603 } // namespace google_apis | 1603 } // namespace google_apis |
OLD | NEW |