| 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 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 base::AutoLock lock(mutex_); | 402 base::AutoLock lock(mutex_); |
| 403 status_code_ = status_code; | 403 status_code_ = status_code; |
| 404 } | 404 } |
| 405 | 405 |
| 406 net::HttpStatusCode RequestHandler::GetStatusCode() const { | 406 net::HttpStatusCode RequestHandler::GetStatusCode() const { |
| 407 base::AutoLock lock(mutex_); | 407 base::AutoLock lock(mutex_); |
| 408 return status_code_; | 408 return status_code_; |
| 409 } | 409 } |
| 410 | 410 |
| 411 TEST_F(AttachmentUploaderImplTest, GetURLForAttachmentId_NoPath) { | 411 TEST_F(AttachmentUploaderImplTest, GetURLForAttachmentId_NoPath) { |
| 412 AttachmentId id = AttachmentId::Create(); | 412 AttachmentId id = AttachmentId::Create(0, 0); |
| 413 std::string unique_id = id.GetProto().unique_id(); | 413 std::string unique_id = id.GetProto().unique_id(); |
| 414 GURL sync_service_url("https://example.com"); | 414 GURL sync_service_url("https://example.com"); |
| 415 EXPECT_EQ("https://example.com/attachments/" + unique_id, | 415 EXPECT_EQ("https://example.com/attachments/" + unique_id, |
| 416 AttachmentUploaderImpl::GetURLForAttachmentId(sync_service_url, id) | 416 AttachmentUploaderImpl::GetURLForAttachmentId(sync_service_url, id) |
| 417 .spec()); | 417 .spec()); |
| 418 } | 418 } |
| 419 | 419 |
| 420 TEST_F(AttachmentUploaderImplTest, GetURLForAttachmentId_JustSlash) { | 420 TEST_F(AttachmentUploaderImplTest, GetURLForAttachmentId_JustSlash) { |
| 421 AttachmentId id = AttachmentId::Create(); | 421 AttachmentId id = AttachmentId::Create(0, 0); |
| 422 std::string unique_id = id.GetProto().unique_id(); | 422 std::string unique_id = id.GetProto().unique_id(); |
| 423 GURL sync_service_url("https://example.com/"); | 423 GURL sync_service_url("https://example.com/"); |
| 424 EXPECT_EQ("https://example.com/attachments/" + unique_id, | 424 EXPECT_EQ("https://example.com/attachments/" + unique_id, |
| 425 AttachmentUploaderImpl::GetURLForAttachmentId(sync_service_url, id) | 425 AttachmentUploaderImpl::GetURLForAttachmentId(sync_service_url, id) |
| 426 .spec()); | 426 .spec()); |
| 427 } | 427 } |
| 428 | 428 |
| 429 TEST_F(AttachmentUploaderImplTest, GetURLForAttachmentId_Path) { | 429 TEST_F(AttachmentUploaderImplTest, GetURLForAttachmentId_Path) { |
| 430 AttachmentId id = AttachmentId::Create(); | 430 AttachmentId id = AttachmentId::Create(0, 0); |
| 431 std::string unique_id = id.GetProto().unique_id(); | 431 std::string unique_id = id.GetProto().unique_id(); |
| 432 GURL sync_service_url("https://example.com/service"); | 432 GURL sync_service_url("https://example.com/service"); |
| 433 EXPECT_EQ("https://example.com/service/attachments/" + unique_id, | 433 EXPECT_EQ("https://example.com/service/attachments/" + unique_id, |
| 434 AttachmentUploaderImpl::GetURLForAttachmentId(sync_service_url, id) | 434 AttachmentUploaderImpl::GetURLForAttachmentId(sync_service_url, id) |
| 435 .spec()); | 435 .spec()); |
| 436 } | 436 } |
| 437 | 437 |
| 438 TEST_F(AttachmentUploaderImplTest, GetURLForAttachmentId_PathAndSlash) { | 438 TEST_F(AttachmentUploaderImplTest, GetURLForAttachmentId_PathAndSlash) { |
| 439 AttachmentId id = AttachmentId::Create(); | 439 AttachmentId id = AttachmentId::Create(0, 0); |
| 440 std::string unique_id = id.GetProto().unique_id(); | 440 std::string unique_id = id.GetProto().unique_id(); |
| 441 GURL sync_service_url("https://example.com/service/"); | 441 GURL sync_service_url("https://example.com/service/"); |
| 442 EXPECT_EQ("https://example.com/service/attachments/" + unique_id, | 442 EXPECT_EQ("https://example.com/service/attachments/" + unique_id, |
| 443 AttachmentUploaderImpl::GetURLForAttachmentId(sync_service_url, id) | 443 AttachmentUploaderImpl::GetURLForAttachmentId(sync_service_url, id) |
| 444 .spec()); | 444 .spec()); |
| 445 } | 445 } |
| 446 | 446 |
| 447 // Verify the "happy case" of uploading an attachment. | 447 // Verify the "happy case" of uploading an attachment. |
| 448 // | 448 // |
| 449 // Token is requested, token is returned, HTTP request is made, attachment is | 449 // Token is requested, token is returned, HTTP request is made, attachment is |
| (...skipping 221 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 |