Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Unified Diff: components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc

Issue 2549163002: RemoteContentSuggestions: Stores the time of the last successful background fetch in a pref (Closed)
Patch Set: Add a comment for the new pref Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc
diff --git a/components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc b/components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc
index c02ffa4753d5056f26eddc47663323831c844361..8dcc632f32320ac7a245cac155c3e0b6e3e7c297 100644
--- a/components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc
+++ b/components/ntp_snippets/remote/ntp_snippets_fetcher_unittest.cc
@@ -149,13 +149,15 @@ class MockSnippetsAvailableCallback {
public:
// Workaround for gMock's lack of support for movable arguments.
void WrappedRun(
- NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories) {
- Run(&fetched_categories);
+ NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories,
+ NTPSnippetsFetcher::FetchResult fetch_result) {
+ Run(&fetched_categories, fetch_result);
}
- MOCK_METHOD1(
+ MOCK_METHOD2(
Run,
- void(NTPSnippetsFetcher::OptionalFetchedCategories* fetched_categories));
+ void(NTPSnippetsFetcher::OptionalFetchedCategories* fetched_categories,
+ NTPSnippetsFetcher::FetchResult fetch_result));
};
// Factory for FakeURLFetcher objects that always generate errors.
@@ -610,10 +612,10 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) {
"}]}";
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
- EXPECT_CALL(
- mock_callback(),
- Run(AllOf(IsSingleArticle("http://localhost/foobar"),
- FirstCategoryHasInfo(IsCategoryInfoForArticles()))));
+ EXPECT_CALL(mock_callback(),
+ Run(AllOf(IsSingleArticle("http://localhost/foobar"),
+ FirstCategoryHasInfo(IsCategoryInfoForArticles())),
+ NTPSnippetsFetcher::FetchResult::SUCCESS));
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -649,7 +651,8 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ShouldFetchSuccessfully) {
net::URLRequestStatus::SUCCESS);
EXPECT_CALL(mock_callback(),
Run(AllOf(IsSingleArticle("http://localhost/foobar"),
- FirstCategoryHasInfo(IsCategoryInfoForArticles()))));
+ FirstCategoryHasInfo(IsCategoryInfoForArticles())),
+ NTPSnippetsFetcher::FetchResult::SUCCESS));
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -671,7 +674,8 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, EmptyCategoryIsOK) {
"}]}";
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
- EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList()));
+ EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList(),
+ NTPSnippetsFetcher::FetchResult::SUCCESS));
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -722,7 +726,7 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ServerCategories) {
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories;
- EXPECT_CALL(mock_callback(), Run(_))
+ EXPECT_CALL(mock_callback(), Run(_, _))
Marc Treib 2016/12/07 14:42:13 I think this should be an actual status, also in t
markusheintz_ 2016/12/08 09:47:41 Done.
.WillOnce(MoveArgumentPointeeTo(&fetched_categories));
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
@@ -784,7 +788,7 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest,
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories;
- EXPECT_CALL(mock_callback(), Run(_))
+ EXPECT_CALL(mock_callback(), Run(_, _))
.WillOnce(MoveArgumentPointeeTo(&fetched_categories));
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
@@ -848,7 +852,7 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ExclusiveCategoryOnly) {
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
NTPSnippetsFetcher::OptionalFetchedCategories fetched_categories;
- EXPECT_CALL(mock_callback(), Run(_))
+ EXPECT_CALL(mock_callback(), Run(_, _))
.WillOnce(MoveArgumentPointeeTo(&fetched_categories));
NTPSnippetsFetcher::Params params = test_params();
@@ -892,7 +896,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) {
const std::string kJsonStr = "{\"recos\": []}";
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
- EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList()));
+ EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList(), _));
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -940,7 +944,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldRestrictToHosts) {
// call to the delegate that usually happens on |Start|.
// Without the call to the delegate, it leaks the request that owns itself.
ASSERT_THAT(fetcher->delegate(), NotNull());
- EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
+ EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()), _)).Times(1);
// An 4XX response needs the least configuration to successfully invoke the
// callback properly as the results are not important in this test.
fetcher->set_response_code(net::HTTP_NOT_FOUND);
@@ -951,7 +955,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldRestrictToHosts) {
TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) {
SetFakeResponse(/*response_data=*/std::string(), net::HTTP_NOT_FOUND,
net::URLRequestStatus::FAILED);
- EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
+ EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()), _)).Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -971,7 +975,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) {
TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) {
SetFakeResponse(/*response_data=*/std::string(), net::HTTP_NOT_FOUND,
net::URLRequestStatus::SUCCESS);
- EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
+ EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()), _)).Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -990,7 +994,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) {
const std::string kInvalidJsonStr = "{ \"recos\": []";
SetFakeResponse(/*response_data=*/kInvalidJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
- EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
+ EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()), _)).Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -1011,7 +1015,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) {
TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) {
SetFakeResponse(/*response_data=*/std::string(), net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
- EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
+ EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()), _)).Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -1029,7 +1033,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) {
"{\"recos\": [{ \"contentInfo\": { \"foo\" : \"bar\" }}]}";
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
- EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
+ EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()), _)).Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -1048,7 +1052,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) {
// hard-to-reproduce test failures.
TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) {
InitFakeURLFetcherFactory();
- EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
+ EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()), _)).Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -1058,7 +1062,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldProcessConcurrentFetches) {
const std::string kJsonStr = "{ \"recos\": [] }";
SetFakeResponse(/*response_data=*/kJsonStr, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
- EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList())).Times(5);
+ EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList(), _)).Times(5);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
// More calls to FetchSnippets() do not interrupt the previous.

Powered by Google App Engine
This is Rietveld 408576698