1 /* 2 * Copyright (C) 2014 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 package com.android.providers.contacts.util; 17 18 import com.android.providers.contacts.ContactsActor; 19 import com.android.providers.contacts.ContactsActor.MockUserManager; 20 import com.android.providers.contacts.SynchronousContactsProvider2; 21 22 import android.content.ContentProvider; 23 import android.content.Context; 24 import android.os.UserManager; 25 import android.provider.ContactsContract; 26 import android.test.AndroidTestCase; 27 import android.test.suitebuilder.annotation.SmallTest; 28 29 import static com.android.providers.contacts.ContactsActor.PACKAGE_GREY; 30 31 @SmallTest 32 public class UserUtilsTest extends AndroidTestCase { 33 34 protected ContactsActor mActor; 35 36 @Override setUp()37 protected void setUp() throws Exception { 38 super.setUp(); 39 40 mActor = new ContactsActor(getContext(), PACKAGE_GREY, 41 SynchronousContactsProvider2.class, 42 ContactsContract.AUTHORITY); 43 } 44 testGetCorpUser()45 public void testGetCorpUser() { 46 final Context c = mActor.getProviderContext(); 47 final MockUserManager um = mActor.mockUserManager; 48 49 // No corp user. Primary only. 50 assertEquals(-1, UserUtils.getCorpUserId(c)); 51 52 // Primary + corp 53 um.setUsers(MockUserManager.PRIMARY_USER, MockUserManager.CORP_USER); 54 55 um.myUser = MockUserManager.PRIMARY_USER.id; 56 assertEquals(MockUserManager.CORP_USER.id, UserUtils.getCorpUserId(c)); 57 58 um.myUser = MockUserManager.CORP_USER.id; 59 assertEquals(-1, UserUtils.getCorpUserId(c)); 60 61 // Primary + secondary + corp 62 um.setUsers(MockUserManager.PRIMARY_USER, MockUserManager.SECONDARY_USER, 63 MockUserManager.CORP_USER); 64 65 um.myUser = MockUserManager.PRIMARY_USER.id; 66 assertEquals(MockUserManager.CORP_USER.id, UserUtils.getCorpUserId(c)); 67 68 um.myUser = MockUserManager.CORP_USER.id; 69 assertEquals(-1, UserUtils.getCorpUserId(c)); 70 71 um.myUser = MockUserManager.SECONDARY_USER.id; 72 assertEquals(-1, UserUtils.getCorpUserId(c)); 73 74 // Primary + secondary 75 um.setUsers(MockUserManager.PRIMARY_USER, MockUserManager.SECONDARY_USER); 76 77 um.myUser = MockUserManager.PRIMARY_USER.id; 78 assertEquals(-1, UserUtils.getCorpUserId(c)); 79 80 um.myUser = MockUserManager.SECONDARY_USER.id; 81 assertEquals(-1, UserUtils.getCorpUserId(c)); 82 } 83 } 84