| 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 "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/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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 ReadingListEntry e2(GURL("http://example.com"), "bar"); | 35 ReadingListEntry e2(GURL("http://example.com"), "bar"); |
| 36 ASSERT_EQ(e1, e2); | 36 ASSERT_EQ(e1, e2); |
| 37 ASSERT_EQ(e1.Title(), e2.Title()); | 37 ASSERT_EQ(e1.Title(), e2.Title()); |
| 38 | 38 |
| 39 ReadingListEntry e3(std::move(e1)); | 39 ReadingListEntry e3(std::move(e1)); |
| 40 | 40 |
| 41 EXPECT_EQ(e3, e2); | 41 EXPECT_EQ(e3, e2); |
| 42 EXPECT_EQ(e3.Title(), e2.Title()); | 42 EXPECT_EQ(e3.Title(), e2.Title()); |
| 43 } | 43 } |
| 44 | 44 |
| 45 TEST(ReadingListEntry, DistilledURL) { | 45 TEST(ReadingListEntry, DistilledPathAndURL) { |
| 46 ReadingListEntry e(GURL("http://example.com"), "bar"); | 46 ReadingListEntry e(GURL("http://example.com"), "bar"); |
| 47 | 47 |
| 48 EXPECT_FALSE(e.DistilledURL().is_valid()); | 48 EXPECT_FALSE(e.DistilledURL().is_valid()); |
| 49 | 49 |
| 50 const GURL distilled_url("http://distilled.example.com"); | 50 const base::FilePath distilled_path("distilled/page.html"); |
| 51 e.SetDistilledURL(distilled_url); | 51 e.SetDistilledPath(distilled_path); |
| 52 EXPECT_EQ(distilled_url, e.DistilledURL()); | 52 EXPECT_EQ(distilled_path, e.DistilledPath()); |
| 53 EXPECT_EQ(GURL("chrome://offline/distilled/page.html"), e.DistilledURL()); |
| 53 } | 54 } |
| 54 | 55 |
| 55 TEST(ReadingListEntry, DistilledState) { | 56 TEST(ReadingListEntry, DistilledState) { |
| 56 ReadingListEntry e(GURL("http://example.com"), "bar"); | 57 ReadingListEntry e(GURL("http://example.com"), "bar"); |
| 57 | 58 |
| 58 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); | 59 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); |
| 59 | 60 |
| 60 e.SetDistilledState(ReadingListEntry::ERROR); | 61 e.SetDistilledState(ReadingListEntry::ERROR); |
| 61 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); | 62 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); |
| 62 | 63 |
| 63 const GURL distilled_url("http://distilled.example.com"); | 64 const base::FilePath distilled_path("distilled/page.html"); |
| 64 e.SetDistilledURL(distilled_url); | 65 e.SetDistilledPath(distilled_path); |
| 65 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); | 66 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); |
| 66 } | 67 } |
| 67 | 68 |
| 68 // Tests that the the time until next try increase exponentially when the state | 69 // Tests that the the time until next try increase exponentially when the state |
| 69 // changes from non-error to error. | 70 // changes from non-error to error. |
| 70 TEST(ReadingListEntry, TimeUntilNextTry) { | 71 TEST(ReadingListEntry, TimeUntilNextTry) { |
| 71 base::SimpleTestTickClock clock; | 72 base::SimpleTestTickClock clock; |
| 72 std::unique_ptr<net::BackoffEntry> backoff = | 73 std::unique_ptr<net::BackoffEntry> backoff = |
| 73 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 74 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 74 &clock); | 75 &clock); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 147 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 147 &clock); | 148 &clock); |
| 148 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); | 149 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); |
| 149 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 150 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 150 | 151 |
| 151 e.SetDistilledState(ReadingListEntry::ERROR); | 152 e.SetDistilledState(ReadingListEntry::ERROR); |
| 152 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 153 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 153 kFirstBackoff * fuzzing); | 154 kFirstBackoff * fuzzing); |
| 154 | 155 |
| 155 // Action. | 156 // Action. |
| 156 e.SetDistilledURL(GURL("http://example.com")); | 157 e.SetDistilledPath(base::FilePath("distilled/page.html")); |
| 157 | 158 |
| 158 // Test. | 159 // Test. |
| 159 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); | 160 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| 160 e.SetDistilledState(ReadingListEntry::ERROR); | 161 e.SetDistilledState(ReadingListEntry::ERROR); |
| 161 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 162 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 162 kFirstBackoff * fuzzing); | 163 kFirstBackoff * fuzzing); |
| 163 } | 164 } |
| 164 | 165 |
| 165 // Tests that the failed download counter is incremented when the state change | 166 // Tests that the failed download counter is incremented when the state change |
| 166 // from non-error to error. | 167 // from non-error to error. |
| 167 TEST(ReadingListEntry, FailedDownloadCounter) { | 168 TEST(ReadingListEntry, FailedDownloadCounter) { |
| 168 ReadingListEntry e(GURL("http://example.com"), "bar"); | 169 ReadingListEntry e(GURL("http://example.com"), "bar"); |
| 169 | 170 |
| 170 ASSERT_EQ(0, e.FailedDownloadCounter()); | 171 ASSERT_EQ(0, e.FailedDownloadCounter()); |
| 171 | 172 |
| 172 e.SetDistilledState(ReadingListEntry::ERROR); | 173 e.SetDistilledState(ReadingListEntry::ERROR); |
| 173 EXPECT_EQ(1, e.FailedDownloadCounter()); | 174 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 174 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 175 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 175 EXPECT_EQ(1, e.FailedDownloadCounter()); | 176 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 176 | 177 |
| 177 e.SetDistilledState(ReadingListEntry::PROCESSING); | 178 e.SetDistilledState(ReadingListEntry::PROCESSING); |
| 178 EXPECT_EQ(1, e.FailedDownloadCounter()); | 179 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 179 | 180 |
| 180 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 181 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 181 EXPECT_EQ(2, e.FailedDownloadCounter()); | 182 EXPECT_EQ(2, e.FailedDownloadCounter()); |
| 182 e.SetDistilledState(ReadingListEntry::ERROR); | 183 e.SetDistilledState(ReadingListEntry::ERROR); |
| 183 EXPECT_EQ(2, e.FailedDownloadCounter()); | 184 EXPECT_EQ(2, e.FailedDownloadCounter()); |
| 184 } | 185 } |
| OLD | NEW |