| 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/ntp_snippets_fetcher.h" | 5 #include "components/ntp_snippets/remote/ntp_snippets_fetcher.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 " \"title\" : \"Foo Barred from Baz\"," | 677 " \"title\" : \"Foo Barred from Baz\"," |
| 678 " \"snippet\" : \"...\"," | 678 " \"snippet\" : \"...\"," |
| 679 " \"fullPageUrl\" : \"http://localhost/foo2\"," | 679 " \"fullPageUrl\" : \"http://localhost/foo2\"," |
| 680 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," | 680 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," |
| 681 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," | 681 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," |
| 682 " \"attribution\" : \"Foo News\"," | 682 " \"attribution\" : \"Foo News\"," |
| 683 " \"imageUrl\" : \"http://localhost/foo2.jpg\"," | 683 " \"imageUrl\" : \"http://localhost/foo2.jpg\"," |
| 684 " \"ampUrl\" : \"http://localhost/amp\"," | 684 " \"ampUrl\" : \"http://localhost/amp\"," |
| 685 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " | 685 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
| 686 " }]" | 686 " }]" |
| 687 "}, {" |
| 688 " \"id\": 3," |
| 689 " \"localizedTitle\": \"Articles for Anybody\"," |
| 690 " \"suggestions\" : [{" |
| 691 " \"ids\" : [\"http://localhost/foo3\"]," |
| 692 " \"title\" : \"Foo Barred from Baz\"," |
| 693 " \"snippet\" : \"...\"," |
| 694 " \"fullPageUrl\" : \"http://localhost/foo3\"," |
| 695 " \"creationTime\" : \"2016-06-30T11:01:37.000Z\"," |
| 696 " \"expirationTime\" : \"2016-07-01T11:01:37.000Z\"," |
| 697 " \"attribution\" : \"Foo News\"," |
| 698 " \"imageUrl\" : \"http://localhost/foo3.jpg\"," |
| 699 " \"ampUrl\" : \"http://localhost/amp\"," |
| 700 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " |
| 701 " }]" |
| 687 "}]}"; | 702 "}]}"; |
| 688 SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, | 703 SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| 689 net::URLRequestStatus::SUCCESS); | 704 net::URLRequestStatus::SUCCESS); |
| 690 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories; | 705 NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories; |
| 691 EXPECT_CALL(mock_callback(), Run(_)) | 706 EXPECT_CALL(mock_callback(), Run(_)) |
| 692 .WillOnce(WithArg<0>(MovePointeeTo(&fetched_categories))); | 707 .WillOnce(WithArg<0>(MovePointeeTo(&fetched_categories))); |
| 693 | 708 |
| 694 NTPSnippetsFetcher::Params params = test_params(); | 709 NTPSnippetsFetcher::Params params = test_params(); |
| 695 params.exclusive_category = base::Optional<Category>( | 710 params.exclusive_category = base::Optional<Category>( |
| 696 CategoryFactory().FromKnownCategory(KnownCategories::ARTICLES)); | 711 CategoryFactory().FromRemoteCategory(2)); |
| 697 snippets_fetcher().FetchSnippets( | 712 snippets_fetcher().FetchSnippets( |
| 698 params, ToSnippetsAvailableCallback(&mock_callback())); | 713 params, ToSnippetsAvailableCallback(&mock_callback())); |
| 699 FastForwardUntilNoTasksRemain(); | 714 FastForwardUntilNoTasksRemain(); |
| 700 | 715 |
| 701 ASSERT_TRUE(fetched_categories); | 716 ASSERT_TRUE(fetched_categories); |
| 702 ASSERT_THAT(fetched_categories->size(), Eq(1u)); | 717 ASSERT_THAT(fetched_categories->size(), Eq(1u)); |
| 703 const auto& category = (*fetched_categories)[0]; | 718 const auto& category = (*fetched_categories)[0]; |
| 704 EXPECT_THAT(category.category.id(), | 719 EXPECT_THAT(category.category.id(), |
| 705 Eq(static_cast<int>(KnownCategories::ARTICLES))); | 720 Eq(CategoryFactory().FromRemoteCategory(2).id())); |
| 706 ASSERT_THAT(category.snippets.size(), Eq(1u)); | 721 ASSERT_THAT(category.snippets.size(), Eq(1u)); |
| 707 EXPECT_THAT(category.snippets[0]->best_source().url.spec(), | 722 EXPECT_THAT(category.snippets[0]->best_source().url.spec(), |
| 708 Eq("http://localhost/foobar")); | 723 Eq("http://localhost/foo2")); |
| 709 } | 724 } |
| 710 | 725 |
| 711 TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) { | 726 TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) { |
| 712 const std::string kJsonStr = "{\"recos\": []}"; | 727 const std::string kJsonStr = "{\"recos\": []}"; |
| 713 SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, | 728 SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK, |
| 714 net::URLRequestStatus::SUCCESS); | 729 net::URLRequestStatus::SUCCESS); |
| 715 EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList())); | 730 EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList())); |
| 716 snippets_fetcher().FetchSnippets( | 731 snippets_fetcher().FetchSnippets( |
| 717 test_params(), ToSnippetsAvailableCallback(&mock_callback())); | 732 test_params(), ToSnippetsAvailableCallback(&mock_callback())); |
| 718 FastForwardUntilNoTasksRemain(); | 733 FastForwardUntilNoTasksRemain(); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 const NTPSnippetsFetcher::OptionalFetchedCategories& fetched_categories) { | 907 const NTPSnippetsFetcher::OptionalFetchedCategories& fetched_categories) { |
| 893 if (fetched_categories) { | 908 if (fetched_categories) { |
| 894 // Matchers above aren't any more precise than this, so this is sufficient | 909 // Matchers above aren't any more precise than this, so this is sufficient |
| 895 // for test-failure diagnostics. | 910 // for test-failure diagnostics. |
| 896 return os << "list with " << fetched_categories->size() << " elements"; | 911 return os << "list with " << fetched_categories->size() << " elements"; |
| 897 } | 912 } |
| 898 return os << "null"; | 913 return os << "null"; |
| 899 } | 914 } |
| 900 | 915 |
| 901 } // namespace ntp_snippets | 916 } // namespace ntp_snippets |
| OLD | NEW |