chromium/components/search_engines/template_url_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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "components/search_engines/template_url.h"

#include <stddef.h>

#include <string>

#include "base/base64.h"
#include "base/base_paths.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/i18n/case_conversion.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/with_feature_override.h"
#include "components/google/core/common/google_util.h"
#include "components/omnibox/common/omnibox_features.h"
#include "components/search_engines/regulatory_extension_type.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url_data.h"
#include "components/search_engines/testing_search_terms_data.h"
#include "net/base/url_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/omnibox_event.pb.h"
#include "third_party/metrics_proto/omnibox_input_type.pb.h"
#include "third_party/omnibox_proto/chrome_searchbox_stats.pb.h"
#include "ui/base/device_form_factor.h"

ASCIIToUTF16;
CreatedByPolicy;
RequestSource;

namespace {
bool IsLowerCase(const std::u16string& str) {}
}

class TemplateURLTest : public testing::Test {};

void TemplateURLTest::CheckSuggestBaseURL(
    const std::string& base_url,
    const std::string& base_suggest_url) const {}

// static
void TemplateURLTest::ExpectPostParamIs(const TemplateURLRef::PostParam& param,
                                        const std::string& name,
                                        const std::string& value,
                                        const std::string& content_type) {}

// static
void TemplateURLTest::ExpectContainsPostParam(
    const TemplateURLRef::PostParams& params,
    const std::string& name,
    const std::string& value,
    const std::string& content_type) {}

TEST_F(TemplateURLTest, Defaults) {}

TEST_F(TemplateURLTest, TestValidWithComplete) {}

TEST_F(TemplateURLTest, URLRefTestSearchTerms) {}

TEST_F(TemplateURLTest, URLRefTestCount) {}

TEST_F(TemplateURLTest, URLRefTestCount2) {}

TEST_F(TemplateURLTest, URLRefTestIndices) {}

TEST_F(TemplateURLTest, URLRefTestIndices2) {}

TEST_F(TemplateURLTest, URLRefTestEncoding) {}

TEST_F(TemplateURLTest, URLRefTestImageURLWithPOST) {}

TEST_F(TemplateURLTest, ImageThumbnailContentTypePostParams) {}

TEST_F(TemplateURLTest, ImageURLWithGetShouldNotCrash) {}

TEST_F(TemplateURLTest, ParsePlayStoreDefinitions) {}

// Test that setting the prepopulate ID from TemplateURL causes the stored
// TemplateURLRef to handle parsing the URL parameters differently.
TEST_F(TemplateURLTest, SetPrepopulatedAndParse) {}

// Test that setting the prepopulate ID from TemplateURL causes the stored
// TemplateURLRef to handle parsing the URL parameters differently.
TEST_F(TemplateURLTest, SetPrepopulatedAndReplace) {}

TEST_F(TemplateURLTest, InputEncodingBeforeSearchTerm) {}

TEST_F(TemplateURLTest, URLRefTestEncoding2) {}

TEST_F(TemplateURLTest, URLRefTestSearchTermsUsingTermsData) {}

TEST_F(TemplateURLTest, URLRefTermToWide) {}

TEST_F(TemplateURLTest, DisplayURLToURLRef) {}

TEST_F(TemplateURLTest, ReplaceSearchTerms) {}


// Tests replacing search terms in various encodings and making sure the
// generated URL matches the expected value.
TEST_F(TemplateURLTest, ReplaceArbitrarySearchTerms) {}

// Test that encoding with several optional codepages works as intended.
// Codepages are tried in order, fallback is UTF-8.
TEST_F(TemplateURLTest, ReplaceSearchTermsMultipleEncodings) {}

// Tests replacing prefetch parameters (pf) and searchbox stats (gs_lcrp) in
// various scenarios.
void TemplateURLTest::TestReplaceSearcboxStats(
    bool is_prefetch,
    const std::string& expected_prefetch_param,
    const std::string& expected_gs_lcrp_param) {}

TEST_F(TemplateURLTest, ReplaceSearchboxStats) {}

// Tests replacing cursor position.
TEST_F(TemplateURLTest, ReplaceCursorPosition) {}

// Tests replacing input type (&oit=).
TEST_F(TemplateURLTest, ReplaceInputType) {}

// Tests replacing omnibox focus type (&oft=).
TEST_F(TemplateURLTest, ReplaceOmniboxFocusType) {}

TEST_F(TemplateURLTest, GetRegulatoryExtensionType) {}

