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

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

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

Powered by Google App Engine
This is Rietveld 408576698