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

This commit is contained in:
Oleg Semenenko
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent ca0a38d3fa
commit 794b68d364
7 changed files with 95 additions and 0 deletions
@@ -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))
}
}
@@ -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)
@@ -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 =