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/ntp_snippets/remote/remote_suggestions_fetcher.h" | 5 #include "components/ntp_snippets/remote/remote_suggestions_fetcher.h" |
6 | 6 |
7 #include <deque> | 7 #include <deque> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <utility> | 10 #include <utility> |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 if (category->suggestions[0]->url().spec() != url) { | 113 if (category->suggestions[0]->url().spec() != url) { |
114 *result_listener << "unexpected url, got: " | 114 *result_listener << "unexpected url, got: " |
115 << category->suggestions[0]->url().spec(); | 115 << category->suggestions[0]->url().spec(); |
116 return false; | 116 return false; |
117 } | 117 } |
118 return true; | 118 return true; |
119 } | 119 } |
120 | 120 |
121 MATCHER(IsCategoryInfoForArticles, "") { | 121 MATCHER(IsCategoryInfoForArticles, "") { |
122 if (!arg.has_fetch_action()) { | 122 if (arg.additional_action() != ContentSuggestionsAdditionalAction::FETCH) { |
123 *result_listener << "missing expected has_fetc_action"; | 123 *result_listener << "missing expected FETCH action"; |
124 return false; | |
125 } | |
126 if (arg.has_view_all_action()) { | |
127 *result_listener << "unexpected has_view_all_action"; | |
128 return false; | 124 return false; |
129 } | 125 } |
130 if (!arg.show_if_empty()) { | 126 if (!arg.show_if_empty()) { |
131 *result_listener << "missing expected show_if_empty"; | 127 *result_listener << "missing expected show_if_empty"; |
132 return false; | 128 return false; |
133 } | 129 } |
134 return true; | 130 return true; |
135 } | 131 } |
136 | 132 |
137 MATCHER_P(FirstCategoryHasInfo, info_matcher, "") { | 133 MATCHER_P(FirstCategoryHasInfo, info_matcher, "") { |
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 ASSERT_THAT(fetched_categories->size(), Eq(2u)); | 663 ASSERT_THAT(fetched_categories->size(), Eq(2u)); |
668 for (const auto& category : *fetched_categories) { | 664 for (const auto& category : *fetched_categories) { |
669 const auto& articles = category.suggestions; | 665 const auto& articles = category.suggestions; |
670 if (category.category.IsKnownCategory(KnownCategories::ARTICLES)) { | 666 if (category.category.IsKnownCategory(KnownCategories::ARTICLES)) { |
671 ASSERT_THAT(articles.size(), Eq(1u)); | 667 ASSERT_THAT(articles.size(), Eq(1u)); |
672 EXPECT_THAT(articles[0]->url().spec(), Eq("http://localhost/foobar")); | 668 EXPECT_THAT(articles[0]->url().spec(), Eq("http://localhost/foobar")); |
673 EXPECT_THAT(category.info, IsCategoryInfoForArticles()); | 669 EXPECT_THAT(category.info, IsCategoryInfoForArticles()); |
674 } else if (category.category == Category::FromRemoteCategory(2)) { | 670 } else if (category.category == Category::FromRemoteCategory(2)) { |
675 ASSERT_THAT(articles.size(), Eq(1u)); | 671 ASSERT_THAT(articles.size(), Eq(1u)); |
676 EXPECT_THAT(articles[0]->url().spec(), Eq("http://localhost/foo2")); | 672 EXPECT_THAT(articles[0]->url().spec(), Eq("http://localhost/foo2")); |
677 EXPECT_THAT(category.info.has_fetch_action(), Eq(true)); | 673 EXPECT_THAT(category.info.additional_action(), |
678 EXPECT_THAT(category.info.has_view_all_action(), Eq(false)); | 674 Eq(ContentSuggestionsAdditionalAction::FETCH)); |
679 EXPECT_THAT(category.info.show_if_empty(), Eq(false)); | 675 EXPECT_THAT(category.info.show_if_empty(), Eq(false)); |
680 } else { | 676 } else { |
681 FAIL() << "unknown category ID " << category.category.id(); | 677 FAIL() << "unknown category ID " << category.category.id(); |
682 } | 678 } |
683 } | 679 } |
684 | 680 |
685 EXPECT_THAT(fetcher().last_status(), Eq("OK")); | 681 EXPECT_THAT(fetcher().last_status(), Eq("OK")); |
686 EXPECT_THAT(fetcher().last_json(), Eq(kJsonStr)); | 682 EXPECT_THAT(fetcher().last_json(), Eq(kJsonStr)); |
687 EXPECT_THAT(histogram_tester().GetAllSamples( | 683 EXPECT_THAT(histogram_tester().GetAllSamples( |
688 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), | 684 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), |
(...skipping 30 matching lines...) Expand all Loading... |
719 net::URLRequestStatus::SUCCESS); | 715 net::URLRequestStatus::SUCCESS); |
720 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories; | 716 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories; |
721 EXPECT_CALL(mock_callback(), Run(IsSuccess(), _)) | 717 EXPECT_CALL(mock_callback(), Run(IsSuccess(), _)) |
722 .WillOnce(MoveArgument1PointeeTo(&fetched_categories)); | 718 .WillOnce(MoveArgument1PointeeTo(&fetched_categories)); |
723 fetcher().FetchSnippets(test_params(), | 719 fetcher().FetchSnippets(test_params(), |
724 ToSnippetsAvailableCallback(&mock_callback())); | 720 ToSnippetsAvailableCallback(&mock_callback())); |
725 FastForwardUntilNoTasksRemain(); | 721 FastForwardUntilNoTasksRemain(); |
726 | 722 |
727 ASSERT_TRUE(fetched_categories); | 723 ASSERT_TRUE(fetched_categories); |
728 ASSERT_THAT(fetched_categories->size(), Eq(1u)); | 724 ASSERT_THAT(fetched_categories->size(), Eq(1u)); |
729 EXPECT_THAT(fetched_categories->front().info.has_fetch_action(), Eq(false)); | 725 EXPECT_THAT(fetched_categories->front().info.additional_action(), |
| 726 Eq(ContentSuggestionsAdditionalAction::NONE)); |
730 EXPECT_THAT(fetched_categories->front().info.title(), | 727 EXPECT_THAT(fetched_categories->front().info.title(), |
731 Eq(base::UTF8ToUTF16("Articles for Me"))); | 728 Eq(base::UTF8ToUTF16("Articles for Me"))); |
732 } | 729 } |
733 | 730 |
734 TEST_F(RemoteSuggestionsSignedOutFetcherTest, ExclusiveCategoryOnly) { | 731 TEST_F(RemoteSuggestionsSignedOutFetcherTest, ExclusiveCategoryOnly) { |
735 const std::string kJsonStr = | 732 const std::string kJsonStr = |
736 "{\"categories\" : [{" | 733 "{\"categories\" : [{" |
737 " \"id\": 1," | 734 " \"id\": 1," |
738 " \"localizedTitle\": \"Articles for You\"," | 735 " \"localizedTitle\": \"Articles for You\"," |
739 " \"suggestions\" : [{" | 736 " \"suggestions\" : [{" |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 fetched_categories) { | 1034 fetched_categories) { |
1038 if (fetched_categories) { | 1035 if (fetched_categories) { |
1039 // Matchers above aren't any more precise than this, so this is sufficient | 1036 // Matchers above aren't any more precise than this, so this is sufficient |
1040 // for test-failure diagnostics. | 1037 // for test-failure diagnostics. |
1041 return os << "list with " << fetched_categories->size() << " elements"; | 1038 return os << "list with " << fetched_categories->size() << " elements"; |
1042 } | 1039 } |
1043 return os << "null"; | 1040 return os << "null"; |
1044 } | 1041 } |
1045 | 1042 |
1046 } // namespace ntp_snippets | 1043 } // namespace ntp_snippets |
OLD | NEW |