diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java b/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java index 5ee2f28e1..3572316db 100644 --- a/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java +++ b/tests/src/com/android/dialer/compat/FilteredNumberCompatTest.java @@ -18,19 +18,20 @@ package com.android.dialer.compat; import static org.mockito.Matchers.anyInt; import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.ComponentName; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; -import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; +import android.os.UserManager; import android.provider.BlockedNumberContract.BlockedNumbers; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; -import android.util.Log; import com.android.contacts.common.compat.CompatUtils; import com.android.dialer.DialerApplication; @@ -41,7 +42,6 @@ import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes; import com.android.dialer.filterednumber.BlockedNumbersSettingsActivity; import org.mockito.Mock; -import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import java.util.Arrays; @@ -227,6 +227,54 @@ public class FilteredNumberCompatTest extends AndroidTestCase { .getComponent())); } + public void testCanCurrentUserOpenBlockSettings_M_SecondaryUser() { + if (CompatUtils.isNCompatible()) { + return; + } + UserManager userManager = mock(UserManager.class); + when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(userManager); + when(userManager.isSystemUser()).thenReturn(false); + assertFalse(FilteredNumberCompat.canCurrentUserOpenBlockSettings(mContext)); + verify(mContext).getSystemService(Context.USER_SERVICE); + verify(userManager).isSystemUser(); + } + + public void testCanCurrentUserOpenBlockSettings_M_PrimaryUser() { + if (CompatUtils.isNCompatible()) { + return; + } + UserManager userManager = mock(UserManager.class); + when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(userManager); + when(userManager.isSystemUser()).thenReturn(true); + assertTrue(FilteredNumberCompat.canCurrentUserOpenBlockSettings(mContext)); + verify(mContext).getSystemService(Context.USER_SERVICE); + verify(userManager).isSystemUser(); + } + + public void testCanAttemptBlockOperations_M_SecondaryUser() { + if (CompatUtils.isNCompatible()) { + return; + } + UserManager userManager = mock(UserManager.class); + when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(userManager); + when(userManager.isSystemUser()).thenReturn(false); + assertFalse(FilteredNumberCompat.canAttemptBlockOperations(mContext)); + verify(mContext).getSystemService(Context.USER_SERVICE); + verify(userManager).isSystemUser(); + } + + public void testCanAttemptBlockOperations_M_PrimaryUser() { + if (CompatUtils.isNCompatible()) { + return; + } + UserManager userManager = mock(UserManager.class); + when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(userManager); + when(userManager.isSystemUser()).thenReturn(true); + assertTrue(FilteredNumberCompat.canAttemptBlockOperations(mContext)); + verify(mContext).getSystemService(Context.USER_SERVICE); + verify(userManager).isSystemUser(); + } + private ContentValues newExpectedContentValuesM(String number, String e164Number, String countryIso) { ContentValues contentValues = new ContentValues(); |