[fenix] For https://github.com/mozilla-mobile/fenix/issues/22879: Filter default engines when sending telemetry.
Filter out custom engines that are not well known search domains.pull/600/head
parent
cb307f7bd3
commit
1facaaf775
@ -0,0 +1,33 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
|
||||
// List of well known search domains, taken from
|
||||
// https://searchfox.org/mozilla-central/source/toolkit/components/search/SearchService.jsm#2405
|
||||
private val wellKnownSearchDomains = setOf(
|
||||
"aol",
|
||||
"ask",
|
||||
"baidu",
|
||||
"bing",
|
||||
"duckduckgo",
|
||||
"google",
|
||||
"yahoo",
|
||||
"yandex",
|
||||
"startpage"
|
||||
)
|
||||
|
||||
/**
|
||||
* Whether or not the search engine is a custom engine added by the user.
|
||||
*/
|
||||
fun SearchEngine.isCustomEngine(): Boolean =
|
||||
this.type == SearchEngine.Type.CUSTOM
|
||||
|
||||
/**
|
||||
* Whether or not the search engine is a known search domain.
|
||||
*/
|
||||
fun SearchEngine.isKnownSearchDomain(): Boolean =
|
||||
this.resultUrls[0].findAnyOf(wellKnownSearchDomains, 0, true) != null
|
@ -0,0 +1,67 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ext
|
||||
|
||||
import mozilla.components.browser.state.search.SearchEngine
|
||||
import mozilla.components.support.test.mock
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.util.UUID
|
||||
|
||||
class SearchEngineTest {
|
||||
|
||||
@Test
|
||||
fun `custom search engines are identified correctly`() {
|
||||
val searchEngine = SearchEngine(
|
||||
id = UUID.randomUUID().toString(),
|
||||
name = "Not custom",
|
||||
icon = mock(),
|
||||
type = SearchEngine.Type.BUNDLED,
|
||||
resultUrls = listOf(
|
||||
"https://www.startpage.com/sp/search?q={searchTerms}"
|
||||
)
|
||||
)
|
||||
|
||||
val customSearchEngine = SearchEngine(
|
||||
id = UUID.randomUUID().toString(),
|
||||
name = "Custom",
|
||||
icon = mock(),
|
||||
type = SearchEngine.Type.CUSTOM,
|
||||
resultUrls = listOf(
|
||||
"https://www.startpage.com/sp/search?q={searchTerms}"
|
||||
)
|
||||
)
|
||||
|
||||
assertFalse(searchEngine.isCustomEngine())
|
||||
assertTrue(customSearchEngine.isCustomEngine())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `well known search engines are identified correctly`() {
|
||||
val searchEngine = SearchEngine(
|
||||
id = UUID.randomUUID().toString(),
|
||||
name = "Not well known",
|
||||
icon = mock(),
|
||||
type = SearchEngine.Type.BUNDLED,
|
||||
resultUrls = listOf(
|
||||
"https://www.random.com/sp/search?q={searchTerms}"
|
||||
)
|
||||
)
|
||||
|
||||
val wellKnownSearchEngine = SearchEngine(
|
||||
id = UUID.randomUUID().toString(),
|
||||
name = "Well known",
|
||||
icon = mock(),
|
||||
type = SearchEngine.Type.CUSTOM,
|
||||
resultUrls = listOf(
|
||||
"https://www.startpage.com/sp/search?q={searchTerms}"
|
||||
)
|
||||
)
|
||||
|
||||
assertFalse(searchEngine.isKnownSearchDomain())
|
||||
assertTrue(wellKnownSearchEngine.isKnownSearchDomain())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue