summaryrefslogtreecommitdiffstats
path: root/tests/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'tests/src/com')
-rw-r--r--tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java217
1 files changed, 174 insertions, 43 deletions
diff --git a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java
index 6bb478e2a..88f38fd62 100644
--- a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java
+++ b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java
@@ -18,11 +18,16 @@ package com.android.dialer.database;
import android.content.ContentValues;
import android.net.Uri;
+import android.provider.BlockedNumberContract;
+import android.provider.BlockedNumberContract.BlockedNumbers;
import android.test.InstrumentationTestCase;
import android.test.mock.MockContentResolver;
+import android.test.suitebuilder.annotation.SmallTest;
+import com.android.contacts.common.compat.CompatUtils;
import com.android.contacts.common.test.mocks.MockContentProvider;
import com.android.contacts.common.test.mocks.MockContentProvider.Query;
+import com.android.dialer.compat.FilteredNumberCompat;
import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnBlockNumberListener;
import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnCheckBlockedListener;
import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnHasBlockedNumbersListener;
@@ -33,14 +38,19 @@ import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
+@SmallTest
public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase {
private static final String E164_NUMBER = "+16502530000";
private static final String NUMBER = "6502530000";
private static final String COUNTRY_ISO = "US";
private static final Integer ID = 1;
- private static final Uri BLOCKED_NUMBER_URI =
+ private static final Uri BLOCKED_NUMBER_URI_N = CompatUtils.isNCompatible() ?
+ Uri.withAppendedPath(BlockedNumberContract.AUTHORITY_URI, "blocked") : null;
+ private static final Uri BLOCKED_NUMBER_URI_M =
Uri.withAppendedPath(FilteredNumberContract.AUTHORITY_URI, "filtered_numbers_table");
+ private static final Uri BLOCKED_NUMBER_URI = CompatUtils.isNCompatible() ? BLOCKED_NUMBER_URI_N
+ : BLOCKED_NUMBER_URI_M;
private static final Uri EXPECTED_URI = Uri.fromParts("android", "google", "dialer");
private final MockContentResolver mContentResolver = new MockContentResolver();
@@ -49,40 +59,39 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase
@Override
public void setUp() throws Exception {
super.setUp();
- mContentResolver.addProvider(FilteredNumberContract.AUTHORITY, mContentProvider);
+ FilteredNumberCompat.setIsEnabledForTest(true);
+ if (CompatUtils.isNCompatible()) {
+ mContentResolver.addProvider(BlockedNumberContract.AUTHORITY, mContentProvider);
+ } else {
+ mContentResolver.addProvider(FilteredNumberContract.AUTHORITY, mContentProvider);
+ }
}
- public void testIsBlockedNumber_NoResults() throws Throwable {
- newIsBlockedNumberExpectedQueryM().returnEmptyCursor();
- final CheckBlockedListener listener = new CheckBlockedListener();
+ public void testHasBlockedNumbers_Disabled() throws Throwable {
+ if (!CompatUtils.isNCompatible()) {
+ return;
+ }
+ FilteredNumberCompat.setIsEnabledForTest(false);
+ final MockContentResolver resolver = new MockContentResolver();
+ MockContentProvider disabledProvider = new MockContentProvider();
+ resolver.addProvider(FilteredNumberContract.AUTHORITY, disabledProvider);
+ disabledProvider.expectQuery(BLOCKED_NUMBER_URI_M).withProjection(FilteredNumberColumns._ID)
+ .withSelection(FilteredNumberColumns.TYPE + "="
+ + FilteredNumberTypes.BLOCKED_NUMBER, null).returnRow(ID);
+ final HasBlockedNumbersListener listener = new HasBlockedNumbersListener();
runTestOnUiThread(new Runnable() {
@Override
public void run() {
- new FilteredNumberAsyncQueryHandler(mContentResolver)
- .isBlockedNumber(listener, NUMBER, COUNTRY_ISO);
+ new FilteredNumberAsyncQueryHandler(resolver).hasBlockedNumbers(listener);
}
});
- assertNull(listener.waitForCallback());
- mContentProvider.verify();
- }
-
- public void testIsBlockedNumber() throws Throwable {
- newIsBlockedNumberExpectedQueryM().returnRow(ID, FilteredNumberTypes.BLOCKED_NUMBER);
- final CheckBlockedListener listener = new CheckBlockedListener();
- runTestOnUiThread(new Runnable() {
- @Override
- public void run() {
- new FilteredNumberAsyncQueryHandler(mContentResolver)
- .isBlockedNumber(listener, NUMBER, COUNTRY_ISO);
- }
- });
- assertEquals(ID, listener.waitForCallback());
- mContentProvider.verify();
+ assertTrue(listener.waitForCallback());
+ disabledProvider.verify();
}
public void testHasBlockedNumbers_NoResults() throws Throwable {
- newHasBlockedNumbersExpectedQueryM().returnEmptyCursor();
+ newHasBlockedNumbersExpectedQuery().returnEmptyCursor();
final HasBlockedNumbersListener listener = new HasBlockedNumbersListener();
runTestOnUiThread(new Runnable() {
@Override
@@ -95,7 +104,7 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase
}
public void testHasBlockedNumbers() throws Throwable {
- newHasBlockedNumbersExpectedQueryM().returnRow(ID);
+ newHasBlockedNumbersExpectedQuery().returnRow(ID);
final HasBlockedNumbersListener listener = new HasBlockedNumbersListener();
runTestOnUiThread(new Runnable() {
@Override
@@ -107,24 +116,90 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase
mContentProvider.verify();
}
- private Query newIsBlockedNumberExpectedQueryM() {
- return mContentProvider.expectQuery(BLOCKED_NUMBER_URI)
+ public void testIsBlockedNumber_Disabled() throws Throwable {
+ if (!CompatUtils.isNCompatible()) {
+ return;
+ }
+ FilteredNumberCompat.setIsEnabledForTest(false);
+ final MockContentResolver resolver = new MockContentResolver();
+ MockContentProvider disabledProvider = new MockContentProvider();
+ resolver.addProvider(FilteredNumberContract.AUTHORITY, disabledProvider);
+ disabledProvider.expectQuery(BLOCKED_NUMBER_URI_M)
.withProjection(FilteredNumberColumns._ID, FilteredNumberColumns.TYPE)
- .withSelection(FilteredNumberColumns.NORMALIZED_NUMBER + " = ?", E164_NUMBER);
+ .withSelection(FilteredNumberColumns.NORMALIZED_NUMBER + " = ?", E164_NUMBER)
+ .returnRow(ID, FilteredNumberTypes.BLOCKED_NUMBER);
+ final CheckBlockedListener listener = new CheckBlockedListener();
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ new FilteredNumberAsyncQueryHandler(resolver)
+ .isBlockedNumber(listener, NUMBER, COUNTRY_ISO);
+ }
+ });
+ assertEquals(ID, listener.waitForCallback());
+ mContentProvider.verify();
}
- private Query newHasBlockedNumbersExpectedQueryM() {
- return mContentProvider.expectQuery(BLOCKED_NUMBER_URI).withProjection(
- FilteredNumberColumns._ID)
- .withSelection(FilteredNumberColumns.TYPE + "="
- + FilteredNumberTypes.BLOCKED_NUMBER, null);
+ public void testIsBlockedNumber_NoResults() throws Throwable {
+ newIsBlockedNumberExpectedQuery().returnEmptyCursor();
+ final CheckBlockedListener listener = new CheckBlockedListener();
+
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ new FilteredNumberAsyncQueryHandler(mContentResolver)
+ .isBlockedNumber(listener, NUMBER, COUNTRY_ISO);
+ }
+ });
+ assertNull(listener.waitForCallback());
+ mContentProvider.verify();
+ }
+
+ public void testIsBlockedNumber() throws Throwable {
+ if (CompatUtils.isNCompatible()) {
+ newIsBlockedNumberExpectedQuery().returnRow(ID);
+ } else {
+ newIsBlockedNumberExpectedQuery().returnRow(ID, FilteredNumberTypes.BLOCKED_NUMBER);
+ }
+ final CheckBlockedListener listener = new CheckBlockedListener();
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ new FilteredNumberAsyncQueryHandler(mContentResolver)
+ .isBlockedNumber(listener, NUMBER, COUNTRY_ISO);
+ }
+ });
+ assertEquals(ID, listener.waitForCallback());
+ mContentProvider.verify();
+ }
+
+ public void testBlockNumber_Disabled() throws Throwable {
+ if (!CompatUtils.isNCompatible()) {
+ return;
+ }
+ FilteredNumberCompat.setIsEnabledForTest(false);
+ final MockContentResolver resolver = new MockContentResolver();
+ MockContentProvider disabledProvider = new MockContentProvider();
+ resolver.addProvider(FilteredNumberContract.AUTHORITY, disabledProvider);
+
+ disabledProvider.expectInsert(BLOCKED_NUMBER_URI_M, newBlockNumberContentValuesM(),
+ EXPECTED_URI);
+ final BlockNumberListener listener = new BlockNumberListener();
+ runTestOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ new FilteredNumberAsyncQueryHandler(resolver).blockNumber(listener, E164_NUMBER,
+ NUMBER, COUNTRY_ISO);
+ }
+ });
+ assertSame(EXPECTED_URI, listener.waitForCallback());
+ disabledProvider.verify();
}
public void testBlockNumber() throws Throwable {
mContentProvider.expectInsert(BLOCKED_NUMBER_URI, newBlockNumberContentValues(),
EXPECTED_URI);
- final BlockingArgumentCaptorOnBlockNumberListener listener =
- new BlockingArgumentCaptorOnBlockNumberListener();
+ final BlockNumberListener listener = new BlockNumberListener();
runTestOnUiThread(new Runnable() {
@Override
public void run() {
@@ -132,16 +207,14 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase
E164_NUMBER, NUMBER, COUNTRY_ISO);
}
});
- assertTrue(listener.onBlockCompleteCalled.await(5000, TimeUnit.MILLISECONDS));
- assertSame(EXPECTED_URI, listener.uri);
+ assertSame(EXPECTED_URI, listener.waitForCallback());
mContentProvider.verify();
}
public void testBlockNumber_NullNormalizedNumber() throws Throwable {
mContentProvider.expectInsert(BLOCKED_NUMBER_URI, newBlockNumberContentValues(),
EXPECTED_URI);
- final BlockingArgumentCaptorOnBlockNumberListener listener =
- new BlockingArgumentCaptorOnBlockNumberListener();
+ final BlockNumberListener listener = new BlockNumberListener();
runTestOnUiThread(new Runnable() {
@Override
public void run() {
@@ -149,12 +222,63 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase
NUMBER, COUNTRY_ISO);
}
});
- assertTrue(listener.onBlockCompleteCalled.await(5000, TimeUnit.MILLISECONDS));
- assertSame(EXPECTED_URI, listener.uri);
+ assertSame(EXPECTED_URI, listener.waitForCallback());
mContentProvider.verify();
}
+ private Query newIsBlockedNumberExpectedQuery() {
+ if (CompatUtils.isNCompatible()) {
+ return newIsBlockedNumberExpectedQueryN();
+ }
+ return newIsBlockedNumberExpectedQueryM();
+ }
+
+ private Query newIsBlockedNumberExpectedQueryN() {
+ return mContentProvider.expectQuery(BLOCKED_NUMBER_URI)
+ .withProjection(BlockedNumbers.COLUMN_ID)
+ .withSelection(BlockedNumbers.COLUMN_E164_NUMBER + " = ?", E164_NUMBER);
+ }
+
+ private Query newIsBlockedNumberExpectedQueryM() {
+ return mContentProvider.expectQuery(BLOCKED_NUMBER_URI)
+ .withProjection(FilteredNumberColumns._ID, FilteredNumberColumns.TYPE)
+ .withSelection(FilteredNumberColumns.NORMALIZED_NUMBER + " = ?", E164_NUMBER);
+ }
+
+ private Query newHasBlockedNumbersExpectedQuery() {
+ if (CompatUtils.isNCompatible()) {
+ return newHasBlockedNumbersExpectedQueryN();
+ }
+ return newHasBlockedNumbersExpectedQueryM();
+ }
+
+ private Query newHasBlockedNumbersExpectedQueryN() {
+ return mContentProvider.expectQuery(BLOCKED_NUMBER_URI)
+ .withProjection(BlockedNumbers.COLUMN_ID)
+ .withSelection(null, null);
+ }
+
+ private Query newHasBlockedNumbersExpectedQueryM() {
+ return mContentProvider.expectQuery(BLOCKED_NUMBER_URI).withProjection(
+ FilteredNumberColumns._ID)
+ .withSelection(FilteredNumberColumns.TYPE + "="
+ + FilteredNumberTypes.BLOCKED_NUMBER, null);
+ }
+
private ContentValues newBlockNumberContentValues() {
+ if (CompatUtils.isNCompatible()) {
+ return newBlockNumberContentValuesN();
+ }
+ return newBlockNumberContentValuesM();
+ }
+
+ private ContentValues newBlockNumberContentValuesN() {
+ ContentValues contentValues = new ContentValues();
+ contentValues.put(BlockedNumbers.COLUMN_ORIGINAL_NUMBER, NUMBER);
+ return contentValues;
+ }
+
+ private ContentValues newBlockNumberContentValuesM() {
ContentValues contentValues = new ContentValues();
contentValues.put(FilteredNumberColumns.NORMALIZED_NUMBER, E164_NUMBER);
contentValues.put(FilteredNumberColumns.NUMBER, NUMBER);
@@ -208,11 +332,11 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase
}
}
- private class BlockingArgumentCaptorOnBlockNumberListener implements OnBlockNumberListener {
+ private class BlockNumberListener implements OnBlockNumberListener {
public final CountDownLatch onBlockCompleteCalled;
public Uri uri;
- public BlockingArgumentCaptorOnBlockNumberListener() {
+ public BlockNumberListener() {
onBlockCompleteCalled = new CountDownLatch(1);
}
@@ -221,5 +345,12 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase
this.uri = uri;
onBlockCompleteCalled.countDown();
}
+
+ public Uri waitForCallback() throws InterruptedException {
+ if (!onBlockCompleteCalled.await(5000, TimeUnit.MILLISECONDS)) {
+ throw new IllegalStateException("Waiting on callback timed out.");
+ }
+ return uri;
+ }
}
}