Save the value for showing the initial autofill dialog (#916)

This commit is contained in:
Oleg Semenenko 2024-01-31 19:28:32 -06:00 committed by Álison Fernandes
parent ca0a38d3fa
commit 794b68d364
7 changed files with 95 additions and 0 deletions

View file

@ -18,6 +18,11 @@ interface SettingsDiskSource {
*/
var appLanguage: AppLanguage?
/**
* Has the initial autofill dialog been shown to the user.
*/
var initialAutofillDialogShown: Boolean?
/**
* The currently persisted app theme (or `null` if not set).
*/

View file

@ -32,6 +32,7 @@ private const val SYSTEM_BIOMETRIC_INTEGRITY_SOURCE_KEY = "$BASE_KEY:biometricIn
private const val ACCOUNT_BIOMETRIC_INTEGRITY_VALID_KEY = "$BASE_KEY:accountBiometricIntegrityValid"
private const val CRASH_LOGGING_ENABLED_KEY = "$BASE_KEY:crashLoggingEnabled"
private const val CLEAR_CLIPBOARD_INTERVAL_KEY = "$BASE_KEY:clearClipboard"
private const val INITIAL_AUTOFILL_DIALOG_SHOWN = "$BASE_KEY:addSitePromptShown"
/**
* Primary implementation of [SettingsDiskSource].
@ -77,6 +78,15 @@ class SettingsDiskSourceImpl(
)
}
override var initialAutofillDialogShown: Boolean?
get() = getBoolean(key = INITIAL_AUTOFILL_DIALOG_SHOWN)
set(value) {
putBoolean(
key = INITIAL_AUTOFILL_DIALOG_SHOWN,
value = value,
)
}
override var systemBiometricIntegritySource: String?
get() = getString(key = SYSTEM_BIOMETRIC_INTEGRITY_SOURCE_KEY)
set(value) {

View file

@ -32,6 +32,11 @@ interface SettingsRepository {
*/
val appThemeStateFlow: StateFlow<AppTheme>
/**
* Has the initial autofill dialog been shown to the user.
*/
var initialAutofillDialogShown: Boolean
/**
* The currently stored last time the vault was synced.
*/

View file

@ -65,6 +65,12 @@ class SettingsRepositoryImpl(
initialValue = settingsDiskSource.appTheme,
)
override var initialAutofillDialogShown: Boolean
get() = settingsDiskSource.initialAutofillDialogShown ?: false
set(value) {
settingsDiskSource.initialAutofillDialogShown = value
}
override var vaultLastSync: Instant?
get() = vaultLastSyncStateFlow.value
set(value) {

View file

@ -936,4 +936,53 @@ class SettingsDiskSourceTest {
settingsDiskSource.getClearClipboardFrequencySeconds(mockUserId),
)
}
@Test
fun `initialAutofillDialogShown should pull from and update SharedPreferences`() {
val initialAutofillDialogShownKey = "bwPreferencesStorage:addSitePromptShown"
val expectedValue = true
assertEquals(null, settingsDiskSource.initialAutofillDialogShown)
assertFalse(fakeSharedPreferences.getBoolean(initialAutofillDialogShownKey, false))
// Update SharedPreferences updates the disk source
fakeSharedPreferences.edit {
putBoolean(initialAutofillDialogShownKey, expectedValue)
}
assertEquals(
expectedValue,
settingsDiskSource.initialAutofillDialogShown,
)
// Updating the disk source updates shared preferences
settingsDiskSource.initialAutofillDialogShown = false
assertFalse(fakeSharedPreferences.getBoolean(initialAutofillDialogShownKey, true))
}
@Suppress("MaxLineLength")
@Test
fun `initialAutofillDialogShown should clear the SharedPreferences value if the value is null `() {
val initialAutofillDialogShownKey = "bwPreferencesStorage:addSitePromptShown"
val expectedValue = true
assertEquals(null, settingsDiskSource.initialAutofillDialogShown)
assertFalse(fakeSharedPreferences.getBoolean(initialAutofillDialogShownKey, false))
// Update SharedPreferences updates the disk source
fakeSharedPreferences.edit {
putBoolean(initialAutofillDialogShownKey, expectedValue)
}
assertEquals(
expectedValue,
settingsDiskSource.initialAutofillDialogShown,
)
// Updating the disk source updates shared preferences
settingsDiskSource.initialAutofillDialogShown = null
assertFalse(fakeSharedPreferences.contains(initialAutofillDialogShownKey))
}
}

View file

@ -51,6 +51,7 @@ class FakeSettingsDiskSource : SettingsDiskSource {
private val storedBlockedAutofillUris = mutableMapOf<String, List<String>?>()
private var storedIsIconLoadingDisabled: Boolean? = null
private var storedIsCrashLoggingEnabled: Boolean? = null
private var storedInitialAutofillDialogShown: Boolean? = null
private val storedApprovePasswordLoginsEnabled = mutableMapOf<String, Boolean?>()
private val storedScreenCaptureAllowed = mutableMapOf<String, Boolean?>()
private var storedSystemBiometricIntegritySource: String? = null
@ -83,6 +84,12 @@ class FakeSettingsDiskSource : SettingsDiskSource {
mutableIsIconLoadingDisabled.tryEmit(value)
}
override var initialAutofillDialogShown: Boolean?
get() = storedInitialAutofillDialogShown
set(value) {
storedInitialAutofillDialogShown = value
}
override val isIconLoadingDisabledFlow: Flow<Boolean?>
get() = mutableIsIconLoadingDisabled.onSubscription {
emit(isIconLoadingDisabled)

View file

@ -898,6 +898,19 @@ class SettingsRepositoryTest {
settingsRepository.clearClipboardFrequency,
)
}
@Suppress("MaxLineLength")
@Test
fun `initialAutofillDialogShown should pull from and update SettingsDiskSource`() =
runTest {
fakeAuthDiskSource.userState = MOCK_USER_STATE
fakeSettingsDiskSource.initialAutofillDialogShown = true
assertTrue(settingsRepository.initialAutofillDialogShown)
settingsRepository.initialAutofillDialogShown = false
assertEquals(false, fakeSettingsDiskSource.initialAutofillDialogShown)
}
}
private val MOCK_USER_STATE =