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

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

Issue 2279483002: Allow category["suggestions"] to be absent. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Created 4 years, 4 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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK")); 419 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK"));
420 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr)); 420 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
421 EXPECT_THAT(histogram_tester().GetAllSamples( 421 EXPECT_THAT(histogram_tester().GetAllSamples(
422 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"), 422 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
423 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1))); 423 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
424 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"), 424 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
425 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs, 425 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs,
426 /*count=*/1))); 426 /*count=*/1)));
427 } 427 }
428 428
429 TEST_F(NTPSnippetsContentSuggestionsFetcherTest, EmptyCategoryIsOK) {
430 const std::string kJsonStr =
431 "{\"categories\" : [{"
432 " \"id\": 1,"
433 " \"localizedTitle\": \"Articles for You\""
434 "}]}";
435 SetFakeResponse(/*data=*/kJsonStr, net::HTTP_OK,
436 net::URLRequestStatus::SUCCESS);
437 EXPECT_CALL(mock_callback(), Run(IsEmptyArticleList()));
438 snippets_fetcher().FetchSnippetsFromHosts(test_hosts(), test_lang(),
439 /*count=*/1,
440 /*interactive_request=*/true);
441 FastForwardUntilNoTasksRemain();
442 EXPECT_THAT(snippets_fetcher().last_status(), Eq("OK"));
443 EXPECT_THAT(snippets_fetcher().last_json(), Eq(kJsonStr));
444 EXPECT_THAT(histogram_tester().GetAllSamples(
445 "NewTabPage.Snippets.FetchHttpResponseOrErrorCode"),
446 ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
447 EXPECT_THAT(histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchTime"),
448 ElementsAre(base::Bucket(/*min=*/kTestJsonParsingLatencyMs,
449 /*count=*/1)));
450 }
451
429 TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ServerCategories) { 452 TEST_F(NTPSnippetsContentSuggestionsFetcherTest, ServerCategories) {
430 const std::string kJsonStr = 453 const std::string kJsonStr =
431 "{\"categories\" : [{" 454 "{\"categories\" : [{"
432 " \"id\": 1," 455 " \"id\": 1,"
433 " \"localizedTitle\": \"Articles for You\"," 456 " \"localizedTitle\": \"Articles for You\","
434 " \"suggestions\" : [{" 457 " \"suggestions\" : [{"
435 " \"ids\" : [\"http://localhost/foobar\"]," 458 " \"ids\" : [\"http://localhost/foobar\"],"
436 " \"title\" : \"Foo Barred from Baz\"," 459 " \"title\" : \"Foo Barred from Baz\","
437 " \"snippet\" : \"...\"," 460 " \"snippet\" : \"...\","
438 " \"fullPageUrl\" : \"http://localhost/foobar\"," 461 " \"fullPageUrl\" : \"http://localhost/foobar\","
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 if (snippets) { 736 if (snippets) {
714 // Matchers above aren't any more precise than this, so this is sufficient 737 // Matchers above aren't any more precise than this, so this is sufficient
715 // for test-failure diagnostics. 738 // for test-failure diagnostics.
716 return os << "list with " << snippets->size() << " elements"; 739 return os << "list with " << snippets->size() << " elements";
717 } else { 740 } else {
718 return os << "null"; 741 return os << "null";
719 } 742 }
720 } 743 }
721 744
722 } // namespace ntp_snippets 745 } // namespace ntp_snippets
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698