chromium/components/history/core/browser/expire_history_backend_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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

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

#include <stddef.h>

#include <memory>
#include <string>
#include <utility>

#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/scoped_observation.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/current_thread.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/favicon/core/favicon_database.h"
#include "components/history/core/browser/history_backend_client.h"
#include "components/history/core/browser/history_backend_notifier.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/top_sites.h"
#include "components/history/core/browser/top_sites_impl.h"
#include "components/history/core/browser/top_sites_observer.h"
#include "components/history/core/test/history_client_fake_bookmarks.h"
#include "components/history/core/test/test_history_database.h"
#include "components/history/core/test/thumbnail.h"
#include "components/history/core/test/wait_top_sites_loaded_observer.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

UnorderedElementsAre;

// The test must be in the history namespace for the gtest forward declarations
// to work. It also eliminates a bunch of ugly "history::".
namespace history {

namespace {

const std::string kTestAppId =;

base::Time PretendNow() {}

// Returns whether `url` can be added to history.
bool MockCanAddURLToHistory(const GURL& url) {}

base::Time GetOldFaviconThreshold() {}

}  // namespace

// ExpireHistoryTest -----------------------------------------------------------

class ExpireHistoryTest : public testing::Test, public HistoryBackendNotifier {};

// The example data consists of 4 visits. The middle two visits are to the
// same URL, while the first and last are for unique ones. This allows a test
// for the oldest or newest to include both a URL that should get totally
// deleted (the one on the end) with one that should only get a visit deleted
// (with the one in the middle) when it picks the proper threshold time.
//
// Each visit has indexed data, each URL has thumbnail. The first two URLs will
// share the same favicon, while the last one will have a unique favicon. The
// second visit for the middle URL is typed.
//
// The IDs of the added URLs, and the times of the four added visits will be
// added to the given arrays. If set_app_id is true, set the app_id to the
// 2nd/3rd row for testing.
void ExpireHistoryTest::AddExampleData(URLID url_ids[3],
                                       base::Time visit_times[4],
                                       bool set_app_id) {}

bool ExpireHistoryTest::HasFavicon(favicon_base::FaviconID favicon_id) {}

favicon_base::FaviconID ExpireHistoryTest::GetFavicon(
    const GURL& page_url,
    favicon_base::IconType icon_type) {}

void ExpireHistoryTest::EnsureURLInfoGone(const URLRow& row, bool expired) {}

bool ExpireHistoryTest::ModifiedNotificationSentDueToExpiry(const GURL& url) {}
bool ExpireHistoryTest::ModifiedNotificationSentDueToUserAction(
    const GURL& url) {}

bool ExpireHistoryTest::ModifiedNotificationSent(
    const GURL& url,
    bool should_be_from_expiration) {}

TEST_F(ExpireHistoryTest, DeleteFaviconsIfPossible) {}

// Deletes a URL with a favicon that it is the last referencer of, so that it
// should also get deleted.
// This test failed near end of month.
// Please comment on http://crbug.com/15724 if it fails again.
TEST_F(ExpireHistoryTest, DeleteURLAndFavicon) {}

// Deletes visits to a URL with a time bound. The url, favicon and the second
// visit should not get deleted.
TEST_F(ExpireHistoryTest, DeleteURLWithTimeBound) {}

// Deletes a URL with a favicon that other URLs reference, so that the favicon
// should not get deleted. This also tests deleting more than one visit.
TEST_F(ExpireHistoryTest, DeleteURLWithoutFavicon) {}

// Deletes a URL with context annotations attached to the visits. Verifies the
// context annotations are also deleted.
TEST_F(ExpireHistoryTest, DeleteURLAndContextAnnotations) {}

// DeleteURL should delete the history of starred urls, but the URL should
// remain starred and its favicon should remain too.
TEST_F(ExpireHistoryTest, DeleteStarredVisitedURL) {}

// DeleteURL should not delete the favicon of bookmarked URLs.
TEST_F(ExpireHistoryTest, DeleteStarredUnvisitedURL) {}

// Deletes multiple URLs at once.  The favicon for the third one but
// not the first two should be deleted.
TEST_F(ExpireHistoryTest, DeleteURLs) {}

// Expires all URLs more recent than a given time, with no starred items.
// Our time threshold is such that one URL should be updated (we delete one of
// the two visits) and one is deleted.
TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarred) {}

