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/simple_test_tick_clock.h" | 8 #include "base/test/simple_test_tick_clock.h" |
9 #include "components/reading_list/ios/proto/reading_list.pb.h" | 9 #include "components/reading_list/ios/proto/reading_list.pb.h" |
10 #include "components/sync/protocol/reading_list_specifics.pb.h" | 10 #include "components/sync/protocol/reading_list_specifics.pb.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 EXPECT_EQ(waiting_entry->UpdateTime(), 2); | 309 EXPECT_EQ(waiting_entry->UpdateTime(), 2); |
310 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); | 310 EXPECT_EQ(waiting_entry->FailedDownloadCounter(), 2); |
311 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); | 311 EXPECT_EQ(waiting_entry->DistilledState(), ReadingListEntry::WAITING); |
312 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); | 312 EXPECT_EQ(waiting_entry->DistilledPath(), base::FilePath()); |
313 base::Time waiting_next_call = | 313 base::Time waiting_next_call = |
314 base::Time::Now() + waiting_entry->TimeUntilNextTry(); | 314 base::Time::Now() + waiting_entry->TimeUntilNextTry(); |
315 base::TimeDelta delta = next_call - waiting_next_call; | 315 base::TimeDelta delta = next_call - waiting_next_call; |
316 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); | 316 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); |
317 } | 317 } |
318 | 318 |
319 // Tests that the merging of two ReadingListEntry. | 319 // Tests the merging of two ReadingListEntry. |
320 TEST(ReadingListEntry, MergeLocalStateFrom) { | 320 TEST(ReadingListEntry, MergeWithEntry) { |
321 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); | 321 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); |
| 322 local_entry.SetDistilledState(ReadingListEntry::ERROR); |
322 base::Time next_call = base::Time::Now() + local_entry.TimeUntilNextTry(); | 323 base::Time next_call = base::Time::Now() + local_entry.TimeUntilNextTry(); |
323 int64_t local_update_time_us = local_entry.UpdateTime(); | 324 int64_t local_update_time_us = local_entry.UpdateTime(); |
| 325 |
| 326 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); |
| 327 sync_entry.SetDistilledState(ReadingListEntry::ERROR); |
| 328 int64_t sync_update_time_us = sync_entry.UpdateTime(); |
| 329 EXPECT_NE(local_update_time_us, sync_update_time_us); |
| 330 local_entry.MergeWithEntry(sync_entry); |
| 331 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); |
| 332 EXPECT_EQ(local_entry.Title(), "title2"); |
| 333 EXPECT_FALSE(local_entry.HasBeenSeen()); |
| 334 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); |
| 335 EXPECT_EQ(local_entry.FailedDownloadCounter(), 1); |
| 336 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::ERROR); |
| 337 base::Time merge_next_call = |
| 338 base::Time::Now() + local_entry.TimeUntilNextTry(); |
| 339 base::TimeDelta delta = merge_next_call - next_call; |
| 340 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); |
| 341 } |
| 342 |
| 343 // Tests the merging of two ReadingListEntry, the oldest one SEEN and the newer |
| 344 // UNSEEN. |
| 345 TEST(ReadingListEntry, MergeWithEntrySeen) { |
| 346 ReadingListEntry local_entry(GURL("http://example.com/"), "title"); |
| 347 local_entry.SetRead(true); |
| 348 int64_t local_update_time_us = local_entry.UpdateTime(); |
324 local_entry.SetDistilledPath(base::FilePath("distilled/page.html")); | 349 local_entry.SetDistilledPath(base::FilePath("distilled/page.html")); |
325 | 350 |
326 ReadingListEntry sync_entry(GURL("http://example2.com/"), "title2"); | 351 ReadingListEntry sync_entry(GURL("http://example.com/"), "title2"); |
327 sync_entry.SetDistilledState(ReadingListEntry::ERROR); | |
328 int64_t sync_update_time_us = sync_entry.UpdateTime(); | 352 int64_t sync_update_time_us = sync_entry.UpdateTime(); |
329 EXPECT_NE(local_update_time_us, sync_update_time_us); | 353 EXPECT_NE(local_update_time_us, sync_update_time_us); |
330 sync_entry.MergeLocalStateFrom(local_entry); | 354 local_entry.MergeWithEntry(sync_entry); |
331 EXPECT_EQ(sync_entry.URL().spec(), "http://example2.com/"); | 355 EXPECT_EQ(local_entry.URL().spec(), "http://example.com/"); |
332 EXPECT_EQ(sync_entry.Title(), "title2"); | 356 EXPECT_EQ(local_entry.Title(), "title2"); |
333 EXPECT_EQ(sync_entry.UpdateTime(), sync_update_time_us); | 357 EXPECT_TRUE(local_entry.HasBeenSeen()); |
334 EXPECT_EQ(sync_entry.FailedDownloadCounter(), 0); | 358 EXPECT_EQ(local_entry.UpdateTime(), sync_update_time_us); |
335 EXPECT_EQ(sync_entry.DistilledState(), ReadingListEntry::PROCESSED); | 359 EXPECT_EQ(local_entry.FailedDownloadCounter(), 0); |
336 EXPECT_EQ(sync_entry.DistilledPath().value(), "distilled/page.html"); | 360 EXPECT_EQ(local_entry.DistilledState(), ReadingListEntry::PROCESSED); |
337 base::Time sync_next_call = base::Time::Now() + sync_entry.TimeUntilNextTry(); | 361 EXPECT_EQ(local_entry.DistilledPath().value(), "distilled/page.html"); |
338 base::TimeDelta delta = next_call - sync_next_call; | |
339 EXPECT_NEAR(delta.InMillisecondsRoundedUp(), 0, 10); | |
340 } | 362 } |
OLD | NEW |