chromium/components/history/core/browser/history_service_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// History unit tests come in two flavors:
//
// 1. The more complicated style is that the unit test creates a full history
//    service. This spawns a background thread for the history backend, and
//    all communication is asynchronous. This is useful for testing more
//    complicated things or end-to-end behavior.
//
// 2. The simpler style is to create a history backend on this thread and
//    access it directly without a HistoryService object. This is much simpler
//    because communication is synchronous. Generally, sets should go through
//    the history backend (since there is a lot of logic) but gets can come
//    directly from the HistoryDatabase. This is because the backend generally
//    has no logic in the getter except threading stuff, which we don't want
//    to run.

#include "components/history/core/browser/history_service.h"

#include <stdint.h>

#include <algorithm>
#include <array>
#include <memory>
#include <string>
#include <utility>

#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "components/history/core/browser/features.h"
#include "components/history/core/browser/history_backend.h"
#include "components/history/core/browser/history_client.h"
#include "components/history/core/browser/history_database_params.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/visit_delegate.h"
#include "components/history/core/test/database_test_utils.h"
#include "components/history/core/test/test_history_database.h"
#include "components/visitedlink/core/visited_link.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace history {

class TestVisitDelegate : public VisitDelegate {};

void TestVisitDelegate::AddVisitedLink(const VisitedLink& link) {}

class HistoryServiceTest : public testing::Test {};

// Simple test that removes a bookmark. This test exercises the code paths in
// History that block till BookmarkModel is loaded.
TEST_F(HistoryServiceTest, RemoveNotification) {}

TEST_F(HistoryServiceTest, AddPage) {}

TEST_F(HistoryServiceTest, AddRedirect) {}

TEST_F(HistoryServiceTest, MakeIntranetURLsTyped) {}

TEST_F(HistoryServiceTest, Typed) {}

TEST_F(HistoryServiceTest, SetTitle) {}

TEST_F(HistoryServiceTest, MostVisitedURLs) {}

TEST_F(HistoryServiceTest, QueryMostRepeatedQueriesForKeyword) {}

namespace {

// A HistoryDBTask implementation. Each time RunOnDBThread is invoked
// invoke_count is increment. When invoked kWantInvokeCount times, true is
// returned from RunOnDBThread which should stop RunOnDBThread from being
// invoked again. When DoneRunOnMainThread is invoked, done_invoked is set to
// true.
class HistoryDBTaskImpl : public HistoryDBTask {};

// static
const int HistoryDBTaskImpl::kWantInvokeCount =;

}  // namespace

TEST_F(HistoryServiceTest, HistoryDBTask) {}

TEST_F(HistoryServiceTest, HistoryDBTaskCanceled) {}

// Helper to add a page at specified point of time.
void AddPageAtTime(HistoryService* history,
                   const std::string& url_spec,
                   base::Time time_in_the_past) {}

void AddPageInThePast(HistoryService* history,
                      const std::string& url_spec,
                      int days_back) {}

// Helper to add a synced page at a specified day in the past.
void AddSyncedPageInThePast(HistoryService* history,
                            const std::string& url_spec,
                            int days_back) {}

// Helper to add a page with specified days back in the past.
base::Time GetTimeInThePast(base::Time base_time,
                            int days_back,
                            int hours_since_midnight,
                            int minutes = 0,
                            int seconds = 0) {}

// Helper to contain a callback and run loop logic.
int GetMonthlyHostCountHelper(HistoryService* history,
                              base::CancelableTaskTracker* tracker) {}

std::pair<DomainDiversityResults, DomainDiversityResults>
GetDomainDiversityHelper(HistoryService* history,
                         base::Time begin_time,
                         base::Time end_time,
                         DomainMetricBitmaskType metric_type_bitmask,
                         base::CancelableTaskTracker* tracker) {}

// Test one domain visit metric. A negative value indicates that an invalid
// metric is expected.
void TestDomainMetric(const std::optional<DomainMetricCountType>& metric,
                      int expected) {}

// Test a set of 1-day, 7-day and 28-day domain visit metrics.
void TestDomainMetricSet(const DomainMetricSet& metric_set,
                         int expected_one_day_metric,
                         int expected_seven_day_metric,
                         int expected_twenty_eight_day_metric) {}

// Counts hosts visited in the last month.
TEST_F(HistoryServiceTest, CountMonthlyVisitedHosts) {}

TEST_F(HistoryServiceTest, GetDomainDiversityShortBasetimeRange) {}

TEST_F(HistoryServiceTest, GetDomainDiversityLongBasetimeRange) {}

TEST_F(HistoryServiceTest, GetDomainDiversityBitmaskTest) {}

// Gets unique local and synced domains visited and the last visited domain
// within a time range.
TEST_F(HistoryServiceTest, GetUniqueDomainsVisited) {}

namespace {

class AddSyncedVisitTask : public HistoryDBTask {};

}  // namespace

TEST_F(HistoryServiceTest, GetDomainDiversityLocalVsSynced) {}

TEST_F(HistoryServiceTest, GetMostRecentVisitsForGurl) {}

// This class mocks the VisitDelegate in HistoryService to ensure that
// partitioned visited links are not added immediately, but rather are posted to
// the HistoryBackend before notifying the VisitDelegate.
class OrderingHistoryServiceTest : public HistoryServiceTest {};

TEST_F(OrderingHistoryServiceTest, EnsureCorrectOrder) {}

}  // namespace history