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 7afd3aebe0396b04ef101f9927e186765c1ad108..6a4369e67c6ed8a193a530807343d0d517c6397f 100644 |
| --- a/components/reading_list/ios/reading_list_entry_unittest.cc |
| +++ b/components/reading_list/ios/reading_list_entry_unittest.cc |
| @@ -17,6 +17,11 @@ const int kSecondBackoff = 10; |
| const int kThirdBackoff = 60; |
| const int kFourthBackoff = 120; |
| const int kFifthBackoff = 120; |
| + |
| +// Returns the number of microseconds since Jan 1st 1970. |
| +int64_t Now() { |
|
gambard
2017/02/22 12:30:16
Nit: I don't like this. I guess the "right" way to
|
| + return (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds(); |
| +} |
| } // namespace |
| TEST(ReadingListEntry, CompareIgnoreTitle) { |
| @@ -69,16 +74,22 @@ TEST(ReadingListEntry, UpdateTitle) { |
| EXPECT_EQ("foo", e.Title()); |
| } |
| -TEST(ReadingListEntry, DistilledPathAndURL) { |
| +TEST(ReadingListEntry, DistilledInfo) { |
| ReadingListEntry e(GURL("http://example.com"), "bar"); |
| EXPECT_TRUE(e.DistilledPath().empty()); |
| const base::FilePath distilled_path("distilled/page.html"); |
| const GURL distilled_url("http://example.com/distilled"); |
| - e.SetDistilledInfo(distilled_path, distilled_url); |
| + int64_t size = 50; |
| + int64_t before = Now(); |
| + e.SetDistilledInfo(distilled_path, distilled_url, size); |
| + int64_t after = Now(); |
| EXPECT_EQ(distilled_path, e.DistilledPath()); |
| EXPECT_EQ(distilled_url, e.DistilledURL()); |
| + EXPECT_EQ(size, e.DistillationSize()); |
| + EXPECT_GE(e.DistillationTime(), before); |
| + EXPECT_GE(after, e.DistillationTime()); |
| } |
| TEST(ReadingListEntry, DistilledState) { |
| @@ -91,7 +102,7 @@ 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); |
| + e.SetDistilledInfo(distilled_path, distilled_url, 50); |
| EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); |
| } |
| @@ -185,7 +196,7 @@ 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); |
| + e.SetDistilledInfo(distilled_path, distilled_url, 50); |
| // Test. |
| EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| @@ -288,7 +299,9 @@ TEST(ReadingListEntry, AsReadingListLocal) { |
| const base::FilePath distilled_path("distilled/page.html"); |
| const GURL distilled_url("http://example.com/distilled"); |
| - entry.SetDistilledInfo(distilled_path, distilled_url); |
| + int64_t size = 50; |
| + entry.SetDistilledInfo(distilled_path, distilled_url, size); |
| + |
| entry.SetRead(true); |
| entry.MarkEntryUpdated(); |
| EXPECT_NE(entry.UpdateTime(), creation_time_us); |
| @@ -302,6 +315,9 @@ TEST(ReadingListEntry, AsReadingListLocal) { |
| reading_list::ReadingListLocal::PROCESSED); |
| EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); |
| EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); |
| + EXPECT_EQ(distilled_pb_entry->distillation_time_us(), |
| + entry.DistillationTime()); |
| + EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize()); |
| } |
| // Tests that the reading list entry is correctly parsed from |
| @@ -312,6 +328,7 @@ TEST(ReadingListEntry, FromReadingListLocal) { |
| std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| entry.AsReadingListLocal()); |
| + int64_t now = Now(); |
| pb_entry->set_entry_id("http://example.com/"); |
| pb_entry->set_url("http://example.com/"); |
| @@ -321,6 +338,8 @@ TEST(ReadingListEntry, FromReadingListLocal) { |
| pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); |
| pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); |
| pb_entry->set_failed_download_counter(2); |
| + pb_entry->set_distillation_time_us(now); |
| + pb_entry->set_distillation_size(50); |
| std::unique_ptr<ReadingListEntry> waiting_entry( |
| ReadingListEntry::FromReadingListLocal(*pb_entry)); |
| @@ -330,6 +349,8 @@ TEST(ReadingListEntry, FromReadingListLocal) { |
| EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); |
| EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); |
| EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); |
| + EXPECT_EQ(waiting_entry->DistillationSize(), 50); |
| + EXPECT_EQ(waiting_entry->DistillationTime(), now); |
| base::Time waiting_next_call = |
| base::Time::Now() + waiting_entry->TimeUntilNextTry(); |
| base::TimeDelta delta = next_call - waiting_next_call; |