summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/tests/robotests/src/com/android/settingslib/enterprise/BiometricActionDisabledByAdminControllerTest.java
blob: b2258e1d4208042f231650170d010821d547c2a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * 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.android.settingslib.enterprise;

import static com.android.settingslib.enterprise.ActionDisabledByAdminControllerTestUtils.ENFORCED_ADMIN;
import static com.android.settingslib.enterprise.ActionDisabledByAdminControllerTestUtils.ENFORCEMENT_ADMIN_USER_ID;
import static com.android.settingslib.enterprise.FakeDeviceAdminStringProvider.DEFAULT_DEVICE_ADMIN_STRING_PROVIDER;

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

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.UserHandle;
import android.provider.Settings;

import com.android.settingslib.RestrictedLockUtils;

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 {

    @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() {
        ComponentName componentName = new ComponentName("com.android.test", "AThing");
        RestrictedLockUtils.EnforcedAdmin enforcedAdmin = new RestrictedLockUtils.EnforcedAdmin(
                componentName, new UserHandle(UserHandle.myUserId()));

        DialogInterface.OnClickListener listener =
                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(mContext).startActivity(intentCaptor.capture());
        assertEquals(Settings.ACTION_MANAGE_SUPERVISOR_RESTRICTED_SETTING,
                intentCaptor.getValue().getAction());
        assertEquals(Settings.SUPERVISOR_VERIFICATION_SETTING_BIOMETRICS,
                intentCaptor.getValue().getIntExtra(
                        Settings.EXTRA_SUPERVISOR_RESTRICTED_SETTING_KEY, -1));
        assertEquals(componentName.getPackageName(), intentCaptor.getValue().getPackage());
    }
}