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); |
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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 request->set_file_id("resource_id"); | 519 request->set_file_id("resource_id"); |
505 request->set_set_modified_date(true); | 520 request->set_set_modified_date(true); |
506 request->set_update_viewed_date(false); | 521 request->set_update_viewed_date(false); |
507 | 522 |
508 request->set_title("new title"); | 523 request->set_title("new title"); |
509 request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate)); | 524 request->set_modified_date(base::Time::FromUTCExploded(kModifiedDate)); |
510 request->set_last_viewed_by_me_date( | 525 request->set_last_viewed_by_me_date( |
511 base::Time::FromUTCExploded(kLastViewedByMeDate)); | 526 base::Time::FromUTCExploded(kLastViewedByMeDate)); |
512 request->add_parent("parent_resource_id"); | 527 request->add_parent("parent_resource_id"); |
513 | 528 |
514 drive::Property private_property; | 529 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); | 530 request_sender_->StartRequestWithRetry(request); |
529 run_loop.Run(); | 531 run_loop.Run(); |
530 } | 532 } |
531 | 533 |
532 EXPECT_EQ(HTTP_SUCCESS, error); | 534 EXPECT_EQ(HTTP_SUCCESS, error); |
533 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); | 535 EXPECT_EQ(net::test_server::METHOD_PATCH, http_request_.method); |
534 EXPECT_EQ("/drive/v2/files/resource_id" | 536 EXPECT_EQ("/drive/v2/files/resource_id" |
535 "?setModifiedDate=true&updateViewedDate=false", | 537 "?setModifiedDate=true&updateViewedDate=false", |
536 http_request_.relative_url); | 538 http_request_.relative_url); |
537 | 539 |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 new drive::InitiateUploadNewFileRequest( | 959 new drive::InitiateUploadNewFileRequest( |
958 request_sender_.get(), | 960 request_sender_.get(), |
959 *url_generator_, | 961 *url_generator_, |
960 kTestContentType, | 962 kTestContentType, |
961 kTestContent.size(), | 963 kTestContent.size(), |
962 "parent_resource_id", // The resource id of the parent directory. | 964 "parent_resource_id", // The resource id of the parent directory. |
963 "new file title", // The title of the file being uploaded. | 965 "new file title", // The title of the file being uploaded. |
964 test_util::CreateQuitCallback( | 966 test_util::CreateQuitCallback( |
965 &run_loop, | 967 &run_loop, |
966 test_util::CreateCopyResultCallback(&error, &upload_url))); | 968 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 969 request->set_properties(testing_properties_); |
967 request_sender_->StartRequestWithRetry(request); | 970 request_sender_->StartRequestWithRetry(request); |
968 run_loop.Run(); | 971 run_loop.Run(); |
969 } | 972 } |
970 | 973 |
971 EXPECT_EQ(HTTP_SUCCESS, error); | 974 EXPECT_EQ(HTTP_SUCCESS, error); |
972 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); | 975 EXPECT_EQ(kTestUploadNewFilePath, upload_url.path()); |
973 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 976 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
974 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 977 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
975 http_request_.headers["X-Upload-Content-Length"]); | 978 http_request_.headers["X-Upload-Content-Length"]); |
976 | 979 |
977 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); | 980 EXPECT_EQ(net::test_server::METHOD_POST, http_request_.method); |
978 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", | 981 EXPECT_EQ("/upload/drive/v2/files?uploadType=resumable", |
979 http_request_.relative_url); | 982 http_request_.relative_url); |
980 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); | 983 EXPECT_EQ("application/json", http_request_.headers["Content-Type"]); |
981 EXPECT_TRUE(http_request_.has_content); | 984 EXPECT_TRUE(http_request_.has_content); |
982 EXPECT_EQ("{\"parents\":[{" | 985 EXPECT_EQ( |
983 "\"id\":\"parent_resource_id\"," | 986 "{\"parents\":[{" |
984 "\"kind\":\"drive#fileLink\"" | 987 "\"id\":\"parent_resource_id\"," |
985 "}]," | 988 "\"kind\":\"drive#fileLink\"" |
986 "\"title\":\"new file title\"}", | 989 "}]," |
987 http_request_.content); | 990 "\"properties\":[" |
| 991 "{\"key\":\"key1\",\"value\":\"value1\",\"visibility\":\"PRIVATE\"}," |
| 992 "{\"key\":\"key2\",\"value\":\"value2\",\"visibility\":\"PUBLIC\"}]," |
| 993 "\"title\":\"new file title\"}", |
| 994 http_request_.content); |
988 | 995 |
989 // Upload the content to the upload URL. | 996 // Upload the content to the upload URL. |
990 UploadRangeResponse response; | 997 UploadRangeResponse response; |
991 scoped_ptr<FileResource> new_entry; | 998 scoped_ptr<FileResource> new_entry; |
992 | 999 |
993 { | 1000 { |
994 base::RunLoop run_loop; | 1001 base::RunLoop run_loop; |
995 drive::ResumeUploadRequest* resume_request = | 1002 drive::ResumeUploadRequest* resume_request = |
996 new drive::ResumeUploadRequest( | 1003 new drive::ResumeUploadRequest( |
997 request_sender_.get(), | 1004 request_sender_.get(), |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 new drive::InitiateUploadExistingFileRequest( | 1377 new drive::InitiateUploadExistingFileRequest( |
1371 request_sender_.get(), | 1378 request_sender_.get(), |
1372 *url_generator_, | 1379 *url_generator_, |
1373 kTestContentType, | 1380 kTestContentType, |
1374 kTestContent.size(), | 1381 kTestContent.size(), |
1375 "resource_id", // The resource id of the file to be overwritten. | 1382 "resource_id", // The resource id of the file to be overwritten. |
1376 std::string(), // No etag. | 1383 std::string(), // No etag. |
1377 test_util::CreateQuitCallback( | 1384 test_util::CreateQuitCallback( |
1378 &run_loop, | 1385 &run_loop, |
1379 test_util::CreateCopyResultCallback(&error, &upload_url))); | 1386 test_util::CreateCopyResultCallback(&error, &upload_url))); |
| 1387 request->set_properties(testing_properties_); |
1380 request_sender_->StartRequestWithRetry(request); | 1388 request_sender_->StartRequestWithRetry(request); |
1381 run_loop.Run(); | 1389 run_loop.Run(); |
1382 } | 1390 } |
1383 | 1391 |
1384 EXPECT_EQ(HTTP_SUCCESS, error); | 1392 EXPECT_EQ(HTTP_SUCCESS, error); |
1385 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); | 1393 EXPECT_EQ(kTestUploadExistingFilePath, upload_url.path()); |
1386 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); | 1394 EXPECT_EQ(kTestContentType, http_request_.headers["X-Upload-Content-Type"]); |
1387 EXPECT_EQ(base::Int64ToString(kTestContent.size()), | 1395 EXPECT_EQ(base::Int64ToString(kTestContent.size()), |
1388 http_request_.headers["X-Upload-Content-Length"]); | 1396 http_request_.headers["X-Upload-Content-Length"]); |
1389 EXPECT_EQ("*", http_request_.headers["If-Match"]); | 1397 EXPECT_EQ("*", http_request_.headers["If-Match"]); |
1390 | 1398 |
1391 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); | 1399 EXPECT_EQ(net::test_server::METHOD_PUT, http_request_.method); |
1392 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", | 1400 EXPECT_EQ("/upload/drive/v2/files/resource_id?uploadType=resumable", |
1393 http_request_.relative_url); | 1401 http_request_.relative_url); |
1394 EXPECT_TRUE(http_request_.has_content); | 1402 EXPECT_TRUE(http_request_.has_content); |
1395 EXPECT_TRUE(http_request_.content.empty()); | 1403 EXPECT_EQ( |
| 1404 "{\"properties\":[" |
| 1405 "{\"key\":\"key1\",\"value\":\"value1\",\"visibility\":\"PRIVATE\"}," |
| 1406 "{\"key\":\"key2\",\"value\":\"value2\",\"visibility\":\"PUBLIC\"}]}", |
| 1407 http_request_.content); |
1396 | 1408 |
1397 // Upload the content to the upload URL. | 1409 // Upload the content to the upload URL. |
1398 UploadRangeResponse response; | 1410 UploadRangeResponse response; |
1399 scoped_ptr<FileResource> new_entry; | 1411 scoped_ptr<FileResource> new_entry; |
1400 | 1412 |
1401 { | 1413 { |
1402 base::RunLoop run_loop; | 1414 base::RunLoop run_loop; |
1403 drive::ResumeUploadRequest* resume_request = | 1415 drive::ResumeUploadRequest* resume_request = |
1404 new drive::ResumeUploadRequest( | 1416 new drive::ResumeUploadRequest( |
1405 request_sender_.get(), | 1417 request_sender_.get(), |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 expected.reset(base::JSONReader::Read( | 1875 expected.reset(base::JSONReader::Read( |
1864 "{\"role\":\"writer\", \"type\":\"domain\",\"value\":\"example.com\"}")); | 1876 "{\"role\":\"writer\", \"type\":\"domain\",\"value\":\"example.com\"}")); |
1865 ASSERT_TRUE(expected); | 1877 ASSERT_TRUE(expected); |
1866 | 1878 |
1867 result.reset(base::JSONReader::Read(http_request_.content)); | 1879 result.reset(base::JSONReader::Read(http_request_.content)); |
1868 EXPECT_TRUE(http_request_.has_content); | 1880 EXPECT_TRUE(http_request_.has_content); |
1869 EXPECT_TRUE(base::Value::Equals(expected.get(), result.get())); | 1881 EXPECT_TRUE(base::Value::Equals(expected.get(), result.get())); |
1870 } | 1882 } |
1871 | 1883 |
1872 } // namespace google_apis | 1884 } // namespace google_apis |
OLD | NEW |