OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/reading_list/core/reading_list_store.h" | 5 #include "components/reading_list/core/reading_list_store.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 AssertCounts(1, 0, 0, 0, 0); | 217 AssertCounts(1, 0, 0, 0, 0); |
218 syncer::EntityData* data = put_multimap_["http://unread.example.com/"].get(); | 218 syncer::EntityData* data = put_multimap_["http://unread.example.com/"].get(); |
219 const sync_pb::ReadingListSpecifics& specifics = | 219 const sync_pb::ReadingListSpecifics& specifics = |
220 data->specifics.reading_list(); | 220 data->specifics.reading_list(); |
221 EXPECT_EQ(specifics.title(), "unread title"); | 221 EXPECT_EQ(specifics.title(), "unread title"); |
222 EXPECT_EQ(specifics.url(), "http://unread.example.com/"); | 222 EXPECT_EQ(specifics.url(), "http://unread.example.com/"); |
223 EXPECT_EQ(specifics.status(), sync_pb::ReadingListSpecifics::UNSEEN); | 223 EXPECT_EQ(specifics.status(), sync_pb::ReadingListSpecifics::UNSEEN); |
224 } | 224 } |
225 | 225 |
226 TEST_F(ReadingListStoreTest, SyncMergeOneEntry) { | 226 TEST_F(ReadingListStoreTest, SyncMergeOneEntry) { |
227 syncer::EntityDataMap remote_input; | 227 syncer::EntityChangeList remote_input; |
228 ReadingListEntry entry(GURL("http://read.example.com/"), "read title", | 228 ReadingListEntry entry(GURL("http://read.example.com/"), "read title", |
229 AdvanceAndGetTime(clock_)); | 229 AdvanceAndGetTime(clock_)); |
230 entry.SetRead(true, AdvanceAndGetTime(clock_)); | 230 entry.SetRead(true, AdvanceAndGetTime(clock_)); |
231 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = | 231 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = |
232 entry.AsReadingListSpecifics(); | 232 entry.AsReadingListSpecifics(); |
233 | 233 |
234 syncer::EntityData data; | 234 syncer::EntityData data; |
235 data.client_tag_hash = "http://read.example.com/"; | 235 data.client_tag_hash = "http://read.example.com/"; |
236 *data.specifics.mutable_reading_list() = *specifics; | 236 *data.specifics.mutable_reading_list() = *specifics; |
237 | 237 |
238 remote_input["http://read.example.com/"] = data.PassToPtr(); | 238 remote_input.push_back(syncer::EntityChange::CreateAdd( |
| 239 "http://read.example.com/", data.PassToPtr())); |
239 | 240 |
240 std::unique_ptr<syncer::MetadataChangeList> metadata_changes( | 241 std::unique_ptr<syncer::MetadataChangeList> metadata_changes( |
241 reading_list_store_->CreateMetadataChangeList()); | 242 reading_list_store_->CreateMetadataChangeList()); |
242 auto error = reading_list_store_->MergeSyncData(std::move(metadata_changes), | 243 auto error = reading_list_store_->MergeSyncData(std::move(metadata_changes), |
243 remote_input); | 244 remote_input); |
244 AssertCounts(0, 0, 1, 0, 0); | 245 AssertCounts(0, 0, 1, 0, 0); |
245 EXPECT_EQ(sync_added_.size(), 1u); | 246 EXPECT_EQ(sync_added_.size(), 1u); |
246 EXPECT_EQ(sync_added_.count("http://read.example.com/"), 1u); | 247 EXPECT_EQ(sync_added_.count("http://read.example.com/"), 1u); |
247 EXPECT_EQ(sync_added_["http://read.example.com/"], true); | 248 EXPECT_EQ(sync_added_["http://read.example.com/"], true); |
248 } | 249 } |
249 | 250 |
250 TEST_F(ReadingListStoreTest, ApplySyncChangesOneAdd) { | 251 TEST_F(ReadingListStoreTest, ApplySyncChangesOneAdd) { |
251 syncer::EntityDataMap remote_input; | |
252 ReadingListEntry entry(GURL("http://read.example.com/"), "read title", | 252 ReadingListEntry entry(GURL("http://read.example.com/"), "read title", |
253 AdvanceAndGetTime(clock_)); | 253 AdvanceAndGetTime(clock_)); |
254 entry.SetRead(true, AdvanceAndGetTime(clock_)); | 254 entry.SetRead(true, AdvanceAndGetTime(clock_)); |
255 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = | 255 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = |
256 entry.AsReadingListSpecifics(); | 256 entry.AsReadingListSpecifics(); |
257 syncer::EntityData data; | 257 syncer::EntityData data; |
258 data.client_tag_hash = "http://read.example.com/"; | 258 data.client_tag_hash = "http://read.example.com/"; |
259 *data.specifics.mutable_reading_list() = *specifics; | 259 *data.specifics.mutable_reading_list() = *specifics; |
260 | 260 |
261 syncer::EntityChangeList add_changes; | 261 syncer::EntityChangeList add_changes; |
262 | 262 |
263 add_changes.push_back(syncer::EntityChange::CreateAdd( | 263 add_changes.push_back(syncer::EntityChange::CreateAdd( |
264 "http://read.example.com/", data.PassToPtr())); | 264 "http://read.example.com/", data.PassToPtr())); |
265 auto error = reading_list_store_->ApplySyncChanges( | 265 auto error = reading_list_store_->ApplySyncChanges( |
266 reading_list_store_->CreateMetadataChangeList(), add_changes); | 266 reading_list_store_->CreateMetadataChangeList(), add_changes); |
267 AssertCounts(0, 0, 1, 0, 0); | 267 AssertCounts(0, 0, 1, 0, 0); |
268 EXPECT_EQ(sync_added_.size(), 1u); | 268 EXPECT_EQ(sync_added_.size(), 1u); |
269 EXPECT_EQ(sync_added_.count("http://read.example.com/"), 1u); | 269 EXPECT_EQ(sync_added_.count("http://read.example.com/"), 1u); |
270 EXPECT_EQ(sync_added_["http://read.example.com/"], true); | 270 EXPECT_EQ(sync_added_["http://read.example.com/"], true); |
271 } | 271 } |
272 | 272 |
273 TEST_F(ReadingListStoreTest, ApplySyncChangesOneMerge) { | 273 TEST_F(ReadingListStoreTest, ApplySyncChangesOneMerge) { |
274 syncer::EntityDataMap remote_input; | |
275 AdvanceAndGetTime(clock_); | 274 AdvanceAndGetTime(clock_); |
276 model_->AddEntry(GURL("http://unread.example.com/"), "unread title", | 275 model_->AddEntry(GURL("http://unread.example.com/"), "unread title", |
277 reading_list::ADDED_VIA_CURRENT_APP); | 276 reading_list::ADDED_VIA_CURRENT_APP); |
278 | 277 |
279 ReadingListEntry new_entry(GURL("http://unread.example.com/"), "unread title", | 278 ReadingListEntry new_entry(GURL("http://unread.example.com/"), "unread title", |
280 AdvanceAndGetTime(clock_)); | 279 AdvanceAndGetTime(clock_)); |
281 new_entry.SetRead(true, AdvanceAndGetTime(clock_)); | 280 new_entry.SetRead(true, AdvanceAndGetTime(clock_)); |
282 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = | 281 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = |
283 new_entry.AsReadingListSpecifics(); | 282 new_entry.AsReadingListSpecifics(); |
284 syncer::EntityData data; | 283 syncer::EntityData data; |
(...skipping 10 matching lines...) Expand all Loading... |
295 EXPECT_EQ(sync_merged_.count("http://unread.example.com/"), 1u); | 294 EXPECT_EQ(sync_merged_.count("http://unread.example.com/"), 1u); |
296 EXPECT_EQ(sync_merged_["http://unread.example.com/"], true); | 295 EXPECT_EQ(sync_merged_["http://unread.example.com/"], true); |
297 } | 296 } |
298 | 297 |
299 TEST_F(ReadingListStoreTest, ApplySyncChangesOneIgnored) { | 298 TEST_F(ReadingListStoreTest, ApplySyncChangesOneIgnored) { |
300 // Read entry but with unread URL as it must update the other one. | 299 // Read entry but with unread URL as it must update the other one. |
301 ReadingListEntry old_entry(GURL("http://unread.example.com/"), | 300 ReadingListEntry old_entry(GURL("http://unread.example.com/"), |
302 "old unread title", AdvanceAndGetTime(clock_)); | 301 "old unread title", AdvanceAndGetTime(clock_)); |
303 old_entry.SetRead(true, AdvanceAndGetTime(clock_)); | 302 old_entry.SetRead(true, AdvanceAndGetTime(clock_)); |
304 | 303 |
305 syncer::EntityDataMap remote_input; | |
306 AdvanceAndGetTime(clock_); | 304 AdvanceAndGetTime(clock_); |
307 model_->AddEntry(GURL("http://unread.example.com/"), "new unread title", | 305 model_->AddEntry(GURL("http://unread.example.com/"), "new unread title", |
308 reading_list::ADDED_VIA_CURRENT_APP); | 306 reading_list::ADDED_VIA_CURRENT_APP); |
309 AssertCounts(0, 0, 0, 0, 0); | 307 AssertCounts(0, 0, 0, 0, 0); |
310 | 308 |
311 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = | 309 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = |
312 old_entry.AsReadingListSpecifics(); | 310 old_entry.AsReadingListSpecifics(); |
313 syncer::EntityData data; | 311 syncer::EntityData data; |
314 data.client_tag_hash = "http://unread.example.com/"; | 312 data.client_tag_hash = "http://unread.example.com/"; |
315 *data.specifics.mutable_reading_list() = *specifics; | 313 *data.specifics.mutable_reading_list() = *specifics; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 entryB.set_status(status_oder[index_a]); | 447 entryB.set_status(status_oder[index_a]); |
450 ExpectAB(entryA, entryB, true); | 448 ExpectAB(entryA, entryB, true); |
451 ExpectAB(entryB, entryA, true); | 449 ExpectAB(entryB, entryA, true); |
452 for (int index_b = index_a + 1; index_b < 3; index_b++) { | 450 for (int index_b = index_a + 1; index_b < 3; index_b++) { |
453 entryB.set_status(status_oder[index_b]); | 451 entryB.set_status(status_oder[index_b]); |
454 ExpectAB(entryA, entryB, true); | 452 ExpectAB(entryA, entryB, true); |
455 ExpectAB(entryB, entryA, false); | 453 ExpectAB(entryB, entryA, false); |
456 } | 454 } |
457 } | 455 } |
458 } | 456 } |
OLD | NEW |