TEST_F(TemplateURLTest, GetRegulatoryExtension_NoExtension) {}

TEST_F(TemplateURLTest, GetRegulatoryExtension_OnlyDefaultExtension) {}

TEST_F(TemplateURLTest, GetRegulatoryExtension_WithDefaultAndEEAExtensions) {}

class TemplateURLOnePrefetchSourceTest : public base::test::WithFeatureOverride,
                                         public TemplateURLTest {};
INSTANTIATE_FEATURE_OVERRIDE_TEST_SUITE();
// Tests replacing prefetch param (&pf=) with assistedQueryStats.
TEST_P(TemplateURLOnePrefetchSourceTest, ReplaceIsPrefetch) {}

// Tests replacing currentPageUrl.
TEST_F(TemplateURLTest, ReplaceCurrentPageUrl) {}

#if BUILDFLAG(IS_ANDROID)
// Tests appending attribution parameter to queries originating from Play API
// search engine.
TEST_F(TemplateURLTest, PlayAPIAttributionEnabled) {
  base::test::ScopedFeatureList feature_list{
      switches::kSearchEngineChoiceAttribution};
  const struct TestData {
    const char* url;
    std::u16string terms;
    bool created_from_play_api;
    const char* output;
  } test_data[] = {
      {"http://foo/?q={searchTerms}", u"bar", false, "http://foo/?q=bar"},
      {"http://foo/?q={searchTerms}", u"bar", true,
       "http://foo/?q=bar&chrome_dse_attribution=1"}};
  TemplateURLData data;
  for (const auto& entry : test_data) {
    data.SetURL(entry.url);
    data.created_from_play_api = entry.created_from_play_api;
    TemplateURL url(data);
    EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
    ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
    GURL result(url.url_ref().ReplaceSearchTerms(
        TemplateURLRef::SearchTermsArgs(entry.terms), search_terms_data_));
    ASSERT_TRUE(result.is_valid());
    EXPECT_EQ(entry.output, result.spec());
  }
}

TEST_F(TemplateURLTest, PlayAPIAttributionDisabled) {
  base::test::ScopedFeatureList feature_list;
  feature_list.InitAndDisableFeature(switches::kSearchEngineChoiceAttribution);
  const struct TestData {
    const char* url;
    std::u16string terms;
    bool created_from_play_api;
    const char* output;
  } test_data[] = {
      {"http://foo/?q={searchTerms}", u"bar", false, "http://foo/?q=bar"},
      {"http://foo/?q={searchTerms}", u"bar", true, "http://foo/?q=bar"}};
  TemplateURLData data;
  for (const auto& entry : test_data) {
    data.SetURL(entry.url);
    data.created_from_play_api = entry.created_from_play_api;
    TemplateURL url(data);
    EXPECT_TRUE(url.url_ref().IsValid(search_terms_data_));
    ASSERT_TRUE(url.url_ref().SupportsReplacement(search_terms_data_));
    GURL result(url.url_ref().ReplaceSearchTerms(
        TemplateURLRef::SearchTermsArgs(entry.terms), search_terms_data_));
    ASSERT_TRUE(result.is_valid());
    EXPECT_EQ(entry.output, result.spec());
  }
}
#endif

TEST_F(TemplateURLTest, Suggestions) {}

TEST_F(TemplateURLTest, RLZ) {}

TEST_F(TemplateURLTest, RLZFromAppList) {}

TEST_F(TemplateURLTest, HostAndSearchTermKey) {}

TEST_F(TemplateURLTest, SearchTermKeyLocation) {}

TEST_F(TemplateURLTest, GoogleBaseSuggestURL) {}

TEST_F(TemplateURLTest, ParseParameterKnown) {}

TEST_F(TemplateURLTest, ParseParameterUnknown) {}

TEST_F(TemplateURLTest, ParseURLEmpty) {}

TEST_F(TemplateURLTest, ParseURLNoTemplateEnd) {}

TEST_F(TemplateURLTest, ParseURLNoKnownParameters) {}

TEST_F(TemplateURLTest, ParseURLTwoParameters) {}

TEST_F(TemplateURLTest, ParseURLNestedParameter) {}

TEST_F(TemplateURLTest, SearchSourceId) {}

TEST_F(TemplateURLTest, SearchClient) {}

TEST_F(TemplateURLTest, SuggestClient) {}

TEST_F(TemplateURLTest, SuggestRequestIdentifier) {}

