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_entry.h" | 5 #include "components/reading_list/ios/reading_list_entry.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
9 #include "components/reading_list/ios/proto/reading_list.pb.h" | 9 #include "components/reading_list/ios/proto/reading_list.pb.h" |
10 #include "components/sync/protocol/reading_list_specifics.pb.h" | 10 #include "components/sync/protocol/reading_list_specifics.pb.h" |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); | 310 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); |
311 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); | 311 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); |
312 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); | 312 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); |
313 base::Time waiting_next_call = | 313 base::Time waiting_next_call = |
314 base::Time::Now() + waiting_entry->TimeUntilNextTry(); | 314 base::Time::Now() + waiting_entry->TimeUntilNextTry(); |
315 base::TimeDelta delta = next_call - waiting_next_call; | 315 base::TimeDelta delta = next_call - waiting_next_call; |
316 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); | 316 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); |
317 } | 317 } |
318 | 318 |
319 // Tests the merging of two ReadingListEntry. | 319 // Tests the merging of two ReadingListEntry. |
| 320 // Additional merging tests are done in |
| 321 // ReadingListStoreTest.CompareEntriesForSync |
320 TEST(ReadingListEntry, MergeWithEntry) { | 322 TEST(ReadingListEntry, MergeWithEntry) { |
321 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); | 323 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); |
322 local_entry.SetDistilledState(ReadingListEntry::ERROR); | 324 local_entry.SetDistilledState(ReadingListEntry::ERROR); |
323 base::Time next_call = base::Time::Now() + local_entry.TimeUntilNextTry(); | 325 base::Time next_call = base::Time::Now() + local_entry.TimeUntilNextTry(); |
324 int64_t local_update_time_us = local_entry.UpdateTime(); | 326 int64_t local_update_time_us = local_entry.UpdateTime(); |
325 | 327 |
326 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); | 328 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); |
327 sync_entry.SetDistilledState(ReadingListEntry::ERROR); | 329 sync_entry.SetDistilledState(ReadingListEntry::ERROR); |
328 int64_t sync_update_time_us = sync_entry.UpdateTime(); | 330 int64_t sync_update_time_us = sync_entry.UpdateTime(); |
329 EXPECT_NE(local_update_time_us, sync_update_time_us); | 331 EXPECT_NE(local_update_time_us, sync_update_time_us); |
330 local_entry.MergeWithEntry(sync_entry); | 332 local_entry.MergeWithEntry(sync_entry); |
331 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); | 333 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); |
332 EXPECT_EQ(local_entry.Title(), "title2"); | 334 EXPECT_EQ(local_entry.Title(), "title2"); |
333 EXPECT_FALSE(local_entry.HasBeenSeen()); | 335 EXPECT_FALSE(local_entry.HasBeenSeen()); |
334 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); | 336 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); |
335 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); | 337 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); |
336 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); | 338 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); |
337 base::Time merge_next_call = | 339 base::Time merge_next_call = |
338 base::Time::Now() + local_entry.TimeUntilNextTry(); | 340 base::Time::Now() + local_entry.TimeUntilNextTry(); |
339 base::TimeDelta delta = merge_next_call - next_call; | 341 base::TimeDelta delta = merge_next_call - next_call; |
340 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); | 342 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); |
341 } | 343 } |
342 | |
343 // Tests the merging of two ReadingListEntry, the oldest one SEEN and the newer | |
344 // UNSEEN. | |
345 TEST(ReadingListEntry, MergeWithEntrySeen) { | |
346 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); | |
347 local_entry.SetRead(true); | |
348 int64_t local_update_time_us = local_entry.UpdateTime(); | |
349 local_entry.SetDistilledPath(base::FilePath("distilled/page.html")); | |
350 | |
351 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); | |
352 int64_t sync_update_time_us = sync_entry.UpdateTime(); | |
353 EXPECT_NE(local_update_time_us, sync_update_time_us); | |
354 local_entry.MergeWithEntry(sync_entry); | |
355 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); | |
356 EXPECT_EQ(local_entry.Title(), "title2"); | |
357 EXPECT_TRUE(local_entry.HasBeenSeen()); | |
358 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); | |
359 EXPECT_EQ(local_entry.FailedDownloadCounter(), 0); | |
360 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::PROCESSED); | |
361 EXPECT_EQ(local_entry.DistilledPath().value(), "distilled/page.html"); | |
362 } | |
OLD | NEW |