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/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 scoped_ptr<std::string> content) { | 55 scoped_ptr<std::string> content) { |
56 EXPECT_EQ(HTTP_SUCCESS, error); | 56 EXPECT_EQ(HTTP_SUCCESS, error); |
57 out->append(*content); | 57 out->append(*content); |
58 } | 58 } |
59 | 59 |
60 } // namespace | 60 } // namespace |
61 | 61 |
62 class DriveApiRequestsTest : public testing::Test { | 62 class DriveApiRequestsTest : public testing::Test { |
63 public: | 63 public: |
64 DriveApiRequestsTest() { | 64 DriveApiRequestsTest() { |
65 // Testing properties used by multiple test cases. | |
66 drive::Property private_property; | |
67 private_property.set_key("key1"); | |
68 private_property.set_value("value1"); | |
69 | |
70 drive::Property public_property; | |
71 public_property.set_visibility(drive::Property::VISIBILITY_PUBLIC); | |
72 public_property.set_key("key2"); | |
73 public_property.set_value("value2"); | |
74 | |
75 testing_properties_.push_back(private_property); | |
76 testing_properties_.push_back(public_property); | |
hashimoto
2015/02/23 10:16:20
nit: Initialization order and declaration order sh
mtomasz
2015/02/24 02:30:38
Done.
| |
65 } | 77 } |
66 | 78 |
67 void SetUp() override { | 79 void SetUp() override { |
68 request_context_getter_ = new net::TestURLRequestContextGetter( | 80 request_context_getter_ = new net::TestURLRequestContextGetter( |
69 message_loop_.message_loop_proxy()); | 81 message_loop_.message_loop_proxy()); |
70 | 82 |
71 request_sender_.reset(new RequestSender(new DummyAuthService, | 83 request_sender_.reset(new RequestSender(new DummyAuthService, |
72 request_context_getter_.get(), | 84 request_context_getter_.get(), |
73 message_loop_.message_loop_proxy(), | 85 message_loop_.message_loop_proxy(), |
74 kTestUserAgent)); | 86 kTestUserAgent)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 // These are content and its type in the expected response from the server. | 145 // These are content and its type in the expected response from the server. |
134 // See also HandleContentResponse below. | 146 // See also HandleContentResponse below. |
135 std::string expected_content_type_; | 147 std::string expected_content_type_; |
136 std::string expected_content_; | 148 std::string expected_content_; |
137 | 149 |
138 // The incoming HTTP request is saved so tests can verify the request | 150 // The incoming HTTP request is saved so tests can verify the request |
139 // parameters like HTTP method (ex. some requests should use DELETE | 151 // parameters like HTTP method (ex. some requests should use DELETE |
140 // instead of GET). | 152 // instead of GET). |
141 net::test_server::HttpRequest http_request_; | 153 net::test_server::HttpRequest http_request_; |
142 | 154 |
155 // Testing properties used by multiple test cases. | |
156 drive::Properties testing_properties_; | |
157 | |
143 private: | 158 private: |
144 void ResetExpectedResponse() { | 159 void ResetExpectedResponse() { |
145 expected_data_file_path_.clear(); | 160 expected_data_file_path_.clear(); |
146 expected_upload_path_.clear(); | 161 expected_upload_path_.clear(); |
147 expected_content_type_.clear(); | 162 expected_content_type_.clear(); |
148 expected_content_.clear(); | 163 expected_content_.clear(); |
149 } | 164 } |
150 | 165 |
151 // For "Children: delete" request, the server will return "204 No Content" | 166 // For "Children: delete" request, the server will return "204 No Content" |
152 // response meaning "success". | 167 // response meaning "success". |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
444 *url_generator_, | 459 *url_generator_, |
445 test_util::CreateQuitCallback( | 460 test_util::CreateQuitCallback( |
446 &run_loop, | 461 &run_loop, |
447 test_util::CreateCopyResultCallback(&error, &file_resource))); | 462 test_util::CreateCopyResultCallback(&error, &file_resource))); |
448 request->set_last_viewed_by_me_date( | 463 request->set_last_viewed_by_me_date( |
449 base::Time::FromUTCExploded(kLastViewedByMeDate)); | 464 base::Time::FromUTCExploded(kLastViewedByMeDate)); |
450 request->set_mime_type("application/vnd.google-apps.folder"); | 465 request->set_mime_type("application/vnd.google-apps.folder"); |
451 request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate)); | 466 request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate)); |
452 request->add_parent("root"); | 467 request->add_parent("root"); |
453 request->set_title("new directory"); | 468 request->set_title("new directory"); |
469 request->set_properties(testing_properties_); | |
454 request_sender_->StartRequestWithRetry(request); | 470 request_sender_->StartRequestWithRetry(request); |
455 run_loop.Run(); | 471 run_loop.Run(); |
456 } | 472 } |
457 | 473 |
458 EXPECT_EQ(HTTP_SUCCESS, error); | 474 EXPECT_EQ(HTTP_SUCCESS, error); |
459 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 475 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
460 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); | 476 EXPECT_EQ("/drive/v2/files", http_request_.relative_url); |
461 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 477 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
462 | 478 |
463 EXPECT_TRUE(http_request_.has_content); | 479 EXPECT_TRUE(http_request_.has_content); |
464 EXPECT_EQ("{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\"," | 480 EXPECT_EQ( |
465 "\"mimeType\":\"application/vnd.google-apps.folder\"," | 481 "{\"lastViewedByMeDate\":\"2013-07-19T15:59:13.123Z\"," |
466 "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\"," | 482 "\"mimeType\":\"application/vnd.google-apps.folder\"," |
467 "\"parents\":[{\"id\":\"root\"}]," | 483 "\"modifiedDate\":\"2012-07-19T15:59:13.123Z\"," |
468 "\"title\":\"new directory\"}", | 484 "\"parents\":[{\"id\":\"root\"}]," |
469 http_request_.content); | 485 "\"properties\":[" |
486 "{\"key\":\"key1\",\"value\":\"value1\",\"visibility\":\"PRIVATE\"}," | |
487 "{\"key\":\"key2\",\"value\":\"value2\",\"visibility\":\"PUBLIC\"}]," | |
488 "\"title\":\"new directory\"}", | |
489 http_request_.content); | |
470 | 490 |
471 scoped_ptr<FileResource> expected( | 491 scoped_ptr<FileResource> expected( |
472 FileResource::CreateFrom( | 492 FileResource::CreateFrom( |
473 *test_util::LoadJSONFile("drive/directory_entry.json"))); | 493 *test_util::LoadJSONFile("drive/directory_entry.json"))); |
474 | 494 |
475 // Sanity check. | 495 // Sanity check. |
476 ASSERT_TRUE(file_resource.get()); | 496 ASSERT_TRUE(file_resource.get()); |
477 | 497 |
478 EXPECT_EQ(expected->file_id(), file_resource->file_id()); | 498 EXPECT_EQ(expected->file_id(), file_resource->file_id()); |
479 EXPECT_EQ(expected->title(), file_resource->title()); | 499 EXPECT_EQ(expected->title(), file_resource->title()); |
(...skipping 24 matching lines...) Expand all Loading... | |
504 request->set_file_id("resource_id"); | 524 request->set_file_id("resource_id"); |
505 request->set_set_modified_date(true); | 525 request->set_set_modified_date(true); |
506 request->set_update_viewed_date(false); | 526 request->set_update_viewed_date(false); |
507 | 527 |
508 request->set_title("new title"); | 528 request->set_title("new title"); |
509 request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate)); | 529 request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate)); |
510 request->set_last_viewed_by_me_date( | 530 request->set_last_viewed_by_me_date( |
511 base::Time::FromUTCExploded(kLastViewedByMeDate)); | 531 base::Time::FromUTCExploded(kLastViewedByMeDate)); |
512 request->add_parent("parent_resource_id"); | 532 request->add_parent("parent_resource_id"); |
513 | 533 |
514 drive::Property private_property; | 534 request->set_properties(testing_properties_); |
515 private_property.set_key("key1"); | |
516 private_property.set_value("value1"); | |
517 | |
518 drive::Property public_property; | |
519 public_property.set_visibility(drive::Property::VISIBILITY_PUBLIC); | |
520 public_property.set_key("key2"); | |
521 public_property.set_value("value2"); | |
522 | |
523 drive::Properties properties; | |
524 properties.push_back(private_property); | |
525 properties.push_back(public_property); | |
526 request->set_properties(properties); | |
527 | |
528 request_sender_->StartRequestWithRetry(request); | 535 request_sender_->StartRequestWithRetry(request); |
529 run_loop.Run(); | 536 run_loop.Run(); |
530 } | 537 } |
531 | 538 |
532 EXPECT_EQ(HTTP_SUCCESS, error); | 539 EXPECT_EQ(HTTP_SUCCESS, error); |
533 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); | 540 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); |
534 EXPECT_EQ("/drive/v2/files/resource_id" | 541 EXPECT_EQ("/drive/v2/files/resource_id" |
535 "?setModifiedDate=true&updateViewedDate=false", | 542 "?setModifiedDate=true&updateViewedDate=false", |
536 http_request_.relative_url); | 543 http_request_.relative_url); |
537 | 544 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
957 new drive::InitiateUploadNewFileRequest( | 964 new drive::InitiateUploadNewFileRequest( |
958 request_sender_.get(), | 965 request_sender_.get(), |
959 *url_generator_, | 966 *url_generator_, |
960 kTestContentType, | 967 kTestContentType, |
961 kTestContent.size(), | 968 kTestContent.size(), |
962 "parent_resource_id", // The resource id of the parent directory. | 969 "parent_resource_id", // The resource id of the parent directory. |
963 "new file title", // The title of the file being uploaded. | 970 "new file title", // The title of the file being uploaded. |
964 test_util::CreateQuitCallback( | 971 test_util::CreateQuitCallback( |
965 &run_loop, | 972 &run_loop, |
966 test_util::CreateCopyResultCallback(&error, &upload_url))); | 973 test_util::CreateCopyResultCallback(&error, &upload_url))); |
974 request->set_properties(testing_properties_); | |
967 request_sender_->StartRequestWithRetry(request); | 975 request_sender_->StartRequestWithRetry(request); |
968 run_loop.Run(); | 976 run_loop.Run(); |
969 } | 977 } |
970 | 978 |
971 EXPECT_EQ(HTTP_SUCCESS, error); | 979 EXPECT_EQ(HTTP_SUCCESS, error); |
972 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); | 980 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); |
973 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 981 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
974 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 982 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
975 http_request_.headers["X-Upload-Content-Length"]); | 983 http_request_.headers["X-Upload-Content-Length"]); |
976 | 984 |
977 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 985 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
978 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", | 986 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", |
979 http_request_.relative_url); | 987 http_request_.relative_url); |
980 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 988 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
981 EXPECT_TRUE(http_request_.has_content); | 989 EXPECT_TRUE(http_request_.has_content); |
982 EXPECT_EQ("{\"parents\":[{" | 990 EXPECT_EQ( |
983 "\"id\":\"parent_resource_id\"," | 991 "{\"parents\":[{" |
984 "\"kind\":\"drive#fileLink\"" | 992 "\"id\":\"parent_resource_id\"," |
985 "}]," | 993 "\"kind\":\"drive#fileLink\"" |
986 "\"title\":\"new file title\"}", | 994 "}]," |
987 http_request_.content); | 995 "\"properties\":[" |
996 "{\"key\":\"key1\",\"value\":\"value1\",\"visibility\":\"PRIVATE\"}," | |
997 "{\"key\":\"key2\",\"value\":\"value2\",\"visibility\":\"PUBLIC\"}]," | |
998 "\"title\":\"new file title\"}", | |
999 http_request_.content); | |
988 | 1000 |
989 // Upload the content to the upload URL. | 1001 // Upload the content to the upload URL. |
990 UploadRangeResponse response; | 1002 UploadRangeResponse response; |
991 scoped_ptr<FileResource> new_entry; | 1003 scoped_ptr<FileResource> new_entry; |
992 | 1004 |
993 { | 1005 { |
994 base::RunLoop run_loop; | 1006 base::RunLoop run_loop; |
995 drive::ResumeUploadRequest* resume_request = | 1007 drive::ResumeUploadRequest* resume_request = |
996 new drive::ResumeUploadRequest( | 1008 new drive::ResumeUploadRequest( |
997 request_sender_.get(), | 1009 request_sender_.get(), |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1370 new drive::InitiateUploadExistingFileRequest( | 1382 new drive::InitiateUploadExistingFileRequest( |
1371 request_sender_.get(), | 1383 request_sender_.get(), |
1372 *url_generator_, | 1384 *url_generator_, |
1373 kTestContentType, | 1385 kTestContentType, |
1374 kTestContent.size(), | 1386 kTestContent.size(), |
1375 "resource_id", // The resource id of the file to be overwritten. | 1387 "resource_id", // The resource id of the file to be overwritten. |
1376 std::string(), // No etag. | 1388 std::string(), // No etag. |
1377 test_util::CreateQuitCallback( | 1389 test_util::CreateQuitCallback( |
1378 &run_loop, | 1390 &run_loop, |
1379 test_util::CreateCopyResultCallback(&error, &upload_url))); | 1391 test_util::CreateCopyResultCallback(&error, &upload_url))); |
1392 request->set_properties(testing_properties_); | |
1380 request_sender_->StartRequestWithRetry(request); | 1393 request_sender_->StartRequestWithRetry(request); |
1381 run_loop.Run(); | 1394 run_loop.Run(); |
1382 } | 1395 } |
1383 | 1396 |
1384 EXPECT_EQ(HTTP_SUCCESS, error); | 1397 EXPECT_EQ(HTTP_SUCCESS, error); |
1385 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); | 1398 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); |
1386 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 1399 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
1387 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 1400 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
1388 http_request_.headers["X-Upload-Content-Length"]); | 1401 http_request_.headers["X-Upload-Content-Length"]); |
1389 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 1402 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
1390 | 1403 |
1391 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1404 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1392 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", | 1405 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", |
1393 http_request_.relative_url); | 1406 http_request_.relative_url); |
1394 EXPECT_TRUE(http_request_.has_content); | 1407 EXPECT_TRUE(http_request_.has_content); |
1395 EXPECT_TRUE(http_request_.content.empty()); | 1408 EXPECT_EQ( |
1409 "{\"properties\":[" | |
1410 "{\"key\":\"key1\",\"value\":\"value1\",\"visibility\":\"PRIVATE\"}," | |
1411 "{\"key\":\"key2\",\"value\":\"value2\",\"visibility\":\"PUBLIC\"}]}", | |
1412 http_request_.content); | |
1396 | 1413 |
1397 // Upload the content to the upload URL. | 1414 // Upload the content to the upload URL. |
1398 UploadRangeResponse response; | 1415 UploadRangeResponse response; |
1399 scoped_ptr<FileResource> new_entry; | 1416 scoped_ptr<FileResource> new_entry; |
1400 | 1417 |
1401 { | 1418 { |
1402 base::RunLoop run_loop; | 1419 base::RunLoop run_loop; |
1403 drive::ResumeUploadRequest* resume_request = | 1420 drive::ResumeUploadRequest* resume_request = |
1404 new drive::ResumeUploadRequest( | 1421 new drive::ResumeUploadRequest( |
1405 request_sender_.get(), | 1422 request_sender_.get(), |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1863 expected.reset(base::JSONReader::Read( | 1880 expected.reset(base::JSONReader::Read( |
1864 "{\"role\":\"writer\", \"type\":\"domain\",\"value\":\"example.com\"}")); | 1881 "{\"role\":\"writer\", \"type\":\"domain\",\"value\":\"example.com\"}")); |
1865 ASSERT_TRUE(expected); | 1882 ASSERT_TRUE(expected); |
1866 | 1883 |
1867 result.reset(base::JSONReader::Read(http_request_.content)); | 1884 result.reset(base::JSONReader::Read(http_request_.content)); |
1868 EXPECT_TRUE(http_request_.has_content); | 1885 EXPECT_TRUE(http_request_.has_content); |
1869 EXPECT_TRUE(base::Value::Equals(expected.get(), result.get())); | 1886 EXPECT_TRUE(base::Value::Equals(expected.get(), result.get())); |
1870 } | 1887 } |
1871 | 1888 |
1872 } // namespace google_apis | 1889 } // namespace google_apis |
OLD | NEW |