diff options
Diffstat (limited to 'tests/src/com/android/dialer/voicemail')
5 files changed, 0 insertions, 1150 deletions
diff --git a/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java b/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java deleted file mode 100644 index cabaf6732..000000000 --- a/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java +++ /dev/null @@ -1,227 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.voicemail; - -import android.app.Activity; -import android.content.ContentResolver; -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.res.AssetManager; -import android.net.Uri; -import android.provider.VoicemailContract; -import android.test.ActivityInstrumentationTestCase2; -import android.test.suitebuilder.annotation.Suppress; -import android.view.View; - -import com.android.dialer.R; -import com.android.dialer.util.AsyncTaskExecutors; -import com.android.dialer.util.FakeAsyncTaskExecutor; -import com.android.dialer.util.LocaleTestUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.Locale; - -import static com.android.dialer.voicemail.VoicemailPlaybackPresenter.Tasks.CHECK_FOR_CONTENT; - -/** - * Common methods and attributes between {@link VoicemailArchiveTest} and - * {@link VoicemailPlaybackTest}. - */ -public class VoicemailActivityInstrumentationTestCase2<T extends Activity> - extends ActivityInstrumentationTestCase2<T> { - protected static final String TEST_ASSET_NAME = "quick_test_recording.mp3"; - protected static final String MIME_TYPE = "audio/mp3"; - protected static final String CONTACT_NUMBER = "+1412555555"; - protected static final String VOICEMAIL_FILE_LOCATION = "/sdcard/sadlfj893w4j23o9sfu.mp3"; - - private T mActivity; - protected VoicemailPlaybackPresenter mPresenter; - private VoicemailPlaybackLayout mLayout; - - protected Uri mVoicemailUri; - private LocaleTestUtils mLocaleTestUtils; - protected FakeAsyncTaskExecutor mFakeAsyncTaskExecutor; - - public VoicemailActivityInstrumentationTestCase2(Class<T> activityClass) { - super(activityClass); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - - mFakeAsyncTaskExecutor = new FakeAsyncTaskExecutor(getInstrumentation()); - AsyncTaskExecutors.setFactoryForTest(mFakeAsyncTaskExecutor.getFactory()); - - // Some of the tests rely on the text - safest to force a specific locale. - mLocaleTestUtils = new LocaleTestUtils(getInstrumentation().getTargetContext()); - mLocaleTestUtils.setLocale(Locale.US); - - mActivity = getActivity(); - mLayout = new VoicemailPlaybackLayout(mActivity); - mLayout.onFinishInflate(); - } - - @Override - protected void tearDown() throws Exception { - cleanUpVoicemailUri(); - - mLocaleTestUtils.restoreLocale(); - mLocaleTestUtils = null; - - mPresenter.clearInstance(); - AsyncTaskExecutors.setFactoryForTest(null); - - mActivity = null; - mPresenter = null; - mLayout = null; - - super.tearDown(); - } - - @Suppress - public void testFetchingVoicemail() throws Throwable { - setUriForUnfetchedVoicemailEntry(); - setPlaybackViewForPresenter(); - - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mPresenter.resumePlayback(); - assertStateTextContains("Loading voicemail"); - } - }); - } - - @Suppress - public void testInvalidVoicemailShowsErrorMessage() throws Throwable { - setUriForInvalidVoicemailEntry(); - setPlaybackViewForPresenter(); - - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mPresenter.resumePlayback(); - } - }); - mFakeAsyncTaskExecutor.runTask(CHECK_FOR_CONTENT); - getInstrumentation().waitForIdleSync(); - - // The media player will have thrown an IOException since the file doesn't exist. - // This should have put a failed to play message on screen, buffering is gone. - assertStateTextContains("Couldn't play voicemail"); - assertStateTextNotContains("Buffering"); - } - - public void testClickingSpeakerphoneButton() throws Throwable { - setUriForRealFileVoicemailEntry(); - setPlaybackViewForPresenter(); - - // Check that the speakerphone is false to start. - assertFalse(mPresenter.isSpeakerphoneOn()); - - View speakerphoneButton = mLayout.findViewById(R.id.playback_speakerphone); - speakerphoneButton.performClick(); - assertTrue(mPresenter.isSpeakerphoneOn()); - } - - protected void cleanUpVoicemailUri() { - if (mVoicemailUri != null) { - getContentResolver().delete(VoicemailContract.Voicemails.CONTENT_URI, - "_ID = ?", new String[] { String.valueOf(ContentUris.parseId(mVoicemailUri)) }); - mVoicemailUri = null; - } - } - - protected void setUriForRealFileVoicemailEntry() throws IOException { - assertNull(mVoicemailUri); - ContentValues values = new ContentValues(); - values.put(VoicemailContract.Voicemails.DATE, String.valueOf(System.currentTimeMillis())); - values.put(VoicemailContract.Voicemails.NUMBER, CONTACT_NUMBER); - values.put(VoicemailContract.Voicemails.MIME_TYPE, MIME_TYPE); - values.put(VoicemailContract.Voicemails.HAS_CONTENT, 1); - String packageName = getInstrumentation().getTargetContext().getPackageName(); - mVoicemailUri = getContentResolver().insert( - VoicemailContract.Voicemails.buildSourceUri(packageName), values); - AssetManager assets = getAssets(); - try (InputStream inputStream = assets.open(TEST_ASSET_NAME); - OutputStream outputStream = getContentResolver().openOutputStream(mVoicemailUri)) { - copyBetweenStreams(inputStream, outputStream); - } - } - - protected void setUriForUnfetchedVoicemailEntry() { - assertNull(mVoicemailUri); - ContentValues values = new ContentValues(); - values.put(VoicemailContract.Voicemails.DATE, String.valueOf(System.currentTimeMillis())); - values.put(VoicemailContract.Voicemails.NUMBER, CONTACT_NUMBER); - values.put(VoicemailContract.Voicemails.MIME_TYPE, MIME_TYPE); - values.put(VoicemailContract.Voicemails.HAS_CONTENT, 0); - String packageName = getInstrumentation().getTargetContext().getPackageName(); - mVoicemailUri = getContentResolver().insert( - VoicemailContract.Voicemails.buildSourceUri(packageName), values); - } - - protected void setUriForInvalidVoicemailEntry() { - assertNull(mVoicemailUri); - ContentResolver contentResolver = getContentResolver(); - ContentValues values = new ContentValues(); - values.put(VoicemailContract.Voicemails.NUMBER, CONTACT_NUMBER); - values.put(VoicemailContract.Voicemails.HAS_CONTENT, 1); - // VoicemailContract.Voicemails._DATA - values.put("_data", VOICEMAIL_FILE_LOCATION); - mVoicemailUri = contentResolver.insert(VoicemailContract.Voicemails.CONTENT_URI, values); - } - - protected void setPlaybackViewForPresenter() { - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mPresenter.setPlaybackView(mLayout, mVoicemailUri, false); - } - }); - } - - protected void copyBetweenStreams(InputStream in, OutputStream out) throws IOException { - byte[] buffer = new byte[1024]; - int bytesRead; - while ((bytesRead = in.read(buffer)) > 0) { - out.write(buffer, 0, bytesRead); - } - } - - protected void assertStateTextContains(String text) { - assertNotNull(mLayout); - assertTrue(mLayout.getStateText().contains(text)); - } - - protected void assertStateTextNotContains(String text) { - assertNotNull(mLayout); - assertFalse(mLayout.getStateText().contains(text)); - } - - protected ContentResolver getContentResolver() { - return getInstrumentation().getTargetContext().getContentResolver(); - } - - protected AssetManager getAssets() { - return getInstrumentation().getContext().getAssets(); - } - -} diff --git a/tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java b/tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java deleted file mode 100644 index bbd5edc48..000000000 --- a/tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.voicemail; - -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.res.AssetManager; - -import com.android.dialer.database.VoicemailArchiveContract.VoicemailArchive; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * Unit tests for {@link VoicemailArchiveActivity} and {@link VoicemailArchivePlaybackPresenter}. - */ -public class VoicemailArchiveTest - extends VoicemailActivityInstrumentationTestCase2<VoicemailArchiveActivity> { - - public VoicemailArchiveTest() { - super(VoicemailArchiveActivity.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - mPresenter = VoicemailArchivePlaybackPresenter.getInstance(getActivity(), null); - } - - @Override - public void testFetchingVoicemail() throws Throwable { - setUriForRealFileVoicemailEntry(); - setPlaybackViewForPresenter(); - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mPresenter.checkForContent( - new VoicemailPlaybackPresenter.OnContentCheckedListener() { - @Override - public void onContentChecked(boolean hasContent) { - mPresenter.resumePlayback(); - assertEquals(true, mPresenter.isPlaying()); - } - }); - } - }); - } - - @Override - public void testInvalidVoicemailShowsErrorMessage() throws Throwable { - setUriForInvalidVoicemailEntry(); - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mPresenter.checkForContent( - new VoicemailPlaybackPresenter.OnContentCheckedListener() { - @Override - public void onContentChecked(boolean hasContent) { - assertStateTextContains("Couldn't play voicemail"); - } - }); - } - }); - } - - @Override - protected void setUriForInvalidVoicemailEntry() { - assertNull(mVoicemailUri); - ContentValues values = new ContentValues(); - values.put(VoicemailArchive.NUMBER, CONTACT_NUMBER); - values.put(VoicemailArchive.DATE, String.valueOf(System.currentTimeMillis())); - values.put(VoicemailArchive.MIME_TYPE, MIME_TYPE); - values.put(VoicemailArchive._DATA, VOICEMAIL_FILE_LOCATION); - mVoicemailUri = getContentResolver().insert(VoicemailArchive.CONTENT_URI, values); - } - - @Override - protected void setUriForRealFileVoicemailEntry() throws IOException { - assertNull(mVoicemailUri); - ContentValues values = new ContentValues(); - values.put(VoicemailArchive.DATE, String.valueOf(System.currentTimeMillis())); - values.put(VoicemailArchive.NUMBER, CONTACT_NUMBER); - values.put(VoicemailArchive.MIME_TYPE, MIME_TYPE); - values.put(VoicemailArchive.DURATION, 0); - mVoicemailUri = getContentResolver().insert(VoicemailArchive.CONTENT_URI, values); - AssetManager assets = getAssets(); - try (InputStream inputStream = assets.open(TEST_ASSET_NAME); - OutputStream outputStream = getContentResolver().openOutputStream(mVoicemailUri)) { - copyBetweenStreams(inputStream, outputStream); - } - } - - @Override - protected void cleanUpVoicemailUri() { - if (mVoicemailUri != null) { - getContentResolver().delete(VoicemailArchive.CONTENT_URI, - "_ID = ?", new String[] { String.valueOf(ContentUris.parseId(mVoicemailUri)) }); - mVoicemailUri = null; - } - } -} diff --git a/tests/src/com/android/dialer/voicemail/VoicemailAsyncTaskUtilTest.java b/tests/src/com/android/dialer/voicemail/VoicemailAsyncTaskUtilTest.java deleted file mode 100644 index d98d9fa59..000000000 --- a/tests/src/com/android/dialer/voicemail/VoicemailAsyncTaskUtilTest.java +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package com.android.dialer.voicemail; - -import android.content.ContentUris; -import android.content.ContentValues; -import android.content.res.AssetFileDescriptor; -import android.net.Uri; -import android.os.Bundle; -import android.os.ParcelFileDescriptor; -import android.provider.CallLog; -import android.provider.VoicemailContract; -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.calllog.CallLogQuery; -import com.android.dialer.database.VoicemailArchiveContract; -import com.android.dialer.util.AsyncTaskExecutors; -import com.android.dialer.util.FakeAsyncTaskExecutor; -import com.android.dialer.voicemail.VoicemailAsyncTaskUtil.OnGetArchivedVoicemailFilePathListener; -import com.android.dialer.voicemail.VoicemailAsyncTaskUtil.OnArchiveVoicemailListener; -import com.android.dialer.voicemail.VoicemailAsyncTaskUtil.OnSetVoicemailArchiveStatusListener; - -import org.junit.Rule; -import org.junit.rules.TemporaryFolder; -import static org.mockito.Mockito.*; - -import java.io.FileNotFoundException; -import java.io.IOException; - -public class VoicemailAsyncTaskUtilTest extends InstrumentationTestCase { - private static final String TEST_MIME_TYPE = "audio/mp3"; - private static final String TEST_NUMBER = "+1412555555"; - private static final String TEST_FILE_PATH = "TEST_PATH"; - private static final String TEST_TRANSCRIPTION = "TEST_TRANSCRIPTION"; - private static final long TEST_DATE = 0; - private static final long TEST_DURATION = 0; - private static final int TEST_SERVER_ID = 1; - private static final int TEST_ID = 2; - private static final Uri ARCHIVED_VOICEMAIL_URI = - VoicemailArchiveContract.VoicemailArchive.buildWithId(TEST_ID); - private static final Uri VOICEMAIL_URI = VoicemailContract.Voicemails.CONTENT_URI - .buildUpon().appendPath(Integer.toString(TEST_SERVER_ID)).build(); - private static final String[] CALLLOG_QUERY_PROJECTION = new String[] { - CallLog.Calls._ID, - CallLog.Calls.NUMBER, - CallLog.Calls.DATE, - CallLog.Calls.DURATION, - CallLog.Calls.TYPE, - CallLog.Calls.COUNTRY_ISO, - CallLog.Calls.VOICEMAIL_URI, - CallLog.Calls.GEOCODED_LOCATION, - CallLog.Calls.CACHED_NAME, - CallLog.Calls.CACHED_NUMBER_TYPE, - CallLog.Calls.CACHED_NUMBER_LABEL, - CallLog.Calls.CACHED_LOOKUP_URI, - CallLog.Calls.CACHED_MATCHED_NUMBER, - CallLog.Calls.CACHED_NORMALIZED_NUMBER, - CallLog.Calls.CACHED_PHOTO_ID, - CallLog.Calls.CACHED_FORMATTED_NUMBER, - CallLog.Calls.IS_READ, - CallLog.Calls.NUMBER_PRESENTATION, - CallLog.Calls.PHONE_ACCOUNT_COMPONENT_NAME, - CallLog.Calls.PHONE_ACCOUNT_ID, - CallLog.Calls.FEATURES, - CallLog.Calls.DATA_USAGE, - CallLog.Calls.TRANSCRIPTION, - CallLog.Calls.CACHED_PHOTO_URI - }; - private static final String[] VOICEMAIL_PROJECTION = new String[] { - VoicemailContract.Voicemails._ID, - VoicemailContract.Voicemails.NUMBER, - VoicemailContract.Voicemails.DATE, - VoicemailContract.Voicemails.DURATION, - VoicemailContract.Voicemails.MIME_TYPE, - VoicemailContract.Voicemails.TRANSCRIPTION, - }; - - private final MockContentResolver mContentResolver = new MockContentResolver(); - private final MockContentProvider mArchiveContentProvider = new TestVoicemailContentProvider(); - private final MockContentProvider mVoicemailContentProvider = - new TestVoicemailContentProvider(); - private final MockContentProvider mCallLogContentProvider = new MockContentProvider(); - @Rule - private final TemporaryFolder mTemporaryFolder = new TemporaryFolder(); - - private VoicemailAsyncTaskUtil mVoicemailAsyncTaskUtil; - private FakeAsyncTaskExecutor mFakeAsyncTaskExecutor; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mFakeAsyncTaskExecutor = new FakeAsyncTaskExecutor(getInstrumentation()); - AsyncTaskExecutors.setFactoryForTest(mFakeAsyncTaskExecutor.getFactory()); - mContentResolver.addProvider(VoicemailArchiveContract.AUTHORITY, mArchiveContentProvider); - mContentResolver.addProvider(VoicemailContract.AUTHORITY, mVoicemailContentProvider); - mContentResolver.addProvider(CallLog.AUTHORITY, mCallLogContentProvider); - mVoicemailAsyncTaskUtil = new VoicemailAsyncTaskUtil(mContentResolver); - } - - @Override - protected void tearDown() throws Exception { - AsyncTaskExecutors.setFactoryForTest(null); - super.tearDown(); - } - - public void testGetVoicemailFilePath_VoicemailExists() throws Throwable { - newVoicemailArchiveQuery().withAnyProjection() - .returnRow(getCombinedContentValuesWithData()); - final OnGetArchivedVoicemailFilePathListener listener = - mock(OnGetArchivedVoicemailFilePathListener.class); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - mVoicemailAsyncTaskUtil.getVoicemailFilePath(listener, ARCHIVED_VOICEMAIL_URI); - } - }); - mFakeAsyncTaskExecutor.runTask(VoicemailAsyncTaskUtil.Tasks.GET_VOICEMAIL_FILE_PATH); - verify(listener).onGetArchivedVoicemailFilePath(TEST_FILE_PATH); - verifyQueries(); - } - - public void testGetVoicemailFilePath_VoicemailNotExists() throws Throwable { - newVoicemailArchiveFakeQuery().withAnyProjection().returnEmptyCursor(); - final OnGetArchivedVoicemailFilePathListener listener = - mock(OnGetArchivedVoicemailFilePathListener.class); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - mVoicemailAsyncTaskUtil.getVoicemailFilePath(listener, getFakeVoicemailUri()); - } - }); - mFakeAsyncTaskExecutor.runTask(VoicemailAsyncTaskUtil.Tasks.GET_VOICEMAIL_FILE_PATH); - verify(listener).onGetArchivedVoicemailFilePath(null); - verifyQueries(); - } - - public void testSetVoicemailArchiveStatus_VoicemailNotExists() throws Throwable { - newVoicemailArchiveNotExistsUpdateQuery(true); - final OnSetVoicemailArchiveStatusListener listener = - mock(OnSetVoicemailArchiveStatusListener.class); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - mVoicemailAsyncTaskUtil.setVoicemailArchiveStatus(listener, - getFakeVoicemailUri(), true); - } - }); - mFakeAsyncTaskExecutor.runTask(VoicemailAsyncTaskUtil.Tasks.SET_VOICEMAIL_ARCHIVE_STATUS); - verify(listener).onSetVoicemailArchiveStatus(false); - verifyQueries(); - } - - public void testSetVoicemailArchiveStatus_VoicemailExists() throws Throwable { - newVoicemailArchiveExistsUpdateQuery(true); - final OnSetVoicemailArchiveStatusListener listener = - mock(OnSetVoicemailArchiveStatusListener.class); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - mVoicemailAsyncTaskUtil.setVoicemailArchiveStatus(listener, - ARCHIVED_VOICEMAIL_URI, true); - } - }); - mFakeAsyncTaskExecutor.runTask(VoicemailAsyncTaskUtil.Tasks.SET_VOICEMAIL_ARCHIVE_STATUS); - verify(listener).onSetVoicemailArchiveStatus(true); - verifyQueries(); - } - - public void testArchiveVoicemailContent_ArchiveNotExists() throws Throwable { - newVoicemailArchiveExistsQuery().returnEmptyCursor(); - newQueryCallLogInfo().returnRow(getCallLogContentValues()); - newVoicemailQuery().returnRow(getVoicemailContentValues()); - newVoicemailArchiveInsert(); - final OnArchiveVoicemailListener listener = mock(OnArchiveVoicemailListener.class); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - mVoicemailAsyncTaskUtil.archiveVoicemailContent(listener, VOICEMAIL_URI); - } - }); - mFakeAsyncTaskExecutor.runTask(VoicemailAsyncTaskUtil.Tasks.ARCHIVE_VOICEMAIL_CONTENT); - verify(listener).onArchiveVoicemail(ARCHIVED_VOICEMAIL_URI); - verifyQueries(); - } - - public void testArchiveVoicemailContent_ArchiveExists() throws Throwable { - newVoicemailArchiveExistsQuery().returnRow(getCombinedValuesWithId()); - final OnArchiveVoicemailListener listener = mock(OnArchiveVoicemailListener.class); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - mVoicemailAsyncTaskUtil.archiveVoicemailContent(listener, VOICEMAIL_URI); - } - }); - mFakeAsyncTaskExecutor.runTask(VoicemailAsyncTaskUtil.Tasks.ARCHIVE_VOICEMAIL_CONTENT); - verify(listener).onArchiveVoicemail(ARCHIVED_VOICEMAIL_URI); - verifyQueries(); - } - - public void testArchiveVoicemailContent_CallLogInfoNotExists() throws Throwable { - newVoicemailArchiveExistsQuery().returnEmptyCursor(); - newQueryCallLogInfo().returnEmptyCursor(); - newVoicemailQuery().returnEmptyCursor(); - final OnArchiveVoicemailListener listener = mock(OnArchiveVoicemailListener.class); - runTestOnUiThread(new Runnable() { - @Override - public void run() { - mVoicemailAsyncTaskUtil.archiveVoicemailContent(listener, VOICEMAIL_URI); - } - }); - mFakeAsyncTaskExecutor.runTask(VoicemailAsyncTaskUtil.Tasks.ARCHIVE_VOICEMAIL_CONTENT); - verify(listener).onArchiveVoicemail(null); - verifyQueries(); - } - - private Query newVoicemailArchiveQuery() { - return mArchiveContentProvider.expectQuery(ARCHIVED_VOICEMAIL_URI); - } - - private Query newVoicemailArchiveFakeQuery() { - return mArchiveContentProvider.expectQuery(getFakeVoicemailUri()); - } - - private Query newQueryCallLogInfo() { - return mCallLogContentProvider.expectQuery(ContentUris.withAppendedId( - CallLog.Calls.CONTENT_URI_WITH_VOICEMAIL, ContentUris.parseId(VOICEMAIL_URI))) - .withProjection(CALLLOG_QUERY_PROJECTION); - } - - private Query newVoicemailQuery() { - return mVoicemailContentProvider.expectQuery(VOICEMAIL_URI).withAnySelection() - .withProjection(VOICEMAIL_PROJECTION); - } - - private Query newVoicemailArchiveExistsQuery() { - return mArchiveContentProvider.expectQuery( - VoicemailArchiveContract.VoicemailArchive.CONTENT_URI) - .withSelection(VoicemailArchiveContract.VoicemailArchive.SERVER_ID + "=" - + ContentUris.parseId(VOICEMAIL_URI), (String[]) null) - .withProjection(VoicemailArchiveContract.VoicemailArchive._ID); - } - - private void newVoicemailArchiveInsert() { - mArchiveContentProvider.expectInsert( - VoicemailArchiveContract.VoicemailArchive.CONTENT_URI, getCombinedContentValues(), - ARCHIVED_VOICEMAIL_URI); - } - - private void newVoicemailArchiveNotExistsUpdateQuery(boolean status) { - mArchiveContentProvider.expectUpdate(getFakeVoicemailUri(), - getArchiveStatusUpdateValues(status), null, null).returnRowsAffected(0); - } - - private void newVoicemailArchiveExistsUpdateQuery(boolean status) { - mArchiveContentProvider.expectUpdate(ARCHIVED_VOICEMAIL_URI, - getArchiveStatusUpdateValues(status), null, null).returnRowsAffected(1); - } - - private static ContentValues getCallLogContentValues() { - ContentValues values = new ContentValues(); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.GEOCODED_LOCATION], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.CACHED_NAME], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.COUNTRY_ISO], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.CACHED_NUMBER_TYPE], 0); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.CACHED_NUMBER_LABEL], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.CACHED_LOOKUP_URI], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.CACHED_MATCHED_NUMBER], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.CACHED_NORMALIZED_NUMBER], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.CACHED_FORMATTED_NUMBER], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.NUMBER_PRESENTATION], 0); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.ACCOUNT_COMPONENT_NAME], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.ACCOUNT_ID], ""); - values.put(CALLLOG_QUERY_PROJECTION[CallLogQuery.FEATURES], 0); - values.put(CALLLOG_QUERY_PROJECTION[23], ""); - return values; - } - - private static ContentValues getVoicemailContentValues() { - ContentValues values = new ContentValues(); - values.put(VoicemailContract.Voicemails.NUMBER, TEST_NUMBER); - values.put(VoicemailContract.Voicemails.DATE, TEST_DATE); - values.put(VoicemailContract.Voicemails.DURATION, TEST_DURATION); - values.put(VoicemailContract.Voicemails.MIME_TYPE, TEST_MIME_TYPE); - values.put(VoicemailContract.Voicemails._ID, TEST_SERVER_ID); - values.put(VoicemailContract.Voicemails.TRANSCRIPTION, TEST_TRANSCRIPTION); - values.put("_data", TEST_FILE_PATH); // VoicemailContract.Voicemails._DATA - return values; - } - - private static ContentValues getCombinedContentValues() { - ContentValues values = new ContentValues(); - // Call log info - values.put(VoicemailArchiveContract.VoicemailArchive.GEOCODED_LOCATION, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.CACHED_NAME, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.CACHED_NUMBER_TYPE, 0); - values.put(VoicemailArchiveContract.VoicemailArchive.CACHED_NUMBER_LABEL, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.CACHED_LOOKUP_URI, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.CACHED_MATCHED_NUMBER, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.CACHED_NORMALIZED_NUMBER, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.CACHED_FORMATTED_NUMBER, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.NUMBER_PRESENTATION, 0); - values.put(VoicemailArchiveContract.VoicemailArchive.ACCOUNT_COMPONENT_NAME, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.ACCOUNT_ID, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.FEATURES, 0); - values.put(VoicemailArchiveContract.VoicemailArchive.CACHED_PHOTO_URI, ""); - values.put(VoicemailArchiveContract.VoicemailArchive.COUNTRY_ISO, ""); - - // Voicemail content info - values.put(VoicemailArchiveContract.VoicemailArchive.NUMBER, TEST_NUMBER); - values.put(VoicemailArchiveContract.VoicemailArchive.DATE, TEST_DATE); - values.put(VoicemailArchiveContract.VoicemailArchive.DURATION, TEST_DURATION); - values.put(VoicemailArchiveContract.VoicemailArchive.MIME_TYPE, TEST_MIME_TYPE); - values.put(VoicemailArchiveContract.VoicemailArchive.SERVER_ID, TEST_SERVER_ID); - values.put(VoicemailArchiveContract.VoicemailArchive.TRANSCRIPTION, TEST_TRANSCRIPTION); - - // Custom fields - values.put(VoicemailArchiveContract.VoicemailArchive.ARCHIVED, false); - return values; - } - - private static ContentValues getCombinedContentValuesWithData() { - ContentValues values = getCombinedContentValues(); - values.put(VoicemailArchiveContract.VoicemailArchive._DATA, TEST_FILE_PATH); - return values; - } - - private static ContentValues getCombinedValuesWithId() { - ContentValues values = getCombinedContentValuesWithData(); - values.put(VoicemailArchiveContract.VoicemailArchive._ID, TEST_ID); - return values; - } - - private static ContentValues getArchiveStatusUpdateValues(boolean status) { - ContentValues values = new ContentValues(); - values.put(VoicemailArchiveContract.VoicemailArchive.ARCHIVED, status); - return values; - } - - private static Uri getFakeVoicemailUri() { - return VoicemailArchiveContract.VoicemailArchive.buildWithId(0); - } - - private void verifyQueries() { - mArchiveContentProvider.verify(); - mCallLogContentProvider.verify(); - mVoicemailContentProvider.verify(); - } - - private class TestVoicemailContentProvider extends MockContentProvider { - @Override - public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException { - int modeBits = ParcelFileDescriptor.parseMode(mode); - try { - return ParcelFileDescriptor.open(mTemporaryFolder.newFile(), modeBits); - } catch (IOException e) { - return null; - } - } - - @Override - public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts) { - try { - return new AssetFileDescriptor(openFile(uri, "r"), 0, - AssetFileDescriptor.UNKNOWN_LENGTH); - } catch (FileNotFoundException e) { - return null; - } - } - } -} - diff --git a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java deleted file mode 100644 index be9905edd..000000000 --- a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.voicemail; - -import android.content.ContentUris; -import android.database.Cursor; -import android.net.Uri; -import android.test.suitebuilder.annotation.Suppress; - -import com.android.dialer.calllog.CallLogActivity; -import com.android.dialer.database.VoicemailArchiveContract; -import static com.android.dialer.voicemail.VoicemailAsyncTaskUtil.Tasks.ARCHIVE_VOICEMAIL_CONTENT; -import static com.android.dialer.voicemail.VoicemailPlaybackPresenter.Tasks.CHECK_FOR_CONTENT; - -/** - * Unit tests for {@link VoicemailPlaybackPresenter} and {@link VoicemailPlaybackLayout}. - */ -public class VoicemailPlaybackTest - extends VoicemailActivityInstrumentationTestCase2<CallLogActivity> { - - public VoicemailPlaybackTest() { - super(CallLogActivity.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - mPresenter = VoicemailPlaybackPresenter.getInstance(getActivity(), null); - } - - @Override - public void tearDown() throws Exception { - cleanUpArchivedVoicemailUri(); - super.tearDown(); - } - - @Suppress - public void testWhenCheckForContentCompletes() throws Throwable { - setUriForRealFileVoicemailEntry(); - setPlaybackViewForPresenter(); - - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mPresenter.resumePlayback(); - } - }); - mFakeAsyncTaskExecutor.runTask(CHECK_FOR_CONTENT); - getInstrumentation().waitForIdleSync(); - - assertStateTextContains("Loading voicemail"); - } - - public void testArchiveContent() throws Throwable { - setUriForRealFileVoicemailEntry(); - setPlaybackViewForPresenter(); - mFakeAsyncTaskExecutor.runTask(CHECK_FOR_CONTENT); - - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mPresenter.archiveContent(mVoicemailUri, true); - } - }); - mFakeAsyncTaskExecutor.runTask(CHECK_FOR_CONTENT); - mFakeAsyncTaskExecutor.runTask(ARCHIVE_VOICEMAIL_CONTENT); - getInstrumentation().waitForIdleSync(); - assertVoicemailArchived(); - } - - public void testShareContent() throws Throwable { - setUriForRealFileVoicemailEntry(); - setPlaybackViewForPresenter(); - mFakeAsyncTaskExecutor.runTask(CHECK_FOR_CONTENT); - - getInstrumentation().runOnMainSync(new Runnable() { - @Override - public void run() { - mPresenter.archiveContent(mVoicemailUri, false); - } - }); - mFakeAsyncTaskExecutor.runTask(CHECK_FOR_CONTENT); - mFakeAsyncTaskExecutor.runTask(ARCHIVE_VOICEMAIL_CONTENT); - getInstrumentation().waitForIdleSync(); - assertVoicemailArchived(); - } - - private void assertVoicemailArchived() { - try (Cursor cursor = getArchivedVoicemailCursor()) { - assertTrue(hasContent(cursor)); - assertEquals(ContentUris.parseId(mVoicemailUri), getRowServerId(cursor)); - } catch (Exception e) { - fail("Voicemail was not archived: " + e.toString()); - } - } - - private void cleanUpArchivedVoicemailUri() { - try (Cursor cursor = getArchivedVoicemailCursor()) { - if (hasContent(cursor)) { - getContentResolver().delete(getRowUri(cursor), null, null); - } - } - } - - private Cursor getArchivedVoicemailCursor() { - return getContentResolver().query( - VoicemailArchiveContract.VoicemailArchive.CONTENT_URI, - new String[] { - VoicemailArchiveContract.VoicemailArchive._ID, - VoicemailArchiveContract.VoicemailArchive.SERVER_ID - }, - VoicemailArchiveContract.VoicemailArchive.SERVER_ID + "=" - + ContentUris.parseId(mVoicemailUri), - null, - null); - } - - private int getRowServerId(Cursor cursor) { - return cursor - .getInt(cursor.getColumnIndex(VoicemailArchiveContract.VoicemailArchive.SERVER_ID)); - } - - private Uri getRowUri(Cursor cursor) { - return VoicemailArchiveContract.VoicemailArchive.buildWithId(cursor.getInt( - cursor.getColumnIndex(VoicemailArchiveContract.VoicemailArchive._ID))); - } - - private boolean hasContent(Cursor cursor) { - return cursor != null && cursor.moveToFirst(); - } -}
\ No newline at end of file diff --git a/tests/src/com/android/dialer/voicemail/VoicemailStatusHelperImplTest.java b/tests/src/com/android/dialer/voicemail/VoicemailStatusHelperImplTest.java deleted file mode 100644 index 03776440f..000000000 --- a/tests/src/com/android/dialer/voicemail/VoicemailStatusHelperImplTest.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.dialer.voicemail; - -import static android.provider.VoicemailContract.Status.CONFIGURATION_STATE; -import static android.provider.VoicemailContract.Status.CONFIGURATION_STATE_CAN_BE_CONFIGURED; -import static android.provider.VoicemailContract.Status.CONFIGURATION_STATE_NOT_CONFIGURED; -import static android.provider.VoicemailContract.Status.DATA_CHANNEL_STATE; -import static android.provider.VoicemailContract.Status.DATA_CHANNEL_STATE_NO_CONNECTION; -import static android.provider.VoicemailContract.Status.DATA_CHANNEL_STATE_OK; -import static android.provider.VoicemailContract.Status.NOTIFICATION_CHANNEL_STATE; -import static android.provider.VoicemailContract.Status.NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING; -import static android.provider.VoicemailContract.Status.NOTIFICATION_CHANNEL_STATE_NO_CONNECTION; -import static android.provider.VoicemailContract.Status.NOTIFICATION_CHANNEL_STATE_OK; - -import android.content.ContentResolver; -import android.content.ContentValues; -import android.database.Cursor; -import android.net.Uri; -import android.provider.VoicemailContract.Status; -import android.test.AndroidTestCase; - -import com.android.dialer.R; -import com.android.dialer.voicemail.VoicemailStatusHelper.StatusMessage; - -import java.util.List; - -/** - * Unit tests for {@link VoicemailStatusHelperImpl}. - */ -public class VoicemailStatusHelperImplTest extends AndroidTestCase { - private static final String[] TEST_PACKAGES = new String[] { - "com.test.package1", - "com.test.package2" - }; - - private static final Uri TEST_SETTINGS_URI = Uri.parse("http://www.visual.voicemail.setup"); - private static final Uri TEST_VOICEMAIL_URI = Uri.parse("tel:901"); - - private static final int ACTION_MSG_CALL_VOICEMAIL = - R.string.voicemail_status_action_call_server; - private static final int ACTION_MSG_CONFIGURE = R.string.voicemail_status_action_configure; - - private static final int STATUS_MSG_NONE = -1; - private static final int STATUS_MSG_VOICEMAIL_NOT_AVAILABLE = - R.string.voicemail_status_voicemail_not_available; - private static final int STATUS_MSG_AUDIO_NOT_AVAIALABLE = - R.string.voicemail_status_audio_not_available; - private static final int STATUS_MSG_MESSAGE_WAITING = R.string.voicemail_status_messages_waiting; - private static final int STATUS_MSG_INVITE_FOR_CONFIGURATION = - R.string.voicemail_status_configure_voicemail; - - // Object under test. - private VoicemailStatusHelper mStatusHelper; - - @Override - protected void setUp() throws Exception { - super.setUp(); - mStatusHelper = new VoicemailStatusHelperImpl(); - } - - @Override - protected void tearDown() throws Exception { - for (String sourcePackage : TEST_PACKAGES) { - deleteEntryForPackage(sourcePackage); - } - // Set member variables to null so that they are garbage collected across different runs - // of the tests. - mStatusHelper = null; - super.tearDown(); - } - - - public void testNoStatusEntries() { - assertEquals(0, getStatusMessages().size()); - } - - public void testAllOK() { - insertEntryForPackage(TEST_PACKAGES[0], getAllOkStatusValues()); - insertEntryForPackage(TEST_PACKAGES[1], getAllOkStatusValues()); - assertEquals(0, getStatusMessages().size()); - } - - public void testNotAllOKForOnePackage() { - insertEntryForPackage(TEST_PACKAGES[0], getAllOkStatusValues()); - insertEntryForPackage(TEST_PACKAGES[1], getAllOkStatusValues()); - - ContentValues values = new ContentValues(); - // Good data channel + no notification - // action: call voicemail - // msg: voicemail not available in call log page & none in call details page. - values.put(NOTIFICATION_CHANNEL_STATE, NOTIFICATION_CHANNEL_STATE_NO_CONNECTION); - values.put(DATA_CHANNEL_STATE, DATA_CHANNEL_STATE_OK); - updateEntryForPackage(TEST_PACKAGES[1], values); - checkExpectedMessage(TEST_PACKAGES[1], values, STATUS_MSG_VOICEMAIL_NOT_AVAILABLE, - STATUS_MSG_NONE, ACTION_MSG_CALL_VOICEMAIL); - - // Message waiting + good data channel - no action. - values.put(NOTIFICATION_CHANNEL_STATE, NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING); - values.put(DATA_CHANNEL_STATE, DATA_CHANNEL_STATE_OK); - updateEntryForPackage(TEST_PACKAGES[1], values); - checkNoMessages(TEST_PACKAGES[1], values); - - // No data channel + no notification - // action: call voicemail - // msg: voicemail not available in call log page & audio not available in call details page. - values.put(NOTIFICATION_CHANNEL_STATE, NOTIFICATION_CHANNEL_STATE_OK); - values.put(DATA_CHANNEL_STATE, DATA_CHANNEL_STATE_NO_CONNECTION); - updateEntryForPackage(TEST_PACKAGES[1], values); - checkExpectedMessage(TEST_PACKAGES[1], values, STATUS_MSG_VOICEMAIL_NOT_AVAILABLE, - STATUS_MSG_AUDIO_NOT_AVAIALABLE, ACTION_MSG_CALL_VOICEMAIL); - - // No data channel + Notification OK - // action: call voicemail - // msg: voicemail not available in call log page & audio not available in call details page. - values.put(NOTIFICATION_CHANNEL_STATE, NOTIFICATION_CHANNEL_STATE_NO_CONNECTION); - values.put(DATA_CHANNEL_STATE, DATA_CHANNEL_STATE_NO_CONNECTION); - updateEntryForPackage(TEST_PACKAGES[1], values); - checkExpectedMessage(TEST_PACKAGES[1], values, STATUS_MSG_VOICEMAIL_NOT_AVAILABLE, - STATUS_MSG_AUDIO_NOT_AVAIALABLE, ACTION_MSG_CALL_VOICEMAIL); - - // No data channel + Notification OK - // action: call voicemail - // msg: message waiting in call log page & audio not available in call details page. - values.put(NOTIFICATION_CHANNEL_STATE, NOTIFICATION_CHANNEL_STATE_MESSAGE_WAITING); - values.put(DATA_CHANNEL_STATE, DATA_CHANNEL_STATE_NO_CONNECTION); - updateEntryForPackage(TEST_PACKAGES[1], values); - checkExpectedMessage(TEST_PACKAGES[1], values, STATUS_MSG_MESSAGE_WAITING, - STATUS_MSG_AUDIO_NOT_AVAIALABLE, ACTION_MSG_CALL_VOICEMAIL); - - // Not configured. No user action, so no message. - values.put(CONFIGURATION_STATE, CONFIGURATION_STATE_NOT_CONFIGURED); - updateEntryForPackage(TEST_PACKAGES[1], values); - checkNoMessages(TEST_PACKAGES[1], values); - - // Can be configured - invite user for configure voicemail. - values.put(CONFIGURATION_STATE, CONFIGURATION_STATE_CAN_BE_CONFIGURED); - updateEntryForPackage(TEST_PACKAGES[1], values); - checkExpectedMessage(TEST_PACKAGES[1], values, STATUS_MSG_INVITE_FOR_CONFIGURATION, - STATUS_MSG_NONE, ACTION_MSG_CONFIGURE, TEST_SETTINGS_URI); - } - - // Test that priority of messages are handled well. - public void testMessageOrdering() { - insertEntryForPackage(TEST_PACKAGES[0], getAllOkStatusValues()); - insertEntryForPackage(TEST_PACKAGES[1], getAllOkStatusValues()); - - final ContentValues valuesNoNotificationGoodDataChannel = new ContentValues(); - valuesNoNotificationGoodDataChannel.put(NOTIFICATION_CHANNEL_STATE, - NOTIFICATION_CHANNEL_STATE_NO_CONNECTION); - valuesNoNotificationGoodDataChannel.put(DATA_CHANNEL_STATE, DATA_CHANNEL_STATE_OK); - - final ContentValues valuesNoNotificationNoDataChannel = new ContentValues(); - valuesNoNotificationNoDataChannel.put(NOTIFICATION_CHANNEL_STATE, - NOTIFICATION_CHANNEL_STATE_NO_CONNECTION); - valuesNoNotificationNoDataChannel.put(DATA_CHANNEL_STATE, DATA_CHANNEL_STATE_NO_CONNECTION); - - // Package1 with valuesNoNotificationGoodDataChannel and - // package2 with valuesNoNotificationNoDataChannel. Package2 should be above. - updateEntryForPackage(TEST_PACKAGES[0], valuesNoNotificationGoodDataChannel); - updateEntryForPackage(TEST_PACKAGES[1], valuesNoNotificationNoDataChannel); - List<StatusMessage> messages = getStatusMessages(); - assertEquals(2, messages.size()); - assertEquals(TEST_PACKAGES[0], messages.get(1).sourcePackage); - assertEquals(TEST_PACKAGES[1], messages.get(0).sourcePackage); - - // Now reverse the values - ordering should be reversed as well. - updateEntryForPackage(TEST_PACKAGES[0], valuesNoNotificationNoDataChannel); - updateEntryForPackage(TEST_PACKAGES[1], valuesNoNotificationGoodDataChannel); - messages = getStatusMessages(); - assertEquals(2, messages.size()); - assertEquals(TEST_PACKAGES[0], messages.get(0).sourcePackage); - assertEquals(TEST_PACKAGES[1], messages.get(1).sourcePackage); - } - - /** Checks that the expected source status message is returned by VoicemailStatusHelper. */ - private void checkExpectedMessage(String sourcePackage, ContentValues values, - int expectedCallLogMsg, int expectedCallDetailsMsg, int expectedActionMsg, - Uri expectedUri) { - List<StatusMessage> messages = getStatusMessages(); - assertEquals(1, messages.size()); - checkMessageMatches(messages.get(0), sourcePackage, expectedCallLogMsg, - expectedCallDetailsMsg, expectedActionMsg, expectedUri); - } - - private void checkExpectedMessage(String sourcePackage, ContentValues values, - int expectedCallLogMsg, int expectedCallDetailsMessage, int expectedActionMsg) { - checkExpectedMessage(sourcePackage, values, expectedCallLogMsg, expectedCallDetailsMessage, - expectedActionMsg, TEST_VOICEMAIL_URI); - } - - private void checkMessageMatches(StatusMessage message, String expectedSourcePackage, - int expectedCallLogMsg, int expectedCallDetailsMsg, int expectedActionMsg, - Uri expectedUri) { - assertEquals(expectedSourcePackage, message.sourcePackage); - assertEquals(expectedCallLogMsg, message.callLogMessageId); - assertEquals(expectedCallDetailsMsg, message.callDetailsMessageId); - assertEquals(expectedActionMsg, message.actionMessageId); - if (expectedUri == null) { - assertNull(message.actionUri); - } else { - assertEquals(expectedUri, message.actionUri); - } - } - - private void checkNoMessages(String sourcePackage, ContentValues values) { - assertEquals(1, updateEntryForPackage(sourcePackage, values)); - List<StatusMessage> messages = getStatusMessages(); - assertEquals(0, messages.size()); - } - - private ContentValues getAllOkStatusValues() { - ContentValues values = new ContentValues(); - values.put(Status.SETTINGS_URI, TEST_SETTINGS_URI.toString()); - values.put(Status.VOICEMAIL_ACCESS_URI, TEST_VOICEMAIL_URI.toString()); - values.put(Status.CONFIGURATION_STATE, Status.CONFIGURATION_STATE_OK); - values.put(Status.DATA_CHANNEL_STATE, Status.DATA_CHANNEL_STATE_OK); - values.put(Status.NOTIFICATION_CHANNEL_STATE, Status.NOTIFICATION_CHANNEL_STATE_OK); - return values; - } - - private void insertEntryForPackage(String sourcePackage, ContentValues values) { - // If insertion fails then try update as the record might already exist. - if (getContentResolver().insert(Status.buildSourceUri(sourcePackage), values) == null) { - updateEntryForPackage(sourcePackage, values); - } - } - - private void deleteEntryForPackage(String sourcePackage) { - getContentResolver().delete(Status.buildSourceUri(sourcePackage), null, null); - } - - private int updateEntryForPackage(String sourcePackage, ContentValues values) { - return getContentResolver().update( - Status.buildSourceUri(sourcePackage), values, null, null); - } - - private List<StatusMessage> getStatusMessages() { - // Restrict the cursor to only the the test packages to eliminate any side effects if there - // are other status messages already stored on the device. - Cursor cursor = getContentResolver().query(Status.CONTENT_URI, - VoicemailStatusHelperImpl.PROJECTION, getTestPackageSelection(), null, null); - return mStatusHelper.getStatusMessages(cursor); - } - - private String getTestPackageSelection() { - StringBuilder sb = new StringBuilder(); - for (String sourcePackage : TEST_PACKAGES) { - if (sb.length() > 0) { - sb.append(" OR "); - } - sb.append(String.format("(source_package='%s')", sourcePackage)); - } - return sb.toString(); - } - - private ContentResolver getContentResolver() { - return getContext().getContentResolver(); - } -} |