Skip to content

Commit

Permalink
refactor: call autofill feature directly from runtime config
Browse files Browse the repository at this point in the history
  • Loading branch information
dbajpeyi committed Aug 30, 2024
1 parent d284aea commit 5138d1d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5834,6 +5834,5 @@ class BrowserTabViewModelTest {
override suspend fun canSaveCredentialsFromWebView(url: String) = enabled
override suspend fun canGeneratePasswordFromWebView(url: String) = enabled
override suspend fun canAccessCredentialManagementScreen() = enabled
override suspend fun canCategorizeUnknownUsername() = enabled
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,4 @@ interface AutofillCapabilityChecker {
* Whether autofill is configured to be enabled. This is a configuration value, not a user preference.
*/
suspend fun isAutofillEnabledByConfiguration(url: String): Boolean

/**
* Whether canCategorizeUnknownUsername feature is configured to be enabled.
*/
suspend fun canCategorizeUnknownUsername(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ class AutofillCapabilityCheckerImpl @Inject constructor(
return@withContext autofillFeature.canAccessCredentialManagement().isEnabled()
}

override suspend fun canCategorizeUnknownUsername(): Boolean = withContext(dispatcherProvider.io()) {
return@withContext autofillFeature.canCategorizeUnknownUsername().isEnabled()
}

private suspend fun isInternalTester(): Boolean {
return withContext(dispatcherProvider.io()) {
internalTestUserChecker.isInternalTestUser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.duckduckgo.autofill.impl.configuration

import com.duckduckgo.autofill.api.AutofillCapabilityChecker
import com.duckduckgo.autofill.api.AutofillFeature
import com.duckduckgo.autofill.api.domain.app.LoginCredentials
import com.duckduckgo.autofill.api.email.EmailManager
import com.duckduckgo.autofill.impl.email.incontext.availability.EmailProtectionInContextAvailabilityRules
Expand All @@ -42,6 +43,7 @@ class RealAutofillRuntimeConfigProvider @Inject constructor(
private val autofillStore: InternalAutofillStore,
private val runtimeConfigurationWriter: RuntimeConfigurationWriter,
private val autofillCapabilityChecker: AutofillCapabilityChecker,
private val autofillFeature: AutofillFeature,
private val shareableCredentials: ShareableCredentials,
private val emailProtectionInContextAvailabilityRules: EmailProtectionInContextAvailabilityRules,
private val neverSavedSiteRepository: NeverSavedSiteRepository,
Expand Down Expand Up @@ -127,8 +129,8 @@ class RealAutofillRuntimeConfigProvider @Inject constructor(
return !neverSavedSiteRepository.isInNeverSaveList(url)
}

private suspend fun canCategorizeUnknownUsername(): Boolean {
return autofillCapabilityChecker.canCategorizeUnknownUsername()
private fun canCategorizeUnknownUsername(): Boolean {
return autofillFeature.canCategorizeUnknownUsername().isEnabled()
}

private suspend fun canShowInContextEmailProtectionSignup(url: String?): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.duckduckgo.autofill.impl.jsbridge.response.AvailableInputTypeCredenti
import com.duckduckgo.autofill.impl.sharedcreds.ShareableCredentials
import com.duckduckgo.autofill.impl.store.InternalAutofillStore
import com.duckduckgo.autofill.impl.store.NeverSavedSiteRepository
import com.duckduckgo.feature.toggles.api.toggle.AutofillTestFeature
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
Expand All @@ -40,6 +41,7 @@ class RealAutofillRuntimeConfigProviderTest {

private val emailManager: EmailManager = mock()
private val autofillStore: InternalAutofillStore = mock()
private val autofillFeature: AutofillTestFeature = AutofillTestFeature()
private val runtimeConfigurationWriter: RuntimeConfigurationWriter = mock()
private val shareableCredentials: ShareableCredentials = mock()
private val autofillCapabilityChecker: AutofillCapabilityChecker = mock()
Expand All @@ -54,6 +56,7 @@ class RealAutofillRuntimeConfigProviderTest {
autofillStore,
runtimeConfigurationWriter,
autofillCapabilityChecker = autofillCapabilityChecker,
autofillFeature = autofillFeature,
shareableCredentials = shareableCredentials,
emailProtectionInContextAvailabilityRules = emailProtectionInContextAvailabilityRules,
neverSavedSiteRepository = neverSavedSiteRepository,
Expand All @@ -64,6 +67,7 @@ class RealAutofillRuntimeConfigProviderTest {
whenever(neverSavedSiteRepository.isInNeverSaveList(any())).thenReturn(false)
}

autofillFeature.canCategorizeUnknownUsername = true
whenever(runtimeConfigurationWriter.generateContentScope()).thenReturn("")
whenever(runtimeConfigurationWriter.generateResponseGetAvailableInputTypes(any(), any())).thenReturn("")
whenever(runtimeConfigurationWriter.generateUserUnprotectedDomains()).thenReturn("")
Expand Down Expand Up @@ -375,7 +379,6 @@ class RealAutofillRuntimeConfigProviderTest {
whenever(autofillCapabilityChecker.canSaveCredentialsFromWebView(any())).thenReturn(enabled)
whenever(autofillCapabilityChecker.canGeneratePasswordFromWebView(any())).thenReturn(enabled)
whenever(emailProtectionInContextAvailabilityRules.permittedToShow(any())).thenReturn(enabled)
whenever(autofillCapabilityChecker.canCategorizeUnknownUsername()).thenReturn(enabled)
}

private fun verifyAutofillCredentialsReturnedAs(expectedValue: Boolean) {
Expand Down

0 comments on commit 5138d1d

Please sign in to comment.