diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-03-21 16:55:10 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2016-03-21 16:55:10 +0000 |
commit | c98a56336fd49a8c5ea2834a141627d3cf0d8d6d (patch) | |
tree | f9d807fabf204b210e3d9906db679f1f6f3f561c /tests/src | |
parent | 40831d0bdaa12903d1668e8f955a5539a6dcbf11 (diff) | |
parent | 3ec5d25470379acbbf3bb2bcc83e5e897a22a59d (diff) |
Merge "Only allow primary users to block numbers" into nyc-dev
Diffstat (limited to 'tests/src')
-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(); |