AutofillTwoFactorChipLabelTest.kt

2.6 KB · raw

1package com.peachpasswords.autofill23import com.peachpasswords.autofill.AutofillResponseBuilder.FillMode4import com.peachpasswords.vault.VaultEntry5import org.junit.Assert.assertEquals6import org.junit.Assert.assertNotEquals7import org.junit.Test89/**10 * Confirms the keyboard-row chip carries WHAT it will fill. Users must be11 * able to tell a creds-fill chip from a TOTP-fill chip at a glance — same12 * labels on both pages was a real user-visible gap (logged 2026-08-05).13 *14 * The fix routes the OTP-only fill path through a separate FillMode so the15 * chip title carries the actual TOTP code instead of the entry title.16 */17class AutofillTwoFactorChipLabelTest {1819    private fun entry(20        title: String = "GitHub",21        username: String? = "june",22        email: String? = null,23        url: String? = "https://github.com",24        totp: String? = "JBSWY3DPEHPK3PXP",25    ) = VaultEntry(26        id = title, title = title, username = username, email = email, url = url, totp = totp,27        createdAt = 0, modifiedAt = 0,28    )2930    private fun loginLabels() =31        AutofillResponseBuilder.previewLabels(32            privatePreview = false,33            entry = entry(),34            originDomain = "github.com",35            fillMode = FillMode.LOGIN,36        )3738    private fun otpLabels(code: String = "482901") =39        AutofillResponseBuilder.previewLabels(40            privatePreview = false,41            entry = entry(),42            originDomain = "github.com",43            fillMode = FillMode.OTP_FILL,44            otpCode = code,45        )4647    @Test fun login_and_2fa_chips_now_differ() {48        val login = loginLabels()49        val otp = otpLabels()50        println("--- LOGIN chip labels ---")51        println("  title=${login.title}  subtitle=${login.subtitle}")52        println("--- 2FA chip labels ---")53        println("  title=${otp.title}  subtitle=${otp.subtitle}")54        assertEquals("GitHub", login.title)55        assertEquals("june", login.subtitle)56        assertEquals("482 901", otp.title)57        assertEquals("2FA", otp.subtitle)58        assertNotEquals(login.title, otp.title)59        assertNotEquals(login.subtitle, otp.subtitle)60    }6162    @Test fun otp_label_tracks_the_code_passed_in() {63        // The chip is recomputed each call — a fresh code passed in shows up64        // as the title. Verification gate for the datasetFor recompute path65        // (Phase B), which will route a chip-tap through this same labels66        // function with a newly-generated TOTP code.67        val one = otpLabels("111111")68        val two = otpLabels("222222")69        assertEquals("111 111", one.title)70        assertEquals("222 222", two.title)71    }72}