diff options
author | Brandon Maxwell <maxwelb@google.com> | 2016-02-28 15:28:45 -0800 |
---|---|---|
committer | Brandon Maxwell <maxwelb@google.com> | 2016-03-01 10:18:44 -0800 |
commit | f0e0ce60005a5732c65bddf290cd758c517d99db (patch) | |
tree | 6af138b0372d083aa17ed9f13b76104c1b3ba6a7 /tests | |
parent | 60fb1dc7afe8fe6079785724a21bbffbdb4eac88 (diff) |
Using FilteredNumCompat for unblock
+ This CL updates the FilteredNumberAsyncQueryHandler#unblock methods
to use the FilteredNumberCompat class to properly choose between the
original Dialer blocking implementation and new blocking.
Bug=26664600
Change-Id: I528604eeafa4f7fa131cb1898d57a87708ba58b5
Diffstat (limited to 'tests')
-rw-r--r-- | tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java index 88f38fd62..28fdda0dc 100644 --- a/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java +++ b/tests/src/com/android/dialer/database/FilteredNumberAsyncQueryHandlerTest.java @@ -16,6 +16,7 @@ package com.android.dialer.database; +import android.content.ContentUris; import android.content.ContentValues; import android.net.Uri; import android.provider.BlockedNumberContract; @@ -31,6 +32,7 @@ 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; +import com.android.dialer.database.FilteredNumberAsyncQueryHandler.OnUnblockNumberListener; import com.android.dialer.database.FilteredNumberContract.FilteredNumberColumns; import com.android.dialer.database.FilteredNumberContract.FilteredNumberSources; import com.android.dialer.database.FilteredNumberContract.FilteredNumberTypes; @@ -51,6 +53,8 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase 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 BLOCKED_NUMBER_URI_WITH_ID = + ContentUris.withAppendedId(BLOCKED_NUMBER_URI, ID); private static final Uri EXPECTED_URI = Uri.fromParts("android", "google", "dialer"); private final MockContentResolver mContentResolver = new MockContentResolver(); @@ -226,6 +230,60 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase mContentProvider.verify(); } + public void testUnblockNumber_Disabled() throws Throwable { + if (!CompatUtils.isNCompatible()) { + return; + } + FilteredNumberCompat.setIsEnabledForTest(false); + final MockContentResolver resolver = new MockContentResolver(); + MockContentProvider disabledProvider = new MockContentProvider(); + resolver.addProvider(FilteredNumberContract.AUTHORITY, disabledProvider); + + Uri uriWithId = ContentUris.withAppendedId(BLOCKED_NUMBER_URI_M, ID); + disabledProvider.expectQuery(uriWithId) + .withProjection(null) + .withDefaultProjection(FilteredNumberCompat.getIdColumnName()) + .withSelection(null, null) + .withSortOrder(null) + .returnRow(ID); + disabledProvider.expectDelete(uriWithId).returnRowsAffected(1); + final UnblockNumberListener listener = new UnblockNumberListener(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + new FilteredNumberAsyncQueryHandler(resolver).unblock(listener, ID); + } + }); + assertNotNull(listener.waitForCallback()); + disabledProvider.verify(); + } + + public void testUnblockNumber_NullId() { + try { + new FilteredNumberAsyncQueryHandler(mContentResolver).unblock(null, (Integer) null); + fail(); + } catch (IllegalArgumentException e) {} + } + + public void testUnblockNumber() throws Throwable { + mContentProvider.expectQuery(BLOCKED_NUMBER_URI_WITH_ID) + .withProjection(null) + .withDefaultProjection(FilteredNumberCompat.getIdColumnName()) + .withSelection(null, null) + .withSortOrder(null) + .returnRow(ID); + mContentProvider.expectDelete(BLOCKED_NUMBER_URI_WITH_ID).returnRowsAffected(1); + final UnblockNumberListener listener = new UnblockNumberListener(); + runTestOnUiThread(new Runnable() { + @Override + public void run() { + new FilteredNumberAsyncQueryHandler(mContentResolver).unblock(listener, ID); + } + }); + assertNotNull(listener.waitForCallback()); + mContentProvider.verify(); + } + private Query newIsBlockedNumberExpectedQuery() { if (CompatUtils.isNCompatible()) { return newIsBlockedNumberExpectedQueryN(); @@ -353,4 +411,26 @@ public class FilteredNumberAsyncQueryHandlerTest extends InstrumentationTestCase return uri; } } + + private class UnblockNumberListener implements OnUnblockNumberListener { + public final CountDownLatch onUnblockCompleteCalled; + public Integer result; + + public UnblockNumberListener() { + onUnblockCompleteCalled = new CountDownLatch(1); + } + + @Override + public void onUnblockComplete(int rows, ContentValues values) { + result = rows; + onUnblockCompleteCalled.countDown(); + } + + public Integer waitForCallback() throws InterruptedException { + if (!onUnblockCompleteCalled.await(5000, TimeUnit.MILLISECONDS)) { + throw new IllegalStateException("Waiting on callback timed out."); + } + return result; + } + } } |