| 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 base::UTF8ToUTF16(kTestJsonDefaultCategoryTitle); | 598 base::UTF8ToUTF16(kTestJsonDefaultCategoryTitle); |
| 599 | 599 |
| 600 // Don't send an initial response -- we want to test what happens without any | 600 // Don't send an initial response -- we want to test what happens without any |
| 601 // server status. | 601 // server status. |
| 602 auto service = MakeSuggestionsProvider(/*set_empty_response=*/false); | 602 auto service = MakeSuggestionsProvider(/*set_empty_response=*/false); |
| 603 | 603 |
| 604 // The articles category should be there by default, and have a title. | 604 // The articles category should be there by default, and have a title. |
| 605 CategoryInfo info_before = service->GetCategoryInfo(articles_category()); | 605 CategoryInfo info_before = service->GetCategoryInfo(articles_category()); |
| 606 ASSERT_THAT(info_before.title(), Not(IsEmpty())); | 606 ASSERT_THAT(info_before.title(), Not(IsEmpty())); |
| 607 ASSERT_THAT(info_before.title(), Not(Eq(test_default_title))); | 607 ASSERT_THAT(info_before.title(), Not(Eq(test_default_title))); |
| 608 EXPECT_THAT(info_before.has_fetch_action(), Eq(true)); | 608 EXPECT_THAT(info_before.additional_action(), |
| 609 EXPECT_THAT(info_before.has_view_all_action(), Eq(false)); | 609 Eq(ContentSuggestionsAdditionalAction::FETCH)); |
| 610 EXPECT_THAT(info_before.show_if_empty(), Eq(true)); | 610 EXPECT_THAT(info_before.show_if_empty(), Eq(true)); |
| 611 | 611 |
| 612 std::string json_str_with_title(GetTestJson({GetSuggestion()})); | 612 std::string json_str_with_title(GetTestJson({GetSuggestion()})); |
| 613 LoadFromJSONString(service.get(), json_str_with_title); | 613 LoadFromJSONString(service.get(), json_str_with_title); |
| 614 | 614 |
| 615 ASSERT_THAT(observer().SuggestionsForCategory(articles_category()), | 615 ASSERT_THAT(observer().SuggestionsForCategory(articles_category()), |
| 616 SizeIs(1)); | 616 SizeIs(1)); |
| 617 ASSERT_THAT(service->GetSuggestionsForTesting(articles_category()), | 617 ASSERT_THAT(service->GetSuggestionsForTesting(articles_category()), |
| 618 SizeIs(1)); | 618 SizeIs(1)); |
| 619 | 619 |
| 620 // The response contained a title, |kTestJsonDefaultCategoryTitle|. | 620 // The response contained a title, |kTestJsonDefaultCategoryTitle|. |
| 621 // Make sure we updated the title in the CategoryInfo. | 621 // Make sure we updated the title in the CategoryInfo. |
| 622 CategoryInfo info_with_title = service->GetCategoryInfo(articles_category()); | 622 CategoryInfo info_with_title = service->GetCategoryInfo(articles_category()); |
| 623 EXPECT_THAT(info_before.title(), Not(Eq(info_with_title.title()))); | 623 EXPECT_THAT(info_before.title(), Not(Eq(info_with_title.title()))); |
| 624 EXPECT_THAT(test_default_title, Eq(info_with_title.title())); | 624 EXPECT_THAT(test_default_title, Eq(info_with_title.title())); |
| 625 EXPECT_THAT(info_before.has_fetch_action(), Eq(true)); | 625 EXPECT_THAT(info_before.additional_action(), |
| 626 EXPECT_THAT(info_before.has_view_all_action(), Eq(false)); | 626 Eq(ContentSuggestionsAdditionalAction::FETCH)); |
| 627 EXPECT_THAT(info_before.show_if_empty(), Eq(true)); | 627 EXPECT_THAT(info_before.show_if_empty(), Eq(true)); |
| 628 } | 628 } |
| 629 | 629 |
| 630 TEST_F(RemoteSuggestionsProviderImplTest, MultipleCategories) { | 630 TEST_F(RemoteSuggestionsProviderImplTest, MultipleCategories) { |
| 631 auto service = MakeSuggestionsProvider(); | 631 auto service = MakeSuggestionsProvider(); |
| 632 std::string json_str = | 632 std::string json_str = |
| 633 MultiCategoryJsonBuilder() | 633 MultiCategoryJsonBuilder() |
| 634 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/1) | 634 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/1) |
| 635 .AddCategory({GetSuggestionN(1)}, /*remote_category_id=*/2) | 635 .AddCategory({GetSuggestionN(1)}, /*remote_category_id=*/2) |
| 636 .Build(); | 636 .Build(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 EXPECT_EQ(kSuggestionText, base::UTF16ToUTF8(suggestion.snippet_text())); | 671 EXPECT_EQ(kSuggestionText, base::UTF16ToUTF8(suggestion.snippet_text())); |
| 672 EXPECT_EQ(GetDefaultCreationTime(), suggestion.publish_date()); | 672 EXPECT_EQ(GetDefaultCreationTime(), suggestion.publish_date()); |
| 673 EXPECT_EQ(kSuggestionPublisherName, | 673 EXPECT_EQ(kSuggestionPublisherName, |
| 674 base::UTF16ToUTF8(suggestion.publisher_name())); | 674 base::UTF16ToUTF8(suggestion.publisher_name())); |
| 675 } | 675 } |
| 676 } | 676 } |
| 677 | 677 |
| 678 TEST_F(RemoteSuggestionsProviderImplTest, ArticleCategoryInfo) { | 678 TEST_F(RemoteSuggestionsProviderImplTest, ArticleCategoryInfo) { |
| 679 auto service = MakeSuggestionsProvider(); | 679 auto service = MakeSuggestionsProvider(); |
| 680 CategoryInfo article_info = service->GetCategoryInfo(articles_category()); | 680 CategoryInfo article_info = service->GetCategoryInfo(articles_category()); |
| 681 EXPECT_THAT(article_info.has_fetch_action(), Eq(true)); | 681 EXPECT_THAT(article_info.additional_action(), |
| 682 EXPECT_THAT(article_info.has_view_all_action(), Eq(false)); | 682 Eq(ContentSuggestionsAdditionalAction::FETCH)); |
| 683 EXPECT_THAT(article_info.show_if_empty(), Eq(true)); | 683 EXPECT_THAT(article_info.show_if_empty(), Eq(true)); |
| 684 } | 684 } |
| 685 | 685 |
| 686 TEST_F(RemoteSuggestionsProviderImplTest, ExperimentalCategoryInfo) { | 686 TEST_F(RemoteSuggestionsProviderImplTest, ExperimentalCategoryInfo) { |
| 687 auto service = MakeSuggestionsProvider(); | 687 auto service = MakeSuggestionsProvider(); |
| 688 std::string json_str = | 688 std::string json_str = |
| 689 MultiCategoryJsonBuilder() | 689 MultiCategoryJsonBuilder() |
| 690 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/1) | 690 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/1) |
| 691 .AddCategory({GetSuggestionN(1)}, kUnknownRemoteCategoryId) | 691 .AddCategory({GetSuggestionN(1)}, kUnknownRemoteCategoryId) |
| 692 .Build(); | 692 .Build(); |
| 693 // Load data with multiple categories so that a new experimental category gets | 693 // Load data with multiple categories so that a new experimental category gets |
| 694 // registered. | 694 // registered. |
| 695 LoadFromJSONString(service.get(), json_str); | 695 LoadFromJSONString(service.get(), json_str); |
| 696 | 696 |
| 697 CategoryInfo info = service->GetCategoryInfo(unknown_category()); | 697 CategoryInfo info = service->GetCategoryInfo(unknown_category()); |
| 698 EXPECT_THAT(info.has_fetch_action(), Eq(false)); | 698 EXPECT_THAT(info.additional_action(), |
| 699 EXPECT_THAT(info.has_view_all_action(), Eq(false)); | 699 Eq(ContentSuggestionsAdditionalAction::NONE)); |
| 700 EXPECT_THAT(info.show_if_empty(), Eq(false)); | 700 EXPECT_THAT(info.show_if_empty(), Eq(false)); |
| 701 } | 701 } |
| 702 | 702 |
| 703 TEST_F(RemoteSuggestionsProviderImplTest, AddRemoteCategoriesToCategoryRanker) { | 703 TEST_F(RemoteSuggestionsProviderImplTest, AddRemoteCategoriesToCategoryRanker) { |
| 704 auto mock_ranker = base::MakeUnique<MockCategoryRanker>(); | 704 auto mock_ranker = base::MakeUnique<MockCategoryRanker>(); |
| 705 MockCategoryRanker* raw_mock_ranker = mock_ranker.get(); | 705 MockCategoryRanker* raw_mock_ranker = mock_ranker.get(); |
| 706 SetCategoryRanker(std::move(mock_ranker)); | 706 SetCategoryRanker(std::move(mock_ranker)); |
| 707 std::string json_str = | 707 std::string json_str = |
| 708 MultiCategoryJsonBuilder() | 708 MultiCategoryJsonBuilder() |
| 709 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/11) | 709 .AddCategory({GetSuggestionN(0)}, /*remote_category_id=*/11) |
| (...skipping 1094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1804 EXPECT_CALL(scheduler, OnProviderActivated()); | 1804 EXPECT_CALL(scheduler, OnProviderActivated()); |
| 1805 // The scheduler should be notified of clearing the history. | 1805 // The scheduler should be notified of clearing the history. |
| 1806 EXPECT_CALL(scheduler, OnSuggestionsCleared()); | 1806 EXPECT_CALL(scheduler, OnSuggestionsCleared()); |
| 1807 | 1807 |
| 1808 service->SetRemoteSuggestionsScheduler(&scheduler); | 1808 service->SetRemoteSuggestionsScheduler(&scheduler); |
| 1809 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, | 1809 service->OnStatusChanged(RemoteSuggestionsStatus::ENABLED_AND_SIGNED_OUT, |
| 1810 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); | 1810 RemoteSuggestionsStatus::ENABLED_AND_SIGNED_IN); |
| 1811 } | 1811 } |
| 1812 | 1812 |
| 1813 } // namespace ntp_snippets | 1813 } // namespace ntp_snippets |
| OLD | NEW |