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

Unified Diff: ios/chrome/browser/reading_list/reading_list_entry_unittest.cc

Issue 2338133010: Add a TimeUntilNextTry to reading list (Closed)
Patch Set: Fix comments and tests Created 4 years, 3 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 | « ios/chrome/browser/reading_list/reading_list_entry.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/reading_list/reading_list_entry_unittest.cc
diff --git a/ios/chrome/browser/reading_list/reading_list_entry_unittest.cc b/ios/chrome/browser/reading_list/reading_list_entry_unittest.cc
index 6d517ee6d5e8067f8b16673bcabca25cdbfe5ffc..6539246a7ce72d93c17f2eedb1af6c5581862d30 100644
--- a/ios/chrome/browser/reading_list/reading_list_entry_unittest.cc
+++ b/ios/chrome/browser/reading_list/reading_list_entry_unittest.cc
@@ -4,6 +4,8 @@
#include "ios/chrome/browser/reading_list/reading_list_entry.h"
+#include "base/memory/ptr_util.h"
+#include "base/test/simple_test_tick_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
TEST(ReadingListEntry, CompareIgnoreTitle) {
@@ -54,3 +56,77 @@ TEST(ReadingListEntry, DistilledState) {
e.SetDistilledURL(distilled_url);
EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState());
}
+
+// Tests that the the time until next try increase exponentially when the state
+// changes from non-error to error.
+TEST(ReadingListEntry, TimeUntilNextTry) {
+ base::SimpleTestTickClock clock;
+ std::unique_ptr<net::BackoffEntry> backoff =
+ base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
+ &clock);
+
+ ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff));
+
+ ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds());
+
+ e.SetDistilledState(ReadingListEntry::ERROR);
+ EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
+ e.SetDistilledState(ReadingListEntry::WILL_RETRY);
+ EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
+
+ e.SetDistilledState(ReadingListEntry::PROCESSING);
+ EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
+
+ e.SetDistilledState(ReadingListEntry::WILL_RETRY);
+ EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
+ e.SetDistilledState(ReadingListEntry::ERROR);
+ EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
+
+ e.SetDistilledState(ReadingListEntry::PROCESSING);
+ EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
+
+ e.SetDistilledState(ReadingListEntry::WILL_RETRY);
+ EXPECT_EQ(4, e.TimeUntilNextTry().InSeconds());
+}
+
+// Tests that if the time until next try is in the past, 0 is returned.
+TEST(ReadingListEntry, TimeUntilNextTryInThePast) {
+ // Setup.
+ base::SimpleTestTickClock clock;
+ std::unique_ptr<net::BackoffEntry> backoff =
+ base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
+ &clock);
+ ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff));
+
+ e.SetDistilledState(ReadingListEntry::ERROR);
+ ASSERT_EQ(1, e.TimeUntilNextTry().InSeconds());
+
+ // Action.
+ clock.Advance(base::TimeDelta::FromSeconds(2));
+
+ // Test.
+ EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds());
+}
+
+// Tests that if the time until next try is in the past, 0 is returned.
+TEST(ReadingListEntry, ResetTimeUntilNextTry) {
+ // Setup.
+ base::SimpleTestTickClock clock;
+ std::unique_ptr<net::BackoffEntry> backoff =
+ base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
+ &clock);
+ ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff));
+
+ e.SetDistilledState(ReadingListEntry::ERROR);
+ e.SetDistilledState(ReadingListEntry::PROCESSING);
+ e.SetDistilledState(ReadingListEntry::ERROR);
+ ASSERT_EQ(2, e.TimeUntilNextTry().InSeconds());
+
+ // Action.
+ e.SetDistilledURL(GURL("http://example.com"));
+
+ // Test.
+ EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds());
+ e.SetDistilledState(ReadingListEntry::ERROR);
+ EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
+}
« no previous file with comments | « ios/chrome/browser/reading_list/reading_list_entry.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698