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..2316fc2639e17f02d4c40b92c24be3006dfcb980 |
| --- /dev/null |
| +++ b/components/ntp_snippets/content_suggestions_metrics_unittest.cc |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
Alexei Svitkine (slow)
2017/01/16 17:37:10
It's 2017 now!
tschumann
2017/01/16 17:58:37
Done. Happy new year ;-)
|
| +// 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 { |
|
Alexei Svitkine (slow)
2017/01/16 17:37:10
Nit: I don't think tests are usually put in an ano
tschumann
2017/01/16 17:58:37
interesting. It's actually considered good practic
|
| + |
| +using testing::ElementsAre; |
| + |
| +TEST(ContentSuggestionsMetricsTest, ShouldLogOnSuggestionsShown) { |
| + base::HistogramTester histogram_tester; |
| + OnSuggestionShown(/*global_position=*/1, |
| + Category::FromKnownCategory(KnownCategories::ARTICLES), |
| + /*category_position=*/3, |
| + base::Time::Now(), |
| + base::Time::Now() - base::TimeDelta::FromHours(2), |
| + 0.01f); |
| + // 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), 0.0f); |
| + OnSuggestionShown(/*global_position=*/1, |
| + Category::FromKnownCategory(KnownCategories::ARTICLES), |
| + /*category_position=*/3, base::Time::Now(), |
| + base::Time::Now() - base::TimeDelta::FromHours(2), 1.0f); |
| + OnSuggestionShown(/*global_position=*/1, |
| + Category::FromKnownCategory(KnownCategories::ARTICLES), |
| + /*category_position=*/3, base::Time::Now(), |
| + base::Time::Now() - base::TimeDelta::FromHours(2), 8.0f); |
| + |
| + EXPECT_THAT( |
| + histogram_tester.GetAllSamples( |
| + "NewTabPage.ContentSuggestions.ShownScoreNormalized.Articles"), |
| + ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), |
| + base::Bucket(/*min=*/1, /*count=*/1), |
| + base::Bucket(/*min=*/10, /*count=*/1), |
| + base::Bucket(/*min=*/11, /*count=*/1))); |
| +} |
| + |
| +} // namespace |
| +} // namespace metrics |
| +} // namespace ntp_snippets |