Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: sync/internal_api/attachments/attachment_uploader_impl_unittest.cc

Issue 710073003: Store attachment crc in AttachmentStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Add comment in attachment_util.h. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/synchronization/lock.h" 14 #include "base/synchronization/lock.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "base/threading/non_thread_safe.h" 16 #include "base/threading/non_thread_safe.h"
17 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
18 #include "google_apis/gaia/fake_oauth2_token_service.h" 18 #include "google_apis/gaia/fake_oauth2_token_service.h"
19 #include "google_apis/gaia/gaia_constants.h" 19 #include "google_apis/gaia/gaia_constants.h"
20 #include "google_apis/gaia/oauth2_token_service_request.h" 20 #include "google_apis/gaia/oauth2_token_service_request.h"
21 #include "net/test/embedded_test_server/embedded_test_server.h" 21 #include "net/test/embedded_test_server/embedded_test_server.h"
22 #include "net/test/embedded_test_server/http_request.h" 22 #include "net/test/embedded_test_server/http_request.h"
23 #include "net/test/embedded_test_server/http_response.h" 23 #include "net/test/embedded_test_server/http_response.h"
24 #include "net/url_request/url_request_test_util.h" 24 #include "net/url_request/url_request_test_util.h"
25 #include "sync/api/attachments/attachment.h" 25 #include "sync/api/attachments/attachment.h"
26 #include "sync/internal_api/public/attachments/attachment_util.h"
26 #include "sync/protocol/sync.pb.h" 27 #include "sync/protocol/sync.pb.h"
27 #include "testing/gmock/include/gmock/gmock-matchers.h" 28 #include "testing/gmock/include/gmock/gmock-matchers.h"
28 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
29 30
30 namespace { 31 namespace {
31 32
32 const char kAttachmentData[] = "some data"; 33 const char kAttachmentData[] = "some data";
33 const char kAccountId[] = "some-account-id"; 34 const char kAccountId[] = "some-account-id";
34 const char kAccessToken[] = "some-access-token"; 35 const char kAccessToken[] = "some-access-token";
35 const char kAuthorization[] = "Authorization"; 36 const char kAuthorization[] = "Authorization";
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 std::string expected_relative_url(kAttachments + 621 std::string expected_relative_url(kAttachments +
621 attachment.GetId().GetProto().unique_id()); 622 attachment.GetId().GetProto().unique_id());
622 EXPECT_EQ(expected_relative_url, http_request.relative_url); 623 EXPECT_EQ(expected_relative_url, http_request.relative_url);
623 EXPECT_TRUE(http_request.has_content); 624 EXPECT_TRUE(http_request.has_content);
624 EXPECT_EQ(kAttachmentData, http_request.content); 625 EXPECT_EQ(kAttachmentData, http_request.content);
625 626
626 // See that we invalidated the token. 627 // See that we invalidated the token.
627 ASSERT_EQ(1, token_service().num_invalidate_token()); 628 ASSERT_EQ(1, token_service().num_invalidate_token());
628 } 629 }
629 630
630 TEST_F(AttachmentUploaderImplTest, ComputeCrc32cHash) { 631 TEST_F(AttachmentUploaderImplTest, FormatCrc32cHash) {
631 scoped_refptr<base::RefCountedString> empty(new base::RefCountedString); 632 scoped_refptr<base::RefCountedString> empty(new base::RefCountedString);
632 empty->data() = ""; 633 empty->data() = "";
633 EXPECT_EQ("AAAAAA==", 634 EXPECT_EQ("AAAAAA==",
634 AttachmentUploaderImpl::ComputeCrc32cHash(empty->front_as<char>(), 635 AttachmentUploaderImpl::FormatCrc32cHash(ComputeCrc32c(empty)));
635 empty->size()));
636 636
637 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString); 637 scoped_refptr<base::RefCountedString> hello_world(new base::RefCountedString);
638 hello_world->data() = "hello world"; 638 hello_world->data() = "hello world";
639 EXPECT_EQ("yZRlqg==", 639 EXPECT_EQ("yZRlqg==", AttachmentUploaderImpl::FormatCrc32cHash(
640 AttachmentUploaderImpl::ComputeCrc32cHash( 640 ComputeCrc32c(hello_world)));
641 hello_world->front_as<char>(), hello_world->size()));
642 } 641 }
643 642
644 // TODO(maniscalco): Add test case for when we are uploading an attachment that 643 // TODO(maniscalco): Add test case for when we are uploading an attachment that
645 // already exists. 409 Conflict? (bug 379825) 644 // already exists. 409 Conflict? (bug 379825)
646 645
647 } // namespace syncer 646 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/attachments/attachment_uploader_impl.cc ('k') | sync/internal_api/attachments/attachment_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698