| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ntp_snippets/remote/remote_suggestions_provider_impl.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_provider_impl.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 base::UTF8ToUTF16(kTestJsonDefaultCategoryTitle); | 581 base::UTF8ToUTF16(kTestJsonDefaultCategoryTitle); |
| 582 | 582 |
| 583 // Don't send an initial response -- we want to test what happens without any | 583 // Don't send an initial response -- we want to test what happens without any |
| 584 // server status. | 584 // server status. |
| 585 auto service = MakeSuggestionsProvider(/*set_empty_response=*/false); | 585 auto service = MakeSuggestionsProvider(/*set_empty_response=*/false); |
| 586 | 586 |
| 587 // The articles category should be there by default, and have a title. | 587 // The articles category should be there by default, and have a title. |
| 588 CategoryInfo info_before = service->GetCategoryInfo(articles_category()); | 588 CategoryInfo info_before = service->GetCategoryInfo(articles_category()); |
| 589 ASSERT_THAT(info_before.title(), Not(IsEmpty())); | 589 ASSERT_THAT(info_before.title(), Not(IsEmpty())); |
| 590 ASSERT_THAT(info_before.title(), Not(Eq(test_default_title))); | 590 ASSERT_THAT(info_before.title(), Not(Eq(test_default_title))); |
| 591 EXPECT_THAT(info_before.has_more_action(), Eq(true)); | 591 EXPECT_THAT(info_before.has_fetch_action(), Eq(true)); |
| 592 EXPECT_THAT(info_before.has_reload_action(), Eq(true)); | |
| 593 EXPECT_THAT(info_before.has_view_all_action(), Eq(false)); | 592 EXPECT_THAT(info_before.has_view_all_action(), Eq(false)); |
| 594 EXPECT_THAT(info_before.show_if_empty(), Eq(true)); | 593 EXPECT_THAT(info_before.show_if_empty(), Eq(true)); |
| 595 | 594 |
| 596 std::string json_str_with_title(GetTestJson({GetSuggestion()})); | 595 std::string json_str_with_title(GetTestJson({GetSuggestion()})); |
| 597 LoadFromJSONString(service.get(), json_str_with_title); | 596 LoadFromJSONString(service.get(), json_str_with_title); |
| 598 | 597 |
| 599 ASSERT_THAT(observer().SuggestionsForCategory(articles_category()), | 598 ASSERT_THAT(observer().SuggestionsForCategory(articles_category()), |
| 600 SizeIs(1)); | 599 SizeIs(1)); |
| 601 ASSERT_THAT(service->GetSuggestionsForTesting(articles_category()), | 600 ASSERT_THAT(service->GetSuggestionsForTesting(articles_category()), |
| 602 SizeIs(1)); | 601 SizeIs(1)); |
| 603 | 602 |
| 604 // The response contained a title, |kTestJsonDefaultCategoryTitle|. | 603 // The response contained a title, |kTestJsonDefaultCategoryTitle|. |
| 605 // Make sure we updated the title in the CategoryInfo. | 604 // Make sure we updated the title in the CategoryInfo. |
| 606 CategoryInfo info_with_title = service->GetCategoryInfo(articles_category()); | 605 CategoryInfo info_with_title = service->GetCategoryInfo(articles_category()); |
| 607 EXPECT_THAT(info_before.title(), Not(Eq(info_with_title.title()))); | 606 EXPECT_THAT(info_before.title(), Not(Eq(info_with_title.title()))); |
| 608 EXPECT_THAT(test_default_title, Eq(info_with_title.title())); | 607 EXPECT_THAT(test_default_title, Eq(info_with_title.title())); |
| 609 EXPECT_THAT(info_before.has_more_action(), Eq(true)); | 608 EXPECT_THAT(info_before.has_fetch_action(), Eq(true)); |
| 610 EXPECT_THAT(info_before.has_reload_action(), Eq(true)); | |
| 611 EXPECT_THAT(info_before.has_view_all_action(), Eq(false)); | 609 EXPECT_THAT(info_before.has_view_all_action(), Eq(false)); |
| 612 EXPECT_THAT(info_before.show_if_empty(), Eq(true)); | 610 EXPECT_THAT(info_before.show_if_empty(), Eq(true)); |
| 613 } | 611 } |
| 614 | 612 |
| 615 TEST_F(RemoteSuggestionsProviderImplTest, MultipleCategories) { | 613 TEST_F(RemoteSuggestionsProviderImplTest, MultipleCategories) { |
| 616 auto service = MakeSuggestionsProvider(); | 614 auto service = MakeSuggestionsProvider(); |
| 617 std::string json_str = | 615 std::string json_str = |
| 618 MultiCategoryJsonBuilder() | 616 MultiCategoryJsonBuilder() |
| 619 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/1) | 617 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/1) |
| 620 .AddCategory({GetSuggestionN(1)}, /*remote_category_id=*/2) | 618 .AddCategory({GetSuggestionN(1)}, /*remote_category_id=*/2) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 656 EXPECT_EQ(kSuggestionText, base::UTF16ToUTF8(suggestion.snippet_text())); | 654 EXPECT_EQ(kSuggestionText, base::UTF16ToUTF8(suggestion.snippet_text())); |
| 657 EXPECT_EQ(GetDefaultCreationTime(), suggestion.publish_date()); | 655 EXPECT_EQ(GetDefaultCreationTime(), suggestion.publish_date()); |
| 658 EXPECT_EQ(kSuggestionPublisherName, | 656 EXPECT_EQ(kSuggestionPublisherName, |
| 659 base::UTF16ToUTF8(suggestion.publisher_name())); | 657 base::UTF16ToUTF8(suggestion.publisher_name())); |
| 660 } | 658 } |
| 661 } | 659 } |
| 662 | 660 |
| 663 TEST_F(RemoteSuggestionsProviderImplTest, ArticleCategoryInfo) { | 661 TEST_F(RemoteSuggestionsProviderImplTest, ArticleCategoryInfo) { |
| 664 auto service = MakeSuggestionsProvider(); | 662 auto service = MakeSuggestionsProvider(); |
| 665 CategoryInfo article_info = service->GetCategoryInfo(articles_category()); | 663 CategoryInfo article_info = service->GetCategoryInfo(articles_category()); |
| 666 EXPECT_THAT(article_info.has_more_action(), Eq(true)); | 664 EXPECT_THAT(article_info.has_fetch_action(), Eq(true)); |
| 667 EXPECT_THAT(article_info.has_reload_action(), Eq(true)); | |
| 668 EXPECT_THAT(article_info.has_view_all_action(), Eq(false)); | 665 EXPECT_THAT(article_info.has_view_all_action(), Eq(false)); |
| 669 EXPECT_THAT(article_info.show_if_empty(), Eq(true)); | 666 EXPECT_THAT(article_info.show_if_empty(), Eq(true)); |
| 670 } | 667 } |
| 671 | 668 |
| 672 TEST_F(RemoteSuggestionsProviderImplTest, ExperimentalCategoryInfo) { | 669 TEST_F(RemoteSuggestionsProviderImplTest, ExperimentalCategoryInfo) { |
| 673 auto service = MakeSuggestionsProvider(); | 670 auto service = MakeSuggestionsProvider(); |
| 674 std::string json_str = | 671 std::string json_str = |
| 675 MultiCategoryJsonBuilder() | 672 MultiCategoryJsonBuilder() |
| 676 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/1) | 673 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/1) |
| 677 .AddCategory({GetSuggestionN(1)}, kUnknownRemoteCategoryId) | 674 .AddCategory({GetSuggestionN(1)}, kUnknownRemoteCategoryId) |
| 678 .Build(); | 675 .Build(); |
| 679 // Load data with multiple categories so that a new experimental category gets | 676 // Load data with multiple categories so that a new experimental category gets |
| 680 // registered. | 677 // registered. |
| 681 LoadFromJSONString(service.get(), json_str); | 678 LoadFromJSONString(service.get(), json_str); |
| 682 | 679 |
| 683 CategoryInfo info = service->GetCategoryInfo(unknown_category()); | 680 CategoryInfo info = service->GetCategoryInfo(unknown_category()); |
| 684 EXPECT_THAT(info.has_more_action(), Eq(false)); | 681 EXPECT_THAT(info.has_fetch_action(), Eq(false)); |
| 685 EXPECT_THAT(info.has_reload_action(), Eq(false)); | |
| 686 EXPECT_THAT(info.has_view_all_action(), Eq(false)); | 682 EXPECT_THAT(info.has_view_all_action(), Eq(false)); |
| 687 EXPECT_THAT(info.show_if_empty(), Eq(false)); | 683 EXPECT_THAT(info.show_if_empty(), Eq(false)); |
| 688 } | 684 } |
| 689 | 685 |
| 690 TEST_F(RemoteSuggestionsProviderImplTest, AddRemoteCategoriesToCategoryRanker) { | 686 TEST_F(RemoteSuggestionsProviderImplTest, AddRemoteCategoriesToCategoryRanker) { |
| 691 auto mock_ranker = base::MakeUnique<MockCategoryRanker>(); | 687 auto mock_ranker = base::MakeUnique<MockCategoryRanker>(); |
| 692 MockCategoryRanker* raw_mock_ranker = mock_ranker.get(); | 688 MockCategoryRanker* raw_mock_ranker = mock_ranker.get(); |
| 693 SetCategoryRanker(std::move(mock_ranker)); | 689 SetCategoryRanker(std::move(mock_ranker)); |
| 694 std::string json_str = | 690 std::string json_str = |
| 695 MultiCategoryJsonBuilder() | 691 MultiCategoryJsonBuilder() |
| (...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1820 RemoteSuggestionsProvider::ProviderStatus)>::Call, | 1816 RemoteSuggestionsProvider::ProviderStatus)>::Call, |
| 1821 base::Unretained(&status_callback)))); | 1817 base::Unretained(&status_callback)))); |
| 1822 | 1818 |
| 1823 // Should be called when becoming disabled. | 1819 // Should be called when becoming disabled. |
| 1824 EXPECT_CALL(status_callback, | 1820 EXPECT_CALL(status_callback, |
| 1825 Call(RemoteSuggestionsProvider::ProviderStatus::INACTIVE)); | 1821 Call(RemoteSuggestionsProvider::ProviderStatus::INACTIVE)); |
| 1826 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); | 1822 service->EnterState(RemoteSuggestionsProviderImpl::State::DISABLED); |
| 1827 } | 1823 } |
| 1828 | 1824 |
| 1829 } // namespace ntp_snippets | 1825 } // namespace ntp_snippets |
| OLD | NEW |