Index: components/ntp_snippets/ntp_snippets_fetcher_unittest.cc |
diff --git a/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc b/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc |
index de2e1ccd3bf94f7e2f2fecab6c5213ee85228574..2467e2316689ab26298a9dc63816eb0824da645a 100644 |
--- a/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc |
+++ b/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc |
@@ -179,6 +179,7 @@ class NTPSnippetsFetcherTest : public testing::Test { |
snippets_fetcher_->SetTickClockForTesting( |
mock_task_runner_->GetMockTickClock()); |
test_hosts_.insert("www.somehost.com"); |
+ test_excluded_.insert("1234567890"); |
tschumann
2016/08/24 16:56:19
nit: ids are now in hex format -- might be nice to
|
// Increase initial time such that ticks are non-zero. |
mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); |
} |
@@ -191,6 +192,7 @@ class NTPSnippetsFetcherTest : public testing::Test { |
const std::string& test_lang() const { return test_lang_; } |
const GURL& test_url() { return test_url_; } |
const std::set<std::string>& test_hosts() const { return test_hosts_; } |
+ const std::set<std::string>& test_excluded() const { return test_excluded_; } |
base::HistogramTester& histogram_tester() { return histogram_tester_; } |
void InitFakeURLFetcherFactory() { |
@@ -228,6 +230,7 @@ class NTPSnippetsFetcherTest : public testing::Test { |
const std::string test_lang_; |
const GURL test_url_; |
std::set<std::string> test_hosts_; |
+ std::set<std::string> test_excluded_; |
base::HistogramTester histogram_tester_; |
DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest); |
@@ -255,6 +258,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) { |
params.only_return_personalized_results = true; |
params.user_locale = "en"; |
params.host_restricts = {"chromium.org"}; |
+ params.excluded_ids = {"1234567890"}; |
params.count_to_fetch = 25; |
params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; |
@@ -302,6 +306,9 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) { |
" \"uiLanguage\": \"en\"," |
" \"regularlyVisitedHostNames\": [" |
" \"chromium.org\"" |
+ " ]," |
+ " \"excludedSuggestionIds\": [" |
+ " \"1234567890\"" |
" ]" |
"}")); |
} |
@@ -311,6 +318,7 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { |
params.only_return_personalized_results = false; |
params.host_restricts = {}; |
params.count_to_fetch = 10; |
+ params.excluded_ids = {}; |
params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; |
EXPECT_THAT(params.BuildRequest(), |
@@ -347,7 +355,8 @@ TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { |
params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; |
EXPECT_THAT(params.BuildRequest(), |
EqualsJSON("{" |
- " \"regularlyVisitedHostNames\": []" |
+ " \"regularlyVisitedHostNames\": []," |
+ " \"excludedSuggestionIds\": []" |
"}")); |
} |
@@ -378,6 +387,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) { |
net::URLRequestStatus::SUCCESS); |
EXPECT_CALL(mock_callback(), Run(IsSingleArticle("http://localhost/foobar"))); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -413,6 +423,7 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ShouldFetchSuccessfully) { |
net::URLRequestStatus::SUCCESS); |
EXPECT_CALL(mock_callback(), Run(IsSingleArticle("http://localhost/foobar"))); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -465,6 +476,7 @@ TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ServerCategories) { |
EXPECT_CALL(mock_callback(), Run(_)) |
.WillOnce(WithArg<0>(MovePointeeTo(&snippets))); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*force_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -505,6 +517,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) { |
net::URLRequestStatus::SUCCESS); |
EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList())); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -522,6 +535,7 @@ TEST_F(NTPSnippetsFetcherHostRestrictedTest, ShouldReportEmptyHostsError) { |
EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); |
snippets_fetcher().FetchSnippetsFromHosts(/*hosts=*/std::set<std::string>(), |
/*language_code=*/"en-US", |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -543,7 +557,8 @@ TEST_F(NTPSnippetsFetcherHostRestrictedTest, ShouldReportEmptyHostsError) { |
TEST_F(NTPSnippetsFetcherHostRestrictedTest, ShouldRestrictToHosts) { |
net::TestURLFetcherFactory test_url_fetcher_factory; |
snippets_fetcher().FetchSnippetsFromHosts( |
- {"www.somehost1.com", "www.somehost2.com"}, test_lang(), /*count=*/17, |
+ {"www.somehost1.com", "www.somehost2.com"}, test_lang(), test_excluded(), |
+ /*count=*/17, |
/*interactive_request=*/true); |
net::TestURLFetcher* fetcher = test_url_fetcher_factory.GetFetcherByID(0); |
ASSERT_THAT(fetcher, NotNull()); |
@@ -575,6 +590,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) { |
net::URLRequestStatus::FAILED); |
EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -596,6 +612,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) { |
net::URLRequestStatus::SUCCESS); |
EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -616,6 +633,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) { |
net::URLRequestStatus::SUCCESS); |
EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -638,6 +656,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) { |
net::URLRequestStatus::SUCCESS); |
EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -657,6 +676,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) { |
net::URLRequestStatus::SUCCESS); |
EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -677,6 +697,7 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) { |
InitFakeURLFetcherFactory(); |
EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |
@@ -688,11 +709,13 @@ TEST_F(NTPSnippetsFetcherTest, ShouldCancelOngoingFetch) { |
net::URLRequestStatus::SUCCESS); |
EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList())); |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
// Second call to FetchSnippetsFromHosts() overrides/cancels the previous. |
// Callback is expected to be called once. |
snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), |
+ test_excluded(), |
/*count=*/1, |
/*interactive_request=*/true); |
FastForwardUntilNoTasksRemain(); |