#include "components/omnibox/browser/zero_suggest_provider.h"
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/metrics/field_trial.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/metrics/user_action_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "build/build_config.h"
#include "components/history/core/browser/top_sites.h"
#include "components/lens/proto/server/lens_overlay_response.pb.h"
#include "components/omnibox/browser/autocomplete_provider_listener.h"
#include "components/omnibox/browser/mock_autocomplete_provider_client.h"
#include "components/omnibox/browser/omnibox_field_trial.h"
#include "components/omnibox/browser/omnibox_prefs.h"
#include "components/omnibox/browser/test_scheme_classifier.h"
#include "components/omnibox/browser/zero_suggest_cache_service.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/testing_pref_service.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/variations/entropy_provider.h"
#include "components/variations/scoped_variations_ids_provider.h"
#include "components/variations/variations_associated_data.h"
#include "net/http/http_util.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 "url/gurl.h"
_;
CacheEntry;
namespace {
constexpr int kCacheSize = …;
class FakeAutocompleteProviderClient : public MockAutocompleteProviderClient { … };
}
class ZeroSuggestProviderTest : public testing::Test,
public AutocompleteProviderListener { … };
void ZeroSuggestProviderTest::SetUp() { … }
void ZeroSuggestProviderTest::OnProviderUpdate(
bool updated_matches,
const AutocompleteProvider* provider) { … }
TEST_F(ZeroSuggestProviderTest, AllowZeroPrefixSuggestionsNTP) { … }
TEST_F(ZeroSuggestProviderTest, AllowZeroPrefixSuggestionsOnSearchActivity) { … }
TEST_F(ZeroSuggestProviderTest, AllowZeroPrefixSuggestionsContextualWebAndSRP) { … }
TEST_F(ZeroSuggestProviderTest, AllowZeroPrefixSuggestionsRequestEligibility) { … }
class MockZeroSuggestProvider : public testing::NiceMock<ZeroSuggestProvider> { … };
MockZeroSuggestProvider::MockZeroSuggestProvider(
AutocompleteProviderClient* client,
AutocompleteProviderListener* listener)
: … { … }
class ZeroSuggestProviderRequestTest : public ZeroSuggestProviderTest { … };
#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
TEST_F(ZeroSuggestProviderRequestTest, RequestAllowed) {
EXPECT_CALL(*provider_, AllowZeroPrefixSuggestions(_, _))
.WillRepeatedly(testing::Return(true));
provider_->Start(OnFocusInputForNTP(), false);
EXPECT_FALSE(provider_->done());
EXPECT_TRUE(test_loader_factory()->IsPending("https://defaultturl2/?q=&"));
test_loader_factory()->AddResponse(
test_loader_factory()->GetPendingRequest(0)->request.url.spec(),
R"(["",[],[],[],{}])");
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(provider_->done());
provider_->Start(OnFocusInputForWeb("https://www.example.com"), false);
EXPECT_FALSE(provider_->done());
EXPECT_TRUE(test_loader_factory()->IsPending(
"https://defaultturl2/?q=&url=https%3A%2F%2Fwww.example.com%2F&"));
test_loader_factory()->AddResponse(
test_loader_factory()->GetPendingRequest(0)->request.url.spec(),
R"(["",[],[],[],{}])");
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(provider_->done());
}
#endif
TEST_F(ZeroSuggestProviderRequestTest, RequestDisallowed) { … }
TEST_F(ZeroSuggestProviderRequestTest, RequestAndRemoteSendURLDisallowed) { … }
TEST_F(ZeroSuggestProviderRequestTest,
SendRequestWithoutLensInteractionResponse) { … }
TEST_F(ZeroSuggestProviderRequestTest, SendRequestWithLensInteractionResponse) { … }
TEST_F(ZeroSuggestProviderTest, ResultTypeToRunOnFocusOnClobberContextualWeb) { … }
TEST_F(ZeroSuggestProviderTest, ResultTypeToRunOnFocusOnClobberSRP) { … }
TEST_F(ZeroSuggestProviderTest, StartStopNTP) { … }
TEST_F(ZeroSuggestProviderTest, StartStopSRP) { … }
TEST_F(ZeroSuggestProviderTest, StartStopWeb) { … }
TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestCachingFirstRunNTP) { … }
TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestCachingFirstRunSRP) { … }
TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestCachingFirstRunWeb) { … }
TEST_F(ZeroSuggestProviderTest,
TestPsuggestZeroSuggestOmitAsynchronousMatchesTrueNTP) { … }
TEST_F(ZeroSuggestProviderTest,
TestPsuggestZeroSuggestOmitAsynchronousMatchesTrueSRP) { … }
TEST_F(ZeroSuggestProviderTest,
TestPsuggestZeroSuggestOmitAsynchronousMatchesTrueWeb) { … }
TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestHasCachedResultsNTP) { … }
TEST_F(ZeroSuggestProviderTest, TestZeroSuggestHasInMemoryCachedResultsNTP) { … }
TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestHasCachedResultsSRP) { … }
TEST_F(ZeroSuggestProviderTest, TestZeroSuggestHasInMemoryCachedResultsSRP) { … }
TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestHasCachedResultsWeb) { … }
TEST_F(ZeroSuggestProviderTest, TestZeroSuggestHasInMemoryCachedResultsWeb) { … }
TEST_F(ZeroSuggestProviderTest,
TestPsuggestZeroSuggestReceivedEmptyResultsNTP) { … }
TEST_F(ZeroSuggestProviderTest,
TestPsuggestZeroSuggestReceivedEmptyResultsSRP) { … }
TEST_F(ZeroSuggestProviderTest,
TestPsuggestZeroSuggestReceivedEmptyResultsWeb) { … }
TEST_F(ZeroSuggestProviderTest, TestZeroSuggestReceivedInvalidResults) { … }
TEST_F(ZeroSuggestProviderTest, TestPsuggestZeroSuggestPrefetchThenNTPOnFocus) { … }
TEST_F(ZeroSuggestProviderTest, TestMultipleZeroSuggestPrefetchesInFlight) { … }
TEST_F(ZeroSuggestProviderTest,
TestPsuggestZeroSuggestPrefetchThenSRPOnClobber) { … }
TEST_F(ZeroSuggestProviderTest,
TestPsuggestZeroSuggestPrefetchThenWebOnClobber) { … }
TEST_F(ZeroSuggestProviderTest, TestNoURLResultTypeWithNonEmptyURLInput) { … }
TEST_F(ZeroSuggestProviderTest, TestDeleteMatchClearsPrefsBasedCache) { … }
TEST_F(ZeroSuggestProviderTest, TestDeleteMatchClearsInMemoryCache) { … }
TEST_F(ZeroSuggestProviderTest, TestDeleteMatchTriggersDeletionRequest) { … }