forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close mozilla-mobile#27023: Add capability to override telemetry URL
- Loading branch information
1 parent
50c8e56
commit 6c7c866
Showing
6 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/test/java/org/mozilla/fenix/ext/ConfigurationKtTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("")) | ||
} | ||
} |