Chromium Code Reviews| 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 "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 const GURL callback_url("http://example.com"); | 16 const GURL callback_url("http://example.com"); |
| 17 const std::string callback_title("test title"); | 17 const std::string callback_title("test title"); |
| 18 | 18 |
| 19 class TestReadingListStorageObserver { | 19 class TestReadingListStorageObserver { |
| 20 public: | 20 public: |
| 21 virtual void ReadingListDidSaveEntry() = 0; | 21 virtual void ReadingListDidSaveEntry() = 0; |
| 22 virtual void ReadingListDidRemoveEntry() = 0; | 22 virtual void ReadingListDidRemoveEntry() = 0; |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 class TestReadingListStorage : public ReadingListModelStorage { | 25 class TestReadingListStorage : public ReadingListModelStorage { |
| 26 public: | 26 public: |
| 27 TestReadingListStorage(TestReadingListStorageObserver* observer) | 27 TestReadingListStorage(TestReadingListStorageObserver* observer) |
| 28 : read_(new std::vector<ReadingListEntry>()), | 28 : entries_(new ReadingListEntries()), observer_(observer) {} |
| 29 unread_(new std::vector<ReadingListEntry>()), | |
| 30 observer_(observer) {} | |
| 31 | 29 |
| 32 void AddSampleEntries() { | 30 void AddSampleEntries() { |
| 33 // Adds timer and interlace read/unread entry creation to avoid having two | 31 // Adds timer and interlace read/unread entry creation to avoid having two |
| 34 // entries with the same creation timestamp. | 32 // entries with the same creation timestamp. |
| 35 ReadingListEntry unread_a(GURL("http://unread_a.com"), "unread_a"); | 33 ReadingListEntry unread_a(GURL("http://unread_a.com"), "unread_a"); |
| 34 entries_->insert( | |
| 35 std::make_pair(GURL("http://unread_a.com"), std::move(unread_a))); | |
| 36 base::test::ios::SpinRunLoopWithMinDelay( | 36 base::test::ios::SpinRunLoopWithMinDelay( |
| 37 base::TimeDelta::FromMilliseconds(5)); | 37 base::TimeDelta::FromMilliseconds(5)); |
| 38 | |
| 38 ReadingListEntry read_a(GURL("http://read_a.com"), "read_a"); | 39 ReadingListEntry read_a(GURL("http://read_a.com"), "read_a"); |
| 40 read_a.SetRead(true); | |
| 41 entries_->insert( | |
| 42 std::make_pair(GURL("http://read_a.com"), std::move(read_a))); | |
| 39 base::test::ios::SpinRunLoopWithMinDelay( | 43 base::test::ios::SpinRunLoopWithMinDelay( |
| 40 base::TimeDelta::FromMilliseconds(5)); | 44 base::TimeDelta::FromMilliseconds(5)); |
| 45 | |
| 41 ReadingListEntry unread_b(GURL("http://unread_b.com"), "unread_b"); | 46 ReadingListEntry unread_b(GURL("http://unread_b.com"), "unread_b"); |
| 47 entries_->insert( | |
| 48 std::make_pair(GURL("http://unread_b.com"), std::move(unread_b))); | |
| 42 base::test::ios::SpinRunLoopWithMinDelay( | 49 base::test::ios::SpinRunLoopWithMinDelay( |
| 43 base::TimeDelta::FromMilliseconds(5)); | 50 base::TimeDelta::FromMilliseconds(5)); |
| 51 | |
| 44 ReadingListEntry read_b(GURL("http://read_b.com"), "read_b"); | 52 ReadingListEntry read_b(GURL("http://read_b.com"), "read_b"); |
| 53 read_b.SetRead(true); | |
| 54 entries_->insert( | |
| 55 std::make_pair(GURL("http://read_b.com"), std::move(read_b))); | |
| 45 base::test::ios::SpinRunLoopWithMinDelay( | 56 base::test::ios::SpinRunLoopWithMinDelay( |
| 46 base::TimeDelta::FromMilliseconds(5)); | 57 base::TimeDelta::FromMilliseconds(5)); |
| 58 | |
| 47 ReadingListEntry unread_c(GURL("http://unread_c.com"), "unread_c"); | 59 ReadingListEntry unread_c(GURL("http://unread_c.com"), "unread_c"); |
| 60 entries_->insert( | |
| 61 std::make_pair(GURL("http://unread_c.com"), std::move(unread_c))); | |
| 48 base::test::ios::SpinRunLoopWithMinDelay( | 62 base::test::ios::SpinRunLoopWithMinDelay( |
| 49 base::TimeDelta::FromMilliseconds(5)); | 63 base::TimeDelta::FromMilliseconds(5)); |
| 64 | |
| 50 ReadingListEntry read_c(GURL("http://read_c.com"), "read_c"); | 65 ReadingListEntry read_c(GURL("http://read_c.com"), "read_c"); |
| 66 read_c.SetRead(true); | |
| 67 entries_->insert( | |
| 68 std::make_pair(GURL("http://read_c.com"), std::move(read_c))); | |
| 51 base::test::ios::SpinRunLoopWithMinDelay( | 69 base::test::ios::SpinRunLoopWithMinDelay( |
| 52 base::TimeDelta::FromMilliseconds(5)); | 70 base::TimeDelta::FromMilliseconds(5)); |
| 71 | |
| 53 ReadingListEntry unread_d(GURL("http://unread_d.com"), "unread_d"); | 72 ReadingListEntry unread_d(GURL("http://unread_d.com"), "unread_d"); |
| 73 entries_->insert( | |
| 74 std::make_pair(GURL("http://unread_d.com"), std::move(unread_d))); | |
| 54 base::test::ios::SpinRunLoopWithMinDelay( | 75 base::test::ios::SpinRunLoopWithMinDelay( |
| 55 base::TimeDelta::FromMilliseconds(5)); | 76 base::TimeDelta::FromMilliseconds(5)); |
| 56 read_->push_back(std::move(read_c)); | |
| 57 read_->push_back(std::move(read_a)); | |
| 58 read_->push_back(std::move(read_b)); | |
| 59 | |
| 60 unread_->push_back(std::move(unread_a)); | |
| 61 unread_->push_back(std::move(unread_d)); | |
| 62 unread_->push_back(std::move(unread_c)); | |
| 63 unread_->push_back(std::move(unread_b)); | |
| 64 } | 77 } |
| 65 | 78 |
| 66 void SetReadingListModel(ReadingListModel* model, | 79 void SetReadingListModel(ReadingListModel* model, |
| 67 ReadingListStoreDelegate* delegate_) override { | 80 ReadingListStoreDelegate* delegate_) override { |
| 68 delegate_->StoreLoaded(std::move(unread_), std::move(read_)); | 81 delegate_->StoreLoaded(std::move(entries_)); |
| 69 } | 82 } |
| 70 | 83 |
| 71 syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override { | 84 syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override { |
| 72 return nullptr; | 85 return nullptr; |
| 73 } | 86 } |
| 74 | 87 |
| 75 std::unique_ptr<ScopedBatchUpdate> EnsureBatchCreated() override { | 88 std::unique_ptr<ScopedBatchUpdate> EnsureBatchCreated() override { |
| 76 return std::unique_ptr<ScopedBatchUpdate>(); | 89 return std::unique_ptr<ScopedBatchUpdate>(); |
| 77 } | 90 } |
| 78 | 91 |
| 79 // Saves or updates an entry. If the entry is not yet in the database, it is | 92 // Saves or updates an entry. If the entry is not yet in the database, it is |
| 80 // created. | 93 // created. |
| 81 void SaveEntry(const ReadingListEntry& entry, bool read) override { | 94 void SaveEntry(const ReadingListEntry& entry) override { |
| 82 observer_->ReadingListDidSaveEntry(); | 95 observer_->ReadingListDidSaveEntry(); |
| 83 } | 96 } |
| 84 | 97 |
| 85 // Removed an entry from the storage. | 98 // Removed an entry from the storage. |
| 86 void RemoveEntry(const ReadingListEntry& entry) override { | 99 void RemoveEntry(const ReadingListEntry& entry) override { |
| 87 observer_->ReadingListDidRemoveEntry(); | 100 observer_->ReadingListDidRemoveEntry(); |
| 88 } | 101 } |
| 89 | 102 |
| 90 private: | 103 private: |
| 91 std::unique_ptr<std::vector<ReadingListEntry>> read_; | 104 std::unique_ptr<ReadingListEntries> entries_; |
| 92 std::unique_ptr<std::vector<ReadingListEntry>> unread_; | |
| 93 TestReadingListStorageObserver* observer_; | 105 TestReadingListStorageObserver* observer_; |
| 94 }; | 106 }; |
| 95 | 107 |
| 96 class ReadingListModelTest : public ReadingListModelObserver, | 108 class ReadingListModelTest : public ReadingListModelObserver, |
| 97 public TestReadingListStorageObserver, | 109 public TestReadingListStorageObserver, |
| 98 public testing::Test { | 110 public testing::Test { |
| 99 public: | 111 public: |
| 100 ReadingListModelTest() | 112 ReadingListModelTest() |
| 101 : callback_called_(false), model_(new ReadingListModelImpl()) { | 113 : callback_called_(false), model_(new ReadingListModelImpl()) { |
| 102 ClearCounts(); | 114 ClearCounts(); |
| 103 model_->AddObserver(this); | 115 model_->AddObserver(this); |
| 104 } | 116 } |
| 105 ~ReadingListModelTest() override {} | 117 ~ReadingListModelTest() override {} |
| 106 | 118 |
| 107 void SetStorage(std::unique_ptr<TestReadingListStorage> storage) { | 119 void SetStorage(std::unique_ptr<TestReadingListStorage> storage) { |
| 108 model_ = | 120 model_ = |
| 109 base::MakeUnique<ReadingListModelImpl>(std::move(storage), nullptr); | 121 base::MakeUnique<ReadingListModelImpl>(std::move(storage), nullptr); |
| 110 ClearCounts(); | 122 ClearCounts(); |
| 111 model_->AddObserver(this); | 123 model_->AddObserver(this); |
| 112 } | 124 } |
| 113 | 125 |
| 114 void ClearCounts() { | 126 void ClearCounts() { |
| 115 observer_loaded_ = observer_started_batch_update_ = | 127 observer_loaded_ = observer_started_batch_update_ = |
| 116 observer_completed_batch_update_ = observer_deleted_ = | 128 observer_completed_batch_update_ = observer_deleted_ = |
| 117 observer_remove_unread_ = observer_remove_read_ = observer_move_ = | 129 observer_remove_ = observer_move_ = observer_add_ = |
| 118 observer_add_unread_ = observer_add_read_ = | 130 observer_did_add_ = observer_update_ = observer_did_apply_ = |
| 119 observer_update_unread_ = observer_update_read_ = | 131 storage_saved_ = storage_removed_ = 0; |
| 120 observer_did_apply_ = storage_saved_ = | |
| 121 storage_removed_ = 0; | |
| 122 } | 132 } |
| 123 | 133 |
| 124 void AssertObserverCount(int observer_loaded, | 134 void AssertObserverCount(int observer_loaded, |
| 125 int observer_started_batch_update, | 135 int observer_started_batch_update, |
| 126 int observer_completed_batch_update, | 136 int observer_completed_batch_update, |
| 127 int observer_deleted, | 137 int observer_deleted, |
| 128 int observer_remove_unread, | 138 int observer_remove, |
| 129 int observer_remove_read, | |
| 130 int observer_move, | 139 int observer_move, |
| 131 int observer_add_unread, | 140 int observer_add, |
| 132 int observer_add_read, | 141 int observer_update, |
| 133 int observer_update_unread, | |
| 134 int observer_update_read, | |
| 135 int observer_did_apply) { | 142 int observer_did_apply) { |
| 136 ASSERT_EQ(observer_loaded, observer_loaded_); | 143 ASSERT_EQ(observer_loaded, observer_loaded_); |
| 137 ASSERT_EQ(observer_started_batch_update, observer_started_batch_update_); | 144 ASSERT_EQ(observer_started_batch_update, observer_started_batch_update_); |
| 138 ASSERT_EQ(observer_completed_batch_update, | 145 ASSERT_EQ(observer_completed_batch_update, |
| 139 observer_completed_batch_update_); | 146 observer_completed_batch_update_); |
| 140 ASSERT_EQ(observer_deleted, observer_deleted_); | 147 ASSERT_EQ(observer_deleted, observer_deleted_); |
| 141 ASSERT_EQ(observer_remove_unread, observer_remove_unread_); | 148 ASSERT_EQ(observer_remove, observer_remove_); |
| 142 ASSERT_EQ(observer_remove_read, observer_remove_read_); | |
| 143 ASSERT_EQ(observer_move, observer_move_); | 149 ASSERT_EQ(observer_move, observer_move_); |
| 144 ASSERT_EQ(observer_add_unread, observer_add_unread_); | 150 // Add and did_add should be the same. |
| 145 ASSERT_EQ(observer_add_read, observer_add_read_); | 151 ASSERT_EQ(observer_add, observer_add_); |
| 146 ASSERT_EQ(observer_update_unread, observer_update_unread_); | 152 ASSERT_EQ(observer_add, observer_did_add_); |
| 147 ASSERT_EQ(observer_update_read, observer_update_read_); | 153 ASSERT_EQ(observer_update, observer_update_); |
| 148 ASSERT_EQ(observer_did_apply, observer_did_apply_); | 154 ASSERT_EQ(observer_did_apply, observer_did_apply_); |
| 149 } | 155 } |
| 150 | 156 |
| 151 void AssertStorageCount(int storage_saved, int storage_removed) { | 157 void AssertStorageCount(int storage_saved, int storage_removed) { |
| 152 ASSERT_EQ(storage_saved, storage_saved_); | 158 ASSERT_EQ(storage_saved, storage_saved_); |
| 153 ASSERT_EQ(storage_removed, storage_removed_); | 159 ASSERT_EQ(storage_removed, storage_removed_); |
| 154 } | 160 } |
| 155 | 161 |
| 156 // ReadingListModelObserver | 162 // ReadingListModelObserver |
| 157 void ReadingListModelLoaded(const ReadingListModel* model) override { | 163 void ReadingListModelLoaded(const ReadingListModel* model) override { |
| 158 observer_loaded_ += 1; | 164 observer_loaded_ += 1; |
| 159 } | 165 } |
| 160 void ReadingListModelBeganBatchUpdates( | 166 void ReadingListModelBeganBatchUpdates( |
| 161 const ReadingListModel* model) override { | 167 const ReadingListModel* model) override { |
| 162 observer_started_batch_update_ += 1; | 168 observer_started_batch_update_ += 1; |
| 163 } | 169 } |
| 164 void ReadingListModelCompletedBatchUpdates( | 170 void ReadingListModelCompletedBatchUpdates( |
| 165 const ReadingListModel* model) override { | 171 const ReadingListModel* model) override { |
| 166 observer_completed_batch_update_ += 1; | 172 observer_completed_batch_update_ += 1; |
| 167 } | 173 } |
| 168 void ReadingListModelBeingDeleted(const ReadingListModel* model) override { | 174 void ReadingListModelBeingDeleted(const ReadingListModel* model) override { |
| 169 observer_deleted_ += 1; | 175 observer_deleted_ += 1; |
| 170 } | 176 } |
| 171 void ReadingListWillRemoveUnreadEntry(const ReadingListModel* model, | 177 void ReadingListWillRemoveEntry(const ReadingListModel* model, |
| 172 size_t index) override { | 178 const GURL& url) override { |
| 173 observer_remove_unread_ += 1; | 179 observer_remove_ += 1; |
| 174 } | 180 } |
| 175 void ReadingListWillMoveEntry(const ReadingListModel* model, | 181 void ReadingListWillMoveEntry(const ReadingListModel* model, |
| 176 size_t index, | 182 const GURL& url) override { |
| 177 bool read) override { | |
| 178 observer_move_ += 1; | 183 observer_move_ += 1; |
| 179 } | 184 } |
| 180 void ReadingListWillRemoveReadEntry(const ReadingListModel* model, | 185 void ReadingListWillAddEntry(const ReadingListModel* model, |
| 181 size_t index) override { | 186 const ReadingListEntry& entry) override { |
| 182 observer_remove_read_ += 1; | 187 observer_add_ += 1; |
| 183 } | 188 } |
| 184 void ReadingListWillAddUnreadEntry(const ReadingListModel* model, | 189 void ReadingListDidAddEntry(const ReadingListModel* model, |
| 185 const ReadingListEntry& entry) override { | 190 const GURL& url) override { |
| 186 observer_add_unread_ += 1; | 191 observer_did_add_ += 1; |
| 187 } | 192 } |
| 188 void ReadingListWillAddReadEntry(const ReadingListModel* model, | 193 void ReadingListWillUpdateEntry(const ReadingListModel* model, |
| 189 const ReadingListEntry& entry) override { | 194 const GURL& url) override { |
| 190 observer_add_read_ += 1; | 195 observer_update_ += 1; |
| 191 } | |
| 192 void ReadingListWillUpdateUnreadEntry(const ReadingListModel* model, | |
| 193 size_t index) override { | |
| 194 observer_update_unread_ += 1; | |
| 195 } | |
| 196 void ReadingListWillUpdateReadEntry(const ReadingListModel* model, | |
| 197 size_t index) override { | |
| 198 observer_update_read_ += 1; | |
| 199 } | 196 } |
| 200 void ReadingListDidApplyChanges(ReadingListModel* model) override { | 197 void ReadingListDidApplyChanges(ReadingListModel* model) override { |
| 201 observer_did_apply_ += 1; | 198 observer_did_apply_ += 1; |
| 202 } | 199 } |
| 203 | 200 |
| 204 void ReadingListDidSaveEntry() override { storage_saved_ += 1; } | 201 void ReadingListDidSaveEntry() override { storage_saved_ += 1; } |
| 205 void ReadingListDidRemoveEntry() override { storage_removed_ += 1; } | 202 void ReadingListDidRemoveEntry() override { storage_removed_ += 1; } |
| 206 | 203 |
| 204 size_t UnreadSize() { | |
| 205 size_t size = 0; | |
| 206 for (const auto& iterator : *model_) { | |
| 207 if (!iterator.second.IsRead()) { | |
| 208 size++; | |
| 209 } | |
| 210 } | |
| 211 DCHECK_EQ(size, morel_->unread_size()); | |
|
noyau (Ping after 24h)
2016/11/28 15:30:15
morel?
| |
| 212 return size; | |
| 213 } | |
| 214 | |
| 215 size_t ReadSize() { | |
| 216 size_t size = 0; | |
| 217 for (const auto& iterator : *model_) { | |
| 218 if (iterator.second.IsRead()) { | |
| 219 size++; | |
| 220 } | |
| 221 } | |
| 222 return size; | |
| 223 } | |
| 224 | |
| 207 void Callback(const ReadingListEntry& entry) { | 225 void Callback(const ReadingListEntry& entry) { |
| 208 EXPECT_EQ(callback_url, entry.URL()); | 226 EXPECT_EQ(callback_url, entry.URL()); |
| 209 EXPECT_EQ(callback_title, entry.Title()); | 227 EXPECT_EQ(callback_title, entry.Title()); |
| 210 callback_called_ = true; | 228 callback_called_ = true; |
| 211 } | 229 } |
| 212 | 230 |
| 213 bool CallbackCalled() { return callback_called_; } | 231 bool CallbackCalled() { return callback_called_; } |
| 214 | 232 |
| 215 protected: | 233 protected: |
| 216 int observer_loaded_; | 234 int observer_loaded_; |
| 217 int observer_started_batch_update_; | 235 int observer_started_batch_update_; |
| 218 int observer_completed_batch_update_; | 236 int observer_completed_batch_update_; |
| 219 int observer_deleted_; | 237 int observer_deleted_; |
| 220 int observer_remove_unread_; | 238 int observer_remove_; |
| 221 int observer_remove_read_; | |
| 222 int observer_move_; | 239 int observer_move_; |
| 223 int observer_add_unread_; | 240 int observer_add_; |
| 224 int observer_add_read_; | 241 int observer_did_add_; |
| 225 int observer_update_unread_; | 242 int observer_update_; |
| 226 int observer_update_read_; | |
| 227 int observer_did_apply_; | 243 int observer_did_apply_; |
| 228 int storage_saved_; | 244 int storage_saved_; |
| 229 int storage_removed_; | 245 int storage_removed_; |
| 230 bool callback_called_; | 246 bool callback_called_; |
| 231 | 247 |
| 232 std::unique_ptr<ReadingListModelImpl> model_; | 248 std::unique_ptr<ReadingListModelImpl> model_; |
| 233 }; | 249 }; |
| 234 | 250 |
| 235 TEST_F(ReadingListModelTest, EmptyLoaded) { | 251 TEST_F(ReadingListModelTest, EmptyLoaded) { |
| 236 EXPECT_TRUE(model_->loaded()); | 252 EXPECT_TRUE(model_->loaded()); |
| 237 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 253 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 238 EXPECT_EQ(0ul, model_->unread_size()); | 254 EXPECT_EQ(0ul, UnreadSize()); |
| 239 EXPECT_EQ(0ul, model_->read_size()); | 255 EXPECT_EQ(0ul, ReadSize()); |
| 240 model_->Shutdown(); | 256 model_->Shutdown(); |
| 241 EXPECT_FALSE(model_->loaded()); | 257 EXPECT_FALSE(model_->loaded()); |
| 242 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); | 258 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0); |
| 243 } | 259 } |
| 244 | 260 |
| 245 TEST_F(ReadingListModelTest, ModelLoaded) { | 261 TEST_F(ReadingListModelTest, ModelLoaded) { |
| 246 ClearCounts(); | 262 ClearCounts(); |
| 247 auto storage = base::MakeUnique<TestReadingListStorage>(this); | 263 auto storage = base::MakeUnique<TestReadingListStorage>(this); |
| 248 storage->AddSampleEntries(); | 264 storage->AddSampleEntries(); |
| 249 SetStorage(std::move(storage)); | 265 SetStorage(std::move(storage)); |
| 250 | 266 |
| 251 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 267 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 252 EXPECT_EQ(model_->read_size(), 3u); | 268 std::map<GURL, std::string> loaded_entries; |
| 253 EXPECT_EQ(model_->GetReadEntryAtIndex(0).Title(), "read_c"); | 269 int size = 0; |
| 254 EXPECT_EQ(model_->GetReadEntryAtIndex(1).Title(), "read_b"); | 270 for (const auto& iterator : *model_) { |
| 255 EXPECT_EQ(model_->GetReadEntryAtIndex(2).Title(), "read_a"); | 271 size++; |
| 256 | 272 loaded_entries[iterator.first] = iterator.second.Title(); |
| 257 EXPECT_EQ(model_->unread_size(), 4u); | 273 } |
| 258 EXPECT_EQ(model_->GetUnreadEntryAtIndex(0).Title(), "unread_d"); | 274 EXPECT_EQ(size, 7); |
| 259 EXPECT_EQ(model_->GetUnreadEntryAtIndex(1).Title(), "unread_c"); | 275 EXPECT_EQ(loaded_entries[GURL("http://unread_a.com")], "unread_a"); |
| 260 EXPECT_EQ(model_->GetUnreadEntryAtIndex(2).Title(), "unread_b"); | 276 EXPECT_EQ(loaded_entries[GURL("http://unread_b.com")], "unread_b"); |
| 261 EXPECT_EQ(model_->GetUnreadEntryAtIndex(3).Title(), "unread_a"); | 277 EXPECT_EQ(loaded_entries[GURL("http://unread_c.com")], "unread_c"); |
| 278 EXPECT_EQ(loaded_entries[GURL("http://unread_d.com")], "unread_d"); | |
| 279 EXPECT_EQ(loaded_entries[GURL("http://read_a.com")], "read_a"); | |
| 280 EXPECT_EQ(loaded_entries[GURL("http://read_b.com")], "read_b"); | |
| 281 EXPECT_EQ(loaded_entries[GURL("http://read_c.com")], "read_c"); | |
| 262 } | 282 } |
| 263 | 283 |
| 264 TEST_F(ReadingListModelTest, AddEntry) { | 284 TEST_F(ReadingListModelTest, AddEntry) { |
| 265 auto storage = base::MakeUnique<TestReadingListStorage>(this); | 285 auto storage = base::MakeUnique<TestReadingListStorage>(this); |
| 266 SetStorage(std::move(storage)); | 286 SetStorage(std::move(storage)); |
| 267 ClearCounts(); | 287 ClearCounts(); |
| 268 | 288 |
| 269 const ReadingListEntry& entry = | 289 const ReadingListEntry& entry = |
| 270 model_->AddEntry(GURL("http://example.com"), "\n \tsample Test "); | 290 model_->AddEntry(GURL("http://example.com"), "\n \tsample Test "); |
| 271 EXPECT_EQ(GURL("http://example.com"), entry.URL()); | 291 EXPECT_EQ(GURL("http://example.com"), entry.URL()); |
| 272 EXPECT_EQ("sample Test", entry.Title()); | 292 EXPECT_EQ("sample Test", entry.Title()); |
| 273 | 293 |
| 274 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1); | 294 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 1); |
| 275 AssertStorageCount(1, 0); | 295 AssertStorageCount(1, 0); |
| 276 EXPECT_EQ(1ul, model_->unread_size()); | 296 EXPECT_EQ(1ul, UnreadSize()); |
| 277 EXPECT_EQ(0ul, model_->read_size()); | 297 EXPECT_EQ(0ul, ReadSize()); |
| 278 EXPECT_TRUE(model_->HasUnseenEntries()); | 298 EXPECT_TRUE(model_->HasUnseenEntries()); |
| 279 | 299 |
| 280 const ReadingListEntry& other_entry = model_->GetUnreadEntryAtIndex(0); | 300 const ReadingListEntry* other_entry = |
| 281 EXPECT_EQ(GURL("http://example.com"), other_entry.URL()); | 301 model_->GetEntryByURL(GURL("http://example.com")); |
| 282 EXPECT_EQ("sample Test", other_entry.Title()); | 302 EXPECT_NE(other_entry, nullptr); |
| 303 EXPECT_FALSE(other_entry->IsRead()); | |
| 304 EXPECT_EQ(GURL("http://example.com"), other_entry->URL()); | |
| 305 EXPECT_EQ("sample Test", other_entry->Title()); | |
| 283 } | 306 } |
| 284 | 307 |
| 285 TEST_F(ReadingListModelTest, SyncAddEntry) { | 308 TEST_F(ReadingListModelTest, SyncAddEntry) { |
| 286 auto storage = base::MakeUnique<TestReadingListStorage>(this); | 309 auto storage = base::MakeUnique<TestReadingListStorage>(this); |
| 287 SetStorage(std::move(storage)); | 310 SetStorage(std::move(storage)); |
| 288 auto entry = | 311 auto entry = |
| 289 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); | 312 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); |
| 313 entry->SetRead(true); | |
| 290 ClearCounts(); | 314 ClearCounts(); |
| 291 | 315 |
| 292 model_->SyncAddEntry(std::move(entry), true); | 316 model_->SyncAddEntry(std::move(entry)); |
| 293 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1); | 317 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 1); |
| 294 AssertStorageCount(0, 0); | 318 AssertStorageCount(0, 0); |
| 295 ASSERT_EQ(model_->unread_size(), 0u); | 319 EXPECT_EQ(0ul, UnreadSize()); |
| 296 ASSERT_EQ(model_->read_size(), 1u); | 320 EXPECT_EQ(1ul, ReadSize()); |
| 297 ClearCounts(); | 321 ClearCounts(); |
| 298 } | 322 } |
| 299 | 323 |
| 300 TEST_F(ReadingListModelTest, SyncMergeEntry) { | 324 TEST_F(ReadingListModelTest, SyncMergeEntry) { |
| 301 auto storage = base::MakeUnique<TestReadingListStorage>(this); | 325 auto storage = base::MakeUnique<TestReadingListStorage>(this); |
| 302 SetStorage(std::move(storage)); | 326 SetStorage(std::move(storage)); |
| 303 model_->AddEntry(GURL("http://example.com"), "sample"); | 327 model_->AddEntry(GURL("http://example.com"), "sample"); |
| 304 model_->SetEntryDistilledPath(GURL("http://example.com"), | 328 model_->SetEntryDistilledPath(GURL("http://example.com"), |
| 305 base::FilePath("distilled/page.html")); | 329 base::FilePath("distilled/page.html")); |
| 306 const ReadingListEntry* local_entry = | 330 const ReadingListEntry* local_entry = |
| 307 model_->GetEntryFromURL(GURL("http://example.com"), nullptr); | 331 model_->GetEntryByURL(GURL("http://example.com")); |
| 308 int64_t local_update_time = local_entry->UpdateTime(); | 332 int64_t local_update_time = local_entry->UpdateTime(); |
| 309 | 333 |
| 310 base::test::ios::SpinRunLoopWithMinDelay( | 334 base::test::ios::SpinRunLoopWithMinDelay( |
| 311 base::TimeDelta::FromMilliseconds(10)); | 335 base::TimeDelta::FromMilliseconds(10)); |
| 312 auto sync_entry = | 336 auto sync_entry = |
| 313 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); | 337 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); |
| 338 sync_entry->SetRead(true); | |
| 314 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); | 339 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); |
| 315 int64_t sync_update_time = sync_entry->UpdateTime(); | 340 int64_t sync_update_time = sync_entry->UpdateTime(); |
| 316 EXPECT_TRUE(sync_entry->DistilledPath().empty()); | 341 EXPECT_TRUE(sync_entry->DistilledPath().empty()); |
| 317 | 342 |
| 318 EXPECT_EQ(model_->unread_size(), 1u); | 343 EXPECT_EQ(1ul, UnreadSize()); |
| 319 EXPECT_EQ(model_->read_size(), 0u); | 344 EXPECT_EQ(0ul, ReadSize()); |
| 320 | 345 |
| 321 ReadingListEntry* merged_entry = | 346 ReadingListEntry* merged_entry = |
| 322 model_->SyncMergeEntry(std::move(sync_entry), true); | 347 model_->SyncMergeEntry(std::move(sync_entry)); |
| 323 EXPECT_EQ(model_->unread_size(), 0u); | 348 EXPECT_EQ(0ul, UnreadSize()); |
| 324 EXPECT_EQ(model_->read_size(), 1u); | 349 EXPECT_EQ(1ul, ReadSize()); |
| 325 EXPECT_EQ(merged_entry->DistilledPath(), | 350 EXPECT_EQ(merged_entry->DistilledPath(), |
| 326 base::FilePath("distilled/page.html")); | 351 base::FilePath("distilled/page.html")); |
| 327 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time); | 352 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time); |
| 328 } | 353 } |
| 329 | 354 |
| 330 TEST_F(ReadingListModelTest, RemoveEntryByUrl) { | 355 TEST_F(ReadingListModelTest, RemoveEntryByUrl) { |
| 331 auto storage = base::MakeUnique<TestReadingListStorage>(this); | 356 auto storage = base::MakeUnique<TestReadingListStorage>(this); |
| 332 SetStorage(std::move(storage)); | 357 SetStorage(std::move(storage)); |
| 333 model_->AddEntry(GURL("http://example.com"), "sample"); | 358 model_->AddEntry(GURL("http://example.com"), "sample"); |
| 334 ClearCounts(); | 359 ClearCounts(); |
| 335 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), | 360 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| 336 nullptr); | 361 EXPECT_EQ(1ul, UnreadSize()); |
| 337 EXPECT_EQ(model_->unread_size(), 1u); | 362 EXPECT_EQ(0ul, ReadSize()); |
| 338 model_->RemoveEntryByURL(GURL("http://example.com")); | 363 model_->RemoveEntryByURL(GURL("http://example.com")); |
| 339 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1); | 364 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1); |
| 340 AssertStorageCount(0, 1); | 365 AssertStorageCount(0, 1); |
| 341 EXPECT_EQ(model_->unread_size(), 0u); | 366 EXPECT_EQ(0ul, UnreadSize()); |
| 342 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), | 367 EXPECT_EQ(0ul, ReadSize()); |
| 343 nullptr); | 368 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| 344 | 369 |
| 345 model_->AddEntry(GURL("http://example.com"), "sample"); | 370 model_->AddEntry(GURL("http://example.com"), "sample"); |
| 346 model_->MarkReadByURL(GURL("http://example.com")); | 371 model_->SetReadStatus(GURL("http://example.com"), true); |
| 347 ClearCounts(); | 372 ClearCounts(); |
| 348 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), | 373 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| 349 nullptr); | 374 EXPECT_EQ(0ul, UnreadSize()); |
| 350 EXPECT_EQ(model_->read_size(), 1u); | 375 EXPECT_EQ(1ul, ReadSize()); |
| 351 model_->RemoveEntryByURL(GURL("http://example.com")); | 376 model_->RemoveEntryByURL(GURL("http://example.com")); |
| 352 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1); | 377 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1); |
| 353 AssertStorageCount(0, 1); | 378 AssertStorageCount(0, 1); |
| 354 EXPECT_EQ(model_->read_size(), 0u); | 379 EXPECT_EQ(0ul, UnreadSize()); |
| 355 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), | 380 EXPECT_EQ(0ul, ReadSize()); |
| 356 nullptr); | 381 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| 357 } | 382 } |
| 358 | 383 |
| 359 TEST_F(ReadingListModelTest, RemoveSyncEntryByUrl) { | 384 TEST_F(ReadingListModelTest, RemoveSyncEntryByUrl) { |
| 360 auto storage = base::MakeUnique<TestReadingListStorage>(this); | 385 auto storage = base::MakeUnique<TestReadingListStorage>(this); |
| 361 SetStorage(std::move(storage)); | 386 SetStorage(std::move(storage)); |
| 362 model_->AddEntry(GURL("http://example.com"), "sample"); | 387 model_->AddEntry(GURL("http://example.com"), "sample"); |
| 363 ClearCounts(); | 388 ClearCounts(); |
| 364 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), | 389 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| 365 nullptr); | 390 EXPECT_EQ(1ul, UnreadSize()); |
| 366 EXPECT_EQ(model_->unread_size(), 1u); | 391 EXPECT_EQ(0ul, ReadSize()); |
| 367 model_->SyncRemoveEntry(GURL("http://example.com")); | 392 model_->SyncRemoveEntry(GURL("http://example.com")); |
| 368 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1); | 393 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1); |
| 369 AssertStorageCount(0, 0); | 394 AssertStorageCount(0, 0); |
| 370 EXPECT_EQ(model_->unread_size(), 0u); | 395 EXPECT_EQ(0ul, UnreadSize()); |
| 371 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), | 396 EXPECT_EQ(0ul, ReadSize()); |
| 372 nullptr); | 397 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| 373 | 398 |
| 374 model_->AddEntry(GURL("http://example.com"), "sample"); | 399 model_->AddEntry(GURL("http://example.com"), "sample"); |
| 375 model_->MarkReadByURL(GURL("http://example.com")); | 400 model_->SetReadStatus(GURL("http://example.com"), true); |
| 376 ClearCounts(); | 401 ClearCounts(); |
| 377 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), | 402 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| 378 nullptr); | 403 EXPECT_EQ(0ul, UnreadSize()); |
| 379 EXPECT_EQ(model_->read_size(), 1u); | 404 EXPECT_EQ(1ul, ReadSize()); |
| 380 model_->SyncRemoveEntry(GURL("http://example.com")); | 405 model_->SyncRemoveEntry(GURL("http://example.com")); |
| 381 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1); | 406 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1); |
| 382 AssertStorageCount(0, 0); | 407 AssertStorageCount(0, 0); |
| 383 EXPECT_EQ(model_->read_size(), 0u); | 408 EXPECT_EQ(0ul, UnreadSize()); |
| 384 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), | 409 EXPECT_EQ(0ul, ReadSize()); |
| 385 nullptr); | 410 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| 386 } | 411 } |
| 387 | 412 |
| 388 TEST_F(ReadingListModelTest, ReadEntry) { | 413 TEST_F(ReadingListModelTest, ReadEntry) { |
| 389 model_->AddEntry(GURL("http://example.com"), "sample"); | 414 model_->AddEntry(GURL("http://example.com"), "sample"); |
| 390 | 415 |
| 391 ClearCounts(); | 416 ClearCounts(); |
| 392 model_->MarkReadByURL(GURL("http://example.com")); | 417 model_->SetReadStatus(GURL("http://example.com"), true); |
| 393 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); | 418 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 1); |
| 394 EXPECT_EQ(0ul, model_->unread_size()); | 419 EXPECT_EQ(0ul, UnreadSize()); |
| 395 EXPECT_EQ(1ul, model_->read_size()); | 420 EXPECT_EQ(1ul, ReadSize()); |
| 396 EXPECT_FALSE(model_->HasUnseenEntries()); | 421 EXPECT_FALSE(model_->HasUnseenEntries()); |
| 397 | 422 |
| 398 const ReadingListEntry& other_entry = model_->GetReadEntryAtIndex(0); | 423 const ReadingListEntry* other_entry = |
| 399 EXPECT_EQ(GURL("http://example.com"), other_entry.URL()); | 424 model_->GetEntryByURL(GURL("http://example.com")); |
| 400 EXPECT_EQ("sample", other_entry.Title()); | 425 EXPECT_NE(other_entry, nullptr); |
| 426 EXPECT_TRUE(other_entry->IsRead()); | |
| 427 EXPECT_EQ(GURL("http://example.com"), other_entry->URL()); | |
| 428 EXPECT_EQ("sample", other_entry->Title()); | |
| 401 } | 429 } |
| 402 | 430 |
| 403 TEST_F(ReadingListModelTest, EntryFromURL) { | 431 TEST_F(ReadingListModelTest, EntryFromURL) { |
| 404 GURL url1("http://example.com"); | 432 GURL url1("http://example.com"); |
| 405 GURL url2("http://example2.com"); | 433 GURL url2("http://example2.com"); |
| 406 std::string entry1_title = "foo bar qux"; | 434 std::string entry1_title = "foo bar qux"; |
| 407 model_->AddEntry(url1, entry1_title); | 435 model_->AddEntry(url1, entry1_title); |
| 408 | 436 |
| 409 // Check call with nullptr |read| parameter. | 437 // Check call with nullptr |read| parameter. |
| 410 const ReadingListEntry* entry1 = model_->GetEntryFromURL(url1, nullptr); | 438 const ReadingListEntry* entry1 = model_->GetEntryByURL(url1); |
| 411 EXPECT_NE(nullptr, entry1); | 439 EXPECT_NE(nullptr, entry1); |
| 412 EXPECT_EQ(entry1_title, entry1->Title()); | 440 EXPECT_EQ(entry1_title, entry1->Title()); |
| 413 | 441 |
| 414 bool read; | 442 entry1 = model_->GetEntryByURL(url1); |
| 415 entry1 = model_->GetEntryFromURL(url1, &read); | |
| 416 EXPECT_NE(nullptr, entry1); | 443 EXPECT_NE(nullptr, entry1); |
| 417 EXPECT_EQ(entry1_title, entry1->Title()); | 444 EXPECT_EQ(entry1_title, entry1->Title()); |
| 418 EXPECT_EQ(read, false); | 445 EXPECT_EQ(entry1->IsRead(), false); |
| 419 model_->MarkReadByURL(url1); | 446 model_->SetReadStatus(url1, true); |
| 420 entry1 = model_->GetEntryFromURL(url1, &read); | 447 entry1 = model_->GetEntryByURL(url1); |
| 421 EXPECT_NE(nullptr, entry1); | 448 EXPECT_NE(nullptr, entry1); |
| 422 EXPECT_EQ(entry1_title, entry1->Title()); | 449 EXPECT_EQ(entry1_title, entry1->Title()); |
| 423 EXPECT_EQ(read, true); | 450 EXPECT_EQ(entry1->IsRead(), true); |
| 424 | 451 |
| 425 const ReadingListEntry* entry2 = model_->GetEntryFromURL(url2, &read); | 452 const ReadingListEntry* entry2 = model_->GetEntryByURL(url2); |
| 426 EXPECT_EQ(nullptr, entry2); | 453 EXPECT_EQ(nullptr, entry2); |
| 427 } | 454 } |
| 428 | 455 |
| 429 TEST_F(ReadingListModelTest, UnreadEntry) { | 456 TEST_F(ReadingListModelTest, UnreadEntry) { |
| 430 // Setup. | 457 // Setup. |
| 431 model_->AddEntry(GURL("http://example.com"), "sample"); | 458 model_->AddEntry(GURL("http://example.com"), "sample"); |
| 432 model_->MarkReadByURL(GURL("http://example.com")); | 459 model_->SetReadStatus(GURL("http://example.com"), true); |
| 433 ClearCounts(); | 460 ClearCounts(); |
| 434 ASSERT_EQ(0ul, model_->unread_size()); | 461 EXPECT_EQ(0ul, UnreadSize()); |
| 435 ASSERT_EQ(1ul, model_->read_size()); | 462 EXPECT_EQ(1ul, ReadSize()); |
| 436 | 463 |
| 437 // Action. | 464 // Action. |
| 438 model_->MarkUnreadByURL(GURL("http://example.com")); | 465 model_->SetReadStatus(GURL("http://example.com"), false); |
| 439 | 466 |
| 440 // Tests. | 467 // Tests. |
| 441 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); | 468 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 1); |
| 442 EXPECT_EQ(1ul, model_->unread_size()); | 469 EXPECT_EQ(1ul, UnreadSize()); |
| 443 EXPECT_EQ(0ul, model_->read_size()); | 470 EXPECT_EQ(0ul, ReadSize()); |
| 444 EXPECT_TRUE(model_->HasUnseenEntries()); | 471 EXPECT_TRUE(model_->HasUnseenEntries()); |
| 445 | 472 |
| 446 const ReadingListEntry& other_entry = model_->GetUnreadEntryAtIndex(0); | 473 const ReadingListEntry* other_entry = |
| 447 EXPECT_EQ(GURL("http://example.com"), other_entry.URL()); | 474 model_->GetEntryByURL(GURL("http://example.com")); |
| 448 EXPECT_EQ("sample", other_entry.Title()); | 475 EXPECT_NE(other_entry, nullptr); |
| 476 EXPECT_FALSE(other_entry->IsRead()); | |
| 477 EXPECT_EQ(GURL("http://example.com"), other_entry->URL()); | |
| 478 EXPECT_EQ("sample", other_entry->Title()); | |
| 449 } | 479 } |
| 450 | 480 |
| 451 TEST_F(ReadingListModelTest, BatchUpdates) { | 481 TEST_F(ReadingListModelTest, BatchUpdates) { |
| 452 auto token = model_->BeginBatchUpdates(); | 482 auto token = model_->BeginBatchUpdates(); |
| 453 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 483 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0); |
| 454 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); | 484 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); |
| 455 | 485 |
| 456 delete token.release(); | 486 delete token.release(); |
| 457 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 487 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0); |
| 458 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); | 488 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); |
| 459 } | 489 } |
| 460 | 490 |
| 461 TEST_F(ReadingListModelTest, BatchUpdatesReentrant) { | 491 TEST_F(ReadingListModelTest, BatchUpdatesReentrant) { |
| 462 // When two updates happen at the same time, the notification is only sent | 492 // When two updates happen at the same time, the notification is only sent |
| 463 // for beginning of first update and completion of last update. | 493 // for beginning of first update and completion of last update. |
| 464 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); | 494 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); |
| 465 | 495 |
| 466 auto token = model_->BeginBatchUpdates(); | 496 auto token = model_->BeginBatchUpdates(); |
| 467 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 497 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0); |
| 468 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); | 498 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); |
| 469 | 499 |
| 470 auto second_token = model_->BeginBatchUpdates(); | 500 auto second_token = model_->BeginBatchUpdates(); |
| 471 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 501 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0); |
| 472 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); | 502 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); |
| 473 | 503 |
| 474 delete token.release(); | 504 delete token.release(); |
| 475 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 505 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0); |
| 476 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); | 506 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); |
| 477 | 507 |
| 478 delete second_token.release(); | 508 delete second_token.release(); |
| 479 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 509 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0); |
| 480 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); | 510 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); |
| 481 | 511 |
| 482 // Consequent updates send notifications. | 512 // Consequent updates send notifications. |
| 483 auto third_token = model_->BeginBatchUpdates(); | 513 auto third_token = model_->BeginBatchUpdates(); |
| 484 AssertObserverCount(1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 514 AssertObserverCount(1, 2, 1, 0, 0, 0, 0, 0, 0); |
| 485 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); | 515 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); |
| 486 | 516 |
| 487 delete third_token.release(); | 517 delete third_token.release(); |
| 488 AssertObserverCount(1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 518 AssertObserverCount(1, 2, 2, 0, 0, 0, 0, 0, 0); |
| 489 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); | 519 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); |
| 490 } | 520 } |
| 491 | 521 |
| 492 TEST_F(ReadingListModelTest, UpdateEntryTitle) { | 522 TEST_F(ReadingListModelTest, UpdateEntryTitle) { |
| 493 const GURL gurl("http://example.com"); | 523 const GURL gurl("http://example.com"); |
| 494 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); | 524 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); |
| 495 ClearCounts(); | 525 ClearCounts(); |
| 496 | 526 |
| 497 model_->SetEntryTitle(gurl, "ping"); | 527 model_->SetEntryTitle(gurl, "ping"); |
| 498 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1); | 528 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 499 EXPECT_EQ("ping", entry.Title()); | 529 EXPECT_EQ("ping", entry.Title()); |
| 500 } | 530 } |
| 501 | 531 |
| 502 TEST_F(ReadingListModelTest, UpdateEntryState) { | 532 TEST_F(ReadingListModelTest, UpdateEntryDistilledState) { |
| 503 const GURL gurl("http://example.com"); | 533 const GURL gurl("http://example.com"); |
| 504 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); | 534 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); |
| 505 ClearCounts(); | 535 ClearCounts(); |
| 506 | 536 |
| 507 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING); | 537 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING); |
| 508 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1); | 538 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 509 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); | 539 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); |
| 510 } | 540 } |
| 511 | 541 |
| 512 TEST_F(ReadingListModelTest, UpdateDistilledPath) { | 542 TEST_F(ReadingListModelTest, UpdateDistilledPath) { |
| 513 const GURL gurl("http://example.com"); | 543 const GURL gurl("http://example.com"); |
| 514 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); | 544 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); |
| 515 ClearCounts(); | 545 ClearCounts(); |
| 516 | 546 |
| 517 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); | 547 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); |
| 518 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1); | 548 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 519 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); | 549 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); |
| 520 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath()); | 550 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath()); |
| 521 } | 551 } |
| 522 | 552 |
| 523 TEST_F(ReadingListModelTest, UpdateReadEntryTitle) { | 553 TEST_F(ReadingListModelTest, UpdateReadEntryTitle) { |
| 524 const GURL gurl("http://example.com"); | 554 const GURL gurl("http://example.com"); |
| 525 model_->AddEntry(gurl, "sample"); | 555 model_->AddEntry(gurl, "sample"); |
| 526 model_->MarkReadByURL(gurl); | 556 model_->MarkReadByURL(gurl); |
| 527 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); | 557 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); |
| 528 ClearCounts(); | 558 ClearCounts(); |
| 529 | 559 |
| 530 model_->SetEntryTitle(gurl, "ping"); | 560 model_->SetEntryTitle(gurl, "ping"); |
| 531 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1); | 561 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 532 EXPECT_EQ("ping", entry.Title()); | 562 EXPECT_EQ("ping", entry.Title()); |
| 533 } | 563 } |
| 534 | 564 |
| 535 TEST_F(ReadingListModelTest, UpdateReadEntryState) { | 565 TEST_F(ReadingListModelTest, UpdateReadEntryState) { |
| 536 const GURL gurl("http://example.com"); | 566 const GURL gurl("http://example.com"); |
| 537 model_->AddEntry(gurl, "sample"); | 567 model_->AddEntry(gurl, "sample"); |
| 538 model_->MarkReadByURL(gurl); | 568 model_->MarkReadByURL(gurl); |
| 539 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); | 569 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); |
| 540 ClearCounts(); | 570 ClearCounts(); |
| 541 | 571 |
| 542 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING); | 572 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING); |
| 543 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1); | 573 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 544 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); | 574 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); |
| 545 } | 575 } |
| 546 | 576 |
| 547 TEST_F(ReadingListModelTest, UpdateReadDistilledPath) { | 577 TEST_F(ReadingListModelTest, UpdateReadDistilledPath) { |
| 548 const GURL gurl("http://example.com"); | 578 const GURL gurl("http://example.com"); |
| 549 model_->AddEntry(gurl, "sample"); | 579 model_->AddEntry(gurl, "sample"); |
| 550 model_->MarkReadByURL(gurl); | 580 model_->MarkReadByURL(gurl); |
| 551 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); | 581 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); |
| 552 ClearCounts(); | 582 ClearCounts(); |
| 553 | 583 |
| 554 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); | 584 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); |
| 555 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1); | 585 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 556 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); | 586 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); |
| 557 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath()); | 587 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath()); |
| 558 } | 588 } |
| 559 | 589 |
| 560 // Tests that the callback is called when the entry is unread. | |
| 561 TEST_F(ReadingListModelTest, CallbackEntryURLUnread) { | |
| 562 // Setup. | |
| 563 model_->AddEntry(callback_url, callback_title); | |
| 564 | |
| 565 ASSERT_EQ(0UL, model_->read_size()); | |
| 566 ASSERT_EQ(1UL, model_->unread_size()); | |
| 567 | |
| 568 // Action. | |
| 569 bool result = model_->CallbackEntryURL( | |
| 570 callback_url, | |
| 571 base::Bind(&ReadingListModelTest::Callback, base::Unretained(this))); | |
| 572 | |
| 573 // Test. | |
| 574 EXPECT_TRUE(result); | |
| 575 EXPECT_TRUE(CallbackCalled()); | |
| 576 } | |
| 577 | |
| 578 // Tests that the callback is called when the entry is read. | |
| 579 TEST_F(ReadingListModelTest, CallbackEntryURLRead) { | |
| 580 // Setup. | |
| 581 model_->AddEntry(callback_url, callback_title); | |
| 582 model_->MarkReadByURL(callback_url); | |
| 583 | |
| 584 ASSERT_EQ(1UL, model_->read_size()); | |
| 585 ASSERT_EQ(0UL, model_->unread_size()); | |
| 586 | |
| 587 // Action. | |
| 588 bool result = model_->CallbackEntryURL( | |
| 589 callback_url, | |
| 590 base::Bind(&ReadingListModelTest::Callback, base::Unretained(this))); | |
| 591 | |
| 592 // Test. | |
| 593 EXPECT_TRUE(result); | |
| 594 EXPECT_TRUE(CallbackCalled()); | |
| 595 } | |
| 596 | |
| 597 // Tests that the callback is not called when the entry is not present. | |
| 598 TEST_F(ReadingListModelTest, CallbackEntryURLNotPresent) { | |
| 599 // Setup. | |
| 600 const GURL gurl("http://foo.bar"); | |
| 601 ASSERT_NE(gurl, callback_url); | |
| 602 model_->AddEntry(gurl, callback_title); | |
| 603 | |
| 604 // Action. | |
| 605 bool result = model_->CallbackEntryURL( | |
| 606 callback_url, | |
| 607 base::Bind(&ReadingListModelTest::Callback, base::Unretained(this))); | |
| 608 | |
| 609 // Test. | |
| 610 EXPECT_FALSE(result); | |
| 611 EXPECT_FALSE(CallbackCalled()); | |
| 612 } | |
| 613 | |
| 614 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. | 590 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. |
| 615 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { | 591 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { |
| 616 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | 592 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 617 model_.reset(); | 593 model_.reset(); |
| 618 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); | 594 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0); |
| 619 } | 595 } |
| 620 | 596 |
| 621 } // namespace | 597 } // namespace |
| OLD | NEW |