// Expires all URLs visited between two given times, with no starred items.
TEST_F(ExpireHistoryTest, FlushURLsUnstarredBetweenTwoTimestamps) {}

// Expires all URLs more recent than a given time, with no starred items.
// Same as FlushRecentURLsUnstarred test but with base::Time::Max() as end_time.
TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredWithMaxTime) {}

// Expires all URLs with a given app ID, more recent than a given time, with no
// starred items.
TEST_F(ExpireHistoryTest, FlushRecentURLsWithAppIdUnstarredWithMaxTime) {}

// Expires all URLs with no starred items.
TEST_F(ExpireHistoryTest, FlushAllURLsUnstarred) {}

// Expires all URLs with times in a given set.
TEST_F(ExpireHistoryTest, FlushURLsForTimes) {}

// Expires only a specific URLs more recent than a given time, with no starred
// items.  Our time threshold is such that the URL should be updated (we delete
// one of the two visits).
TEST_F(ExpireHistoryTest, FlushRecentURLsUnstarredRestricted) {}

// Expire a starred URL, it shouldn't get deleted
TEST_F(ExpireHistoryTest, FlushRecentURLsStarred) {}

TEST_F(ExpireHistoryTest, ExpireHistoryBetweenPropagatesUserInitiated) {}

TEST_F(ExpireHistoryTest, ExpireHistoryBeforeUnstarred) {}

TEST_F(ExpireHistoryTest, ExpireHistoryBeforeStarred) {}

// Tests the return values from ExpireSomeOldHistory. The rest of the
// functionality of this function is tested by the ExpireHistoryBefore*
// tests which use this function internally.
TEST_F(ExpireHistoryTest, ExpireSomeOldHistory) {}

TEST_F(ExpireHistoryTest, ExpiringVisitsReader) {}

// Test that ClearOldOnDemandFaviconsIfPossible() deletes favicons associated
// only to unstarred page URLs.
TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesDeleteUnstarred) {}

// Test that ClearOldOnDemandFaviconsIfPossible() deletes favicons associated to
// at least one starred page URL.
TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesNotDeleteStarred) {}

// Test that ClearOldOnDemandFaviconsIfPossible() has effect if the last
// clearing was long time age (such as 2 days ago).
TEST_F(ExpireHistoryTest, ClearOldOnDemandFaviconsDoesDeleteAfterLongDelay) {}

// Test that ClearOldOnDemandFaviconsIfPossible() deletes favicons associated to
// at least one starred page URL.
TEST_F(ExpireHistoryTest,
       ClearOldOnDemandFaviconsDoesNotDeleteAfterShortDelay) {}

// Test that all visits that are redirect parents of specified visits are also
// removed. See crbug.com/786878.
TEST_F(ExpireHistoryTest, DeleteVisitAndRedirects) {}

// Test that loops in redirect parents are handled. See crbug.com/798234.
TEST_F(ExpireHistoryTest, DeleteVisitAndRedirectsWithLoop) {}

// Test that visits that are referers but not part of a redirect chain don't
// get deleted. See crbug.com/919488.
TEST_F(ExpireHistoryTest, DeleteVisitButNotActualReferers) {}

TEST_F(ExpireHistoryTest, DeleteVisitsWithoutDeletingURLs) {}

// TODO(brettw) add some visits with no URL to make sure everything is updated
// properly. Have the visits also refer to nonexistent FTS rows.
//
// Maybe also refer to invalid favicons.

}  // namespace history