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

Side by Side Diff: components/dom_distiller/core/dom_distiller_store_unittest.cc

Issue 1879613003: Convert //components/dom_distiller from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/dom_distiller/core/dom_distiller_store.h" 5 #include "components/dom_distiller/core/dom_distiller_store.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/ptr_util.h"
13 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
14 #include "base/run_loop.h" 16 #include "base/run_loop.h"
15 #include "base/time/time.h" 17 #include "base/time/time.h"
16 #include "components/dom_distiller/core/article_entry.h" 18 #include "components/dom_distiller/core/article_entry.h"
17 #include "components/dom_distiller/core/dom_distiller_test_util.h" 19 #include "components/dom_distiller/core/dom_distiller_test_util.h"
18 #include "components/leveldb_proto/testing/fake_db.h" 20 #include "components/leveldb_proto/testing/fake_db.h"
19 #include "sync/api/attachments/attachment_id.h" 21 #include "sync/api/attachments/attachment_id.h"
20 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h" 22 #include "sync/internal_api/public/attachments/attachment_service_proxy_for_test .h"
21 #include "sync/protocol/sync.pb.h" 23 #include "sync/protocol/sync.pb.h"
22 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 void CreateStore() { 149 void CreateStore() {
148 fake_db_ = new FakeDB<ArticleEntry>(&db_model_); 150 fake_db_ = new FakeDB<ArticleEntry>(&db_model_);
149 store_.reset(test::util::CreateStoreWithFakeDB(fake_db_, store_model_)); 151 store_.reset(test::util::CreateStoreWithFakeDB(fake_db_, store_model_));
150 } 152 }
151 153
152 void StartSyncing() { 154 void StartSyncing() {
153 fake_sync_processor_ = new FakeSyncChangeProcessor(&sync_model_); 155 fake_sync_processor_ = new FakeSyncChangeProcessor(&sync_model_);
154 156
155 store_->MergeDataAndStartSyncing( 157 store_->MergeDataAndStartSyncing(
156 kDomDistillerModelType, SyncDataFromEntryMap(sync_model_), 158 kDomDistillerModelType, SyncDataFromEntryMap(sync_model_),
157 make_scoped_ptr<SyncChangeProcessor>(fake_sync_processor_), 159 base::WrapUnique<SyncChangeProcessor>(fake_sync_processor_),
158 scoped_ptr<SyncErrorFactory>(new FakeSyncErrorFactory())); 160 std::unique_ptr<SyncErrorFactory>(new FakeSyncErrorFactory()));
159 } 161 }
160 162
161 protected: 163 protected:
162 SyncData CreateSyncData(const ArticleEntry& entry) { 164 SyncData CreateSyncData(const ArticleEntry& entry) {
163 EntitySpecifics specifics = SpecificsFromEntry(entry); 165 EntitySpecifics specifics = SpecificsFromEntry(entry);
164 return SyncData::CreateRemoteData( 166 return SyncData::CreateRemoteData(
165 next_sync_id_++, specifics, Time::UnixEpoch(), 167 next_sync_id_++, specifics, Time::UnixEpoch(),
166 syncer::AttachmentIdList(), 168 syncer::AttachmentIdList(),
167 syncer::AttachmentServiceProxyForTest::Create()); 169 syncer::AttachmentServiceProxyForTest::Create());
168 } 170 }
169 171
170 SyncDataList SyncDataFromEntryMap(const EntryMap& model) { 172 SyncDataList SyncDataFromEntryMap(const EntryMap& model) {
171 SyncDataList data; 173 SyncDataList data;
172 for (EntryMap::const_iterator it = model.begin(); it != model.end(); ++it) { 174 for (EntryMap::const_iterator it = model.begin(); it != model.end(); ++it) {
173 data.push_back(CreateSyncData(it->second)); 175 data.push_back(CreateSyncData(it->second));
174 } 176 }
175 return data; 177 return data;
176 } 178 }
177 179
178 base::MessageLoop message_loop_; 180 base::MessageLoop message_loop_;
179 181
180 EntryMap db_model_; 182 EntryMap db_model_;
181 EntryMap sync_model_; 183 EntryMap sync_model_;
182 FakeDB<ArticleEntry>::EntryMap store_model_; 184 FakeDB<ArticleEntry>::EntryMap store_model_;
183 185
184 scoped_ptr<DomDistillerStore> store_; 186 std::unique_ptr<DomDistillerStore> store_;
185 187
186 // Both owned by |store_|. 188 // Both owned by |store_|.
187 FakeDB<ArticleEntry>* fake_db_; 189 FakeDB<ArticleEntry>* fake_db_;
188 FakeSyncChangeProcessor* fake_sync_processor_; 190 FakeSyncChangeProcessor* fake_sync_processor_;
189 191
190 int64_t next_sync_id_; 192 int64_t next_sync_id_;
191 }; 193 };
192 194
193 AssertionResult AreEntriesEqual(const DomDistillerStore::EntryVector& entries, 195 AssertionResult AreEntriesEqual(const DomDistillerStore::EntryVector& entries,
194 EntryMap expected_entries) { 196 EntryMap expected_entries) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 store_->RemoveEntry(updated_entry); 311 store_->RemoveEntry(updated_entry);
310 EXPECT_FALSE(store_->UpdateEntry(updated_entry)); 312 EXPECT_FALSE(store_->UpdateEntry(updated_entry));
311 EXPECT_FALSE(store_->UpdateEntry(GetSampleEntry(0))); 313 EXPECT_FALSE(store_->UpdateEntry(GetSampleEntry(0)));
312 } 314 }
313 315
314 class MockAttachmentsCallbacks { 316 class MockAttachmentsCallbacks {
315 public: 317 public:
316 MOCK_METHOD2(Get, void(bool, ArticleAttachmentsData*)); 318 MOCK_METHOD2(Get, void(bool, ArticleAttachmentsData*));
317 MOCK_METHOD1(Update, void(bool)); 319 MOCK_METHOD1(Update, void(bool));
318 320
319 void GetImpl(bool success, scoped_ptr<ArticleAttachmentsData> attachments) { 321 void GetImpl(bool success,
322 std::unique_ptr<ArticleAttachmentsData> attachments) {
320 Get(success, attachments.get()); 323 Get(success, attachments.get());
321 } 324 }
322 325
323 DomDistillerStore::UpdateAttachmentsCallback UpdateCallback() { 326 DomDistillerStore::UpdateAttachmentsCallback UpdateCallback() {
324 return base::Bind(&MockAttachmentsCallbacks::Update, 327 return base::Bind(&MockAttachmentsCallbacks::Update,
325 base::Unretained(this)); 328 base::Unretained(this));
326 } 329 }
327 330
328 DomDistillerStore::GetAttachmentsCallback GetCallback() { 331 DomDistillerStore::GetAttachmentsCallback GetCallback() {
329 return base::Bind(&MockAttachmentsCallbacks::GetImpl, 332 return base::Bind(&MockAttachmentsCallbacks::GetImpl,
(...skipping 14 matching lines...) Expand all
344 store_->GetAttachments(entry.entry_id(), callbacks.GetCallback()); 347 store_->GetAttachments(entry.entry_id(), callbacks.GetCallback());
345 EXPECT_CALL(callbacks, Get(false, _)); 348 EXPECT_CALL(callbacks, Get(false, _));
346 base::RunLoop().RunUntilIdle(); 349 base::RunLoop().RunUntilIdle();
347 350
348 ArticleAttachmentsData attachments, got_attachments; 351 ArticleAttachmentsData attachments, got_attachments;
349 DistilledArticleProto article_proto; 352 DistilledArticleProto article_proto;
350 article_proto.set_title("A title"); 353 article_proto.set_title("A title");
351 attachments.set_distilled_article(article_proto); 354 attachments.set_distilled_article(article_proto);
352 store_->UpdateAttachments( 355 store_->UpdateAttachments(
353 entry.entry_id(), 356 entry.entry_id(),
354 make_scoped_ptr(new ArticleAttachmentsData(attachments)), 357 base::WrapUnique(new ArticleAttachmentsData(attachments)),
355 callbacks.UpdateCallback()); 358 callbacks.UpdateCallback());
356 EXPECT_CALL(callbacks, Update(true)); 359 EXPECT_CALL(callbacks, Update(true));
357 base::RunLoop().RunUntilIdle(); 360 base::RunLoop().RunUntilIdle();
358 361
359 store_->GetAttachments(entry.entry_id(), callbacks.GetCallback()); 362 store_->GetAttachments(entry.entry_id(), callbacks.GetCallback());
360 EXPECT_CALL(callbacks, Get(true, _)) 363 EXPECT_CALL(callbacks, Get(true, _))
361 .WillOnce(SaveArgPointee<1>(&got_attachments)); 364 .WillOnce(SaveArgPointee<1>(&got_attachments));
362 base::RunLoop().RunUntilIdle(); 365 base::RunLoop().RunUntilIdle();
363 366
364 EXPECT_EQ(attachments.ToString(), 367 EXPECT_EQ(attachments.ToString(),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 AddEntry(GetSampleEntry(3), &expected_model); 505 AddEntry(GetSampleEntry(3), &expected_model);
503 AddEntry(GetSampleEntry(4), &expected_model); 506 AddEntry(GetSampleEntry(4), &expected_model);
504 507
505 CreateStore(); 508 CreateStore();
506 509
507 fake_db_->InitCallback(true); 510 fake_db_->InitCallback(true);
508 fake_db_->LoadCallback(true); 511 fake_db_->LoadCallback(true);
509 512
510 FakeDB<ArticleEntry>* other_fake_db = 513 FakeDB<ArticleEntry>* other_fake_db =
511 new FakeDB<ArticleEntry>(&other_db_model); 514 new FakeDB<ArticleEntry>(&other_db_model);
512 scoped_ptr<DomDistillerStore> owned_other_store(new DomDistillerStore( 515 std::unique_ptr<DomDistillerStore> owned_other_store(new DomDistillerStore(
513 scoped_ptr<leveldb_proto::ProtoDatabase<ArticleEntry> >(other_fake_db), 516 std::unique_ptr<leveldb_proto::ProtoDatabase<ArticleEntry>>(
517 other_fake_db),
514 std::vector<ArticleEntry>(), 518 std::vector<ArticleEntry>(),
515 base::FilePath(FILE_PATH_LITERAL("/fake/other/path")))); 519 base::FilePath(FILE_PATH_LITERAL("/fake/other/path"))));
516 DomDistillerStore* other_store = owned_other_store.get(); 520 DomDistillerStore* other_store = owned_other_store.get();
517 other_fake_db->InitCallback(true); 521 other_fake_db->InitCallback(true);
518 other_fake_db->LoadCallback(true); 522 other_fake_db->LoadCallback(true);
519 523
520 EXPECT_FALSE(AreEntriesEqual(store_->GetEntries(), expected_model)); 524 EXPECT_FALSE(AreEntriesEqual(store_->GetEntries(), expected_model));
521 EXPECT_FALSE(AreEntriesEqual(other_store->GetEntries(), expected_model)); 525 EXPECT_FALSE(AreEntriesEqual(other_store->GetEntries(), expected_model));
522 ASSERT_TRUE(AreEntriesEqual(other_store->GetEntries(), other_db_model)); 526 ASSERT_TRUE(AreEntriesEqual(other_store->GetEntries(), other_db_model));
523 527
524 FakeSyncErrorFactory* other_error_factory = new FakeSyncErrorFactory(); 528 FakeSyncErrorFactory* other_error_factory = new FakeSyncErrorFactory();
525 store_->MergeDataAndStartSyncing( 529 store_->MergeDataAndStartSyncing(
526 kDomDistillerModelType, SyncDataFromEntryMap(other_db_model), 530 kDomDistillerModelType, SyncDataFromEntryMap(other_db_model),
527 std::move(owned_other_store), 531 std::move(owned_other_store),
528 make_scoped_ptr<SyncErrorFactory>(other_error_factory)); 532 base::WrapUnique<SyncErrorFactory>(other_error_factory));
529 533
530 EXPECT_TRUE(AreEntriesEqual(store_->GetEntries(), expected_model)); 534 EXPECT_TRUE(AreEntriesEqual(store_->GetEntries(), expected_model));
531 EXPECT_TRUE(AreEntriesEqual(other_store->GetEntries(), expected_model)); 535 EXPECT_TRUE(AreEntriesEqual(other_store->GetEntries(), expected_model));
532 } 536 }
533 537
534 TEST_F(DomDistillerStoreTest, TestObserver) { 538 TEST_F(DomDistillerStoreTest, TestObserver) {
535 CreateStore(); 539 CreateStore();
536 MockDistillerObserver observer; 540 MockDistillerObserver observer;
537 store_->AddObserver(&observer); 541 store_->AddObserver(&observer);
538 fake_db_->InitCallback(true); 542 fake_db_->InitCallback(true);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 expected_updates.push_back(update); 582 expected_updates.push_back(update);
579 EXPECT_CALL(observer, ArticleEntriesUpdated( 583 EXPECT_CALL(observer, ArticleEntriesUpdated(
580 test::util::HasExpectedUpdates(expected_updates))); 584 test::util::HasExpectedUpdates(expected_updates)));
581 585
582 FakeSyncErrorFactory* fake_error_factory = new FakeSyncErrorFactory(); 586 FakeSyncErrorFactory* fake_error_factory = new FakeSyncErrorFactory();
583 EntryMap fake_model; 587 EntryMap fake_model;
584 FakeSyncChangeProcessor* fake_sync_change_processor = 588 FakeSyncChangeProcessor* fake_sync_change_processor =
585 new FakeSyncChangeProcessor(&fake_model); 589 new FakeSyncChangeProcessor(&fake_model);
586 store_->MergeDataAndStartSyncing( 590 store_->MergeDataAndStartSyncing(
587 kDomDistillerModelType, change_data, 591 kDomDistillerModelType, change_data,
588 make_scoped_ptr<SyncChangeProcessor>(fake_sync_change_processor), 592 base::WrapUnique<SyncChangeProcessor>(fake_sync_change_processor),
589 make_scoped_ptr<SyncErrorFactory>(fake_error_factory)); 593 base::WrapUnique<SyncErrorFactory>(fake_error_factory));
590 } 594 }
591 595
592 } // namespace dom_distiller 596 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/dom_distiller_store.cc ('k') | components/dom_distiller/core/dom_distiller_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698