OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "google_apis/drive/base_requests.h" | 5 #include "google_apis/drive/base_requests.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 } | 48 } |
49 | 49 |
50 EntryActionCallback callback_; | 50 EntryActionCallback callback_; |
51 GURL url_; | 51 GURL url_; |
52 }; | 52 }; |
53 | 53 |
54 class FakeMultipartUploadRequest : public MultipartUploadRequestBase { | 54 class FakeMultipartUploadRequest : public MultipartUploadRequestBase { |
55 public: | 55 public: |
56 FakeMultipartUploadRequest( | 56 FakeMultipartUploadRequest( |
57 RequestSender* sender, | 57 RequestSender* sender, |
58 const std::string& title, | 58 const std::string& metadata_json, |
59 const std::string& parent_resource_id, | |
60 const std::string& content_type, | 59 const std::string& content_type, |
61 int64 content_length, | 60 int64 content_length, |
62 const base::Time& modified_date, | |
63 const base::Time& last_viewed_by_me_date, | |
64 const base::FilePath& local_file_path, | 61 const base::FilePath& local_file_path, |
65 const FileResourceCallback& callback, | 62 const FileResourceCallback& callback, |
66 const google_apis::ProgressCallback& progress_callback, | 63 const google_apis::ProgressCallback& progress_callback, |
67 const GURL& url, | 64 const GURL& url, |
68 std::string* upload_content_type, | 65 std::string* upload_content_type, |
69 std::string* upload_content_data) | 66 std::string* upload_content_data) |
70 : MultipartUploadRequestBase(sender, | 67 : MultipartUploadRequestBase(sender, |
71 title, | 68 metadata_json, |
72 parent_resource_id, | |
73 content_type, | 69 content_type, |
74 content_length, | 70 content_length, |
75 modified_date, | |
76 last_viewed_by_me_date, | |
77 local_file_path, | 71 local_file_path, |
78 callback, | 72 callback, |
79 progress_callback), | 73 progress_callback), |
80 url_(url), | 74 url_(url), |
81 upload_content_type_(upload_content_type), | 75 upload_content_type_(upload_content_type), |
82 upload_content_data_(upload_content_data) {} | 76 upload_content_data_(upload_content_data) {} |
83 | 77 |
84 ~FakeMultipartUploadRequest() override {} | 78 ~FakeMultipartUploadRequest() override {} |
85 | 79 |
86 bool GetContentData(std::string* content_type, | 80 bool GetContentData(std::string* content_type, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 response_code_ = net::HTTP_OK; | 190 response_code_ = net::HTTP_OK; |
197 response_body_ = "{\"kind\": \"drive#file\", \"id\": \"file_id\"}"; | 191 response_body_ = "{\"kind\": \"drive#file\", \"id\": \"file_id\"}"; |
198 scoped_ptr<google_apis::FileResource> file; | 192 scoped_ptr<google_apis::FileResource> file; |
199 DriveApiErrorCode error = DRIVE_OTHER_ERROR; | 193 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
200 base::RunLoop run_loop; | 194 base::RunLoop run_loop; |
201 const base::FilePath source_path = | 195 const base::FilePath source_path = |
202 google_apis::test_util::GetTestFilePath("chromeos/file_manager/text.txt"); | 196 google_apis::test_util::GetTestFilePath("chromeos/file_manager/text.txt"); |
203 std::string upload_content_type; | 197 std::string upload_content_type; |
204 std::string upload_content_data; | 198 std::string upload_content_data; |
205 scoped_ptr<FakeMultipartUploadRequest> request(new FakeMultipartUploadRequest( | 199 scoped_ptr<FakeMultipartUploadRequest> request(new FakeMultipartUploadRequest( |
206 sender_.get(), "test.txt", "parent_id", "text/plain", 10, base::Time(), | 200 sender_.get(), "{json:\"test\"}", "text/plain", 10, source_path, |
207 base::Time(), source_path, | |
208 test_util::CreateQuitCallback( | 201 test_util::CreateQuitCallback( |
209 &run_loop, test_util::CreateCopyResultCallback(&error, &file)), | 202 &run_loop, test_util::CreateCopyResultCallback(&error, &file)), |
210 ProgressCallback(), test_server_.base_url(), &upload_content_type, | 203 ProgressCallback(), test_server_.base_url(), &upload_content_type, |
211 &upload_content_data)); | 204 &upload_content_data)); |
212 request->SetBoundaryForTesting("TESTBOUNDARY"); | 205 request->SetBoundaryForTesting("TESTBOUNDARY"); |
213 sender_->StartRequestWithRetry(request.release()); | 206 sender_->StartRequestWithRetry(request.release()); |
214 run_loop.Run(); | 207 run_loop.Run(); |
215 EXPECT_EQ("multipart/related; boundary=TESTBOUNDARY", upload_content_type); | 208 EXPECT_EQ("multipart/related; boundary=TESTBOUNDARY", upload_content_type); |
216 EXPECT_EQ( | 209 EXPECT_EQ( |
217 "--TESTBOUNDARY\n" | 210 "--TESTBOUNDARY\n" |
218 "Content-Type: application/json\n" | 211 "Content-Type: application/json\n" |
219 "\n" | 212 "\n" |
220 "{\"parents\":[{\"id\":\"parent_id\",\"kind\":\"drive#fileLink\"}]," | 213 "{json:\"test\"}\n" |
221 "\"title\":\"test.txt\"}\n" | |
222 "--TESTBOUNDARY\n" | 214 "--TESTBOUNDARY\n" |
223 "Content-Type: text/plain\n" | 215 "Content-Type: text/plain\n" |
224 "\n" | 216 "\n" |
225 "This is a sample file. I like chocolate and chips.\n" | 217 "This is a sample file. I like chocolate and chips.\n" |
226 "\n" | 218 "\n" |
227 "--TESTBOUNDARY--", | 219 "--TESTBOUNDARY--", |
228 upload_content_data); | 220 upload_content_data); |
229 ASSERT_EQ(HTTP_SUCCESS, error); | 221 ASSERT_EQ(HTTP_SUCCESS, error); |
230 EXPECT_EQ("file_id", file->file_id()); | 222 EXPECT_EQ("file_id", file->file_id()); |
231 } | 223 } |
232 | 224 |
233 } // Namespace google_apis | 225 } // Namespace google_apis |
OLD | NEW |