single_domain_cluster_finalizer_unittest.cc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/history_clusters/core/single_domain_cluster_finalizer.h"
  5. #include "base/test/metrics/histogram_tester.h"
  6. #include "base/test/task_environment.h"
  7. #include "components/history_clusters/core/clustering_test_utils.h"
  8. #include "testing/gmock/include/gmock/gmock.h"
  9. #include "testing/gtest/include/gtest/gtest.h"
  10. namespace history_clusters {
  11. namespace {
  12. class SingleDomainClusterFinalizerTest : public ::testing::Test {
  13. public:
  14. void SetUp() override {
  15. cluster_finalizer_ = std::make_unique<SingleDomainClusterFinalizer>();
  16. }
  17. void TearDown() override { cluster_finalizer_.reset(); }
  18. void FinalizeCluster(history::Cluster& cluster) {
  19. cluster_finalizer_->FinalizeCluster(cluster);
  20. }
  21. private:
  22. std::unique_ptr<SingleDomainClusterFinalizer> cluster_finalizer_;
  23. base::test::TaskEnvironment task_environment_;
  24. };
  25. TEST_F(SingleDomainClusterFinalizerTest, OneDomainMultipleHosts) {
  26. history::ClusterVisit visit_0 = testing::CreateClusterVisit(
  27. testing::CreateDefaultAnnotatedVisit(1, GURL("https://google.com/")));
  28. history::ClusterVisit visit_1 =
  29. testing::CreateClusterVisit(testing::CreateDefaultAnnotatedVisit(
  30. 2, GURL("https://mail.google.com/")));
  31. history::Cluster cluster;
  32. cluster.visits = {visit_0, visit_1};
  33. FinalizeCluster(cluster);
  34. EXPECT_FALSE(cluster.should_show_on_prominent_ui_surfaces);
  35. }
  36. TEST_F(SingleDomainClusterFinalizerTest, OneVisit) {
  37. history::ClusterVisit visit_0 = testing::CreateClusterVisit(
  38. testing::CreateDefaultAnnotatedVisit(1, GURL("https://google.com/")));
  39. history::Cluster cluster;
  40. cluster.visits = {visit_0};
  41. cluster.should_show_on_prominent_ui_surfaces = true;
  42. FinalizeCluster(cluster);
  43. EXPECT_FALSE(cluster.should_show_on_prominent_ui_surfaces);
  44. }
  45. TEST_F(SingleDomainClusterFinalizerTest,
  46. MultipleDomainsButExplicitlyNotShownBefore) {
  47. base::HistogramTester histogram_tester;
  48. history::ClusterVisit visit_0 = testing::CreateClusterVisit(
  49. testing::CreateDefaultAnnotatedVisit(1, GURL("https://google.com/")));
  50. history::ClusterVisit visit_1 = testing::CreateClusterVisit(
  51. testing::CreateDefaultAnnotatedVisit(2, GURL("https://foo.com/")));
  52. history::Cluster cluster;
  53. cluster.visits = {visit_0, visit_1};
  54. cluster.should_show_on_prominent_ui_surfaces = false;
  55. FinalizeCluster(cluster);
  56. EXPECT_FALSE(cluster.should_show_on_prominent_ui_surfaces);
  57. histogram_tester.ExpectUniqueSample(
  58. "History.Clusters.Backend.WasClusterFiltered.SingleDomain", false, 1);
  59. }
  60. TEST_F(SingleDomainClusterFinalizerTest, MultipleDomains) {
  61. base::HistogramTester histogram_tester;
  62. history::ClusterVisit visit_0 = testing::CreateClusterVisit(
  63. testing::CreateDefaultAnnotatedVisit(1, GURL("https://google.com/")));
  64. history::ClusterVisit visit_1 = testing::CreateClusterVisit(
  65. testing::CreateDefaultAnnotatedVisit(2, GURL("https://foo.com/")));
  66. history::Cluster cluster;
  67. cluster.visits = {visit_0, visit_1};
  68. FinalizeCluster(cluster);
  69. EXPECT_TRUE(cluster.should_show_on_prominent_ui_surfaces);
  70. histogram_tester.ExpectUniqueSample(
  71. "History.Clusters.Backend.WasClusterFiltered.SingleDomain", false, 1);
  72. }
  73. } // namespace
  74. } // namespace history_clusters