| 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/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" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 EXPECT_GT(e.UpdateTitleTime(), e.CreationTime()); | 68 EXPECT_GT(e.UpdateTitleTime(), e.CreationTime()); |
| 69 EXPECT_EQ("foo", e.Title()); | 69 EXPECT_EQ("foo", e.Title()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 TEST(ReadingListEntry, DistilledPathAndURL) { | 72 TEST(ReadingListEntry, DistilledPathAndURL) { |
| 73 ReadingListEntry e(GURL("http://example.com"), "bar"); | 73 ReadingListEntry e(GURL("http://example.com"), "bar"); |
| 74 | 74 |
| 75 EXPECT_TRUE(e.DistilledPath().empty()); | 75 EXPECT_TRUE(e.DistilledPath().empty()); |
| 76 | 76 |
| 77 const base::FilePath distilled_path("distilled/page.html"); | 77 const base::FilePath distilled_path("distilled/page.html"); |
| 78 e.SetDistilledPath(distilled_path); | 78 const GURL distilled_url("http://example.com/distilled"); |
| 79 e.SetDistilledInfo(distilled_path, distilled_url); |
| 79 EXPECT_EQ(distilled_path, e.DistilledPath()); | 80 EXPECT_EQ(distilled_path, e.DistilledPath()); |
| 81 EXPECT_EQ(distilled_url, e.DistilledURL()); |
| 80 } | 82 } |
| 81 | 83 |
| 82 TEST(ReadingListEntry, DistilledState) { | 84 TEST(ReadingListEntry, DistilledState) { |
| 83 ReadingListEntry e(GURL("http://example.com"), "bar"); | 85 ReadingListEntry e(GURL("http://example.com"), "bar"); |
| 84 | 86 |
| 85 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); | 87 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); |
| 86 | 88 |
| 87 e.SetDistilledState(ReadingListEntry::ERROR); | 89 e.SetDistilledState(ReadingListEntry::ERROR); |
| 88 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); | 90 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); |
| 89 | 91 |
| 90 const base::FilePath distilled_path("distilled/page.html"); | 92 const base::FilePath distilled_path("distilled/page.html"); |
| 91 e.SetDistilledPath(distilled_path); | 93 const GURL distilled_url("http://example.com/distilled"); |
| 94 e.SetDistilledInfo(distilled_path, distilled_url); |
| 92 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); | 95 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); |
| 93 } | 96 } |
| 94 | 97 |
| 95 // Tests that the the time until next try increase exponentially when the state | 98 // Tests that the the time until next try increase exponentially when the state |
| 96 // changes from non-error to error. | 99 // changes from non-error to error. |
| 97 TEST(ReadingListEntry, TimeUntilNextTry) { | 100 TEST(ReadingListEntry, TimeUntilNextTry) { |
| 98 base::SimpleTestTickClock clock; | 101 base::SimpleTestTickClock clock; |
| 99 std::unique_ptr<net::BackoffEntry> backoff = | 102 std::unique_ptr<net::BackoffEntry> backoff = |
| 100 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 103 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 101 &clock); | 104 &clock); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 176 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 174 &clock); | 177 &clock); |
| 175 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); | 178 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); |
| 176 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 179 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 177 | 180 |
| 178 e.SetDistilledState(ReadingListEntry::ERROR); | 181 e.SetDistilledState(ReadingListEntry::ERROR); |
| 179 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 182 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 180 kFirstBackoff * fuzzing); | 183 kFirstBackoff * fuzzing); |
| 181 | 184 |
| 182 // Action. | 185 // Action. |
| 183 e.SetDistilledPath(base::FilePath("distilled/page.html")); | 186 const base::FilePath distilled_path("distilled/page.html"); |
| 187 const GURL distilled_url("http://example.com/distilled"); |
| 188 e.SetDistilledInfo(distilled_path, distilled_url); |
| 184 | 189 |
| 185 // Test. | 190 // Test. |
| 186 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); | 191 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| 187 e.SetDistilledState(ReadingListEntry::ERROR); | 192 e.SetDistilledState(ReadingListEntry::ERROR); |
| 188 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 193 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 189 kFirstBackoff * fuzzing); | 194 kFirstBackoff * fuzzing); |
| 190 } | 195 } |
| 191 | 196 |
| 192 // Tests that the failed download counter is incremented when the state change | 197 // Tests that the failed download counter is incremented when the state change |
| 193 // from non-error to error. | 198 // from non-error to error. |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 EXPECT_EQ(pb_entry->failed_download_counter(), 0); | 279 EXPECT_EQ(pb_entry->failed_download_counter(), 0); |
| 275 EXPECT_NE(pb_entry->backoff(), ""); | 280 EXPECT_NE(pb_entry->backoff(), ""); |
| 276 | 281 |
| 277 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); | 282 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 278 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( | 283 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( |
| 279 entry.AsReadingListLocal()); | 284 entry.AsReadingListLocal()); |
| 280 EXPECT_EQ(will_retry_pb_entry->distillation_state(), | 285 EXPECT_EQ(will_retry_pb_entry->distillation_state(), |
| 281 reading_list::ReadingListLocal::WILL_RETRY); | 286 reading_list::ReadingListLocal::WILL_RETRY); |
| 282 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); | 287 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); |
| 283 | 288 |
| 284 entry.SetDistilledPath(base::FilePath("distilled/page.html")); | 289 const base::FilePath distilled_path("distilled/page.html"); |
| 290 const GURL distilled_url("http://example.com/distilled"); |
| 291 entry.SetDistilledInfo(distilled_path, distilled_url); |
| 285 entry.SetRead(true); | 292 entry.SetRead(true); |
| 286 entry.MarkEntryUpdated(); | 293 entry.MarkEntryUpdated(); |
| 287 EXPECT_NE(entry.UpdateTime(), creation_time_us); | 294 EXPECT_NE(entry.UpdateTime(), creation_time_us); |
| 288 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( | 295 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( |
| 289 entry.AsReadingListLocal()); | 296 entry.AsReadingListLocal()); |
| 290 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); | 297 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); |
| 291 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); | 298 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); |
| 292 EXPECT_NE(distilled_pb_entry->backoff(), ""); | 299 EXPECT_NE(distilled_pb_entry->backoff(), ""); |
| 293 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); | 300 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); |
| 294 EXPECT_EQ(distilled_pb_entry->distillation_state(), | 301 EXPECT_EQ(distilled_pb_entry->distillation_state(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 EXPECT_EQ(local_entry.Title(), "title2"); | 354 EXPECT_EQ(local_entry.Title(), "title2"); |
| 348 EXPECT_FALSE(local_entry.HasBeenSeen()); | 355 EXPECT_FALSE(local_entry.HasBeenSeen()); |
| 349 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); | 356 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); |
| 350 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); | 357 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); |
| 351 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); | 358 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); |
| 352 base::Time merge_next_call = | 359 base::Time merge_next_call = |
| 353 base::Time::Now() + local_entry.TimeUntilNextTry(); | 360 base::Time::Now() + local_entry.TimeUntilNextTry(); |
| 354 base::TimeDelta delta = merge_next_call - next_call; | 361 base::TimeDelta delta = merge_next_call - next_call; |
| 355 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); | 362 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); |
| 356 } | 363 } |
| OLD | NEW |