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

Side by Side Diff: components/ntp_snippets/ntp_snippets_fetcher_unittest.cc

Issue 2274953002: Inform server of dismissed articles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: JSON comma. Created 4 years, 3 months 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 unified diff | Download patch
OLDNEW
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/ntp_snippets_fetcher.h" 5 #include "components/ntp_snippets/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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 new net::TestURLRequestContextGetter(mock_task_runner_.get())), 172 new net::TestURLRequestContextGetter(mock_task_runner_.get())),
173 pref_service_.get(), &category_factory_, base::Bind(&ParseJsonDelayed), 173 pref_service_.get(), &category_factory_, base::Bind(&ParseJsonDelayed),
174 /*is_stable_channel=*/true); 174 /*is_stable_channel=*/true);
175 175
176 snippets_fetcher_->SetCallback( 176 snippets_fetcher_->SetCallback(
177 base::Bind(&MockSnippetsAvailableCallback::WrappedRun, 177 base::Bind(&MockSnippetsAvailableCallback::WrappedRun,
178 base::Unretained(&mock_callback_))); 178 base::Unretained(&mock_callback_)));
179 snippets_fetcher_->SetTickClockForTesting( 179 snippets_fetcher_->SetTickClockForTesting(
180 mock_task_runner_->GetMockTickClock()); 180 mock_task_runner_->GetMockTickClock());
181 test_hosts_.insert("www.somehost.com"); 181 test_hosts_.insert("www.somehost.com");
182 test_excluded_.insert("1234567890");
182 // Increase initial time such that ticks are non-zero. 183 // Increase initial time such that ticks are non-zero.
183 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234)); 184 mock_task_runner_->FastForwardBy(base::TimeDelta::FromMilliseconds(1234));
184 } 185 }
185 186
186 NTPSnippetsFetcher& snippets_fetcher() { return *snippets_fetcher_; } 187 NTPSnippetsFetcher& snippets_fetcher() { return *snippets_fetcher_; }
187 MockSnippetsAvailableCallback& mock_callback() { return mock_callback_; } 188 MockSnippetsAvailableCallback& mock_callback() { return mock_callback_; }
188 void FastForwardUntilNoTasksRemain() { 189 void FastForwardUntilNoTasksRemain() {
189 mock_task_runner_->FastForwardUntilNoTasksRemain(); 190 mock_task_runner_->FastForwardUntilNoTasksRemain();
190 } 191 }
191 const std::string& test_lang() const { return test_lang_; } 192 const std::string& test_lang() const { return test_lang_; }
192 const GURL& test_url() { return test_url_; } 193 const GURL& test_url() { return test_url_; }
193 const std::set<std::string>& test_hosts() const { return test_hosts_; } 194 const std::set<std::string>& test_hosts() const { return test_hosts_; }
195 const std::set<std::string>& test_excluded() const { return test_excluded_; }
194 base::HistogramTester& histogram_tester() { return histogram_tester_; } 196 base::HistogramTester& histogram_tester() { return histogram_tester_; }
195 197
196 void InitFakeURLFetcherFactory() { 198 void InitFakeURLFetcherFactory() {
197 if (fake_url_fetcher_factory_) 199 if (fake_url_fetcher_factory_)
198 return; 200 return;
199 // Instantiation of factory automatically sets itself as URLFetcher's 201 // Instantiation of factory automatically sets itself as URLFetcher's
200 // factory. 202 // factory.
201 fake_url_fetcher_factory_.reset(new net::FakeURLFetcherFactory( 203 fake_url_fetcher_factory_.reset(new net::FakeURLFetcherFactory(
202 /*default_factory=*/&failing_url_fetcher_factory_)); 204 /*default_factory=*/&failing_url_fetcher_factory_));
203 } 205 }
(...skipping 17 matching lines...) Expand all
221 std::unique_ptr<AccountTrackerService> account_tracker_; 223 std::unique_ptr<AccountTrackerService> account_tracker_;
222 std::unique_ptr<SigninManagerBase> fake_signin_manager_; 224 std::unique_ptr<SigninManagerBase> fake_signin_manager_;
223 std::unique_ptr<OAuth2TokenService> fake_token_service_; 225 std::unique_ptr<OAuth2TokenService> fake_token_service_;
224 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_; 226 std::unique_ptr<NTPSnippetsFetcher> snippets_fetcher_;
225 std::unique_ptr<TestingPrefServiceSimple> pref_service_; 227 std::unique_ptr<TestingPrefServiceSimple> pref_service_;
226 CategoryFactory category_factory_; 228 CategoryFactory category_factory_;
227 MockSnippetsAvailableCallback mock_callback_; 229 MockSnippetsAvailableCallback mock_callback_;
228 const std::string test_lang_; 230 const std::string test_lang_;
229 const GURL test_url_; 231 const GURL test_url_;
230 std::set<std::string> test_hosts_; 232 std::set<std::string> test_hosts_;
233 std::set<std::string> test_excluded_;
231 base::HistogramTester histogram_tester_; 234 base::HistogramTester histogram_tester_;
232 235
233 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest); 236 DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest);
234 }; 237 };
235 238
236 class NTPSnippetsContentSuggestionsFetcherTest : public NTPSnippetsFetcherTest { 239 class NTPSnippetsContentSuggestionsFetcherTest : public NTPSnippetsFetcherTest {
237 public: 240 public:
238 NTPSnippetsContentSuggestionsFetcherTest() 241 NTPSnippetsContentSuggestionsFetcherTest()
239 : NTPSnippetsFetcherTest( 242 : NTPSnippetsFetcherTest(
240 GetFetcherUrl(kTestChromeContentSuggestionsUrlFormat), 243 GetFetcherUrl(kTestChromeContentSuggestionsUrlFormat),
241 {{"content_suggestions_backend", kContentSuggestionsServer}}) {} 244 {{"content_suggestions_backend", kContentSuggestionsServer}}) {}
242 }; 245 };
243 246
244 class NTPSnippetsFetcherHostRestrictedTest : public NTPSnippetsFetcherTest { 247 class NTPSnippetsFetcherHostRestrictedTest : public NTPSnippetsFetcherTest {
245 public: 248 public:
246 NTPSnippetsFetcherHostRestrictedTest() 249 NTPSnippetsFetcherHostRestrictedTest()
247 : NTPSnippetsFetcherTest( 250 : NTPSnippetsFetcherTest(
248 GetFetcherUrl(kTestChromeReaderUrlFormat), 251 GetFetcherUrl(kTestChromeReaderUrlFormat),
249 {{"fetching_host_restrict", "on"}}) {} 252 {{"fetching_host_restrict", "on"}}) {}
250 }; 253 };
251 254
252 TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) { 255 TEST_F(NTPSnippetsFetcherTest, BuildRequestAuthenticated) {
253 NTPSnippetsFetcher::RequestParams params; 256 NTPSnippetsFetcher::RequestParams params;
254 params.obfuscated_gaia_id = "0BFUSGAIA"; 257 params.obfuscated_gaia_id = "0BFUSGAIA";
255 params.only_return_personalized_results = true; 258 params.only_return_personalized_results = true;
256 params.user_locale = "en"; 259 params.user_locale = "en";
257 params.host_restricts = {"chromium.org"}; 260 params.host_restricts = {"chromium.org"};
261 params.excluded_ids = {"1234567890"};
258 params.count_to_fetch = 25; 262 params.count_to_fetch = 25;
259 263
260 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 264 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
261 EXPECT_THAT(params.BuildRequest(), 265 EXPECT_THAT(params.BuildRequest(),
262 EqualsJSON("{" 266 EqualsJSON("{"
263 " \"response_detail_level\": \"STANDARD\"," 267 " \"response_detail_level\": \"STANDARD\","
264 " \"obfuscated_gaia_id\": \"0BFUSGAIA\"," 268 " \"obfuscated_gaia_id\": \"0BFUSGAIA\","
265 " \"user_locale\": \"en\"," 269 " \"user_locale\": \"en\","
266 " \"advanced_options\": {" 270 " \"advanced_options\": {"
267 " \"local_scoring_params\": {" 271 " \"local_scoring_params\": {"
(...skipping 27 matching lines...) Expand all
295 " }" 299 " }"
296 " }" 300 " }"
297 "}")); 301 "}"));
298 302
299 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 303 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
300 EXPECT_THAT(params.BuildRequest(), 304 EXPECT_THAT(params.BuildRequest(),
301 EqualsJSON("{" 305 EqualsJSON("{"
302 " \"uiLanguage\": \"en\"," 306 " \"uiLanguage\": \"en\","
303 " \"regularlyVisitedHostNames\": [" 307 " \"regularlyVisitedHostNames\": ["
304 " \"chromium.org\"" 308 " \"chromium.org\""
309 " ],"
310 " \"excludedSuggestionIds\": ["
311 " \"1234567890\""
305 " ]" 312 " ]"
306 "}")); 313 "}"));
307 } 314 }
308 315
309 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) { 316 TEST_F(NTPSnippetsFetcherTest, BuildRequestUnauthenticated) {
310 NTPSnippetsFetcher::RequestParams params; 317 NTPSnippetsFetcher::RequestParams params;
311 params.only_return_personalized_results = false; 318 params.only_return_personalized_results = false;
312 params.host_restricts = {}; 319 params.host_restricts = {};
313 params.count_to_fetch = 10; 320 params.count_to_fetch = 10;
321 params.excluded_ids = {};
314 322
315 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API; 323 params.fetch_api = NTPSnippetsFetcher::CHROME_READER_API;
316 EXPECT_THAT(params.BuildRequest(), 324 EXPECT_THAT(params.BuildRequest(),
317 EqualsJSON("{" 325 EqualsJSON("{"
318 " \"response_detail_level\": \"STANDARD\"," 326 " \"response_detail_level\": \"STANDARD\","
319 " \"advanced_options\": {" 327 " \"advanced_options\": {"
320 " \"local_scoring_params\": {" 328 " \"local_scoring_params\": {"
321 " \"content_params\": {" 329 " \"content_params\": {"
322 " \"only_return_personalized_results\": false" 330 " \"only_return_personalized_results\": false"
323 " }," 331 " },"
(...skipping 16 matching lines...) Expand all
340 " \"global_scoring_params\": {" 348 " \"global_scoring_params\": {"
341 " \"num_to_return\": 10," 349 " \"num_to_return\": 10,"
342 " \"sort_type\": 1" 350 " \"sort_type\": 1"
343 " }" 351 " }"
344 " }" 352 " }"
345 "}")); 353 "}"));
346 354
347 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API; 355 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
348 EXPECT_THAT(params.BuildRequest(), 356 EXPECT_THAT(params.BuildRequest(),
349 EqualsJSON("{" 357 EqualsJSON("{"
350 " \"regularlyVisitedHostNames\": []" 358 " \"regularlyVisitedHostNames\": [],"
359 " \"excludedSuggestionIds\": []"
351 "}")); 360 "}"));
352 } 361 }
353 362
363 TEST_F(NTPSnippetsFetcherTest, BuildRequestExcludedIds) {
364 NTPSnippetsFetcher::RequestParams params;
365 params.only_return_personalized_results = false;
366 params.host_restricts = {};
367 params.count_to_fetch = 10;
368 for (int i = 0; i < 200; ++i) {
369 params.excluded_ids.insert(base::StringPrintf("%03d", i));
370 }
371
372 params.fetch_api = NTPSnippetsFetcher::CHROME_CONTENT_SUGGESTIONS_API;
373 EXPECT_THAT(params.BuildRequest(),
374 EqualsJSON("{"
375 " \"regularlyVisitedHostNames\": [],"
376 " \"excludedSuggestionIds\": ["
377 " \"000\", \"001\", \"002\", \"003\", \"004\","
378 " \"005\", \"006\", \"007\", \"008\", \"009\","
379 " \"010\", \"011\", \"012\", \"013\", \"014\","
380 " \"015\", \"016\", \"017\", \"018\", \"019\","
381 " \"020\", \"021\", \"022\", \"023\", \"024\","
382 " \"025\", \"026\", \"027\", \"028\", \"029\","
383 " \"030\", \"031\", \"032\", \"033\", \"034\","
384 " \"035\", \"036\", \"037\", \"038\", \"039\","
385 " \"040\", \"041\", \"042\", \"043\", \"044\","
386 " \"045\", \"046\", \"047\", \"048\", \"049\","
387 " \"050\", \"051\", \"052\", \"053\", \"054\","
388 " \"055\", \"056\", \"057\", \"058\", \"059\","
389 " \"060\", \"061\", \"062\", \"063\", \"064\","
390 " \"065\", \"066\", \"067\", \"068\", \"069\","
391 " \"070\", \"071\", \"072\", \"073\", \"074\","
392 " \"075\", \"076\", \"077\", \"078\", \"079\","
393 " \"080\", \"081\", \"082\", \"083\", \"084\","
394 " \"085\", \"086\", \"087\", \"088\", \"089\","
395 " \"090\", \"091\", \"092\", \"093\", \"094\","
396 " \"095\", \"096\", \"097\", \"098\", \"099\""
397 // Truncated to 100 entries, those lexically first.
Marc Treib 2016/08/25 11:41:44 "lexically first" is really just how it happens to
sfiera 2016/08/25 11:58:07 Done.
398 " ]"
399 "}"));
400 }
401
354 TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) { 402 TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) {
355 // The lack of registered baked in responses would cause any fetch to fail. 403 // The lack of registered baked in responses would cause any fetch to fail.
356 FastForwardUntilNoTasksRemain(); 404 FastForwardUntilNoTasksRemain();
357 EXPECT_THAT(histogram_tester().GetAllSamples( 405 EXPECT_THAT(histogram_tester().GetAllSamples(
358 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 406 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
359 IsEmpty()); 407 IsEmpty());
360 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 408 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
361 IsEmpty()); 409 IsEmpty());
362 EXPECT_THAT(snippets_fetcher().last_status(), IsEmpty()); 410 EXPECT_THAT(snippets_fetcher().last_status(), IsEmpty());
363 } 411 }
364 412
365 TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) { 413 TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) {
366 const std::string kJsonStr = 414 const std::string kJsonStr =
367 "{\"recos\": [{" 415 "{\"recos\": [{"
368 " \"contentInfo\": {" 416 " \"contentInfo\": {"
369 " \"url\" : \"http://localhost/foobar\"," 417 " \"url\" : \"http://localhost/foobar\","
370 " \"sourceCorpusInfo\" : [{" 418 " \"sourceCorpusInfo\" : [{"
371 " \"ampUrl\" : \"http://localhost/amp\"," 419 " \"ampUrl\" : \"http://localhost/amp\","
372 " \"corpusId\" : \"http://localhost/foobar\"," 420 " \"corpusId\" : \"http://localhost/foobar\","
373 " \"publisherData\": { \"sourceName\" : \"Foo News\" }" 421 " \"publisherData\": { \"sourceName\" : \"Foo News\" }"
374 " }]" 422 " }]"
375 " }" 423 " }"
376 "}]}"; 424 "}]}";
377 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK, 425 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK,
378 net::URLRequestStatus::SUCCESS); 426 net::URLRequestStatus::SUCCESS);
379 EXPECT_CALL(mock_callback(), Run(IsSingleArticle("http://localhost/foobar"))); 427 EXPECT_CALL(mock_callback(), Run(IsSingleArticle("http://localhost/foobar")));
380 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 428 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
429 test_excluded(),
381 /*count=*/1, 430 /*count=*/1,
382 /*interactive_request=*/true); 431 /*interactive_request=*/true);
383 FastForwardUntilNoTasksRemain(); 432 FastForwardUntilNoTasksRemain();
384 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); 433 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK"));
385 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); 434 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
386 EXPECT_THAT(histogram_tester().GetAllSamples( 435 EXPECT_THAT(histogram_tester().GetAllSamples(
387 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 436 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
388 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); 437 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
389 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 438 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
390 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs, 439 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs,
(...skipping 15 matching lines...) Expand all
406 " \"attribution\" : \"Foo News\"," 455 " \"attribution\" : \"Foo News\","
407 " \"imageUrl\" : \"http://localhost/foobar.jpg\"," 456 " \"imageUrl\" : \"http://localhost/foobar.jpg\","
408 " \"ampUrl\" : \"http://localhost/amp\"," 457 " \"ampUrl\" : \"http://localhost/amp\","
409 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " 458 " \"faviconUrl\" : \"http://localhost/favicon.ico\" "
410 " }]" 459 " }]"
411 "}]}"; 460 "}]}";
412 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK, 461 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK,
413 net::URLRequestStatus::SUCCESS); 462 net::URLRequestStatus::SUCCESS);
414 EXPECT_CALL(mock_callback(), Run(IsSingleArticle("http://localhost/foobar"))); 463 EXPECT_CALL(mock_callback(), Run(IsSingleArticle("http://localhost/foobar")));
415 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 464 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
465 test_excluded(),
416 /*count=*/1, 466 /*count=*/1,
417 /*interactive_request=*/true); 467 /*interactive_request=*/true);
418 FastForwardUntilNoTasksRemain(); 468 FastForwardUntilNoTasksRemain();
419 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); 469 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK"));
420 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); 470 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
421 EXPECT_THAT(histogram_tester().GetAllSamples( 471 EXPECT_THAT(histogram_tester().GetAllSamples(
422 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 472 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
423 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); 473 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
424 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 474 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
425 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs, 475 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 " \"ampUrl\" : \"http://localhost/amp\"," 508 " \"ampUrl\" : \"http://localhost/amp\","
459 " \"faviconUrl\" : \"http://localhost/favicon.ico\" " 509 " \"faviconUrl\" : \"http://localhost/favicon.ico\" "
460 " }]" 510 " }]"
461 "}]}"; 511 "}]}";
462 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK, 512 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK,
463 net::URLRequestStatus::SUCCESS); 513 net::URLRequestStatus::SUCCESS);
464 NTPSnippetsFetcher::OptionalSnippets snippets; 514 NTPSnippetsFetcher::OptionalSnippets snippets;
465 EXPECT_CALL(mock_callback(), Run(_)) 515 EXPECT_CALL(mock_callback(), Run(_))
466 .WillOnce(WithArg<0>(MovePointeeTo(&snippets))); 516 .WillOnce(WithArg<0>(MovePointeeTo(&snippets)));
467 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 517 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
518 test_excluded(),
468 /*count=*/1, 519 /*count=*/1,
469 /*force_request=*/true); 520 /*force_request=*/true);
470 FastForwardUntilNoTasksRemain(); 521 FastForwardUntilNoTasksRemain();
471 522
472 ASSERT_TRUE(snippets); 523 ASSERT_TRUE(snippets);
473 ASSERT_THAT(snippets->size(), Eq(2u)); 524 ASSERT_THAT(snippets->size(), Eq(2u));
474 for (const auto& category : *snippets) { 525 for (const auto& category : *snippets) {
475 const auto& articles = category.second; 526 const auto& articles = category.second;
476 switch (category.first.id()) { 527 switch (category.first.id()) {
477 case static_cast<int>(KnownCategories::ARTICLES): 528 case static_cast<int>(KnownCategories::ARTICLES):
(...skipping 20 matching lines...) Expand all
498 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs, 549 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs,
499 /*count=*/1))); 550 /*count=*/1)));
500 } 551 }
501 552
502 TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) { 553 TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfullyEmptyList) {
503 const std::string kJsonStr = "{\"recos\": []}"; 554 const std::string kJsonStr = "{\"recos\": []}";
504 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK, 555 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK,
505 net::URLRequestStatus::SUCCESS); 556 net::URLRequestStatus::SUCCESS);
506 EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList())); 557 EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList()));
507 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 558 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
559 test_excluded(),
508 /*count=*/1, 560 /*count=*/1,
509 /*interactive_request=*/true); 561 /*interactive_request=*/true);
510 FastForwardUntilNoTasksRemain(); 562 FastForwardUntilNoTasksRemain();
511 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); 563 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK"));
512 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); 564 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
513 EXPECT_THAT( 565 EXPECT_THAT(
514 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"), 566 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"),
515 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1))); 567 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
516 EXPECT_THAT(histogram_tester().GetAllSamples( 568 EXPECT_THAT(histogram_tester().GetAllSamples(
517 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 569 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
518 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); 570 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
519 } 571 }
520 572
521 TEST_F(NTPSnippetsFetcherHostRestrictedTest, ShouldReportEmptyHostsError) { 573 TEST_F(NTPSnippetsFetcherHostRestrictedTest, ShouldReportEmptyHostsError) {
522 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); 574 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
523 snippets_fetcher().FetchSnippetsFromHosts(/*hosts=*/std::set<std::string>(), 575 snippets_fetcher().FetchSnippetsFromHosts(/*hosts=*/std::set<std::string>(),
524 /*language_code=*/"en-US", 576 /*language_code=*/"en-US",
577 test_excluded(),
525 /*count=*/1, 578 /*count=*/1,
526 /*interactive_request=*/true); 579 /*interactive_request=*/true);
527 FastForwardUntilNoTasksRemain(); 580 FastForwardUntilNoTasksRemain();
528 EXPECT_THAT(snippets_fetcher().last_status(), 581 EXPECT_THAT(snippets_fetcher().last_status(),
529 Eq("Cannot fetch for empty hosts list.")); 582 Eq("Cannot fetch for empty hosts list."));
530 EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty()); 583 EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty());
531 EXPECT_THAT( 584 EXPECT_THAT(
532 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"), 585 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"),
533 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); 586 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
534 // This particular error gets triggered prior to fetching, so no fetch time 587 // This particular error gets triggered prior to fetching, so no fetch time
535 // or response should get recorded. 588 // or response should get recorded.
536 EXPECT_THAT(histogram_tester().GetAllSamples( 589 EXPECT_THAT(histogram_tester().GetAllSamples(
537 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 590 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
538 IsEmpty()); 591 IsEmpty());
539 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 592 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
540 IsEmpty()); 593 IsEmpty());
541 } 594 }
542 595
543 TEST_F(NTPSnippetsFetcherHostRestrictedTest, ShouldRestrictToHosts) { 596 TEST_F(NTPSnippetsFetcherHostRestrictedTest, ShouldRestrictToHosts) {
544 net::TestURLFetcherFactory test_url_fetcher_factory; 597 net::TestURLFetcherFactory test_url_fetcher_factory;
545 snippets_fetcher().FetchSnippetsFromHosts( 598 snippets_fetcher().FetchSnippetsFromHosts(
546 {"www.somehost1.com", "www.somehost2.com"}, test_lang(), /*count=*/17, 599 {"www.somehost1.com", "www.somehost2.com"}, test_lang(), test_excluded(),
600 /*count=*/17,
547 /*interactive_request=*/true); 601 /*interactive_request=*/true);
548 net::TestURLFetcher* fetcher = test_url_fetcher_factory.GetFetcherByID(0); 602 net::TestURLFetcher* fetcher = test_url_fetcher_factory.GetFetcherByID(0);
549 ASSERT_THAT(fetcher, NotNull()); 603 ASSERT_THAT(fetcher, NotNull());
550 std::unique_ptr<base::Value> value = 604 std::unique_ptr<base::Value> value =
551 base::JSONReader::Read(fetcher->upload_data()); 605 base::JSONReader::Read(fetcher->upload_data());
552 ASSERT_TRUE(value) << " failed to parse JSON: " 606 ASSERT_TRUE(value) << " failed to parse JSON: "
553 << PrintToString(fetcher->upload_data()); 607 << PrintToString(fetcher->upload_data());
554 const base::DictionaryValue* dict = nullptr; 608 const base::DictionaryValue* dict = nullptr;
555 ASSERT_TRUE(value->GetAsDictionary(&dict)); 609 ASSERT_TRUE(value->GetAsDictionary(&dict));
556 const base::DictionaryValue* local_scoring_params = nullptr; 610 const base::DictionaryValue* local_scoring_params = nullptr;
(...skipping 11 matching lines...) Expand all
568 ASSERT_TRUE(content_selectors->GetDictionary(1, &content_selector)); 622 ASSERT_TRUE(content_selectors->GetDictionary(1, &content_selector));
569 EXPECT_TRUE(content_selector->GetString("value", &content_selector_value)); 623 EXPECT_TRUE(content_selector->GetString("value", &content_selector_value));
570 EXPECT_THAT(content_selector_value, Eq("www.somehost2.com")); 624 EXPECT_THAT(content_selector_value, Eq("www.somehost2.com"));
571 } 625 }
572 626
573 TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) { 627 TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) {
574 SetFakeResponse(/*data=*/std::string(), net::HTTP_NOT_FOUND, 628 SetFakeResponse(/*data=*/std::string(), net::HTTP_NOT_FOUND,
575 net::URLRequestStatus::FAILED); 629 net::URLRequestStatus::FAILED);
576 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); 630 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
577 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 631 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
632 test_excluded(),
578 /*count=*/1, 633 /*count=*/1,
579 /*interactive_request=*/true); 634 /*interactive_request=*/true);
580 FastForwardUntilNoTasksRemain(); 635 FastForwardUntilNoTasksRemain();
581 EXPECT_THAT(snippets_fetcher().last_status(), 636 EXPECT_THAT(snippets_fetcher().last_status(),
582 Eq("URLRequestStatus error -2")); 637 Eq("URLRequestStatus error -2"));
583 EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty()); 638 EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty());
584 EXPECT_THAT( 639 EXPECT_THAT(
585 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"), 640 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"),
586 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1))); 641 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1)));
587 EXPECT_THAT(histogram_tester().GetAllSamples( 642 EXPECT_THAT(histogram_tester().GetAllSamples(
588 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 643 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
589 ElementsAre(base::Bucket(/*min=*/-2, /*count=*/1))); 644 ElementsAre(base::Bucket(/*min=*/-2, /*count=*/1)));
590 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 645 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
591 Not(IsEmpty())); 646 Not(IsEmpty()));
592 } 647 }
593 648
594 TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) { 649 TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) {
595 SetFakeResponse(/*data=*/std::string(), net::HTTP_NOT_FOUND, 650 SetFakeResponse(/*data=*/std::string(), net::HTTP_NOT_FOUND,
596 net::URLRequestStatus::SUCCESS); 651 net::URLRequestStatus::SUCCESS);
597 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); 652 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
598 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 653 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
654 test_excluded(),
599 /*count=*/1, 655 /*count=*/1,
600 /*interactive_request=*/true); 656 /*interactive_request=*/true);
601 FastForwardUntilNoTasksRemain(); 657 FastForwardUntilNoTasksRemain();
602 EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty()); 658 EXPECT_THAT(snippets_fetcher().last_json(), IsEmpty());
603 EXPECT_THAT( 659 EXPECT_THAT(
604 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"), 660 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"),
605 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); 661 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1)));
606 EXPECT_THAT(histogram_tester().GetAllSamples( 662 EXPECT_THAT(histogram_tester().GetAllSamples(
607 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 663 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
608 ElementsAre(base::Bucket(/*min=*/404, /*count=*/1))); 664 ElementsAre(base::Bucket(/*min=*/404, /*count=*/1)));
609 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 665 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
610 Not(IsEmpty())); 666 Not(IsEmpty()));
611 } 667 }
612 668
613 TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) { 669 TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonError) {
614 const std::string kInvalidJsonStr = "{ \"recos\": []"; 670 const std::string kInvalidJsonStr = "{ \"recos\": []";
615 SetFakeResponse(/*data=*/kInvalidJsonStr, net::HTTP_OK, 671 SetFakeResponse(/*data=*/kInvalidJsonStr, net::HTTP_OK,
616 net::URLRequestStatus::SUCCESS); 672 net::URLRequestStatus::SUCCESS);
617 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); 673 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
618 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 674 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
675 test_excluded(),
619 /*count=*/1, 676 /*count=*/1,
620 /*interactive_request=*/true); 677 /*interactive_request=*/true);
621 FastForwardUntilNoTasksRemain(); 678 FastForwardUntilNoTasksRemain();
622 EXPECT_THAT(snippets_fetcher().last_status(), 679 EXPECT_THAT(snippets_fetcher().last_status(),
623 StartsWith("Received invalid JSON (error ")); 680 StartsWith("Received invalid JSON (error "));
624 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kInvalidJsonStr)); 681 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kInvalidJsonStr));
625 EXPECT_THAT( 682 EXPECT_THAT(
626 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"), 683 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"),
627 ElementsAre(base::Bucket(/*min=*/4, /*count=*/1))); 684 ElementsAre(base::Bucket(/*min=*/4, /*count=*/1)));
628 EXPECT_THAT(histogram_tester().GetAllSamples( 685 EXPECT_THAT(histogram_tester().GetAllSamples(
629 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 686 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
630 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); 687 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
631 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 688 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
632 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs, 689 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs,
633 /*count=*/1))); 690 /*count=*/1)));
634 } 691 }
635 692
636 TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) { 693 TEST_F(NTPSnippetsFetcherTest, ShouldReportJsonErrorForEmptyResponse) {
637 SetFakeResponse(/*data=*/std::string(), net::HTTP_OK, 694 SetFakeResponse(/*data=*/std::string(), net::HTTP_OK,
638 net::URLRequestStatus::SUCCESS); 695 net::URLRequestStatus::SUCCESS);
639 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); 696 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
640 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 697 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
698 test_excluded(),
641 /*count=*/1, 699 /*count=*/1,
642 /*interactive_request=*/true); 700 /*interactive_request=*/true);
643 FastForwardUntilNoTasksRemain(); 701 FastForwardUntilNoTasksRemain();
644 EXPECT_THAT(snippets_fetcher().last_json(), std::string()); 702 EXPECT_THAT(snippets_fetcher().last_json(), std::string());
645 EXPECT_THAT( 703 EXPECT_THAT(
646 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"), 704 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"),
647 ElementsAre(base::Bucket(/*min=*/4, /*count=*/1))); 705 ElementsAre(base::Bucket(/*min=*/4, /*count=*/1)));
648 EXPECT_THAT(histogram_tester().GetAllSamples( 706 EXPECT_THAT(histogram_tester().GetAllSamples(
649 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 707 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
650 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); 708 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
651 } 709 }
652 710
653 TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) { 711 TEST_F(NTPSnippetsFetcherTest, ShouldReportInvalidListError) {
654 const std::string kJsonStr = 712 const std::string kJsonStr =
655 "{\"recos\": [{ \"contentInfo\": { \"foo\" : \"bar\" }}]}"; 713 "{\"recos\": [{ \"contentInfo\": { \"foo\" : \"bar\" }}]}";
656 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK, 714 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK,
657 net::URLRequestStatus::SUCCESS); 715 net::URLRequestStatus::SUCCESS);
658 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); 716 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
659 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 717 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
718 test_excluded(),
660 /*count=*/1, 719 /*count=*/1,
661 /*interactive_request=*/true); 720 /*interactive_request=*/true);
662 FastForwardUntilNoTasksRemain(); 721 FastForwardUntilNoTasksRemain();
663 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); 722 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
664 EXPECT_THAT( 723 EXPECT_THAT(
665 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"), 724 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"),
666 ElementsAre(base::Bucket(/*min=*/5, /*count=*/1))); 725 ElementsAre(base::Bucket(/*min=*/5, /*count=*/1)));
667 EXPECT_THAT(histogram_tester().GetAllSamples( 726 EXPECT_THAT(histogram_tester().GetAllSamples(
668 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 727 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
669 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); 728 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
670 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 729 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
671 Not(IsEmpty())); 730 Not(IsEmpty()));
672 } 731 }
673 732
674 // This test actually verifies that the test setup itself is sane, to prevent 733 // This test actually verifies that the test setup itself is sane, to prevent
675 // hard-to-reproduce test failures. 734 // hard-to-reproduce test failures.
676 TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) { 735 TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpErrorForMissingBakedResponse) {
677 InitFakeURLFetcherFactory(); 736 InitFakeURLFetcherFactory();
678 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1); 737 EXPECT_CALL(mock_callback(), Run(/*snippets=*/Not(HasValue()))).Times(1);
679 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 738 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
739 test_excluded(),
680 /*count=*/1, 740 /*count=*/1,
681 /*interactive_request=*/true); 741 /*interactive_request=*/true);
682 FastForwardUntilNoTasksRemain(); 742 FastForwardUntilNoTasksRemain();
683 } 743 }
684 744
685 TEST_F(NTPSnippetsFetcherTest, ShouldCancelOngoingFetch) { 745 TEST_F(NTPSnippetsFetcherTest, ShouldCancelOngoingFetch) {
686 const std::string kJsonStr = "{ \"recos\": [] }"; 746 const std::string kJsonStr = "{ \"recos\": [] }";
687 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK, 747 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK,
688 net::URLRequestStatus::SUCCESS); 748 net::URLRequestStatus::SUCCESS);
689 EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList())); 749 EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList()));
690 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 750 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
751 test_excluded(),
691 /*count=*/1, 752 /*count=*/1,
692 /*interactive_request=*/true); 753 /*interactive_request=*/true);
693 // Second call to FetchSnippetsFromHosts() overrides/cancels the previous. 754 // Second call to FetchSnippetsFromHosts() overrides/cancels the previous.
694 // Callback is expected to be called once. 755 // Callback is expected to be called once.
695 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(), 756 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
757 test_excluded(),
696 /*count=*/1, 758 /*count=*/1,
697 /*interactive_request=*/true); 759 /*interactive_request=*/true);
698 FastForwardUntilNoTasksRemain(); 760 FastForwardUntilNoTasksRemain();
699 EXPECT_THAT( 761 EXPECT_THAT(
700 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"), 762 histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResult"),
701 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1))); 763 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
702 EXPECT_THAT(histogram_tester().GetAllSamples( 764 EXPECT_THAT(histogram_tester().GetAllSamples(
703 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 765 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
704 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); 766 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
705 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 767 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
706 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs, 768 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs,
707 /*count=*/1))); 769 /*count=*/1)));
708 } 770 }
709 771
710 ::std::ostream& operator<<( 772 ::std::ostream& operator<<(
711 ::std::ostream& os, 773 ::std::ostream& os,
712 const NTPSnippetsFetcher::OptionalSnippets& snippets) { 774 const NTPSnippetsFetcher::OptionalSnippets& snippets) {
713 if (snippets) { 775 if (snippets) {
714 // Matchers above aren't any more precise than this, so this is sufficient 776 // Matchers above aren't any more precise than this, so this is sufficient
715 // for test-failure diagnostics. 777 // for test-failure diagnostics.
716 return os << "list with " << snippets->size() << " elements"; 778 return os << "list with " << snippets->size() << " elements";
717 } else { 779 } else {
718 return os << "null"; 780 return os << "null";
719 } 781 }
720 } 782 }
721 783
722 } // namespace ntp_snippets 784 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698