[fenix] Close https://github.com/mozilla-mobile/fenix/issues/27023: Add capability to override telemetry URL
parent
9f534dcc6c
commit
fdaae59999
@ -0,0 +1,31 @@
|
||||
/* 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 android.content.Context
|
||||
import androidx.preference.PreferenceManager
|
||||
import mozilla.components.service.glean.config.Configuration
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
/**
|
||||
* Get custom Glean server URL if available.
|
||||
*/
|
||||
fun getCustomGleanServerUrlIfAvailable(context: Context): String? {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getString(
|
||||
context.getPreferenceKey(R.string.pref_key_custom_glean_server_url),
|
||||
null,
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the custom Glean server URL to the Configuration if available.
|
||||
*/
|
||||
fun Configuration.setCustomEndpointIfAvailable(serverEndpoint: String?): Configuration {
|
||||
if (!serverEndpoint.isNullOrEmpty()) {
|
||||
return copy(serverEndpoint = serverEndpoint)
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/* 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 io.mockk.mockk
|
||||
import mozilla.components.service.glean.config.Configuration
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotEquals
|
||||
import org.junit.Test
|
||||
|
||||
class ConfigurationKtTest {
|
||||
@Test
|
||||
fun `GIVEN server endpoint is null THEN return the same configuration`() {
|
||||
val configuration = Configuration(httpClient = mockk())
|
||||
|
||||
assertEquals(configuration, configuration.setCustomEndpointIfAvailable(null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN server endpoint is not empty THEN make a copy of configuration with server endpoint`() {
|
||||
val configuration = Configuration(httpClient = mockk())
|
||||
|
||||
assertNotEquals(configuration, configuration.setCustomEndpointIfAvailable("test"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `GIVEN server endpoint is empty THEN return the same configuration`() {
|
||||
val configuration = Configuration(httpClient = mockk())
|
||||
|
||||
assertEquals(configuration, configuration.setCustomEndpointIfAvailable(""))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue