package com.peachpasswords.vault import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test /** * Gate for the new-install default. The Credential Manager provider is on by * default for fresh installs so users get passkey sign-in without having to * dig into Settings. Existing users who explicitly disabled it must stay * off — the stored value is preserved over the default (see [VaultStore] * which falls back to [VaultSettings] only when nothing is on disk). */ class VaultSettingsDefaultsTest { @Test fun new_install_default_has_passkey_enabled() { assertTrue( "first-launch default must enable passkey provider — user said 'q2 is correct'", VaultSettings().passkeyProviderEnabled, ) } @Test fun explicitly_disabled_setting_round_trips_through_codec() { val original = VaultSettings(passkeyProviderEnabled = false) val encoded = VaultCodec.encodeSettings(original) val decoded = VaultCodec.decodeSettings(encoded) assertEquals(original, decoded) assertFalse("explicit off must not be auto-flipped to on by load", decoded!!.passkeyProviderEnabled) } @Test fun explicitly_enabled_setting_round_trips_through_codec() { val original = VaultSettings(passkeyProviderEnabled = true) val encoded = VaultCodec.encodeSettings(original) val decoded = VaultCodec.decodeSettings(encoded) assertEquals(original, decoded) } @Test fun legacy_enabled_favicons_doNotGainConsentByUpgrade() { val legacy = VaultCodec.decodeSettings("{\"faviconsEnabled\":true}")!! assertEquals(0, legacy.faviconConsentVersion) assertFalse(faviconsAllowed(legacy)) } @Test fun currentExplicitConsentAllowsEnabledFavicons() { val consented = grantCurrentFaviconConsent(VaultSettings()) assertTrue(consented.faviconsEnabled) assertEquals(CURRENT_FAVICON_CONSENT_VERSION, consented.faviconConsentVersion) assertTrue(faviconsAllowed(consented)) } @Test fun disabledFaviconsStayOffAfterPriorConsent() { val disabled = grantCurrentFaviconConsent(VaultSettings()).copy(faviconsEnabled = false) assertFalse(faviconsAllowed(disabled)) } }