OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "sync/internal_api/public/attachments/attachment_uploader_impl.h" | 5 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 private: | 217 private: |
218 // An UploadCallback invoked by AttachmentUploaderImpl. | 218 // An UploadCallback invoked by AttachmentUploaderImpl. |
219 void UploadDone(const AttachmentUploader::UploadResult& result, | 219 void UploadDone(const AttachmentUploader::UploadResult& result, |
220 const AttachmentId& attachment_id); | 220 const AttachmentId& attachment_id); |
221 | 221 |
222 base::MessageLoopForIO message_loop_; | 222 base::MessageLoopForIO message_loop_; |
223 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | 223 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; |
224 scoped_ptr<RequestHandler> request_handler_; | 224 scoped_ptr<RequestHandler> request_handler_; |
225 scoped_ptr<AttachmentUploader> uploader_; | 225 scoped_ptr<AttachmentUploader> uploader_; |
226 AttachmentUploader::UploadCallback upload_callback_; | 226 AttachmentUploader::UploadCallback upload_callback_; |
227 net::test_server::EmbeddedTestServer server_; | 227 net::EmbeddedTestServer server_; |
228 // A closure that signals an upload has finished. | 228 // A closure that signals an upload has finished. |
229 base::Closure signal_upload_done_; | 229 base::Closure signal_upload_done_; |
230 std::vector<HttpRequest> http_requests_received_; | 230 std::vector<HttpRequest> http_requests_received_; |
231 std::vector<AttachmentUploader::UploadResult> upload_results_; | 231 std::vector<AttachmentUploader::UploadResult> upload_results_; |
232 std::vector<AttachmentId> attachment_ids_; | 232 std::vector<AttachmentId> attachment_ids_; |
233 scoped_ptr<MockOAuth2TokenService> token_service_; | 233 scoped_ptr<MockOAuth2TokenService> token_service_; |
234 | 234 |
235 // Must be last data member. | 235 // Must be last data member. |
236 base::WeakPtrFactory<AttachmentUploaderImplTest> weak_ptr_factory_; | 236 base::WeakPtrFactory<AttachmentUploaderImplTest> weak_ptr_factory_; |
237 }; | 237 }; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 http_requests_received_.push_back(request); | 275 http_requests_received_.push_back(request); |
276 } | 276 } |
277 | 277 |
278 void AttachmentUploaderImplTest::SetUp() { | 278 void AttachmentUploaderImplTest::SetUp() { |
279 DCHECK(CalledOnValidThread()); | 279 DCHECK(CalledOnValidThread()); |
280 request_handler_.reset(new RequestHandler(message_loop_.task_runner(), | 280 request_handler_.reset(new RequestHandler(message_loop_.task_runner(), |
281 weak_ptr_factory_.GetWeakPtr())); | 281 weak_ptr_factory_.GetWeakPtr())); |
282 url_request_context_getter_ = | 282 url_request_context_getter_ = |
283 new net::TestURLRequestContextGetter(message_loop_.task_runner()); | 283 new net::TestURLRequestContextGetter(message_loop_.task_runner()); |
284 | 284 |
285 ASSERT_TRUE(server_.InitializeAndWaitUntilReady()); | 285 ASSERT_TRUE(server_.Start()); |
286 server_.RegisterRequestHandler( | 286 server_.RegisterRequestHandler( |
287 base::Bind(&RequestHandler::HandleRequest, | 287 base::Bind(&RequestHandler::HandleRequest, |
288 base::Unretained(request_handler_.get()))); | 288 base::Unretained(request_handler_.get()))); |
289 | 289 |
290 GURL url(base::StringPrintf("http://localhost:%u/", server_.port())); | 290 GURL url(base::StringPrintf("http://localhost:%u/", server_.port())); |
291 | 291 |
292 token_service_.reset(new MockOAuth2TokenService); | 292 token_service_.reset(new MockOAuth2TokenService); |
293 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> | 293 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> |
294 token_service_provider(new TokenServiceProvider(token_service_.get())); | 294 token_service_provider(new TokenServiceProvider(token_service_.get())); |
295 | 295 |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); | 671 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); |
672 hello_world->data() = "hello world"; | 672 hello_world->data() = "hello world"; |
673 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash( | 673 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash( |
674 ComputeCrc32c(hello_world))); | 674 ComputeCrc32c(hello_world))); |
675 } | 675 } |
676 | 676 |
677 // TODO(maniscalco): Add test case for when we are uploading an attachment that | 677 // TODO(maniscalco): Add test case for when we are uploading an attachment that |
678 // already exists. 409 Conflict? (bug 379825) | 678 // already exists. 409 Conflict? (bug 379825) |
679 | 679 |
680 } // namespace syncer | 680 } // namespace syncer |
OLD | NEW |