| 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 47cc5d4546e385e83fb856527114dd4aafa7d0b1..4f58b17c2eedf5e1fc365e1a2ef6f7f5f441b04c 100644
|
| --- a/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc
|
| +++ b/components/ntp_snippets/ntp_snippets_fetcher_unittest.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/run_loop.h"
|
| +#include "base/test/histogram_tester.h"
|
| #include "base/thread_task_runner_handle.h"
|
| #include "net/url_request/test_url_fetcher_factory.h"
|
| #include "net/url_request/url_request_test_util.h"
|
| @@ -15,6 +16,8 @@
|
| namespace ntp_snippets {
|
| namespace {
|
|
|
| +using testing::ElementsAre;
|
| +using testing::IsEmpty;
|
| using testing::IsNull;
|
| using testing::NotNull;
|
|
|
| @@ -49,6 +52,8 @@ class NTPSnippetsFetcherTest : public testing::Test {
|
|
|
| MockSnippetsAvailableCallback& mock_callback() { return mock_callback_; }
|
|
|
| + base::HistogramTester& histogram_tester() { return histogram_tester_; }
|
| +
|
| private:
|
| // Instantiation of factory automatically sets itself as URLFetcher's factory.
|
| net::FakeURLFetcherFactory fake_url_fetcher_factory_;
|
| @@ -59,6 +64,7 @@ class NTPSnippetsFetcherTest : public testing::Test {
|
| std::unique_ptr<
|
| NTPSnippetsFetcher::SnippetsAvailableCallbackList::Subscription>
|
| snippets_fetcher_subscription_;
|
| + base::HistogramTester histogram_tester_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(NTPSnippetsFetcherTest);
|
| };
|
| @@ -66,6 +72,12 @@ class NTPSnippetsFetcherTest : public testing::Test {
|
| TEST_F(NTPSnippetsFetcherTest, ShouldNotFetchOnCreation) {
|
| // The lack of registered baked in responses would cause any fetch to fail.
|
| base::RunLoop().RunUntilIdle();
|
| + EXPECT_THAT(
|
| + histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResponseCode"),
|
| + IsEmpty());
|
| + EXPECT_THAT(histogram_tester().GetAllSamples(
|
| + "NewTabPage.Snippets.FailedRequestErrorCode"),
|
| + IsEmpty());
|
| }
|
|
|
| TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) {
|
| @@ -79,6 +91,12 @@ TEST_F(NTPSnippetsFetcherTest, ShouldFetchSuccessfully) {
|
| snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
|
| /*count=*/1);
|
| base::RunLoop().RunUntilIdle();
|
| + EXPECT_THAT(
|
| + histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResponseCode"),
|
| + ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
|
| + EXPECT_THAT(histogram_tester().GetAllSamples(
|
| + "NewTabPage.Snippets.FailedRequestErrorCode"),
|
| + IsEmpty());
|
| }
|
|
|
| TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) {
|
| @@ -93,6 +111,12 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportUrlStatusError) {
|
| snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
|
| /*count=*/1);
|
| base::RunLoop().RunUntilIdle();
|
| + EXPECT_THAT(
|
| + histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResponseCode"),
|
| + IsEmpty());
|
| + EXPECT_THAT(histogram_tester().GetAllSamples(
|
| + "NewTabPage.Snippets.FailedRequestErrorCode"),
|
| + ElementsAre(base::Bucket(/*min=*/2, /*count=*/1)));
|
| }
|
|
|
| TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) {
|
| @@ -106,6 +130,12 @@ TEST_F(NTPSnippetsFetcherTest, ShouldReportHttpError) {
|
| snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
|
| /*count=*/1);
|
| base::RunLoop().RunUntilIdle();
|
| + EXPECT_THAT(
|
| + histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResponseCode"),
|
| + ElementsAre(base::Bucket(/*min=*/404, /*count=*/1)));
|
| + EXPECT_THAT(histogram_tester().GetAllSamples(
|
| + "NewTabPage.Snippets.FailedRequestErrorCode"),
|
| + IsEmpty());
|
| }
|
|
|
| TEST_F(NTPSnippetsFetcherTest, ShouldCancelOngoingFetch) {
|
| @@ -123,6 +153,12 @@ TEST_F(NTPSnippetsFetcherTest, ShouldCancelOngoingFetch) {
|
| snippets_fetcher().FetchSnippets(/*hosts=*/std::set<std::string>(),
|
| /*count=*/1);
|
| base::RunLoop().RunUntilIdle();
|
| + EXPECT_THAT(
|
| + histogram_tester().GetAllSamples("NewTabPage.Snippets.FetchResponseCode"),
|
| + ElementsAre(base::Bucket(/*min=*/200, /*count=*/1)));
|
| + EXPECT_THAT(histogram_tester().GetAllSamples(
|
| + "NewTabPage.Snippets.FailedRequestErrorCode"),
|
| + IsEmpty());
|
| }
|
|
|
| } // namespace
|
|
|