#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/search_engines/template_url_prepopulate_data.h"
#include <stddef.h>
#include <memory>
#include <numeric>
#include <utility>
#include <vector>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/containers/to_vector.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "base/values.h"
#include "components/country_codes/country_codes.h"
#include "components/google/core/common/google_switches.h"
#include "components/search_engines/eea_countries_ids.h"
#include "components/search_engines/prepopulated_engines.h"
#include "components/search_engines/search_engine_choice/search_engine_choice_service.h"
#include "components/search_engines/search_engine_choice/search_engine_choice_utils.h"
#include "components/search_engines/search_engine_type.h"
#include "components/search_engines/search_engines_pref_names.h"
#include "components/search_engines/search_engines_switches.h"
#include "components/search_engines/search_engines_test_environment.h"
#include "components/search_engines/search_engines_test_util.h"
#include "components/search_engines/search_terms_data.h"
#include "components/search_engines/template_url.h"
#include "components/search_engines/template_url_data_util.h"
#include "components/search_engines/testing_search_terms_data.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
ASCIIToUTF16;
namespace {
SearchEngineType GetEngineType(const std::string& url) { … }
std::string GetHostFromTemplateURLData(const TemplateURLData& data) { … }
const int kAllCountryIds[] = …;
void CheckUrlIsEmptyOrSecure(const std::string url) { … }
void CheckTemplateUrlRefIsCryptographic(const TemplateURLRef& url_ref) { … }
}
class TemplateURLPrepopulateDataTest : public testing::Test { … };
TEST_F(TemplateURLPrepopulateDataTest, UniqueIDs) { … }
TEST_F(TemplateURLPrepopulateDataTest, NumberOfEntriesPerCountryConsistency) { … }
TEST_F(TemplateURLPrepopulateDataTest, EntriesPerCountryConsistency) { … }
TEST_F(TemplateURLPrepopulateDataTest,
SearchEnginesOrderDoesNotChangePerProfile) { … }
TEST_F(TemplateURLPrepopulateDataTest,
SearchEnginesOrderChangesOnChromeUpdate) { … }
TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrefs) { … }
TEST_F(TemplateURLPrepopulateDataTest, ClearProvidersFromPrefs) { … }
TEST_F(TemplateURLPrepopulateDataTest, ProvidersFromPrepopulated) { … }
TEST_F(TemplateURLPrepopulateDataTest, PrepopulatedAreHttps) { … }
TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeBasic) { … }
TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeAdvanced) { … }
TEST_F(TemplateURLPrepopulateDataTest, GetEngineTypeForAllPrepopulatedEngines) { … }
TEST_F(TemplateURLPrepopulateDataTest, CheckSearchURLDetection) { … }
TEST_F(TemplateURLPrepopulateDataTest, HttpsUrls) { … }
TEST_F(TemplateURLPrepopulateDataTest, FindGoogleAsFallback) { … }
TEST_F(TemplateURLPrepopulateDataTest, GetPrepopulatedEngineFromFullList) { … }
#if BUILDFLAG(IS_ANDROID)
TEST_F(TemplateURLPrepopulateDataTest, GetLocalPrepopulatedEngines) {
constexpr char sample_country[] = "US";
OverrideCountryId(country_codes::CountryCharsToCountryID(sample_country[0],
sample_country[1]));
auto expected_urls = TemplateURLPrepopulateData::GetPrepopulatedEngines(
pref_service(), search_engine_choice_service());
auto actual_urls = TemplateURLPrepopulateData::GetLocalPrepopulatedEngines(
sample_country, *pref_service());
ASSERT_EQ(actual_urls.size(), expected_urls.size());
for (unsigned int i = 0; i < actual_urls.size(); ++i) {
EXPECT_EQ(actual_urls[i]->prepopulate_id, expected_urls[i]->prepopulate_id);
EXPECT_EQ(actual_urls[i]->keyword(), expected_urls[i]->keyword());
EXPECT_EQ(actual_urls[i]->url(), expected_urls[i]->url());
}
EXPECT_THAT(TemplateURLPrepopulateData::GetLocalPrepopulatedEngines(
"NOT A COUNTRY", *pref_service()),
testing::IsEmpty());
}
#endif
class TemplateURLPrepopulateDataListTest
: public TemplateURLPrepopulateDataTest,
public testing::WithParamInterface<int> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(TemplateURLPrepopulateDataListTest,
QuickEeaEngineListIsRandomPerCountry) { … }
TEST_P(TemplateURLPrepopulateDataListTest,
DISABLED_ManualEeaEngineListIsRandomPerCountry) { … }