From 8f62a58f88a4e3f0502485978547b4f07567622e Mon Sep 17 00:00:00 2001 From: Matt Van Horn <455140+mvanhorn@users.noreply.github.com> Date: Wed, 19 Aug 2026 20:06:11 -0700 Subject: [PATCH] fix: address self-review findings --- .../viewing/AutofillManagementDisabledMode.kt | 2 - .../AutofillManagementDisabledModeTest.kt | 84 +++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/ui/credential/management/viewing/AutofillManagementDisabledModeTest.kt diff --git a/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/ui/credential/management/viewing/AutofillManagementDisabledMode.kt b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/ui/credential/management/viewing/AutofillManagementDisabledMode.kt index 1a8938c53d67..2ccda4e4b8da 100644 --- a/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/ui/credential/management/viewing/AutofillManagementDisabledMode.kt +++ b/autofill/autofill-impl/src/main/java/com/duckduckgo/autofill/impl/ui/credential/management/viewing/AutofillManagementDisabledMode.kt @@ -101,8 +101,6 @@ class AutofillManagementDisabledMode : DuckDuckGoFragment() { Intent(ACTION_FINGERPRINT_ENROLL).safeLaunchSettingsActivity(tryFallback = true) } } - - requireActivity().finish() } /** diff --git a/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/ui/credential/management/viewing/AutofillManagementDisabledModeTest.kt b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/ui/credential/management/viewing/AutofillManagementDisabledModeTest.kt new file mode 100644 index 000000000000..3fba198cd257 --- /dev/null +++ b/autofill/autofill-impl/src/test/java/com/duckduckgo/autofill/impl/ui/credential/management/viewing/AutofillManagementDisabledModeTest.kt @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2026 DuckDuckGo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.duckduckgo.autofill.impl.ui.credential.management.viewing + +import android.os.Bundle +import android.provider.Settings.ACTION_BIOMETRIC_ENROLL +import android.widget.FrameLayout +import androidx.appcompat.app.AppCompatActivity +import androidx.test.ext.junit.runners.AndroidJUnit4 +import com.duckduckgo.appbuildconfig.api.AppBuildConfig +import com.duckduckgo.autofill.impl.R +import com.duckduckgo.common.utils.edgetoedge.EdgeToEdgeHandler +import com.duckduckgo.common.utils.edgetoedge.EdgeToEdgeProvider +import dagger.android.AndroidInjector +import dagger.android.HasAndroidInjector +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.kotlin.any +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever +import org.robolectric.Robolectric +import org.robolectric.Shadows.shadowOf +import org.robolectric.annotation.Config +import com.duckduckgo.mobile.android.R as CommonR + +@RunWith(AndroidJUnit4::class) +@Config(sdk = [30]) +class AutofillManagementDisabledModeTest { + + private val appBuildConfig: AppBuildConfig = mock() + private val edgeToEdgeProvider: EdgeToEdgeProvider = mock() + + @Test + fun whenSetUpInSettingsClickedThenBiometricEnrollmentIsLaunchedAndActivityRemainsOpen() { + whenever(appBuildConfig.manufacturer).thenReturn("Google") + whenever(appBuildConfig.sdkInt).thenReturn(30) + whenever(edgeToEdgeProvider.isEnabled(any())).thenReturn(false) + val activity = Robolectric.buildActivity(TestActivity::class.java).setup().get() + val fragment = AutofillManagementDisabledMode().apply { + appBuildConfig = this@AutofillManagementDisabledModeTest.appBuildConfig + edgeToEdgeProvider = this@AutofillManagementDisabledModeTest.edgeToEdgeProvider + edgeToEdgeHandler = EdgeToEdgeHandler() + } + activity.supportFragmentManager.beginTransaction() + .add(TestActivity.CONTAINER_ID, fragment) + .commitNow() + + fragment.requireView().findViewById(R.id.disabled_cta).performClick() + + assertEquals(ACTION_BIOMETRIC_ENROLL, shadowOf(activity).nextStartedActivity.action) + assertFalse(activity.isFinishing) + } +} + +class TestActivity : AppCompatActivity(), HasAndroidInjector { + + override fun onCreate(savedInstanceState: Bundle?) { + setTheme(CommonR.style.Theme_DuckDuckGo_Light) + super.onCreate(savedInstanceState) + setContentView(FrameLayout(this).apply { id = CONTAINER_ID }) + } + + override fun androidInjector(): AndroidInjector = AndroidInjector { } + + companion object { + const val CONTAINER_ID = 1 + } +}