chromium/components/favicon/core/favicon_database_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 <stddef.h>

#include <algorithm>
#include <vector>

#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted_memory.h"
#include "base/path_service.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/favicon/core/favicon_database.h"
#include "components/favicon_base/favicon_types.h"
#include "components/history/core/test/database_test_utils.h"
#include "sql/database.h"
#include "sql/recovery.h"
#include "sql/test/scoped_error_expecter.h"
#include "sql/test/test_helpers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
#include "url/origin.h"

AllOf;
ElementsAre;
Field;
Pair;
Return;

namespace favicon {

namespace {

// Blobs for the bitmap tests.  These aren't real bitmaps.  Golden
// database files store the same blobs (see VersionN tests).
const unsigned char kBlob1[] =;
const unsigned char kBlob2[] =;

const gfx::Size kSmallSize =;
const gfx::Size kLargeSize =;

// Verify that the up-to-date database has the expected tables and
// columns.  Functional tests only check whether the things which
// should be there are, but do not check if extraneous items are
// present.  Any extraneous items have the potential to interact
// negatively with future schema changes.
void VerifyTablesAndColumns(sql::Database* db) {}

// Adds a favicon at `icon_url` with `icon_type` with default bitmap data and
// maps `page_url` to `icon_url`.
void AddAndMapFaviconSimple(FaviconDatabase* db,
                            const GURL& page_url,
                            const GURL& icon_url,
                            favicon_base::IconType icon_type) {}

void VerifyDatabaseEmpty(sql::Database* db) {}

// Helper to check that an expected mapping exists.
[[nodiscard]] bool CheckPageHasIcon(
    FaviconDatabase* db,
    const GURL& page_url,
    favicon_base::IconType expected_icon_type,
    const GURL& expected_icon_url,
    const gfx::Size& expected_icon_size,
    size_t expected_icon_contents_size,
    const unsigned char* expected_icon_contents) {}

bool CompareIconMappingIconUrl(const IconMapping& a, const IconMapping& b) {}

void SortMappingsByIconUrl(std::vector<IconMapping>* mappings) {}

base::Time GetLastUpdated(FaviconDatabase* db, favicon_base::FaviconID icon) {}

}  // namespace

class FaviconDatabaseTest : public testing::Test {};

TEST_F(FaviconDatabaseTest, AddIconMapping) {}

TEST_F(FaviconDatabaseTest, AddOnDemandFaviconBitmapCreatesCorrectTimestamps) {}

TEST_F(FaviconDatabaseTest, AddFaviconBitmapCreatesCorrectTimestamps) {}

TEST_F(FaviconDatabaseTest, GetFaviconLastUpdatedTimeReturnsFalseForNoBitmaps) {}

TEST_F(FaviconDatabaseTest, GetFaviconLastUpdatedTimeReturnsMaxTime) {}

TEST_F(FaviconDatabaseTest, TouchUpdatesOnDemandFavicons) {}

TEST_F(FaviconDatabaseTest, TouchUpdatesOnlyInfrequently) {}

TEST_F(FaviconDatabaseTest, TouchDoesNotUpdateStandardFavicons) {}

// Test that FaviconDatabase::GetOldOnDemandFavicons() returns on-demand icons
// which were requested prior to the passed in timestamp.
TEST_F(FaviconDatabaseTest, GetOldOnDemandFaviconsReturnsOld) {}

// Test that FaviconDatabase::GetOldOnDemandFavicons() returns on-visit icons
// if the on-visit icons have expired. We need this behavior in order to delete
// icons stored via HistoryService::SetOnDemandFavicons() prior to on-demand
// icons setting the "last_requested" time.
TEST_F(FaviconDatabaseTest, GetOldOnDemandFaviconsDoesNotReturnExpired) {}

// Test that FaviconDatabase::GetOldOnDemandFavicons() does not return
// on-demand icons which were requested after the passed in timestamp.
TEST_F(FaviconDatabaseTest, GetOldOnDemandFaviconsDoesNotReturnFresh) {}

// Test that FaviconDatabase::GetOldOnDemandFavicons() does not return
// non-expired on-visit icons.
TEST_F(FaviconDatabaseTest, GetOldOnDemandFaviconsDoesNotDeleteStandard) {}

TEST_F(FaviconDatabaseTest, DeleteIconMappings) {}

TEST_F(FaviconDatabaseTest, GetIconMappingsForPageURL) {}

TEST_F(FaviconDatabaseTest, RetainDataForPageUrls) {}

// Test that RetainDataForPageUrls() expires retained favicons.
TEST_F(FaviconDatabaseTest, RetainDataForPageUrlsExpiresRetainedFavicons) {}

// Tests that deleting a favicon deletes the favicon row and favicon bitmap
// rows from the database.
TEST_F(FaviconDatabaseTest, DeleteFavicon) {}

TEST_F(FaviconDatabaseTest, GetIconMappingsForPageURLForReturnOrder) {}

// Test that when multiple icon types are passed to GetIconMappingsForPageURL()
// that the results are filtered according to the passed in types.
TEST_F(FaviconDatabaseTest, GetIconMappingsForPageURLWithIconTypes) {}

TEST_F(FaviconDatabaseTest, FindFirstPageURLForHost) {}

TEST_F(FaviconDatabaseTest, HasMappingFor) {}

// Test loading version 3 database.
TEST_F(FaviconDatabaseTest, Version3) {}

// Test loading version 4 database.
TEST_F(FaviconDatabaseTest, Version4) {}

// Test loading version 5 database.
TEST_F(FaviconDatabaseTest, Version5) {}

// Test loading version 6 database.
TEST_F(FaviconDatabaseTest, Version6) {}

// Test loading version 7 database.
TEST_F(FaviconDatabaseTest, Version7) {}

// Test loading version 8 database.
TEST_F(FaviconDatabaseTest, Version8) {}

TEST_F(FaviconDatabaseTest, Recovery) {}

TEST_F(FaviconDatabaseTest, Recovery7) {}

TEST_F(FaviconDatabaseTest, Recovery6) {}

TEST_F(FaviconDatabaseTest, Recovery5) {}

// Test that various broken schema found in the wild can be opened
// successfully, and result in the correct schema.
TEST_F(FaviconDatabaseTest, WildSchema) {}

TEST(FaviconDatabaseIconTypeTest, ShouldBeBackwardCompatible) {}

TEST_F(FaviconDatabaseTest, GetFaviconsLastUpdatedBefore) {}

TEST_F(FaviconDatabaseTest, SetFaviconsOutOfDateBetween) {}

// Test that GetFaviconIDForFaviconURL can filter by origin.
TEST_F(FaviconDatabaseTest, GetFaviconIDForFaviconURLOriginFilter) {}

}  // namespace favicon