BIT-833: Add storage for "use inline autofill" setting (#645)

This commit is contained in:
Brian Yencho 2024-01-17 14:15:31 -06:00 committed by Álison Fernandes
parent 8d5bcc4433
commit dbbb9f6587
4 changed files with 94 additions and 2 deletions

View file

@ -92,4 +92,14 @@ interface SettingsDiskSource {
* Stores the given [isPullToRefreshEnabled] for the given [userId].
*/
fun storePullToRefreshEnabled(userId: String, isPullToRefreshEnabled: Boolean?)
/**
* Gets the value determining if inline autofill is enabled for the given [userId].
*/
fun getInlineAutofillEnabled(userId: String): Boolean?
/**
* Stores the given [isInlineAutofillEnabled] value for the given [userId].
*/
fun storeInlineAutofillEnabled(userId: String, isInlineAutofillEnabled: Boolean?)
}

View file

@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.onSubscription
private const val APP_LANGUAGE_KEY = "$BASE_KEY:appLocale"
private const val APP_THEME_KEY = "$BASE_KEY:theme"
private const val PULL_TO_REFRESH_KEY = "$BASE_KEY:syncOnRefresh"
private const val INLINE_AUTOFILL_ENABLED_KEY = "$BASE_KEY:inlineAutofillEnabled"
private const val VAULT_TIMEOUT_ACTION_KEY = "$BASE_KEY:vaultTimeoutAction"
private const val VAULT_TIME_IN_MINUTES_KEY = "$BASE_KEY:vaultTimeout"
private const val DISABLE_ICON_LOADING_KEY = "$BASE_KEY:disableFavicon"
@ -84,6 +85,8 @@ class SettingsDiskSourceImpl(
override fun clearData(userId: String) {
storeVaultTimeoutInMinutes(userId = userId, vaultTimeoutInMinutes = null)
storeVaultTimeoutAction(userId = userId, vaultTimeoutAction = null)
storePullToRefreshEnabled(userId = userId, isPullToRefreshEnabled = null)
storeInlineAutofillEnabled(userId = userId, isInlineAutofillEnabled = null)
}
override fun getVaultTimeoutInMinutes(userId: String): Int? =
@ -136,6 +139,19 @@ class SettingsDiskSourceImpl(
getMutablePullToRefreshEnabledFlowMap(userId = userId).tryEmit(isPullToRefreshEnabled)
}
override fun getInlineAutofillEnabled(userId: String): Boolean? =
getBoolean(key = "${INLINE_AUTOFILL_ENABLED_KEY}_$userId")
override fun storeInlineAutofillEnabled(
userId: String,
isInlineAutofillEnabled: Boolean?,
) {
putBoolean(
key = "${INLINE_AUTOFILL_ENABLED_KEY}_$userId",
value = isInlineAutofillEnabled,
)
}
private fun getMutableVaultTimeoutActionFlow(
userId: String,
): MutableSharedFlow<VaultTimeoutAction?> =

View file

@ -70,11 +70,21 @@ class SettingsDiskSourceTest {
userId = userId,
vaultTimeoutAction = VaultTimeoutAction.LOCK,
)
settingsDiskSource.storePullToRefreshEnabled(
userId = userId,
isPullToRefreshEnabled = true,
)
settingsDiskSource.storeInlineAutofillEnabled(
userId = userId,
isInlineAutofillEnabled = true,
)
settingsDiskSource.clearData(userId = userId)
assertNull(settingsDiskSource.getVaultTimeoutInMinutes(userId = userId))
assertNull(settingsDiskSource.getVaultTimeoutAction(userId = userId))
assertNull(settingsDiskSource.getPullToRefreshEnabled(userId = userId))
assertNull(settingsDiskSource.getInlineAutofillEnabled(userId = userId))
}
@Test
@ -329,7 +339,7 @@ class SettingsDiskSourceTest {
}
@Test
fun `storePullToRefreshEnabled when values are present should pull from SharedPreferences`() {
fun `getPullToRefreshEnabled when values are present should pull from SharedPreferences`() {
val pullToRefreshBaseKey = "bwPreferencesStorage:syncOnRefresh"
val mockUserId = "mockUserId"
val pullToRefreshKey = "${pullToRefreshBaseKey}_$mockUserId"
@ -341,7 +351,7 @@ class SettingsDiskSourceTest {
}
@Test
fun `storePullToRefreshEnabled when values are absent should return null`() {
fun `getPullToRefreshEnabled when values are absent should return null`() {
val mockUserId = "mockUserId"
assertNull(settingsDiskSource.getPullToRefreshEnabled(userId = mockUserId))
}
@ -388,4 +398,47 @@ class SettingsDiskSourceTest {
)
assertFalse(fakeSharedPreferences.contains(pullToRefreshKey))
}
@Test
fun `getInlineAutofillEnabled when values are present should pull from SharedPreferences`() {
val inlineAutofillEnabledBaseKey = "bwPreferencesStorage:inlineAutofillEnabled"
val mockUserId = "mockUserId"
val inlineAutofillEnabledKey = "${inlineAutofillEnabledBaseKey}_$mockUserId"
fakeSharedPreferences
.edit {
putBoolean(inlineAutofillEnabledKey, true)
}
assertEquals(true, settingsDiskSource.getInlineAutofillEnabled(userId = mockUserId))
}
@Test
fun `getInlineAutofillEnabled when values are absent should return null`() {
val mockUserId = "mockUserId"
assertNull(settingsDiskSource.getInlineAutofillEnabled(userId = mockUserId))
}
@Test
fun `storeInlineAutofillEnabled for non-null values should update SharedPreferences`() {
val inlineAutofillEnabledBaseKey = "bwPreferencesStorage:inlineAutofillEnabled"
val mockUserId = "mockUserId"
val inlineAutofillEnabledKey = "${inlineAutofillEnabledBaseKey}_$mockUserId"
settingsDiskSource.storeInlineAutofillEnabled(
userId = mockUserId,
isInlineAutofillEnabled = true,
)
assertTrue(fakeSharedPreferences.getBoolean(inlineAutofillEnabledKey, false))
}
@Test
fun `storeInlineAutofillEnabled for null values should clear SharedPreferences`() {
val inlineAutofillEnabledBaseKey = "bwPreferencesStorage:inlineAutofillEnabled"
val mockUserId = "mockUserId"
val inlineAutofillEnabledKey = "${inlineAutofillEnabledBaseKey}_$mockUserId"
fakeSharedPreferences.edit { putBoolean(inlineAutofillEnabledKey, false) }
settingsDiskSource.storeInlineAutofillEnabled(
userId = mockUserId,
isInlineAutofillEnabled = null,
)
assertFalse(fakeSharedPreferences.contains(inlineAutofillEnabledKey))
}
}

View file

@ -34,6 +34,7 @@ class FakeSettingsDiskSource : SettingsDiskSource {
private val storedVaultTimeoutInMinutes = mutableMapOf<String, Int?>()
private val storedPullToRefreshEnabled = mutableMapOf<String, Boolean?>()
private val storedInlineAutofillEnabled = mutableMapOf<String, Boolean?>()
private var storedIsIconLoadingDisabled: Boolean? = null
@ -66,6 +67,8 @@ class FakeSettingsDiskSource : SettingsDiskSource {
override fun clearData(userId: String) {
storedVaultTimeoutActions.remove(userId)
storedVaultTimeoutInMinutes.remove(userId)
storedPullToRefreshEnabled.remove(userId)
storedInlineAutofillEnabled.remove(userId)
mutableVaultTimeoutActionsFlowMap.remove(userId)
mutableVaultTimeoutInMinutesFlowMap.remove(userId)
@ -113,6 +116,16 @@ class FakeSettingsDiskSource : SettingsDiskSource {
getMutablePullToRefreshEnabledFlow(userId = userId).tryEmit(isPullToRefreshEnabled)
}
override fun getInlineAutofillEnabled(userId: String): Boolean? =
storedInlineAutofillEnabled[userId]
override fun storeInlineAutofillEnabled(
userId: String,
isInlineAutofillEnabled: Boolean?,
) {
storedInlineAutofillEnabled[userId] = isInlineAutofillEnabled
}
//region Private helper functions
private fun getMutableVaultTimeoutActionsFlow(