OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/reading_list/ios/reading_list_store.h" | 5 #include "components/reading_list/ios/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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
248 reading_list_store_->CreateMetadataChangeList(), add_changes); | 248 reading_list_store_->CreateMetadataChangeList(), add_changes); |
249 AssertCounts(1, 0, 0, 0, 1); | 249 AssertCounts(1, 0, 0, 0, 1); |
250 EXPECT_EQ(sync_merged_.size(), 1u); | 250 EXPECT_EQ(sync_merged_.size(), 1u); |
251 EXPECT_EQ(sync_merged_.count("http://unread.example.com/"), 1u); | 251 EXPECT_EQ(sync_merged_.count("http://unread.example.com/"), 1u); |
252 EXPECT_EQ(sync_merged_["http://unread.example.com/"], true); | 252 EXPECT_EQ(sync_merged_["http://unread.example.com/"], true); |
253 } | 253 } |
254 | 254 |
255 TEST_F(ReadingListStoreTest, ApplySyncChangesOneIgnored) { | 255 TEST_F(ReadingListStoreTest, ApplySyncChangesOneIgnored) { |
256 // Read entry but with unread URL as it must update the other one. | 256 // Read entry but with unread URL as it must update the other one. |
257 ReadingListEntry old_entry(GURL("http://unread.example.com/"), | 257 ReadingListEntry old_entry(GURL("http://unread.example.com/"), |
258 "unread title"); | 258 "old unread title"); |
259 old_entry.SetRead(true); | 259 old_entry.SetRead(true); |
260 | 260 |
261 base::test::ios::SpinRunLoopWithMinDelay( | 261 base::test::ios::SpinRunLoopWithMinDelay( |
262 base::TimeDelta::FromMilliseconds(10)); | 262 base::TimeDelta::FromMilliseconds(10)); |
263 syncer::EntityDataMap remote_input; | 263 syncer::EntityDataMap remote_input; |
264 model_->AddEntry(GURL("http://unread.example.com/"), "unread title"); | 264 model_->AddEntry(GURL("http://unread.example.com/"), "new unread title"); |
265 AssertCounts(0, 0, 0, 0, 0); | 265 AssertCounts(0, 0, 0, 0, 0); |
266 | 266 |
267 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = | 267 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = |
268 old_entry.AsReadingListSpecifics(); | 268 old_entry.AsReadingListSpecifics(); |
269 syncer::EntityData data; | 269 syncer::EntityData data; |
270 data.client_tag_hash = "http://unread.example.com/"; | 270 data.client_tag_hash = "http://unread.example.com/"; |
271 *data.specifics.mutable_reading_list() = *specifics; | 271 *data.specifics.mutable_reading_list() = *specifics; |
272 | 272 |
273 syncer::EntityChangeList add_changes; | 273 syncer::EntityChangeList add_changes; |
274 add_changes.push_back(syncer::EntityChange::CreateAdd( | 274 add_changes.push_back(syncer::EntityChange::CreateAdd( |
275 "http://unread.example.com/", data.PassToPtr())); | 275 "http://unread.example.com/", data.PassToPtr())); |
276 syncer::SyncError error = reading_list_store_->ApplySyncChanges( | 276 syncer::SyncError error = reading_list_store_->ApplySyncChanges( |
gambard
2016/12/07 10:28:49
Do you need the |error| variable?
| |
277 reading_list_store_->CreateMetadataChangeList(), add_changes); | 277 reading_list_store_->CreateMetadataChangeList(), add_changes); |
278 AssertCounts(1, 0, 0, 0, 0); | 278 AssertCounts(1, 0, 0, 0, 1); |
279 EXPECT_EQ(sync_merged_.size(), 0u); | 279 EXPECT_EQ(sync_merged_.size(), 1u); |
280 EXPECT_EQ(model_->GetEntryByURL(GURL("http://unread.example.com/"))->Title(), | |
281 "new unread title"); | |
280 } | 282 } |
281 | 283 |
282 TEST_F(ReadingListStoreTest, ApplySyncChangesOneRemove) { | 284 TEST_F(ReadingListStoreTest, ApplySyncChangesOneRemove) { |
283 syncer::EntityChangeList delete_changes; | 285 syncer::EntityChangeList delete_changes; |
284 delete_changes.push_back( | 286 delete_changes.push_back( |
285 syncer::EntityChange::CreateDelete("http://read.example.com/")); | 287 syncer::EntityChange::CreateDelete("http://read.example.com/")); |
286 syncer::SyncError error = reading_list_store_->ApplySyncChanges( | 288 syncer::SyncError error = reading_list_store_->ApplySyncChanges( |
287 reading_list_store_->CreateMetadataChangeList(), delete_changes); | 289 reading_list_store_->CreateMetadataChangeList(), delete_changes); |
288 AssertCounts(0, 0, 0, 1, 0); | 290 AssertCounts(0, 0, 0, 1, 0); |
289 EXPECT_EQ(sync_removed_.size(), 1u); | 291 EXPECT_EQ(sync_removed_.size(), 1u); |
290 EXPECT_EQ(sync_removed_.count("http://read.example.com/"), 1u); | 292 EXPECT_EQ(sync_removed_.count("http://read.example.com/"), 1u); |
291 } | 293 } |
294 | |
295 TEST_F(ReadingListStoreTest, CompareEntriesForSync) { | |
296 sync_pb::ReadingListSpecifics entryA; | |
297 sync_pb::ReadingListSpecifics entryB; | |
298 entryA.set_url("http://foo.bar"); | |
299 entryB.set_url("http://foo.bar"); | |
300 entryA.set_title("Foo Bar"); | |
301 entryB.set_title("Foo Bar"); | |
302 entryA.set_status(sync_pb::ReadingListSpecifics::UNREAD); | |
303 entryB.set_status(sync_pb::ReadingListSpecifics::UNREAD); | |
304 entryA.set_creation_time_us(10); | |
305 entryB.set_creation_time_us(10); | |
306 entryA.set_update_time_us(100); | |
307 entryB.set_update_time_us(100); | |
308 // Equal entries can be submitted. | |
309 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
310 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
311 | |
312 // Try to update each field. | |
313 entryA.set_url("http://foo.foo"); | |
314 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
315 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
316 entryA.set_update_time_us(110); | |
317 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
318 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
319 entryA.set_url("http://foo.bar"); | |
320 entryA.set_update_time_us(100); | |
321 | |
322 entryA.set_title("foo bar"); | |
323 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
324 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
325 entryA.set_update_time_us(110); | |
326 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
327 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
328 entryA.set_title("Foo Bar"); | |
329 entryA.set_update_time_us(100); | |
330 | |
331 entryA.set_creation_time_us(15); | |
332 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
333 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
334 entryA.set_update_time_us(110); | |
335 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
336 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
337 entryA.set_creation_time_us(10); | |
338 entryA.set_update_time_us(100); | |
339 | |
340 entryA.set_status(sync_pb::ReadingListSpecifics::READ); | |
341 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
342 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
343 entryA.set_update_time_us(110); | |
344 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
345 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
346 entryA.set_status(sync_pb::ReadingListSpecifics::UNREAD); | |
347 entryA.set_update_time_us(100); | |
348 | |
349 entryA.set_status(sync_pb::ReadingListSpecifics::UNSEEN); | |
350 // Special case UNSEEN -> SEEN status | |
351 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
352 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
353 entryA.set_update_time_us(110); | |
354 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB)); | |
355 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, entryA)); | |
356 entryA.set_status(sync_pb::ReadingListSpecifics::UNREAD); | |
357 entryA.set_update_time_us(100); | |
358 } | |
OLD | NEW |