Chromium Code Reviews| 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" | |
| 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(), 20 * 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 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 114 | 134 |
| 115 ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds()); | 135 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| 116 | 136 |
| 117 // First error. | 137 // First error. |
| 118 e.SetDistilledState(ReadingListEntry::ERROR); | 138 e.SetDistilledState(ReadingListEntry::ERROR); |
| 119 int nextTry = e.TimeUntilNextTry().InMinutes(); | 139 int nextTry = e.TimeUntilNextTry().InMinutes(); |
| 120 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 140 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
| 121 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 141 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 122 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); | 142 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); |
| 123 | 143 |
| 124 e.SetDistilledState(ReadingListEntry::PROCESSING); | 144 e.SetDistilledState(ReadingListEntry::PROCESSING); |
| 125 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); | 145 EXPECT_EQ(nextTry, e.TimeUntilNextTry().InMinutes()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 152 kFifthBackoff * fuzzing); | 172 kFifthBackoff * fuzzing); |
| 153 } | 173 } |
| 154 | 174 |
| 155 // Tests that if the time until next try is in the past, 0 is returned. | 175 // Tests that if the time until next try is in the past, 0 is returned. |
| 156 TEST(ReadingListEntry, TimeUntilNextTryInThePast) { | 176 TEST(ReadingListEntry, TimeUntilNextTryInThePast) { |
| 157 // Setup. | 177 // Setup. |
| 158 base::SimpleTestTickClock clock; | 178 base::SimpleTestTickClock clock; |
| 159 std::unique_ptr<net::BackoffEntry> backoff = | 179 std::unique_ptr<net::BackoffEntry> backoff = |
| 160 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 180 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 161 &clock); | 181 &clock); |
| 162 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); | 182 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 183 base::Time::FromTimeT(10), std::move(backoff)); | |
| 163 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 184 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 164 | 185 |
| 165 e.SetDistilledState(ReadingListEntry::ERROR); | 186 e.SetDistilledState(ReadingListEntry::ERROR); |
| 166 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 187 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 167 kFirstBackoff * fuzzing); | 188 kFirstBackoff * fuzzing); |
| 168 | 189 |
| 169 // Action. | 190 // Action. |
| 170 clock.Advance(base::TimeDelta::FromMinutes(kFirstBackoff * 2)); | 191 clock.Advance(base::TimeDelta::FromMinutes(kFirstBackoff * 2)); |
| 171 | 192 |
| 172 // Test. | 193 // Test. |
| 173 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds()); | 194 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds()); |
| 174 } | 195 } |
| 175 | 196 |
| 176 // Tests that if the entry gets a distilled URL, 0 is returned. | 197 // Tests that if the entry gets a distilled URL, 0 is returned. |
| 177 TEST(ReadingListEntry, ResetTimeUntilNextTry) { | 198 TEST(ReadingListEntry, ResetTimeUntilNextTry) { |
| 178 // Setup. | 199 // Setup. |
| 179 base::SimpleTestTickClock clock; | 200 base::SimpleTestTickClock clock; |
| 180 std::unique_ptr<net::BackoffEntry> backoff = | 201 std::unique_ptr<net::BackoffEntry> backoff = |
| 181 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 202 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 182 &clock); | 203 &clock); |
| 183 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); | 204 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 205 base::Time::FromTimeT(10), std::move(backoff)); | |
| 184 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 206 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 185 | 207 |
| 186 e.SetDistilledState(ReadingListEntry::ERROR); | 208 e.SetDistilledState(ReadingListEntry::ERROR); |
| 187 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 209 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 188 kFirstBackoff * fuzzing); | 210 kFirstBackoff * fuzzing); |
| 189 | 211 |
| 190 // Action. | 212 // Action. |
| 191 const base::FilePath distilled_path("distilled/page.html"); | 213 const base::FilePath distilled_path("distilled/page.html"); |
| 192 const GURL distilled_url("http://example.com/distilled"); | 214 const GURL distilled_url("http://example.com/distilled"); |
| 193 e.SetDistilledInfo(distilled_path, distilled_url, 50, 100); | 215 e.SetDistilledInfo(distilled_path, distilled_url, 50, |
| 216 base::Time::FromTimeT(100)); | |
| 194 | 217 |
| 195 // Test. | 218 // Test. |
| 196 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); | 219 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| 197 e.SetDistilledState(ReadingListEntry::ERROR); | 220 e.SetDistilledState(ReadingListEntry::ERROR); |
| 198 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 221 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 199 kFirstBackoff * fuzzing); | 222 kFirstBackoff * fuzzing); |
| 200 } | 223 } |
| 201 | 224 |
| 202 // Tests that the failed download counter is incremented when the state change | 225 // Tests that the failed download counter is incremented when the state change |
| 203 // from non-error to error. | 226 // from non-error to error. |
| 204 TEST(ReadingListEntry, FailedDownloadCounter) { | 227 TEST(ReadingListEntry, FailedDownloadCounter) { |
| 205 ReadingListEntry e(GURL("http://example.com"), "bar"); | 228 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 229 base::Time::FromTimeT(10)); | |
| 206 | 230 |
| 207 ASSERT_EQ(0, e.FailedDownloadCounter()); | 231 EXPECT_EQ(0, e.FailedDownloadCounter()); |
| 208 | 232 |
| 209 e.SetDistilledState(ReadingListEntry::ERROR); | 233 e.SetDistilledState(ReadingListEntry::ERROR); |
| 210 EXPECT_EQ(1, e.FailedDownloadCounter()); | 234 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 211 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 235 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 212 EXPECT_EQ(1, e.FailedDownloadCounter()); | 236 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 213 | 237 |
| 214 e.SetDistilledState(ReadingListEntry::PROCESSING); | 238 e.SetDistilledState(ReadingListEntry::PROCESSING); |
| 215 EXPECT_EQ(1, e.FailedDownloadCounter()); | 239 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 216 | 240 |
| 217 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 241 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 218 EXPECT_EQ(2, e.FailedDownloadCounter()); | 242 EXPECT_EQ(2, e.FailedDownloadCounter()); |
| 219 e.SetDistilledState(ReadingListEntry::ERROR); | 243 e.SetDistilledState(ReadingListEntry::ERROR); |
| 220 EXPECT_EQ(2, e.FailedDownloadCounter()); | 244 EXPECT_EQ(2, e.FailedDownloadCounter()); |
| 221 } | 245 } |
| 222 | 246 |
| 223 // Tests that the reading list entry is correctly encoded to | 247 // Tests that the reading list entry is correctly encoded to |
| 224 // sync_pb::ReadingListSpecifics. | 248 // sync_pb::ReadingListSpecifics. |
| 225 TEST(ReadingListEntry, AsReadingListSpecifics) { | 249 TEST(ReadingListEntry, AsReadingListSpecifics) { |
| 226 ReadingListEntry entry(GURL("http://example.com/"), "bar"); | 250 ReadingListEntry entry(GURL("http://example.com"), "bar", |
| 251 base::Time::FromTimeT(10)); | |
| 227 int64_t creation_time_us = entry.UpdateTime(); | 252 int64_t creation_time_us = entry.UpdateTime(); |
| 228 | 253 |
| 229 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry( | 254 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry( |
| 230 entry.AsReadingListSpecifics()); | 255 entry.AsReadingListSpecifics()); |
| 231 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); | 256 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); |
| 232 EXPECT_EQ(pb_entry->url(), "http://example.com/"); | 257 EXPECT_EQ(pb_entry->url(), "http://example.com/"); |
| 233 EXPECT_EQ(pb_entry->title(), "bar"); | 258 EXPECT_EQ(pb_entry->title(), "bar"); |
| 234 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); | 259 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); |
| 235 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); | 260 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); |
| 236 EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNSEEN); | 261 EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNSEEN); |
| 237 | 262 |
| 238 entry.SetRead(true); | 263 entry.SetRead(true, base::Time::FromTimeT(15)); |
| 239 EXPECT_NE(entry.UpdateTime(), creation_time_us); | 264 // Getters are in microseconds. |
| 265 EXPECT_EQ(entry.CreationTime(), 10 * base::Time::kMicrosecondsPerSecond); | |
| 266 EXPECT_EQ(entry.UpdateTime(), 15 * base::Time::kMicrosecondsPerSecond); | |
| 240 std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry( | 267 std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry( |
| 241 entry.AsReadingListSpecifics()); | 268 entry.AsReadingListSpecifics()); |
| 242 EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us); | 269 EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us); |
| 243 EXPECT_EQ(updated_pb_entry->update_time_us(), entry.UpdateTime()); | 270 EXPECT_EQ(updated_pb_entry->update_time_us(), entry.UpdateTime()); |
| 244 EXPECT_EQ(updated_pb_entry->status(), sync_pb::ReadingListSpecifics::READ); | 271 EXPECT_EQ(updated_pb_entry->status(), sync_pb::ReadingListSpecifics::READ); |
| 245 } | 272 } |
| 246 | 273 |
| 247 // Tests that the reading list entry is correctly parsed from | 274 // Tests that the reading list entry is correctly parsed from |
| 248 // sync_pb::ReadingListSpecifics. | 275 // sync_pb::ReadingListSpecifics. |
| 249 TEST(ReadingListEntry, FromReadingListSpecifics) { | 276 TEST(ReadingListEntry, FromReadingListSpecifics) { |
| 250 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry = | 277 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry = |
| 251 base::MakeUnique<sync_pb::ReadingListSpecifics>(); | 278 base::MakeUnique<sync_pb::ReadingListSpecifics>(); |
| 252 pb_entry->set_entry_id("http://example.com/"); | 279 pb_entry->set_entry_id("http://example.com/"); |
| 253 pb_entry->set_url("http://example.com/"); | 280 pb_entry->set_url("http://example.com/"); |
| 254 pb_entry->set_title("title"); | 281 pb_entry->set_title("title"); |
| 255 pb_entry->set_creation_time_us(1); | 282 pb_entry->set_creation_time_us(1); |
|
gambard
2017/03/21 15:36:53
You are still not checking the creation time?
Olivier
2017/03/21 17:22:47
Done, thanks
| |
| 256 pb_entry->set_update_time_us(2); | 283 pb_entry->set_update_time_us(2); |
| 284 pb_entry->set_update_title_time_us(3); | |
| 257 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); | 285 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); |
| 258 | 286 |
| 259 std::unique_ptr<ReadingListEntry> entry( | 287 std::unique_ptr<ReadingListEntry> entry( |
| 260 ReadingListEntry::FromReadingListSpecifics(*pb_entry)); | 288 ReadingListEntry::FromReadingListSpecifics(*pb_entry, |
| 289 base::Time::FromTimeT(10))); | |
| 261 EXPECT_EQ(entry->URL().spec(), "http://example.com/"); | 290 EXPECT_EQ(entry->URL().spec(), "http://example.com/"); |
| 262 EXPECT_EQ(entry->Title(), "title"); | 291 EXPECT_EQ(entry->Title(), "title"); |
| 263 EXPECT_EQ(entry->UpdateTime(), 2); | 292 EXPECT_EQ(entry->UpdateTime(), 2); |
| 293 EXPECT_EQ(entry->UpdateTitleTime(), 3); | |
| 264 EXPECT_EQ(entry->FailedDownloadCounter(), 0); | 294 EXPECT_EQ(entry->FailedDownloadCounter(), 0); |
| 265 } | 295 } |
| 266 | 296 |
| 267 // Tests that the reading list entry is correctly encoded to | 297 // Tests that the reading list entry is correctly encoded to |
| 268 // reading_list::ReadingListLocal. | 298 // reading_list::ReadingListLocal. |
| 269 TEST(ReadingListEntry, AsReadingListLocal) { | 299 TEST(ReadingListEntry, AsReadingListLocal) { |
| 270 ReadingListEntry entry(GURL("http://example.com/"), "bar"); | 300 ReadingListEntry entry(GURL("http://example.com/"), "foo", |
| 301 base::Time::FromTimeT(10)); | |
| 271 int64_t creation_time_us = entry.UpdateTime(); | 302 int64_t creation_time_us = entry.UpdateTime(); |
| 303 entry.SetTitle("bar", base::Time::FromTimeT(20)); | |
| 304 entry.MarkEntryUpdated(base::Time::FromTimeT(30)); | |
| 272 | 305 |
| 273 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( | 306 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| 274 entry.AsReadingListLocal()); | 307 entry.AsReadingListLocal(base::Time::FromTimeT(40))); |
| 275 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); | 308 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); |
| 276 EXPECT_EQ(pb_entry->url(), "http://example.com/"); | 309 EXPECT_EQ(pb_entry->url(), "http://example.com/"); |
| 277 EXPECT_EQ(pb_entry->title(), "bar"); | 310 EXPECT_EQ(pb_entry->title(), "bar"); |
| 278 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); | 311 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); |
| 279 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); | 312 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); |
| 280 EXPECT_EQ(pb_entry->status(), reading_list::ReadingListLocal::UNSEEN); | 313 EXPECT_EQ(pb_entry->status(), reading_list::ReadingListLocal::UNSEEN); |
| 281 EXPECT_EQ(pb_entry->distillation_state(), | 314 EXPECT_EQ(pb_entry->distillation_state(), |
| 282 reading_list::ReadingListLocal::WAITING); | 315 reading_list::ReadingListLocal::WAITING); |
| 283 EXPECT_EQ(pb_entry->distilled_path(), ""); | 316 EXPECT_EQ(pb_entry->distilled_path(), ""); |
| 284 EXPECT_EQ(pb_entry->failed_download_counter(), 0); | 317 EXPECT_EQ(pb_entry->failed_download_counter(), 0); |
| 285 EXPECT_NE(pb_entry->backoff(), ""); | 318 EXPECT_NE(pb_entry->backoff(), ""); |
| 286 | 319 |
| 287 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); | 320 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 288 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( | 321 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( |
| 289 entry.AsReadingListLocal()); | 322 entry.AsReadingListLocal(base::Time::FromTimeT(50))); |
| 290 EXPECT_EQ(will_retry_pb_entry->distillation_state(), | 323 EXPECT_EQ(will_retry_pb_entry->distillation_state(), |
| 291 reading_list::ReadingListLocal::WILL_RETRY); | 324 reading_list::ReadingListLocal::WILL_RETRY); |
| 292 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); | 325 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); |
| 293 | 326 |
| 294 const base::FilePath distilled_path("distilled/page.html"); | 327 const base::FilePath distilled_path("distilled/page.html"); |
| 295 const GURL distilled_url("http://example.com/distilled"); | 328 const GURL distilled_url("http://example.com/distilled"); |
| 296 int64_t size = 50; | 329 int64_t size = 50; |
| 297 entry.SetDistilledInfo(distilled_path, distilled_url, size, 100); | 330 entry.SetDistilledInfo(distilled_path, distilled_url, size, |
| 331 base::Time::FromTimeT(100)); | |
| 298 | 332 |
| 299 entry.SetRead(true); | 333 entry.SetRead(true, base::Time::FromTimeT(20)); |
| 300 entry.MarkEntryUpdated(); | 334 entry.MarkEntryUpdated(base::Time::FromTimeT(30)); |
| 301 EXPECT_NE(entry.UpdateTime(), creation_time_us); | 335 EXPECT_NE(entry.UpdateTime(), creation_time_us); |
| 302 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( | 336 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( |
| 303 entry.AsReadingListLocal()); | 337 entry.AsReadingListLocal(base::Time::FromTimeT(40))); |
| 304 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); | 338 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); |
| 305 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); | 339 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); |
| 306 EXPECT_NE(distilled_pb_entry->backoff(), ""); | 340 EXPECT_NE(distilled_pb_entry->backoff(), ""); |
| 307 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); | 341 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); |
| 308 EXPECT_EQ(distilled_pb_entry->distillation_state(), | 342 EXPECT_EQ(distilled_pb_entry->distillation_state(), |
| 309 reading_list::ReadingListLocal::PROCESSED); | 343 reading_list::ReadingListLocal::PROCESSED); |
| 310 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); | 344 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); |
| 311 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); | 345 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); |
| 312 EXPECT_EQ(distilled_pb_entry->distillation_time_us(), | 346 EXPECT_EQ(distilled_pb_entry->distillation_time_us(), |
| 313 entry.DistillationTime()); | 347 entry.DistillationTime()); |
| 314 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize()); | 348 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize()); |
| 315 } | 349 } |
| 316 | 350 |
| 317 // Tests that the reading list entry is correctly parsed from | 351 // Tests that the reading list entry is correctly parsed from |
| 318 // sync_pb::ReadingListLocal. | 352 // sync_pb::ReadingListLocal. |
| 319 TEST(ReadingListEntry, FromReadingListLocal) { | 353 TEST(ReadingListEntry, FromReadingListLocal) { |
| 320 ReadingListEntry entry(GURL("http://example.com/"), "title"); | 354 ReadingListEntry entry(GURL("http://example.com/"), "title", |
| 355 base::Time::FromTimeT(10)); | |
| 321 entry.SetDistilledState(ReadingListEntry::ERROR); | 356 entry.SetDistilledState(ReadingListEntry::ERROR); |
| 322 | 357 |
| 323 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( | 358 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| 324 entry.AsReadingListLocal()); | 359 entry.AsReadingListLocal(base::Time::FromTimeT(10))); |
| 325 int64_t now = 12345; | 360 int64_t now = 12345; |
| 326 | 361 |
| 327 pb_entry->set_entry_id("http://example.com/"); | 362 pb_entry->set_entry_id("http://example.com/"); |
| 328 pb_entry->set_url("http://example.com/"); | 363 pb_entry->set_url("http://example.com/"); |
| 329 pb_entry->set_title("title"); | 364 pb_entry->set_title("title"); |
| 330 pb_entry->set_creation_time_us(1); | 365 pb_entry->set_creation_time_us(1); |
| 331 pb_entry->set_update_time_us(2); | 366 pb_entry->set_update_time_us(2); |
| 367 pb_entry->set_update_title_time_us(3); | |
| 332 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); | 368 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); |
| 333 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); | 369 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); |
| 334 pb_entry->set_failed_download_counter(2); | 370 pb_entry->set_failed_download_counter(2); |
| 335 pb_entry->set_distillation_time_us(now); | 371 pb_entry->set_distillation_time_us(now); |
| 336 pb_entry->set_distillation_size(50); | 372 pb_entry->set_distillation_size(50); |
| 337 | 373 |
| 338 std::unique_ptr<ReadingListEntry> waiting_entry( | 374 std::unique_ptr<ReadingListEntry> waiting_entry( |
| 339 ReadingListEntry::FromReadingListLocal(*pb_entry)); | 375 ReadingListEntry::FromReadingListLocal(*pb_entry, |
| 376 base::Time::FromTimeT(20))); | |
| 340 EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/"); | 377 EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/"); |
| 341 EXPECT_EQ(waiting_entry->Title(), "title"); | 378 EXPECT_EQ(waiting_entry->Title(), "title"); |
| 342 EXPECT_EQ(waiting_entry->UpdateTime(), 2); | 379 EXPECT_EQ(waiting_entry->UpdateTime(), 2); |
| 380 EXPECT_EQ(waiting_entry->UpdateTitleTime(), 3); | |
| 343 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); | 381 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); |
| 344 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); | 382 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); |
| 345 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); | 383 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); |
| 346 EXPECT_EQ(waiting_entry->DistillationSize(), 50); | 384 EXPECT_EQ(waiting_entry->DistillationSize(), 50); |
| 347 EXPECT_EQ(waiting_entry->DistillationTime(), now); | 385 EXPECT_EQ(waiting_entry->DistillationTime(), now); |
| 348 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 386 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 349 int nextTry = waiting_entry->TimeUntilNextTry().InMinutes(); | 387 int nextTry = waiting_entry->TimeUntilNextTry().InMinutes(); |
| 350 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 388 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
| 351 } | 389 } |
| 352 | 390 |
| 353 // Tests the merging of two ReadingListEntry. | 391 // Tests the merging of two ReadingListEntry. |
| 354 // Additional merging tests are done in | 392 // Additional merging tests are done in |
| 355 // ReadingListStoreTest.CompareEntriesForSync | 393 // ReadingListStoreTest.CompareEntriesForSync |
| 356 TEST(ReadingListEntry, MergeWithEntry) { | 394 TEST(ReadingListEntry, MergeWithEntry) { |
| 357 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); | 395 ReadingListEntry local_entry(GURL("http://example.com/"), "title", |
| 396 base::Time::FromTimeT(10)); | |
| 358 local_entry.SetDistilledState(ReadingListEntry::ERROR); | 397 local_entry.SetDistilledState(ReadingListEntry::ERROR); |
| 398 local_entry.SetTitle("title updated", base::Time::FromTimeT(30)); | |
| 359 int64_t local_update_time_us = local_entry.UpdateTime(); | 399 int64_t local_update_time_us = local_entry.UpdateTime(); |
| 360 | 400 |
| 361 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); | 401 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2", |
| 402 base::Time::FromTimeT(20)); | |
| 362 sync_entry.SetDistilledState(ReadingListEntry::ERROR); | 403 sync_entry.SetDistilledState(ReadingListEntry::ERROR); |
| 363 int64_t sync_update_time_us = sync_entry.UpdateTime(); | 404 int64_t sync_update_time_us = sync_entry.UpdateTime(); |
| 364 EXPECT_NE(local_update_time_us, sync_update_time_us); | 405 EXPECT_NE(local_update_time_us, sync_update_time_us); |
| 365 local_entry.MergeWithEntry(sync_entry); | 406 local_entry.MergeWithEntry(sync_entry); |
| 366 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); | 407 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); |
| 367 EXPECT_EQ(local_entry.Title(), "title2"); | 408 EXPECT_EQ(local_entry.Title(), "title updated"); |
| 409 EXPECT_EQ(local_entry.UpdateTitleTime(), | |
| 410 30 * base::Time::kMicrosecondsPerSecond); | |
| 368 EXPECT_FALSE(local_entry.HasBeenSeen()); | 411 EXPECT_FALSE(local_entry.HasBeenSeen()); |
| 369 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); | 412 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); |
| 370 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); | 413 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); |
| 371 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); | 414 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); |
| 372 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 415 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 373 int nextTry = local_entry.TimeUntilNextTry().InMinutes(); | 416 int nextTry = local_entry.TimeUntilNextTry().InMinutes(); |
| 374 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 417 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
| 375 } | 418 } |
| OLD | NEW |