diff options
Diffstat (limited to 'tests/src')
4 files changed, 149 insertions, 8 deletions
diff --git a/tests/src/com/android/dialer/database/VoicemailArchiveProviderTest.java b/tests/src/com/android/dialer/database/VoicemailArchiveProviderTest.java index cec7e050d..abc2dc5b0 100644 --- a/tests/src/com/android/dialer/database/VoicemailArchiveProviderTest.java +++ b/tests/src/com/android/dialer/database/VoicemailArchiveProviderTest.java @@ -79,6 +79,33 @@ public class VoicemailArchiveProviderTest extends assertTrue(doesFileExist()); } + public void testQuery_createFileMimeTypeIsAMR() throws Exception { + insertVoicemailWithMimeType("audio/amr"); + assertTrue(doesRowExist()); + assertFalse(doesFileExist()); + createFile(); + assertTrue(doesFileExist()); + assertEquals("amr", getFileExtension(getFilePath())); + } + + public void testQuery_createFileMimeTypeIsMP3() throws Exception { + insertVoicemailWithMimeType("audio/mpeg"); + assertTrue(doesRowExist()); + assertFalse(doesFileExist()); + createFile(); + assertTrue(doesFileExist()); + assertEquals("mp3", getFileExtension(getFilePath())); + } + + public void testQuery_createFileMimeTypeNotExists() throws Exception { + insertVoicemailWithMimeType(TEST_STRING); + assertTrue(doesRowExist()); + assertFalse(doesFileExist()); + createFile(); + assertTrue(doesFileExist()); + assertEquals("", getFileExtension(getFilePath())); + } + public void testQuery() { insertVoicemail(); updateCursor(); @@ -179,6 +206,13 @@ public class VoicemailArchiveProviderTest extends return voicemailFile.exists(); } + private static String getFileExtension(String filePath) { + File file = new File(filePath); + String fileName = file.getName(); + int index = fileName.lastIndexOf("."); + return index > 0 ? fileName.substring(index + 1) : ""; + } + private void assertCursorCount(int count) { assertEquals(count, mCursor.getCount()); } @@ -196,6 +230,12 @@ public class VoicemailArchiveProviderTest extends mVoicemailUri = mResolver.insert(VoicemailArchive.CONTENT_URI, getTestValues()); } + private void insertVoicemailWithMimeType(String mimeType) { + ContentValues values = getTestValues(); + values.put(VoicemailArchive.MIME_TYPE, mimeType); + mVoicemailUri = mResolver.insert(VoicemailArchive.CONTENT_URI, values); + } + private void updateCursor() { mCursor = mResolver.query(mVoicemailUri, null, null, null, null); assertEquals(true, mCursor.getCount() > 0); @@ -226,7 +266,7 @@ public class VoicemailArchiveProviderTest extends return mCursor.getString(mCursor.getColumnIndex(VoicemailArchive._DATA)); } - private ContentValues getTestValues() { + private static ContentValues getTestValues() { ContentValues values = new ContentValues(); values.put(VoicemailArchive.NUMBER, TEST_NUMBER); values.put(VoicemailArchive.MIME_TYPE, TEST_MIME_TYPE); diff --git a/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java b/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java index a992e8bd0..cabaf6732 100644 --- a/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java +++ b/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java @@ -1,3 +1,19 @@ +/* + * 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; @@ -23,7 +39,6 @@ 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}. diff --git a/tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java b/tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java index 8cbd344a2..bbd5edc48 100644 --- a/tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java +++ b/tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java @@ -15,15 +15,13 @@ */ package com.android.dialer.voicemail; + import android.content.ContentUris; import android.content.ContentValues; +import android.content.res.AssetManager; -import com.android.dialer.R; import com.android.dialer.database.VoicemailArchiveContract.VoicemailArchive; -import android.content.res.AssetManager; -import android.test.suitebuilder.annotation.Suppress; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; diff --git a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java index abd582bec..be9905edd 100644 --- a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java +++ b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 The Android Open Source Project + * 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. @@ -16,10 +16,14 @@ 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; /** @@ -38,6 +42,12 @@ public class VoicemailPlaybackTest mPresenter = VoicemailPlaybackPresenter.getInstance(getActivity(), null); } + @Override + public void tearDown() throws Exception { + cleanUpArchivedVoicemailUri(); + super.tearDown(); + } + @Suppress public void testWhenCheckForContentCompletes() throws Throwable { setUriForRealFileVoicemailEntry(); @@ -54,4 +64,82 @@ public class VoicemailPlaybackTest 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 |