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

Side by Side Diff: ios/chrome/browser/reading_list/reading_list_model_unittest.cc

Issue 2451843002: Add Store+Sync to reading list. (Closed)
Patch Set: fix xcode clang Created 4 years, 1 month 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ptr_util.h"
7 #import "base/test/ios/wait_util.h"
6 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h" 8 #include "ios/chrome/browser/reading_list/reading_list_model_impl.h"
9 #include "ios/chrome/browser/reading_list/reading_list_model_storage.h"
7 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
8 11
9 namespace { 12 namespace {
10 13
11 const GURL callback_url("http://example.com"); 14 const GURL callback_url("http://example.com");
12 const std::string callback_title("test title"); 15 const std::string callback_title("test title");
13 16
17 class TestReadingListStorageObserver {
18 public:
19 virtual void ReadingListDidSaveEntry() = 0;
20 virtual void ReadingListDidRemoveEntry() = 0;
21 };
22
23 class TestReadingListStorage : public ReadingListModelStorage {
24 public:
25 TestReadingListStorage(TestReadingListStorageObserver* observer)
26 : read_(new std::vector<ReadingListEntry>()),
27 unread_(new std::vector<ReadingListEntry>()),
28 observer_(observer) {}
29
30 void AddSampleEntries() {
31 ReadingListEntry read_a(GURL("http://read_a.com"), "read_a");
32 ReadingListEntry read_b(GURL("http://read_b.com"), "read_b");
33 ReadingListEntry read_c(GURL("http://read_c.com"), "read_c");
34 read_->push_back(std::move(read_c));
35 read_->push_back(std::move(read_a));
36 read_->push_back(std::move(read_b));
37 ReadingListEntry unread_a(GURL("http://unread_a.com"), "unread_a");
38 ReadingListEntry unread_b(GURL("http://unread_b.com"), "unread_b");
39 ReadingListEntry unread_c(GURL("http://unread_c.com"), "unread_c");
40 ReadingListEntry unread_d(GURL("http://unread_d.com"), "unread_d");
41 unread_->push_back(std::move(unread_a));
42 unread_->push_back(std::move(unread_d));
43 unread_->push_back(std::move(unread_c));
44 unread_->push_back(std::move(unread_b));
45 }
46
47 void SetReadingListModel(ReadingListModel* model,
48 ReadingListStoreDelegate* delegate_) override {
49 delegate_->StoreLoaded(std::move(unread_), std::move(read_));
50 }
51
52 syncer::ModelTypeSyncBridge* GetModelTypeSyncBridge() override {
53 return nullptr;
54 }
55
56 std::unique_ptr<ScopedBatchUpdate> EnsureBatchCreated() override {
57 return std::unique_ptr<ScopedBatchUpdate>();
58 }
59
60 // Saves or updates an entry. If the entry is not yet in the database, it is
61 // created.
62 void SaveEntry(const ReadingListEntry& entry, bool read) override {
63 observer_->ReadingListDidSaveEntry();
64 }
65
66 // Removed an entry from the storage.
67 void RemoveEntry(const ReadingListEntry& entry) override {
68 observer_->ReadingListDidRemoveEntry();
69 }
70
71 private:
72 std::unique_ptr<std::vector<ReadingListEntry>> read_;
73 std::unique_ptr<std::vector<ReadingListEntry>> unread_;
74 TestReadingListStorageObserver* observer_;
75 };
76
14 class ReadingListModelTest : public ReadingListModelObserver, 77 class ReadingListModelTest : public ReadingListModelObserver,
78 public TestReadingListStorageObserver,
15 public testing::Test { 79 public testing::Test {
16 public: 80 public:
17 ReadingListModelTest() 81 ReadingListModelTest()
18 : callback_called_(false), model_(new ReadingListModelImpl()) { 82 : callback_called_(false), model_(new ReadingListModelImpl()) {
19 ClearCounts(); 83 ClearCounts();
20 model_->AddObserver(this); 84 model_->AddObserver(this);
21 } 85 }
22 ~ReadingListModelTest() override {} 86 ~ReadingListModelTest() override {}
23 87
88 void SetStorage(std::unique_ptr<TestReadingListStorage> storage) {
89 model_ =
90 base::MakeUnique<ReadingListModelImpl>(std::move(storage), nullptr);
91 ClearCounts();
92 model_->AddObserver(this);
93 }
94
24 void ClearCounts() { 95 void ClearCounts() {
25 observer_loaded_ = observer_started_batch_update_ = 96 observer_loaded_ = observer_started_batch_update_ =
26 observer_completed_batch_update_ = observer_deleted_ = 97 observer_completed_batch_update_ = observer_deleted_ =
27 observer_remove_unread_ = observer_remove_read_ = observer_move_ = 98 observer_remove_unread_ = observer_remove_read_ = observer_move_ =
28 observer_add_unread_ = observer_add_read_ = 99 observer_add_unread_ = observer_add_read_ =
29 observer_update_unread_ = observer_update_read_ = 100 observer_update_unread_ = observer_update_read_ =
30 observer_did_apply_ = 0; 101 observer_did_apply_ = storage_saved_ =
102 storage_removed_ = 0;
31 } 103 }
32 104
33 void AssertObserverCount(int observer_loaded, 105 void AssertObserverCount(int observer_loaded,
34 int observer_started_batch_update, 106 int observer_started_batch_update,
35 int observer_completed_batch_update, 107 int observer_completed_batch_update,
36 int observer_deleted, 108 int observer_deleted,
37 int observer_remove_unread, 109 int observer_remove_unread,
38 int observer_remove_read, 110 int observer_remove_read,
39 int observer_move, 111 int observer_move,
40 int observer_add_unread, 112 int observer_add_unread,
41 int observer_add_read, 113 int observer_add_read,
42 int observer_update_unread, 114 int observer_update_unread,
43 int observer_update_read, 115 int observer_update_read,
44 int observer_did_apply) { 116 int observer_did_apply) {
45 ASSERT_EQ(observer_loaded, observer_loaded_); 117 ASSERT_EQ(observer_loaded, observer_loaded_);
46 ASSERT_EQ(observer_started_batch_update, observer_started_batch_update_); 118 ASSERT_EQ(observer_started_batch_update, observer_started_batch_update_);
47 ASSERT_EQ(observer_completed_batch_update, 119 ASSERT_EQ(observer_completed_batch_update,
48 observer_completed_batch_update_); 120 observer_completed_batch_update_);
49 ASSERT_EQ(observer_deleted, observer_deleted_); 121 ASSERT_EQ(observer_deleted, observer_deleted_);
50 ASSERT_EQ(observer_remove_unread, observer_remove_unread_); 122 ASSERT_EQ(observer_remove_unread, observer_remove_unread_);
51 ASSERT_EQ(observer_remove_read, observer_remove_read_); 123 ASSERT_EQ(observer_remove_read, observer_remove_read_);
52 ASSERT_EQ(observer_move, observer_move_); 124 ASSERT_EQ(observer_move, observer_move_);
53 ASSERT_EQ(observer_add_unread, observer_add_unread_); 125 ASSERT_EQ(observer_add_unread, observer_add_unread_);
54 ASSERT_EQ(observer_add_read, observer_add_read_); 126 ASSERT_EQ(observer_add_read, observer_add_read_);
55 ASSERT_EQ(observer_update_unread, observer_update_unread_); 127 ASSERT_EQ(observer_update_unread, observer_update_unread_);
56 ASSERT_EQ(observer_update_read, observer_update_read_); 128 ASSERT_EQ(observer_update_read, observer_update_read_);
57 ASSERT_EQ(observer_did_apply, observer_did_apply_); 129 ASSERT_EQ(observer_did_apply, observer_did_apply_);
58 } 130 }
59 131
132 void AssertStorageCount(int storage_saved, int storage_removed) {
133 ASSERT_EQ(storage_saved, storage_saved_);
134 ASSERT_EQ(storage_removed, storage_removed_);
135 }
136
60 // ReadingListModelObserver 137 // ReadingListModelObserver
61 void ReadingListModelLoaded(const ReadingListModel* model) override { 138 void ReadingListModelLoaded(const ReadingListModel* model) override {
62 observer_loaded_ += 1; 139 observer_loaded_ += 1;
63 } 140 }
64 void ReadingListModelBeganBatchUpdates( 141 void ReadingListModelBeganBatchUpdates(
65 const ReadingListModel* model) override { 142 const ReadingListModel* model) override {
66 observer_started_batch_update_ += 1; 143 observer_started_batch_update_ += 1;
67 } 144 }
68 void ReadingListModelCompletedBatchUpdates( 145 void ReadingListModelCompletedBatchUpdates(
69 const ReadingListModel* model) override { 146 const ReadingListModel* model) override {
70 observer_completed_batch_update_ += 1; 147 observer_completed_batch_update_ += 1;
71 } 148 }
72 void ReadingListModelBeingDeleted(const ReadingListModel* model) override { 149 void ReadingListModelBeingDeleted(const ReadingListModel* model) override {
73 observer_deleted_ += 1; 150 observer_deleted_ += 1;
74 } 151 }
75 void ReadingListWillRemoveUnreadEntry(const ReadingListModel* model, 152 void ReadingListWillRemoveUnreadEntry(const ReadingListModel* model,
76 size_t index) override { 153 size_t index) override {
77 observer_remove_unread_ += 1; 154 observer_remove_unread_ += 1;
78 } 155 }
79 void ReadingListWillMoveEntry(const ReadingListModel* model, 156 void ReadingListWillMoveEntry(const ReadingListModel* model,
80 size_t index) override { 157 size_t index,
158 bool read) override {
81 observer_move_ += 1; 159 observer_move_ += 1;
82 } 160 }
83 void ReadingListWillRemoveReadEntry(const ReadingListModel* model, 161 void ReadingListWillRemoveReadEntry(const ReadingListModel* model,
84 size_t index) override { 162 size_t index) override {
85 observer_remove_read_ += 1; 163 observer_remove_read_ += 1;
86 } 164 }
87 void ReadingListWillAddUnreadEntry(const ReadingListModel* model, 165 void ReadingListWillAddUnreadEntry(const ReadingListModel* model,
88 const ReadingListEntry& entry) override { 166 const ReadingListEntry& entry) override {
89 observer_add_unread_ += 1; 167 observer_add_unread_ += 1;
90 } 168 }
91 void ReadingListWillAddReadEntry(const ReadingListModel* model, 169 void ReadingListWillAddReadEntry(const ReadingListModel* model,
92 const ReadingListEntry& entry) override { 170 const ReadingListEntry& entry) override {
93 observer_add_read_ += 1; 171 observer_add_read_ += 1;
94 } 172 }
95 void ReadingListWillUpdateUnreadEntry(const ReadingListModel* model, 173 void ReadingListWillUpdateUnreadEntry(const ReadingListModel* model,
96 size_t index) override { 174 size_t index) override {
97 observer_update_unread_ += 1; 175 observer_update_unread_ += 1;
98 } 176 }
99 void ReadingListWillUpdateReadEntry(const ReadingListModel* model, 177 void ReadingListWillUpdateReadEntry(const ReadingListModel* model,
100 size_t index) override { 178 size_t index) override {
101 observer_update_read_ += 1; 179 observer_update_read_ += 1;
102 } 180 }
103 void ReadingListDidApplyChanges(ReadingListModel* model) override { 181 void ReadingListDidApplyChanges(ReadingListModel* model) override {
104 observer_did_apply_ += 1; 182 observer_did_apply_ += 1;
105 } 183 }
184
185 void ReadingListDidSaveEntry() override { storage_saved_ += 1; }
186 void ReadingListDidRemoveEntry() override { storage_removed_ += 1; }
187
106 void Callback(const ReadingListEntry& entry) { 188 void Callback(const ReadingListEntry& entry) {
107 EXPECT_EQ(callback_url, entry.URL()); 189 EXPECT_EQ(callback_url, entry.URL());
108 EXPECT_EQ(callback_title, entry.Title()); 190 EXPECT_EQ(callback_title, entry.Title());
109 callback_called_ = true; 191 callback_called_ = true;
110 } 192 }
111 193
112 bool CallbackCalled() { return callback_called_; } 194 bool CallbackCalled() { return callback_called_; }
113 195
114 protected: 196 protected:
115 int observer_loaded_; 197 int observer_loaded_;
116 int observer_started_batch_update_; 198 int observer_started_batch_update_;
117 int observer_completed_batch_update_; 199 int observer_completed_batch_update_;
118 int observer_deleted_; 200 int observer_deleted_;
119 int observer_remove_unread_; 201 int observer_remove_unread_;
120 int observer_remove_read_; 202 int observer_remove_read_;
121 int observer_move_; 203 int observer_move_;
122 int observer_add_unread_; 204 int observer_add_unread_;
123 int observer_add_read_; 205 int observer_add_read_;
124 int observer_update_unread_; 206 int observer_update_unread_;
125 int observer_update_read_; 207 int observer_update_read_;
126 int observer_did_apply_; 208 int observer_did_apply_;
209 int storage_saved_;
210 int storage_removed_;
127 bool callback_called_; 211 bool callback_called_;
128 212
129 std::unique_ptr<ReadingListModelImpl> model_; 213 std::unique_ptr<ReadingListModelImpl> model_;
130 }; 214 };
131 215
132 TEST_F(ReadingListModelTest, EmptyLoaded) { 216 TEST_F(ReadingListModelTest, EmptyLoaded) {
133 EXPECT_TRUE(model_->loaded()); 217 EXPECT_TRUE(model_->loaded());
134 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 218 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
135 EXPECT_EQ(0ul, model_->unread_size()); 219 EXPECT_EQ(0ul, model_->unread_size());
136 EXPECT_EQ(0ul, model_->read_size()); 220 EXPECT_EQ(0ul, model_->read_size());
137 model_->Shutdown(); 221 model_->Shutdown();
138 EXPECT_FALSE(model_->loaded()); 222 EXPECT_FALSE(model_->loaded());
139 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); 223 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
140 } 224 }
141 225
226 TEST_F(ReadingListModelTest, ModelLoaded) {
227 ClearCounts();
228 auto storage = base::MakeUnique<TestReadingListStorage>(this);
229 storage->AddSampleEntries();
230 SetStorage(std::move(storage));
231
232 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
233 EXPECT_EQ(model_->read_size(), 3u);
234 EXPECT_EQ(model_->GetReadEntryAtIndex(0).Title(), "read_c");
235 EXPECT_EQ(model_->GetReadEntryAtIndex(1).Title(), "read_b");
236 EXPECT_EQ(model_->GetReadEntryAtIndex(2).Title(), "read_a");
237
238 EXPECT_EQ(model_->unread_size(), 4u);
239 EXPECT_EQ(model_->GetUnreadEntryAtIndex(0).Title(), "unread_d");
240 EXPECT_EQ(model_->GetUnreadEntryAtIndex(1).Title(), "unread_c");
241 EXPECT_EQ(model_->GetUnreadEntryAtIndex(2).Title(), "unread_b");
242 EXPECT_EQ(model_->GetUnreadEntryAtIndex(3).Title(), "unread_a");
243 }
244
142 TEST_F(ReadingListModelTest, AddEntry) { 245 TEST_F(ReadingListModelTest, AddEntry) {
246 auto storage = base::MakeUnique<TestReadingListStorage>(this);
247 SetStorage(std::move(storage));
143 ClearCounts(); 248 ClearCounts();
249
144 const ReadingListEntry& entry = 250 const ReadingListEntry& entry =
145 model_->AddEntry(GURL("http://example.com"), "\n \tsample Test "); 251 model_->AddEntry(GURL("http://example.com"), "\n \tsample Test ");
146 EXPECT_EQ(GURL("http://example.com"), entry.URL()); 252 EXPECT_EQ(GURL("http://example.com"), entry.URL());
147 EXPECT_EQ("sample Test", entry.Title()); 253 EXPECT_EQ("sample Test", entry.Title());
148 254
149 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1); 255 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1);
256 AssertStorageCount(1, 0);
150 EXPECT_EQ(1ul, model_->unread_size()); 257 EXPECT_EQ(1ul, model_->unread_size());
151 EXPECT_EQ(0ul, model_->read_size()); 258 EXPECT_EQ(0ul, model_->read_size());
152 EXPECT_TRUE(model_->HasUnseenEntries()); 259 EXPECT_TRUE(model_->HasUnseenEntries());
153 260
154 const ReadingListEntry& other_entry = model_->GetUnreadEntryAtIndex(0); 261 const ReadingListEntry& other_entry = model_->GetUnreadEntryAtIndex(0);
155 EXPECT_EQ(GURL("http://example.com"), other_entry.URL()); 262 EXPECT_EQ(GURL("http://example.com"), other_entry.URL());
156 EXPECT_EQ("sample Test", other_entry.Title()); 263 EXPECT_EQ("sample Test", other_entry.Title());
157 } 264 }
158 265
266 TEST_F(ReadingListModelTest, SyncAddEntry) {
267 auto storage = base::MakeUnique<TestReadingListStorage>(this);
268 SetStorage(std::move(storage));
269 auto entry =
270 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample");
271 ClearCounts();
272
273 model_->SyncAddEntry(std::move(entry), true);
274 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1);
275 AssertStorageCount(0, 0);
276 ASSERT_EQ(model_->unread_size(), 0u);
277 ASSERT_EQ(model_->read_size(), 1u);
278 ClearCounts();
279 }
280
281 TEST_F(ReadingListModelTest, SyncMergeEntry) {
282 auto storage = base::MakeUnique<TestReadingListStorage>(this);
283 SetStorage(std::move(storage));
284 model_->AddEntry(GURL("http://example.com"), "sample");
285 model_->SetEntryDistilledPath(GURL("http://example.com"),
286 base::FilePath("distilled/page.html"));
287 const ReadingListEntry* local_entry =
288 model_->GetEntryFromURL(GURL("http://example.com"), nullptr);
289 int64_t local_update_time = local_entry->UpdateTime();
290
291 base::test::ios::SpinRunLoopWithMinDelay(
292 base::TimeDelta::FromMilliseconds(10));
293 auto sync_entry =
294 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample");
295 ASSERT_GT(sync_entry->UpdateTime(), local_update_time);
296 int64_t sync_update_time = sync_entry->UpdateTime();
297 EXPECT_FALSE(sync_entry->DistilledURL().is_valid());
298
299 EXPECT_EQ(model_->unread_size(), 1u);
300 EXPECT_EQ(model_->read_size(), 0u);
301
302 ReadingListEntry* merged_entry =
303 model_->SyncMergeEntry(std::move(sync_entry), true);
304 EXPECT_EQ(model_->unread_size(), 0u);
305 EXPECT_EQ(model_->read_size(), 1u);
306 EXPECT_EQ(merged_entry->DistilledPath(),
307 base::FilePath("distilled/page.html"));
308 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time);
309 }
310
311 TEST_F(ReadingListModelTest, RemoveEntryByUrl) {
312 auto storage = base::MakeUnique<TestReadingListStorage>(this);
313 SetStorage(std::move(storage));
314 model_->AddEntry(GURL("http://example.com"), "sample");
315 ClearCounts();
316 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr),
317 nullptr);
318 EXPECT_EQ(model_->unread_size(), 1u);
319 model_->RemoveEntryByURL(GURL("http://example.com"));
320 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1);
321 AssertStorageCount(0, 1);
322 EXPECT_EQ(model_->unread_size(), 0u);
323 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr),
324 nullptr);
325
326 model_->AddEntry(GURL("http://example.com"), "sample");
327 model_->MarkReadByURL(GURL("http://example.com"));
328 ClearCounts();
329 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr),
330 nullptr);
331 EXPECT_EQ(model_->read_size(), 1u);
332 model_->RemoveEntryByURL(GURL("http://example.com"));
333 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1);
334 AssertStorageCount(0, 1);
335 EXPECT_EQ(model_->read_size(), 0u);
336 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr),
337 nullptr);
338 }
339
340 TEST_F(ReadingListModelTest, RemoveSyncEntryByUrl) {
341 auto storage = base::MakeUnique<TestReadingListStorage>(this);
342 SetStorage(std::move(storage));
343 model_->AddEntry(GURL("http://example.com"), "sample");
344 ClearCounts();
345 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr),
346 nullptr);
347 EXPECT_EQ(model_->unread_size(), 1u);
348 model_->SyncRemoveEntry(GURL("http://example.com"));
349 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1);
350 AssertStorageCount(0, 0);
351 EXPECT_EQ(model_->unread_size(), 0u);
352 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr),
353 nullptr);
354
355 model_->AddEntry(GURL("http://example.com"), "sample");
356 model_->MarkReadByURL(GURL("http://example.com"));
357 ClearCounts();
358 EXPECT_NE(model_->GetEntryFromURL(GURL("http://example.com"), nullptr),
359 nullptr);
360 EXPECT_EQ(model_->read_size(), 1u);
361 model_->SyncRemoveEntry(GURL("http://example.com"));
362 AssertObserverCount(0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1);
363 AssertStorageCount(0, 0);
364 EXPECT_EQ(model_->read_size(), 0u);
365 EXPECT_EQ(model_->GetEntryFromURL(GURL("http://example.com"), nullptr),
366 nullptr);
367 }
368
159 TEST_F(ReadingListModelTest, ReadEntry) { 369 TEST_F(ReadingListModelTest, ReadEntry) {
160 model_->AddEntry(GURL("http://example.com"), "sample"); 370 model_->AddEntry(GURL("http://example.com"), "sample");
161 371
162 ClearCounts(); 372 ClearCounts();
163 model_->MarkReadByURL(GURL("http://example.com")); 373 model_->MarkReadByURL(GURL("http://example.com"));
164 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); 374 AssertObserverCount(0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
165 EXPECT_EQ(0ul, model_->unread_size()); 375 EXPECT_EQ(0ul, model_->unread_size());
166 EXPECT_EQ(1ul, model_->read_size()); 376 EXPECT_EQ(1ul, model_->read_size());
167 EXPECT_FALSE(model_->HasUnseenEntries()); 377 EXPECT_FALSE(model_->HasUnseenEntries());
168 378
169 const ReadingListEntry& other_entry = model_->GetReadEntryAtIndex(0); 379 const ReadingListEntry& other_entry = model_->GetReadEntryAtIndex(0);
170 EXPECT_EQ(GURL("http://example.com"), other_entry.URL()); 380 EXPECT_EQ(GURL("http://example.com"), other_entry.URL());
171 EXPECT_EQ("sample", other_entry.Title()); 381 EXPECT_EQ("sample", other_entry.Title());
172 } 382 }
173 383
174 TEST_F(ReadingListModelTest, EntryFromURL) { 384 TEST_F(ReadingListModelTest, EntryFromURL) {
175 GURL url1("http://example.com"); 385 GURL url1("http://example.com");
176 GURL url2("http://example2.com"); 386 GURL url2("http://example2.com");
177 std::string entry1_title = "foo bar qux"; 387 std::string entry1_title = "foo bar qux";
178 model_->AddEntry(url1, entry1_title); 388 model_->AddEntry(url1, entry1_title);
179 389
180 const ReadingListEntry* entry1 = model_->GetEntryFromURL(url1); 390 // Check call with nullptr |read| parameter.
181 EXPECT_NE(nullptr, entry1); 391 const ReadingListEntry* entry1 = model_->GetEntryFromURL(url1, nullptr);
182 EXPECT_EQ(entry1_title, entry1->Title());
183 model_->MarkReadByURL(url1);
184 entry1 = model_->GetEntryFromURL(url1);
185 EXPECT_NE(nullptr, entry1); 392 EXPECT_NE(nullptr, entry1);
186 EXPECT_EQ(entry1_title, entry1->Title()); 393 EXPECT_EQ(entry1_title, entry1->Title());
187 394
188 const ReadingListEntry* entry2 = model_->GetEntryFromURL(url2); 395 bool read;
396 entry1 = model_->GetEntryFromURL(url1, &read);
397 EXPECT_NE(nullptr, entry1);
398 EXPECT_EQ(entry1_title, entry1->Title());
399 EXPECT_EQ(read, false);
400 model_->MarkReadByURL(url1);
401 entry1 = model_->GetEntryFromURL(url1, &read);
402 EXPECT_NE(nullptr, entry1);
403 EXPECT_EQ(entry1_title, entry1->Title());
404 EXPECT_EQ(read, true);
405
406 const ReadingListEntry* entry2 = model_->GetEntryFromURL(url2, &read);
189 EXPECT_EQ(nullptr, entry2); 407 EXPECT_EQ(nullptr, entry2);
190 } 408 }
191 409
192 TEST_F(ReadingListModelTest, UnreadEntry) { 410 TEST_F(ReadingListModelTest, UnreadEntry) {
193 // Setup. 411 // Setup.
194 model_->AddEntry(GURL("http://example.com"), "sample"); 412 model_->AddEntry(GURL("http://example.com"), "sample");
195 model_->MarkReadByURL(GURL("http://example.com")); 413 model_->MarkReadByURL(GURL("http://example.com"));
196 ClearCounts(); 414 ClearCounts();
197 ASSERT_EQ(0ul, model_->unread_size()); 415 ASSERT_EQ(0ul, model_->unread_size());
198 ASSERT_EQ(1ul, model_->read_size()); 416 ASSERT_EQ(1ul, model_->read_size());
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 } 593 }
376 594
377 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. 595 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed.
378 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { 596 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) {
379 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); 597 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
380 model_.reset(); 598 model_.reset();
381 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); 599 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0);
382 } 600 }
383 601
384 } // namespace 602 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698