mirror of
https://github.com/bitwarden/android.git
synced 2026-10-23 11:33:22 -05:00
BIT-1486: Use inline autofill based on user's setting (#702)
This commit is contained in:
1 parent
99f5325580
commit
4510695f76
5 files changed
+141
-10
No files matched your search
@@ -15,6 +15,7 @@ import com.x8bit.bitwarden.data.autofill.util.buildUriOrNull
|
||||
import com.x8bit.bitwarden.data.autofill.util.getInlinePresentationSpecs
|
||||
import com.x8bit.bitwarden.data.autofill.util.getMaxInlineSuggestionsCount
|
||||
import com.x8bit.bitwarden.data.autofill.util.toAutofillView
|
||||
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
@@ -64,6 +65,11 @@ class AutofillParserTests {
|
||||
every { this@mockk.fillContexts } returns listOf(fillContext)
|
||||
}
|
||||
private val inlinePresentationSpecs: List<InlinePresentationSpec> = mockk()
|
||||
private val settingsRepository: SettingsRepository = mockk {
|
||||
every { isInlineAutofillEnabled } answers { mockIsInlineAutofillEnabled }
|
||||
}
|
||||
|
||||
private var mockIsInlineAutofillEnabled = true
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
@@ -76,15 +82,31 @@ class AutofillParserTests {
|
||||
every {
|
||||
fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
} returns inlinePresentationSpecs
|
||||
every {
|
||||
fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = false,
|
||||
)
|
||||
} returns emptyList()
|
||||
every {
|
||||
fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
} returns MAX_INLINE_SUGGESTION_COUNT
|
||||
every {
|
||||
fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = false,
|
||||
)
|
||||
} returns 0
|
||||
every { any<List<ViewNodeTraversalData>>().buildUriOrNull(assistStructure) } returns URI
|
||||
parser = AutofillParserImpl()
|
||||
parser = AutofillParserImpl(
|
||||
settingsRepository = settingsRepository,
|
||||
)
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@@ -183,9 +205,11 @@ class AutofillParserTests {
|
||||
verify(exactly = 1) {
|
||||
fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
any<List<ViewNodeTraversalData>>().buildUriOrNull(assistStructure)
|
||||
}
|
||||
@@ -231,9 +255,11 @@ class AutofillParserTests {
|
||||
verify(exactly = 1) {
|
||||
fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
any<List<ViewNodeTraversalData>>().buildUriOrNull(assistStructure)
|
||||
}
|
||||
@@ -279,9 +305,11 @@ class AutofillParserTests {
|
||||
verify(exactly = 1) {
|
||||
fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
any<List<ViewNodeTraversalData>>().buildUriOrNull(assistStructure)
|
||||
}
|
||||
@@ -327,9 +355,62 @@ class AutofillParserTests {
|
||||
verify(exactly = 1) {
|
||||
fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
any<List<ViewNodeTraversalData>>().buildUriOrNull(assistStructure)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `parse should return empty inline suggestions when inline autofill is disabled`() {
|
||||
// Setup
|
||||
mockIsInlineAutofillEnabled = false
|
||||
setupAssistStructureWithAllAutofillViewTypes()
|
||||
val cardAutofillView: AutofillView.Card = AutofillView.Card.ExpirationMonth(
|
||||
data = autofillViewData.copy(
|
||||
autofillId = cardAutofillId,
|
||||
isFocused = true,
|
||||
),
|
||||
)
|
||||
val loginAutofillView: AutofillView.Login = AutofillView.Login.Username(
|
||||
data = autofillViewData.copy(
|
||||
autofillId = loginAutofillId,
|
||||
isFocused = true,
|
||||
),
|
||||
)
|
||||
val autofillPartition = AutofillPartition.Card(
|
||||
views = listOf(cardAutofillView),
|
||||
)
|
||||
val expected = AutofillRequest.Fillable(
|
||||
ignoreAutofillIds = emptyList(),
|
||||
inlinePresentationSpecs = emptyList(),
|
||||
maxInlineSuggestionsCount = 0,
|
||||
partition = autofillPartition,
|
||||
uri = URI,
|
||||
)
|
||||
every { cardViewNode.toAutofillView() } returns cardAutofillView
|
||||
every { loginViewNode.toAutofillView() } returns loginAutofillView
|
||||
|
||||
// Test
|
||||
val actual = parser.parse(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
fillRequest = fillRequest,
|
||||
)
|
||||
|
||||
// Verify
|
||||
assertEquals(expected, actual)
|
||||
verify(exactly = 1) {
|
||||
fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = false,
|
||||
)
|
||||
fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = false,
|
||||
)
|
||||
any<List<ViewNodeTraversalData>>().buildUriOrNull(assistStructure)
|
||||
}
|
||||
|
||||
+40
-4
@@ -20,7 +20,23 @@ class FillRequestExtensionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getInlinePresentationSpecs should return empty list when pre-R`() {
|
||||
fun `getInlinePresentationSpecs should return empty list when disabled`() {
|
||||
// Setup
|
||||
val autofillAppInfo: AutofillAppInfo = mockk()
|
||||
val expected: List<InlinePresentationSpec> = emptyList()
|
||||
|
||||
// Test
|
||||
val actual = fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = false,
|
||||
)
|
||||
|
||||
// Verify
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getInlinePresentationSpecs should return empty list when enabled pre-R`() {
|
||||
// Setup
|
||||
val autofillAppInfo = AutofillAppInfo(
|
||||
context = mockk(),
|
||||
@@ -32,6 +48,7 @@ class FillRequestExtensionsTest {
|
||||
// Test
|
||||
val actual = fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
|
||||
// Verify
|
||||
@@ -39,7 +56,7 @@ class FillRequestExtensionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getInlinePresentationSpecs should return populated list when post-R`() {
|
||||
fun `getInlinePresentationSpecs should return populated list when enabled and post-R`() {
|
||||
// Setup
|
||||
val autofillAppInfo = AutofillAppInfo(
|
||||
context = mockk(),
|
||||
@@ -51,6 +68,7 @@ class FillRequestExtensionsTest {
|
||||
// Test
|
||||
val actual = fillRequest.getInlinePresentationSpecs(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
|
||||
// Verify
|
||||
@@ -58,7 +76,23 @@ class FillRequestExtensionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getMaxInlineSuggestionsCount should return 0 when pre-R`() {
|
||||
fun `getMaxInlineSuggestionsCount should return 0 when disabled`() {
|
||||
// Setup
|
||||
val autofillAppInfo: AutofillAppInfo = mockk()
|
||||
val expected = 0
|
||||
|
||||
// Test
|
||||
val actual = fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = false,
|
||||
)
|
||||
|
||||
// Verify
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getMaxInlineSuggestionsCount should return 0 when enabled and pre-R`() {
|
||||
// Setup
|
||||
val autofillAppInfo = AutofillAppInfo(
|
||||
context = mockk(),
|
||||
@@ -70,6 +104,7 @@ class FillRequestExtensionsTest {
|
||||
// Test
|
||||
val actual = fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
|
||||
// Verify
|
||||
@@ -77,7 +112,7 @@ class FillRequestExtensionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getMaxInlineSuggestionsCount should return the max count when post-R`() {
|
||||
fun `getMaxInlineSuggestionsCount should return the max count when enabled and post-R`() {
|
||||
// Setup
|
||||
val autofillAppInfo = AutofillAppInfo(
|
||||
context = mockk(),
|
||||
@@ -89,6 +124,7 @@ class FillRequestExtensionsTest {
|
||||
// Test
|
||||
val actual = fillRequest.getMaxInlineSuggestionsCount(
|
||||
autofillAppInfo = autofillAppInfo,
|
||||
isInlineAutofillEnabled = true,
|
||||
)
|
||||
|
||||
// Verify
|
||||
|
||||
Reference in new issue
Block a user