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

Side by Side Diff: components/reading_list/ios/reading_list_model_unittest.mm

Issue 2525663002: Refactor Reading List Model to use URL as key. (Closed)
Patch Set: feedback Created 4 years 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 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(
jif-google 2016/11/28 16:28:21 If possible, try writing (*entries_)[GURL("http://
jif 2016/11/28 18:15:31 I get it, it's not possible.
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 return size;
212 }
213
214 size_t ReadSize() {
215 size_t size = 0;
216 for (const auto& iterator : *model_) {
217 if (iterator.second.IsRead()) {
218 size++;
219 }
220 }
221 return size;
222 }
223
207 void Callback(const ReadingListEntry& entry) { 224 void Callback(const ReadingListEntry& entry) {
208 EXPECT_EQ(callback_url, entry.URL()); 225 EXPECT_EQ(callback_url, entry.URL());
209 EXPECT_EQ(callback_title, entry.Title()); 226 EXPECT_EQ(callback_title, entry.Title());
210 callback_called_ = true; 227 callback_called_ = true;
211 } 228 }
212 229
213 bool CallbackCalled() { return callback_called_; } 230 bool CallbackCalled() { return callback_called_; }
214 231
215 protected: 232 protected:
216 int observer_loaded_; 233 int observer_loaded_;
217 int observer_started_batch_update_; 234 int observer_started_batch_update_;
218 int observer_completed_batch_update_; 235 int observer_completed_batch_update_;
219 int observer_deleted_; 236 int observer_deleted_;
220 int observer_remove_unread_; 237 int observer_remove_;
221 int observer_remove_read_;
222 int observer_move_; 238 int observer_move_;
223 int observer_add_unread_; 239 int observer_add_;
224 int observer_add_read_; 240 int observer_did_add_;
225 int observer_update_unread_; 241 int observer_update_;
226 int observer_update_read_;
227 int observer_did_apply_; 242 int observer_did_apply_;
228 int storage_saved_; 243 int storage_saved_;
229 int storage_removed_; 244 int storage_removed_;
230 bool callback_called_; 245 bool callback_called_;
231 246
232 std::unique_ptr<ReadingListModelImpl> model_; 247 std::unique_ptr<ReadingListModelImpl> model_;
233 }; 248 };
234 249
235 TEST_F(ReadingListModelTest, EmptyLoaded) { 250 TEST_F(ReadingListModelTest, EmptyLoaded) {
236 EXPECT_TRUE(model_->loaded()); 251 EXPECT_TRUE(model_->loaded());
237 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 252 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0);
238 EXPECT_EQ(0ul, model_->unread_size()); 253 EXPECT_EQ(0ul, UnreadSize());
239 EXPECT_EQ(0ul, model_->read_size()); 254 EXPECT_EQ(0ul, ReadSize());
240 model_->Shutdown(); 255 model_->Shutdown();
241 EXPECT_FALSE(model_->loaded()); 256 EXPECT_FALSE(model_->loaded());
242 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); 257 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0);
243 } 258 }
244 259
245 TEST_F(ReadingListModelTest, ModelLoaded) { 260 TEST_F(ReadingListModelTest, ModelLoaded) {
246 ClearCounts(); 261 ClearCounts();
247 auto storage = base::MakeUnique<TestReadingListStorage>(this); 262 auto storage = base::MakeUnique<TestReadingListStorage>(this);
248 storage->AddSampleEntries(); 263 storage->AddSampleEntries();
249 SetStorage(std::move(storage)); 264 SetStorage(std::move(storage));
250 265
251 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 266 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0);
252 EXPECT_EQ(model_->read_size(), 3u); 267 std::map<GURL, std::string> loaded_entries;
253 EXPECT_EQ(model_->GetReadEntryAtIndex(0).Title(), "read_c"); 268 int size = 0;
254 EXPECT_EQ(model_->GetReadEntryAtIndex(1).Title(), "read_b"); 269 for (const auto& iterator : *model_) {
255 EXPECT_EQ(model_->GetReadEntryAtIndex(2).Title(), "read_a"); 270 size++;
256 271 loaded_entries[iterator.first] = iterator.second.Title();
257 EXPECT_EQ(model_->unread_size(), 4u); 272 }
258 EXPECT_EQ(model_->GetUnreadEntryAtIndex(0).Title(), "unread_d"); 273 EXPECT_EQ(size, 7);
259 EXPECT_EQ(model_->GetUnreadEntryAtIndex(1).Title(), "unread_c"); 274 EXPECT_EQ(loaded_entries[GURL("http://unread_a.com")], "unread_a");
260 EXPECT_EQ(model_->GetUnreadEntryAtIndex(2).Title(), "unread_b"); 275 EXPECT_EQ(loaded_entries[GURL("http://unread_b.com")], "unread_b");
261 EXPECT_EQ(model_->GetUnreadEntryAtIndex(3).Title(), "unread_a"); 276 EXPECT_EQ(loaded_entries[GURL("http://unread_c.com")], "unread_c");
277 EXPECT_EQ(loaded_entries[GURL("http://unread_d.com")], "unread_d");
278 EXPECT_EQ(loaded_entries[GURL("http://read_a.com")], "read_a");
279 EXPECT_EQ(loaded_entries[GURL("http://read_b.com")], "read_b");
280 EXPECT_EQ(loaded_entries[GURL("http://read_c.com")], "read_c");
262 } 281 }
263 282
264 TEST_F(ReadingListModelTest, AddEntry) { 283 TEST_F(ReadingListModelTest, AddEntry) {
265 auto storage = base::MakeUnique<TestReadingListStorage>(this); 284 auto storage = base::MakeUnique<TestReadingListStorage>(this);
266 SetStorage(std::move(storage)); 285 SetStorage(std::move(storage));
267 ClearCounts(); 286 ClearCounts();
268 287
269 const ReadingListEntry& entry = 288 const ReadingListEntry& entry =
270 model_->AddEntry(GURL("http://example.com"), "\n \tsample Test "); 289 model_->AddEntry(GURL("http://example.com"), "\n \tsample Test ");
271 EXPECT_EQ(GURL("http://example.com"), entry.URL()); 290 EXPECT_EQ(GURL("http://example.com"), entry.URL());
272 EXPECT_EQ("sample Test", entry.Title()); 291 EXPECT_EQ("sample Test", entry.Title());
273 292
274 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1); 293 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 1);
275 AssertStorageCount(1, 0); 294 AssertStorageCount(1, 0);
276 EXPECT_EQ(1ul, model_->unread_size()); 295 EXPECT_EQ(1ul, UnreadSize());
277 EXPECT_EQ(0ul, model_->read_size()); 296 EXPECT_EQ(0ul, ReadSize());
278 EXPECT_TRUE(model_->HasUnseenEntries()); 297 EXPECT_TRUE(model_->HasUnseenEntries());
279 298
280 const ReadingListEntry& other_entry = model_->GetUnreadEntryAtIndex(0); 299 const ReadingListEntry* other_entry =
281 EXPECT_EQ(GURL("http://example.com"), other_entry.URL()); 300 model_->GetEntryByURL(GURL("http://example.com"));
282 EXPECT_EQ("sample Test", other_entry.Title()); 301 EXPECT_NE(other_entry, nullptr);
302 EXPECT_FALSE(other_entry->IsRead());
303 EXPECT_EQ(GURL("http://example.com"), other_entry->URL());
304 EXPECT_EQ("sample Test", other_entry->Title());
283 } 305 }
284 306
285 TEST_F(ReadingListModelTest, SyncAddEntry) { 307 TEST_F(ReadingListModelTest, SyncAddEntry) {
286 auto storage = base::MakeUnique<TestReadingListStorage>(this); 308 auto storage = base::MakeUnique<TestReadingListStorage>(this);
287 SetStorage(std::move(storage)); 309 SetStorage(std::move(storage));
288 auto entry = 310 auto entry =
289 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); 311 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample");
312 entry->SetRead(true);
290 ClearCounts(); 313 ClearCounts();
291 314
292 model_->SyncAddEntry(std::move(entry), true); 315 model_->SyncAddEntry(std::move(entry));
293 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1); 316 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 1);
294 AssertStorageCount(0, 0); 317 AssertStorageCount(0, 0);
295 ASSERT_EQ(model_->unread_size(), 0u); 318 EXPECT_EQ(0ul, UnreadSize());
296 ASSERT_EQ(model_->read_size(), 1u); 319 EXPECT_EQ(1ul, ReadSize());
297 ClearCounts(); 320 ClearCounts();
298 } 321 }
299 322
300 TEST_F(ReadingListModelTest, SyncMergeEntry) { 323 TEST_F(ReadingListModelTest, SyncMergeEntry) {
301 auto storage = base::MakeUnique<TestReadingListStorage>(this); 324 auto storage = base::MakeUnique<TestReadingListStorage>(this);
302 SetStorage(std::move(storage)); 325 SetStorage(std::move(storage));
303 model_->AddEntry(GURL("http://example.com"), "sample"); 326 model_->AddEntry(GURL("http://example.com"), "sample");
304 model_->SetEntryDistilledPath(GURL("http://example.com"), 327 model_->SetEntryDistilledPath(GURL("http://example.com"),
305 base::FilePath("distilled/page.html")); 328 base::FilePath("distilled/page.html"));
306 const ReadingListEntry* local_entry = 329 const ReadingListEntry* local_entry =
307 model_->GetEntryFromURL(GURL("http://example.com"), nullptr); 330 model_->GetEntryByURL(GURL("http://example.com"));
308 int64_t local_update_time = local_entry->UpdateTime(); 331 int64_t local_update_time = local_entry->UpdateTime();
309 332
310 base::test::ios::SpinRunLoopWithMinDelay( 333 base::test::ios::SpinRunLoopWithMinDelay(
311 base::TimeDelta::FromMilliseconds(10)); 334 base::TimeDelta::FromMilliseconds(10));
312 auto sync_entry = 335 auto sync_entry =
313 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); 336 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample");
337 sync_entry->SetRead(true);
314 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); 338 ASSERT_GT(sync_entry->UpdateTime(), local_update_time);
315 int64_t sync_update_time = sync_entry->UpdateTime(); 339 int64_t sync_update_time = sync_entry->UpdateTime();
316 EXPECT_TRUE(sync_entry->DistilledPath().empty()); 340 EXPECT_TRUE(sync_entry->DistilledPath().empty());
317 341
318 EXPECT_EQ(model_->unread_size(), 1u); 342 EXPECT_EQ(1ul, UnreadSize());
319 EXPECT_EQ(model_->read_size(), 0u); 343 EXPECT_EQ(0ul, ReadSize());
320 344
321 ReadingListEntry* merged_entry = 345 ReadingListEntry* merged_entry =
322 model_->SyncMergeEntry(std::move(sync_entry), true); 346 model_->SyncMergeEntry(std::move(sync_entry));
323 EXPECT_EQ(model_->unread_size(), 0u); 347 EXPECT_EQ(0ul, UnreadSize());
324 EXPECT_EQ(model_->read_size(), 1u); 348 EXPECT_EQ(1ul, ReadSize());
325 EXPECT_EQ(merged_entry->DistilledPath(), 349 EXPECT_EQ(merged_entry->DistilledPath(),
326 base::FilePath("distilled/page.html")); 350 base::FilePath("distilled/page.html"));
327 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time); 351 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time);
328 } 352 }
329 353
330 TEST_F(ReadingListModelTest, RemoveEntryByUrl) { 354 TEST_F(ReadingListModelTest, RemoveEntryByUrl) {
331 auto storage = base::MakeUnique<TestReadingListStorage>(this); 355 auto storage = base::MakeUnique<TestReadingListStorage>(this);
332 SetStorage(std::move(storage)); 356 SetStorage(std::move(storage));
333 model_->AddEntry(GURL("http://example.com"), "sample"); 357 model_->AddEntry(GURL("http://example.com"), "sample");
334 ClearCounts(); 358 ClearCounts();
335 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), 359 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
336 nullptr); 360 EXPECT_EQ(1ul, UnreadSize());
337 EXPECT_EQ(model_->unread_size(), 1u); 361 EXPECT_EQ(0ul, ReadSize());
338 model_->RemoveEntryByURL(GURL("http://example.com")); 362 model_->RemoveEntryByURL(GURL("http://example.com"));
339 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1); 363 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1);
340 AssertStorageCount(0, 1); 364 AssertStorageCount(0, 1);
341 EXPECT_EQ(model_->unread_size(), 0u); 365 EXPECT_EQ(0ul, UnreadSize());
342 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), 366 EXPECT_EQ(0ul, ReadSize());
343 nullptr); 367 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
344 368
345 model_->AddEntry(GURL("http://example.com"), "sample"); 369 model_->AddEntry(GURL("http://example.com"), "sample");
346 model_->MarkReadByURL(GURL("http://example.com")); 370 model_->SetReadStatus(GURL("http://example.com"), true);
347 ClearCounts(); 371 ClearCounts();
348 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), 372 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
349 nullptr); 373 EXPECT_EQ(0ul, UnreadSize());
350 EXPECT_EQ(model_->read_size(), 1u); 374 EXPECT_EQ(1ul, ReadSize());
351 model_->RemoveEntryByURL(GURL("http://example.com")); 375 model_->RemoveEntryByURL(GURL("http://example.com"));
352 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1); 376 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1);
353 AssertStorageCount(0, 1); 377 AssertStorageCount(0, 1);
354 EXPECT_EQ(model_->read_size(), 0u); 378 EXPECT_EQ(0ul, UnreadSize());
355 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), 379 EXPECT_EQ(0ul, ReadSize());
356 nullptr); 380 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
357 } 381 }
358 382
359 TEST_F(ReadingListModelTest, RemoveSyncEntryByUrl) { 383 TEST_F(ReadingListModelTest, RemoveSyncEntryByUrl) {
360 auto storage = base::MakeUnique<TestReadingListStorage>(this); 384 auto storage = base::MakeUnique<TestReadingListStorage>(this);
361 SetStorage(std::move(storage)); 385 SetStorage(std::move(storage));
362 model_->AddEntry(GURL("http://example.com"), "sample"); 386 model_->AddEntry(GURL("http://example.com"), "sample");
363 ClearCounts(); 387 ClearCounts();
364 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), 388 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
365 nullptr); 389 EXPECT_EQ(1ul, UnreadSize());
366 EXPECT_EQ(model_->unread_size(), 1u); 390 EXPECT_EQ(0ul, ReadSize());
367 model_->SyncRemoveEntry(GURL("http://example.com")); 391 model_->SyncRemoveEntry(GURL("http://example.com"));
368 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1); 392 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1);
369 AssertStorageCount(0, 0); 393 AssertStorageCount(0, 0);
370 EXPECT_EQ(model_->unread_size(), 0u); 394 EXPECT_EQ(0ul, UnreadSize());
371 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), 395 EXPECT_EQ(0ul, ReadSize());
372 nullptr); 396 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
373 397
374 model_->AddEntry(GURL("http://example.com"), "sample"); 398 model_->AddEntry(GURL("http://example.com"), "sample");
375 model_->MarkReadByURL(GURL("http://example.com")); 399 model_->SetReadStatus(GURL("http://example.com"), true);
376 ClearCounts(); 400 ClearCounts();
377 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), 401 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
378 nullptr); 402 EXPECT_EQ(0ul, UnreadSize());
379 EXPECT_EQ(model_->read_size(), 1u); 403 EXPECT_EQ(1ul, ReadSize());
380 model_->SyncRemoveEntry(GURL("http://example.com")); 404 model_->SyncRemoveEntry(GURL("http://example.com"));
381 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1); 405 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 1);
382 AssertStorageCount(0, 0); 406 AssertStorageCount(0, 0);
383 EXPECT_EQ(model_->read_size(), 0u); 407 EXPECT_EQ(0ul, UnreadSize());
384 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr), 408 EXPECT_EQ(0ul, ReadSize());
385 nullptr); 409 EXPECT_EQ(model_->GetEntryByURL(GURL("http://example.com")), nullptr);
386 } 410 }
387 411
388 TEST_F(ReadingListModelTest, ReadEntry) { 412 TEST_F(ReadingListModelTest, ReadEntry) {
389 model_->AddEntry(GURL("http://example.com"), "sample"); 413 model_->AddEntry(GURL("http://example.com"), "sample");
390 414
391 ClearCounts(); 415 ClearCounts();
392 model_->MarkReadByURL(GURL("http://example.com")); 416 model_->SetReadStatus(GURL("http://example.com"), true);
393 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 417 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 1);
394 EXPECT_EQ(0ul, model_->unread_size()); 418 EXPECT_EQ(0ul, UnreadSize());
395 EXPECT_EQ(1ul, model_->read_size()); 419 EXPECT_EQ(1ul, ReadSize());
396 EXPECT_FALSE(model_->HasUnseenEntries()); 420 EXPECT_FALSE(model_->HasUnseenEntries());
397 421
398 const ReadingListEntry& other_entry = model_->GetReadEntryAtIndex(0); 422 const ReadingListEntry* other_entry =
399 EXPECT_EQ(GURL("http://example.com"), other_entry.URL()); 423 model_->GetEntryByURL(GURL("http://example.com"));
400 EXPECT_EQ("sample", other_entry.Title()); 424 EXPECT_NE(other_entry, nullptr);
425 EXPECT_TRUE(other_entry->IsRead());
426 EXPECT_EQ(GURL("http://example.com"), other_entry->URL());
427 EXPECT_EQ("sample", other_entry->Title());
401 } 428 }
402 429
403 TEST_F(ReadingListModelTest, EntryFromURL) { 430 TEST_F(ReadingListModelTest, EntryFromURL) {
404 GURL url1("http://example.com"); 431 GURL url1("http://example.com");
405 GURL url2("http://example2.com"); 432 GURL url2("http://example2.com");
406 std::string entry1_title = "foo bar qux"; 433 std::string entry1_title = "foo bar qux";
407 model_->AddEntry(url1, entry1_title); 434 model_->AddEntry(url1, entry1_title);
408 435
409 // Check call with nullptr |read| parameter. 436 // Check call with nullptr |read| parameter.
410 const ReadingListEntry* entry1 = model_->GetEntryFromURL(url1, nullptr); 437 const ReadingListEntry* entry1 = model_->GetEntryByURL(url1);
411 EXPECT_NE(nullptr, entry1); 438 EXPECT_NE(nullptr, entry1);
412 EXPECT_EQ(entry1_title, entry1->Title()); 439 EXPECT_EQ(entry1_title, entry1->Title());
413 440
414 bool read; 441 entry1 = model_->GetEntryByURL(url1);
415 entry1 = model_->GetEntryFromURL(url1, &read);
416 EXPECT_NE(nullptr, entry1); 442 EXPECT_NE(nullptr, entry1);
417 EXPECT_EQ(entry1_title, entry1->Title()); 443 EXPECT_EQ(entry1_title, entry1->Title());
418 EXPECT_EQ(read, false); 444 EXPECT_EQ(entry1->IsRead(), false);
419 model_->MarkReadByURL(url1); 445 model_->SetReadStatus(url1, true);
420 entry1 = model_->GetEntryFromURL(url1, &read); 446 entry1 = model_->GetEntryByURL(url1);
421 EXPECT_NE(nullptr, entry1); 447 EXPECT_NE(nullptr, entry1);
422 EXPECT_EQ(entry1_title, entry1->Title()); 448 EXPECT_EQ(entry1_title, entry1->Title());
423 EXPECT_EQ(read, true); 449 EXPECT_EQ(entry1->IsRead(), true);
424 450
425 const ReadingListEntry* entry2 = model_->GetEntryFromURL(url2, &read); 451 const ReadingListEntry* entry2 = model_->GetEntryByURL(url2);
426 EXPECT_EQ(nullptr, entry2); 452 EXPECT_EQ(nullptr, entry2);
427 } 453 }
428 454
429 TEST_F(ReadingListModelTest, UnreadEntry) { 455 TEST_F(ReadingListModelTest, UnreadEntry) {
430 // Setup. 456 // Setup.
431 model_->AddEntry(GURL("http://example.com"), "sample"); 457 model_->AddEntry(GURL("http://example.com"), "sample");
432 model_->MarkReadByURL(GURL("http://example.com")); 458 model_->SetReadStatus(GURL("http://example.com"), true);
433 ClearCounts(); 459 ClearCounts();
434 ASSERT_EQ(0ul, model_->unread_size()); 460 EXPECT_EQ(0ul, UnreadSize());
435 ASSERT_EQ(1ul, model_->read_size()); 461 EXPECT_EQ(1ul, ReadSize());
436 462
437 // Action. 463 // Action.
438 model_->MarkUnreadByURL(GURL("http://example.com")); 464 model_->SetReadStatus(GURL("http://example.com"), false);
439 465
440 // Tests. 466 // Tests.
441 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 467 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 1);
442 EXPECT_EQ(1ul, model_->unread_size()); 468 EXPECT_EQ(1ul, UnreadSize());
443 EXPECT_EQ(0ul, model_->read_size()); 469 EXPECT_EQ(0ul, ReadSize());
444 EXPECT_TRUE(model_->HasUnseenEntries()); 470 EXPECT_TRUE(model_->HasUnseenEntries());
445 471
446 const ReadingListEntry& other_entry = model_->GetUnreadEntryAtIndex(0); 472 const ReadingListEntry* other_entry =
447 EXPECT_EQ(GURL("http://example.com"), other_entry.URL()); 473 model_->GetEntryByURL(GURL("http://example.com"));
448 EXPECT_EQ("sample", other_entry.Title()); 474 EXPECT_NE(other_entry, nullptr);
475 EXPECT_FALSE(other_entry->IsRead());
476 EXPECT_EQ(GURL("http://example.com"), other_entry->URL());
477 EXPECT_EQ("sample", other_entry->Title());
449 } 478 }
450 479
451 TEST_F(ReadingListModelTest, BatchUpdates) { 480 TEST_F(ReadingListModelTest, BatchUpdates) {
452 auto token = model_->BeginBatchUpdates(); 481 auto token = model_->BeginBatchUpdates();
453 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 482 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0);
454 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); 483 EXPECT_TRUE(model_->IsPerformingBatchUpdates());
455 484
456 delete token.release(); 485 delete token.release();
457 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); 486 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0);
458 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); 487 EXPECT_FALSE(model_->IsPerformingBatchUpdates());
459 } 488 }
460 489
461 TEST_F(ReadingListModelTest, BatchUpdatesReentrant) { 490 TEST_F(ReadingListModelTest, BatchUpdatesReentrant) {
462 // When two updates happen at the same time, the notification is only sent 491 // When two updates happen at the same time, the notification is only sent
463 // for beginning of first update and completion of last update. 492 // for beginning of first update and completion of last update.
464 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); 493 EXPECT_FALSE(model_->IsPerformingBatchUpdates());
465 494
466 auto token = model_->BeginBatchUpdates(); 495 auto token = model_->BeginBatchUpdates();
467 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 496 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0);
468 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); 497 EXPECT_TRUE(model_->IsPerformingBatchUpdates());
469 498
470 auto second_token = model_->BeginBatchUpdates(); 499 auto second_token = model_->BeginBatchUpdates();
471 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 500 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0);
472 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); 501 EXPECT_TRUE(model_->IsPerformingBatchUpdates());
473 502
474 delete token.release(); 503 delete token.release();
475 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 504 AssertObserverCount(1, 1, 0, 0, 0, 0, 0, 0, 0);
476 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); 505 EXPECT_TRUE(model_->IsPerformingBatchUpdates());
477 506
478 delete second_token.release(); 507 delete second_token.release();
479 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); 508 AssertObserverCount(1, 1, 1, 0, 0, 0, 0, 0, 0);
480 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); 509 EXPECT_FALSE(model_->IsPerformingBatchUpdates());
481 510
482 // Consequent updates send notifications. 511 // Consequent updates send notifications.
483 auto third_token = model_->BeginBatchUpdates(); 512 auto third_token = model_->BeginBatchUpdates();
484 AssertObserverCount(1, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); 513 AssertObserverCount(1, 2, 1, 0, 0, 0, 0, 0, 0);
485 EXPECT_TRUE(model_->IsPerformingBatchUpdates()); 514 EXPECT_TRUE(model_->IsPerformingBatchUpdates());
486 515
487 delete third_token.release(); 516 delete third_token.release();
488 AssertObserverCount(1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0); 517 AssertObserverCount(1, 2, 2, 0, 0, 0, 0, 0, 0);
489 EXPECT_FALSE(model_->IsPerformingBatchUpdates()); 518 EXPECT_FALSE(model_->IsPerformingBatchUpdates());
490 } 519 }
491 520
492 TEST_F(ReadingListModelTest, UpdateEntryTitle) { 521 TEST_F(ReadingListModelTest, UpdateEntryTitle) {
493 const GURL gurl("http://example.com"); 522 const GURL gurl("http://example.com");
494 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); 523 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample");
495 ClearCounts(); 524 ClearCounts();
496 525
497 model_->SetEntryTitle(gurl, "ping"); 526 model_->SetEntryTitle(gurl, "ping");
498 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1); 527 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
499 EXPECT_EQ("ping", entry.Title()); 528 EXPECT_EQ("ping", entry.Title());
500 } 529 }
501 530
502 TEST_F(ReadingListModelTest, UpdateEntryState) { 531 TEST_F(ReadingListModelTest, UpdateEntryDistilledState) {
503 const GURL gurl("http://example.com"); 532 const GURL gurl("http://example.com");
504 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); 533 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample");
505 ClearCounts(); 534 ClearCounts();
506 535
507 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING); 536 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING);
508 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1); 537 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
509 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); 538 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState());
510 } 539 }
511 540
512 TEST_F(ReadingListModelTest, UpdateDistilledPath) { 541 TEST_F(ReadingListModelTest, UpdateDistilledPath) {
513 const GURL gurl("http://example.com"); 542 const GURL gurl("http://example.com");
514 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample"); 543 const ReadingListEntry& entry = model_->AddEntry(gurl, "sample");
515 ClearCounts(); 544 ClearCounts();
516 545
517 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); 546 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html"));
518 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1); 547 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
519 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); 548 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState());
520 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath()); 549 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath());
521 } 550 }
522 551
523 TEST_F(ReadingListModelTest, UpdateReadEntryTitle) { 552 TEST_F(ReadingListModelTest, UpdateReadEntryTitle) {
524 const GURL gurl("http://example.com"); 553 const GURL gurl("http://example.com");
525 model_->AddEntry(gurl, "sample"); 554 model_->AddEntry(gurl, "sample");
526 model_->MarkReadByURL(gurl); 555 model_->MarkReadByURL(gurl);
527 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); 556 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0);
528 ClearCounts(); 557 ClearCounts();
529 558
530 model_->SetEntryTitle(gurl, "ping"); 559 model_->SetEntryTitle(gurl, "ping");
531 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1); 560 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
532 EXPECT_EQ("ping", entry.Title()); 561 EXPECT_EQ("ping", entry.Title());
533 } 562 }
534 563
535 TEST_F(ReadingListModelTest, UpdateReadEntryState) { 564 TEST_F(ReadingListModelTest, UpdateReadEntryState) {
536 const GURL gurl("http://example.com"); 565 const GURL gurl("http://example.com");
537 model_->AddEntry(gurl, "sample"); 566 model_->AddEntry(gurl, "sample");
538 model_->MarkReadByURL(gurl); 567 model_->MarkReadByURL(gurl);
539 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); 568 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0);
540 ClearCounts(); 569 ClearCounts();
541 570
542 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING); 571 model_->SetEntryDistilledState(gurl, ReadingListEntry::PROCESSING);
543 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1); 572 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
544 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); 573 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState());
545 } 574 }
546 575
547 TEST_F(ReadingListModelTest, UpdateReadDistilledPath) { 576 TEST_F(ReadingListModelTest, UpdateReadDistilledPath) {
548 const GURL gurl("http://example.com"); 577 const GURL gurl("http://example.com");
549 model_->AddEntry(gurl, "sample"); 578 model_->AddEntry(gurl, "sample");
550 model_->MarkReadByURL(gurl); 579 model_->MarkReadByURL(gurl);
551 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0); 580 const ReadingListEntry& entry = model_->GetReadEntryAtIndex(0);
552 ClearCounts(); 581 ClearCounts();
553 582
554 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html")); 583 model_->SetEntryDistilledPath(gurl, base::FilePath("distilled/page.html"));
555 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1); 584 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1);
556 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); 585 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState());
557 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath()); 586 EXPECT_EQ(base::FilePath("distilled/page.html"), entry.DistilledPath());
558 } 587 }
559 588
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. 589 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed.
615 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { 590 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) {
616 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 591 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0);
617 model_.reset(); 592 model_.reset();
618 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); 593 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0);
619 } 594 }
620 595
621 } // namespace 596 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698