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

Unified Diff: components/reading_list/ios/reading_list_entry_unittest.cc

Issue 2764533002: Reading List iOS: Use external clock in ReadingListEntry. (Closed)
Patch Set: jitter Created 3 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/reading_list/ios/reading_list_entry.cc ('k') | components/reading_list/ios/reading_list_model.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..018a7decd999c7b19155383f47a91aecf4d3184e 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(), 10 * 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,13 @@ 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;
+ // Allow twice the jitter as test is not instantaneous.
+ double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor;
- ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds());
+ EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds());
// First error.
e.SetDistilledState(ReadingListEntry::ERROR);
@@ -159,7 +180,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 +202,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 +213,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 +226,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 +248,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 +261,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 +282,31 @@ TEST(ReadingListEntry, FromReadingListSpecifics) {
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(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->CreationTime(), 1);
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 +321,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 +329,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 +353,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 +366,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,16 +374,19 @@ 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());
EXPECT_EQ(waiting_entry->DistillationSize(), 50);
EXPECT_EQ(waiting_entry->DistillationTime(), now);
- double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor;
+ // Allow twice the jitter as test is not instantaneous.
+ double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor;
int nextTry = waiting_entry->TimeUntilNextTry().InMinutes();
EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing);
}
@@ -354,22 +395,28 @@ 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);
EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR);
- double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor;
+ // Allow twice the jitter as test is not instantaneous.
+ double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor;
int nextTry = local_entry.TimeUntilNextTry().InMinutes();
EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing);
}
« no previous file with comments | « components/reading_list/ios/reading_list_entry.cc ('k') | components/reading_list/ios/reading_list_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698