Chromium Code Reviews| Index: components/reading_list/ios/reading_list_entry_unittest.cc |
| diff --git a/components/reading_list/ios/reading_list_entry_unittest.cc b/components/reading_list/ios/reading_list_entry_unittest.cc |
| index a4e38b534d5820f15d63a056b7dbacb8bf58ea6f..2ab9c38115709eaad0365f55b3ad0ee90c3c8e3e 100644 |
| --- a/components/reading_list/ios/reading_list_entry_unittest.cc |
| +++ b/components/reading_list/ios/reading_list_entry_unittest.cc |
| @@ -5,7 +5,6 @@ |
| #include "components/reading_list/ios/reading_list_entry.h" |
| #include "base/memory/ptr_util.h" |
| -#include "base/test/ios/wait_util.h" |
| #include "base/test/simple_test_tick_clock.h" |
| #include "components/reading_list/ios/proto/reading_list.pb.h" |
| #include "components/sync/protocol/reading_list_specifics.pb.h" |
| @@ -21,57 +20,74 @@ const int kFifthBackoff = 120; |
| } // namespace |
| TEST(ReadingListEntry, CompareIgnoreTitle) { |
| - const ReadingListEntry e1(GURL("http://example.com"), "bar"); |
| - const ReadingListEntry e2(GURL("http://example.com"), "foo"); |
| + const ReadingListEntry e1(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| + const ReadingListEntry e2(GURL("http://example.com"), "foo", |
| + base::Time::FromTimeT(20)); |
| EXPECT_EQ(e1, e2); |
| } |
| -TEST(ReadingListEntry, CompareFailureIgnoreTitle) { |
| - const ReadingListEntry e1(GURL("http://example.com"), "bar"); |
| - const ReadingListEntry e2(GURL("http://example.org"), "bar"); |
| +TEST(ReadingListEntry, CompareFailureIgnoreTitleAndCreationTime) { |
| + const ReadingListEntry e1(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| + const ReadingListEntry e2(GURL("http://example.org"), "bar", |
| + base::Time::FromTimeT(10)); |
| EXPECT_FALSE(e1 == e2); |
| } |
| TEST(ReadingListEntry, MovesAreEquals) { |
| - ReadingListEntry e1(GURL("http://example.com"), "bar"); |
| - ReadingListEntry e2(GURL("http://example.com"), "bar"); |
| - ASSERT_EQ(e1, e2); |
| - ASSERT_EQ(e1.Title(), e2.Title()); |
| + ReadingListEntry e1(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| + ReadingListEntry e2(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| + EXPECT_EQ(e1, e2); |
| + EXPECT_EQ(e1.Title(), e2.Title()); |
| + EXPECT_EQ(e1.CreationTime(), e2.CreationTime()); |
| ReadingListEntry e3(std::move(e1)); |
| EXPECT_EQ(e3, e2); |
| EXPECT_EQ(e3.Title(), e2.Title()); |
| + EXPECT_EQ(e3.CreationTime(), e2.CreationTime()); |
| } |
| TEST(ReadingListEntry, ReadState) { |
| - ReadingListEntry e(GURL("http://example.com"), "bar"); |
| + ReadingListEntry e(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| EXPECT_FALSE(e.HasBeenSeen()); |
| EXPECT_FALSE(e.IsRead()); |
| - e.SetRead(false); |
| + e.SetRead(false, base::Time::FromTimeT(20)); |
| + EXPECT_EQ(e.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond); |
| + EXPECT_EQ(e.UpdateTime(), 20 * base::Time::kMicrosecondsPerSecond); |
| + EXPECT_EQ(e.UpdateTitleTime(), 10 * base::Time::kMicrosecondsPerSecond); |
| EXPECT_TRUE(e.HasBeenSeen()); |
| EXPECT_FALSE(e.IsRead()); |
| - e.SetRead(true); |
| + e.SetRead(true, base::Time::FromTimeT(30)); |
| + EXPECT_EQ(e.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond); |
| + EXPECT_EQ(e.UpdateTime(), 30 * base::Time::kMicrosecondsPerSecond); |
| + EXPECT_EQ(e.UpdateTitleTime(), 10 * base::Time::kMicrosecondsPerSecond); |
| EXPECT_TRUE(e.HasBeenSeen()); |
| EXPECT_TRUE(e.IsRead()); |
| } |
| TEST(ReadingListEntry, UpdateTitle) { |
| - ReadingListEntry e(GURL("http://example.com"), "bar"); |
| - ASSERT_EQ("bar", e.Title()); |
| - ASSERT_EQ(e.CreationTime(), e.UpdateTitleTime()); |
| - |
| - base::test::ios::SpinRunLoopWithMinDelay( |
| - base::TimeDelta::FromMilliseconds(5)); |
| - e.SetTitle("foo"); |
| - EXPECT_GT(e.UpdateTitleTime(), e.CreationTime()); |
| + ReadingListEntry e(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| + EXPECT_EQ("bar", e.Title()); |
| + // Getters are in microseconds. |
| + EXPECT_EQ(e.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond); |
| + EXPECT_EQ(e.UpdateTitleTime(), 10 * base::Time::kMicrosecondsPerSecond); |
| + |
| + e.SetTitle("foo", base::Time::FromTimeT(15)); |
| + EXPECT_EQ(e.UpdateTitleTime(), 15 * base::Time::kMicrosecondsPerSecond); |
| EXPECT_EQ("foo", e.Title()); |
| } |
| TEST(ReadingListEntry, DistilledInfo) { |
| - ReadingListEntry e(GURL("http://example.com"), "bar"); |
| + ReadingListEntry e(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| EXPECT_TRUE(e.DistilledPath().empty()); |
| @@ -79,15 +95,17 @@ TEST(ReadingListEntry, DistilledInfo) { |
| const GURL distilled_url("http://example.com/distilled"); |
| int64_t size = 50; |
| int64_t time = 100; |
| - e.SetDistilledInfo(distilled_path, distilled_url, size, time); |
| + e.SetDistilledInfo(distilled_path, distilled_url, size, |
| + base::Time::FromTimeT(time)); |
| EXPECT_EQ(distilled_path, e.DistilledPath()); |
| EXPECT_EQ(distilled_url, e.DistilledURL()); |
| EXPECT_EQ(size, e.DistillationSize()); |
| - EXPECT_EQ(e.DistillationTime(), time); |
| + EXPECT_EQ(e.DistillationTime(), time * base::Time::kMicrosecondsPerSecond); |
| } |
| TEST(ReadingListEntry, DistilledState) { |
| - ReadingListEntry e(GURL("http://example.com"), "bar"); |
| + ReadingListEntry e(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); |
| @@ -96,7 +114,8 @@ TEST(ReadingListEntry, DistilledState) { |
| const base::FilePath distilled_path("distilled/page.html"); |
| const GURL distilled_url("http://example.com/distilled"); |
| - e.SetDistilledInfo(distilled_path, distilled_url, 50, 100); |
| + e.SetDistilledInfo(distilled_path, distilled_url, 50, |
| + base::Time::FromTimeT(100)); |
| EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); |
| } |
| @@ -108,11 +127,12 @@ TEST(ReadingListEntry, TimeUntilNextTry) { |
| base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| &clock); |
| - ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); |
| + ReadingListEntry e(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10), std::move(backoff)); |
| double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| - ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| + EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| // First error. |
| e.SetDistilledState(ReadingListEntry::ERROR); |
| @@ -159,7 +179,8 @@ TEST(ReadingListEntry, TimeUntilNextTryInThePast) { |
| std::unique_ptr<net::BackoffEntry> backoff = |
| base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| &clock); |
| - ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); |
| + ReadingListEntry e(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10), std::move(backoff)); |
| double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| e.SetDistilledState(ReadingListEntry::ERROR); |
| @@ -180,7 +201,8 @@ TEST(ReadingListEntry, ResetTimeUntilNextTry) { |
| std::unique_ptr<net::BackoffEntry> backoff = |
| base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| &clock); |
| - ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); |
| + ReadingListEntry e(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10), std::move(backoff)); |
| double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| e.SetDistilledState(ReadingListEntry::ERROR); |
| @@ -190,7 +212,8 @@ TEST(ReadingListEntry, ResetTimeUntilNextTry) { |
| // Action. |
| const base::FilePath distilled_path("distilled/page.html"); |
| const GURL distilled_url("http://example.com/distilled"); |
| - e.SetDistilledInfo(distilled_path, distilled_url, 50, 100); |
| + e.SetDistilledInfo(distilled_path, distilled_url, 50, |
| + base::Time::FromTimeT(100)); |
| // Test. |
| EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| @@ -202,9 +225,10 @@ TEST(ReadingListEntry, ResetTimeUntilNextTry) { |
| // Tests that the failed download counter is incremented when the state change |
| // from non-error to error. |
| TEST(ReadingListEntry, FailedDownloadCounter) { |
| - ReadingListEntry e(GURL("http://example.com"), "bar"); |
| + ReadingListEntry e(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| - ASSERT_EQ(0, e.FailedDownloadCounter()); |
| + EXPECT_EQ(0, e.FailedDownloadCounter()); |
| e.SetDistilledState(ReadingListEntry::ERROR); |
| EXPECT_EQ(1, e.FailedDownloadCounter()); |
| @@ -223,7 +247,8 @@ TEST(ReadingListEntry, FailedDownloadCounter) { |
| // Tests that the reading list entry is correctly encoded to |
| // sync_pb::ReadingListSpecifics. |
| TEST(ReadingListEntry, AsReadingListSpecifics) { |
| - ReadingListEntry entry(GURL("http://example.com/"), "bar"); |
| + ReadingListEntry entry(GURL("http://example.com"), "bar", |
| + base::Time::FromTimeT(10)); |
| int64_t creation_time_us = entry.UpdateTime(); |
| std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry( |
| @@ -235,8 +260,10 @@ TEST(ReadingListEntry, AsReadingListSpecifics) { |
| EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); |
| EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNSEEN); |
| - entry.SetRead(true); |
| - EXPECT_NE(entry.UpdateTime(), creation_time_us); |
| + entry.SetRead(true, base::Time::FromTimeT(15)); |
| + // Getters are in microseconds. |
| + EXPECT_EQ(entry.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond); |
| + EXPECT_EQ(entry.UpdateTime(), 15 * base::Time::kMicrosecondsPerSecond); |
| std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry( |
| entry.AsReadingListSpecifics()); |
| EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us); |
| @@ -254,24 +281,30 @@ TEST(ReadingListEntry, FromReadingListSpecifics) { |
| pb_entry->set_title("title"); |
| pb_entry->set_creation_time_us(1); |
|
gambard
2017/03/21 15:36:53
You are still not checking the creation time?
Olivier
2017/03/21 17:22:47
Done, thanks
|
| pb_entry->set_update_time_us(2); |
| + pb_entry->set_update_title_time_us(3); |
| pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); |
| std::unique_ptr<ReadingListEntry> entry( |
| - ReadingListEntry::FromReadingListSpecifics(*pb_entry)); |
| + ReadingListEntry::FromReadingListSpecifics(*pb_entry, |
| + base::Time::FromTimeT(10))); |
| EXPECT_EQ(entry->URL().spec(), "http://example.com/"); |
| EXPECT_EQ(entry->Title(), "title"); |
| EXPECT_EQ(entry->UpdateTime(), 2); |
| + EXPECT_EQ(entry->UpdateTitleTime(), 3); |
| EXPECT_EQ(entry->FailedDownloadCounter(), 0); |
| } |
| // Tests that the reading list entry is correctly encoded to |
| // reading_list::ReadingListLocal. |
| TEST(ReadingListEntry, AsReadingListLocal) { |
| - ReadingListEntry entry(GURL("http://example.com/"), "bar"); |
| + ReadingListEntry entry(GURL("http://example.com/"), "foo", |
| + base::Time::FromTimeT(10)); |
| int64_t creation_time_us = entry.UpdateTime(); |
| + entry.SetTitle("bar", base::Time::FromTimeT(20)); |
| + entry.MarkEntryUpdated(base::Time::FromTimeT(30)); |
| std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| - entry.AsReadingListLocal()); |
| + entry.AsReadingListLocal(base::Time::FromTimeT(40))); |
| EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); |
| EXPECT_EQ(pb_entry->url(), "http://example.com/"); |
| EXPECT_EQ(pb_entry->title(), "bar"); |
| @@ -286,7 +319,7 @@ TEST(ReadingListEntry, AsReadingListLocal) { |
| entry.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( |
| - entry.AsReadingListLocal()); |
| + entry.AsReadingListLocal(base::Time::FromTimeT(50))); |
| EXPECT_EQ(will_retry_pb_entry->distillation_state(), |
| reading_list::ReadingListLocal::WILL_RETRY); |
| EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); |
| @@ -294,13 +327,14 @@ TEST(ReadingListEntry, AsReadingListLocal) { |
| const base::FilePath distilled_path("distilled/page.html"); |
| const GURL distilled_url("http://example.com/distilled"); |
| int64_t size = 50; |
| - entry.SetDistilledInfo(distilled_path, distilled_url, size, 100); |
| + entry.SetDistilledInfo(distilled_path, distilled_url, size, |
| + base::Time::FromTimeT(100)); |
| - entry.SetRead(true); |
| - entry.MarkEntryUpdated(); |
| + entry.SetRead(true, base::Time::FromTimeT(20)); |
| + entry.MarkEntryUpdated(base::Time::FromTimeT(30)); |
| EXPECT_NE(entry.UpdateTime(), creation_time_us); |
| std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( |
| - entry.AsReadingListLocal()); |
| + entry.AsReadingListLocal(base::Time::FromTimeT(40))); |
| EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); |
| EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); |
| EXPECT_NE(distilled_pb_entry->backoff(), ""); |
| @@ -317,11 +351,12 @@ TEST(ReadingListEntry, AsReadingListLocal) { |
| // Tests that the reading list entry is correctly parsed from |
| // sync_pb::ReadingListLocal. |
| TEST(ReadingListEntry, FromReadingListLocal) { |
| - ReadingListEntry entry(GURL("http://example.com/"), "title"); |
| + ReadingListEntry entry(GURL("http://example.com/"), "title", |
| + base::Time::FromTimeT(10)); |
| entry.SetDistilledState(ReadingListEntry::ERROR); |
| std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| - entry.AsReadingListLocal()); |
| + entry.AsReadingListLocal(base::Time::FromTimeT(10))); |
| int64_t now = 12345; |
| pb_entry->set_entry_id("http://example.com/"); |
| @@ -329,6 +364,7 @@ TEST(ReadingListEntry, FromReadingListLocal) { |
| pb_entry->set_title("title"); |
| pb_entry->set_creation_time_us(1); |
| pb_entry->set_update_time_us(2); |
| + pb_entry->set_update_title_time_us(3); |
| pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); |
| pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); |
| pb_entry->set_failed_download_counter(2); |
| @@ -336,10 +372,12 @@ TEST(ReadingListEntry, FromReadingListLocal) { |
| pb_entry->set_distillation_size(50); |
| std::unique_ptr<ReadingListEntry> waiting_entry( |
| - ReadingListEntry::FromReadingListLocal(*pb_entry)); |
| + ReadingListEntry::FromReadingListLocal(*pb_entry, |
| + base::Time::FromTimeT(20))); |
| EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/"); |
| EXPECT_EQ(waiting_entry->Title(), "title"); |
| EXPECT_EQ(waiting_entry->UpdateTime(), 2); |
| + EXPECT_EQ(waiting_entry->UpdateTitleTime(), 3); |
| EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); |
| EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); |
| EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); |
| @@ -354,17 +392,22 @@ TEST(ReadingListEntry, FromReadingListLocal) { |
| // Additional merging tests are done in |
| // ReadingListStoreTest.CompareEntriesForSync |
| TEST(ReadingListEntry, MergeWithEntry) { |
| - ReadingListEntry local_entry(GURL("http://example.com/"), "title"); |
| + ReadingListEntry local_entry(GURL("http://example.com/"), "title", |
| + base::Time::FromTimeT(10)); |
| local_entry.SetDistilledState(ReadingListEntry::ERROR); |
| + local_entry.SetTitle("title updated", base::Time::FromTimeT(30)); |
| int64_t local_update_time_us = local_entry.UpdateTime(); |
| - ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); |
| + ReadingListEntry sync_entry(GURL("http://example.com/"), "title2", |
| + base::Time::FromTimeT(20)); |
| sync_entry.SetDistilledState(ReadingListEntry::ERROR); |
| int64_t sync_update_time_us = sync_entry.UpdateTime(); |
| EXPECT_NE(local_update_time_us, sync_update_time_us); |
| local_entry.MergeWithEntry(sync_entry); |
| EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); |
| - EXPECT_EQ(local_entry.Title(), "title2"); |
| + EXPECT_EQ(local_entry.Title(), "title updated"); |
| + EXPECT_EQ(local_entry.UpdateTitleTime(), |
| + 30 * base::Time::kMicrosecondsPerSecond); |
| EXPECT_FALSE(local_entry.HasBeenSeen()); |
| EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); |
| EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); |