Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #3022: Update Yandex search engine. (#3050)
Browse files Browse the repository at this point in the history
  • Loading branch information
iccub committed Nov 19, 2020
1 parent bb19eb5 commit f819b55
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 122 deletions.
21 changes: 0 additions & 21 deletions Client/Assets/SearchPlugins/yandex-ru.xml

This file was deleted.

22 changes: 0 additions & 22 deletions Client/Assets/SearchPlugins/yandex-tr.xml

This file was deleted.

14 changes: 6 additions & 8 deletions Client/Assets/SearchPlugins/yandex.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/">
<ShortName>Яндекс</ShortName>
<ShortName>Yandex</ShortName>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAD8GlDQ1BJQ0MgUHJvZmlsZQAAOI2NVd1v21QUP4lvXKQWP6Cxjg4Vi69VU1u5GxqtxgZJk6XpQhq5zdgqpMl1bhpT1za2021Vn/YCbwz4A4CyBx6QeEIaDMT2su0BtElTQRXVJKQ9dNpAaJP2gqpwrq9Tu13GuJGvfznndz7v0TVAx1ea45hJGWDe8l01n5GPn5iWO1YhCc9BJ/RAp6Z7TrpcLgIuxoVH1sNfIcHeNwfa6/9zdVappwMknkJsVz19HvFpgJSpO64PIN5G+fAp30Hc8TziHS4miFhheJbjLMMzHB8POFPqKGKWi6TXtSriJcT9MzH5bAzzHIK1I08t6hq6zHpRdu2aYdJYuk9Q/881bzZa8Xrx6fLmJo/iu4/VXnfH1BB/rmu5ScQvI77m+BkmfxXxvcZcJY14L0DymZp7pML5yTcW61PvIN6JuGr4halQvmjNlCa4bXJ5zj6qhpxrujeKPYMXEd+q00KR5yNAlWZzrF+Ie+uNsdC/MO4tTOZafhbroyXu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/x-suggestions+json" method="GET" template="https://suggest.yandex.net/suggest-ff.cgi">
<Url type="application/x-suggestions+json" method="GET" template="https://suggest.yandex.ru/suggest-ff.cgi">
<Param name="part" value="{searchTerms}"/>
<!-- Despite name, this param applies to both desktop and mobile clients. -->
<Param name="srv" value="brave_desktop"/>
</Url>
<Url type="text/html" method="GET" template="https://yandex.kz/yandsearch">
<Param name="clid" value="2186727"/>
<Param name="text" value="{searchTerms}"/>
</Url>
<Url type="application/x-moz-tabletsearch" method="GET" template="https://yandex.kz/yandsearch">
<Param name="clid" value="2186733"/>
<Url type="text/html" method="GET" template="https://yandex.ru/search">
<Param name="text" value="{searchTerms}"/>
<Param name="clid" value="2423859"/>
</Url>
<SearchForm>https://www.yandex.kz/</SearchForm>
</SearchPlugin>
33 changes: 6 additions & 27 deletions Client/Frontend/Browser/Search/InitialSearchEngines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class InitialSearchEngines {

static let ddgDefaultRegions = ["DE", "AU", "NZ", "IE"]
static let qwantDefaultRegions = ["FR"]
static let yandexDefaultRegions = ["BY", "KZ", "RU", "TR"]
static let yandexDefaultRegions = ["AM", "AZ", "BY", "KG", "KZ", "MD", "RU", "TJ", "TM", "TZ"]
static let yahooEligibleRegions =
["GB", "US", "AR", "AT", "AU", "BR", "CA", "CH", "CL", "CO", "DE", "DK", "ES", "FI", "FR", "HK",
"ID", "IE", "IN", "IT", "MX", "MY", "NL", "NO", "NZ", "PE", "PH", "SE", "SG", "TH", "TW", "VE", "VN"]
Expand Down Expand Up @@ -99,35 +99,10 @@ class InitialSearchEngines {
// MARK: - Locale overrides

private func languageOverrides() {
guard let language = locale.languageCode, let region = locale.regionCode else { return }
guard let language = locale.languageCode else { return }
if language == "ja" {
replaceOrInsert(engineId: .yahoo, customId: "yahoo-jp")
}

if language == "ru" {
replaceOrInsert(engineId: .yandex, customId: "yandex-ru")

if Self.yandexDefaultRegions.contains(region) {
defaultSearchEngine = .yandex
}
}

if language == "kk" {
engines.append(.init(id: .yandex))

if Self.yandexDefaultRegions.contains(region) {
defaultSearchEngine = .yandex
}
}

if language == "tr" {
replaceOrInsert(engineId: .yandex, customId: "yandex-tr")

if Self.yandexDefaultRegions.contains(region) {
defaultSearchEngine = .yandex
}
}

}

private func regionOverrides() {
Expand All @@ -140,6 +115,10 @@ class InitialSearchEngines {
if Self.qwantDefaultRegions.contains(region) {
defaultSearchEngine = .qwant
}

if Self.yandexDefaultRegions.contains(region) {
defaultSearchEngine = .yandex
}
}

private func priorityOverrides() {
Expand Down
64 changes: 20 additions & 44 deletions ClientTests/InitialSearchEnginesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,50 +51,11 @@ class InitialSearchEnginesTests: XCTestCase {
}
}

func testYandexLocales() throws {

for language in ["ru", "kk", "tr"] {
for region in InitialSearchEngines.yandexDefaultRegions {
let localeSE = SE(locale: Locale(identifier: "\(language)_\(region)"))
let engines = localeSE.engines.map { $0.id }

XCTAssertEqual(engines, [.yandex,
.google,
.bing,
.duckduckgo,
.qwant,
.startpage])

XCTAssertEqual(localeSE.defaultSearchEngine, .yandex)

// Check for language specific search engines
if language == "ru" {
XCTAssertNotNil(localeSE.engines.first(where: { $0.customId == "yandex-ru" }))
}

if language == "tr" {
XCTAssertNotNil(localeSE.engines.first(where: { $0.customId == "yandex-tr" }))
}

if language == "kk" {
XCTAssertNil(localeSE.engines.first(where: { $0.id == .yandex })?.customId)
}
}

// non matching region
for region in ["XX", "PL"] {
let localeSE = SE(locale: Locale(identifier: "\(language)_\(region)"))
let engines = localeSE.engines.map { $0.id }

XCTAssertEqual(engines, [.google,
.bing,
.duckduckgo,
.qwant,
.startpage,
.yandex])

XCTAssertEqual(localeSE.defaultSearchEngine, .google)
}
func testYandexRegions() throws {

for region in InitialSearchEngines.yandexDefaultRegions {
let localeSE = SE(locale: Locale(identifier: "ru_\(region)"))
XCTAssertEqual(localeSE.defaultSearchEngine, .yandex)
}
}

Expand Down Expand Up @@ -189,4 +150,19 @@ class InitialSearchEnginesTests: XCTestCase {
XCTAssertEqual(unknownLocaleSE.defaultSearchEngine, .google)
XCTAssertNil(unknownLocaleSE.priorityEngine)
}

func testRuRu() throws {
let russianLocale = SE(locale: Locale(identifier: "ru_RU"))
let engines = russianLocale.engines.map { $0.id }

XCTAssertEqual(engines, [.yandex,
.google,
.bing,
.duckduckgo,
.qwant,
.startpage])

XCTAssertEqual(russianLocale.defaultSearchEngine, .yandex)
XCTAssertNil(russianLocale.priorityEngine)
}
}

0 comments on commit f819b55

Please sign in to comment.