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/on_disk_attachment_store.h" | 5 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 // Instantiation of common attachment store tests. | 34 // Instantiation of common attachment store tests. |
35 class OnDiskAttachmentStoreFactory { | 35 class OnDiskAttachmentStoreFactory { |
36 public: | 36 public: |
37 OnDiskAttachmentStoreFactory() {} | 37 OnDiskAttachmentStoreFactory() {} |
38 ~OnDiskAttachmentStoreFactory() {} | 38 ~OnDiskAttachmentStoreFactory() {} |
39 | 39 |
40 scoped_refptr<AttachmentStore> CreateAttachmentStore() { | 40 scoped_ptr<AttachmentStore> CreateAttachmentStore() { |
41 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); | 41 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); |
42 scoped_refptr<AttachmentStore> store; | 42 scoped_ptr<AttachmentStore> store; |
43 AttachmentStore::Result result = AttachmentStore::UNSPECIFIED_ERROR; | 43 AttachmentStore::Result result = AttachmentStore::UNSPECIFIED_ERROR; |
44 store = AttachmentStore::CreateOnDiskStore( | 44 store = AttachmentStore::CreateOnDiskStore( |
45 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), | 45 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), |
46 base::Bind(&AttachmentStoreCreated, &result)); | 46 base::Bind(&AttachmentStoreCreated, &result)); |
47 base::RunLoop run_loop; | 47 base::RunLoop run_loop; |
48 run_loop.RunUntilIdle(); | 48 run_loop.RunUntilIdle(); |
49 EXPECT_EQ(AttachmentStore::SUCCESS, result); | 49 EXPECT_EQ(AttachmentStore::SUCCESS, result); |
50 return store; | 50 return store; |
51 } | 51 } |
52 | 52 |
53 private: | 53 private: |
54 base::ScopedTempDir temp_dir_; | 54 base::ScopedTempDir temp_dir_; |
55 }; | 55 }; |
56 | 56 |
57 INSTANTIATE_TYPED_TEST_CASE_P(OnDisk, | 57 INSTANTIATE_TYPED_TEST_CASE_P(OnDisk, |
58 AttachmentStoreTest, | 58 AttachmentStoreTest, |
59 OnDiskAttachmentStoreFactory); | 59 OnDiskAttachmentStoreFactory); |
60 | 60 |
61 // Tests specific to OnDiskAttachmentStore. | 61 // Tests specific to OnDiskAttachmentStore. |
62 class OnDiskAttachmentStoreSpecificTest : public testing::Test { | 62 class OnDiskAttachmentStoreSpecificTest : public testing::Test { |
63 public: | 63 public: |
64 base::ScopedTempDir temp_dir_; | 64 base::ScopedTempDir temp_dir_; |
65 base::FilePath db_path_; | 65 base::FilePath db_path_; |
66 base::MessageLoop message_loop_; | 66 base::MessageLoop message_loop_; |
67 scoped_refptr<AttachmentStore> store_; | 67 scoped_ptr<AttachmentStore> store_; |
68 | 68 |
69 OnDiskAttachmentStoreSpecificTest() {} | 69 OnDiskAttachmentStoreSpecificTest() {} |
70 | 70 |
71 void SetUp() override { | 71 void SetUp() override { |
72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
73 db_path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("leveldb")); | 73 db_path_ = temp_dir_.path().Append(FILE_PATH_LITERAL("leveldb")); |
74 base::CreateDirectory(db_path_); | 74 base::CreateDirectory(db_path_); |
75 } | 75 } |
76 | 76 |
77 void CopyResult(AttachmentStore::Result* destination_result, | 77 void CopyResult(AttachmentStore::Result* destination_result, |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 store_->ReadAllMetadata( | 468 store_->ReadAllMetadata( |
469 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultMetadata, | 469 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultMetadata, |
470 base::Unretained(this), &metadata_result, &metadata_list)); | 470 base::Unretained(this), &metadata_result, &metadata_list)); |
471 RunLoop(); | 471 RunLoop(); |
472 EXPECT_EQ(AttachmentStore::SUCCESS, create_result); | 472 EXPECT_EQ(AttachmentStore::SUCCESS, create_result); |
473 EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, metadata_result); | 473 EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, metadata_result); |
474 EXPECT_EQ(2U, metadata_list->size()); | 474 EXPECT_EQ(2U, metadata_list->size()); |
475 } | 475 } |
476 | 476 |
477 } // namespace syncer | 477 } // namespace syncer |
OLD | NEW |