diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-03-21 17:03:22 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-03-21 17:03:22 +0000 |
commit | 12c93d5a6e63d9cd4d8457551d41056ae12cd16c (patch) | |
tree | d300ab3da0e3d94d17632cfe498c0889ed3c08a0 /tests | |
parent | e5c0b968526379d93e82226710c2c32aa291f09f (diff) | |
parent | 25b094b0473bb52238d7d45d4ba69b0d9949121c (diff) |
Merge "Only allow primary users to block numbers" into nyc-dev am: c98a563
am: 25b094b
* commit '25b094b0473bb52238d7d45d4ba69b0d9949121c':
Only allow primary users to block numbers
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(); |