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

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: Remove LOG(ERROR) dbg statment 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..4eb5814cb60a1ec83023f99a189b7e9ec22ed3f6 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(_, NTPSnippetsFetcher::FetchResult::SUCCESS))
.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(_, NTPSnippetsFetcher::FetchResult::SUCCESS))
.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(_, NTPSnippetsFetcher::FetchResult::SUCCESS))
.WillOnce(MoveArgumentPointeeTo(&fetched_categories));
NTPSnippetsFetcher::Params params = test_params();
@@ -892,7 +896,8 @@ 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(),
+ NTPSnippetsFetcher::FetchResult::SUCCESS));
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -940,7 +945,9 @@ 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()),
+ NTPSnippetsFetcher::FetchResult::SUCCESS))
+ .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 +958,10 @@ 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()),
+ NTPSnippetsFetcher::FetchResult::URL_REQUEST_STATUS_ERROR))
+ .Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -971,7 +981,9 @@ 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()),
+ NTPSnippetsFetcher::FetchResult::HTTP_ERROR))
+ .Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -990,7 +1002,9 @@ 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()),
+ NTPSnippetsFetcher::FetchResult::SUCCESS))
+ .Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -1011,7 +1025,9 @@ 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()),
+ NTPSnippetsFetcher::FetchResult::SUCCESS))
+ .Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -1029,7 +1045,9 @@ 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()),
+ NTPSnippetsFetcher::FetchResult::SUCCESS))
+ .Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -1048,7 +1066,9 @@ 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()),
+ NTPSnippetsFetcher::FetchResult::SUCCESS))
+ .Times(1);
snippets_fetcher().FetchSnippets(
test_params(), ToSnippetsAvailableCallback(&mock_callback()));
FastForwardUntilNoTasksRemain();
@@ -1058,7 +1078,9 @@ 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(),
+ NTPSnippetsFetcher::FetchResult::SUCCESS))
+ .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