| 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_model.h" | 5 #include "components/reading_list/core/reading_list_model.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/test/simple_test_clock.h" | 9 #include "base/test/simple_test_clock.h" |
| 10 #include "components/reading_list/ios/reading_list_model_impl.h" | 10 #include "components/reading_list/core/reading_list_model_impl.h" |
| 11 #include "components/reading_list/ios/reading_list_model_storage.h" | 11 #include "components/reading_list/core/reading_list_model_storage.h" |
| 12 #include "components/reading_list/ios/reading_list_store_delegate.h" | 12 #include "components/reading_list/core/reading_list_store_delegate.h" |
| 13 #include "components/sync/model/metadata_change_list.h" | 13 #include "components/sync/model/metadata_change_list.h" |
| 14 #include "components/sync/model/model_error.h" | 14 #include "components/sync/model/model_error.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const GURL callback_url("http://example.com"); | 19 const GURL callback_url("http://example.com"); |
| 20 const std::string callback_title("test title"); | 20 const std::string callback_title("test title"); |
| 21 | 21 |
| 22 base::Time AdvanceAndGetTime(base::SimpleTestClock* clock) { | 22 base::Time AdvanceAndGetTime(base::SimpleTestClock* clock) { |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 ClearCounts(); | 388 ClearCounts(); |
| 389 } | 389 } |
| 390 | 390 |
| 391 // Tests updating entry from sync. | 391 // Tests updating entry from sync. |
| 392 TEST_F(ReadingListModelTest, SyncMergeEntry) { | 392 TEST_F(ReadingListModelTest, SyncMergeEntry) { |
| 393 auto clock = base::MakeUnique<base::SimpleTestClock>(); | 393 auto clock = base::MakeUnique<base::SimpleTestClock>(); |
| 394 auto storage = base::MakeUnique<TestReadingListStorage>(this, clock.get()); | 394 auto storage = base::MakeUnique<TestReadingListStorage>(this, clock.get()); |
| 395 SetStorage(std::move(storage), std::move(clock)); | 395 SetStorage(std::move(storage), std::move(clock)); |
| 396 model_->AddEntry(GURL("http://example.com"), "sample", | 396 model_->AddEntry(GURL("http://example.com"), "sample", |
| 397 reading_list::ADDED_VIA_CURRENT_APP); | 397 reading_list::ADDED_VIA_CURRENT_APP); |
| 398 const base::FilePath distilled_path("distilled/page.html"); | 398 const base::FilePath distilled_path(FILE_PATH_LITERAL("distilled/page.html")); |
| 399 const GURL distilled_url("http://example.com/distilled"); | 399 const GURL distilled_url("http://example.com/distilled"); |
| 400 int64_t size = 50; | 400 int64_t size = 50; |
| 401 int64_t time = 100; | 401 int64_t time = 100; |
| 402 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, | 402 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, |
| 403 distilled_url, size, | 403 distilled_url, size, |
| 404 base::Time::FromTimeT(time)); | 404 base::Time::FromTimeT(time)); |
| 405 const ReadingListEntry* local_entry = | 405 const ReadingListEntry* local_entry = |
| 406 model_->GetEntryByURL(GURL("http://example.com")); | 406 model_->GetEntryByURL(GURL("http://example.com")); |
| 407 int64_t local_update_time = local_entry->UpdateTime(); | 407 int64_t local_update_time = local_entry->UpdateTime(); |
| 408 | 408 |
| 409 auto sync_entry = base::MakeUnique<ReadingListEntry>( | 409 auto sync_entry = base::MakeUnique<ReadingListEntry>( |
| 410 GURL("http://example.com"), "sample", AdvanceAndGetTime(clock_)); | 410 GURL("http://example.com"), "sample", AdvanceAndGetTime(clock_)); |
| 411 sync_entry->SetRead(true, AdvanceAndGetTime(clock_)); | 411 sync_entry->SetRead(true, AdvanceAndGetTime(clock_)); |
| 412 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); | 412 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); |
| 413 int64_t sync_update_time = sync_entry->UpdateTime(); | 413 int64_t sync_update_time = sync_entry->UpdateTime(); |
| 414 EXPECT_TRUE(sync_entry->DistilledPath().empty()); | 414 EXPECT_TRUE(sync_entry->DistilledPath().empty()); |
| 415 | 415 |
| 416 EXPECT_EQ(1ul, UnreadSize()); | 416 EXPECT_EQ(1ul, UnreadSize()); |
| 417 EXPECT_EQ(0ul, ReadSize()); | 417 EXPECT_EQ(0ul, ReadSize()); |
| 418 | 418 |
| 419 ReadingListEntry* merged_entry = | 419 ReadingListEntry* merged_entry = |
| 420 model_->SyncMergeEntry(std::move(sync_entry)); | 420 model_->SyncMergeEntry(std::move(sync_entry)); |
| 421 EXPECT_EQ(0ul, UnreadSize()); | 421 EXPECT_EQ(0ul, UnreadSize()); |
| 422 EXPECT_EQ(1ul, ReadSize()); | 422 EXPECT_EQ(1ul, ReadSize()); |
| 423 EXPECT_EQ(merged_entry->DistilledPath(), | 423 EXPECT_EQ(merged_entry->DistilledPath(), |
| 424 base::FilePath("distilled/page.html")); | 424 base::FilePath(FILE_PATH_LITERAL("distilled/page.html"))); |
| 425 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time); | 425 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time); |
| 426 EXPECT_EQ(size, merged_entry->DistillationSize()); | 426 EXPECT_EQ(size, merged_entry->DistillationSize()); |
| 427 EXPECT_EQ(time * base::Time::kMicrosecondsPerSecond, | 427 EXPECT_EQ(time * base::Time::kMicrosecondsPerSecond, |
| 428 merged_entry->DistillationTime()); | 428 merged_entry->DistillationTime()); |
| 429 } | 429 } |
| 430 | 430 |
| 431 // Tests deleting entry. | 431 // Tests deleting entry. |
| 432 TEST_F(ReadingListModelTest, RemoveEntryByUrl) { | 432 TEST_F(ReadingListModelTest, RemoveEntryByUrl) { |
| 433 auto clock = base::MakeUnique<base::SimpleTestClock>(); | 433 auto clock = base::MakeUnique<base::SimpleTestClock>(); |
| 434 auto storage = base::MakeUnique<TestReadingListStorage>(this, clock.get()); | 434 auto storage = base::MakeUnique<TestReadingListStorage>(this, clock.get()); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); | 635 EXPECT_EQ(ReadingListEntry::PROCESSING, entry.DistilledState()); |
| 636 } | 636 } |
| 637 | 637 |
| 638 // Tests setting distillation info on unread entry. | 638 // Tests setting distillation info on unread entry. |
| 639 TEST_F(ReadingListModelTest, UpdateDistilledInfo) { | 639 TEST_F(ReadingListModelTest, UpdateDistilledInfo) { |
| 640 const GURL gurl("http://example.com"); | 640 const GURL gurl("http://example.com"); |
| 641 const ReadingListEntry& entry = | 641 const ReadingListEntry& entry = |
| 642 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); | 642 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); |
| 643 ClearCounts(); | 643 ClearCounts(); |
| 644 | 644 |
| 645 const base::FilePath distilled_path("distilled/page.html"); | 645 const base::FilePath distilled_path(FILE_PATH_LITERAL("distilled/page.html")); |
| 646 const GURL distilled_url("http://example.com/distilled"); | 646 const GURL distilled_url("http://example.com/distilled"); |
| 647 int64_t size = 50; | 647 int64_t size = 50; |
| 648 int64_t time = 100; | 648 int64_t time = 100; |
| 649 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, | 649 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, |
| 650 distilled_url, size, | 650 distilled_url, size, |
| 651 base::Time::FromTimeT(time)); | 651 base::Time::FromTimeT(time)); |
| 652 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); | 652 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 653 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); | 653 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); |
| 654 EXPECT_EQ(distilled_path, entry.DistilledPath()); | 654 EXPECT_EQ(distilled_path, entry.DistilledPath()); |
| 655 EXPECT_EQ(distilled_url, entry.DistilledURL()); | 655 EXPECT_EQ(distilled_url, entry.DistilledURL()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 685 } | 685 } |
| 686 | 686 |
| 687 // Tests setting distillation info on read entry. | 687 // Tests setting distillation info on read entry. |
| 688 TEST_F(ReadingListModelTest, UpdateReadDistilledInfo) { | 688 TEST_F(ReadingListModelTest, UpdateReadDistilledInfo) { |
| 689 const GURL gurl("http://example.com"); | 689 const GURL gurl("http://example.com"); |
| 690 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); | 690 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); |
| 691 model_->SetReadStatus(gurl, true); | 691 model_->SetReadStatus(gurl, true); |
| 692 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); | 692 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); |
| 693 ClearCounts(); | 693 ClearCounts(); |
| 694 | 694 |
| 695 const base::FilePath distilled_path("distilled/page.html"); | 695 const base::FilePath distilled_path(FILE_PATH_LITERAL("distilled/page.html")); |
| 696 const GURL distilled_url("http://example.com/distilled"); | 696 const GURL distilled_url("http://example.com/distilled"); |
| 697 int64_t size = 50; | 697 int64_t size = 50; |
| 698 int64_t time = 100; | 698 int64_t time = 100; |
| 699 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, | 699 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, |
| 700 distilled_url, size, | 700 distilled_url, size, |
| 701 base::Time::FromTimeT(time)); | 701 base::Time::FromTimeT(time)); |
| 702 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); | 702 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 703 EXPECT_EQ(ReadingListEntry::PROCESSED, entry->DistilledState()); | 703 EXPECT_EQ(ReadingListEntry::PROCESSED, entry->DistilledState()); |
| 704 EXPECT_EQ(distilled_path, entry->DistilledPath()); | 704 EXPECT_EQ(distilled_path, entry->DistilledPath()); |
| 705 EXPECT_EQ(distilled_url, entry->DistilledURL()); | 705 EXPECT_EQ(distilled_url, entry->DistilledURL()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 723 model_->SetReadStatus(gurl, true); | 723 model_->SetReadStatus(gurl, true); |
| 724 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); | 724 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); |
| 725 EXPECT_EQ(entry->Title(), "This title contains new line characters"); | 725 EXPECT_EQ(entry->Title(), "This title contains new line characters"); |
| 726 model_->SetEntryTitle(gurl, "test"); | 726 model_->SetEntryTitle(gurl, "test"); |
| 727 EXPECT_EQ(entry->Title(), "test"); | 727 EXPECT_EQ(entry->Title(), "test"); |
| 728 model_->SetEntryTitle(gurl, title); | 728 model_->SetEntryTitle(gurl, title); |
| 729 EXPECT_EQ(entry->Title(), "This title contains new line characters"); | 729 EXPECT_EQ(entry->Title(), "This title contains new line characters"); |
| 730 } | 730 } |
| 731 | 731 |
| 732 } // namespace | 732 } // namespace |
| OLD | NEW |