TEST_F(TemplateURLTest, ZeroSuggestCacheDuration) {}

TEST_F(TemplateURLTest, GetURLNoSuggestionsURL) {}

TEST_F(TemplateURLTest, GetURLOnlyOneURL) {}

TEST_F(TemplateURLTest, ExtractSearchTermsFromURL) {}

TEST_F(TemplateURLTest, ExtractSearchTermsFromURLPath) {}

// Checks that the ExtractSearchTermsFromURL function works correctly
// for urls containing non-latin characters in UTF8 encoding.
TEST_F(TemplateURLTest, ExtractSearchTermsFromUTF8URL) {}

// Checks that the ExtractSearchTermsFromURL function works correctly
// for urls containing non-latin characters in non-UTF8 encoding.
TEST_F(TemplateURLTest, ExtractSearchTermsFromNonUTF8URL) {}

// Checks that the ExtractSearchTermsFromURL function strips constant
// prefix/suffix strings from the search terms param.
TEST_F(TemplateURLTest, ExtractSearchTermsWithPrefixAndSuffix) {}

TEST_F(TemplateURLTest, ReplaceSearchTermsInURL) {}

TEST_F(TemplateURLTest, ReplaceSearchTermsInURLPath) {}

// Checks that the ReplaceSearchTermsInURL function works correctly
// for search terms containing non-latin characters for a search engine
// using UTF-8 input encoding.
TEST_F(TemplateURLTest, ReplaceSearchTermsInUTF8URL) {}

// Checks that the ReplaceSearchTermsInURL function works correctly
// for search terms containing non-latin characters for a search engine
// using non UTF-8 input encoding.
TEST_F(TemplateURLTest, ReplaceSearchTermsInNonUTF8URL) {}

// Test the |additional_query_params| field of SearchTermsArgs.
TEST_F(TemplateURLTest, SuggestQueryParams) {}

// Test the |search_terms.append_extra_query_params_from_command_line| field of
// SearchTermsArgs.
TEST_F(TemplateURLTest, ExtraQueryParams) {}

// Tests replacing pageClassification.
TEST_F(TemplateURLTest, ReplacePageClassification) {}

// Test the IsSearchURL function.
TEST_F(TemplateURLTest, IsSearchURL) {}

TEST_F(TemplateURLTest, SearchboxVersionIncludedForAnswers) {}

TEST_F(TemplateURLTest, SessionToken) {}

TEST_F(TemplateURLTest, ContextualSearchParameters) {}

TEST_F(TemplateURLTest, GenerateKeyword) {}

TEST_F(TemplateURLTest, KeepSearchTermsInURL) {}

TEST_F(TemplateURLTest, GenerateSearchURL) {}

TEST_F(TemplateURLTest, GenerateURL_NoRegulatoryExtensions) {}

TEST_F(TemplateURLTest, GenerateURL_WithEmptyRegulatoryExtensions) {}

TEST_F(TemplateURLTest, GenerateURL_WithFullRegulatoryExtensions) {}

TEST_F(TemplateURLTest, GenerateURL_RegulatoryExtensionVariantHistograms) {}

TEST_F(TemplateURLTest, GenerateSuggestionURL) {}

TEST_F(TemplateURLTest, PrefetchQueryParameters) {}

// Tests that TemplateURL works correctly after changing the Google base URL
// and invalidating cached values.
TEST_F(TemplateURLTest, InvalidateCachedValues) {}

// Tests the use of wildcards in the path to ensure both extracting search terms
// and generating a search URL work correctly.
TEST_F(TemplateURLTest, PathWildcard) {}

TEST_F(TemplateURLTest, SideImageSearchParams) {}

TEST_F(TemplateURLTest, ImageTranslate) {}

TEST_F(TemplateURLTest, ImageSearchBrandingLabel) {}

struct IsBetterThanEngineTestEngine {};

TemplateURL CreateEngineFromTestEngine(
    const IsBetterThanEngineTestEngine& engine) {}

struct IsBetterThanEngineTestCase {} kTestCases[] =;

class TemplateURLIsBetterThanEngineTest
    : public TemplateURLTest,
      public testing::WithParamInterface<IsBetterThanEngineTestCase> {};

std::string ParamToTestSuffix(
    const ::testing::TestParamInfo<IsBetterThanEngineTestCase>& info) {}

INSTANTIATE_TEST_SUITE_P();

TEST_P(TemplateURLIsBetterThanEngineTest, Compare) {}