1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.enterprise;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.app.admin.DevicePolicyManager;
22 import android.content.ComponentName;
23 import android.content.Intent;
24 import android.os.UserHandle;
25 
26 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
27 
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.robolectric.RobolectricTestRunner;
32 
33 @RunWith(RobolectricTestRunner.class)
34 public class ActionDisabledByAdminDialogTest {
35 
36     private ActionDisabledByAdminDialog mDialog;
37 
38     @Before
setUp()39     public void setUp() {
40         mDialog = new ActionDisabledByAdminDialog();
41     }
42 
43     @Test
testGetAdminDetailsFromIntent()44     public void testGetAdminDetailsFromIntent() {
45         final int userId = 123;
46         final ComponentName component = new ComponentName("com.some.package", ".SomeClass");
47         final EnforcedAdmin expectedAdmin = new EnforcedAdmin(component, UserHandle.of(userId));
48 
49         final Intent intent = new Intent();
50         intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, component);
51         intent.putExtra(Intent.EXTRA_USER_ID, userId);
52         assertEquals(expectedAdmin, mDialog.getAdminDetailsFromIntent(intent));
53     }
54 
55     @Test
testGetAdminDetailsFromNullIntent()56     public void testGetAdminDetailsFromNullIntent() {
57         final int userId = UserHandle.myUserId();
58         final EnforcedAdmin expectedAdmin = new EnforcedAdmin(null, UserHandle.of(userId));
59 
60         assertEquals(expectedAdmin, mDialog.getAdminDetailsFromIntent(null));
61     }
62 
63     @Test
testGetRestrictionFromIntent()64     public void testGetRestrictionFromIntent() {
65         final String restriction = "someRestriction";
66         final Intent intent = new Intent();
67 
68         intent.putExtra(DevicePolicyManager.EXTRA_RESTRICTION, restriction);
69         assertEquals(restriction, mDialog.getRestrictionFromIntent(intent));
70     }
71 
72     @Test
testGetRestrictionFromNullIntent()73     public void testGetRestrictionFromNullIntent() {
74         assertEquals(null, mDialog.getRestrictionFromIntent(null));
75     }
76 }
77