OLD | NEW |
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/core/reading_list_entry.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/test/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
9 #include "components/reading_list/ios/proto/reading_list.pb.h" | 9 #include "components/reading_list/core/proto/reading_list.pb.h" |
10 #include "components/sync/protocol/reading_list_specifics.pb.h" | 10 #include "components/sync/protocol/reading_list_specifics.pb.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 const int kFirstBackoff = 10; | 14 const int kFirstBackoff = 10; |
15 const int kSecondBackoff = 10; | 15 const int kSecondBackoff = 10; |
16 const int kThirdBackoff = 60; | 16 const int kThirdBackoff = 60; |
17 const int kFourthBackoff = 120; | 17 const int kFourthBackoff = 120; |
18 const int kFifthBackoff = 120; | 18 const int kFifthBackoff = 120; |
19 | 19 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 EXPECT_EQ(e.UpdateTitleTime(), 15 * base::Time::kMicrosecondsPerSecond); | 84 EXPECT_EQ(e.UpdateTitleTime(), 15 * base::Time::kMicrosecondsPerSecond); |
85 EXPECT_EQ("foo", e.Title()); | 85 EXPECT_EQ("foo", e.Title()); |
86 } | 86 } |
87 | 87 |
88 TEST(ReadingListEntry, DistilledInfo) { | 88 TEST(ReadingListEntry, DistilledInfo) { |
89 ReadingListEntry e(GURL("http://example.com"), "bar", | 89 ReadingListEntry e(GURL("http://example.com"), "bar", |
90 base::Time::FromTimeT(10)); | 90 base::Time::FromTimeT(10)); |
91 | 91 |
92 EXPECT_TRUE(e.DistilledPath().empty()); | 92 EXPECT_TRUE(e.DistilledPath().empty()); |
93 | 93 |
94 const base::FilePath distilled_path("distilled/page.html"); | 94 const base::FilePath distilled_path(FILE_PATH_LITERAL("distilled/page.html")); |
95 const GURL distilled_url("http://example.com/distilled"); | 95 const GURL distilled_url("http://example.com/distilled"); |
96 int64_t size = 50; | 96 int64_t size = 50; |
97 int64_t time = 100; | 97 int64_t time = 100; |
98 e.SetDistilledInfo(distilled_path, distilled_url, size, | 98 e.SetDistilledInfo(distilled_path, distilled_url, size, |
99 base::Time::FromTimeT(time)); | 99 base::Time::FromTimeT(time)); |
100 EXPECT_EQ(distilled_path, e.DistilledPath()); | 100 EXPECT_EQ(distilled_path, e.DistilledPath()); |
101 EXPECT_EQ(distilled_url, e.DistilledURL()); | 101 EXPECT_EQ(distilled_url, e.DistilledURL()); |
102 EXPECT_EQ(size, e.DistillationSize()); | 102 EXPECT_EQ(size, e.DistillationSize()); |
103 EXPECT_EQ(e.DistillationTime(), time * base::Time::kMicrosecondsPerSecond); | 103 EXPECT_EQ(e.DistillationTime(), time * base::Time::kMicrosecondsPerSecond); |
104 } | 104 } |
105 | 105 |
106 TEST(ReadingListEntry, DistilledState) { | 106 TEST(ReadingListEntry, DistilledState) { |
107 ReadingListEntry e(GURL("http://example.com"), "bar", | 107 ReadingListEntry e(GURL("http://example.com"), "bar", |
108 base::Time::FromTimeT(10)); | 108 base::Time::FromTimeT(10)); |
109 | 109 |
110 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); | 110 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); |
111 | 111 |
112 e.SetDistilledState(ReadingListEntry::ERROR); | 112 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
113 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); | 113 EXPECT_EQ(ReadingListEntry::DISTILLATION_ERROR, e.DistilledState()); |
114 | 114 |
115 const base::FilePath distilled_path("distilled/page.html"); | 115 const base::FilePath distilled_path(FILE_PATH_LITERAL("distilled/page.html")); |
116 const GURL distilled_url("http://example.com/distilled"); | 116 const GURL distilled_url("http://example.com/distilled"); |
117 e.SetDistilledInfo(distilled_path, distilled_url, 50, | 117 e.SetDistilledInfo(distilled_path, distilled_url, 50, |
118 base::Time::FromTimeT(100)); | 118 base::Time::FromTimeT(100)); |
119 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); | 119 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); |
120 } | 120 } |
121 | 121 |
122 // 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 |
123 // changes from non-error to error. | 123 // changes from non-error to error. |
124 TEST(ReadingListEntry, TimeUntilNextTry) { | 124 TEST(ReadingListEntry, TimeUntilNextTry) { |
125 base::SimpleTestTickClock clock; | 125 base::SimpleTestTickClock clock; |
126 std::unique_ptr<net::BackoffEntry> backoff = | 126 std::unique_ptr<net::BackoffEntry> backoff = |
127 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 127 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
128 &clock); | 128 &clock); |
129 | 129 |
130 ReadingListEntry e(GURL("http://example.com"), "bar", | 130 ReadingListEntry e(GURL("http://example.com"), "bar", |
131 base::Time::FromTimeT(10), std::move(backoff)); | 131 base::Time::FromTimeT(10), std::move(backoff)); |
132 | 132 |
133 // Allow twice the jitter as test is not instantaneous. | 133 // Allow twice the jitter as test is not instantaneous. |
134 double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor; | 134 double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor; |
135 | 135 |
136 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); | 136 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
137 | 137 |
138 // First error. | 138 // First error. |
139 e.SetDistilledState(ReadingListEntry::ERROR); | 139 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
140 int nextTry = e.TimeUntilNextTry().InMinutes(); | 140 int nextTry = e.TimeUntilNextTry().InMinutes(); |
141 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 141 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
142 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 142 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
143 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); | 143 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); |
144 | 144 |
145 e.SetDistilledState(ReadingListEntry::PROCESSING); | 145 e.SetDistilledState(ReadingListEntry::PROCESSING); |
146 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); | 146 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); |
147 | 147 |
148 // Second error. | 148 // Second error. |
149 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 149 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
150 nextTry = e.TimeUntilNextTry().InMinutes(); | 150 nextTry = e.TimeUntilNextTry().InMinutes(); |
151 EXPECT_NEAR(kSecondBackoff, nextTry, kSecondBackoff * fuzzing); | 151 EXPECT_NEAR(kSecondBackoff, nextTry, kSecondBackoff * fuzzing); |
152 e.SetDistilledState(ReadingListEntry::ERROR); | 152 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
153 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); | 153 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); |
154 | 154 |
155 e.SetDistilledState(ReadingListEntry::PROCESSING); | 155 e.SetDistilledState(ReadingListEntry::PROCESSING); |
156 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); | 156 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); |
157 | 157 |
158 // Third error. | 158 // Third error. |
159 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 159 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
160 EXPECT_NEAR(kThirdBackoff, e.TimeUntilNextTry().InMinutes(), | 160 EXPECT_NEAR(kThirdBackoff, e.TimeUntilNextTry().InMinutes(), |
161 kThirdBackoff * fuzzing); | 161 kThirdBackoff * fuzzing); |
162 | 162 |
163 // Fourth error. | 163 // Fourth error. |
164 e.SetDistilledState(ReadingListEntry::PROCESSING); | 164 e.SetDistilledState(ReadingListEntry::PROCESSING); |
165 e.SetDistilledState(ReadingListEntry::ERROR); | 165 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
166 EXPECT_NEAR(kFourthBackoff, e.TimeUntilNextTry().InMinutes(), | 166 EXPECT_NEAR(kFourthBackoff, e.TimeUntilNextTry().InMinutes(), |
167 kFourthBackoff * fuzzing); | 167 kFourthBackoff * fuzzing); |
168 | 168 |
169 // Fifth error. | 169 // Fifth error. |
170 e.SetDistilledState(ReadingListEntry::PROCESSING); | 170 e.SetDistilledState(ReadingListEntry::PROCESSING); |
171 e.SetDistilledState(ReadingListEntry::ERROR); | 171 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
172 EXPECT_NEAR(kFifthBackoff, e.TimeUntilNextTry().InMinutes(), | 172 EXPECT_NEAR(kFifthBackoff, e.TimeUntilNextTry().InMinutes(), |
173 kFifthBackoff * fuzzing); | 173 kFifthBackoff * fuzzing); |
174 } | 174 } |
175 | 175 |
176 // 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. |
177 TEST(ReadingListEntry, TimeUntilNextTryInThePast) { | 177 TEST(ReadingListEntry, TimeUntilNextTryInThePast) { |
178 // Setup. | 178 // Setup. |
179 base::SimpleTestTickClock clock; | 179 base::SimpleTestTickClock clock; |
180 std::unique_ptr<net::BackoffEntry> backoff = | 180 std::unique_ptr<net::BackoffEntry> backoff = |
181 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 181 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
182 &clock); | 182 &clock); |
183 ReadingListEntry e(GURL("http://example.com"), "bar", | 183 ReadingListEntry e(GURL("http://example.com"), "bar", |
184 base::Time::FromTimeT(10), std::move(backoff)); | 184 base::Time::FromTimeT(10), std::move(backoff)); |
185 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 185 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
186 | 186 |
187 e.SetDistilledState(ReadingListEntry::ERROR); | 187 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
188 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 188 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
189 kFirstBackoff * fuzzing); | 189 kFirstBackoff * fuzzing); |
190 | 190 |
191 // Action. | 191 // Action. |
192 clock.Advance(base::TimeDelta::FromMinutes(kFirstBackoff * 2)); | 192 clock.Advance(base::TimeDelta::FromMinutes(kFirstBackoff * 2)); |
193 | 193 |
194 // Test. | 194 // Test. |
195 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds()); | 195 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds()); |
196 } | 196 } |
197 | 197 |
198 // 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. |
199 TEST(ReadingListEntry, ResetTimeUntilNextTry) { | 199 TEST(ReadingListEntry, ResetTimeUntilNextTry) { |
200 // Setup. | 200 // Setup. |
201 base::SimpleTestTickClock clock; | 201 base::SimpleTestTickClock clock; |
202 std::unique_ptr<net::BackoffEntry> backoff = | 202 std::unique_ptr<net::BackoffEntry> backoff = |
203 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 203 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
204 &clock); | 204 &clock); |
205 ReadingListEntry e(GURL("http://example.com"), "bar", | 205 ReadingListEntry e(GURL("http://example.com"), "bar", |
206 base::Time::FromTimeT(10), std::move(backoff)); | 206 base::Time::FromTimeT(10), std::move(backoff)); |
207 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 207 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
208 | 208 |
209 e.SetDistilledState(ReadingListEntry::ERROR); | 209 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
210 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 210 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
211 kFirstBackoff * fuzzing); | 211 kFirstBackoff * fuzzing); |
212 | 212 |
213 // Action. | 213 // Action. |
214 const base::FilePath distilled_path("distilled/page.html"); | 214 const base::FilePath distilled_path(FILE_PATH_LITERAL("distilled/page.html")); |
215 const GURL distilled_url("http://example.com/distilled"); | 215 const GURL distilled_url("http://example.com/distilled"); |
216 e.SetDistilledInfo(distilled_path, distilled_url, 50, | 216 e.SetDistilledInfo(distilled_path, distilled_url, 50, |
217 base::Time::FromTimeT(100)); | 217 base::Time::FromTimeT(100)); |
218 | 218 |
219 // Test. | 219 // Test. |
220 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); | 220 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
221 e.SetDistilledState(ReadingListEntry::ERROR); | 221 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
222 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 222 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
223 kFirstBackoff * fuzzing); | 223 kFirstBackoff * fuzzing); |
224 } | 224 } |
225 | 225 |
226 // 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 |
227 // from non-error to error. | 227 // from non-error to error. |
228 TEST(ReadingListEntry, FailedDownloadCounter) { | 228 TEST(ReadingListEntry, FailedDownloadCounter) { |
229 ReadingListEntry e(GURL("http://example.com"), "bar", | 229 ReadingListEntry e(GURL("http://example.com"), "bar", |
230 base::Time::FromTimeT(10)); | 230 base::Time::FromTimeT(10)); |
231 | 231 |
232 EXPECT_EQ(0, e.FailedDownloadCounter()); | 232 EXPECT_EQ(0, e.FailedDownloadCounter()); |
233 | 233 |
234 e.SetDistilledState(ReadingListEntry::ERROR); | 234 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
235 EXPECT_EQ(1, e.FailedDownloadCounter()); | 235 EXPECT_EQ(1, e.FailedDownloadCounter()); |
236 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 236 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
237 EXPECT_EQ(1, e.FailedDownloadCounter()); | 237 EXPECT_EQ(1, e.FailedDownloadCounter()); |
238 | 238 |
239 e.SetDistilledState(ReadingListEntry::PROCESSING); | 239 e.SetDistilledState(ReadingListEntry::PROCESSING); |
240 EXPECT_EQ(1, e.FailedDownloadCounter()); | 240 EXPECT_EQ(1, e.FailedDownloadCounter()); |
241 | 241 |
242 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 242 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
243 EXPECT_EQ(2, e.FailedDownloadCounter()); | 243 EXPECT_EQ(2, e.FailedDownloadCounter()); |
244 e.SetDistilledState(ReadingListEntry::ERROR); | 244 e.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
245 EXPECT_EQ(2, e.FailedDownloadCounter()); | 245 EXPECT_EQ(2, e.FailedDownloadCounter()); |
246 } | 246 } |
247 | 247 |
248 // Tests that the reading list entry is correctly encoded to | 248 // Tests that the reading list entry is correctly encoded to |
249 // sync_pb::ReadingListSpecifics. | 249 // sync_pb::ReadingListSpecifics. |
250 TEST(ReadingListEntry, AsReadingListSpecifics) { | 250 TEST(ReadingListEntry, AsReadingListSpecifics) { |
251 ReadingListEntry entry(GURL("http://example.com"), "bar", | 251 ReadingListEntry entry(GURL("http://example.com"), "bar", |
252 base::Time::FromTimeT(10)); | 252 base::Time::FromTimeT(10)); |
253 int64_t creation_time_us = entry.UpdateTime(); | 253 int64_t creation_time_us = entry.UpdateTime(); |
254 | 254 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 EXPECT_EQ(pb_entry->failed_download_counter(), 0); | 319 EXPECT_EQ(pb_entry->failed_download_counter(), 0); |
320 EXPECT_NE(pb_entry->backoff(), ""); | 320 EXPECT_NE(pb_entry->backoff(), ""); |
321 | 321 |
322 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); | 322 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); |
323 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( | 323 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( |
324 entry.AsReadingListLocal(base::Time::FromTimeT(50))); | 324 entry.AsReadingListLocal(base::Time::FromTimeT(50))); |
325 EXPECT_EQ(will_retry_pb_entry->distillation_state(), | 325 EXPECT_EQ(will_retry_pb_entry->distillation_state(), |
326 reading_list::ReadingListLocal::WILL_RETRY); | 326 reading_list::ReadingListLocal::WILL_RETRY); |
327 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); | 327 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); |
328 | 328 |
329 const base::FilePath distilled_path("distilled/page.html"); | 329 const base::FilePath distilled_path(FILE_PATH_LITERAL("distilled/page.html")); |
330 const GURL distilled_url("http://example.com/distilled"); | 330 const GURL distilled_url("http://example.com/distilled"); |
331 int64_t size = 50; | 331 int64_t size = 50; |
332 entry.SetDistilledInfo(distilled_path, distilled_url, size, | 332 entry.SetDistilledInfo(distilled_path, distilled_url, size, |
333 base::Time::FromTimeT(100)); | 333 base::Time::FromTimeT(100)); |
334 | 334 |
335 entry.SetRead(true, base::Time::FromTimeT(20)); | 335 entry.SetRead(true, base::Time::FromTimeT(20)); |
336 entry.MarkEntryUpdated(base::Time::FromTimeT(30)); | 336 entry.MarkEntryUpdated(base::Time::FromTimeT(30)); |
337 EXPECT_NE(entry.UpdateTime(), creation_time_us); | 337 EXPECT_NE(entry.UpdateTime(), creation_time_us); |
338 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( | 338 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( |
339 entry.AsReadingListLocal(base::Time::FromTimeT(40))); | 339 entry.AsReadingListLocal(base::Time::FromTimeT(40))); |
340 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); | 340 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); |
341 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); | 341 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); |
342 EXPECT_NE(distilled_pb_entry->backoff(), ""); | 342 EXPECT_NE(distilled_pb_entry->backoff(), ""); |
343 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); | 343 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); |
344 EXPECT_EQ(distilled_pb_entry->distillation_state(), | 344 EXPECT_EQ(distilled_pb_entry->distillation_state(), |
345 reading_list::ReadingListLocal::PROCESSED); | 345 reading_list::ReadingListLocal::PROCESSED); |
346 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); | 346 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); |
347 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); | 347 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); |
348 EXPECT_EQ(distilled_pb_entry->distillation_time_us(), | 348 EXPECT_EQ(distilled_pb_entry->distillation_time_us(), |
349 entry.DistillationTime()); | 349 entry.DistillationTime()); |
350 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize()); | 350 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize()); |
351 } | 351 } |
352 | 352 |
353 // Tests that the reading list entry is correctly parsed from | 353 // Tests that the reading list entry is correctly parsed from |
354 // sync_pb::ReadingListLocal. | 354 // sync_pb::ReadingListLocal. |
355 TEST(ReadingListEntry, FromReadingListLocal) { | 355 TEST(ReadingListEntry, FromReadingListLocal) { |
356 ReadingListEntry entry(GURL("http://example.com/"), "title", | 356 ReadingListEntry entry(GURL("http://example.com/"), "title", |
357 base::Time::FromTimeT(10)); | 357 base::Time::FromTimeT(10)); |
358 entry.SetDistilledState(ReadingListEntry::ERROR); | 358 entry.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
359 | 359 |
360 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( | 360 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
361 entry.AsReadingListLocal(base::Time::FromTimeT(10))); | 361 entry.AsReadingListLocal(base::Time::FromTimeT(10))); |
362 int64_t now = 12345; | 362 int64_t now = 12345; |
363 | 363 |
364 pb_entry->set_entry_id("http://example.com/"); | 364 pb_entry->set_entry_id("http://example.com/"); |
365 pb_entry->set_url("http://example.com/"); | 365 pb_entry->set_url("http://example.com/"); |
366 pb_entry->set_title("title"); | 366 pb_entry->set_title("title"); |
367 pb_entry->set_creation_time_us(1); | 367 pb_entry->set_creation_time_us(1); |
368 pb_entry->set_update_time_us(2); | 368 pb_entry->set_update_time_us(2); |
(...skipping 21 matching lines...) Expand all Loading... |
390 int nextTry = waiting_entry->TimeUntilNextTry().InMinutes(); | 390 int nextTry = waiting_entry->TimeUntilNextTry().InMinutes(); |
391 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 391 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
392 } | 392 } |
393 | 393 |
394 // Tests the merging of two ReadingListEntry. | 394 // Tests the merging of two ReadingListEntry. |
395 // Additional merging tests are done in | 395 // Additional merging tests are done in |
396 // ReadingListStoreTest.CompareEntriesForSync | 396 // ReadingListStoreTest.CompareEntriesForSync |
397 TEST(ReadingListEntry, MergeWithEntry) { | 397 TEST(ReadingListEntry, MergeWithEntry) { |
398 ReadingListEntry local_entry(GURL("http://example.com/"), "title", | 398 ReadingListEntry local_entry(GURL("http://example.com/"), "title", |
399 base::Time::FromTimeT(10)); | 399 base::Time::FromTimeT(10)); |
400 local_entry.SetDistilledState(ReadingListEntry::ERROR); | 400 local_entry.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
401 local_entry.SetTitle("title updated", base::Time::FromTimeT(30)); | 401 local_entry.SetTitle("title updated", base::Time::FromTimeT(30)); |
402 int64_t local_update_time_us = local_entry.UpdateTime(); | 402 int64_t local_update_time_us = local_entry.UpdateTime(); |
403 | 403 |
404 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2", | 404 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2", |
405 base::Time::FromTimeT(20)); | 405 base::Time::FromTimeT(20)); |
406 sync_entry.SetDistilledState(ReadingListEntry::ERROR); | 406 sync_entry.SetDistilledState(ReadingListEntry::DISTILLATION_ERROR); |
407 int64_t sync_update_time_us = sync_entry.UpdateTime(); | 407 int64_t sync_update_time_us = sync_entry.UpdateTime(); |
408 EXPECT_NE(local_update_time_us, sync_update_time_us); | 408 EXPECT_NE(local_update_time_us, sync_update_time_us); |
409 local_entry.MergeWithEntry(sync_entry); | 409 local_entry.MergeWithEntry(sync_entry); |
410 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); | 410 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); |
411 EXPECT_EQ(local_entry.Title(), "title updated"); | 411 EXPECT_EQ(local_entry.Title(), "title updated"); |
412 EXPECT_EQ(local_entry.UpdateTitleTime(), | 412 EXPECT_EQ(local_entry.UpdateTitleTime(), |
413 30 * base::Time::kMicrosecondsPerSecond); | 413 30 * base::Time::kMicrosecondsPerSecond); |
414 EXPECT_FALSE(local_entry.HasBeenSeen()); | 414 EXPECT_FALSE(local_entry.HasBeenSeen()); |
415 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); | 415 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); |
416 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); | 416 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); |
417 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); | 417 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::DISTILLATION_ERROR); |
418 // Allow twice the jitter as test is not instantaneous. | 418 // Allow twice the jitter as test is not instantaneous. |
419 double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor; | 419 double fuzzing = 2 * ReadingListEntry::kBackoffPolicy.jitter_factor; |
420 int nextTry = local_entry.TimeUntilNextTry().InMinutes(); | 420 int nextTry = local_entry.TimeUntilNextTry().InMinutes(); |
421 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 421 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
422 } | 422 } |
OLD | NEW |