| 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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 108 } |
| 109 if (category->suggestions[0]->url().spec() != url) { | 109 if (category->suggestions[0]->url().spec() != url) { |
| 110 *result_listener << "unexpected url, got: " | 110 *result_listener << "unexpected url, got: " |
| 111 << category->suggestions[0]->url().spec(); | 111 << category->suggestions[0]->url().spec(); |
| 112 return false; | 112 return false; |
| 113 } | 113 } |
| 114 return true; | 114 return true; |
| 115 } | 115 } |
| 116 | 116 |
| 117 MATCHER(IsCategoryInfoForArticles, "") { | 117 MATCHER(IsCategoryInfoForArticles, "") { |
| 118 if (!arg.has_more_action()) { | 118 if (!arg.has_fetch_action()) { |
| 119 *result_listener << "missing expected has_more_action"; | 119 *result_listener << "missing expected has_fetc_action"; |
| 120 return false; | |
| 121 } | |
| 122 if (!arg.has_reload_action()) { | |
| 123 *result_listener << "missing expected has_reload_action"; | |
| 124 return false; | 120 return false; |
| 125 } | 121 } |
| 126 if (arg.has_view_all_action()) { | 122 if (arg.has_view_all_action()) { |
| 127 *result_listener << "unexpected has_view_all_action"; | 123 *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 } |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 ASSERT_THAT(fetched_categories->size(), Eq(2u)); | 547 ASSERT_THAT(fetched_categories->size(), Eq(2u)); |
| 552 for (const auto& category : *fetched_categories) { | 548 for (const auto& category : *fetched_categories) { |
| 553 const auto& articles = category.suggestions; | 549 const auto& articles = category.suggestions; |
| 554 if (category.category.IsKnownCategory(KnownCategories::ARTICLES)) { | 550 if (category.category.IsKnownCategory(KnownCategories::ARTICLES)) { |
| 555 ASSERT_THAT(articles.size(), Eq(1u)); | 551 ASSERT_THAT(articles.size(), Eq(1u)); |
| 556 EXPECT_THAT(articles[0]->url().spec(), Eq("http://localhost/foobar")); | 552 EXPECT_THAT(articles[0]->url().spec(), Eq("http://localhost/foobar")); |
| 557 EXPECT_THAT(category.info, IsCategoryInfoForArticles()); | 553 EXPECT_THAT(category.info, IsCategoryInfoForArticles()); |
| 558 } else if (category.category == Category::FromRemoteCategory(2)) { | 554 } else if (category.category == Category::FromRemoteCategory(2)) { |
| 559 ASSERT_THAT(articles.size(), Eq(1u)); | 555 ASSERT_THAT(articles.size(), Eq(1u)); |
| 560 EXPECT_THAT(articles[0]->url().spec(), Eq("http://localhost/foo2")); | 556 EXPECT_THAT(articles[0]->url().spec(), Eq("http://localhost/foo2")); |
| 561 EXPECT_THAT(category.info.has_more_action(), Eq(true)); | 557 EXPECT_THAT(category.info.has_fetch_action(), Eq(true)); |
| 562 EXPECT_THAT(category.info.has_reload_action(), Eq(true)); | |
| 563 EXPECT_THAT(category.info.has_view_all_action(), Eq(false)); | 558 EXPECT_THAT(category.info.has_view_all_action(), Eq(false)); |
| 564 EXPECT_THAT(category.info.show_if_empty(), Eq(false)); | 559 EXPECT_THAT(category.info.show_if_empty(), Eq(false)); |
| 565 } else { | 560 } else { |
| 566 FAIL() << "unknown category ID " << category.category.id(); | 561 FAIL() << "unknown category ID " << category.category.id(); |
| 567 } | 562 } |
| 568 } | 563 } |
| 569 | 564 |
| 570 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); | 565 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); |
| 571 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); | 566 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); |
| 572 EXPECT_THAT(histogram_tester().GetAllSamples( | 567 EXPECT_THAT(histogram_tester().GetAllSamples( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 net::URLRequestStatus::SUCCESS); | 599 net::URLRequestStatus::SUCCESS); |
| 605 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories; | 600 RemoteSuggestionsFetcher::OptionalFetchedCategories fetched_categories; |
| 606 EXPECT_CALL(mock_callback(), Run(IsSuccess(), _)) | 601 EXPECT_CALL(mock_callback(), Run(IsSuccess(), _)) |
| 607 .WillOnce(MoveArgument1PointeeTo(&fetched_categories)); | 602 .WillOnce(MoveArgument1PointeeTo(&fetched_categories)); |
| 608 snippets_fetcher().FetchSnippets( | 603 snippets_fetcher().FetchSnippets( |
| 609 test_params(), ToSnippetsAvailableCallback(&mock_callback())); | 604 test_params(), ToSnippetsAvailableCallback(&mock_callback())); |
| 610 FastForwardUntilNoTasksRemain(); | 605 FastForwardUntilNoTasksRemain(); |
| 611 | 606 |
| 612 ASSERT_TRUE(fetched_categories); | 607 ASSERT_TRUE(fetched_categories); |
| 613 ASSERT_THAT(fetched_categories->size(), Eq(1u)); | 608 ASSERT_THAT(fetched_categories->size(), Eq(1u)); |
| 614 EXPECT_THAT(fetched_categories->front().info.has_more_action(), Eq(false)); | 609 EXPECT_THAT(fetched_categories->front().info.has_fetch_action(), Eq(false)); |
| 615 EXPECT_THAT(fetched_categories->front().info.title(), | 610 EXPECT_THAT(fetched_categories->front().info.title(), |
| 616 Eq(base::UTF8ToUTF16("Articles for Me"))); | 611 Eq(base::UTF8ToUTF16("Articles for Me"))); |
| 617 } | 612 } |
| 618 | 613 |
| 619 TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ExclusiveCategoryOnly) { | 614 TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ExclusiveCategoryOnly) { |
| 620 const std::string kJsonStr = | 615 const std::string kJsonStr = |
| 621 "{\"categories\" : [{" | 616 "{\"categories\" : [{" |
| 622 " \"id\": 1," | 617 " \"id\": 1," |
| 623 " \"localizedTitle\": \"Articles for You\"," | 618 " \"localizedTitle\": \"Articles for You\"," |
| 624 " \"suggestions\" : [{" | 619 " \"suggestions\" : [{" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 922 fetched_categories) { | 917 fetched_categories) { |
| 923 if (fetched_categories) { | 918 if (fetched_categories) { |
| 924 // Matchers above aren't any more precise than this, so this is sufficient | 919 // Matchers above aren't any more precise than this, so this is sufficient |
| 925 // for test-failure diagnostics. | 920 // for test-failure diagnostics. |
| 926 return os << "list with " << fetched_categories->size() << " elements"; | 921 return os << "list with " << fetched_categories->size() << " elements"; |
| 927 } | 922 } |
| 928 return os << "null"; | 923 return os << "null"; |
| 929 } | 924 } |
| 930 | 925 |
| 931 } // namespace ntp_snippets | 926 } // namespace ntp_snippets |
| OLD | NEW |