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)); |
| 43 ReadingListEntry e2(GURL("http://example.com"), "bar", | |
| 44 base::Time::FromTimeT(10)); | |
| 40 ASSERT_EQ(e1, e2); | 45 ASSERT_EQ(e1, e2); |
| 41 ASSERT_EQ(e1.Title(), e2.Title()); | 46 ASSERT_EQ(e1.Title(), e2.Title()); |
| 47 ASSERT_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 ASSERT_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)); |
|
gambard
2017/03/21 13:08:06
Test update time
Olivier
2017/03/21 14:01:09
Done.
Olivier
2017/03/21 14:01:09
Done.
| |
| 54 EXPECT_TRUE(e.HasBeenSeen()); | 62 EXPECT_TRUE(e.HasBeenSeen()); |
| 55 EXPECT_FALSE(e.IsRead()); | 63 EXPECT_FALSE(e.IsRead()); |
| 56 e.SetRead(true); | 64 e.SetRead(true, base::Time::FromTimeT(30)); |
|
gambard
2017/03/21 13:08:06
Test update time
Olivier
2017/03/21 14:01:09
Done.
| |
| 57 EXPECT_TRUE(e.HasBeenSeen()); | 65 EXPECT_TRUE(e.HasBeenSeen()); |
| 58 EXPECT_TRUE(e.IsRead()); | 66 EXPECT_TRUE(e.IsRead()); |
| 59 } | 67 } |
| 60 | 68 |
| 61 TEST(ReadingListEntry, UpdateTitle) { | 69 TEST(ReadingListEntry, UpdateTitle) { |
| 62 ReadingListEntry e(GURL("http://example.com"), "bar"); | 70 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 71 base::Time::FromTimeT(10)); | |
| 63 ASSERT_EQ("bar", e.Title()); | 72 ASSERT_EQ("bar", e.Title()); |
| 64 ASSERT_EQ(e.CreationTime(), e.UpdateTitleTime()); | 73 // Getters are in microseconds. |
|
gambard
2017/03/21 13:08:06
What about creating a kMicrosecondInOneSecond (or
Olivier
2017/03/21 14:01:09
Done.
| |
| 74 ASSERT_EQ(e.CreationTime(), 10000000); | |
| 75 ASSERT_EQ(e.UpdateTitleTime(), 10000000); | |
| 65 | 76 |
| 66 base::test::ios::SpinRunLoopWithMinDelay( | 77 e.SetTitle("foo", base::Time::FromTimeT(15)); |
| 67 base::TimeDelta::FromMilliseconds(5)); | 78 EXPECT_EQ(e.UpdateTitleTime(), 15000000); |
| 68 e.SetTitle("foo"); | |
| 69 EXPECT_GT(e.UpdateTitleTime(), e.CreationTime()); | |
| 70 EXPECT_EQ("foo", e.Title()); | 79 EXPECT_EQ("foo", e.Title()); |
| 71 } | 80 } |
| 72 | 81 |
| 73 TEST(ReadingListEntry, DistilledInfo) { | 82 TEST(ReadingListEntry, DistilledInfo) { |
| 74 ReadingListEntry e(GURL("http://example.com"), "bar"); | 83 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 84 base::Time::FromTimeT(10)); | |
| 75 | 85 |
| 76 EXPECT_TRUE(e.DistilledPath().empty()); | 86 EXPECT_TRUE(e.DistilledPath().empty()); |
| 77 | 87 |
| 78 const base::FilePath distilled_path("distilled/page.html"); | 88 const base::FilePath distilled_path("distilled/page.html"); |
| 79 const GURL distilled_url("http://example.com/distilled"); | 89 const GURL distilled_url("http://example.com/distilled"); |
| 80 int64_t size = 50; | 90 int64_t size = 50; |
| 81 int64_t time = 100; | 91 int64_t time = 100; |
| 82 e.SetDistilledInfo(distilled_path, distilled_url, size, time); | 92 e.SetDistilledInfo(distilled_path, distilled_url, size, |
| 93 base::Time::FromTimeT(time)); | |
| 83 EXPECT_EQ(distilled_path, e.DistilledPath()); | 94 EXPECT_EQ(distilled_path, e.DistilledPath()); |
| 84 EXPECT_EQ(distilled_url, e.DistilledURL()); | 95 EXPECT_EQ(distilled_url, e.DistilledURL()); |
| 85 EXPECT_EQ(size, e.DistillationSize()); | 96 EXPECT_EQ(size, e.DistillationSize()); |
| 86 EXPECT_EQ(e.DistillationTime(), time); | 97 EXPECT_EQ(e.DistillationTime(), time * 1000000); |
| 87 } | 98 } |
| 88 | 99 |
| 89 TEST(ReadingListEntry, DistilledState) { | 100 TEST(ReadingListEntry, DistilledState) { |
| 90 ReadingListEntry e(GURL("http://example.com"), "bar"); | 101 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 102 base::Time::FromTimeT(10)); | |
| 91 | 103 |
| 92 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); | 104 EXPECT_EQ(ReadingListEntry::WAITING, e.DistilledState()); |
| 93 | 105 |
| 94 e.SetDistilledState(ReadingListEntry::ERROR); | 106 e.SetDistilledState(ReadingListEntry::ERROR); |
| 95 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); | 107 EXPECT_EQ(ReadingListEntry::ERROR, e.DistilledState()); |
| 96 | 108 |
| 97 const base::FilePath distilled_path("distilled/page.html"); | 109 const base::FilePath distilled_path("distilled/page.html"); |
| 98 const GURL distilled_url("http://example.com/distilled"); | 110 const GURL distilled_url("http://example.com/distilled"); |
| 99 e.SetDistilledInfo(distilled_path, distilled_url, 50, 100); | 111 e.SetDistilledInfo(distilled_path, distilled_url, 50, |
| 112 base::Time::FromTimeT(100)); | |
| 100 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); | 113 EXPECT_EQ(ReadingListEntry::PROCESSED, e.DistilledState()); |
| 101 } | 114 } |
| 102 | 115 |
| 103 // Tests that the the time until next try increase exponentially when the state | 116 // Tests that the the time until next try increase exponentially when the state |
| 104 // changes from non-error to error. | 117 // changes from non-error to error. |
| 105 TEST(ReadingListEntry, TimeUntilNextTry) { | 118 TEST(ReadingListEntry, TimeUntilNextTry) { |
| 106 base::SimpleTestTickClock clock; | 119 base::SimpleTestTickClock clock; |
| 107 std::unique_ptr<net::BackoffEntry> backoff = | 120 std::unique_ptr<net::BackoffEntry> backoff = |
| 108 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 121 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 109 &clock); | 122 &clock); |
| 110 | 123 |
| 111 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); | 124 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 125 base::Time::FromTimeT(10), std::move(backoff)); | |
| 112 | 126 |
| 113 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 127 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 114 | 128 |
| 115 ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds()); | 129 ASSERT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| 116 | 130 |
| 117 // First error. | 131 // First error. |
| 118 e.SetDistilledState(ReadingListEntry::ERROR); | 132 e.SetDistilledState(ReadingListEntry::ERROR); |
| 119 int nextTry = e.TimeUntilNextTry().InMinutes(); | 133 int nextTry = e.TimeUntilNextTry().InMinutes(); |
| 120 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 134 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
| 121 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 135 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 152 kFifthBackoff * fuzzing); | 166 kFifthBackoff * fuzzing); |
| 153 } | 167 } |
| 154 | 168 |
| 155 // Tests that if the time until next try is in the past, 0 is returned. | 169 // Tests that if the time until next try is in the past, 0 is returned. |
| 156 TEST(ReadingListEntry, TimeUntilNextTryInThePast) { | 170 TEST(ReadingListEntry, TimeUntilNextTryInThePast) { |
| 157 // Setup. | 171 // Setup. |
| 158 base::SimpleTestTickClock clock; | 172 base::SimpleTestTickClock clock; |
| 159 std::unique_ptr<net::BackoffEntry> backoff = | 173 std::unique_ptr<net::BackoffEntry> backoff = |
| 160 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 174 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 161 &clock); | 175 &clock); |
| 162 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); | 176 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 177 base::Time::FromTimeT(10), std::move(backoff)); | |
| 163 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 178 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 164 | 179 |
| 165 e.SetDistilledState(ReadingListEntry::ERROR); | 180 e.SetDistilledState(ReadingListEntry::ERROR); |
| 166 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 181 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 167 kFirstBackoff * fuzzing); | 182 kFirstBackoff * fuzzing); |
| 168 | 183 |
| 169 // Action. | 184 // Action. |
| 170 clock.Advance(base::TimeDelta::FromMinutes(kFirstBackoff * 2)); | 185 clock.Advance(base::TimeDelta::FromMinutes(kFirstBackoff * 2)); |
| 171 | 186 |
| 172 // Test. | 187 // Test. |
| 173 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds()); | 188 EXPECT_EQ(0, e.TimeUntilNextTry().InMilliseconds()); |
| 174 } | 189 } |
| 175 | 190 |
| 176 // Tests that if the entry gets a distilled URL, 0 is returned. | 191 // Tests that if the entry gets a distilled URL, 0 is returned. |
| 177 TEST(ReadingListEntry, ResetTimeUntilNextTry) { | 192 TEST(ReadingListEntry, ResetTimeUntilNextTry) { |
| 178 // Setup. | 193 // Setup. |
| 179 base::SimpleTestTickClock clock; | 194 base::SimpleTestTickClock clock; |
| 180 std::unique_ptr<net::BackoffEntry> backoff = | 195 std::unique_ptr<net::BackoffEntry> backoff = |
| 181 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, | 196 base::MakeUnique<net::BackoffEntry>(&ReadingListEntry::kBackoffPolicy, |
| 182 &clock); | 197 &clock); |
| 183 ReadingListEntry e(GURL("http://example.com"), "bar", std::move(backoff)); | 198 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 199 base::Time::FromTimeT(10), std::move(backoff)); | |
| 184 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 200 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 185 | 201 |
| 186 e.SetDistilledState(ReadingListEntry::ERROR); | 202 e.SetDistilledState(ReadingListEntry::ERROR); |
| 187 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 203 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 188 kFirstBackoff * fuzzing); | 204 kFirstBackoff * fuzzing); |
| 189 | 205 |
| 190 // Action. | 206 // Action. |
| 191 const base::FilePath distilled_path("distilled/page.html"); | 207 const base::FilePath distilled_path("distilled/page.html"); |
| 192 const GURL distilled_url("http://example.com/distilled"); | 208 const GURL distilled_url("http://example.com/distilled"); |
| 193 e.SetDistilledInfo(distilled_path, distilled_url, 50, 100); | 209 e.SetDistilledInfo(distilled_path, distilled_url, 50, |
| 210 base::Time::FromTimeT(100)); | |
| 194 | 211 |
| 195 // Test. | 212 // Test. |
| 196 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); | 213 EXPECT_EQ(0, e.TimeUntilNextTry().InSeconds()); |
| 197 e.SetDistilledState(ReadingListEntry::ERROR); | 214 e.SetDistilledState(ReadingListEntry::ERROR); |
| 198 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), | 215 ASSERT_NEAR(kFirstBackoff, e.TimeUntilNextTry().InMinutes(), |
| 199 kFirstBackoff * fuzzing); | 216 kFirstBackoff * fuzzing); |
| 200 } | 217 } |
| 201 | 218 |
| 202 // Tests that the failed download counter is incremented when the state change | 219 // Tests that the failed download counter is incremented when the state change |
| 203 // from non-error to error. | 220 // from non-error to error. |
| 204 TEST(ReadingListEntry, FailedDownloadCounter) { | 221 TEST(ReadingListEntry, FailedDownloadCounter) { |
| 205 ReadingListEntry e(GURL("http://example.com"), "bar"); | 222 ReadingListEntry e(GURL("http://example.com"), "bar", |
| 223 base::Time::FromTimeT(10)); | |
| 206 | 224 |
| 207 ASSERT_EQ(0, e.FailedDownloadCounter()); | 225 ASSERT_EQ(0, e.FailedDownloadCounter()); |
| 208 | 226 |
| 209 e.SetDistilledState(ReadingListEntry::ERROR); | 227 e.SetDistilledState(ReadingListEntry::ERROR); |
| 210 EXPECT_EQ(1, e.FailedDownloadCounter()); | 228 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 211 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 229 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 212 EXPECT_EQ(1, e.FailedDownloadCounter()); | 230 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 213 | 231 |
| 214 e.SetDistilledState(ReadingListEntry::PROCESSING); | 232 e.SetDistilledState(ReadingListEntry::PROCESSING); |
| 215 EXPECT_EQ(1, e.FailedDownloadCounter()); | 233 EXPECT_EQ(1, e.FailedDownloadCounter()); |
| 216 | 234 |
| 217 e.SetDistilledState(ReadingListEntry::WILL_RETRY); | 235 e.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 218 EXPECT_EQ(2, e.FailedDownloadCounter()); | 236 EXPECT_EQ(2, e.FailedDownloadCounter()); |
| 219 e.SetDistilledState(ReadingListEntry::ERROR); | 237 e.SetDistilledState(ReadingListEntry::ERROR); |
| 220 EXPECT_EQ(2, e.FailedDownloadCounter()); | 238 EXPECT_EQ(2, e.FailedDownloadCounter()); |
| 221 } | 239 } |
| 222 | 240 |
| 223 // Tests that the reading list entry is correctly encoded to | 241 // Tests that the reading list entry is correctly encoded to |
| 224 // sync_pb::ReadingListSpecifics. | 242 // sync_pb::ReadingListSpecifics. |
| 225 TEST(ReadingListEntry, AsReadingListSpecifics) { | 243 TEST(ReadingListEntry, AsReadingListSpecifics) { |
| 226 ReadingListEntry entry(GURL("http://example.com/"), "bar"); | 244 ReadingListEntry entry(GURL("http://example.com"), "bar", |
| 245 base::Time::FromTimeT(10)); | |
| 227 int64_t creation_time_us = entry.UpdateTime(); | 246 int64_t creation_time_us = entry.UpdateTime(); |
| 228 | 247 |
| 229 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry( | 248 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry( |
| 230 entry.AsReadingListSpecifics()); | 249 entry.AsReadingListSpecifics()); |
| 231 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); | 250 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); |
| 232 EXPECT_EQ(pb_entry->url(), "http://example.com/"); | 251 EXPECT_EQ(pb_entry->url(), "http://example.com/"); |
| 233 EXPECT_EQ(pb_entry->title(), "bar"); | 252 EXPECT_EQ(pb_entry->title(), "bar"); |
| 234 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); | 253 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); |
| 235 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); | 254 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); |
| 236 EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNSEEN); | 255 EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNSEEN); |
| 237 | 256 |
| 238 entry.SetRead(true); | 257 entry.SetRead(true, base::Time::FromTimeT(15)); |
| 239 EXPECT_NE(entry.UpdateTime(), creation_time_us); | 258 // Getters are in microseconds. |
| 259 EXPECT_EQ(entry.CreationTime(), 10000000); | |
| 260 EXPECT_EQ(entry.UpdateTime(), 15000000); | |
| 240 std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry( | 261 std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry( |
| 241 entry.AsReadingListSpecifics()); | 262 entry.AsReadingListSpecifics()); |
| 242 EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us); | 263 EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us); |
| 243 EXPECT_EQ(updated_pb_entry->update_time_us(), entry.UpdateTime()); | 264 EXPECT_EQ(updated_pb_entry->update_time_us(), entry.UpdateTime()); |
| 244 EXPECT_EQ(updated_pb_entry->status(), sync_pb::ReadingListSpecifics::READ); | 265 EXPECT_EQ(updated_pb_entry->status(), sync_pb::ReadingListSpecifics::READ); |
| 245 } | 266 } |
| 246 | 267 |
| 247 // Tests that the reading list entry is correctly parsed from | 268 // Tests that the reading list entry is correctly parsed from |
| 248 // sync_pb::ReadingListSpecifics. | 269 // sync_pb::ReadingListSpecifics. |
| 249 TEST(ReadingListEntry, FromReadingListSpecifics) { | 270 TEST(ReadingListEntry, FromReadingListSpecifics) { |
| 250 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry = | 271 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry = |
| 251 base::MakeUnique<sync_pb::ReadingListSpecifics>(); | 272 base::MakeUnique<sync_pb::ReadingListSpecifics>(); |
| 252 pb_entry->set_entry_id("http://example.com/"); | 273 pb_entry->set_entry_id("http://example.com/"); |
| 253 pb_entry->set_url("http://example.com/"); | 274 pb_entry->set_url("http://example.com/"); |
| 254 pb_entry->set_title("title"); | 275 pb_entry->set_title("title"); |
| 255 pb_entry->set_creation_time_us(1); | 276 pb_entry->set_creation_time_us(1); |
| 256 pb_entry->set_update_time_us(2); | 277 pb_entry->set_update_time_us(2); |
| 278 pb_entry->set_update_title_time_us(3); | |
|
gambard
2017/03/21 13:08:07
You are setting it but not checking it.
Same for t
Olivier
2017/03/21 14:01:09
Done.
| |
| 257 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); | 279 pb_entry->set_status(sync_pb::ReadingListSpecifics::UNREAD); |
| 258 | 280 |
| 259 std::unique_ptr<ReadingListEntry> entry( | 281 std::unique_ptr<ReadingListEntry> entry( |
| 260 ReadingListEntry::FromReadingListSpecifics(*pb_entry)); | 282 ReadingListEntry::FromReadingListSpecifics(*pb_entry, |
| 283 base::Time::FromTimeT(10))); | |
|
gambard
2017/03/21 13:08:06
You can test the deserialization value for the bac
Olivier
2017/03/21 14:01:09
There is no serialized backoff in ReadingListSpeci
gambard
2017/03/21 15:36:53
Acknowledged.
| |
| 261 EXPECT_EQ(entry->URL().spec(), "http://example.com/"); | 284 EXPECT_EQ(entry->URL().spec(), "http://example.com/"); |
| 262 EXPECT_EQ(entry->Title(), "title"); | 285 EXPECT_EQ(entry->Title(), "title"); |
| 263 EXPECT_EQ(entry->UpdateTime(), 2); | 286 EXPECT_EQ(entry->UpdateTime(), 2); |
| 264 EXPECT_EQ(entry->FailedDownloadCounter(), 0); | 287 EXPECT_EQ(entry->FailedDownloadCounter(), 0); |
| 265 } | 288 } |
| 266 | 289 |
| 267 // Tests that the reading list entry is correctly encoded to | 290 // Tests that the reading list entry is correctly encoded to |
| 268 // reading_list::ReadingListLocal. | 291 // reading_list::ReadingListLocal. |
| 269 TEST(ReadingListEntry, AsReadingListLocal) { | 292 TEST(ReadingListEntry, AsReadingListLocal) { |
| 270 ReadingListEntry entry(GURL("http://example.com/"), "bar"); | 293 ReadingListEntry entry(GURL("http://example.com/"), "bar", |
| 294 base::Time::FromTimeT(10)); | |
| 271 int64_t creation_time_us = entry.UpdateTime(); | 295 int64_t creation_time_us = entry.UpdateTime(); |
|
gambard
2017/03/21 13:08:06
Maybe you should set a different update time and t
Olivier
2017/03/21 14:01:10
Done.
| |
| 272 | 296 |
| 273 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( | 297 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| 274 entry.AsReadingListLocal()); | 298 entry.AsReadingListLocal(base::Time::Now())); |
|
gambard
2017/03/21 13:08:06
Why base::Time::Now()?
Olivier
2017/03/21 14:01:10
Done.
| |
| 275 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); | 299 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); |
| 276 EXPECT_EQ(pb_entry->url(), "http://example.com/"); | 300 EXPECT_EQ(pb_entry->url(), "http://example.com/"); |
| 277 EXPECT_EQ(pb_entry->title(), "bar"); | 301 EXPECT_EQ(pb_entry->title(), "bar"); |
| 278 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); | 302 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); |
| 279 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); | 303 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); |
| 280 EXPECT_EQ(pb_entry->status(), reading_list::ReadingListLocal::UNSEEN); | 304 EXPECT_EQ(pb_entry->status(), reading_list::ReadingListLocal::UNSEEN); |
| 281 EXPECT_EQ(pb_entry->distillation_state(), | 305 EXPECT_EQ(pb_entry->distillation_state(), |
| 282 reading_list::ReadingListLocal::WAITING); | 306 reading_list::ReadingListLocal::WAITING); |
| 283 EXPECT_EQ(pb_entry->distilled_path(), ""); | 307 EXPECT_EQ(pb_entry->distilled_path(), ""); |
| 284 EXPECT_EQ(pb_entry->failed_download_counter(), 0); | 308 EXPECT_EQ(pb_entry->failed_download_counter(), 0); |
| 285 EXPECT_NE(pb_entry->backoff(), ""); | 309 EXPECT_NE(pb_entry->backoff(), ""); |
| 286 | 310 |
| 287 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); | 311 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 288 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( | 312 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( |
| 289 entry.AsReadingListLocal()); | 313 entry.AsReadingListLocal(base::Time::Now())); |
|
gambard
2017/03/21 13:08:06
Same
Olivier
2017/03/21 14:01:09
Done.
| |
| 290 EXPECT_EQ(will_retry_pb_entry->distillation_state(), | 314 EXPECT_EQ(will_retry_pb_entry->distillation_state(), |
| 291 reading_list::ReadingListLocal::WILL_RETRY); | 315 reading_list::ReadingListLocal::WILL_RETRY); |
| 292 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); | 316 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); |
| 293 | 317 |
| 294 const base::FilePath distilled_path("distilled/page.html"); | 318 const base::FilePath distilled_path("distilled/page.html"); |
| 295 const GURL distilled_url("http://example.com/distilled"); | 319 const GURL distilled_url("http://example.com/distilled"); |
| 296 int64_t size = 50; | 320 int64_t size = 50; |
| 297 entry.SetDistilledInfo(distilled_path, distilled_url, size, 100); | 321 entry.SetDistilledInfo(distilled_path, distilled_url, size, |
| 322 base::Time::FromTimeT(100)); | |
| 298 | 323 |
| 299 entry.SetRead(true); | 324 entry.SetRead(true, base::Time::FromTimeT(20)); |
| 300 entry.MarkEntryUpdated(); | 325 entry.MarkEntryUpdated(base::Time::FromTimeT(30)); |
| 301 EXPECT_NE(entry.UpdateTime(), creation_time_us); | 326 EXPECT_NE(entry.UpdateTime(), creation_time_us); |
| 302 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( | 327 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( |
| 303 entry.AsReadingListLocal()); | 328 entry.AsReadingListLocal(base::Time::Now())); |
|
gambard
2017/03/21 13:08:06
Same
Olivier
2017/03/21 14:01:10
Done.
| |
| 304 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); | 329 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); |
| 305 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); | 330 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); |
| 306 EXPECT_NE(distilled_pb_entry->backoff(), ""); | 331 EXPECT_NE(distilled_pb_entry->backoff(), ""); |
| 307 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); | 332 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); |
| 308 EXPECT_EQ(distilled_pb_entry->distillation_state(), | 333 EXPECT_EQ(distilled_pb_entry->distillation_state(), |
| 309 reading_list::ReadingListLocal::PROCESSED); | 334 reading_list::ReadingListLocal::PROCESSED); |
| 310 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); | 335 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); |
| 311 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); | 336 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); |
| 312 EXPECT_EQ(distilled_pb_entry->distillation_time_us(), | 337 EXPECT_EQ(distilled_pb_entry->distillation_time_us(), |
| 313 entry.DistillationTime()); | 338 entry.DistillationTime()); |
| 314 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize()); | 339 EXPECT_EQ(distilled_pb_entry->distillation_size(), entry.DistillationSize()); |
| 315 } | 340 } |
| 316 | 341 |
| 317 // Tests that the reading list entry is correctly parsed from | 342 // Tests that the reading list entry is correctly parsed from |
| 318 // sync_pb::ReadingListLocal. | 343 // sync_pb::ReadingListLocal. |
| 319 TEST(ReadingListEntry, FromReadingListLocal) { | 344 TEST(ReadingListEntry, FromReadingListLocal) { |
| 320 ReadingListEntry entry(GURL("http://example.com/"), "title"); | 345 ReadingListEntry entry(GURL("http://example.com/"), "title", |
| 346 base::Time::FromTimeT(10)); | |
| 321 entry.SetDistilledState(ReadingListEntry::ERROR); | 347 entry.SetDistilledState(ReadingListEntry::ERROR); |
| 322 | 348 |
| 323 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( | 349 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| 324 entry.AsReadingListLocal()); | 350 entry.AsReadingListLocal(base::Time::FromTimeT(10))); |
| 325 int64_t now = 12345; | 351 int64_t now = 12345; |
| 326 | 352 |
| 327 pb_entry->set_entry_id("http://example.com/"); | 353 pb_entry->set_entry_id("http://example.com/"); |
| 328 pb_entry->set_url("http://example.com/"); | 354 pb_entry->set_url("http://example.com/"); |
| 329 pb_entry->set_title("title"); | 355 pb_entry->set_title("title"); |
| 330 pb_entry->set_creation_time_us(1); | 356 pb_entry->set_creation_time_us(1); |
| 331 pb_entry->set_update_time_us(2); | 357 pb_entry->set_update_time_us(2); |
|
gambard
2017/03/21 13:08:07
Can you add the title update time?
Olivier
2017/03/21 14:01:09
Done.
| |
| 332 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); | 358 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); |
| 333 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); | 359 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); |
| 334 pb_entry->set_failed_download_counter(2); | 360 pb_entry->set_failed_download_counter(2); |
| 335 pb_entry->set_distillation_time_us(now); | 361 pb_entry->set_distillation_time_us(now); |
| 336 pb_entry->set_distillation_size(50); | 362 pb_entry->set_distillation_size(50); |
| 337 | 363 |
| 338 std::unique_ptr<ReadingListEntry> waiting_entry( | 364 std::unique_ptr<ReadingListEntry> waiting_entry( |
| 339 ReadingListEntry::FromReadingListLocal(*pb_entry)); | 365 ReadingListEntry::FromReadingListLocal(*pb_entry, |
| 366 base::Time::FromTimeT(20))); | |
| 340 EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/"); | 367 EXPECT_EQ(waiting_entry->URL().spec(), "http://example.com/"); |
| 341 EXPECT_EQ(waiting_entry->Title(), "title"); | 368 EXPECT_EQ(waiting_entry->Title(), "title"); |
| 342 EXPECT_EQ(waiting_entry->UpdateTime(), 2); | 369 EXPECT_EQ(waiting_entry->UpdateTime(), 2); |
| 343 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); | 370 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); |
| 344 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); | 371 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); |
| 345 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); | 372 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); |
| 346 EXPECT_EQ(waiting_entry->DistillationSize(), 50); | 373 EXPECT_EQ(waiting_entry->DistillationSize(), 50); |
| 347 EXPECT_EQ(waiting_entry->DistillationTime(), now); | 374 EXPECT_EQ(waiting_entry->DistillationTime(), now); |
| 348 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 375 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 349 int nextTry = waiting_entry->TimeUntilNextTry().InMinutes(); | 376 int nextTry = waiting_entry->TimeUntilNextTry().InMinutes(); |
| 350 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 377 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
| 351 } | 378 } |
| 352 | 379 |
| 353 // Tests the merging of two ReadingListEntry. | 380 // Tests the merging of two ReadingListEntry. |
| 354 // Additional merging tests are done in | 381 // Additional merging tests are done in |
| 355 // ReadingListStoreTest.CompareEntriesForSync | 382 // ReadingListStoreTest.CompareEntriesForSync |
| 356 TEST(ReadingListEntry, MergeWithEntry) { | 383 TEST(ReadingListEntry, MergeWithEntry) { |
| 357 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); | 384 ReadingListEntry local_entry(GURL("http://example.com/"), "title", |
| 385 base::Time::FromTimeT(10)); | |
| 358 local_entry.SetDistilledState(ReadingListEntry::ERROR); | 386 local_entry.SetDistilledState(ReadingListEntry::ERROR); |
| 359 int64_t local_update_time_us = local_entry.UpdateTime(); | 387 int64_t local_update_time_us = local_entry.UpdateTime(); |
| 360 | 388 |
| 361 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); | 389 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2", |
| 390 base::Time::FromTimeT(20)); | |
| 362 sync_entry.SetDistilledState(ReadingListEntry::ERROR); | 391 sync_entry.SetDistilledState(ReadingListEntry::ERROR); |
| 363 int64_t sync_update_time_us = sync_entry.UpdateTime(); | 392 int64_t sync_update_time_us = sync_entry.UpdateTime(); |
| 364 EXPECT_NE(local_update_time_us, sync_update_time_us); | 393 EXPECT_NE(local_update_time_us, sync_update_time_us); |
| 365 local_entry.MergeWithEntry(sync_entry); | 394 local_entry.MergeWithEntry(sync_entry); |
| 366 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); | 395 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); |
| 367 EXPECT_EQ(local_entry.Title(), "title2"); | 396 EXPECT_EQ(local_entry.Title(), "title2"); |
| 368 EXPECT_FALSE(local_entry.HasBeenSeen()); | 397 EXPECT_FALSE(local_entry.HasBeenSeen()); |
| 369 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); | 398 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); |
|
gambard
2017/03/21 13:08:06
Maybe add a title update test? :)
Olivier
2017/03/21 14:01:09
Done.
| |
| 370 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); | 399 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); |
| 371 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); | 400 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); |
| 372 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; | 401 double fuzzing = ReadingListEntry::kBackoffPolicy.jitter_factor; |
| 373 int nextTry = local_entry.TimeUntilNextTry().InMinutes(); | 402 int nextTry = local_entry.TimeUntilNextTry().InMinutes(); |
| 374 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); | 403 EXPECT_NEAR(kFirstBackoff, nextTry, kFirstBackoff * fuzzing); |
| 375 } | 404 } |
| OLD | NEW |