#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/omnibox/browser/search_provider.h"
#include <stddef.h>
#include <memory>
#include <string>
#include "base/base64.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
#include "base/strings/escape.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_provider_client.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/autocomplete/document_suggestions_service_factory.h"
#include "chrome/browser/autocomplete/remote_suggestions_service_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/signin/chrome_signin_client_factory.h"
#include "chrome/browser/signin/chrome_signin_client_test_util.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "components/google/core/common/google_switches.h"
#include "components/history/core/browser/history_service.h"
#include "components/lens/proto/server/lens_overlay_response.pb.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_provider.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/history_url_provider.h"
#include "components/omnibox/browser/omnibox_feature_configs.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/remote_suggestions_service.h"
#include "components/omnibox/browser/suggestion_answer.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/search_engine_type.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_service.h"
#include "components/variations/scoped_variations_ids_provider.h"
#include "components/variations/variations_associated_data.h"
#include "content/public/test/browser_task_environment.h"
#include "net/http/http_util.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.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/navigational_intent.pb.h"
#include "ui/base/device_form_factor.h"
ASCIIToUTF16;
_;
namespace {
ACMatches::const_iterator FindDefaultMatch(const ACMatches& matches) { … }
class SearchProviderForTest : public SearchProvider { … };
SearchProviderForTest::SearchProviderForTest(
AutocompleteProviderClient* client,
AutocompleteProviderListener* listener,
Profile* profile)
: … { … }
SearchProviderForTest::~SearchProviderForTest() = default;
void SearchProviderForTest::RecordDeletionResult(bool success) { … }
class TestAutocompleteProviderClient : public ChromeAutocompleteProviderClient { … };
std::unique_ptr<KeyedService> BuildRemoteSuggestionsServiceWithURLLoader(
network::TestURLLoaderFactory* test_url_loader_factory,
content::BrowserContext* context) { … }
std::string SerializeAndEncodeEntityInfo(
const omnibox::EntityInfo& entity_info) { … }
}
class SearchProviderFeatureTestComponent { … };
SearchProviderFeatureTestComponent::SearchProviderFeatureTestComponent(
const bool command_line_overrides) { … }
class BaseSearchProviderTest : public testing::Test,
public AutocompleteProviderListener { … };
class SearchProviderTest : public BaseSearchProviderTest { … };
class InvalidSearchProviderTest : public BaseSearchProviderTest { … };
const char BaseSearchProviderTest::kNotApplicable[] = …;
const BaseSearchProviderTest::ExpectedMatch
BaseSearchProviderTest::kEmptyExpectedMatch = …;
void BaseSearchProviderTest::CustomizableSetUp(
const std::string& search_url,
const std::string& suggestions_url) { … }
void BaseSearchProviderTest::TearDown() { … }
void BaseSearchProviderTest::RunTest(TestData* cases,
int num_cases,
bool prefer_keyword) { … }
void BaseSearchProviderTest::OnProviderUpdate(
bool updated_matches,
const AutocompleteProvider* provider) { … }
void BaseSearchProviderTest::RunTillProviderDone() { … }
void BaseSearchProviderTest::QueryForInput(const AutocompleteInput& input) { … }
void BaseSearchProviderTest::QueryForInput(const std::u16string& text,
bool prevent_inline_autocomplete,
bool prefer_keyword) { … }
void BaseSearchProviderTest::QueryForInputAndSetWYTMatch(
const std::u16string& text,
AutocompleteMatch* wyt_match) { … }
void BaseSearchProviderTest::QueryForInputAndWaitForFetcherResponses(
const std::u16string& text,
const bool prefer_keyword,
const std::string& default_fetcher_response,
const std::string& keyword_fetcher_response) { … }
GURL BaseSearchProviderTest::AddSearchToHistory(TemplateURL* t_url,
std::u16string term,
int visit_count) { … }
bool BaseSearchProviderTest::FindMatchWithContents(
const std::u16string& contents,
AutocompleteMatch* match) { … }
bool BaseSearchProviderTest::FindMatchWithDestination(
const GURL& url,
AutocompleteMatch* match) { … }
void BaseSearchProviderTest::FinishDefaultSuggestQuery(
const std::u16string& query_text) { … }
void BaseSearchProviderTest::CheckMatches(
const std::string& description,
const size_t num_expected_matches,
const ExpectedMatch expected_matches[],
const ACMatches& matches) { … }
void BaseSearchProviderTest::ClearAllResults() { … }
TEST_F(SearchProviderTest, QueryDefaultProvider) { … }
TEST_F(SearchProviderTest, QueryDefaultProvider_LensSearchbox) { … }
TEST_F(SearchProviderTest, HasQueryWhatYouTypedIfDefaultKeywordChanges) { … }
TEST_F(SearchProviderTest, HonorPreventInlineAutocomplete) { … }
TEST_F(SearchProviderTest, QueryKeywordProvider) { … }
TEST_F(SearchProviderTest, SendDataToSuggestAtAppropriateTimes) { … }
TEST_F(SearchProviderTest, DontAutocompleteURLLikeTerms) { … }
TEST_F(SearchProviderTest, DontAutocompleteUntilMultipleWordsTyped) { … }
TEST_F(SearchProviderTest, AutocompleteMultipleVisitsImmediately) { … }
TEST_F(SearchProviderTest, AutocompleteAfterSpace) { … }
TEST_F(SearchProviderTest, ScoreNewerSearchesHigher) { … }
TEST_F(SearchProviderTest, ResetResultsBetweenRuns) { … }
TEST_F(SearchProviderTest, DontReplacePreviousAutocompletion) { … }
TEST_F(SearchProviderTest, DontCrowdOutSingleWords) { … }
TEST_F(SearchProviderTest, InlineMixedCaseMatches) { … }
TEST_F(SearchProviderTest, KeywordOrderingAndDescriptions) { … }
TEST_F(SearchProviderTest, KeywordVerbatim) { … }
TEST_F(SearchProviderTest, NavSuggestNoSuggestedRelevanceScores) { … }
TEST_F(SearchProviderTest, SuggestRelevance) { … }
TEST_F(SearchProviderTest, DefaultProviderNoSuggestRelevanceInKeywordMode) { … }
TEST_F(SearchProviderTest, DefaultFetcherSuggestRelevance) { … }
TEST_F(SearchProviderTest, KeywordFetcherSuggestRelevance) { … }
TEST_F(SearchProviderTest, DontInlineAutocompleteAsynchronously) { … }
TEST_F(SearchProviderTest, DontCacheCalculatorSuggestions) { … }
TEST_F(SearchProviderTest, LocalAndRemoteRelevances) { … }
TEST_F(SearchProviderTest, DefaultProviderSuggestRelevanceScoringUrlInput) { … }
TEST_F(SearchProviderTest, FieldTrialTriggeredParsing) { … }
TEST_F(SearchProviderTest, SpecificTypeIdentifierParsing) { … }
TEST_F(SearchProviderTest, NavigationInline) { … }
TEST_F(SearchProviderTest, NavigationInlineSchemeSubstring) { … }
TEST_F(SearchProviderTest, NavigationInlineDomainClassify) { … }
TEST_F(SearchProviderTest, NavigationPrefixClassify) { … }
TEST_F(SearchProviderTest, NavigationMidWordClassify) { … }
TEST_F(SearchProviderTest, NavigationWordBreakClassify) { … }
TEST_F(SearchProviderTest, DoTrimHttpScheme) { … }
TEST_F(SearchProviderTest, DontTrimHttpSchemeIfInputHasScheme) { … }
TEST_F(SearchProviderTest, DontTrimHttpsSchemeIfInputHasScheme) { … }
TEST_F(SearchProviderTest, DoTrimHttpsScheme) { … }
TEST_F(SearchProviderTest, ParseEntitySuggestion) { … }
TEST_F(SearchProviderTest, PrefetchMetadataParsing) { … }
TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_InvalidResponse) { … }
TEST_F(SearchProviderTest, XSSIGuardedJSONParsing_ValidResponses) { … }
TEST_F(SearchProviderTest, ParseDeletionUrl) { … }
TEST_F(SearchProviderTest, CanSendRequestWithURL) { … }
class MockSearchProviderForTest
: public testing::NiceMock<SearchProviderForTest> { … };
MockSearchProviderForTest::MockSearchProviderForTest(
AutocompleteProviderClient* client,
AutocompleteProviderListener* listener,
Profile* profile)
: … { … }
class SearchProviderRequestTest : public SearchProviderTest { … };
TEST_F(SearchProviderRequestTest, SendRequestWithoutURL) { … }
TEST_F(SearchProviderRequestTest, SendRequestWithURL) { … }
TEST_F(SearchProviderRequestTest, SendRequestWithoutLensInteractionResponse) { … }
TEST_F(SearchProviderRequestTest, SendRequestWithLensInteractionResponse) { … }
TEST_F(SearchProviderTest, TestDeleteMatch) { … }
TEST_F(SearchProviderTest, TestDeleteHistoryQueryMatch) { … }
TEST_F(SearchProviderTest, CheckDuplicateMatchesSaved) { … }
TEST_F(SearchProviderTest, SuggestQueryUsesToken) { … }
TEST_F(SearchProviderTest, AnswersCache) { … }
TEST_F(SearchProviderTest, RemoveExtraAnswers) { … }
TEST_F(SearchProviderTest, DuplicateCardAnswer) { … }
TEST_F(SearchProviderTest, CopyAnswerToVerbatim) { … }
TEST_F(SearchProviderTest, DoesNotProvideOnFocus) { … }
TEST_F(InvalidSearchProviderTest, DoesNotSendSuggestRequests) { … }
TEST_F(SearchProviderTest, SendsWarmUpRequestOnFocus) { … }
class SearchProviderCommandLineOverrideTest : public SearchProviderTest { … };
TEST_F(SearchProviderCommandLineOverrideTest, CommandLineOverrides) { … }