| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/content_suggestions_metrics.h" | 5 #include "components/ntp_snippets/content_suggestions_metrics.h" |
| 6 | 6 |
| 7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
| 8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "components/ntp_snippets/category.h" | 9 #include "components/ntp_snippets/category.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 namespace ntp_snippets { | 13 namespace ntp_snippets { |
| 14 namespace metrics { | 14 namespace metrics { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 using testing::ElementsAre; | 17 using testing::ElementsAre; |
| 18 | 18 |
| 19 TEST(ContentSuggestionsMetricsTest, ShouldLogOnSuggestionsShown) { | 19 TEST(ContentSuggestionsMetricsTest, ShouldLogOnSuggestionsShown) { |
| 20 base::HistogramTester histogram_tester; | 20 base::HistogramTester histogram_tester; |
| 21 OnSuggestionShown(/*global_position=*/1, | 21 OnSuggestionShown(/*global_position=*/1, |
| 22 Category::FromKnownCategory(KnownCategories::ARTICLES), | 22 Category::FromKnownCategory(KnownCategories::ARTICLES), |
| 23 /*category_position=*/3, | 23 /*category_position=*/3, base::Time::Now(), 0.01f, |
| 24 base::Time::Now(), | 24 base::Time::Now() - base::TimeDelta::FromHours(2)); |
| 25 base::Time::Now() - base::TimeDelta::FromHours(2), | |
| 26 0.01f); | |
| 27 // Test corner cases for score. | 25 // Test corner cases for score. |
| 28 OnSuggestionShown(/*global_position=*/1, | 26 OnSuggestionShown(/*global_position=*/1, |
| 29 Category::FromKnownCategory(KnownCategories::ARTICLES), | 27 Category::FromKnownCategory(KnownCategories::ARTICLES), |
| 30 /*category_position=*/3, base::Time::Now(), | 28 /*category_position=*/3, base::Time::Now(), 0.0f, |
| 31 base::Time::Now() - base::TimeDelta::FromHours(2), 0.0f); | 29 base::Time::Now() - base::TimeDelta::FromHours(2)); |
| 32 OnSuggestionShown(/*global_position=*/1, | 30 OnSuggestionShown(/*global_position=*/1, |
| 33 Category::FromKnownCategory(KnownCategories::ARTICLES), | 31 Category::FromKnownCategory(KnownCategories::ARTICLES), |
| 34 /*category_position=*/3, base::Time::Now(), | 32 /*category_position=*/3, base::Time::Now(), 1.0f, |
| 35 base::Time::Now() - base::TimeDelta::FromHours(2), 1.0f); | 33 base::Time::Now() - base::TimeDelta::FromHours(2)); |
| 36 OnSuggestionShown(/*global_position=*/1, | 34 OnSuggestionShown(/*global_position=*/1, |
| 37 Category::FromKnownCategory(KnownCategories::ARTICLES), | 35 Category::FromKnownCategory(KnownCategories::ARTICLES), |
| 38 /*category_position=*/3, base::Time::Now(), | 36 /*category_position=*/3, base::Time::Now(), 8.0f, |
| 39 base::Time::Now() - base::TimeDelta::FromHours(2), 8.0f); | 37 base::Time::Now() - base::TimeDelta::FromHours(2)); |
| 40 | 38 |
| 41 EXPECT_THAT( | 39 EXPECT_THAT( |
| 42 histogram_tester.GetAllSamples( | 40 histogram_tester.GetAllSamples( |
| 43 "NewTabPage.ContentSuggestions.ShownScoreNormalized.Articles"), | 41 "NewTabPage.ContentSuggestions.ShownScoreNormalized.Articles"), |
| 44 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), | 42 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), |
| 45 base::Bucket(/*min=*/1, /*count=*/1), | 43 base::Bucket(/*min=*/1, /*count=*/1), |
| 46 base::Bucket(/*min=*/10, /*count=*/1), | 44 base::Bucket(/*min=*/10, /*count=*/1), |
| 47 base::Bucket(/*min=*/11, /*count=*/1))); | 45 base::Bucket(/*min=*/11, /*count=*/1))); |
| 48 } | 46 } |
| 49 | 47 |
| 50 } // namespace | 48 } // namespace |
| 51 } // namespace metrics | 49 } // namespace metrics |
| 52 } // namespace ntp_snippets | 50 } // namespace ntp_snippets |
| OLD | NEW |