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

Side by Side Diff: components/reading_list/ios/reading_list_store_unittest.mm

Issue 2553143002: Create a strict order in ReadingListSpecifics (Closed)
Patch Set: rebase Created 4 years 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
« no previous file with comments | « components/reading_list/ios/reading_list_store.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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(
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 } 280 }
281 281
282 TEST_F(ReadingListStoreTest, ApplySyncChangesOneRemove) { 282 TEST_F(ReadingListStoreTest, ApplySyncChangesOneRemove) {
283 syncer::EntityChangeList delete_changes; 283 syncer::EntityChangeList delete_changes;
284 delete_changes.push_back( 284 delete_changes.push_back(
285 syncer::EntityChange::CreateDelete("http://read.example.com/")); 285 syncer::EntityChange::CreateDelete("http://read.example.com/"));
286 syncer::SyncError error = reading_list_store_->ApplySyncChanges( 286 syncer::SyncError error = reading_list_store_->ApplySyncChanges(
287 reading_list_store_->CreateMetadataChangeList(), delete_changes); 287 reading_list_store_->CreateMetadataChangeList(), delete_changes);
288 AssertCounts(0, 0, 0, 1, 0); 288 AssertCounts(0, 0, 0, 1, 0);
289 EXPECT_EQ(sync_removed_.size(), 1u); 289 EXPECT_EQ(sync_removed_.size(), 1u);
290 EXPECT_EQ(sync_removed_.count("http://read.example.com/"), 1u); 290 EXPECT_EQ(sync_removed_.count("http://read.example.com/"), 1u);
291 } 291 }
292
293 TEST_F(ReadingListStoreTest, CompareEntriesForSync) {
294 sync_pb::ReadingListSpecifics entryA;
295 sync_pb::ReadingListSpecifics entryB;
296 entryA.set_url("http://foo.bar");
297 entryB.set_url("http://foo.bar");
298 entryA.set_title("Foo Bar");
299 entryB.set_title("Foo Bar");
300 entryA.set_status(sync_pb::ReadingListSpecifics::UNREAD);
301 entryB.set_status(sync_pb::ReadingListSpecifics::UNREAD);
302 entryA.set_creation_time_us(10);
303 entryB.set_creation_time_us(10);
304 entryA.set_update_time_us(100);
305 entryB.set_update_time_us(100);
306 // Equal entries can be submitted.
307 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
308 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
309
310 // Try to update each field.
311
312 // You cannot change the URL of an entry.
313 entryA.set_url("http://foo.foo");
314 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
315 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
316 entryA.set_url("http://foo.bar");
317
318 // You can set a title to a title later in alphabetical order.
319 entryA.set_title("");
320 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
321 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
322 entryA.set_title("Foo Aar");
323 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
324 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
325 entryA.set_title("Foo Ba");
326 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
327 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
328 entryA.set_title("Foo Bar");
329
330 entryA.set_creation_time_us(9);
331 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
332 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
333 entryA.set_creation_time_us(10);
334
335 entryA.set_update_time_us(99);
336 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
337 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
338 sync_pb::ReadingListSpecifics::ReadingListEntryStatus status_oder[3] = {
339 sync_pb::ReadingListSpecifics::UNSEEN,
340 sync_pb::ReadingListSpecifics::UNREAD,
341 sync_pb::ReadingListSpecifics::READ};
342 for (int index_a = 0; index_a < 3; index_a++) {
343 entryA.set_status(status_oder[index_a]);
344 for (int index_b = 0; index_b < 3; index_b++) {
345 entryB.set_status(status_oder[index_b]);
346 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
347 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
348 }
349 }
350 entryA.set_update_time_us(100);
351 for (int index_a = 0; index_a < 3; index_a++) {
352 entryA.set_status(status_oder[index_a]);
353 entryB.set_status(status_oder[index_a]);
354 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
355 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
356 for (int index_b = index_a + 1; index_b < 3; index_b++) {
357 entryB.set_status(status_oder[index_b]);
358 EXPECT_TRUE(ReadingListStore::CompareEntriesForSync(entryA, entryB));
359 EXPECT_FALSE(ReadingListStore::CompareEntriesForSync(entryB, entryA));
360 }
361 }
362 }
OLDNEW
« no previous file with comments | « components/reading_list/ios/reading_list_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698