#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/omnibox/browser/in_memory_url_index.h"
#include <stddef.h>
#include <stdint.h>
#include <fstream>
#include <memory>
#include <numeric>
#include <string>
#include <utility>
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/i18n/case_conversion.h"
#include "base/memory/raw_ptr.h"
#include "base/path_service.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "components/history/core/browser/history_backend.h"
#include "components/history/core/browser/history_database.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/test/history_service_test_util.h"
#include "components/omnibox/browser/in_memory_url_index_types.h"
#include "components/omnibox/browser/omnibox_triggered_feature_service.h"
#include "components/omnibox/browser/url_index_private_data.h"
#include "components/search_engines/search_engines_test_environment.h"
#include "components/search_engines/template_url_service.h"
#include "components/url_formatter/url_formatter.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const size_t kInvalid = …;
const size_t kProviderMaxMatches = …;
const char kClientAllowlistedScheme[] = …;
const char16_t kDefaultTemplateURLKeyword[] = …;
const char16_t kNonDefaultTemplateURLKeyword[] = …;
const TemplateURLService::Initializer kTemplateURLData[] = …;
void StringToTerms(const char* search_string,
size_t cursor_position,
std::u16string* lower_string,
String16Vector* lower_terms) { … }
}
class InMemoryURLIndexTest : public testing::Test { … };
TemplateURLService* InMemoryURLIndexTest::template_url_service() { … }
sql::Database& InMemoryURLIndexTest::GetDB() { … }
URLIndexPrivateData* InMemoryURLIndexTest::GetPrivateData() const { … }
base::CancelableTaskTracker* InMemoryURLIndexTest::GetPrivateDataTracker()
const { … }
void InMemoryURLIndexTest::ClearPrivateData() { … }
const SchemeSet& InMemoryURLIndexTest::scheme_allowlist() { … }
bool InMemoryURLIndexTest::UpdateURL(const history::URLRow& row) { … }
bool InMemoryURLIndexTest::DeleteURL(const GURL& url) { … }
void InMemoryURLIndexTest::SetUp() { … }
void InMemoryURLIndexTest::TearDown() { … }
base::FilePath::StringType InMemoryURLIndexTest::TestDBName() const { … }
bool InMemoryURLIndexTest::InitializeInMemoryURLIndexInSetUp() const { … }
void InMemoryURLIndexTest::InitializeInMemoryURLIndex() { … }
void InMemoryURLIndexTest::CheckTerm(
const URLIndexPrivateData::SearchTermCacheMap& cache,
std::u16string term) const { … }
void InMemoryURLIndexTest::ExpectPrivateDataNotEmpty(
const URLIndexPrivateData& data) { … }
void InMemoryURLIndexTest::ExpectPrivateDataEmpty(
const URLIndexPrivateData& data) { … }
template <typename T>
void ExpectMapOfContainersIdentical(const T& expected, const T& actual) { … }
void InMemoryURLIndexTest::ExpectPrivateDataEqual(
const URLIndexPrivateData& expected,
const URLIndexPrivateData& actual) { … }
class LimitedInMemoryURLIndexTest : public InMemoryURLIndexTest { … };
base::FilePath::StringType LimitedInMemoryURLIndexTest::TestDBName() const { … }
bool LimitedInMemoryURLIndexTest::InitializeInMemoryURLIndexInSetUp() const { … }
TEST_F(LimitedInMemoryURLIndexTest, Initialization) { … }
TEST_F(InMemoryURLIndexTest, HiddenURLRowsAreIgnored) { … }
TEST_F(InMemoryURLIndexTest, Retrieval) { … }
TEST_F(InMemoryURLIndexTest,
RetrievalWithInternationalizedDomainNameWithInvalidCodePoint) { … }
TEST_F(InMemoryURLIndexTest, CursorPositionRetrieval) { … }
TEST_F(InMemoryURLIndexTest, URLPrefixMatching) { … }
TEST_F(InMemoryURLIndexTest, ProperStringMatching) { … }
TEST_F(InMemoryURLIndexTest, TrimHistoryIds) { … }
TEST_F(InMemoryURLIndexTest, HugeResultSet) { … }
TEST_F(InMemoryURLIndexTest, TitleSearch) { … }
TEST_F(InMemoryURLIndexTest, TitleChange) { … }
TEST_F(InMemoryURLIndexTest, NonUniqueTermCharacterSets) { … }
TEST_F(InMemoryURLIndexTest, TypedCharacterCaching) { … }
TEST_F(InMemoryURLIndexTest, AddNewRows) { … }
TEST_F(InMemoryURLIndexTest, DeleteRows) { … }
TEST_F(InMemoryURLIndexTest, ExpireRow) { … }
TEST_F(InMemoryURLIndexTest, AllowlistedURLs) { … }
TEST_F(InMemoryURLIndexTest, ReadVisitsFromHistory) { … }
TEST_F(InMemoryURLIndexTest, CalculateWordStartsOffsets) { … }