#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/omnibox/browser/history_quick_provider.h"
#include <stddef.h>
#include <functional>
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "base/containers/to_vector.h"
#include "base/memory/raw_ptr.h"
#include "base/ranges/algorithm.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/bookmarks/test/test_bookmark_client.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/browser/history_service_observer.h"
#include "components/history/core/test/history_service_test_util.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/fake_autocomplete_provider_client.h"
#include "components/omnibox/browser/history_test_util.h"
#include "components/omnibox/browser/history_url_provider.h"
#include "components/omnibox/browser/omnibox_triggered_feature_service.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/search_engines/template_url_starter_pack_data.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "third_party/metrics_proto/omnibox_focus_type.pb.h"
ASCIIToUTF16;
namespace {
class WaitForURLsDeletedObserver : public history::HistoryServiceObserver { … };
WaitForURLsDeletedObserver::WaitForURLsDeletedObserver(base::RunLoop* runner)
: … { … }
WaitForURLsDeletedObserver::~WaitForURLsDeletedObserver() = default;
void WaitForURLsDeletedObserver::OnHistoryDeletions(
history::HistoryService* service,
const history::DeletionInfo& deletion_info) { … }
void WaitForURLsDeletedNotification(history::HistoryService* history_service) { … }
class GetURLTask : public history::HistoryDBTask { … };
}
class HistoryQuickProviderTest : public testing::Test { … };
void HistoryQuickProviderTest::SetUp() { … }
void HistoryQuickProviderTest::TearDown() { … }
std::vector<HistoryQuickProviderTest::TestURLInfo>
HistoryQuickProviderTest::GetTestData() { … }
void HistoryQuickProviderTest::FillData() { … }
HistoryQuickProviderTest::SetShouldContain::SetShouldContain(
const ACMatches& matched_urls) { … }
void HistoryQuickProviderTest::SetShouldContain::operator()(
const std::string& expected) { … }
void HistoryQuickProviderTest::RunTest(
const std::u16string& text,
bool prevent_inline_autocomplete,
const std::vector<std::string>& expected_urls,
bool expected_can_inline_top_result,
const std::u16string& expected_fill_into_edit,
const std::u16string& expected_autocompletion) { … }
void HistoryQuickProviderTest::RunTestWithCursor(
const std::u16string& text,
const size_t cursor_position,
bool prevent_inline_autocomplete,
const std::vector<std::string>& expected_urls,
bool expected_can_inline_top_result,
const std::u16string& expected_fill_into_edit,
const std::u16string& expected_autocompletion,
bool duplicates_ok) { … }
bool HistoryQuickProviderTest::GetURLProxy(const GURL& url) { … }
TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { … }
TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) { … }
TEST_F(HistoryQuickProviderTest, MatchWithAndWithoutCursorWordBreak) { … }
TEST_F(HistoryQuickProviderTest, MatchWithAndWithoutCursorWordBreak_Dedupe) { … }
TEST_F(HistoryQuickProviderTest,
MatchWithAndWithoutCursorWordBreak_DedupingKeepsHigherScoredSuggestion) { … }
TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) { … }
TEST_F(HistoryQuickProviderTest, MultiTermTitleMatch) { … }
TEST_F(HistoryQuickProviderTest, NonWordLastCharacterMatch) { … }
TEST_F(HistoryQuickProviderTest, MultiMatch) { … }
TEST_F(HistoryQuickProviderTest, StartRelativeMatch) { … }
TEST_F(HistoryQuickProviderTest, EncodingMatch) { … }
TEST_F(HistoryQuickProviderTest, ContentsClass) { … }
TEST_F(HistoryQuickProviderTest, VisitCountMatches) { … }
TEST_F(HistoryQuickProviderTest, TypedCountMatches) { … }
TEST_F(HistoryQuickProviderTest, DaysAgoMatches) { … }
TEST_F(HistoryQuickProviderTest, EncodingLimitMatch) { … }
TEST_F(HistoryQuickProviderTest, Spans) { … }
TEST_F(HistoryQuickProviderTest, DeleteMatch) { … }
TEST_F(HistoryQuickProviderTest, PreventBeatingURLWhatYouTypedMatch) { … }
TEST_F(HistoryQuickProviderTest, PreventInlineAutocomplete) { … }
TEST_F(HistoryQuickProviderTest, DoesNotProvideMatchesOnFocus) { … }
ScoredHistoryMatch BuildScoredHistoryMatch(const std::string& url_text,
const std::u16string& input_term) { … }
TEST_F(HistoryQuickProviderTest, DoTrimHttpScheme) { … }
TEST_F(HistoryQuickProviderTest, DontTrimHttpSchemeIfInputHasScheme) { … }
TEST_F(HistoryQuickProviderTest, DontTrimHttpSchemeIfInputMatches) { … }
TEST_F(HistoryQuickProviderTest, DontTrimHttpsSchemeIfInputHasScheme) { … }
TEST_F(HistoryQuickProviderTest, DoTrimHttpsScheme) { … }
TEST_F(HistoryQuickProviderTest, CorrectAutocompleteWithTrailingSlash) { … }
TEST_F(HistoryQuickProviderTest, KeywordModeExtractUserInput) { … }
TEST_F(HistoryQuickProviderTest,
QuickMatchToACMatch_HideUrlForDocumentSuggestion) { … }
TEST_F(HistoryQuickProviderTest, MaxMatches) { … }
class HQPDomainSuggestionsTest : public HistoryQuickProviderTest { … };
TEST_F(HQPDomainSuggestionsTest, DomainSuggestions) { … }
class HQPOrderingTest : public HistoryQuickProviderTest { … };
std::vector<HistoryQuickProviderTest::TestURLInfo>
HQPOrderingTest::GetTestData() { … }
TEST_F(HQPOrderingTest, TEMatch) { … }
TEST_F(HQPOrderingTest, TEAMatch) { … }