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" | |
6 | |
7 #include <string> | 5 #include <string> |
6 #include <utility> | |
8 #include <vector> | 7 #include <vector> |
9 | 8 |
10 #include "base/bind.h" | 9 #include "base/bind.h" |
11 #include "base/callback.h" | 10 #include "base/callback.h" |
12 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
13 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
14 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
15 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
16 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
18 #include "base/synchronization/lock.h" | 17 #include "base/synchronization/lock.h" |
19 #include "base/test/histogram_tester.h" | 18 #include "base/test/histogram_tester.h" |
20 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
21 #include "base/threading/non_thread_safe.h" | 20 #include "base/threading/non_thread_safe.h" |
22 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
23 #include "google_apis/gaia/fake_oauth2_token_service.h" | 22 #include "google_apis/gaia/fake_oauth2_token_service.h" |
24 #include "google_apis/gaia/gaia_constants.h" | 23 #include "google_apis/gaia/gaia_constants.h" |
25 #include "google_apis/gaia/oauth2_token_service_request.h" | 24 #include "google_apis/gaia/oauth2_token_service_request.h" |
26 #include "net/http/http_status_code.h" | 25 #include "net/http/http_status_code.h" |
27 #include "net/test/embedded_test_server/embedded_test_server.h" | 26 #include "net/test/embedded_test_server/embedded_test_server.h" |
28 #include "net/test/embedded_test_server/http_request.h" | 27 #include "net/test/embedded_test_server/http_request.h" |
29 #include "net/test/embedded_test_server/http_response.h" | 28 #include "net/test/embedded_test_server/http_response.h" |
30 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
31 #include "sync/api/attachments/attachment.h" | 30 #include "sync/api/attachments/attachment.h" |
31 #include "sync/internal_api/public/attachments/attachment_uploader_impl.h" | |
Nicolas Zea
2015/12/18 23:46:54
keep up top
| |
32 #include "sync/internal_api/public/attachments/attachment_util.h" | 32 #include "sync/internal_api/public/attachments/attachment_util.h" |
33 #include "sync/internal_api/public/base/model_type.h" | 33 #include "sync/internal_api/public/base/model_type.h" |
34 #include "sync/protocol/sync.pb.h" | 34 #include "sync/protocol/sync.pb.h" |
35 #include "testing/gmock/include/gmock/gmock-matchers.h" | 35 #include "testing/gmock/include/gmock/gmock-matchers.h" |
36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 const char kAttachmentData[] = "some data"; | 40 const char kAttachmentData[] = "some data"; |
41 const char kAccountId[] = "some-account-id"; | 41 const char kAccountId[] = "some-account-id"; |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 scoped_ptr<HttpResponse> RequestHandler::HandleRequest( | 390 scoped_ptr<HttpResponse> RequestHandler::HandleRequest( |
391 const HttpRequest& request) { | 391 const HttpRequest& request) { |
392 DCHECK(CalledOnValidThread()); | 392 DCHECK(CalledOnValidThread()); |
393 test_task_runner_->PostTask( | 393 test_task_runner_->PostTask( |
394 FROM_HERE, | 394 FROM_HERE, |
395 base::Bind( | 395 base::Bind( |
396 &AttachmentUploaderImplTest::OnRequestReceived, test_, request)); | 396 &AttachmentUploaderImplTest::OnRequestReceived, test_, request)); |
397 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse); | 397 scoped_ptr<BasicHttpResponse> response(new BasicHttpResponse); |
398 response->set_code(GetStatusCode()); | 398 response->set_code(GetStatusCode()); |
399 response->set_content_type("text/plain"); | 399 response->set_content_type("text/plain"); |
400 return response.Pass(); | 400 return std::move(response); |
401 } | 401 } |
402 | 402 |
403 void RequestHandler::SetStatusCode(const net::HttpStatusCode& status_code) { | 403 void RequestHandler::SetStatusCode(const net::HttpStatusCode& status_code) { |
404 base::AutoLock lock(mutex_); | 404 base::AutoLock lock(mutex_); |
405 status_code_ = status_code; | 405 status_code_ = status_code; |
406 } | 406 } |
407 | 407 |
408 net::HttpStatusCode RequestHandler::GetStatusCode() const { | 408 net::HttpStatusCode RequestHandler::GetStatusCode() const { |
409 base::AutoLock lock(mutex_); | 409 base::AutoLock lock(mutex_); |
410 return status_code_; | 410 return status_code_; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
673 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); | 673 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); |
674 hello_world->data() = "hello world"; | 674 hello_world->data() = "hello world"; |
675 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash( | 675 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash( |
676 ComputeCrc32c(hello_world))); | 676 ComputeCrc32c(hello_world))); |
677 } | 677 } |
678 | 678 |
679 // TODO(maniscalco): Add test case for when we are uploading an attachment that | 679 // TODO(maniscalco): Add test case for when we are uploading an attachment that |
680 // already exists. 409 Conflict? (bug 379825) | 680 // already exists. 409 Conflict? (bug 379825) |
681 | 681 |
682 } // namespace syncer | 682 } // namespace syncer |
OLD | NEW |