diff options
Diffstat (limited to 'tests/src/com')
3 files changed, 68 insertions, 13 deletions
diff --git a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java index fd60d731a..6bb478e2a 100644 --- a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java +++ b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java @@ -16,16 +16,18 @@ package com.android.dialer.database; -import android.content.pm.ProviderInfo; +import android.content.ContentValues; import android.net.Uri; import android.test.InstrumentationTestCase; import android.test.mock.MockContentResolver; import com.android.contacts.common.test.mocks.MockContentProvider; import com.android.contacts.common.test.mocks.MockContentProvider.Query; +import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnBlockNumberListener; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener; import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; +import com.android.dialer.database.FilteredNumberContract.FilteredNumberSources; import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes; import java.util.concurrent.CountDownLatch; @@ -39,6 +41,7 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase private static final Integer ID = 1; private static final Uri BLOCKED_NUMBER_URI = Uri.withAppendedPath(FilteredNumberContract.AUTHORITY_URI, "filtered_numbers_table"); + private static final Uri EXPECTED_URI = Uri.fromParts("android", "google", "dialer"); private final MockContentResolver mContentResolver = new MockContentResolver(); private final MockContentProvider mContentProvider = new MockContentProvider(); @@ -46,16 +49,7 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase @Override public void setUp() throws Exception { super.setUp(); - setUpProviderForAuthority(mContentProvider, FilteredNumberContract.AUTHORITY, - mContentResolver); - } - - private void setUpProviderForAuthority(MockContentProvider provider, String authority, - MockContentResolver contentResolver) { - ProviderInfo providerInfo = new ProviderInfo(); - providerInfo.authority = authority; - provider.attachInfo(null, providerInfo); - contentResolver.addProvider(authority, provider); + mContentResolver.addProvider(FilteredNumberContract.AUTHORITY, mContentProvider); } public void testIsBlockedNumber_NoResults() throws Throwable { @@ -123,7 +117,51 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase return mContentProvider.expectQuery(BLOCKED_NUMBER_URI).withProjection( FilteredNumberColumns._ID) .withSelection(FilteredNumberColumns.TYPE + "=" - + FilteredNumberTypes.BLOCKED_NUMBER); + + FilteredNumberTypes.BLOCKED_NUMBER, null); + } + + public void testBlockNumber() throws Throwable { + mContentProvider.expectInsert(BLOCKED_NUMBER_URI, newBlockNumberContentValues(), + EXPECTED_URI); + final BlockingArgumentCaptorOnBlockNumberListener listener = + new BlockingArgumentCaptorOnBlockNumberListener(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + new FilteredNumberAsyncQueryHandler(mContentResolver).blockNumber(listener, + E164_NUMBER, NUMBER, COUNTRY_ISO); + } + }); + assertTrue(listener.onBlockCompleteCalled.await(5000, TimeUnit.MILLISECONDS)); + assertSame(EXPECTED_URI, listener.uri); + mContentProvider.verify(); + } + + public void testBlockNumber_NullNormalizedNumber() throws Throwable { + mContentProvider.expectInsert(BLOCKED_NUMBER_URI, newBlockNumberContentValues(), + EXPECTED_URI); + final BlockingArgumentCaptorOnBlockNumberListener listener = + new BlockingArgumentCaptorOnBlockNumberListener(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + new FilteredNumberAsyncQueryHandler(mContentResolver).blockNumber(listener, + NUMBER, COUNTRY_ISO); + } + }); + assertTrue(listener.onBlockCompleteCalled.await(5000, TimeUnit.MILLISECONDS)); + assertSame(EXPECTED_URI, listener.uri); + mContentProvider.verify(); + } + + private ContentValues newBlockNumberContentValues() { + ContentValues contentValues = new ContentValues(); + contentValues.put(FilteredNumberColumns.NORMALIZED_NUMBER, E164_NUMBER); + contentValues.put(FilteredNumberColumns.NUMBER, NUMBER); + contentValues.put(FilteredNumberColumns.COUNTRY_ISO, COUNTRY_ISO); + contentValues.put(FilteredNumberColumns.TYPE, FilteredNumberTypes.BLOCKED_NUMBER); + contentValues.put(FilteredNumberColumns.SOURCE, FilteredNumberSources.USER); + return contentValues; } private class CheckBlockedListener implements OnCheckBlockedListener { @@ -169,4 +207,19 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase return hasBlockedNumbers; } } + + private class BlockingArgumentCaptorOnBlockNumberListener implements OnBlockNumberListener { + public final CountDownLatch onBlockCompleteCalled; + public Uri uri; + + public BlockingArgumentCaptorOnBlockNumberListener() { + onBlockCompleteCalled = new CountDownLatch(1); + } + + @Override + public void onBlockComplete(Uri uri) { + this.uri = uri; + onBlockCompleteCalled.countDown(); + } + } } diff --git a/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java b/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java index ccd95ab69..d2e7f0a1c 100644 --- a/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java +++ b/tests/src/com/android/dialer/filterednumber/FilteredNumbersUtilTest.java @@ -17,6 +17,7 @@ package com.android.dialer.filterednumber; import android.preference.PreferenceManager; import android.test.AndroidTestCase; +import android.test.suitebuilder.annotation.SmallTest; import com.android.contacts.common.test.mocks.ContactsMockContext; import com.android.contacts.common.test.mocks.MockContentProvider.Query; @@ -24,6 +25,7 @@ import com.android.dialer.database.FilteredNumberContract; import com.android.dialer.database.FilteredNumberContract.FilteredNumber; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; +@SmallTest public class FilteredNumbersUtilTest extends AndroidTestCase { private static final String COUNTRY_ISO = "US"; diff --git a/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java b/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java index 54a07cc3a..f58e6cc6c 100644 --- a/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java +++ b/tests/src/com/android/dialer/interactions/PhoneNumberInteractionTest.java @@ -257,6 +257,6 @@ public class PhoneNumberInteractionTest extends InstrumentationTestCase { Phone.MIMETYPE, Phone.CONTACT_ID) .withSelection("mimetype IN ('vnd.android.cursor.item/phone_v2'," - + " 'vnd.android.cursor.item/sip_address') AND data1 NOT NULL"); + + " 'vnd.android.cursor.item/sip_address') AND data1 NOT NULL", null); } } |