Chromium Code Reviews| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 entry.AsReadingListSpecifics(); | 213 entry.AsReadingListSpecifics(); |
| 214 | 214 |
| 215 syncer::EntityData data; | 215 syncer::EntityData data; |
| 216 data.client_tag_hash = "http://read.example.com/"; | 216 data.client_tag_hash = "http://read.example.com/"; |
| 217 *data.specifics.mutable_reading_list() = *specifics; | 217 *data.specifics.mutable_reading_list() = *specifics; |
| 218 | 218 |
| 219 remote_input["http://read.example.com/"] = data.PassToPtr(); | 219 remote_input["http://read.example.com/"] = data.PassToPtr(); |
| 220 | 220 |
| 221 std::unique_ptr<syncer::MetadataChangeList> metadata_changes( | 221 std::unique_ptr<syncer::MetadataChangeList> metadata_changes( |
| 222 reading_list_store_->CreateMetadataChangeList()); | 222 reading_list_store_->CreateMetadataChangeList()); |
| 223 const syncer::ModelError error = reading_list_store_->MergeSyncData( | 223 auto error = reading_list_store_->MergeSyncData(std::move(metadata_changes), |
|
skym
2017/01/10 16:24:41
Why are these error variables being stored? They'r
maxbogue
2017/01/10 17:53:50
I don't know; I'll ask Olivier about it.
| |
| 224 std::move(metadata_changes), remote_input); | 224 remote_input); |
| 225 AssertCounts(0, 0, 1, 0, 0); | 225 AssertCounts(0, 0, 1, 0, 0); |
| 226 EXPECT_EQ(sync_added_.size(), 1u); | 226 EXPECT_EQ(sync_added_.size(), 1u); |
| 227 EXPECT_EQ(sync_added_.count("http://read.example.com/"), 1u); | 227 EXPECT_EQ(sync_added_.count("http://read.example.com/"), 1u); |
| 228 EXPECT_EQ(sync_added_["http://read.example.com/"], true); | 228 EXPECT_EQ(sync_added_["http://read.example.com/"], true); |
| 229 } | 229 } |
| 230 | 230 |
| 231 TEST_F(ReadingListStoreTest, ApplySyncChangesOneAdd) { | 231 TEST_F(ReadingListStoreTest, ApplySyncChangesOneAdd) { |
| 232 syncer::EntityDataMap remote_input; | 232 syncer::EntityDataMap remote_input; |
| 233 ReadingListEntry entry(GURL("http://read.example.com/"), "read title"); | 233 ReadingListEntry entry(GURL("http://read.example.com/"), "read title"); |
| 234 entry.SetRead(true); | 234 entry.SetRead(true); |
| 235 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = | 235 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = |
| 236 entry.AsReadingListSpecifics(); | 236 entry.AsReadingListSpecifics(); |
| 237 syncer::EntityData data; | 237 syncer::EntityData data; |
| 238 data.client_tag_hash = "http://read.example.com/"; | 238 data.client_tag_hash = "http://read.example.com/"; |
| 239 *data.specifics.mutable_reading_list() = *specifics; | 239 *data.specifics.mutable_reading_list() = *specifics; |
| 240 | 240 |
| 241 syncer::EntityChangeList add_changes; | 241 syncer::EntityChangeList add_changes; |
| 242 | 242 |
| 243 add_changes.push_back(syncer::EntityChange::CreateAdd( | 243 add_changes.push_back(syncer::EntityChange::CreateAdd( |
| 244 "http://read.example.com/", data.PassToPtr())); | 244 "http://read.example.com/", data.PassToPtr())); |
| 245 syncer::ModelError error = reading_list_store_->ApplySyncChanges( | 245 auto error = reading_list_store_->ApplySyncChanges( |
| 246 reading_list_store_->CreateMetadataChangeList(), add_changes); | 246 reading_list_store_->CreateMetadataChangeList(), add_changes); |
| 247 AssertCounts(0, 0, 1, 0, 0); | 247 AssertCounts(0, 0, 1, 0, 0); |
| 248 EXPECT_EQ(sync_added_.size(), 1u); | 248 EXPECT_EQ(sync_added_.size(), 1u); |
| 249 EXPECT_EQ(sync_added_.count("http://read.example.com/"), 1u); | 249 EXPECT_EQ(sync_added_.count("http://read.example.com/"), 1u); |
| 250 EXPECT_EQ(sync_added_["http://read.example.com/"], true); | 250 EXPECT_EQ(sync_added_["http://read.example.com/"], true); |
| 251 } | 251 } |
| 252 | 252 |
| 253 TEST_F(ReadingListStoreTest, ApplySyncChangesOneMerge) { | 253 TEST_F(ReadingListStoreTest, ApplySyncChangesOneMerge) { |
| 254 syncer::EntityDataMap remote_input; | 254 syncer::EntityDataMap remote_input; |
| 255 model_->AddEntry(GURL("http://unread.example.com/"), "unread title"); | 255 model_->AddEntry(GURL("http://unread.example.com/"), "unread title"); |
| 256 base::test::ios::SpinRunLoopWithMinDelay( | 256 base::test::ios::SpinRunLoopWithMinDelay( |
| 257 base::TimeDelta::FromMilliseconds(10)); | 257 base::TimeDelta::FromMilliseconds(10)); |
| 258 | 258 |
| 259 ReadingListEntry new_entry(GURL("http://unread.example.com/"), | 259 ReadingListEntry new_entry(GURL("http://unread.example.com/"), |
| 260 "unread title"); | 260 "unread title"); |
| 261 new_entry.SetRead(true); | 261 new_entry.SetRead(true); |
| 262 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = | 262 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = |
| 263 new_entry.AsReadingListSpecifics(); | 263 new_entry.AsReadingListSpecifics(); |
| 264 syncer::EntityData data; | 264 syncer::EntityData data; |
| 265 data.client_tag_hash = "http://unread.example.com/"; | 265 data.client_tag_hash = "http://unread.example.com/"; |
| 266 *data.specifics.mutable_reading_list() = *specifics; | 266 *data.specifics.mutable_reading_list() = *specifics; |
| 267 | 267 |
| 268 syncer::EntityChangeList add_changes; | 268 syncer::EntityChangeList add_changes; |
| 269 add_changes.push_back(syncer::EntityChange::CreateAdd( | 269 add_changes.push_back(syncer::EntityChange::CreateAdd( |
| 270 "http://unread.example.com/", data.PassToPtr())); | 270 "http://unread.example.com/", data.PassToPtr())); |
| 271 syncer::ModelError error = reading_list_store_->ApplySyncChanges( | 271 auto error = reading_list_store_->ApplySyncChanges( |
| 272 reading_list_store_->CreateMetadataChangeList(), add_changes); | 272 reading_list_store_->CreateMetadataChangeList(), add_changes); |
| 273 AssertCounts(1, 0, 0, 0, 1); | 273 AssertCounts(1, 0, 0, 0, 1); |
| 274 EXPECT_EQ(sync_merged_.size(), 1u); | 274 EXPECT_EQ(sync_merged_.size(), 1u); |
| 275 EXPECT_EQ(sync_merged_.count("http://unread.example.com/"), 1u); | 275 EXPECT_EQ(sync_merged_.count("http://unread.example.com/"), 1u); |
| 276 EXPECT_EQ(sync_merged_["http://unread.example.com/"], true); | 276 EXPECT_EQ(sync_merged_["http://unread.example.com/"], true); |
| 277 } | 277 } |
| 278 | 278 |
| 279 TEST_F(ReadingListStoreTest, ApplySyncChangesOneIgnored) { | 279 TEST_F(ReadingListStoreTest, ApplySyncChangesOneIgnored) { |
| 280 // Read entry but with unread URL as it must update the other one. | 280 // Read entry but with unread URL as it must update the other one. |
| 281 ReadingListEntry old_entry(GURL("http://unread.example.com/"), | 281 ReadingListEntry old_entry(GURL("http://unread.example.com/"), |
| 282 "old unread title"); | 282 "old unread title"); |
| 283 old_entry.SetRead(true); | 283 old_entry.SetRead(true); |
| 284 | 284 |
| 285 base::test::ios::SpinRunLoopWithMinDelay( | 285 base::test::ios::SpinRunLoopWithMinDelay( |
| 286 base::TimeDelta::FromMilliseconds(10)); | 286 base::TimeDelta::FromMilliseconds(10)); |
| 287 syncer::EntityDataMap remote_input; | 287 syncer::EntityDataMap remote_input; |
| 288 model_->AddEntry(GURL("http://unread.example.com/"), "new unread title"); | 288 model_->AddEntry(GURL("http://unread.example.com/"), "new unread title"); |
| 289 AssertCounts(0, 0, 0, 0, 0); | 289 AssertCounts(0, 0, 0, 0, 0); |
| 290 | 290 |
| 291 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = | 291 std::unique_ptr<sync_pb::ReadingListSpecifics> specifics = |
| 292 old_entry.AsReadingListSpecifics(); | 292 old_entry.AsReadingListSpecifics(); |
| 293 syncer::EntityData data; | 293 syncer::EntityData data; |
| 294 data.client_tag_hash = "http://unread.example.com/"; | 294 data.client_tag_hash = "http://unread.example.com/"; |
| 295 *data.specifics.mutable_reading_list() = *specifics; | 295 *data.specifics.mutable_reading_list() = *specifics; |
| 296 | 296 |
| 297 syncer::EntityChangeList add_changes; | 297 syncer::EntityChangeList add_changes; |
| 298 add_changes.push_back(syncer::EntityChange::CreateAdd( | 298 add_changes.push_back(syncer::EntityChange::CreateAdd( |
| 299 "http://unread.example.com/", data.PassToPtr())); | 299 "http://unread.example.com/", data.PassToPtr())); |
| 300 syncer::ModelError error = reading_list_store_->ApplySyncChanges( | 300 auto error = reading_list_store_->ApplySyncChanges( |
| 301 reading_list_store_->CreateMetadataChangeList(), add_changes); | 301 reading_list_store_->CreateMetadataChangeList(), add_changes); |
| 302 AssertCounts(1, 0, 0, 0, 1); | 302 AssertCounts(1, 0, 0, 0, 1); |
| 303 EXPECT_EQ(sync_merged_.size(), 1u); | 303 EXPECT_EQ(sync_merged_.size(), 1u); |
| 304 } | 304 } |
| 305 | 305 |
| 306 TEST_F(ReadingListStoreTest, ApplySyncChangesOneRemove) { | 306 TEST_F(ReadingListStoreTest, ApplySyncChangesOneRemove) { |
| 307 syncer::EntityChangeList delete_changes; | 307 syncer::EntityChangeList delete_changes; |
| 308 delete_changes.push_back( | 308 delete_changes.push_back( |
| 309 syncer::EntityChange::CreateDelete("http://read.example.com/")); | 309 syncer::EntityChange::CreateDelete("http://read.example.com/")); |
| 310 syncer::ModelError error = reading_list_store_->ApplySyncChanges( | 310 auto error = reading_list_store_->ApplySyncChanges( |
| 311 reading_list_store_->CreateMetadataChangeList(), delete_changes); | 311 reading_list_store_->CreateMetadataChangeList(), delete_changes); |
| 312 AssertCounts(0, 0, 0, 1, 0); | 312 AssertCounts(0, 0, 0, 1, 0); |
| 313 EXPECT_EQ(sync_removed_.size(), 1u); | 313 EXPECT_EQ(sync_removed_.size(), 1u); |
| 314 EXPECT_EQ(sync_removed_.count("http://read.example.com/"), 1u); | 314 EXPECT_EQ(sync_removed_.count("http://read.example.com/"), 1u); |
| 315 } | 315 } |
| 316 | 316 |
| 317 TEST_F(ReadingListStoreTest, CompareEntriesForSync) { | 317 TEST_F(ReadingListStoreTest, CompareEntriesForSync) { |
| 318 sync_pb::ReadingListSpecifics entryA; | 318 sync_pb::ReadingListSpecifics entryA; |
| 319 sync_pb::ReadingListSpecifics entryB; | 319 sync_pb::ReadingListSpecifics entryB; |
| 320 entryA.set_entry_id("http://foo.bar/"); | 320 entryA.set_entry_id("http://foo.bar/"); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 entryB.set_status(status_oder[index_a]); | 429 entryB.set_status(status_oder[index_a]); |
| 430 ExpectAB(entryA, entryB, true); | 430 ExpectAB(entryA, entryB, true); |
| 431 ExpectAB(entryB, entryA, true); | 431 ExpectAB(entryB, entryA, true); |
| 432 for (int index_b = index_a + 1; index_b < 3; index_b++) { | 432 for (int index_b = index_a + 1; index_b < 3; index_b++) { |
| 433 entryB.set_status(status_oder[index_b]); | 433 entryB.set_status(status_oder[index_b]); |
| 434 ExpectAB(entryA, entryB, true); | 434 ExpectAB(entryA, entryB, true); |
| 435 ExpectAB(entryB, entryA, false); | 435 ExpectAB(entryB, entryA, false); |
| 436 } | 436 } |
| 437 } | 437 } |
| 438 } | 438 } |
| OLD | NEW |