chromium/components/omnibox/browser/autocomplete_provider_unittest.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#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 {};

// AutocompleteController::Observer implementation that runs the provided
// closure, when the controller is done.
class TestAutocompleteControllerObserver
    : public AutocompleteController::Observer {};

// AutocompleteProviderListener implementation that runs the provided closure,
// when the provider is done. Informs the controller for non-prefetch requests.
class TestAutocompleteProviderListener : public AutocompleteProviderListener {};

}  // namespace

// Autocomplete provider that provides known results. Note that this is
// refcounted so that it can also be a task on the message loop.
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) {}

// Helper class to make running tests of ClassifyAllMatchesInString() more
// convenient.
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 {}

// Tests that the default selection is set properly when updating results.
TEST_F(AutocompleteProviderTest, Query) {}

// Tests searchbox stats.
TEST_F(AutocompleteProviderTest, SearchboxStats) {}

TEST_F(AutocompleteProviderTest, RemoveDuplicates) {}

TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) {}

// Ensures matches from (only) the default search provider respect any extra
// query params set on the command line.
TEST_F(AutocompleteProviderTest, ExtraQueryParams) {}

// Ensures matches from (only) the default search provider are curbed when in
// keyword mode and LimitKeywordModeSuggestions is enabled.
TEST_F(AutocompleteProviderTest, CurbDefaultSuggestions) {}

// Test that redundant associated keywords are removed.
TEST_F(AutocompleteProviderTest, RedundantKeywordsIgnoredInResult) {}

// Test that exact match keywords trump keywords associated with
// the match.
TEST_F(AutocompleteProviderTest, ExactMatchKeywords) {}

// Tests that the AutocompleteResult is updated with the suggestion group
// information and matches with group IDs are grouped and demoted correctly.
// Also verifies that:
// 1) headers are optional for suggestion groups.
// 2) suggestion groups are ordered based on their priories.
// 3) suggestion group IDs without associated suggestion group information are
//    stripped away.
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) {}