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 android.app.admin.DevicePolicyManager; 20 import android.content.ComponentName; 21 import android.content.Intent; 22 import android.os.UserHandle; 23 24 import com.android.settings.testutils.SettingsRobolectricTestRunner; 25 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 26 27 import org.junit.Assert; 28 import org.junit.Before; 29 import org.junit.Test; 30 import org.junit.runner.RunWith; 31 32 @RunWith(SettingsRobolectricTestRunner.class) 33 public class ActionDisabledByAdminDialogTest { 34 35 private ActionDisabledByAdminDialog mDialog; 36 37 @Before 38 public void setUp() { 39 mDialog = new ActionDisabledByAdminDialog(); 40 } 41 42 @Test 43 public void testGetAdminDetailsFromIntent() { 44 final int userId = 123; 45 final ComponentName component = new ComponentName("com.some.package", ".SomeClass"); 46 final EnforcedAdmin expectedAdmin = new EnforcedAdmin(component, userId); 47 48 final Intent intent = new Intent(); 49 intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, component); 50 intent.putExtra(Intent.EXTRA_USER_ID, userId); 51 Assert.assertEquals(expectedAdmin, mDialog.getAdminDetailsFromIntent(intent)); 52 } 53 54 @Test 55 public void testGetAdminDetailsFromNullIntent() { 56 final int userId = UserHandle.myUserId(); 57 final EnforcedAdmin expectedAdmin = new EnforcedAdmin(null, userId); 58 59 Assert.assertEquals(expectedAdmin, mDialog.getAdminDetailsFromIntent(null)); 60 } 61 62 @Test 63 public void testGetRestrictionFromIntent() { 64 final String restriction = "someRestriction"; 65 final Intent intent = new Intent(); 66 67 intent.putExtra(DevicePolicyManager.EXTRA_RESTRICTION, restriction); 68 Assert.assertEquals(restriction, mDialog.getRestrictionFromIntent(intent)); 69 } 70 71 @Test 72 public void testGetRestrictionFromNullIntent() { 73 Assert.assertEquals(null, mDialog.getRestrictionFromIntent(null)); 74 } 75 } 76