Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/offline_pages/offline_page_metadata_store_impl.h" | 5 #include "components/offline_pages/offline_page_metadata_store_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "components/leveldb_proto/proto_database_impl.h" | 17 #include "components/leveldb_proto/proto_database_impl.h" |
| 18 #include "components/offline_pages/offline_page_item.h" | 18 #include "components/offline_pages/offline_page_item.h" |
| 19 #include "components/offline_pages/offline_page_metadata_store_sql.h" | |
| 19 #include "components/offline_pages/offline_page_model.h" | 20 #include "components/offline_pages/offline_page_model.h" |
| 20 #include "components/offline_pages/proto/offline_pages.pb.h" | 21 #include "components/offline_pages/proto/offline_pages.pb.h" |
| 22 #include "sql/connection.h" | |
|
Scott Hess - ex-Googler
2016/04/25 19:57:55
Is this ever used in this CL?
bburns
2016/04/26 23:27:02
good catch, removed.
Scott Hess - ex-Googler
2016/04/27 15:21:00
Unwinding this another step - since the test does
| |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 24 |
| 23 using leveldb_proto::ProtoDatabaseImpl; | 25 using leveldb_proto::ProtoDatabaseImpl; |
| 24 | 26 |
| 25 namespace offline_pages { | 27 namespace offline_pages { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 | 30 |
| 29 const char kTestURL[] = "https://example.com"; | 31 const char kTestURL[] = "https://example.com"; |
| 30 const ClientId kTestBookmarkId(BOOKMARK_NAMESPACE, "1234"); | 32 const ClientId kTestBookmarkId(BOOKMARK_NAMESPACE, "1234"); |
| 31 const ClientId kTestBookmarkId2(BOOKMARK_NAMESPACE, "5678"); | 33 const ClientId kTestBookmarkId2(BOOKMARK_NAMESPACE, "5678"); |
| 32 const base::FilePath::CharType kFilePath[] = | 34 const base::FilePath::CharType kFilePath[] = |
| 33 FILE_PATH_LITERAL("/offline_pages/example_com.mhtml"); | 35 FILE_PATH_LITERAL("/offline_pages/example_com.mhtml"); |
| 34 int64_t kFileSize = 234567; | 36 int64_t kFileSize = 234567; |
| 35 | 37 |
| 36 } // namespace | 38 class OfflinePageMetadataStoreFactory { |
| 39 public: | |
| 40 virtual OfflinePageMetadataStore* BuildStore(const base::FilePath& file) = 0; | |
| 41 }; | |
| 37 | 42 |
| 38 class OfflinePageMetadataStoreImplTest : public testing::Test { | 43 class OfflinePageMetadataStoreImplFactory |
| 44 : public OfflinePageMetadataStoreFactory { | |
| 39 public: | 45 public: |
| 40 enum CalledCallback { NONE, LOAD, ADD, REMOVE, DESTROY }; | 46 OfflinePageMetadataStore* BuildStore(const base::FilePath& file) override { |
| 41 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE }; | 47 return new OfflinePageMetadataStoreImpl(base::ThreadTaskRunnerHandle::Get(), |
| 48 file); | |
| 49 } | |
| 50 }; | |
| 42 | 51 |
| 43 OfflinePageMetadataStoreImplTest(); | 52 class OfflinePageMetadataStoreSQLFactory |
| 44 ~OfflinePageMetadataStoreImplTest() override; | 53 : public OfflinePageMetadataStoreFactory { |
| 54 public: | |
| 55 OfflinePageMetadataStore* BuildStore(const base::FilePath& file) override { | |
| 56 OfflinePageMetadataStoreSQL* store = new OfflinePageMetadataStoreSQL( | |
| 57 base::ThreadTaskRunnerHandle::Get(), file); | |
| 58 return store; | |
| 59 } | |
| 60 }; | |
| 61 | |
| 62 enum CalledCallback { NONE, LOAD, ADD, REMOVE, DESTROY }; | |
| 63 enum Status { STATUS_NONE, STATUS_TRUE, STATUS_FALSE }; | |
| 64 | |
| 65 class OfflinePageMetadataStoreTestBase : public testing::Test { | |
| 66 public: | |
| 67 OfflinePageMetadataStoreTestBase(); | |
| 68 ~OfflinePageMetadataStoreTestBase() override; | |
| 45 | 69 |
| 46 void TearDown() override { | 70 void TearDown() override { |
| 47 // Wait for all the pieces of the store to delete itself properly. | 71 // Wait for all the pieces of the store to delete itself properly. |
| 48 PumpLoop(); | 72 PumpLoop(); |
| 49 } | 73 } |
| 50 | 74 |
| 51 scoped_ptr<OfflinePageMetadataStoreImpl> BuildStore(); | 75 virtual scoped_ptr<OfflinePageMetadataStore> BuildStore() = 0; |
| 52 void PumpLoop(); | 76 void PumpLoop(); |
| 53 | 77 |
| 54 void LoadCallback(OfflinePageMetadataStore::LoadStatus load_status, | 78 void LoadCallback(OfflinePageMetadataStore::LoadStatus load_status, |
| 55 const std::vector<OfflinePageItem>& offline_pages); | 79 const std::vector<OfflinePageItem>& offline_pages); |
| 56 void UpdateCallback(CalledCallback called_callback, bool success); | 80 void UpdateCallback(CalledCallback called_callback, bool success); |
| 57 | 81 |
| 58 void ClearResults(); | 82 void ClearResults(); |
| 59 | 83 |
| 60 void UpdateStoreEntries( | |
| 61 OfflinePageMetadataStoreImpl* store, | |
| 62 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> | |
| 63 entries_to_save); | |
| 64 | |
| 65 protected: | 84 protected: |
| 66 CalledCallback last_called_callback_; | 85 CalledCallback last_called_callback_; |
| 67 Status last_status_; | 86 Status last_status_; |
| 68 std::vector<OfflinePageItem> offline_pages_; | 87 std::vector<OfflinePageItem> offline_pages_; |
| 69 | 88 |
| 70 base::ScopedTempDir temp_directory_; | 89 base::ScopedTempDir temp_directory_; |
| 71 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 90 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 72 base::ThreadTaskRunnerHandle task_runner_handle_; | 91 base::ThreadTaskRunnerHandle task_runner_handle_; |
| 73 }; | 92 }; |
| 74 | 93 |
| 75 OfflinePageMetadataStoreImplTest::OfflinePageMetadataStoreImplTest() | 94 OfflinePageMetadataStoreTestBase::OfflinePageMetadataStoreTestBase() |
| 76 : last_called_callback_(NONE), | 95 : last_called_callback_(NONE), |
| 77 last_status_(STATUS_NONE), | 96 last_status_(STATUS_NONE), |
| 78 task_runner_(new base::TestSimpleTaskRunner), | 97 task_runner_(new base::TestSimpleTaskRunner), |
| 79 task_runner_handle_(task_runner_) { | 98 task_runner_handle_(task_runner_) { |
| 80 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); | 99 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); |
| 81 } | 100 } |
| 82 | 101 |
| 83 OfflinePageMetadataStoreImplTest::~OfflinePageMetadataStoreImplTest() { | 102 OfflinePageMetadataStoreTestBase::~OfflinePageMetadataStoreTestBase() {} |
| 84 } | |
| 85 | 103 |
| 86 void OfflinePageMetadataStoreImplTest::PumpLoop() { | 104 void OfflinePageMetadataStoreTestBase::PumpLoop() { |
| 87 task_runner_->RunUntilIdle(); | 105 task_runner_->RunUntilIdle(); |
| 88 } | 106 } |
| 89 | 107 |
| 90 scoped_ptr<OfflinePageMetadataStoreImpl> | 108 void OfflinePageMetadataStoreTestBase::LoadCallback( |
| 91 OfflinePageMetadataStoreImplTest::BuildStore() { | |
| 92 scoped_ptr<OfflinePageMetadataStoreImpl> store( | |
| 93 new OfflinePageMetadataStoreImpl(base::ThreadTaskRunnerHandle::Get(), | |
| 94 temp_directory_.path())); | |
| 95 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, | |
| 96 base::Unretained(this))); | |
| 97 PumpLoop(); | |
| 98 return store; | |
| 99 } | |
| 100 | |
| 101 void OfflinePageMetadataStoreImplTest::LoadCallback( | |
| 102 OfflinePageMetadataStore::LoadStatus load_status, | 109 OfflinePageMetadataStore::LoadStatus load_status, |
| 103 const std::vector<OfflinePageItem>& offline_pages) { | 110 const std::vector<OfflinePageItem>& offline_pages) { |
| 104 last_called_callback_ = LOAD; | 111 last_called_callback_ = LOAD; |
| 105 last_status_ = load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED ? | 112 last_status_ = load_status == OfflinePageMetadataStore::LOAD_SUCCEEDED ? |
| 106 STATUS_TRUE : STATUS_FALSE; | 113 STATUS_TRUE : STATUS_FALSE; |
| 107 offline_pages_.swap(const_cast<std::vector<OfflinePageItem>&>(offline_pages)); | 114 offline_pages_.swap(const_cast<std::vector<OfflinePageItem>&>(offline_pages)); |
| 108 } | 115 } |
| 109 | 116 |
| 110 void OfflinePageMetadataStoreImplTest::UpdateCallback( | 117 void OfflinePageMetadataStoreTestBase::UpdateCallback( |
| 111 CalledCallback called_callback, | 118 CalledCallback called_callback, |
| 112 bool status) { | 119 bool status) { |
| 113 last_called_callback_ = called_callback; | 120 last_called_callback_ = called_callback; |
| 114 last_status_ = status ? STATUS_TRUE : STATUS_FALSE; | 121 last_status_ = status ? STATUS_TRUE : STATUS_FALSE; |
| 115 } | 122 } |
| 116 | 123 |
| 117 void OfflinePageMetadataStoreImplTest::ClearResults() { | 124 void OfflinePageMetadataStoreTestBase::ClearResults() { |
| 118 last_called_callback_ = NONE; | 125 last_called_callback_ = NONE; |
| 119 last_status_ = STATUS_NONE; | 126 last_status_ = STATUS_NONE; |
| 120 offline_pages_.clear(); | 127 offline_pages_.clear(); |
| 121 } | 128 } |
| 122 | 129 |
| 123 void OfflinePageMetadataStoreImplTest::UpdateStoreEntries( | 130 template <typename T> |
| 124 OfflinePageMetadataStoreImpl* store, | 131 class OfflinePageMetadataStoreTest : public OfflinePageMetadataStoreTestBase { |
| 125 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> | 132 public: |
| 126 entries_to_save) { | 133 scoped_ptr<OfflinePageMetadataStore> BuildStore(); |
| 127 scoped_ptr<std::vector<std::string>> keys_to_remove( | 134 |
| 128 new std::vector<std::string>()); | 135 protected: |
| 129 store->UpdateEntries( | 136 T factory_; |
| 130 std::move(entries_to_save), std::move(keys_to_remove), | 137 }; |
| 131 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 138 |
| 132 base::Unretained(this), ADD)); | 139 template <typename T> |
| 140 scoped_ptr<OfflinePageMetadataStore> | |
| 141 OfflinePageMetadataStoreTest<T>::BuildStore() { | |
| 142 scoped_ptr<OfflinePageMetadataStore> store( | |
| 143 factory_.BuildStore(temp_directory_.path())); | |
| 144 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback, | |
| 145 base::Unretained(this))); | |
| 146 PumpLoop(); | |
| 147 return store; | |
| 133 } | 148 } |
| 134 | 149 |
| 150 typedef testing::Types<OfflinePageMetadataStoreImplFactory, | |
| 151 OfflinePageMetadataStoreSQLFactory> | |
| 152 MyTypes; | |
| 153 TYPED_TEST_CASE(OfflinePageMetadataStoreTest, MyTypes); | |
| 154 | |
| 135 // Loads empty store and makes sure that there are no offline pages stored in | 155 // Loads empty store and makes sure that there are no offline pages stored in |
| 136 // it. | 156 // it. |
| 137 TEST_F(OfflinePageMetadataStoreImplTest, LoadEmptyStore) { | 157 TYPED_TEST(OfflinePageMetadataStoreTest, LoadEmptyStore) { |
| 138 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); | 158 scoped_ptr<OfflinePageMetadataStore> store(this->BuildStore()); |
| 139 EXPECT_EQ(LOAD, last_called_callback_); | 159 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 140 EXPECT_EQ(STATUS_TRUE, last_status_); | 160 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 141 EXPECT_EQ(0U, offline_pages_.size()); | 161 EXPECT_EQ(0U, this->offline_pages_.size()); |
| 142 } | 162 } |
| 143 | 163 |
| 144 // Adds metadata of an offline page into a store and then opens the store | 164 // Adds metadata of an offline page into a store and then opens the store |
| 145 // again to make sure that stored metadata survives store restarts. | 165 // again to make sure that stored metadata survives store restarts. |
| 146 TEST_F(OfflinePageMetadataStoreImplTest, AddOfflinePage) { | 166 TYPED_TEST(OfflinePageMetadataStoreTest, AddOfflinePage) { |
| 147 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); | 167 scoped_ptr<OfflinePageMetadataStore> store(this->BuildStore()); |
| 148 | 168 |
| 149 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId, | 169 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId, |
| 150 base::FilePath(kFilePath), kFileSize); | 170 base::FilePath(kFilePath), kFileSize); |
| 151 store->AddOrUpdateOfflinePage( | 171 store->AddOrUpdateOfflinePage( |
| 152 offline_page, | 172 offline_page, |
| 153 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 173 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 154 base::Unretained(this), ADD)); | 174 base::Unretained(this), ADD)); |
| 155 PumpLoop(); | 175 this->PumpLoop(); |
| 156 EXPECT_EQ(ADD, last_called_callback_); | 176 EXPECT_EQ(ADD, this->last_called_callback_); |
| 157 EXPECT_EQ(STATUS_TRUE, last_status_); | 177 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 158 | 178 |
| 159 ClearResults(); | 179 this->ClearResults(); |
| 160 | 180 |
| 161 // Close the store first to ensure file lock is removed. | 181 // Close the store first to ensure file lock is removed. |
| 162 store.reset(); | 182 store.reset(); |
| 163 store = BuildStore(); | 183 store = this->BuildStore(); |
| 164 PumpLoop(); | 184 this->PumpLoop(); |
| 165 | 185 |
| 166 EXPECT_EQ(LOAD, last_called_callback_); | 186 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 167 EXPECT_EQ(STATUS_TRUE, last_status_); | 187 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 168 EXPECT_EQ(1U, offline_pages_.size()); | 188 EXPECT_EQ(1U, this->offline_pages_.size()); |
| 169 EXPECT_EQ(offline_page.url, offline_pages_[0].url); | 189 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url); |
| 170 EXPECT_EQ(offline_page.offline_id, offline_pages_[0].offline_id); | 190 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id); |
| 171 EXPECT_EQ(offline_page.version, offline_pages_[0].version); | 191 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version); |
| 172 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); | 192 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path); |
| 173 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); | 193 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size); |
| 174 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); | 194 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time); |
| 175 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); | 195 EXPECT_EQ(offline_page.last_access_time, |
| 176 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); | 196 this->offline_pages_[0].last_access_time); |
| 177 EXPECT_EQ(offline_page.client_id, offline_pages_[0].client_id); | 197 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count); |
| 198 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id); | |
| 178 } | 199 } |
| 179 | 200 |
| 180 // Tests removing offline page metadata from the store, for which it first adds | 201 // Tests removing offline page metadata from the store, for which it first adds |
| 181 // metadata of an offline page. | 202 // metadata of an offline page. |
| 182 TEST_F(OfflinePageMetadataStoreImplTest, RemoveOfflinePage) { | 203 TYPED_TEST(OfflinePageMetadataStoreTest, RemoveOfflinePage) { |
| 183 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); | 204 scoped_ptr<OfflinePageMetadataStore> store(this->BuildStore()); |
| 184 | 205 |
| 185 // Add an offline page. | 206 // Add an offline page. |
| 186 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId, | 207 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId, |
| 187 base::FilePath(kFilePath), kFileSize); | 208 base::FilePath(kFilePath), kFileSize); |
| 188 store->AddOrUpdateOfflinePage( | 209 store->AddOrUpdateOfflinePage( |
| 189 offline_page, | 210 offline_page, |
| 190 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 211 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 191 base::Unretained(this), ADD)); | 212 base::Unretained(this), ADD)); |
| 192 PumpLoop(); | 213 this->PumpLoop(); |
| 193 EXPECT_EQ(ADD, last_called_callback_); | 214 EXPECT_EQ(ADD, this->last_called_callback_); |
| 194 EXPECT_EQ(STATUS_TRUE, last_status_); | 215 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 195 | 216 |
| 196 ClearResults(); | 217 this->ClearResults(); |
| 197 | 218 |
| 198 // Load the store. | 219 // Load the store. |
| 199 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, | 220 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback, |
| 200 base::Unretained(this))); | 221 base::Unretained(this))); |
| 201 PumpLoop(); | 222 this->PumpLoop(); |
| 202 EXPECT_EQ(LOAD, last_called_callback_); | 223 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 203 EXPECT_EQ(1U, offline_pages_.size()); | 224 EXPECT_EQ(1U, this->offline_pages_.size()); |
| 204 | 225 |
| 205 // Remove the offline page. | 226 // Remove the offline page. |
| 206 std::vector<int64_t> ids_to_remove; | 227 std::vector<int64_t> ids_to_remove; |
| 207 ids_to_remove.push_back(offline_page.offline_id); | 228 ids_to_remove.push_back(offline_page.offline_id); |
| 208 store->RemoveOfflinePages( | 229 store->RemoveOfflinePages( |
| 209 ids_to_remove, | 230 ids_to_remove, |
| 210 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 231 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 211 base::Unretained(this), REMOVE)); | 232 base::Unretained(this), REMOVE)); |
| 212 PumpLoop(); | 233 this->PumpLoop(); |
| 213 EXPECT_EQ(REMOVE, last_called_callback_); | 234 EXPECT_EQ(REMOVE, this->last_called_callback_); |
| 214 EXPECT_EQ(STATUS_TRUE, last_status_); | 235 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 215 | 236 |
| 216 ClearResults(); | 237 this->ClearResults(); |
| 217 | 238 |
| 218 // Load the store. | 239 // Load the store. |
| 219 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, | 240 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback, |
| 220 base::Unretained(this))); | 241 base::Unretained(this))); |
| 221 PumpLoop(); | 242 this->PumpLoop(); |
| 222 EXPECT_EQ(LOAD, last_called_callback_); | 243 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 223 EXPECT_EQ(0U, offline_pages_.size()); | 244 EXPECT_EQ(0U, this->offline_pages_.size()); |
| 224 | 245 |
| 225 ClearResults(); | 246 this->ClearResults(); |
| 226 | 247 |
| 227 // Close and reload the store. | 248 // Close and reload the store. |
| 228 store.reset(); | 249 store.reset(); |
| 229 store = BuildStore(); | 250 store = this->BuildStore(); |
| 230 EXPECT_EQ(LOAD, last_called_callback_); | 251 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 231 EXPECT_EQ(STATUS_TRUE, last_status_); | 252 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 232 EXPECT_EQ(0U, offline_pages_.size()); | 253 EXPECT_EQ(0U, this->offline_pages_.size()); |
| 233 } | 254 } |
| 234 | 255 |
| 235 // Adds metadata of multiple offline pages into a store and removes some. | 256 // Adds metadata of multiple offline pages into a store and removes some. |
| 236 TEST_F(OfflinePageMetadataStoreImplTest, AddRemoveMultipleOfflinePages) { | 257 TYPED_TEST(OfflinePageMetadataStoreTest, AddRemoveMultipleOfflinePages) { |
| 237 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); | 258 scoped_ptr<OfflinePageMetadataStore> store(this->BuildStore()); |
| 238 | 259 |
| 239 // Add an offline page. | 260 // Add an offline page. |
| 240 OfflinePageItem offline_page_1(GURL(kTestURL), 12345LL, kTestBookmarkId, | 261 OfflinePageItem offline_page_1(GURL(kTestURL), 12345LL, kTestBookmarkId, |
| 241 base::FilePath(kFilePath), kFileSize); | 262 base::FilePath(kFilePath), kFileSize); |
| 242 base::FilePath file_path_2 = | 263 base::FilePath file_path_2 = |
| 243 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml")); | 264 base::FilePath(FILE_PATH_LITERAL("//other.page.com.mhtml")); |
| 244 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL, | 265 OfflinePageItem offline_page_2(GURL("https://other.page.com"), 5678LL, |
| 245 kTestBookmarkId2, file_path_2, 12345, | 266 kTestBookmarkId2, file_path_2, 12345, |
| 246 base::Time::Now()); | 267 base::Time::Now()); |
| 247 store->AddOrUpdateOfflinePage( | 268 store->AddOrUpdateOfflinePage( |
| 248 offline_page_1, | 269 offline_page_1, |
| 249 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 270 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 250 base::Unretained(this), ADD)); | 271 base::Unretained(this), ADD)); |
| 251 PumpLoop(); | 272 this->PumpLoop(); |
| 252 EXPECT_EQ(ADD, last_called_callback_); | 273 EXPECT_EQ(ADD, this->last_called_callback_); |
| 253 EXPECT_EQ(STATUS_TRUE, last_status_); | 274 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 254 | 275 |
| 255 ClearResults(); | 276 this->ClearResults(); |
| 256 | 277 |
| 257 // Add anther offline page. | 278 // Add anther offline page. |
| 258 store->AddOrUpdateOfflinePage( | 279 store->AddOrUpdateOfflinePage( |
| 259 offline_page_2, | 280 offline_page_2, |
| 260 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 281 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 261 base::Unretained(this), ADD)); | 282 base::Unretained(this), ADD)); |
| 262 PumpLoop(); | 283 this->PumpLoop(); |
| 263 EXPECT_EQ(ADD, last_called_callback_); | 284 EXPECT_EQ(ADD, this->last_called_callback_); |
| 264 EXPECT_EQ(STATUS_TRUE, last_status_); | 285 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 265 | 286 |
| 266 ClearResults(); | 287 this->ClearResults(); |
| 267 | 288 |
| 268 // Load the store. | 289 // Load the store. |
| 269 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, | 290 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback, |
| 270 base::Unretained(this))); | 291 base::Unretained(this))); |
| 271 PumpLoop(); | 292 this->PumpLoop(); |
| 272 | 293 |
| 273 EXPECT_EQ(LOAD, last_called_callback_); | 294 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 274 EXPECT_EQ(STATUS_TRUE, last_status_); | 295 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 275 EXPECT_EQ(2U, offline_pages_.size()); | 296 EXPECT_EQ(2U, this->offline_pages_.size()); |
| 276 | 297 |
| 277 // Remove the offline page. | 298 // Remove the offline page. |
| 278 std::vector<int64_t> ids_to_remove; | 299 std::vector<int64_t> ids_to_remove; |
| 279 ids_to_remove.push_back(offline_page_1.offline_id); | 300 ids_to_remove.push_back(offline_page_1.offline_id); |
| 280 store->RemoveOfflinePages( | 301 store->RemoveOfflinePages( |
| 281 ids_to_remove, | 302 ids_to_remove, |
| 282 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 303 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 283 base::Unretained(this), REMOVE)); | 304 base::Unretained(this), REMOVE)); |
| 284 PumpLoop(); | 305 this->PumpLoop(); |
| 285 EXPECT_EQ(REMOVE, last_called_callback_); | 306 EXPECT_EQ(REMOVE, this->last_called_callback_); |
| 286 EXPECT_EQ(STATUS_TRUE, last_status_); | 307 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 287 | 308 |
| 288 ClearResults(); | 309 this->ClearResults(); |
| 289 | 310 |
| 290 // Close and reload the store. | 311 // Close and reload the store. |
| 291 store.reset(); | 312 store.reset(); |
| 292 store = BuildStore(); | 313 store = this->BuildStore(); |
| 293 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, | 314 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback, |
| 294 base::Unretained(this))); | 315 base::Unretained(this))); |
| 295 PumpLoop(); | 316 this->PumpLoop(); |
| 296 | 317 |
| 297 EXPECT_EQ(LOAD, last_called_callback_); | 318 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 298 EXPECT_EQ(STATUS_TRUE, last_status_); | 319 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 299 EXPECT_EQ(1U, offline_pages_.size()); | 320 EXPECT_EQ(1U, this->offline_pages_.size()); |
| 300 EXPECT_EQ(offline_page_2.url, offline_pages_[0].url); | 321 EXPECT_EQ(offline_page_2.url, this->offline_pages_[0].url); |
| 301 EXPECT_EQ(offline_page_2.offline_id, offline_pages_[0].offline_id); | 322 EXPECT_EQ(offline_page_2.offline_id, this->offline_pages_[0].offline_id); |
| 302 EXPECT_EQ(offline_page_2.version, offline_pages_[0].version); | 323 EXPECT_EQ(offline_page_2.version, this->offline_pages_[0].version); |
| 303 EXPECT_EQ(offline_page_2.file_path, offline_pages_[0].file_path); | 324 EXPECT_EQ(offline_page_2.file_path, this->offline_pages_[0].file_path); |
| 304 EXPECT_EQ(offline_page_2.file_size, offline_pages_[0].file_size); | 325 EXPECT_EQ(offline_page_2.file_size, this->offline_pages_[0].file_size); |
| 305 EXPECT_EQ(offline_page_2.creation_time, offline_pages_[0].creation_time); | 326 EXPECT_EQ(offline_page_2.creation_time, |
| 327 this->offline_pages_[0].creation_time); | |
| 306 EXPECT_EQ(offline_page_2.last_access_time, | 328 EXPECT_EQ(offline_page_2.last_access_time, |
| 307 offline_pages_[0].last_access_time); | 329 this->offline_pages_[0].last_access_time); |
| 308 EXPECT_EQ(offline_page_2.access_count, offline_pages_[0].access_count); | 330 EXPECT_EQ(offline_page_2.access_count, this->offline_pages_[0].access_count); |
| 309 EXPECT_EQ(offline_page_2.client_id, offline_pages_[0].client_id); | 331 EXPECT_EQ(offline_page_2.client_id, this->offline_pages_[0].client_id); |
| 310 } | 332 } |
| 311 | 333 |
| 312 // Tests updating offline page metadata from the store. | 334 // Tests updating offline page metadata from the store. |
| 313 TEST_F(OfflinePageMetadataStoreImplTest, UpdateOfflinePage) { | 335 TYPED_TEST(OfflinePageMetadataStoreTest, UpdateOfflinePage) { |
| 314 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); | 336 scoped_ptr<OfflinePageMetadataStore> store(this->BuildStore()); |
| 315 | 337 |
| 316 // First, adds a fresh page. | 338 // First, add a fresh page. |
| 317 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId, | 339 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId, |
| 318 base::FilePath(kFilePath), kFileSize); | 340 base::FilePath(kFilePath), kFileSize); |
| 319 store->AddOrUpdateOfflinePage( | 341 store->AddOrUpdateOfflinePage( |
| 320 offline_page, | 342 offline_page, |
| 321 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 343 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 322 base::Unretained(this), ADD)); | 344 base::Unretained(this), ADD)); |
| 323 PumpLoop(); | 345 this->PumpLoop(); |
| 324 EXPECT_EQ(ADD, last_called_callback_); | 346 EXPECT_EQ(ADD, this->last_called_callback_); |
| 325 EXPECT_EQ(STATUS_TRUE, last_status_); | 347 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 326 | 348 |
| 327 ClearResults(); | 349 this->ClearResults(); |
| 328 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, | 350 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback, |
| 329 base::Unretained(this))); | 351 base::Unretained(this))); |
| 330 PumpLoop(); | 352 this->PumpLoop(); |
| 331 | 353 |
| 332 EXPECT_EQ(LOAD, last_called_callback_); | 354 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 333 EXPECT_EQ(STATUS_TRUE, last_status_); | 355 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 334 EXPECT_EQ(1U, offline_pages_.size()); | 356 EXPECT_EQ(1U, this->offline_pages_.size()); |
| 335 EXPECT_EQ(offline_page.url, offline_pages_[0].url); | 357 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url); |
| 336 EXPECT_EQ(offline_page.offline_id, offline_pages_[0].offline_id); | 358 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id); |
| 337 EXPECT_EQ(offline_page.version, offline_pages_[0].version); | 359 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version); |
| 338 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); | 360 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path); |
| 339 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); | 361 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size); |
| 340 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); | 362 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time); |
| 341 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); | 363 EXPECT_EQ(offline_page.last_access_time, |
| 342 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); | 364 this->offline_pages_[0].last_access_time); |
| 343 EXPECT_EQ(offline_page.client_id, offline_pages_[0].client_id); | 365 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count); |
| 366 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id); | |
| 344 | 367 |
| 345 // Then updates some data. | 368 // Then update some data. |
| 346 offline_page.file_size = kFileSize + 1; | 369 offline_page.file_size = kFileSize + 1; |
| 347 offline_page.access_count++; | 370 offline_page.access_count++; |
| 348 store->AddOrUpdateOfflinePage( | 371 store->AddOrUpdateOfflinePage( |
| 349 offline_page, | 372 offline_page, |
| 350 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 373 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 351 base::Unretained(this), ADD)); | 374 base::Unretained(this), ADD)); |
| 352 PumpLoop(); | 375 this->PumpLoop(); |
| 353 EXPECT_EQ(ADD, last_called_callback_); | 376 EXPECT_EQ(ADD, this->last_called_callback_); |
| 354 EXPECT_EQ(STATUS_TRUE, last_status_); | 377 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 355 | 378 |
| 356 ClearResults(); | 379 this->ClearResults(); |
| 357 store->Load(base::Bind(&OfflinePageMetadataStoreImplTest::LoadCallback, | 380 store->Load(base::Bind(&OfflinePageMetadataStoreTestBase::LoadCallback, |
| 358 base::Unretained(this))); | 381 base::Unretained(this))); |
| 359 PumpLoop(); | 382 this->PumpLoop(); |
| 360 | 383 |
| 361 EXPECT_EQ(LOAD, last_called_callback_); | 384 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 362 EXPECT_EQ(STATUS_TRUE, last_status_); | 385 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 363 EXPECT_EQ(1U, offline_pages_.size()); | 386 EXPECT_EQ(1U, this->offline_pages_.size()); |
| 364 EXPECT_EQ(offline_page.url, offline_pages_[0].url); | 387 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url); |
| 365 EXPECT_EQ(offline_page.offline_id, offline_pages_[0].offline_id); | 388 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id); |
| 366 EXPECT_EQ(offline_page.version, offline_pages_[0].version); | 389 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version); |
| 367 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); | 390 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path); |
| 368 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); | 391 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size); |
| 369 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); | 392 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time); |
| 370 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); | 393 EXPECT_EQ(offline_page.last_access_time, |
| 371 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); | 394 this->offline_pages_[0].last_access_time); |
| 372 EXPECT_EQ(offline_page.client_id, offline_pages_[0].client_id); | 395 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count); |
| 396 EXPECT_EQ(offline_page.client_id, this->offline_pages_[0].client_id); | |
| 397 } | |
| 398 | |
| 399 } // namespace | |
| 400 | |
| 401 class OfflinePageMetadataStoreImplTest | |
| 402 : public OfflinePageMetadataStoreTest<OfflinePageMetadataStoreImplFactory> { | |
| 403 public: | |
| 404 void UpdateStoreEntries( | |
| 405 OfflinePageMetadataStoreImpl* store, | |
| 406 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> | |
| 407 entries_to_save); | |
| 408 }; | |
| 409 | |
| 410 void OfflinePageMetadataStoreImplTest::UpdateStoreEntries( | |
| 411 OfflinePageMetadataStoreImpl* store, | |
| 412 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> | |
| 413 entries_to_save) { | |
| 414 scoped_ptr<std::vector<std::string>> keys_to_remove( | |
| 415 new std::vector<std::string>()); | |
| 416 store->UpdateEntries( | |
| 417 std::move(entries_to_save), std::move(keys_to_remove), | |
| 418 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, | |
| 419 base::Unretained(this), ADD)); | |
| 373 } | 420 } |
| 374 | 421 |
| 375 // Test that loading a store with a bad value still loads. | 422 // Test that loading a store with a bad value still loads. |
| 376 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST | 423 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST |
| 377 // to work. | 424 // to work. |
| 378 TEST_F(OfflinePageMetadataStoreImplTest, LoadCorruptedStore) { | 425 TEST_F(OfflinePageMetadataStoreImplTest, LoadCorruptedStore) { |
| 379 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); | 426 scoped_ptr<OfflinePageMetadataStore> store(this->BuildStore()); |
| 380 | 427 |
| 381 // Write one ok page. | 428 // Write one ok page. |
| 382 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId, | 429 OfflinePageItem offline_page(GURL(kTestURL), 1234LL, kTestBookmarkId, |
| 383 base::FilePath(kFilePath), kFileSize); | 430 base::FilePath(kFilePath), kFileSize); |
| 384 store->AddOrUpdateOfflinePage( | 431 store->AddOrUpdateOfflinePage( |
| 385 offline_page, | 432 offline_page, |
| 386 base::Bind(&OfflinePageMetadataStoreImplTest::UpdateCallback, | 433 base::Bind(&OfflinePageMetadataStoreTestBase::UpdateCallback, |
| 387 base::Unretained(this), ADD)); | 434 base::Unretained(this), ADD)); |
| 388 PumpLoop(); | 435 this->PumpLoop(); |
| 389 EXPECT_EQ(ADD, last_called_callback_); | 436 EXPECT_EQ(ADD, this->last_called_callback_); |
| 390 EXPECT_EQ(STATUS_TRUE, last_status_); | 437 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 391 | 438 |
| 392 // Manually write one broken page (no id) | 439 // Manually write one broken page (no id) |
| 393 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> | 440 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> |
| 394 entries_to_save( | 441 entries_to_save( |
| 395 new leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); | 442 new leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); |
| 396 | 443 |
| 397 OfflinePageEntry offline_page_proto; | 444 OfflinePageEntry offline_page_proto; |
| 398 entries_to_save->push_back(std::make_pair("0", offline_page_proto)); | 445 entries_to_save->push_back(std::make_pair("0", offline_page_proto)); |
| 399 | 446 |
| 400 UpdateStoreEntries(store.get(), std::move(entries_to_save)); | 447 UpdateStoreEntries((OfflinePageMetadataStoreImpl*)store.get(), |
|
Scott Hess - ex-Googler
2016/04/25 19:57:55
I think Chromium style guide always wants static_c
| |
| 401 PumpLoop(); | 448 std::move(entries_to_save)); |
| 449 this->PumpLoop(); | |
| 402 | 450 |
| 403 EXPECT_EQ(ADD, last_called_callback_); | 451 EXPECT_EQ(ADD, this->last_called_callback_); |
| 404 EXPECT_EQ(STATUS_TRUE, last_status_); | 452 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 405 | 453 |
| 406 ClearResults(); | 454 this->ClearResults(); |
| 407 | 455 |
| 408 // Close the store first to ensure file lock is removed. | 456 // Close the store first to ensure file lock is removed. |
| 409 store.reset(); | 457 store.reset(); |
| 410 store = BuildStore(); | 458 store = this->BuildStore(); |
| 411 PumpLoop(); | 459 this->PumpLoop(); |
| 412 | 460 |
| 413 // One of the pages was busted, so only expect one page. | 461 // One of the pages was busted, so only expect one page. |
| 414 EXPECT_EQ(LOAD, last_called_callback_); | 462 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 415 EXPECT_EQ(STATUS_TRUE, last_status_); | 463 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 416 EXPECT_EQ(1U, offline_pages_.size()); | 464 EXPECT_EQ(1U, this->offline_pages_.size()); |
| 417 EXPECT_EQ(offline_page.url, offline_pages_[0].url); | 465 EXPECT_EQ(offline_page.url, this->offline_pages_[0].url); |
| 418 EXPECT_EQ(offline_page.offline_id, offline_pages_[0].offline_id); | 466 EXPECT_EQ(offline_page.offline_id, this->offline_pages_[0].offline_id); |
| 419 EXPECT_EQ(offline_page.version, offline_pages_[0].version); | 467 EXPECT_EQ(offline_page.version, this->offline_pages_[0].version); |
| 420 EXPECT_EQ(offline_page.file_path, offline_pages_[0].file_path); | 468 EXPECT_EQ(offline_page.file_path, this->offline_pages_[0].file_path); |
| 421 EXPECT_EQ(offline_page.file_size, offline_pages_[0].file_size); | 469 EXPECT_EQ(offline_page.file_size, this->offline_pages_[0].file_size); |
| 422 EXPECT_EQ(offline_page.creation_time, offline_pages_[0].creation_time); | 470 EXPECT_EQ(offline_page.creation_time, this->offline_pages_[0].creation_time); |
| 423 EXPECT_EQ(offline_page.last_access_time, offline_pages_[0].last_access_time); | 471 EXPECT_EQ(offline_page.last_access_time, |
| 424 EXPECT_EQ(offline_page.access_count, offline_pages_[0].access_count); | 472 this->offline_pages_[0].last_access_time); |
| 473 EXPECT_EQ(offline_page.access_count, this->offline_pages_[0].access_count); | |
| 425 } | 474 } |
| 426 | 475 |
| 427 // Test that loading a store with nothing but bad values errors. | 476 // Test that loading a store with nothing but bad values errors. |
| 428 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST | 477 // Needs to be outside of the anonymous namespace in order for FRIEND_TEST |
| 429 // to work. | 478 // to work. |
| 430 TEST_F(OfflinePageMetadataStoreImplTest, LoadTotallyCorruptedStore) { | 479 TEST_F(OfflinePageMetadataStoreImplTest, LoadTotallyCorruptedStore) { |
| 431 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); | 480 scoped_ptr<OfflinePageMetadataStore> store(this->BuildStore()); |
| 432 | 481 |
| 433 // Manually write two broken pages (no id) | 482 // Manually write two broken pages (no id) |
| 434 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> | 483 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> |
| 435 entries_to_save( | 484 entries_to_save( |
| 436 new leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); | 485 new leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); |
| 437 | 486 |
| 438 OfflinePageEntry offline_page_proto; | 487 OfflinePageEntry offline_page_proto; |
| 439 entries_to_save->push_back(std::make_pair("0", offline_page_proto)); | 488 entries_to_save->push_back(std::make_pair("0", offline_page_proto)); |
| 440 entries_to_save->push_back(std::make_pair("1", offline_page_proto)); | 489 entries_to_save->push_back(std::make_pair("1", offline_page_proto)); |
| 441 | 490 |
| 442 UpdateStoreEntries(store.get(), std::move(entries_to_save));; | 491 UpdateStoreEntries((OfflinePageMetadataStoreImpl*)store.get(), |
|
Scott Hess - ex-Googler
2016/04/25 19:57:55
Also here.
| |
| 443 PumpLoop(); | 492 std::move(entries_to_save)); |
| 493 ; | |
| 494 this->PumpLoop(); | |
| 444 | 495 |
| 445 EXPECT_EQ(ADD, last_called_callback_); | 496 EXPECT_EQ(ADD, this->last_called_callback_); |
| 446 EXPECT_EQ(STATUS_TRUE, last_status_); | 497 EXPECT_EQ(STATUS_TRUE, this->last_status_); |
| 447 | 498 |
| 448 ClearResults(); | 499 this->ClearResults(); |
| 449 | 500 |
| 450 // Close the store first to ensure file lock is removed. | 501 // Close the store first to ensure file lock is removed. |
| 451 store.reset(); | 502 store.reset(); |
| 452 store = BuildStore(); | 503 store = this->BuildStore(); |
| 453 PumpLoop(); | 504 this->PumpLoop(); |
| 454 | 505 |
| 455 // One of the pages was busted, so only expect one page. | 506 // One of the pages was busted, so only expect one page. |
| 456 EXPECT_EQ(LOAD, last_called_callback_); | 507 EXPECT_EQ(LOAD, this->last_called_callback_); |
| 457 EXPECT_EQ(STATUS_FALSE, last_status_); | 508 EXPECT_EQ(STATUS_FALSE, this->last_status_); |
| 458 } | 509 } |
| 459 | 510 |
| 460 TEST_F(OfflinePageMetadataStoreImplTest, UpgradeStoreFromBookmarkIdToClientId) { | 511 TEST_F(OfflinePageMetadataStoreImplTest, UpgradeStoreFromBookmarkIdToClientId) { |
| 461 scoped_ptr<OfflinePageMetadataStoreImpl> store(BuildStore()); | 512 scoped_ptr<OfflinePageMetadataStore> store(BuildStore()); |
| 462 | 513 |
| 463 // Manually write a page referring to legacy bookmark id. | 514 // Manually write a page referring to legacy bookmark id. |
| 464 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> | 515 scoped_ptr<leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector> |
| 465 entries_to_save( | 516 entries_to_save( |
| 466 new leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); | 517 new leveldb_proto::ProtoDatabase<OfflinePageEntry>::KeyEntryVector()); |
| 467 | 518 |
| 468 OfflinePageEntry offline_page_proto; | 519 OfflinePageEntry offline_page_proto; |
| 469 offline_page_proto.set_deprecated_bookmark_id(1LL); | 520 offline_page_proto.set_deprecated_bookmark_id(1LL); |
| 470 offline_page_proto.set_version(1); | 521 offline_page_proto.set_version(1); |
| 471 offline_page_proto.set_url(kTestURL); | 522 offline_page_proto.set_url(kTestURL); |
| 472 offline_page_proto.set_file_path("/foo/bar"); | 523 offline_page_proto.set_file_path("/foo/bar"); |
| 473 entries_to_save->push_back(std::make_pair("1", offline_page_proto)); | 524 entries_to_save->push_back(std::make_pair("1", offline_page_proto)); |
| 474 | 525 |
| 475 UpdateStoreEntries(store.get(), std::move(entries_to_save)); | 526 UpdateStoreEntries((OfflinePageMetadataStoreImpl*)store.get(), |
|
Scott Hess - ex-Googler
2016/04/25 19:57:55
Also here.
| |
| 527 std::move(entries_to_save)); | |
| 476 PumpLoop(); | 528 PumpLoop(); |
| 477 | 529 |
| 478 EXPECT_EQ(ADD, last_called_callback_); | 530 EXPECT_EQ(ADD, last_called_callback_); |
| 479 EXPECT_EQ(STATUS_TRUE, last_status_); | 531 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 480 | 532 |
| 481 ClearResults(); | 533 ClearResults(); |
| 482 | 534 |
| 483 // Close the store first to ensure file lock is removed. | 535 // Close the store first to ensure file lock is removed. |
| 484 store.reset(); | 536 store.reset(); |
| 485 store = BuildStore(); | 537 store = BuildStore(); |
| 486 PumpLoop(); | 538 PumpLoop(); |
| 487 | 539 |
| 488 // The page should be upgraded with new Client ID format. | 540 // The page should be upgraded with new Client ID format. |
| 489 EXPECT_EQ(LOAD, last_called_callback_); | 541 EXPECT_EQ(LOAD, last_called_callback_); |
| 490 EXPECT_EQ(STATUS_TRUE, last_status_); | 542 EXPECT_EQ(STATUS_TRUE, last_status_); |
| 491 EXPECT_EQ(1U, offline_pages_.size()); | 543 EXPECT_EQ(1U, offline_pages_.size()); |
| 492 EXPECT_TRUE(offline_pages_[0].offline_id != 0); | 544 EXPECT_TRUE(offline_pages_[0].offline_id != 0); |
| 493 EXPECT_EQ(offline_pages::BOOKMARK_NAMESPACE, | 545 EXPECT_EQ(offline_pages::BOOKMARK_NAMESPACE, |
| 494 offline_pages_[0].client_id.name_space); | 546 offline_pages_[0].client_id.name_space); |
| 495 EXPECT_EQ(base::Int64ToString(offline_page_proto.deprecated_bookmark_id()), | 547 EXPECT_EQ(base::Int64ToString(offline_page_proto.deprecated_bookmark_id()), |
| 496 offline_pages_[0].client_id.id); | 548 offline_pages_[0].client_id.id); |
| 497 EXPECT_EQ(GURL(kTestURL), offline_pages_[0].url); | 549 EXPECT_EQ(GURL(kTestURL), offline_pages_[0].url); |
| 498 EXPECT_EQ(offline_page_proto.version(), offline_pages_[0].version); | 550 EXPECT_EQ(offline_page_proto.version(), offline_pages_[0].version); |
| 499 EXPECT_EQ(offline_page_proto.file_path(), | 551 EXPECT_EQ(offline_page_proto.file_path(), |
| 500 offline_pages_[0].file_path.MaybeAsASCII()); | 552 offline_pages_[0].file_path.MaybeAsASCII()); |
| 501 } | 553 } |
| 502 | 554 |
| 503 } // namespace offline_pages | 555 } // namespace offline_pages |
| OLD | NEW |