#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/omnibox/browser/autocomplete_provider.h"
#include <stddef.h>
#include <memory>
#include <optional>
#include <string>
#include "base/base64url.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "base/test/values_test_util.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/autocomplete_input.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_match_classification.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/keyword_provider.h"
#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/omnibox_feature_configs.h"
#include "components/omnibox/browser/omnibox_prefs.h"
#include "components/omnibox/browser/omnibox_triggered_feature_service.h"
#include "components/omnibox/browser/search_provider.h"
#include "components/omnibox/browser/suggestion_group_util.h"
#include "components/omnibox/browser/zero_suggest_provider.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/open_from_clipboard/fake_clipboard_recent_content.h"
#include "components/prefs/testing_pref_service.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_engines_test_environment.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "components/search_engines/template_url_service_client.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"
#include "third_party/omnibox_proto/types.pb.h"
#include "ui/gfx/image/image_unittest_util.h"
#include "ui/gfx/image/image_util.h"
#include "url/url_constants.h"
namespace {
const size_t kResultsPerProvider = …;
const char16_t kTestTemplateURLKeyword[] = …;
class TestingSchemeClassifier : public AutocompleteSchemeClassifier { … };
class TestAutocompleteControllerObserver
: public AutocompleteController::Observer { … };
class TestAutocompleteProviderListener : public AutocompleteProviderListener { … };
}
class TestProvider : public AutocompleteProvider { … };
void TestProvider::StartPrefetch(const AutocompleteInput& input) { … }
void TestProvider::OnPrefetchRequestDone() { … }
void TestProvider::Start(const AutocompleteInput& input, bool minimal_changes) { … }
void TestProvider::ResizeMatches(size_t max_matches, bool ml_scoring_enabled) { … }
void TestProvider::OnNonPrefetchRequestDone() { … }
void TestProvider::AddResults(int start_at, int num) { … }
void TestProvider::AddResultsWithSearchTermsArgs(
int start_at,
int num,
AutocompleteMatch::Type type,
const TemplateURLRef::SearchTermsArgs& search_terms_args) { … }
class ClassifyTest { … };
ClassifyTest::ClassifyTest(const std::u16string& text,
const bool text_is_query,
ACMatchClassifications matches)
: … { … }
ClassifyTest::~ClassifyTest() = default;
ACMatchClassifications ClassifyTest::RunTest(const std::u16string& find_text) { … }
class AutocompleteProviderTest : public testing::Test { … };
AutocompleteProviderTest::AutocompleteProviderTest()
: … { … }
AutocompleteProviderTest::~AutocompleteProviderTest() { … }
void AutocompleteProviderTest::RegisterTemplateURL(
const std::u16string& keyword,
const std::string& template_url,
const std::string& image_url = "",
const std::string& image_url_post_params = "") { … }
void AutocompleteProviderTest::ResetControllerWithTestProviders(
bool same_destinations,
TestProvider** provider1_ptr,
TestProvider** provider2_ptr) { … }
void AutocompleteProviderTest::ResetControllerWithKeywordAndSearchProviders() { … }
void AutocompleteProviderTest::ResetControllerWithKeywordProvider() { … }
void AutocompleteProviderTest::ResetControllerWithType(int type) { … }
void AutocompleteProviderTest::RunTest() { … }
void AutocompleteProviderTest::RunKeywordTest(const std::u16string& input,
const KeywordTestData* match_data,
size_t size) { … }
void AutocompleteProviderTest::UpdateResultsWithSuggestionGroupsTestData(
const SuggestionGroupsTestData& test_data) { … }
void AutocompleteProviderTest::RunSearchboxStatsTest(
const SearchboxStatsTestData* sbs_test_data,
size_t size,
bool input_is_zero_suggest) { … }
void AutocompleteProviderTest::RunQuery(const std::string& query,
bool allow_exact_keyword_match) { … }
void AutocompleteProviderTest::RunExactKeymatchTest(
bool allow_exact_keyword_match) { … }
void AutocompleteProviderTest::CopyResults() { … }
GURL AutocompleteProviderTest::GetDestinationURL(
AutocompleteMatch& match,
base::TimeDelta query_formulation_time) const { … }
TEST_F(AutocompleteProviderTest, Query) { … }
TEST_F(AutocompleteProviderTest, SearchboxStats) { … }
TEST_F(AutocompleteProviderTest, RemoveDuplicates) { … }
TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) { … }
TEST_F(AutocompleteProviderTest, ExtraQueryParams) { … }
TEST_F(AutocompleteProviderTest, CurbDefaultSuggestions) { … }
TEST_F(AutocompleteProviderTest, RedundantKeywordsIgnoredInResult) { … }
TEST_F(AutocompleteProviderTest, ExactMatchKeywords) { … }
TEST_F(AutocompleteProviderTest, SuggestionGroups) { … }
TEST_F(AutocompleteProviderTest, UpdateSearchboxStats) { … }
TEST_F(AutocompleteProviderTest, GetDestinationURL) { … }
TEST_F(AutocompleteProviderTest, ClassifyAllMatchesInString) { … }
TEST_F(AutocompleteProviderTest, ResizeMatches) { … }
class AutocompleteProviderPrefetchTest : public AutocompleteProviderTest { … };
TEST_F(AutocompleteProviderPrefetchTest, SupportedProvider_NonPrefetch) { … }
TEST_F(AutocompleteProviderPrefetchTest, SupportedProvider_Prefetch) { … }
TEST_F(AutocompleteProviderPrefetchTest, SupportedProvider_OngoingNonPrefetch) { … }
TEST_F(AutocompleteProviderPrefetchTest, UnsupportedProvider_Prefetch) { … }