| 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 "components/sync/protocol/reading_list_specifics.pb.h" | 9 #include "components/sync/protocol/reading_list_specifics.pb.h" |
| 10 #include "ios/chrome/browser/reading_list/proto/reading_list.pb.h" | 10 #include "ios/chrome/browser/reading_list/proto/reading_list.pb.h" |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 EXPECT_EQ(2, e.FailedDownloadCounter()); | 186 EXPECT_EQ(2, e.FailedDownloadCounter()); |
| 187 } | 187 } |
| 188 | 188 |
| 189 // Tests that the reading list entry is correctly encoded to | 189 // Tests that the reading list entry is correctly encoded to |
| 190 // sync_pb::ReadingListSpecifics. | 190 // sync_pb::ReadingListSpecifics. |
| 191 TEST(ReadingListEntry, AsReadingListSpecifics) { | 191 TEST(ReadingListEntry, AsReadingListSpecifics) { |
| 192 ReadingListEntry entry(GURL("http://example.com/"), "bar"); | 192 ReadingListEntry entry(GURL("http://example.com/"), "bar"); |
| 193 int64_t creation_time_us = entry.UpdateTime(); | 193 int64_t creation_time_us = entry.UpdateTime(); |
| 194 | 194 |
| 195 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry( | 195 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry( |
| 196 entry.AsReadingListSpecifics(false)); | 196 entry.AsReadingListSpecifics()); |
| 197 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); | 197 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); |
| 198 EXPECT_EQ(pb_entry->url(), "http://example.com/"); | 198 EXPECT_EQ(pb_entry->url(), "http://example.com/"); |
| 199 EXPECT_EQ(pb_entry->title(), "bar"); | 199 EXPECT_EQ(pb_entry->title(), "bar"); |
| 200 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); | 200 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); |
| 201 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); | 201 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); |
| 202 EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNREAD); | 202 EXPECT_EQ(pb_entry->status(), sync_pb::ReadingListSpecifics::UNREAD); |
| 203 | 203 |
| 204 entry.MarkEntryUpdated(); | 204 entry.SetRead(true); |
| 205 EXPECT_NE(entry.UpdateTime(), creation_time_us); | 205 EXPECT_NE(entry.UpdateTime(), creation_time_us); |
| 206 std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry( | 206 std::unique_ptr<sync_pb::ReadingListSpecifics> updated_pb_entry( |
| 207 entry.AsReadingListSpecifics(true)); | 207 entry.AsReadingListSpecifics()); |
| 208 EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us); | 208 EXPECT_EQ(updated_pb_entry->creation_time_us(), creation_time_us); |
| 209 EXPECT_EQ(updated_pb_entry->update_time_us(), entry.UpdateTime()); | 209 EXPECT_EQ(updated_pb_entry->update_time_us(), entry.UpdateTime()); |
| 210 EXPECT_EQ(updated_pb_entry->status(), sync_pb::ReadingListSpecifics::READ); | 210 EXPECT_EQ(updated_pb_entry->status(), sync_pb::ReadingListSpecifics::READ); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Tests that the reading list entry is correctly parsed from | 213 // Tests that the reading list entry is correctly parsed from |
| 214 // sync_pb::ReadingListSpecifics. | 214 // sync_pb::ReadingListSpecifics. |
| 215 TEST(ReadingListEntry, FromReadingListSpecifics) { | 215 TEST(ReadingListEntry, FromReadingListSpecifics) { |
| 216 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry = | 216 std::unique_ptr<sync_pb::ReadingListSpecifics> pb_entry = |
| 217 base::MakeUnique<sync_pb::ReadingListSpecifics>(); | 217 base::MakeUnique<sync_pb::ReadingListSpecifics>(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 230 EXPECT_EQ(entry->FailedDownloadCounter(), 0); | 230 EXPECT_EQ(entry->FailedDownloadCounter(), 0); |
| 231 } | 231 } |
| 232 | 232 |
| 233 // Tests that the reading list entry is correctly encoded to | 233 // Tests that the reading list entry is correctly encoded to |
| 234 // reading_list::ReadingListLocal. | 234 // reading_list::ReadingListLocal. |
| 235 TEST(ReadingListEntry, AsReadingListLocal) { | 235 TEST(ReadingListEntry, AsReadingListLocal) { |
| 236 ReadingListEntry entry(GURL("http://example.com/"), "bar"); | 236 ReadingListEntry entry(GURL("http://example.com/"), "bar"); |
| 237 int64_t creation_time_us = entry.UpdateTime(); | 237 int64_t creation_time_us = entry.UpdateTime(); |
| 238 | 238 |
| 239 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( | 239 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| 240 entry.AsReadingListLocal(false)); | 240 entry.AsReadingListLocal()); |
| 241 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); | 241 EXPECT_EQ(pb_entry->entry_id(), "http://example.com/"); |
| 242 EXPECT_EQ(pb_entry->url(), "http://example.com/"); | 242 EXPECT_EQ(pb_entry->url(), "http://example.com/"); |
| 243 EXPECT_EQ(pb_entry->title(), "bar"); | 243 EXPECT_EQ(pb_entry->title(), "bar"); |
| 244 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); | 244 EXPECT_EQ(pb_entry->creation_time_us(), creation_time_us); |
| 245 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); | 245 EXPECT_EQ(pb_entry->update_time_us(), entry.UpdateTime()); |
| 246 EXPECT_EQ(pb_entry->status(), reading_list::ReadingListLocal::UNREAD); | 246 EXPECT_EQ(pb_entry->status(), reading_list::ReadingListLocal::UNREAD); |
| 247 EXPECT_EQ(pb_entry->distillation_state(), | 247 EXPECT_EQ(pb_entry->distillation_state(), |
| 248 reading_list::ReadingListLocal::WAITING); | 248 reading_list::ReadingListLocal::WAITING); |
| 249 EXPECT_EQ(pb_entry->distilled_path(), ""); | 249 EXPECT_EQ(pb_entry->distilled_path(), ""); |
| 250 EXPECT_EQ(pb_entry->failed_download_counter(), 0); | 250 EXPECT_EQ(pb_entry->failed_download_counter(), 0); |
| 251 EXPECT_NE(pb_entry->backoff(), ""); | 251 EXPECT_NE(pb_entry->backoff(), ""); |
| 252 | 252 |
| 253 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); | 253 entry.SetDistilledState(ReadingListEntry::WILL_RETRY); |
| 254 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( | 254 std::unique_ptr<reading_list::ReadingListLocal> will_retry_pb_entry( |
| 255 entry.AsReadingListLocal(true)); | 255 entry.AsReadingListLocal()); |
| 256 EXPECT_EQ(will_retry_pb_entry->distillation_state(), | 256 EXPECT_EQ(will_retry_pb_entry->distillation_state(), |
| 257 reading_list::ReadingListLocal::WILL_RETRY); | 257 reading_list::ReadingListLocal::WILL_RETRY); |
| 258 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); | 258 EXPECT_EQ(will_retry_pb_entry->failed_download_counter(), 1); |
| 259 | 259 |
| 260 entry.SetDistilledPath(base::FilePath("distilled/page.html")); | 260 entry.SetDistilledPath(base::FilePath("distilled/page.html")); |
| 261 entry.SetRead(true); |
| 261 entry.MarkEntryUpdated(); | 262 entry.MarkEntryUpdated(); |
| 262 EXPECT_NE(entry.UpdateTime(), creation_time_us); | 263 EXPECT_NE(entry.UpdateTime(), creation_time_us); |
| 263 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( | 264 std::unique_ptr<reading_list::ReadingListLocal> distilled_pb_entry( |
| 264 entry.AsReadingListLocal(true)); | 265 entry.AsReadingListLocal()); |
| 265 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); | 266 EXPECT_EQ(distilled_pb_entry->creation_time_us(), creation_time_us); |
| 266 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); | 267 EXPECT_EQ(distilled_pb_entry->update_time_us(), entry.UpdateTime()); |
| 267 EXPECT_NE(distilled_pb_entry->backoff(), ""); | 268 EXPECT_NE(distilled_pb_entry->backoff(), ""); |
| 268 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); | 269 EXPECT_EQ(distilled_pb_entry->status(), reading_list::ReadingListLocal::READ); |
| 269 EXPECT_EQ(distilled_pb_entry->distillation_state(), | 270 EXPECT_EQ(distilled_pb_entry->distillation_state(), |
| 270 reading_list::ReadingListLocal::PROCESSED); | 271 reading_list::ReadingListLocal::PROCESSED); |
| 271 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); | 272 EXPECT_EQ(distilled_pb_entry->distilled_path(), "distilled/page.html"); |
| 272 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); | 273 EXPECT_EQ(distilled_pb_entry->failed_download_counter(), 0); |
| 273 } | 274 } |
| 274 | 275 |
| 275 // Tests that the reading list entry is correctly parsed from | 276 // Tests that the reading list entry is correctly parsed from |
| 276 // sync_pb::ReadingListLocal. | 277 // sync_pb::ReadingListLocal. |
| 277 TEST(ReadingListEntry, FromReadingListLocal) { | 278 TEST(ReadingListEntry, FromReadingListLocal) { |
| 278 ReadingListEntry entry(GURL("http://example.com/"), "title"); | 279 ReadingListEntry entry(GURL("http://example.com/"), "title"); |
| 279 base::Time next_call = base::Time::Now() + entry.TimeUntilNextTry(); | 280 base::Time next_call = base::Time::Now() + entry.TimeUntilNextTry(); |
| 280 | 281 |
| 281 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( | 282 std::unique_ptr<reading_list::ReadingListLocal> pb_entry( |
| 282 entry.AsReadingListLocal(false)); | 283 entry.AsReadingListLocal()); |
| 283 | 284 |
| 284 pb_entry->set_entry_id("http://example.com/"); | 285 pb_entry->set_entry_id("http://example.com/"); |
| 285 pb_entry->set_url("http://example.com/"); | 286 pb_entry->set_url("http://example.com/"); |
| 286 pb_entry->set_title("title"); | 287 pb_entry->set_title("title"); |
| 287 pb_entry->set_creation_time_us(1); | 288 pb_entry->set_creation_time_us(1); |
| 288 pb_entry->set_update_time_us(2); | 289 pb_entry->set_update_time_us(2); |
| 289 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); | 290 pb_entry->set_status(reading_list::ReadingListLocal::UNREAD); |
| 290 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); | 291 pb_entry->set_distillation_state(reading_list::ReadingListLocal::WAITING); |
| 291 pb_entry->set_failed_download_counter(2); | 292 pb_entry->set_failed_download_counter(2); |
| 292 | 293 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 319 EXPECT_EQ(sync_entry.URL().spec(), "http://example2.com/"); | 320 EXPECT_EQ(sync_entry.URL().spec(), "http://example2.com/"); |
| 320 EXPECT_EQ(sync_entry.Title(), "title2"); | 321 EXPECT_EQ(sync_entry.Title(), "title2"); |
| 321 EXPECT_EQ(sync_entry.UpdateTime(), sync_update_time_us); | 322 EXPECT_EQ(sync_entry.UpdateTime(), sync_update_time_us); |
| 322 EXPECT_EQ(sync_entry.FailedDownloadCounter(), 0); | 323 EXPECT_EQ(sync_entry.FailedDownloadCounter(), 0); |
| 323 EXPECT_EQ(sync_entry.DistilledState(), ReadingListEntry::PROCESSED); | 324 EXPECT_EQ(sync_entry.DistilledState(), ReadingListEntry::PROCESSED); |
| 324 EXPECT_EQ(sync_entry.DistilledPath().value(), "distilled/page.html"); | 325 EXPECT_EQ(sync_entry.DistilledPath().value(), "distilled/page.html"); |
| 325 base::Time sync_next_call = base::Time::Now() + sync_entry.TimeUntilNextTry(); | 326 base::Time sync_next_call = base::Time::Now() + sync_entry.TimeUntilNextTry(); |
| 326 base::TimeDelta delta = next_call - sync_next_call; | 327 base::TimeDelta delta = next_call - sync_next_call; |
| 327 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); | 328 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); |
| 328 } | 329 } |
| OLD | NEW |