Skip to content

Commit

Permalink
Add Yandex as default for several Russian speaking locales.
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Nov 20, 2020
1 parent 586156d commit 7e1a7d2
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "brave/common/pref_names.h"
#include "brave/components/search_engines/brave_prepopulated_engines.h"
#include "components/google/core/common/google_switches.h"
#include "components/search_engines/search_engines_pref_names.h"
Expand Down Expand Up @@ -60,10 +61,18 @@ class BraveTemplateURLPrepopulateDataTest : public testing::Test {
public:
void SetUp() override {
TemplateURLPrepopulateData::RegisterProfilePrefs(prefs_.registry());
// Real registration happens in `brave/browser/brave_profile_prefs.cc`
// Calling brave::RegisterProfilePrefs() causes some problems though
auto* registry = prefs_.registry();
registry->RegisterIntegerPref(
kBraveDefaultSearchVersion,
TemplateURLPrepopulateData::kBraveCurrentDataVersion);
}

void CheckForCountry(char digit1, char digit2, const std::string& expected) {
prefs_.SetInteger(kCountryIDAtInstall, digit1 << 8 | digit2);
prefs_.SetInteger(kBraveDefaultSearchVersion,
TemplateURLPrepopulateData::kBraveCurrentDataVersion);
size_t default_index;
std::vector<std::unique_ptr<TemplateURLData>> t_urls =
TemplateURLPrepopulateData::GetPrepopulatedEngines(&prefs_,
Expand Down Expand Up @@ -173,3 +182,53 @@ TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForIreland) {
CheckForCountry('I', 'E', "DuckDuckGo");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForRepublicOfArmenia) {
CheckForCountry('A', 'M', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForRepublicOfAzerbaijan) {
CheckForCountry('A', 'Z', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForRepublicOfBelarus) {
CheckForCountry('B', 'Y', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForKyrgyzRepublic) {
CheckForCountry('K', 'G', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForRepublicOfKazakhstan) {
CheckForCountry('K', 'Z', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForRepublicOfMoldova) {
CheckForCountry('M', 'D', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForRussianFederation) {
CheckForCountry('R', 'U', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForRepublicOfTajikistan) {
CheckForCountry('T', 'J', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForTurkmenistan) {
CheckForCountry('T', 'M', "Yandex");
}

TEST_F(BraveTemplateURLPrepopulateDataTest,
DefaultSearchProvidersForRepublicOfUzbekistan) {
CheckForCountry('U', 'Z', "Yandex");
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ const std::vector<BravePrepopulatedEngineID> brave_engines_with_yahoo = {
PREPOPULATED_ENGINE_ID_STARTPAGE,
};

const std::vector<BravePrepopulatedEngineID> brave_engines_with_yandex = {
PREPOPULATED_ENGINE_ID_YANDEX,
PREPOPULATED_ENGINE_ID_GOOGLE,
PREPOPULATED_ENGINE_ID_DUCKDUCKGO,
PREPOPULATED_ENGINE_ID_QWANT,
PREPOPULATED_ENGINE_ID_BING,
PREPOPULATED_ENGINE_ID_STARTPAGE,
};

const std::vector<BravePrepopulatedEngineID> brave_engines_DE = {
PREPOPULATED_ENGINE_ID_YAHOO,
PREPOPULATED_ENGINE_ID_DUCKDUCKGO_DE,
Expand Down Expand Up @@ -88,6 +97,10 @@ const std::vector<BravePrepopulatedEngineID> brave_engines_AU_NZ_IE = {
// that don't use the default list.
const std::map<int, const std::vector<BravePrepopulatedEngineID>*>
default_engines_by_country_id_map = {
{country_codes::CountryCharsToCountryID('A', 'M'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('A', 'Z'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('A', 'R'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('A', 'T'),
Expand All @@ -96,6 +109,8 @@ const std::map<int, const std::vector<BravePrepopulatedEngineID>*>
&brave_engines_AU_NZ_IE},
{country_codes::CountryCharsToCountryID('B', 'R'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('B', 'Y'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('C', 'A'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('C', 'H'),
Expand Down Expand Up @@ -126,6 +141,12 @@ const std::map<int, const std::vector<BravePrepopulatedEngineID>*>
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('I', 'T'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('K', 'G'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('K', 'Z'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('M', 'D'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('M', 'X'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('M', 'Y'),
Expand All @@ -140,16 +161,24 @@ const std::map<int, const std::vector<BravePrepopulatedEngineID>*>
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('P', 'H'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('R', 'U'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('S', 'E'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('S', 'G'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('T', 'H'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('T', 'J'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('T', 'M'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('T', 'W'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('U', 'S'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('U', 'Z'),
&brave_engines_with_yandex},
{country_codes::CountryCharsToCountryID('V', 'E'),
&brave_engines_with_yahoo},
{country_codes::CountryCharsToCountryID('V', 'N'),
Expand All @@ -173,16 +202,52 @@ BravePrepopulatedEngineID GetDefaultSearchEngine(int country_id, int version) {
{country_codes::CountryCharsToCountryID('N', 'Z'),
PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE},
});
switch (version) {
case 6:
FALLTHROUGH;
default: {
auto it = content_v6->find(country_id);
if (it == content_v6->end()) {
return default_v6;
}
return it->second;
} break;
static const base::NoDestructor<base::flat_map<int,
BravePrepopulatedEngineID>>
content_v8({
{country_codes::CountryCharsToCountryID('A', 'M'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('A', 'Z'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('A', 'U'),
PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE},
{country_codes::CountryCharsToCountryID('B', 'Y'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('D', 'E'),
PREPOPULATED_ENGINE_ID_DUCKDUCKGO_DE},
{country_codes::CountryCharsToCountryID('F', 'R'),
PREPOPULATED_ENGINE_ID_QWANT},
{country_codes::CountryCharsToCountryID('I', 'E'),
PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE},
{country_codes::CountryCharsToCountryID('K', 'G'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('K', 'Z'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('M', 'D'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('N', 'Z'),
PREPOPULATED_ENGINE_ID_DUCKDUCKGO_AU_NZ_IE},
{country_codes::CountryCharsToCountryID('R', 'U'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('T', 'J'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('T', 'M'),
PREPOPULATED_ENGINE_ID_YANDEX},
{country_codes::CountryCharsToCountryID('U', 'Z'),
PREPOPULATED_ENGINE_ID_YANDEX},
});
if (version > 7) {
auto it = content_v8->find(country_id);
if (it == content_v8->end()) {
return default_v6;
}
return it->second;
} else {
auto it = content_v6->find(country_id);
if (it == content_v6->end()) {
return default_v6;
}
return it->second;
}
}

Expand Down
18 changes: 17 additions & 1 deletion components/search_engines/brave_prepopulated_engines.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace TemplateURLPrepopulateData {

// IMPORTANT! Make sure to bump this value if you make changes to the
// engines below or add/remove engines.
const int kBraveCurrentDataVersion = 7;
const int kBraveCurrentDataVersion = 8;
// DO NOT CHANGE THIS ONE. Used for backfilling kBraveDefaultSearchVersion.
const int kBraveFirstTrackedDataVersion = 6;

Expand All @@ -23,6 +23,7 @@ const std::map<BravePrepopulatedEngineID, const PrepopulatedEngine*>
brave_engines_map = {
{PREPOPULATED_ENGINE_ID_GOOGLE, &google},
{PREPOPULATED_ENGINE_ID_YAHOO, &brave_yahoo},
{PREPOPULATED_ENGINE_ID_YANDEX, &brave_yandex},
{PREPOPULATED_ENGINE_ID_YAHOO_AR, &brave_yahoo_ar},
{PREPOPULATED_ENGINE_ID_YAHOO_AT, &brave_yahoo_at},
{PREPOPULATED_ENGINE_ID_YAHOO_AU, &brave_yahoo_au},
Expand Down Expand Up @@ -195,6 +196,21 @@ const PrepopulatedEngine startpage = {
PREPOPULATED_ENGINE_ID_STARTPAGE,
};

const PrepopulatedEngine brave_yandex =
ModifyEngineParams(yandex_com,
L"Yandex",
NULL,
"https://yandex.ru/search/?clid="
#if defined(OS_ANDROID)
"2423859"
#else
"2353835"
#endif
"&text={searchTerms}",
"https://suggest.yandex.com/suggest-ff.cgi?"
"part={searchTerms}&uil=en&v=3&sn=5&srv=brave_desktop",
PREPOPULATED_ENGINE_ID_YANDEX);

#define kBraveYahooName L"Yahoo"
#define kBraveYahooKeyword L":y"
#define BRAVE_YAHOO_SEARCH_URL(PREFIX) \
Expand Down
2 changes: 2 additions & 0 deletions components/search_engines/brave_prepopulated_engines.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum BravePrepopulatedEngineID : unsigned int {
// These engine IDs are already defined in prepopulated_engines.json
PREPOPULATED_ENGINE_ID_GOOGLE = 1,
PREPOPULATED_ENGINE_ID_BING = 3,
PREPOPULATED_ENGINE_ID_YANDEX = 15,
// These engine IDs are not defined in Chromium
BRAVE_PREPOPULATED_ENGINES_START = 500,
PREPOPULATED_ENGINE_ID_AMAZON = 500, // No longer in defaults (2/2019).
Expand Down Expand Up @@ -96,6 +97,7 @@ extern const PrepopulatedEngine duckduckgo_lite;
#endif
extern const PrepopulatedEngine qwant;
extern const PrepopulatedEngine startpage;
extern const PrepopulatedEngine brave_yandex;

// Yahoo has unique URLs per region
extern const PrepopulatedEngine brave_yahoo;
Expand Down

0 comments on commit 7e1a7d2

Please sign in to comment.