123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- // Copyright 2022 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/history_clusters/core/single_domain_cluster_finalizer.h"
- #include "base/test/metrics/histogram_tester.h"
- #include "base/test/task_environment.h"
- #include "components/history_clusters/core/clustering_test_utils.h"
- #include "testing/gmock/include/gmock/gmock.h"
- #include "testing/gtest/include/gtest/gtest.h"
- namespace history_clusters {
- namespace {
- class SingleDomainClusterFinalizerTest : public ::testing::Test {
- public:
- void SetUp() override {
- cluster_finalizer_ = std::make_unique<SingleDomainClusterFinalizer>();
- }
- void TearDown() override { cluster_finalizer_.reset(); }
- void FinalizeCluster(history::Cluster& cluster) {
- cluster_finalizer_->FinalizeCluster(cluster);
- }
- private:
- std::unique_ptr<SingleDomainClusterFinalizer> cluster_finalizer_;
- base::test::TaskEnvironment task_environment_;
- };
- TEST_F(SingleDomainClusterFinalizerTest, OneDomainMultipleHosts) {
- history::ClusterVisit visit_0 = testing::CreateClusterVisit(
- testing::CreateDefaultAnnotatedVisit(1, GURL("https://google.com/")));
- history::ClusterVisit visit_1 =
- testing::CreateClusterVisit(testing::CreateDefaultAnnotatedVisit(
- 2, GURL("https://mail.google.com/")));
- history::Cluster cluster;
- cluster.visits = {visit_0, visit_1};
- FinalizeCluster(cluster);
- EXPECT_FALSE(cluster.should_show_on_prominent_ui_surfaces);
- }
- TEST_F(SingleDomainClusterFinalizerTest, OneVisit) {
- history::ClusterVisit visit_0 = testing::CreateClusterVisit(
- testing::CreateDefaultAnnotatedVisit(1, GURL("https://google.com/")));
- history::Cluster cluster;
- cluster.visits = {visit_0};
- cluster.should_show_on_prominent_ui_surfaces = true;
- FinalizeCluster(cluster);
- EXPECT_FALSE(cluster.should_show_on_prominent_ui_surfaces);
- }
- TEST_F(SingleDomainClusterFinalizerTest,
- MultipleDomainsButExplicitlyNotShownBefore) {
- base::HistogramTester histogram_tester;
- history::ClusterVisit visit_0 = testing::CreateClusterVisit(
- testing::CreateDefaultAnnotatedVisit(1, GURL("https://google.com/")));
- history::ClusterVisit visit_1 = testing::CreateClusterVisit(
- testing::CreateDefaultAnnotatedVisit(2, GURL("https://foo.com/")));
- history::Cluster cluster;
- cluster.visits = {visit_0, visit_1};
- cluster.should_show_on_prominent_ui_surfaces = false;
- FinalizeCluster(cluster);
- EXPECT_FALSE(cluster.should_show_on_prominent_ui_surfaces);
- histogram_tester.ExpectUniqueSample(
- "History.Clusters.Backend.WasClusterFiltered.SingleDomain", false, 1);
- }
- TEST_F(SingleDomainClusterFinalizerTest, MultipleDomains) {
- base::HistogramTester histogram_tester;
- history::ClusterVisit visit_0 = testing::CreateClusterVisit(
- testing::CreateDefaultAnnotatedVisit(1, GURL("https://google.com/")));
- history::ClusterVisit visit_1 = testing::CreateClusterVisit(
- testing::CreateDefaultAnnotatedVisit(2, GURL("https://foo.com/")));
- history::Cluster cluster;
- cluster.visits = {visit_0, visit_1};
- FinalizeCluster(cluster);
- EXPECT_TRUE(cluster.should_show_on_prominent_ui_surfaces);
- histogram_tester.ExpectUniqueSample(
- "History.Clusters.Backend.WasClusterFiltered.SingleDomain", false, 1);
- }
- } // namespace
- } // namespace history_clusters
|