blob: 2424d503e8b683f4c15ec0d5a0dcbc954e2b688b [file] [log] [blame]
// Copyright 2017 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;
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