| 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/ios/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 #import "base/test/ios/wait_util.h" | 9 #import "base/test/ios/wait_util.h" |
| 10 #include "components/reading_list/ios/reading_list_model_impl.h" | 10 #include "components/reading_list/ios/reading_list_model_impl.h" |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 376 } |
| 377 | 377 |
| 378 // Tests updating entry from sync. | 378 // Tests updating entry from sync. |
| 379 TEST_F(ReadingListModelTest, SyncMergeEntry) { | 379 TEST_F(ReadingListModelTest, SyncMergeEntry) { |
| 380 auto storage = base::MakeUnique<TestReadingListStorage>(this); | 380 auto storage = base::MakeUnique<TestReadingListStorage>(this); |
| 381 SetStorage(std::move(storage)); | 381 SetStorage(std::move(storage)); |
| 382 model_->AddEntry(GURL("http://example.com"), "sample", | 382 model_->AddEntry(GURL("http://example.com"), "sample", |
| 383 reading_list::ADDED_VIA_CURRENT_APP); | 383 reading_list::ADDED_VIA_CURRENT_APP); |
| 384 const base::FilePath distilled_path("distilled/page.html"); | 384 const base::FilePath distilled_path("distilled/page.html"); |
| 385 const GURL distilled_url("http://example.com/distilled"); | 385 const GURL distilled_url("http://example.com/distilled"); |
| 386 int64_t size = 50; |
| 387 int64_t time = 100; |
| 386 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, | 388 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, |
| 387 distilled_url); | 389 distilled_url, size, time); |
| 388 const ReadingListEntry* local_entry = | 390 const ReadingListEntry* local_entry = |
| 389 model_->GetEntryByURL(GURL("http://example.com")); | 391 model_->GetEntryByURL(GURL("http://example.com")); |
| 390 int64_t local_update_time = local_entry->UpdateTime(); | 392 int64_t local_update_time = local_entry->UpdateTime(); |
| 391 | 393 |
| 392 base::test::ios::SpinRunLoopWithMinDelay( | 394 base::test::ios::SpinRunLoopWithMinDelay( |
| 393 base::TimeDelta::FromMilliseconds(10)); | 395 base::TimeDelta::FromMilliseconds(10)); |
| 394 auto sync_entry = | 396 auto sync_entry = |
| 395 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); | 397 base::MakeUnique<ReadingListEntry>(GURL("http://example.com"), "sample"); |
| 396 sync_entry->SetRead(true); | 398 sync_entry->SetRead(true); |
| 397 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); | 399 ASSERT_GT(sync_entry->UpdateTime(), local_update_time); |
| 398 int64_t sync_update_time = sync_entry->UpdateTime(); | 400 int64_t sync_update_time = sync_entry->UpdateTime(); |
| 399 EXPECT_TRUE(sync_entry->DistilledPath().empty()); | 401 EXPECT_TRUE(sync_entry->DistilledPath().empty()); |
| 400 | 402 |
| 401 EXPECT_EQ(1ul, UnreadSize()); | 403 EXPECT_EQ(1ul, UnreadSize()); |
| 402 EXPECT_EQ(0ul, ReadSize()); | 404 EXPECT_EQ(0ul, ReadSize()); |
| 403 | 405 |
| 404 ReadingListEntry* merged_entry = | 406 ReadingListEntry* merged_entry = |
| 405 model_->SyncMergeEntry(std::move(sync_entry)); | 407 model_->SyncMergeEntry(std::move(sync_entry)); |
| 406 EXPECT_EQ(0ul, UnreadSize()); | 408 EXPECT_EQ(0ul, UnreadSize()); |
| 407 EXPECT_EQ(1ul, ReadSize()); | 409 EXPECT_EQ(1ul, ReadSize()); |
| 408 EXPECT_EQ(merged_entry->DistilledPath(), | 410 EXPECT_EQ(merged_entry->DistilledPath(), |
| 409 base::FilePath("distilled/page.html")); | 411 base::FilePath("distilled/page.html")); |
| 410 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time); | 412 EXPECT_EQ(merged_entry->UpdateTime(), sync_update_time); |
| 413 EXPECT_EQ(size, merged_entry->DistillationSize()); |
| 414 EXPECT_EQ(time, merged_entry->DistillationTime()); |
| 411 } | 415 } |
| 412 | 416 |
| 413 // Tests deleting entry. | 417 // Tests deleting entry. |
| 414 TEST_F(ReadingListModelTest, RemoveEntryByUrl) { | 418 TEST_F(ReadingListModelTest, RemoveEntryByUrl) { |
| 415 auto storage = base::MakeUnique<TestReadingListStorage>(this); | 419 auto storage = base::MakeUnique<TestReadingListStorage>(this); |
| 416 SetStorage(std::move(storage)); | 420 SetStorage(std::move(storage)); |
| 417 model_->AddEntry(GURL("http://example.com"), "sample", | 421 model_->AddEntry(GURL("http://example.com"), "sample", |
| 418 reading_list::ADDED_VIA_CURRENT_APP); | 422 reading_list::ADDED_VIA_CURRENT_APP); |
| 419 ClearCounts(); | 423 ClearCounts(); |
| 420 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr); | 424 EXPECT_NE(model_->GetEntryByURL(GURL("http://example.com")), nullptr); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 621 |
| 618 // Tests setting distillation info on unread entry. | 622 // Tests setting distillation info on unread entry. |
| 619 TEST_F(ReadingListModelTest, UpdateDistilledInfo) { | 623 TEST_F(ReadingListModelTest, UpdateDistilledInfo) { |
| 620 const GURL gurl("http://example.com"); | 624 const GURL gurl("http://example.com"); |
| 621 const ReadingListEntry& entry = | 625 const ReadingListEntry& entry = |
| 622 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); | 626 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); |
| 623 ClearCounts(); | 627 ClearCounts(); |
| 624 | 628 |
| 625 const base::FilePath distilled_path("distilled/page.html"); | 629 const base::FilePath distilled_path("distilled/page.html"); |
| 626 const GURL distilled_url("http://example.com/distilled"); | 630 const GURL distilled_url("http://example.com/distilled"); |
| 631 int64_t size = 50; |
| 632 int64_t time = 100; |
| 627 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, | 633 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, |
| 628 distilled_url); | 634 distilled_url, size, time); |
| 629 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); | 635 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 630 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); | 636 EXPECT_EQ(ReadingListEntry::PROCESSED, entry.DistilledState()); |
| 631 EXPECT_EQ(distilled_path, entry.DistilledPath()); | 637 EXPECT_EQ(distilled_path, entry.DistilledPath()); |
| 632 EXPECT_EQ(distilled_url, entry.DistilledURL()); | 638 EXPECT_EQ(distilled_url, entry.DistilledURL()); |
| 639 EXPECT_EQ(size, entry.DistillationSize()); |
| 640 EXPECT_EQ(time, entry.DistillationTime()); |
| 633 } | 641 } |
| 634 | 642 |
| 635 // Tests setting title on read entry. | 643 // Tests setting title on read entry. |
| 636 TEST_F(ReadingListModelTest, UpdateReadEntryTitle) { | 644 TEST_F(ReadingListModelTest, UpdateReadEntryTitle) { |
| 637 const GURL gurl("http://example.com"); | 645 const GURL gurl("http://example.com"); |
| 638 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); | 646 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); |
| 639 model_->SetReadStatus(gurl, true); | 647 model_->SetReadStatus(gurl, true); |
| 640 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); | 648 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); |
| 641 ClearCounts(); | 649 ClearCounts(); |
| 642 | 650 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 661 // Tests setting distillation info on read entry. | 669 // Tests setting distillation info on read entry. |
| 662 TEST_F(ReadingListModelTest, UpdateReadDistilledInfo) { | 670 TEST_F(ReadingListModelTest, UpdateReadDistilledInfo) { |
| 663 const GURL gurl("http://example.com"); | 671 const GURL gurl("http://example.com"); |
| 664 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); | 672 model_->AddEntry(gurl, "sample", reading_list::ADDED_VIA_CURRENT_APP); |
| 665 model_->SetReadStatus(gurl, true); | 673 model_->SetReadStatus(gurl, true); |
| 666 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); | 674 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); |
| 667 ClearCounts(); | 675 ClearCounts(); |
| 668 | 676 |
| 669 const base::FilePath distilled_path("distilled/page.html"); | 677 const base::FilePath distilled_path("distilled/page.html"); |
| 670 const GURL distilled_url("http://example.com/distilled"); | 678 const GURL distilled_url("http://example.com/distilled"); |
| 679 int64_t size = 50; |
| 680 int64_t time = 100; |
| 671 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, | 681 model_->SetEntryDistilledInfo(GURL("http://example.com"), distilled_path, |
| 672 distilled_url); | 682 distilled_url, size, time); |
| 673 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); | 683 AssertObserverCount(0, 0, 0, 0, 0, 0, 0, 1, 1); |
| 674 EXPECT_EQ(ReadingListEntry::PROCESSED, entry->DistilledState()); | 684 EXPECT_EQ(ReadingListEntry::PROCESSED, entry->DistilledState()); |
| 675 EXPECT_EQ(distilled_path, entry->DistilledPath()); | 685 EXPECT_EQ(distilled_path, entry->DistilledPath()); |
| 676 EXPECT_EQ(distilled_url, entry->DistilledURL()); | 686 EXPECT_EQ(distilled_url, entry->DistilledURL()); |
| 687 EXPECT_EQ(size, entry->DistillationSize()); |
| 688 EXPECT_EQ(time, entry->DistillationTime()); |
| 677 } | 689 } |
| 678 | 690 |
| 679 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. | 691 // Tests that ReadingListModel calls CallbackModelBeingDeleted when destroyed. |
| 680 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { | 692 TEST_F(ReadingListModelTest, CallbackModelBeingDeleted) { |
| 681 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 693 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 682 model_.reset(); | 694 model_.reset(); |
| 683 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0); | 695 AssertObserverCount(1, 0, 0, 1, 0, 0, 0, 0, 0); |
| 684 } | 696 } |
| 685 | 697 |
| 686 // Tests that new line characters and spaces are collapsed in title. | 698 // Tests that new line characters and spaces are collapsed in title. |
| 687 TEST_F(ReadingListModelTest, TestTrimmingTitle) { | 699 TEST_F(ReadingListModelTest, TestTrimmingTitle) { |
| 688 const GURL gurl("http://example.com"); | 700 const GURL gurl("http://example.com"); |
| 689 std::string title = "\n This\ttitle \n contains new line \n characters "; | 701 std::string title = "\n This\ttitle \n contains new line \n characters "; |
| 690 model_->AddEntry(gurl, title, reading_list::ADDED_VIA_CURRENT_APP); | 702 model_->AddEntry(gurl, title, reading_list::ADDED_VIA_CURRENT_APP); |
| 691 model_->SetReadStatus(gurl, true); | 703 model_->SetReadStatus(gurl, true); |
| 692 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); | 704 const ReadingListEntry* entry = model_->GetEntryByURL(gurl); |
| 693 EXPECT_EQ(entry->Title(), "This title contains new line characters"); | 705 EXPECT_EQ(entry->Title(), "This title contains new line characters"); |
| 694 model_->SetEntryTitle(gurl, "test"); | 706 model_->SetEntryTitle(gurl, "test"); |
| 695 EXPECT_EQ(entry->Title(), "test"); | 707 EXPECT_EQ(entry->Title(), "test"); |
| 696 model_->SetEntryTitle(gurl, title); | 708 model_->SetEntryTitle(gurl, title); |
| 697 EXPECT_EQ(entry->Title(), "This title contains new line characters"); | 709 EXPECT_EQ(entry->Title(), "This title contains new line characters"); |
| 698 } | 710 } |
| 699 | 711 |
| 700 } // namespace | 712 } // namespace |
| OLD | NEW |