Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8bd322d3 authored by Joe Bolinger's avatar Joe Bolinger
Browse files

Fix broken unit test.

This test was reported flaky, but has been broken since I72ab71d0dd53f66387e5c2ade510ef19c2b7f4e6.

Fix: 194743156
Test: atest BiometricActionDisabledByAdminControllerTest
Change-Id: I663e9f5343297a4653de0b2d40a53f1ed2ad2279
parent 9ff04bdc
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;

import com.android.settingslib.RestrictedLockUtils;

@@ -32,10 +33,12 @@ public class BiometricActionDisabledByAdminController extends BaseActionDisabled

    // These MUST not change, as they are the stable API between here and device admin specified
    // by the component below.
    private static final String ACTION_LEARN_MORE =
            "android.intent.action.MANAGE_RESTRICTED_SETTING";
    private static final String EXTRA_SETTING_KEY = "extra_setting";
    private static final String EXTRA_SETTING_VALUE = "biometric_disabled_by_admin_controller";
    @VisibleForTesting
    static final String ACTION_LEARN_MORE = "android.intent.action.MANAGE_RESTRICTED_SETTING";
    @VisibleForTesting
    static final String EXTRA_SETTING_KEY = "extra_setting";
    @VisibleForTesting
    static final String EXTRA_SETTING_VALUE = "biometric_disabled_by_admin_controller";

    BiometricActionDisabledByAdminController(
            DeviceAdminStringProvider stringProvider) {
+21 −13
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import static com.android.settingslib.enterprise.FakeDeviceAdminStringProvider.D

import static junit.framework.Assert.assertNotNull;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static junit.framework.TestCase.assertSame;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -39,41 +39,49 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class BiometricActionDisabledByAdminControllerTest {

    private final ActionDisabledByAdminControllerTestUtils mTestUtils =
            new ActionDisabledByAdminControllerTestUtils();
    private final BiometricActionDisabledByAdminController mController =
            new BiometricActionDisabledByAdminController(DEFAULT_DEVICE_ADMIN_STRING_PROVIDER);
    @Mock
    private Context mContext;

    private ActionDisabledByAdminControllerTestUtils mTestUtils;
    private BiometricActionDisabledByAdminController mController;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        mTestUtils = new ActionDisabledByAdminControllerTestUtils();

        mController = new BiometricActionDisabledByAdminController(
                DEFAULT_DEVICE_ADMIN_STRING_PROVIDER);
        mController.initialize(mTestUtils.createLearnMoreButtonLauncher());
        mController.updateEnforcedAdmin(ENFORCED_ADMIN, ENFORCEMENT_ADMIN_USER_ID);
    }

    @Test
    public void buttonClicked() {
        Context context = mock(Context.class);
        ComponentName componentName = mock(ComponentName.class);
        RestrictedLockUtils.EnforcedAdmin enforcedAdmin = new RestrictedLockUtils.EnforcedAdmin(
                componentName, new UserHandle(UserHandle.myUserId()));

        DialogInterface.OnClickListener listener =
                mController.getPositiveButtonListener(context, enforcedAdmin);
                mController.getPositiveButtonListener(mContext, enforcedAdmin);
        assertNotNull("Biometric Controller must supply a non-null listener", listener);
        listener.onClick(mock(DialogInterface.class), 0 /* which */);

        ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(context).startActivity(intentCaptor.capture());
        assertEquals("android.settings.LEARN_MORE",
        verify(mContext).startActivity(intentCaptor.capture());
        assertEquals(BiometricActionDisabledByAdminController.ACTION_LEARN_MORE,
                intentCaptor.getValue().getAction());
        assertTrue("from_biometric_setup", intentCaptor.getValue()
                .getBooleanExtra("from_biometric_setup", false));
        assertEquals(componentName, intentCaptor.getValue().getComponent());
        assertEquals(BiometricActionDisabledByAdminController.EXTRA_SETTING_VALUE,
                intentCaptor.getValue().getStringExtra(
                        BiometricActionDisabledByAdminController.EXTRA_SETTING_KEY));
        assertSame(componentName, intentCaptor.getValue().getComponent());
    }

}