| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/reading_list/ios/reading_list_model.h" | 5 #include "components/reading_list/ios/reading_list_model.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #import "base/test/ios/wait_util.h" | 9 #import "base/test/ios/wait_util.h" |
| 10 #include "components/reading_list/ios/reading_list_model_impl.h" | 10 #include "components/reading_list/ios/reading_list_model_impl.h" |
| 11 #include "components/reading_list/ios/reading_list_model_storage.h" | 11 #include "components/reading_list/ios/reading_list_model_storage.h" |
| 12 #include "components/reading_list/ios/reading_list_store_delegate.h" | 12 #include "components/reading_list/ios/reading_list_store_delegate.h" |
| 13 #include "components/sync/model/metadata_change_list.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 const GURL callback_url("http://example.com"); | 18 const GURL callback_url("http://example.com"); |
| 18 const std::string callback_title("test title"); | 19 const std::string callback_title("test title"); |
| 19 | 20 |
| 20 class TestReadingListStorageObserver { | 21 class TestReadingListStorageObserver { |
| 21 public: | 22 public: |
| 22 virtual void ReadingListDidSaveEntry() = 0; | 23 virtual void ReadingListDidSaveEntry() = 0; |
| 23 virtual void ReadingListDidRemoveEntry() = 0; | 24 virtual void ReadingListDidRemoveEntry() = 0; |
| 24 }; | 25 }; |
| 25 | 26 |
| 26 class TestReadingListStorage : public ReadingListModelStorage { | 27 class TestReadingListStorage : public ReadingListModelStorage { |
| 27 public: | 28 public: |
| 28 TestReadingListStorage(TestReadingListStorageObserver* observer) | 29 TestReadingListStorage(TestReadingListStorageObserver* observer) |
| 29 : entries_(new ReadingListStoreDelegate::ReadingListEntries()), | 30 : ReadingListModelStorage( |
| 31 base::Bind(&syncer::ModelTypeChangeProcessor::Create), |
| 32 syncer::READING_LIST), |
| 33 entries_(new ReadingListStoreDelegate::ReadingListEntries()), |
| 30 observer_(observer) {} | 34 observer_(observer) {} |
| 31 | 35 |
| 32 void AddSampleEntries() { | 36 void AddSampleEntries() { |
| 33 // Adds timer and interlace read/unread entry creation to avoid having two | 37 // Adds timer and interlace read/unread entry creation to avoid having two |
| 34 // entries with the same creation timestamp. | 38 // entries with the same creation timestamp. |
| 35 ReadingListEntry unread_a(GURL("http://unread_a.com"), "unread_a"); | 39 ReadingListEntry unread_a(GURL("http://unread_a.com"), "unread_a"); |
| 36 entries_->insert( | 40 entries_->insert( |
| 37 std::make_pair(GURL("http://unread_a.com"), std::move(unread_a))); | 41 std::make_pair(GURL("http://unread_a.com"), std::move(unread_a))); |
| 38 base::test::ios::SpinRunLoopWithMinDelay( | 42 base::test::ios::SpinRunLoopWithMinDelay( |
| 39 base::TimeDelta::FromMilliseconds(5)); | 43 base::TimeDelta::FromMilliseconds(5)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 std::make_pair(GURL("http://unread_d.com"), std::move(unread_d))); | 80 std::make_pair(GURL("http://unread_d.com"), std::move(unread_d))); |
| 77 base::test::ios::SpinRunLoopWithMinDelay( | 81 base::test::ios::SpinRunLoopWithMinDelay( |
| 78 base::TimeDelta::FromMilliseconds(5)); | 82 base::TimeDelta::FromMilliseconds(5)); |
| 79 } | 83 } |
| 80 | 84 |
| 81 void SetReadingListModel(ReadingListModel* model, | 85 void SetReadingListModel(ReadingListModel* model, |
| 82 ReadingListStoreDelegate* delegate) override { | 86 ReadingListStoreDelegate* delegate) override { |
| 83 delegate->StoreLoaded(std::move(entries_)); | 87 delegate->StoreLoaded(std::move(entries_)); |
| 84 } | 88 } |
| 85 | 89 |
| 86 syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override { | |
| 87 return nullptr; | |
| 88 } | |
| 89 | |
| 90 std::unique_ptr<ScopedBatchUpdate> EnsureBatchCreated() override { | |
| 91 return std::unique_ptr<ScopedBatchUpdate>(); | |
| 92 } | |
| 93 | |
| 94 // Saves or updates an entry. If the entry is not yet in the database, it is | 90 // Saves or updates an entry. If the entry is not yet in the database, it is |
| 95 // created. | 91 // created. |
| 96 void SaveEntry(const ReadingListEntry& entry) override { | 92 void SaveEntry(const ReadingListEntry& entry) override { |
| 97 observer_->ReadingListDidSaveEntry(); | 93 observer_->ReadingListDidSaveEntry(); |
| 98 } | 94 } |
| 99 | 95 |
| 100 // Removed an entry from the storage. | 96 // Removes an entry from the storage. |
| 101 void RemoveEntry(const ReadingListEntry& entry) override { | 97 void RemoveEntry(const ReadingListEntry& entry) override { |
| 102 observer_->ReadingListDidRemoveEntry(); | 98 observer_->ReadingListDidRemoveEntry(); |
| 103 } | 99 } |
| 104 | 100 |
| 101 std::unique_ptr<ScopedBatchUpdate> EnsureBatchCreated() override { |
| 102 return std::unique_ptr<ScopedBatchUpdate>(); |
| 103 } |
| 104 |
| 105 // Syncing is not used in this test class. |
| 106 std::unique_ptr<syncer::MetadataChangeList> CreateMetadataChangeList() |
| 107 override { |
| 108 NOTREACHED(); |
| 109 return std::unique_ptr<syncer::MetadataChangeList>(); |
| 110 } |
| 111 |
| 112 syncer::SyncError MergeSyncData( |
| 113 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, |
| 114 syncer::EntityDataMap entity_data_map) override { |
| 115 NOTREACHED(); |
| 116 return syncer::SyncError(); |
| 117 } |
| 118 |
| 119 syncer::SyncError ApplySyncChanges( |
| 120 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, |
| 121 syncer::EntityChangeList entity_changes) override { |
| 122 NOTREACHED(); |
| 123 return syncer::SyncError(); |
| 124 } |
| 125 |
| 126 void GetData(StorageKeyList storage_keys, DataCallback callback) override { |
| 127 NOTREACHED(); |
| 128 return; |
| 129 } |
| 130 |
| 131 void GetAllData(DataCallback callback) override { |
| 132 NOTREACHED(); |
| 133 return; |
| 134 } |
| 135 |
| 136 std::string GetClientTag(const syncer::EntityData& entity_data) override { |
| 137 NOTREACHED(); |
| 138 return ""; |
| 139 } |
| 140 |
| 141 std::string GetStorageKey(const syncer::EntityData& entity_data) override { |
| 142 NOTREACHED(); |
| 143 return ""; |
| 144 } |
| 145 |
| 105 private: | 146 private: |
| 106 std::unique_ptr<ReadingListStoreDelegate::ReadingListEntries> entries_; | 147 std::unique_ptr<ReadingListStoreDelegate::ReadingListEntries> entries_; |
| 107 TestReadingListStorageObserver* observer_; | 148 TestReadingListStorageObserver* observer_; |
| 108 }; | 149 }; |
| 109 | 150 |
| 110 class ReadingListModelTest : public ReadingListModelObserver, | 151 class ReadingListModelTest : public ReadingListModelObserver, |
| 111 public TestReadingListStorageObserver, | 152 public TestReadingListStorageObserver, |
| 112 public testing::Test { | 153 public testing::Test { |
| 113 public: | 154 public: |
| 114 ReadingListModelTest() | 155 ReadingListModelTest() |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 } | 634 } |
| 594 | 635 |
| 595 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. | 636 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. |
| 596 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { | 637 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { |
| 597 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 638 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 598 model_.reset(); | 639 model_.reset(); |
| 599 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0); | 640 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0); |
| 600 } | 641 } |
| 601 | 642 |
| 602 } // namespace | 643 } // namespace |
| OLD | NEW |