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

Side by Side 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 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 "components/reading_list/ios/reading_list_entry.h" 5 #include "components/reading_list/ios/reading_list_entry.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/test/ios/wait_util.h"
9 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
10 #include "components/reading_list/ios/proto/reading_list.pb.h" 9 #include "components/reading_list/ios/proto/reading_list.pb.h"
11 #include "components/sync/protocol/reading_list_specifics.pb.h" 10 #include "components/sync/protocol/reading_list_specifics.pb.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
13 12
14 namespace { 13 namespace {
15 const int kFirstBackoff = 10; 14 const int kFirstBackoff = 10;
16 const int kSecondBackoff = 10; 15 const int kSecondBackoff = 10;
17 const int kThirdBackoff = 60; 16 const int kThirdBackoff = 60;
18 const int kFourthBackoff = 120; 17 const int kFourthBackoff = 120;
19 const int kFifthBackoff = 120; 18 const int kFifthBackoff = 120;
20 19
21 } // namespace 20 } // namespace
22 21
23 TEST(ReadingListEntry, CompareIgnoreTitle) { 22 TEST(ReadingListEntry, CompareIgnoreTitle) {
24 const ReadingListEntry e1(GURL("http://example.com"), "bar"); 23 const ReadingListEntry e1(GURL("http://example.com"), "bar",
25 const ReadingListEntry e2(GURL("http://example.com"), "foo"); 24 base::Time::FromTimeT(10));
25 const ReadingListEntry e2(GURL("http://example.com"), "foo",
26 base::Time::FromTimeT(20));
26 27
27 EXPECT_EQ(e1, e2); 28 EXPECT_EQ(e1, e2);
28 } 29 }
29 30
30 TEST(ReadingListEntry, CompareFailureIgnoreTitle) { 31 TEST(ReadingListEntry, CompareFailureIgnoreTitleAndCreationTime) {
31 const ReadingListEntry e1(GURL("http://example.com"), "bar"); 32 const ReadingListEntry e1(GURL("http://example.com"), "bar",
32 const ReadingListEntry e2(GURL("http://example.org"), "bar"); 33 base::Time::FromTimeT(10));
34 const ReadingListEntry e2(GURL("http://example.org"), "bar",
35 base::Time::FromTimeT(10));
33 36
34 EXPECT_FALSE(e1 == e2); 37 EXPECT_FALSE(e1 == e2);
35 } 38 }
36 39
37 TEST(ReadingListEntry, MovesAreEquals) { 40 TEST(ReadingListEntry, MovesAreEquals) {
38 ReadingListEntry e1(GURL("http://example.com"), "bar"); 41 ReadingListEntry e1(GURL("http://example.com"), "bar",
39 ReadingListEntry e2(GURL("http://example.com"), "bar"); 42 base::Time::FromTimeT(10));
40 ASSERT_EQ(e1, e2); 43 ReadingListEntry e2(GURL("http://example.com"), "bar",
41 ASSERT_EQ(e1.Title(), e2.Title()); 44 base::Time::FromTimeT(10));
45 EXPECT_EQ(e1, e2);
46 EXPECT_EQ(e1.Title(), e2.Title());
47 EXPECT_EQ(e1.CreationTime(), e2.CreationTime());
42 48
43 ReadingListEntry e3(std::move(e1)); 49 ReadingListEntry e3(std::move(e1));
44 50
45 EXPECT_EQ(e3, e2); 51 EXPECT_EQ(e3, e2);
46 EXPECT_EQ(e3.Title(), e2.Title()); 52 EXPECT_EQ(e3.Title(), e2.Title());
53 EXPECT_EQ(e3.CreationTime(), e2.CreationTime());
47 } 54 }
48 55
49 TEST(ReadingListEntry, ReadState) { 56 TEST(ReadingListEntry, ReadState) {
50 ReadingListEntry e(GURL("http://example.com"), "bar"); 57 ReadingListEntry e(GURL("http://example.com"), "bar",
58 base::Time::FromTimeT(10));
51 EXPECT_FALSE(e.HasBeenSeen()); 59 EXPECT_FALSE(e.HasBeenSeen());
52 EXPECT_FALSE(e.IsRead()); 60 EXPECT_FALSE(e.IsRead());
53 e.SetRead(false); 61 e.SetRead(false, base::Time::FromTimeT(20));
62 EXPECT_EQ(e.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond);
63 EXPECT_EQ(e.UpdateTime(), 10 * base::Time::kMicrosecondsPerSecond);
64 EXPECT_EQ(e.UpdateTitleTime(), 10 * base::Time::kMicrosecondsPerSecond);
54 EXPECT_TRUE(e.HasBeenSeen()); 65 EXPECT_TRUE(e.HasBeenSeen());
55 EXPECT_FALSE(e.IsRead()); 66 EXPECT_FALSE(e.IsRead());
56 e.SetRead(true); 67 e.SetRead(true, base::Time::FromTimeT(30));
68 EXPECT_EQ(e.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond);
69 EXPECT_EQ(e.UpdateTime(), 30 * base::Time::kMicrosecondsPerSecond);
70 EXPECT_EQ(e.UpdateTitleTime(), 10 * base::Time::kMicrosecondsPerSecond);
57 EXPECT_TRUE(e.HasBeenSeen()); 71 EXPECT_TRUE(e.HasBeenSeen());
58 EXPECT_TRUE(e.IsRead()); 72 EXPECT_TRUE(e.IsRead());
59 } 73 }
60 74
61 TEST(ReadingListEntry, UpdateTitle) { 75 TEST(ReadingListEntry, UpdateTitle) {
62 ReadingListEntry e(GURL("http://example.com"), "bar"); 76 ReadingListEntry e(GURL("http://example.com"), "bar",
63 ASSERT_EQ("bar", e.Title()); 77 base::Time::FromTimeT(10));
64 ASSERT_EQ(e.CreationTime(), e.UpdateTitleTime()); 78 EXPECT_EQ("bar", e.Title());
79 // Getters are in microseconds.
80 EXPECT_EQ(e.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond);
81 EXPECT_EQ(e.UpdateTitleTime(), 10 * base::Time::kMicrosecondsPerSecond);
65 82
66 base::test::ios::SpinRunLoopWithMinDelay( 83 e.SetTitle("foo", base::Time::FromTimeT(15));
67 base::TimeDelta::FromMilliseconds(5)); 84 EXPECT_EQ(e.UpdateTitleTime(), 15 * base::Time::kMicrosecondsPerSecond);
68 e.SetTitle("foo");
69 EXPECT_GT(e.UpdateTitleTime(), e.CreationTime());
70 EXPECT_EQ("foo", e.Title()); 85 EXPECT_EQ("foo", e.Title());
71 } 86 }
72 87
73 TEST(ReadingListEntry, DistilledInfo) { 88 TEST(ReadingListEntry, DistilledInfo) {
74 ReadingListEntry e(GURL("http://example.com"), "bar"); 89 ReadingListEntry e(GURL("http://example.com"), "bar",
90 base::Time::FromTimeT(10));
75 91
76 EXPECT_TRUE(e.DistilledPath().empty()); 92 EXPECT_TRUE(e.DistilledPath().empty());
77 93
78 const base::FilePath distilled_path("distilled/page.html"); 94 const base::FilePath distilled_path("distilled/page.html");
79 const GURL distilled_url("http://example.com/distilled"); 95 const GURL distilled_url("http://example.com/distilled");
80 int64_t size = 50; 96 int64_t size = 50;
81 int64_t time = 100; 97 int64_t time = 100;
82 e.SetDistilledInfo(distilled_path, distilled_url, size, time); 98 e.SetDistilledInfo(distilled_path, distilled_url, size,
99 base::Time::FromTimeT(time));
83 EXPECT_EQ(distilled_path, e.DistilledPath()); 100 EXPECT_EQ(distilled_path, e.DistilledPath());
84 EXPECT_EQ(distilled_url, e.DistilledURL()); 101 EXPECT_EQ(distilled_url, e.DistilledURL());
85 EXPECT_EQ(size, e.DistillationSize()); 102 EXPECT_EQ(size, e.DistillationSize());
86 EXPECT_EQ(e.DistillationTime(), time); 103 EXPECT_EQ(e.DistillationTime(), time * base::Time::kMicrosecondsPerSecond);
87 } 104 }
88 105
89 TEST(ReadingListEntry, DistilledState) { 106 TEST(ReadingListEntry, DistilledState) {
90 ReadingListEntry e(GURL("http://example.com"), "bar"); 107 ReadingListEntry e(GURL("http://example.com"), "bar",
108 base::Time::FromTimeT(10));
91 109
92 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); 110 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState());
93 111
94 e.SetDistilledState(ReadingListEntry::ERROR); 112 e.SetDistilledState(ReadingListEntry::ERROR);
95 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); 113 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState());
96 114
97 const base::FilePath distilled_path("distilled/page.html"); 115 const base::FilePath distilled_path("distilled/page.html");
98 const GURL distilled_url("http://example.com/distilled"); 116 const GURL distilled_url("http://example.com/distilled");
99 e.SetDistilledInfo(distilled_path, distilled_url, 50, 100); 117 e.SetDistilledInfo(distilled_path, distilled_url, 50,
118 base::Time::FromTimeT(100));
100 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); 119 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState());
101 } 120 }
102 121
103 // Tests that the the time until next try increase exponentially when the state 122 // Tests that the the time until next try increase exponentially when the state
104 // changes from non-error to error. 123 // changes from non-error to error.
105 TEST(ReadingListEntry, TimeUntilNextTry) { 124 TEST(ReadingListEntry, TimeUntilNextTry) {
106 base::SimpleTestTickClock clock; 125 base::SimpleTestTickClock clock;
107 std::unique_ptr<net::BackoffEntry> backoff = 126 std::unique_ptr<net::BackoffEntry> backoff =
108 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, 127 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
109 &clock); 128 &clock);
110 129
111 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); 130 ReadingListEntry e(GURL("http://example.com"), "bar",
131 base::Time::FromTimeT(10), std::move(backoff));
112 132
113 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; 133 // Allow twice the jitter as test is not instantaneous.
134 double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor;
114 135
115 ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds()); 136 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds());
116 137
117 // First error. 138 // First error.
118 e.SetDistilledState(ReadingListEntry::ERROR); 139 e.SetDistilledState(ReadingListEntry::ERROR);
119 int nextTry = e.TimeUntilNextTry().InMinutes(); 140 int nextTry = e.TimeUntilNextTry().InMinutes();
120 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); 141 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing);
121 e.SetDistilledState(ReadingListEntry::WILL_RETRY); 142 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
122 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); 143 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes());
123 144
124 e.SetDistilledState(ReadingListEntry::PROCESSING); 145 e.SetDistilledState(ReadingListEntry::PROCESSING);
125 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); 146 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes());
(...skipping 26 matching lines...) Expand all
152 kFifthBackoff * fuzzing); 173 kFifthBackoff * fuzzing);
153 } 174 }
154 175
155 // Tests that if the time until next try is in the past, 0 is returned. 176 // Tests that if the time until next try is in the past, 0 is returned.
156 TEST(ReadingListEntry, TimeUntilNextTryInThePast) { 177 TEST(ReadingListEntry, TimeUntilNextTryInThePast) {
157 // Setup. 178 // Setup.
158 base::SimpleTestTickClock clock; 179 base::SimpleTestTickClock clock;
159 std::unique_ptr<net::BackoffEntry> backoff = 180 std::unique_ptr<net::BackoffEntry> backoff =
160 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, 181 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
161 &clock); 182 &clock);
162 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); 183 ReadingListEntry e(GURL("http://example.com"), "bar",
184 base::Time::FromTimeT(10), std::move(backoff));
163 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; 185 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor;
164 186
165 e.SetDistilledState(ReadingListEntry::ERROR); 187 e.SetDistilledState(ReadingListEntry::ERROR);
166 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), 188 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(),
167 kFirstBackoff * fuzzing); 189 kFirstBackoff * fuzzing);
168 190
169 // Action. 191 // Action.
170 clock.Advance(base::TimeDelta::FromMinutes(kFirstBackoff * 2)); 192 clock.Advance(base::TimeDelta::FromMinutes(kFirstBackoff * 2));
171 193
172 // Test. 194 // Test.
173 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds()); 195 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds());
174 } 196 }
175 197
176 // Tests that if the entry gets a distilled URL, 0 is returned. 198 // Tests that if the entry gets a distilled URL, 0 is returned.
177 TEST(ReadingListEntry, ResetTimeUntilNextTry) { 199 TEST(ReadingListEntry, ResetTimeUntilNextTry) {
178 // Setup. 200 // Setup.
179 base::SimpleTestTickClock clock; 201 base::SimpleTestTickClock clock;
180 std::unique_ptr<net::BackoffEntry> backoff = 202 std::unique_ptr<net::BackoffEntry> backoff =
181 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, 203 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
182 &clock); 204 &clock);
183 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); 205 ReadingListEntry e(GURL("http://example.com"), "bar",
206 base::Time::FromTimeT(10), std::move(backoff));
184 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; 207 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor;
185 208
186 e.SetDistilledState(ReadingListEntry::ERROR); 209 e.SetDistilledState(ReadingListEntry::ERROR);
187 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), 210 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(),
188 kFirstBackoff * fuzzing); 211 kFirstBackoff * fuzzing);
189 212
190 // Action. 213 // Action.
191 const base::FilePath distilled_path("distilled/page.html"); 214 const base::FilePath distilled_path("distilled/page.html");
192 const GURL distilled_url("http://example.com/distilled"); 215 const GURL distilled_url("http://example.com/distilled");
193 e.SetDistilledInfo(distilled_path, distilled_url, 50, 100); 216 e.SetDistilledInfo(distilled_path, distilled_url, 50,
217 base::Time::FromTimeT(100));
194 218
195 // Test. 219 // Test.
196 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); 220 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds());
197 e.SetDistilledState(ReadingListEntry::ERROR); 221 e.SetDistilledState(ReadingListEntry::ERROR);
198 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), 222 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(),
199 kFirstBackoff * fuzzing); 223 kFirstBackoff * fuzzing);
200 } 224 }
201 225
202 // Tests that the failed download counter is incremented when the state change 226 // Tests that the failed download counter is incremented when the state change
203 // from non-error to error. 227 // from non-error to error.
204 TEST(ReadingListEntry, FailedDownloadCounter) { 228 TEST(ReadingListEntry, FailedDownloadCounter) {
205 ReadingListEntry e(GURL("http://example.com"), "bar"); 229 ReadingListEntry e(GURL("http://example.com"), "bar",
230 base::Time::FromTimeT(10));
206 231
207 ASSERT_EQ(0, e.FailedDownloadCounter()); 232 EXPECT_EQ(0, e.FailedDownloadCounter());
208 233
209 e.SetDistilledState(ReadingListEntry::ERROR); 234 e.SetDistilledState(ReadingListEntry::ERROR);
210 EXPECT_EQ(1, e.FailedDownloadCounter()); 235 EXPECT_EQ(1, e.FailedDownloadCounter());
211 e.SetDistilledState(ReadingListEntry::WILL_RETRY); 236 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
212 EXPECT_EQ(1, e.FailedDownloadCounter()); 237 EXPECT_EQ(1, e.FailedDownloadCounter());
213 238
214 e.SetDistilledState(ReadingListEntry::PROCESSING); 239 e.SetDistilledState(ReadingListEntry::PROCESSING);
215 EXPECT_EQ(1, e.FailedDownloadCounter()); 240 EXPECT_EQ(1, e.FailedDownloadCounter());
216 241
217 e.SetDistilledState(ReadingListEntry::WILL_RETRY); 242 e.SetDistilledState(ReadingListEntry::WILL_RETRY);
218 EXPECT_EQ(2, e.FailedDownloadCounter()); 243 EXPECT_EQ(2, e.FailedDownloadCounter());
219 e.SetDistilledState(ReadingListEntry::ERROR); 244 e.SetDistilledState(ReadingListEntry::ERROR);
220 EXPECT_EQ(2, e.FailedDownloadCounter()); 245 EXPECT_EQ(2, e.FailedDownloadCounter());
221 } 246 }
222 247
223 // Tests that the reading list entry is correctly encoded to 248 // Tests that the reading list entry is correctly encoded to
224 // sync_pb::ReadingListSpecifics. 249 // sync_pb::ReadingListSpecifics.
225 TEST(ReadingListEntry, AsReadingListSpecifics) { 250 TEST(ReadingListEntry, AsReadingListSpecifics) {
226 ReadingListEntry entry(GURL("http://example.com/"), "bar"); 251 ReadingListEntry entry(GURL("http://example.com"), "bar",
252 base::Time::FromTimeT(10));
227 int64_t creation_time_us = entry.UpdateTime(); 253 int64_t creation_time_us = entry.UpdateTime();
228 254
229 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry( 255 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry(
230 entry.AsReadingListSpecifics()); 256 entry.AsReadingListSpecifics());
231 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); 257 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/");
232 EXPECT_EQ(pb_entry->url(), "http://example.com/"); 258 EXPECT_EQ(pb_entry->url(), "http://example.com/");
233 EXPECT_EQ(pb_entry->title(), "bar"); 259 EXPECT_EQ(pb_entry->title(), "bar");
234 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); 260 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us);
235 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); 261 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime());
236 EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNSEEN); 262 EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNSEEN);
237 263
238 entry.SetRead(true); 264 entry.SetRead(true, base::Time::FromTimeT(15));
239 EXPECT_NE(entry.UpdateTime(), creation_time_us); 265 // Getters are in microseconds.
266 EXPECT_EQ(entry.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond);
267 EXPECT_EQ(entry.UpdateTime(), 15 * base::Time::kMicrosecondsPerSecond);
240 std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry( 268 std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry(
241 entry.AsReadingListSpecifics()); 269 entry.AsReadingListSpecifics());
242 EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us); 270 EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us);
243 EXPECT_EQ(updated_pb_entry->update_time_us(), entry.UpdateTime()); 271 EXPECT_EQ(updated_pb_entry->update_time_us(), entry.UpdateTime());
244 EXPECT_EQ(updated_pb_entry->status(), sync_pb::ReadingListSpecifics::READ); 272 EXPECT_EQ(updated_pb_entry->status(), sync_pb::ReadingListSpecifics::READ);
245 } 273 }
246 274
247 // Tests that the reading list entry is correctly parsed from 275 // Tests that the reading list entry is correctly parsed from
248 // sync_pb::ReadingListSpecifics. 276 // sync_pb::ReadingListSpecifics.
249 TEST(ReadingListEntry, FromReadingListSpecifics) { 277 TEST(ReadingListEntry, FromReadingListSpecifics) {
250 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry = 278 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry =
251 base::MakeUnique<sync_pb::ReadingListSpecifics>(); 279 base::MakeUnique<sync_pb::ReadingListSpecifics>();
252 pb_entry->set_entry_id("http://example.com/"); 280 pb_entry->set_entry_id("http://example.com/");
253 pb_entry->set_url("http://example.com/"); 281 pb_entry->set_url("http://example.com/");
254 pb_entry->set_title("title"); 282 pb_entry->set_title("title");
255 pb_entry->set_creation_time_us(1); 283 pb_entry->set_creation_time_us(1);
256 pb_entry->set_update_time_us(2); 284 pb_entry->set_update_time_us(2);
285 pb_entry->set_update_title_time_us(3);
257 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); 286 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD);
258 287
259 std::unique_ptr<ReadingListEntry> entry( 288 std::unique_ptr<ReadingListEntry> entry(
260 ReadingListEntry::FromReadingListSpecifics(*pb_entry)); 289 ReadingListEntry::FromReadingListSpecifics(*pb_entry,
290 base::Time::FromTimeT(10)));
261 EXPECT_EQ(entry->URL().spec(), "http://example.com/"); 291 EXPECT_EQ(entry->URL().spec(), "http://example.com/");
262 EXPECT_EQ(entry->Title(), "title"); 292 EXPECT_EQ(entry->Title(), "title");
293 EXPECT_EQ(entry->CreationTime(), 1);
263 EXPECT_EQ(entry->UpdateTime(), 2); 294 EXPECT_EQ(entry->UpdateTime(), 2);
295 EXPECT_EQ(entry->UpdateTitleTime(), 3);
264 EXPECT_EQ(entry->FailedDownloadCounter(), 0); 296 EXPECT_EQ(entry->FailedDownloadCounter(), 0);
265 } 297 }
266 298
267 // Tests that the reading list entry is correctly encoded to 299 // Tests that the reading list entry is correctly encoded to
268 // reading_list::ReadingListLocal. 300 // reading_list::ReadingListLocal.
269 TEST(ReadingListEntry, AsReadingListLocal) { 301 TEST(ReadingListEntry, AsReadingListLocal) {
270 ReadingListEntry entry(GURL("http://example.com/"), "bar"); 302 ReadingListEntry entry(GURL("http://example.com/"), "foo",
303 base::Time::FromTimeT(10));
271 int64_t creation_time_us = entry.UpdateTime(); 304 int64_t creation_time_us = entry.UpdateTime();
305 entry.SetTitle("bar", base::Time::FromTimeT(20));
306 entry.MarkEntryUpdated(base::Time::FromTimeT(30));
272 307
273 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( 308 std::unique_ptr<reading_list::ReadingListLocal> pb_entry(
274 entry.AsReadingListLocal()); 309 entry.AsReadingListLocal(base::Time::FromTimeT(40)));
275 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); 310 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/");
276 EXPECT_EQ(pb_entry->url(), "http://example.com/"); 311 EXPECT_EQ(pb_entry->url(), "http://example.com/");
277 EXPECT_EQ(pb_entry->title(), "bar"); 312 EXPECT_EQ(pb_entry->title(), "bar");
278 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); 313 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us);
279 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); 314 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime());
280 EXPECT_EQ(pb_entry->status(), reading_list::ReadingListLocal::UNSEEN); 315 EXPECT_EQ(pb_entry->status(), reading_list::ReadingListLocal::UNSEEN);
281 EXPECT_EQ(pb_entry->distillation_state(), 316 EXPECT_EQ(pb_entry->distillation_state(),
282 reading_list::ReadingListLocal::WAITING); 317 reading_list::ReadingListLocal::WAITING);
283 EXPECT_EQ(pb_entry->distilled_path(), ""); 318 EXPECT_EQ(pb_entry->distilled_path(), "");
284 EXPECT_EQ(pb_entry->failed_download_counter(), 0); 319 EXPECT_EQ(pb_entry->failed_download_counter(), 0);
285 EXPECT_NE(pb_entry->backoff(), ""); 320 EXPECT_NE(pb_entry->backoff(), "");
286 321
287 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); 322 entry.SetDistilledState(ReadingListEntry::WILL_RETRY);
288 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( 323 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry(
289 entry.AsReadingListLocal()); 324 entry.AsReadingListLocal(base::Time::FromTimeT(50)));
290 EXPECT_EQ(will_retry_pb_entry->distillation_state(), 325 EXPECT_EQ(will_retry_pb_entry->distillation_state(),
291 reading_list::ReadingListLocal::WILL_RETRY); 326 reading_list::ReadingListLocal::WILL_RETRY);
292 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); 327 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1);
293 328
294 const base::FilePath distilled_path("distilled/page.html"); 329 const base::FilePath distilled_path("distilled/page.html");
295 const GURL distilled_url("http://example.com/distilled"); 330 const GURL distilled_url("http://example.com/distilled");
296 int64_t size = 50; 331 int64_t size = 50;
297 entry.SetDistilledInfo(distilled_path, distilled_url, size, 100); 332 entry.SetDistilledInfo(distilled_path, distilled_url, size,
333 base::Time::FromTimeT(100));
298 334
299 entry.SetRead(true); 335 entry.SetRead(true, base::Time::FromTimeT(20));
300 entry.MarkEntryUpdated(); 336 entry.MarkEntryUpdated(base::Time::FromTimeT(30));
301 EXPECT_NE(entry.UpdateTime(), creation_time_us); 337 EXPECT_NE(entry.UpdateTime(), creation_time_us);
302 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( 338 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry(
303 entry.AsReadingListLocal()); 339 entry.AsReadingListLocal(base::Time::FromTimeT(40)));
304 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); 340 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us);
305 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); 341 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime());
306 EXPECT_NE(distilled_pb_entry->backoff(), ""); 342 EXPECT_NE(distilled_pb_entry->backoff(), "");
307 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); 343 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ);
308 EXPECT_EQ(distilled_pb_entry->distillation_state(), 344 EXPECT_EQ(distilled_pb_entry->distillation_state(),
309 reading_list::ReadingListLocal::PROCESSED); 345 reading_list::ReadingListLocal::PROCESSED);
310 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); 346 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html");
311 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); 347 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0);
312 EXPECT_EQ(distilled_pb_entry->distillation_time_us(), 348 EXPECT_EQ(distilled_pb_entry->distillation_time_us(),
313 entry.DistillationTime()); 349 entry.DistillationTime());
314 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize()); 350 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize());
315 } 351 }
316 352
317 // Tests that the reading list entry is correctly parsed from 353 // Tests that the reading list entry is correctly parsed from
318 // sync_pb::ReadingListLocal. 354 // sync_pb::ReadingListLocal.
319 TEST(ReadingListEntry, FromReadingListLocal) { 355 TEST(ReadingListEntry, FromReadingListLocal) {
320 ReadingListEntry entry(GURL("http://example.com/"), "title"); 356 ReadingListEntry entry(GURL("http://example.com/"), "title",
357 base::Time::FromTimeT(10));
321 entry.SetDistilledState(ReadingListEntry::ERROR); 358 entry.SetDistilledState(ReadingListEntry::ERROR);
322 359
323 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( 360 std::unique_ptr<reading_list::ReadingListLocal> pb_entry(
324 entry.AsReadingListLocal()); 361 entry.AsReadingListLocal(base::Time::FromTimeT(10)));
325 int64_t now = 12345; 362 int64_t now = 12345;
326 363
327 pb_entry->set_entry_id("http://example.com/"); 364 pb_entry->set_entry_id("http://example.com/");
328 pb_entry->set_url("http://example.com/"); 365 pb_entry->set_url("http://example.com/");
329 pb_entry->set_title("title"); 366 pb_entry->set_title("title");
330 pb_entry->set_creation_time_us(1); 367 pb_entry->set_creation_time_us(1);
331 pb_entry->set_update_time_us(2); 368 pb_entry->set_update_time_us(2);
369 pb_entry->set_update_title_time_us(3);
332 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); 370 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD);
333 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); 371 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING);
334 pb_entry->set_failed_download_counter(2); 372 pb_entry->set_failed_download_counter(2);
335 pb_entry->set_distillation_time_us(now); 373 pb_entry->set_distillation_time_us(now);
336 pb_entry->set_distillation_size(50); 374 pb_entry->set_distillation_size(50);
337 375
338 std::unique_ptr<ReadingListEntry> waiting_entry( 376 std::unique_ptr<ReadingListEntry> waiting_entry(
339 ReadingListEntry::FromReadingListLocal(*pb_entry)); 377 ReadingListEntry::FromReadingListLocal(*pb_entry,
378 base::Time::FromTimeT(20)));
340 EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/"); 379 EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/");
341 EXPECT_EQ(waiting_entry->Title(), "title"); 380 EXPECT_EQ(waiting_entry->Title(), "title");
342 EXPECT_EQ(waiting_entry->UpdateTime(), 2); 381 EXPECT_EQ(waiting_entry->UpdateTime(), 2);
382 EXPECT_EQ(waiting_entry->UpdateTitleTime(), 3);
343 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); 383 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2);
344 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); 384 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING);
345 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); 385 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath());
346 EXPECT_EQ(waiting_entry->DistillationSize(), 50); 386 EXPECT_EQ(waiting_entry->DistillationSize(), 50);
347 EXPECT_EQ(waiting_entry->DistillationTime(), now); 387 EXPECT_EQ(waiting_entry->DistillationTime(), now);
348 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; 388 // Allow twice the jitter as test is not instantaneous.
389 double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor;
349 int nextTry = waiting_entry->TimeUntilNextTry().InMinutes(); 390 int nextTry = waiting_entry->TimeUntilNextTry().InMinutes();
350 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); 391 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing);
351 } 392 }
352 393
353 // Tests the merging of two ReadingListEntry. 394 // Tests the merging of two ReadingListEntry.
354 // Additional merging tests are done in 395 // Additional merging tests are done in
355 // ReadingListStoreTest.CompareEntriesForSync 396 // ReadingListStoreTest.CompareEntriesForSync
356 TEST(ReadingListEntry, MergeWithEntry) { 397 TEST(ReadingListEntry, MergeWithEntry) {
357 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); 398 ReadingListEntry local_entry(GURL("http://example.com/"), "title",
399 base::Time::FromTimeT(10));
358 local_entry.SetDistilledState(ReadingListEntry::ERROR); 400 local_entry.SetDistilledState(ReadingListEntry::ERROR);
401 local_entry.SetTitle("title updated", base::Time::FromTimeT(30));
359 int64_t local_update_time_us = local_entry.UpdateTime(); 402 int64_t local_update_time_us = local_entry.UpdateTime();
360 403
361 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); 404 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2",
405 base::Time::FromTimeT(20));
362 sync_entry.SetDistilledState(ReadingListEntry::ERROR); 406 sync_entry.SetDistilledState(ReadingListEntry::ERROR);
363 int64_t sync_update_time_us = sync_entry.UpdateTime(); 407 int64_t sync_update_time_us = sync_entry.UpdateTime();
364 EXPECT_NE(local_update_time_us, sync_update_time_us); 408 EXPECT_NE(local_update_time_us, sync_update_time_us);
365 local_entry.MergeWithEntry(sync_entry); 409 local_entry.MergeWithEntry(sync_entry);
366 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); 410 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/");
367 EXPECT_EQ(local_entry.Title(), "title2"); 411 EXPECT_EQ(local_entry.Title(), "title updated");
412 EXPECT_EQ(local_entry.UpdateTitleTime(),
413 30 * base::Time::kMicrosecondsPerSecond);
368 EXPECT_FALSE(local_entry.HasBeenSeen()); 414 EXPECT_FALSE(local_entry.HasBeenSeen());
369 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); 415 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us);
370 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); 416 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1);
371 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); 417 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR);
372 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; 418 // Allow twice the jitter as test is not instantaneous.
419 double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor;
373 int nextTry = local_entry.TimeUntilNextTry().InMinutes(); 420 int nextTry = local_entry.TimeUntilNextTry().InMinutes();
374 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); 421 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing);
375 } 422 }
OLDNEW
« 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