| 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 "components/sync/engine_impl/attachments/attachment_uploader_impl.h" | 5 #include "components/sync/engine_impl/attachments/attachment_uploader_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 15 #include "base/memory/ref_counted_memory.h" |
| 15 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 16 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 21 #include "base/test/histogram_tester.h" | 22 #include "base/test/histogram_tester.h" |
| 22 #include "base/threading/thread.h" | 23 #include "base/threading/thread.h" |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 AttachmentUploaderImplTest::AttachmentUploaderImplTest() | 265 AttachmentUploaderImplTest::AttachmentUploaderImplTest() |
| 265 : weak_ptr_factory_(this) {} | 266 : weak_ptr_factory_(this) {} |
| 266 | 267 |
| 267 void AttachmentUploaderImplTest::OnRequestReceived(const HttpRequest& request) { | 268 void AttachmentUploaderImplTest::OnRequestReceived(const HttpRequest& request) { |
| 268 DCHECK(CalledOnValidThread()); | 269 DCHECK(CalledOnValidThread()); |
| 269 http_requests_received_.push_back(request); | 270 http_requests_received_.push_back(request); |
| 270 } | 271 } |
| 271 | 272 |
| 272 void AttachmentUploaderImplTest::SetUp() { | 273 void AttachmentUploaderImplTest::SetUp() { |
| 273 DCHECK(CalledOnValidThread()); | 274 DCHECK(CalledOnValidThread()); |
| 274 request_handler_.reset(new RequestHandler(message_loop_.task_runner(), | 275 request_handler_ = base::MakeUnique<RequestHandler>( |
| 275 weak_ptr_factory_.GetWeakPtr())); | 276 message_loop_.task_runner(), weak_ptr_factory_.GetWeakPtr()); |
| 276 url_request_context_getter_ = | 277 url_request_context_getter_ = |
| 277 new net::TestURLRequestContextGetter(message_loop_.task_runner()); | 278 new net::TestURLRequestContextGetter(message_loop_.task_runner()); |
| 278 | 279 |
| 279 ASSERT_TRUE(server_.Start()); | 280 ASSERT_TRUE(server_.Start()); |
| 280 server_.RegisterRequestHandler( | 281 server_.RegisterRequestHandler( |
| 281 base::Bind(&RequestHandler::HandleRequest, | 282 base::Bind(&RequestHandler::HandleRequest, |
| 282 base::Unretained(request_handler_.get()))); | 283 base::Unretained(request_handler_.get()))); |
| 283 | 284 |
| 284 GURL url(base::StringPrintf("http://localhost:%u/", server_.port())); | 285 GURL url(base::StringPrintf("http://localhost:%u/", server_.port())); |
| 285 | 286 |
| 286 token_service_.reset(new MockOAuth2TokenService); | 287 token_service_ = base::MakeUnique<MockOAuth2TokenService>(); |
| 287 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> | 288 scoped_refptr<OAuth2TokenServiceRequest::TokenServiceProvider> |
| 288 token_service_provider(new TokenServiceProvider(token_service_.get())); | 289 token_service_provider(new TokenServiceProvider(token_service_.get())); |
| 289 | 290 |
| 290 OAuth2TokenService::ScopeSet scopes; | 291 OAuth2TokenService::ScopeSet scopes; |
| 291 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); | 292 scopes.insert(GaiaConstants::kChromeSyncOAuth2Scope); |
| 292 uploader().reset(new AttachmentUploaderImpl( | 293 uploader() = base::MakeUnique<AttachmentUploaderImpl>( |
| 293 url, url_request_context_getter_, kAccountId, scopes, | 294 url, url_request_context_getter_, kAccountId, scopes, |
| 294 token_service_provider, std::string(kStoreBirthday), kModelType)); | 295 token_service_provider, std::string(kStoreBirthday), kModelType); |
| 295 | 296 |
| 296 upload_callback_ = base::Bind(&AttachmentUploaderImplTest::UploadDone, | 297 upload_callback_ = base::Bind(&AttachmentUploaderImplTest::UploadDone, |
| 297 base::Unretained(this)); | 298 base::Unretained(this)); |
| 298 } | 299 } |
| 299 | 300 |
| 300 void AttachmentUploaderImplTest::TearDown() { | 301 void AttachmentUploaderImplTest::TearDown() { |
| 301 base::RunLoop().RunUntilIdle(); | 302 base::RunLoop().RunUntilIdle(); |
| 302 } | 303 } |
| 303 | 304 |
| 304 void AttachmentUploaderImplTest::RunAndWaitFor(int num_uploads) { | 305 void AttachmentUploaderImplTest::RunAndWaitFor(int num_uploads) { |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); | 664 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); |
| 664 hello_world->data() = "hello world"; | 665 hello_world->data() = "hello world"; |
| 665 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash( | 666 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash( |
| 666 ComputeCrc32c(hello_world))); | 667 ComputeCrc32c(hello_world))); |
| 667 } | 668 } |
| 668 | 669 |
| 669 // TODO(maniscalco): Add test case for when we are uploading an attachment that | 670 // TODO(maniscalco): Add test case for when we are uploading an attachment that |
| 670 // already exists. 409 Conflict? (bug 379825) | 671 // already exists. 409 Conflict? (bug 379825) |
| 671 | 672 |
| 672 } // namespace syncer | 673 } // namespace syncer |
| OLD | NEW |