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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ios/chrome/browser/reading_list/reading_list_entry.h" 5 #include "ios/chrome/browser/reading_list/reading_list_entry.h"
6 6
7 #include "base/memory/ptr_util.h"
8 #include "base/test/simple_test_tick_clock.h"
7 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
8 10
9 TEST(ReadingListEntry, CompareIgnoreTitle) { 11 TEST(ReadingListEntry, CompareIgnoreTitle) {
10 const ReadingListEntry e1(GURL("http://example.com"), "bar"); 12 const ReadingListEntry e1(GURL("http://example.com"), "bar");
11 const ReadingListEntry e2(GURL("http://example.com"), "foo"); 13 const ReadingListEntry e2(GURL("http://example.com"), "foo");
12 14
13 EXPECT_EQ(e1, e2); 15 EXPECT_EQ(e1, e2);
14 } 16 }
15 17
16 TEST(ReadingListEntry, CompareFailureIgnoreTitle) { 18 TEST(ReadingListEntry, CompareFailureIgnoreTitle) {
(...skipping 30 matching lines...) Expand all
47 49
48 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); 50 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState());
49 51
50 e.SetDistilledState(ReadingListEntry::ERROR); 52 e.SetDistilledState(ReadingListEntry::ERROR);
51 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); 53 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState());
52 54
53 const GURL distilled_url("http://distilled.example.com"); 55 const GURL distilled_url("http://distilled.example.com");
54 e.SetDistilledURL(distilled_url); 56 e.SetDistilledURL(distilled_url);
55 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); 57 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState());
56 } 58 }
59
60 // Tests that the the time until next try increase exponentially when the state
61 // changes from non-error to error.
62 TEST(ReadingListEntry, TimeUntilNextTry) {
63 base::SimpleTestTickClock clock;
64 std::unique_ptr<net::BackoffEntry> backoff =
65 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
66 &clock);
67
68 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff));
69
70 ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds());
71
72 e.SetDistilledState(ReadingListEntry::ERROR);
73 EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
74 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
75 EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
76
77 e.SetDistilledState(ReadingListEntry::PROCESSING);
78 EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
79
80 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
81 EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
82 e.SetDistilledState(ReadingListEntry::ERROR);
83 EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
84
85 e.SetDistilledState(ReadingListEntry::PROCESSING);
86 EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
87
88 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
89 EXPECT_EQ(4, e.TimeUntilNextTry().InSeconds());
90 }
91
92 // Tests that if the time until next try is in the past, 0 is returned.
93 TEST(ReadingListEntry, TimeUntilNextTryInThePast) {
94 // Setup.
95 base::SimpleTestTickClock clock;
96 std::unique_ptr<net::BackoffEntry> backoff =
97 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
98 &clock);
99 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff));
100
101 e.SetDistilledState(ReadingListEntry::ERROR);
102 ASSERT_EQ(1, e.TimeUntilNextTry().InSeconds());
103
104 // Action.
105 clock.Advance(base::TimeDelta::FromSeconds(2));
106
107 // Test.
108 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds());
109 }
110
111 // Tests that if the time until next try is in the past, 0 is returned.
112 TEST(ReadingListEntry, ResetTimeUntilNextTry) {
113 // Setup.
114 base::SimpleTestTickClock clock;
115 std::unique_ptr<net::BackoffEntry> backoff =
116 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
117 &clock);
118 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff));
119
120 e.SetDistilledState(ReadingListEntry::ERROR);
121 e.SetDistilledState(ReadingListEntry::PROCESSING);
122 e.SetDistilledState(ReadingListEntry::ERROR);
123 ASSERT_EQ(2, e.TimeUntilNextTry().InSeconds());
124
125 // Action.
126 e.SetDistilledURL(GURL("http://example.com"));
127
128 // Test.
129 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds());
130 e.SetDistilledState(ReadingListEntry::ERROR);
131 EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
132 }
OLDNEW
« 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