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 25 matching lines...) Expand all Loading... |
36 url_(url) { | 36 url_(url) { |
37 } | 37 } |
38 | 38 |
39 ~FakeUrlFetchRequest() override {} | 39 ~FakeUrlFetchRequest() override {} |
40 | 40 |
41 protected: | 41 protected: |
42 GURL GetURL() const override { return url_; } | 42 GURL GetURL() const override { return url_; } |
43 void ProcessURLFetchResults(const net::URLFetcher* source) override { | 43 void ProcessURLFetchResults(const net::URLFetcher* source) override { |
44 callback_.Run(GetErrorCode()); | 44 callback_.Run(GetErrorCode()); |
45 } | 45 } |
46 void RunCallbackOnPrematureFailure(GDataErrorCode code) override { | 46 void RunCallbackOnPrematureFailure(DriveApiErrorCode code) override { |
47 callback_.Run(code); | 47 callback_.Run(code); |
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( |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 " \"domain\": \"usageLimits\",\n" | 171 " \"domain\": \"usageLimits\",\n" |
172 " \"reason\": \"rateLimitExceeded\",\n" | 172 " \"reason\": \"rateLimitExceeded\",\n" |
173 " \"message\": \"Rate Limit Exceeded\"\n" | 173 " \"message\": \"Rate Limit Exceeded\"\n" |
174 " }\n" | 174 " }\n" |
175 " ],\n" | 175 " ],\n" |
176 " \"code\": 403,\n" | 176 " \"code\": 403,\n" |
177 " \"message\": \"Rate Limit Exceeded\"\n" | 177 " \"message\": \"Rate Limit Exceeded\"\n" |
178 " }\n" | 178 " }\n" |
179 "}\n"; | 179 "}\n"; |
180 | 180 |
181 GDataErrorCode error = GDATA_OTHER_ERROR; | 181 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
182 base::RunLoop run_loop; | 182 base::RunLoop run_loop; |
183 sender_->StartRequestWithRetry( | 183 sender_->StartRequestWithRetry( |
184 new FakeUrlFetchRequest( | 184 new FakeUrlFetchRequest( |
185 sender_.get(), | 185 sender_.get(), |
186 test_util::CreateQuitCallback( | 186 test_util::CreateQuitCallback( |
187 &run_loop, test_util::CreateCopyResultCallback(&error)), | 187 &run_loop, test_util::CreateCopyResultCallback(&error)), |
188 test_server_.base_url())); | 188 test_server_.base_url())); |
189 run_loop.Run(); | 189 run_loop.Run(); |
190 | 190 |
191 // HTTP_FORBIDDEN (403) is overridden by the error reason. | 191 // HTTP_FORBIDDEN (403) is overridden by the error reason. |
192 EXPECT_EQ(HTTP_SERVICE_UNAVAILABLE, error); | 192 EXPECT_EQ(HTTP_SERVICE_UNAVAILABLE, error); |
193 } | 193 } |
194 | 194 |
195 TEST_F(MultipartUploadRequestBaseTest, Basic) { | 195 TEST_F(MultipartUploadRequestBaseTest, Basic) { |
196 response_code_ = net::HTTP_OK; | 196 response_code_ = net::HTTP_OK; |
197 response_body_ = "{\"kind\": \"drive#file\", \"id\": \"file_id\"}"; | 197 response_body_ = "{\"kind\": \"drive#file\", \"id\": \"file_id\"}"; |
198 scoped_ptr<google_apis::FileResource> file; | 198 scoped_ptr<google_apis::FileResource> file; |
199 GDataErrorCode error = GDATA_OTHER_ERROR; | 199 DriveApiErrorCode error = DRIVE_OTHER_ERROR; |
200 base::RunLoop run_loop; | 200 base::RunLoop run_loop; |
201 const base::FilePath source_path = | 201 const base::FilePath source_path = |
202 google_apis::test_util::GetTestFilePath("chromeos/file_manager/text.txt"); | 202 google_apis::test_util::GetTestFilePath("chromeos/file_manager/text.txt"); |
203 std::string upload_content_type; | 203 std::string upload_content_type; |
204 std::string upload_content_data; | 204 std::string upload_content_data; |
205 scoped_ptr<FakeMultipartUploadRequest> request(new FakeMultipartUploadRequest( | 205 scoped_ptr<FakeMultipartUploadRequest> request(new FakeMultipartUploadRequest( |
206 sender_.get(), "test.txt", "parent_id", "text/plain", 10, base::Time(), | 206 sender_.get(), "test.txt", "parent_id", "text/plain", 10, base::Time(), |
207 base::Time(), source_path, | 207 base::Time(), source_path, |
208 test_util::CreateQuitCallback( | 208 test_util::CreateQuitCallback( |
209 &run_loop, test_util::CreateCopyResultCallback(&error, &file)), | 209 &run_loop, test_util::CreateCopyResultCallback(&error, &file)), |
(...skipping 14 matching lines...) Expand all Loading... |
224 "\n" | 224 "\n" |
225 "This is a sample file. I like chocolate and chips.\n" | 225 "This is a sample file. I like chocolate and chips.\n" |
226 "\n" | 226 "\n" |
227 "--TESTBOUNDARY--", | 227 "--TESTBOUNDARY--", |
228 upload_content_data); | 228 upload_content_data); |
229 ASSERT_EQ(HTTP_SUCCESS, error); | 229 ASSERT_EQ(HTTP_SUCCESS, error); |
230 EXPECT_EQ("file_id", file->file_id()); | 230 EXPECT_EQ("file_id", file->file_id()); |
231 } | 231 } |
232 | 232 |
233 } // Namespace google_apis | 233 } // Namespace google_apis |
OLD | NEW |