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

Side by Side Diff: components/reading_list/ios/reading_list_entry_unittest.cc

Issue 2707043002: [Reading List iOS] Store distillation date and size. (Closed)
Patch Set: done Created 3 years, 10 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" 8 #include "base/test/ios/wait_util.h"
9 #include "base/test/simple_test_tick_clock.h" 9 #include "base/test/simple_test_tick_clock.h"
10 #include "components/reading_list/ios/proto/reading_list.pb.h" 10 #include "components/reading_list/ios/proto/reading_list.pb.h"
11 #include "components/sync/protocol/reading_list_specifics.pb.h" 11 #include "components/sync/protocol/reading_list_specifics.pb.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace { 14 namespace {
15 const int kFirstBackoff = 10; 15 const int kFirstBackoff = 10;
16 const int kSecondBackoff = 10; 16 const int kSecondBackoff = 10;
17 const int kThirdBackoff = 60; 17 const int kThirdBackoff = 60;
18 const int kFourthBackoff = 120; 18 const int kFourthBackoff = 120;
19 const int kFifthBackoff = 120; 19 const int kFifthBackoff = 120;
20
21 // Returns the number of microseconds since Jan 1st 1970.
22 int64_t Now() {
23 return (base::Time::Now() - base::Time::UnixEpoch()).InMicroseconds();
24 }
20 } // namespace 25 } // namespace
21 26
22 TEST(ReadingListEntry, CompareIgnoreTitle) { 27 TEST(ReadingListEntry, CompareIgnoreTitle) {
23 const ReadingListEntry e1(GURL("http://example.com"), "bar"); 28 const ReadingListEntry e1(GURL("http://example.com"), "bar");
24 const ReadingListEntry e2(GURL("http://example.com"), "foo"); 29 const ReadingListEntry e2(GURL("http://example.com"), "foo");
25 30
26 EXPECT_EQ(e1, e2); 31 EXPECT_EQ(e1, e2);
27 } 32 }
28 33
29 TEST(ReadingListEntry, CompareFailureIgnoreTitle) { 34 TEST(ReadingListEntry, CompareFailureIgnoreTitle) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 ASSERT_EQ("bar", e.Title()); 67 ASSERT_EQ("bar", e.Title());
63 ASSERT_EQ(e.CreationTime(), e.UpdateTitleTime()); 68 ASSERT_EQ(e.CreationTime(), e.UpdateTitleTime());
64 69
65 base::test::ios::SpinRunLoopWithMinDelay( 70 base::test::ios::SpinRunLoopWithMinDelay(
66 base::TimeDelta::FromMilliseconds(5)); 71 base::TimeDelta::FromMilliseconds(5));
67 e.SetTitle("foo"); 72 e.SetTitle("foo");
68 EXPECT_GT(e.UpdateTitleTime(), e.CreationTime()); 73 EXPECT_GT(e.UpdateTitleTime(), e.CreationTime());
69 EXPECT_EQ("foo", e.Title()); 74 EXPECT_EQ("foo", e.Title());
70 } 75 }
71 76
72 TEST(ReadingListEntry, DistilledPathAndURL) { 77 TEST(ReadingListEntry, DistilledInfo) {
73 ReadingListEntry e(GURL("http://example.com"), "bar"); 78 ReadingListEntry e(GURL("http://example.com"), "bar");
74 79
75 EXPECT_TRUE(e.DistilledPath().empty()); 80 EXPECT_TRUE(e.DistilledPath().empty());
76 81
77 const base::FilePath distilled_path("distilled/page.html"); 82 const base::FilePath distilled_path("distilled/page.html");
78 const GURL distilled_url("http://example.com/distilled"); 83 const GURL distilled_url("http://example.com/distilled");
79 e.SetDistilledInfo(distilled_path, distilled_url); 84 int64_t size = 50;
85 int64_t time = 100;
86 e.SetDistilledInfo(distilled_path, distilled_url, size, time);
80 EXPECT_EQ(distilled_path, e.DistilledPath()); 87 EXPECT_EQ(distilled_path, e.DistilledPath());
81 EXPECT_EQ(distilled_url, e.DistilledURL()); 88 EXPECT_EQ(distilled_url, e.DistilledURL());
89 EXPECT_EQ(size, e.DistillationSize());
90 EXPECT_EQ(e.DistillationTime(), time);
82 } 91 }
83 92
84 TEST(ReadingListEntry, DistilledState) { 93 TEST(ReadingListEntry, DistilledState) {
85 ReadingListEntry e(GURL("http://example.com"), "bar"); 94 ReadingListEntry e(GURL("http://example.com"), "bar");
86 95
87 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); 96 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState());
88 97
89 e.SetDistilledState(ReadingListEntry::ERROR); 98 e.SetDistilledState(ReadingListEntry::ERROR);
90 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); 99 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState());
91 100
92 const base::FilePath distilled_path("distilled/page.html"); 101 const base::FilePath distilled_path("distilled/page.html");
93 const GURL distilled_url("http://example.com/distilled"); 102 const GURL distilled_url("http://example.com/distilled");
94 e.SetDistilledInfo(distilled_path, distilled_url); 103 e.SetDistilledInfo(distilled_path, distilled_url, 50, 100);
95 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); 104 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState());
96 } 105 }
97 106
98 // Tests that the the time until next try increase exponentially when the state 107 // Tests that the the time until next try increase exponentially when the state
99 // changes from non-error to error. 108 // changes from non-error to error.
100 TEST(ReadingListEntry, TimeUntilNextTry) { 109 TEST(ReadingListEntry, TimeUntilNextTry) {
101 base::SimpleTestTickClock clock; 110 base::SimpleTestTickClock clock;
102 std::unique_ptr<net::BackoffEntry> backoff = 111 std::unique_ptr<net::BackoffEntry> backoff =
103 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, 112 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy,
104 &clock); 113 &clock);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); 187 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff));
179 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; 188 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor;
180 189
181 e.SetDistilledState(ReadingListEntry::ERROR); 190 e.SetDistilledState(ReadingListEntry::ERROR);
182 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), 191 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(),
183 kFirstBackoff * fuzzing); 192 kFirstBackoff * fuzzing);
184 193
185 // Action. 194 // Action.
186 const base::FilePath distilled_path("distilled/page.html"); 195 const base::FilePath distilled_path("distilled/page.html");
187 const GURL distilled_url("http://example.com/distilled"); 196 const GURL distilled_url("http://example.com/distilled");
188 e.SetDistilledInfo(distilled_path, distilled_url); 197 e.SetDistilledInfo(distilled_path, distilled_url, 50, 100);
189 198
190 // Test. 199 // Test.
191 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); 200 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds());
192 e.SetDistilledState(ReadingListEntry::ERROR); 201 e.SetDistilledState(ReadingListEntry::ERROR);
193 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), 202 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(),
194 kFirstBackoff * fuzzing); 203 kFirstBackoff * fuzzing);
195 } 204 }
196 205
197 // Tests that the failed download counter is incremented when the state change 206 // Tests that the failed download counter is incremented when the state change
198 // from non-error to error. 207 // from non-error to error.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 290
282 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); 291 entry.SetDistilledState(ReadingListEntry::WILL_RETRY);
283 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( 292 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry(
284 entry.AsReadingListLocal()); 293 entry.AsReadingListLocal());
285 EXPECT_EQ(will_retry_pb_entry->distillation_state(), 294 EXPECT_EQ(will_retry_pb_entry->distillation_state(),
286 reading_list::ReadingListLocal::WILL_RETRY); 295 reading_list::ReadingListLocal::WILL_RETRY);
287 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); 296 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1);
288 297
289 const base::FilePath distilled_path("distilled/page.html"); 298 const base::FilePath distilled_path("distilled/page.html");
290 const GURL distilled_url("http://example.com/distilled"); 299 const GURL distilled_url("http://example.com/distilled");
291 entry.SetDistilledInfo(distilled_path, distilled_url); 300 int64_t size = 50;
301 entry.SetDistilledInfo(distilled_path, distilled_url, size, 100);
302
292 entry.SetRead(true); 303 entry.SetRead(true);
293 entry.MarkEntryUpdated(); 304 entry.MarkEntryUpdated();
294 EXPECT_NE(entry.UpdateTime(), creation_time_us); 305 EXPECT_NE(entry.UpdateTime(), creation_time_us);
295 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( 306 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry(
296 entry.AsReadingListLocal()); 307 entry.AsReadingListLocal());
297 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); 308 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us);
298 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); 309 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime());
299 EXPECT_NE(distilled_pb_entry->backoff(), ""); 310 EXPECT_NE(distilled_pb_entry->backoff(), "");
300 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); 311 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ);
301 EXPECT_EQ(distilled_pb_entry->distillation_state(), 312 EXPECT_EQ(distilled_pb_entry->distillation_state(),
302 reading_list::ReadingListLocal::PROCESSED); 313 reading_list::ReadingListLocal::PROCESSED);
303 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); 314 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html");
304 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); 315 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0);
316 EXPECT_EQ(distilled_pb_entry->distillation_time_us(),
317 entry.DistillationTime());
318 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize());
305 } 319 }
306 320
307 // Tests that the reading list entry is correctly parsed from 321 // Tests that the reading list entry is correctly parsed from
308 // sync_pb::ReadingListLocal. 322 // sync_pb::ReadingListLocal.
309 TEST(ReadingListEntry, FromReadingListLocal) { 323 TEST(ReadingListEntry, FromReadingListLocal) {
310 ReadingListEntry entry(GURL("http://example.com/"), "title"); 324 ReadingListEntry entry(GURL("http://example.com/"), "title");
311 base::Time next_call = base::Time::Now() + entry.TimeUntilNextTry(); 325 base::Time next_call = base::Time::Now() + entry.TimeUntilNextTry();
312 326
313 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( 327 std::unique_ptr<reading_list::ReadingListLocal> pb_entry(
314 entry.AsReadingListLocal()); 328 entry.AsReadingListLocal());
329 int64_t now = Now();
315 330
316 pb_entry->set_entry_id("http://example.com/"); 331 pb_entry->set_entry_id("http://example.com/");
317 pb_entry->set_url("http://example.com/"); 332 pb_entry->set_url("http://example.com/");
318 pb_entry->set_title("title"); 333 pb_entry->set_title("title");
319 pb_entry->set_creation_time_us(1); 334 pb_entry->set_creation_time_us(1);
320 pb_entry->set_update_time_us(2); 335 pb_entry->set_update_time_us(2);
321 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); 336 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD);
322 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); 337 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING);
323 pb_entry->set_failed_download_counter(2); 338 pb_entry->set_failed_download_counter(2);
339 pb_entry->set_distillation_time_us(now);
340 pb_entry->set_distillation_size(50);
324 341
325 std::unique_ptr<ReadingListEntry> waiting_entry( 342 std::unique_ptr<ReadingListEntry> waiting_entry(
326 ReadingListEntry::FromReadingListLocal(*pb_entry)); 343 ReadingListEntry::FromReadingListLocal(*pb_entry));
327 EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/"); 344 EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/");
328 EXPECT_EQ(waiting_entry->Title(), "title"); 345 EXPECT_EQ(waiting_entry->Title(), "title");
329 EXPECT_EQ(waiting_entry->UpdateTime(), 2); 346 EXPECT_EQ(waiting_entry->UpdateTime(), 2);
330 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); 347 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2);
331 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); 348 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING);
332 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); 349 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath());
350 EXPECT_EQ(waiting_entry->DistillationSize(), 50);
351 EXPECT_EQ(waiting_entry->DistillationTime(), now);
333 base::Time waiting_next_call = 352 base::Time waiting_next_call =
334 base::Time::Now() + waiting_entry->TimeUntilNextTry(); 353 base::Time::Now() + waiting_entry->TimeUntilNextTry();
335 base::TimeDelta delta = next_call - waiting_next_call; 354 base::TimeDelta delta = next_call - waiting_next_call;
336 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); 355 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10);
337 } 356 }
338 357
339 // Tests the merging of two ReadingListEntry. 358 // Tests the merging of two ReadingListEntry.
340 // Additional merging tests are done in 359 // Additional merging tests are done in
341 // ReadingListStoreTest.CompareEntriesForSync 360 // ReadingListStoreTest.CompareEntriesForSync
342 TEST(ReadingListEntry, MergeWithEntry) { 361 TEST(ReadingListEntry, MergeWithEntry) {
(...skipping 11 matching lines...) Expand all
354 EXPECT_EQ(local_entry.Title(), "title2"); 373 EXPECT_EQ(local_entry.Title(), "title2");
355 EXPECT_FALSE(local_entry.HasBeenSeen()); 374 EXPECT_FALSE(local_entry.HasBeenSeen());
356 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); 375 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us);
357 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); 376 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1);
358 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); 377 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR);
359 base::Time merge_next_call = 378 base::Time merge_next_call =
360 base::Time::Now() + local_entry.TimeUntilNextTry(); 379 base::Time::Now() + local_entry.TimeUntilNextTry();
361 base::TimeDelta delta = merge_next_call - next_call; 380 base::TimeDelta delta = merge_next_call - next_call;
362 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); 381 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10);
363 } 382 }
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