chromium/components/history/core/browser/history_backend_db_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_backend.h"

#include <stdint.h>

#include <cstdint>
#include <string>
#include <unordered_set>

#include "base/format_macros.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/i18n/case_conversion.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "base/uuid.h"
#include "components/history/core/browser/download_constants.h"
#include "components/history/core/browser/download_row.h"
#include "components/history/core/browser/history_constants.h"
#include "components/history/core/browser/history_database.h"
#include "components/history/core/browser/history_types.h"
#include "components/history/core/browser/keyword_search_term.h"
#include "components/history/core/browser/page_usage_data.h"
#include "components/history/core/test/history_backend_db_base_test.h"
#include "components/history/core/test/test_history_database.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace history {
namespace {

// This must be outside the anonymous namespace for the friend statement in
// HistoryBackend to work.
class HistoryBackendDBTest : public HistoryBackendDBBaseTest {};

TEST_F(HistoryBackendDBTest, ClearBrowsingData_Downloads) {}

TEST_F(HistoryBackendDBTest, MigrateDownloadsState) {}

TEST_F(HistoryBackendDBTest, MigrateDownloadsReasonPathsAndDangerType) {}

TEST_F(HistoryBackendDBTest, MigrateReferrer) {}

TEST_F(HistoryBackendDBTest, MigrateDownloadedByExtension) {}

TEST_F(HistoryBackendDBTest, MigrateDownloadValidators) {}

TEST_F(HistoryBackendDBTest, MigrateDownloadMimeType) {}

bool IsValidRFC4122Ver4GUID(const std::string& guid) {}

TEST_F(HistoryBackendDBTest, MigrateHashHttpMethodAndGenerateGuids) {}

TEST_F(HistoryBackendDBTest, MigrateTabUrls) {}

TEST_F(HistoryBackendDBTest, MigrateDownloadSiteInstanceUrl) {}

TEST_F(HistoryBackendDBTest, MigrateEmbedderDownloadData) {}

// Tests that downloads_slices table are automatically added when migrating to
// version 33.
TEST_F(HistoryBackendDBTest, MigrateDownloadsSlicesTable) {}

// Tests that last access time and transient is automatically added when
// migrating to version 36.
TEST_F(HistoryBackendDBTest, MigrateDownloadsLastAccessTimeAndTransient) {}

TEST_F(HistoryBackendDBTest, DownloadCreateAndQuery) {}

TEST_F(HistoryBackendDBTest, DownloadCreateAndUpdate_VolatileFields) {}

TEST_F(HistoryBackendDBTest, ConfirmDownloadRowCreateAndDelete) {}

TEST_F(HistoryBackendDBTest, DownloadNukeRecordsMissingURLs) {}

TEST_F(HistoryBackendDBTest, ConfirmDownloadInProgressCleanup) {}

TEST_F(HistoryBackendDBTest, CreateAndUpdateDownloadingSlice) {}

// Test calling UpdateDownload with a new download slice.
TEST_F(HistoryBackendDBTest, UpdateDownloadWithNewSlice) {}

TEST_F(HistoryBackendDBTest, DownloadSliceDeletedIfEmpty) {}

// Test that the web app responsible for a download is recorded.
TEST_F(HistoryBackendDBTest, UpdateDownloadByWebApp) {}

TEST_F(HistoryBackendDBTest, MigratePresentations) {}

TEST_F(HistoryBackendDBTest, CheckLastCompatibleVersion) {}

// Tests that visit segment names are recomputed and segments merged when
// migrating to version 37.
TEST_F(HistoryBackendDBTest, MigrateVisitSegmentNames) {}

// Test to verify the finished column will be correctly added to download slices
// table during migration to version 39.
TEST_F(HistoryBackendDBTest, MigrateDownloadSliceFinished) {}

// Test to verify the incremented_omnibox_typed_score column will be correctly
// added to visits table during migration to version 40.
TEST_F(HistoryBackendDBTest, MigrateVisitsWithoutIncrementedOmniboxTypedScore) {}

// Tests that the migration code correctly handles rows in the visit database
// that may be in an invalid state where visit_id == referring_visit. Regression
// test for https://crbug.com/847246.
TEST_F(HistoryBackendDBTest,
       MigrateVisitsWithoutIncrementedOmniboxTypedScore_BadRow) {}

TEST_F(HistoryBackendDBTest, MigrateVisitsWithoutPubliclyRoutableColumn) {}

TEST_F(HistoryBackendDBTest, MigrateFlocAllowedToAnnotationsTable) {}

TEST_F(HistoryBackendDBTest, MigrateReplaceClusterVisitsTable) {}

// Tests that the migration code correctly replaces the lower_term column in the
// keyword search terms table which normalized_term which contains the
// normalized search term during migration to version 42.
TEST_F(HistoryBackendDBTest, MigrateKeywordSearchTerms) {}

TEST_F(HistoryBackendDBTest, MigrateContentAnnotationsWithoutEntitiesColumn) {}

TEST_F(HistoryBackendDBTest,
       MigrateContentAnnotationsAddRelatedSearchesColumn) {}

TEST_F(HistoryBackendDBTest,
       MigrateVisitsWithoutOpenerVisitColumnAndDropPubliclyRoutableColumn) {}

TEST_F(HistoryBackendDBTest,
       MigrateContextAnnotationsAddTotalForegroundDurationColumn) {}

TEST_F(HistoryBackendDBTest,
       MigrateContentAnnotationsAddSearchMetadataColumns) {}

TEST_F(HistoryBackendDBTest, MigrateContentAnnotationsAddPageMetadataColumns) {}

TEST_F(HistoryBackendDBTest,
       MigrateVisitsAutoincrementIdAndAddOriginatorColumns) {}

TEST_F(HistoryBackendDBTest,
       MigrateVisitsAddOriginatorFromVisitAndOpenerVisitColumns) {}

TEST_F(HistoryBackendDBTest, MigrateClustersAddColumns) {}

TEST_F(HistoryBackendDBTest, MigrateAnnotationsAddColumnsForSync) {}

TEST_F(HistoryBackendDBTest, MigrateVisitsAddIsKnownToSyncColumn) {}

TEST_F(HistoryBackendDBTest, MigrateClustersAddTriggerabilityCalculatedColumn) {}

TEST_F(HistoryBackendDBTest,
       MigrateClustersAutoincrementIdAndAddOriginatorColumns) {}

TEST_F(HistoryBackendDBTest, MigrateContentAnnotationsAddHasUrlKeyedImage) {}

TEST_F(HistoryBackendDBTest,
       MigrateVisitsAddConsiderForNewTabPageMostVisitedColumn) {}

TEST_F(HistoryBackendDBTest, MigrateDownloadByWebApp) {}

TEST_F(HistoryBackendDBTest, MigrateClustersAndVisitsAddInteractionState) {}

TEST_F(HistoryBackendDBTest, MigrateVisitsAddExternalReferrerUrlColumn) {}

TEST_F(HistoryBackendDBTest, MigrateVisitsAddVisitedLinkIdColumn) {}

TEST_F(HistoryBackendDBTest, MigrateRemoveTypedUrlMetadataTable) {}

TEST_F(HistoryBackendDBTest, MigrateVisitsAddAppId) {}

// ^^^ NEW MIGRATION TESTS GO HERE ^^^

// Preparation for the next DB migration: This test verifies that the test DB
// file for the current version exists and can be loaded.
// In the past, we only added a history.57.sql file to the repo while adding a
// migration to the NEXT version 58. That's confusing because then the developer
// has to reverse engineer what the migration for 57 was. This test looks like
// a no-op, but verifies that the test file for the current version always
// pre-exists, so adding the NEXT migration doesn't require reverse engineering.
// If you introduce a new migration, add a test for it above, and add a new
// history.n.sql file for the new DB layout so that this test keeps passing.
// SQL schemas can change without migrations, so make sure to verify the
// history.n-1.sql is up-to-date by re-creating. The flow to create a migration
// n should be:
// 1) There should already exist history.n-1.sql.
// 2) Re-create history.n-1.sql to make sure it hasn't changed since it was
//    created.
// 3) Add a migration test beginning with `CreateDBVersion(n-1)` and ending with
//    `ASSERT_GE(HistoryDatabase::GetCurrentVersion(), n);`
// 4) Create history.n.sql.
TEST_F(HistoryBackendDBTest, VerifyTestSQLFileForCurrentVersionAlreadyExists) {}

bool FilterURL(const GURL& url) {}

TEST_F(HistoryBackendDBTest, QuerySegmentUsage) {}

TEST_F(HistoryBackendDBTest, QuerySegmentUsageReturnsNothingForZeroVisits) {}

}  // namespace
}  // namespace history