chromium/components/omnibox/browser/zero_suggest_provider_unittest.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {};

}  // namespace

class ZeroSuggestProviderTest : public testing::Test,
                                public AutocompleteProviderListener {};

void ZeroSuggestProviderTest::SetUp() {}

void ZeroSuggestProviderTest::OnProviderUpdate(
    bool updated_matches,
    const AutocompleteProvider* provider) {}

// Tests whether zero-suggest is allowed on NTP.
TEST_F(ZeroSuggestProviderTest, AllowZeroPrefixSuggestionsNTP) {}

TEST_F(ZeroSuggestProviderTest, AllowZeroPrefixSuggestionsOnSearchActivity) {}

// Tests whether zero-suggest is allowed on Web/SRP when the external request
// conditions are met.
TEST_F(ZeroSuggestProviderTest, AllowZeroPrefixSuggestionsContextualWebAndSRP) {}

// Tests whether zero-suggest is allowed on NTP/Web/SRP with various external
// request conditions and that the appropriate eligibility metrics are logged.
TEST_F(ZeroSuggestProviderTest, AllowZeroPrefixSuggestionsRequestEligibility) {}

// ZeroSuggestProviderRequestTest ----------------------------------------------

class MockZeroSuggestProvider : public testing::NiceMock<ZeroSuggestProvider> {};

MockZeroSuggestProvider::MockZeroSuggestProvider(
    AutocompleteProviderClient* client,
    AutocompleteProviderListener* listener)
    :{}

// Test environment to verify whether zero-suggest request is made and whether
// the page URL is sent in the request when all the conditions are met or not.
class ZeroSuggestProviderRequestTest : public ZeroSuggestProviderTest {};

#if BUILDFLAG(IS_IOS) || BUILDFLAG(IS_ANDROID)
TEST_F(ZeroSuggestProviderRequestTest, RequestAllowed) {
  EXPECT_CALL(*provider_, AllowZeroPrefixSuggestions(_, _))
      .WillRepeatedly(testing::Return(true));

  // Start a query for the ResultType::kRemoteNoURL variant.
  provider_->Start(OnFocusInputForNTP(), false);
  // Make sure the default provider's suggest endpoint was queried without the
  // current page URL.
  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());

  // Start a query for the ResultType::kRemoteSendURL variant.
  provider_->Start(OnFocusInputForWeb("https://www.example.com"), false);
  // Make sure the default provider's suggest endpoint was queried with the
  // current page URL.
  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) {}