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

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: fixes 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
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/test/simple_test_tick_clock.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 9
9 TEST(ReadingListEntry, CompareIgnoreTitle) { 10 TEST(ReadingListEntry, CompareIgnoreTitle) {
10 const ReadingListEntry e1(GURL("http://example.com"), "bar"); 11 const ReadingListEntry e1(GURL("http://example.com"), "bar");
11 const ReadingListEntry e2(GURL("http://example.com"), "foo"); 12 const ReadingListEntry e2(GURL("http://example.com"), "foo");
12 13
13 EXPECT_EQ(e1, e2); 14 EXPECT_EQ(e1, e2);
14 } 15 }
15 16
16 TEST(ReadingListEntry, CompareFailureIgnoreTitle) { 17 TEST(ReadingListEntry, CompareFailureIgnoreTitle) {
(...skipping 26 matching lines...) Expand all
43 44
44 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); 45 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState());
45 46
46 e.SetDistilledState(ReadingListEntry::ERROR); 47 e.SetDistilledState(ReadingListEntry::ERROR);
47 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); 48 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState());
48 49
49 const GURL distilled_url("http://distilled.example.com"); 50 const GURL distilled_url("http://distilled.example.com");
50 e.SetDistilledURL(distilled_url); 51 e.SetDistilledURL(distilled_url);
51 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); 52 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState());
52 } 53 }
54
55 // Tests that the the time until next try increase exponentially when the state
56 // changes from non-error to error.
57 TEST(ReadingListEntry, TimeUntilNextTry) {
58 base::SimpleTestTickClock clock;
59 ReadingListEntry e(GURL("http://example.com"), "bar", &clock);
60
61 ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds());
62
63 e.SetDistilledState(ReadingListEntry::ERROR);
64 EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
65 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
66 EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
67
68 e.SetDistilledState(ReadingListEntry::PROCESSING);
69 EXPECT_EQ(1, e.TimeUntilNextTry().InSeconds());
70
71 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
72 EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
73 e.SetDistilledState(ReadingListEntry::ERROR);
74 EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
75
76 e.SetDistilledState(ReadingListEntry::PROCESSING);
77 EXPECT_EQ(2, e.TimeUntilNextTry().InSeconds());
78
79 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
80 EXPECT_EQ(4, e.TimeUntilNextTry().InSeconds());
81 }
82
83 // Tests that if the time until next try is in the past, 0 is returned.
84 TEST(ReadingListEntry, TimeUntilNextTryInThePast) {
85 // Setup.
86 base::SimpleTestTickClock clock;
87 ReadingListEntry e(GURL("http://example.com"), "bar", &clock);
88
89 e.SetDistilledState(ReadingListEntry::ERROR);
90 ASSERT_EQ(1, e.TimeUntilNextTry().InSeconds());
91
92 // Action.
93 clock.Advance(base::TimeDelta::FromSeconds(2));
94
95 // Test.
96 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds());
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698