Chromium Code Reviews| Index: components/ntp_snippets/content_suggestions_metrics_unittest.cc |
| diff --git a/components/ntp_snippets/content_suggestions_metrics_unittest.cc b/components/ntp_snippets/content_suggestions_metrics_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..675c84884e5ea115b9fa0fa22cd0727ec4b9a280 |
| --- /dev/null |
| +++ b/components/ntp_snippets/content_suggestions_metrics_unittest.cc |
| @@ -0,0 +1,46 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/ntp_snippets/content_suggestions_metrics.h" |
| + |
| +#include "base/test/histogram_tester.h" |
| +#include "base/time/time.h" |
| +#include "components/ntp_snippets/category.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace ntp_snippets { |
| +namespace metrics { |
| +namespace { |
| + |
| +using testing::ElementsAre; |
| + |
| +TEST(ContentSuggestionsMetricsTest, ShouldLogOnSuggestionsShown) { |
| + base::HistogramTester histogram_tester; |
|
jkrcal
2017/01/10 19:31:47
Yay for increasing test coverage! And thanks for l
|
| + OnSuggestionShown(/*global_position=*/1, |
| + Category::FromKnownCategory(KnownCategories::ARTICLES), |
| + /*category_position=*/3, |
| + base::Time::Now(), |
| + base::Time::Now() - base::TimeDelta::FromHours(2), |
| + 0.01); |
| + // Test corner cases for score. |
| + OnSuggestionShown(/*global_position=*/1, |
| + Category::FromKnownCategory(KnownCategories::ARTICLES), |
| + /*category_position=*/3, base::Time::Now(), |
| + base::Time::Now() - base::TimeDelta::FromHours(2), 1.0); |
| + OnSuggestionShown(/*global_position=*/1, |
| + Category::FromKnownCategory(KnownCategories::ARTICLES), |
| + /*category_position=*/3, base::Time::Now(), |
| + base::Time::Now() - base::TimeDelta::FromHours(2), 8.0); |
| + |
| + EXPECT_THAT(histogram_tester.GetAllSamples( |
| + "NewTabPage.ContentSuggestions.ShownScore.Articles"), |
| + ElementsAre(base::Bucket(/*min=*/1, /*count=*/1), |
| + base::Bucket(/*min=*/10, /*count=*/1), |
| + base::Bucket(/*min=*/11, /*count=*/1))); |
| +} |
| + |
| +} // namespace |
| +} // namespace metrics |
| +} // namespace ntp_snippets |