summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSarmad Hashmi <mhashmi@google.com>2016-03-04 19:45:03 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2016-03-04 19:45:04 +0000
commitee8f5a3c0d865bee5d54ef486fed063f08ceb818 (patch)
tree39454e6cb9b19b3afc63241c9b634558a31f43e4 /tests
parent6b0056f348e1f9ecf0f91b53b51d240961bc8313 (diff)
parent3694b119843c161c3fdcf0820ec8bf755c79158f (diff)
Merge "Add files for voicemail archive tab." into nyc-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java212
-rw-r--r--tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java118
-rw-r--r--tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java206
3 files changed, 336 insertions, 200 deletions
diff --git a/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java b/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java
new file mode 100644
index 000000000..a992e8bd0
--- /dev/null
+++ b/tests/src/com/android/dialer/voicemail/VoicemailActivityInstrumentationTestCase2.java
@@ -0,0 +1,212 @@
+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
new file mode 100644
index 000000000..8cbd344a2
--- /dev/null
+++ b/tests/src/com/android/dialer/voicemail/VoicemailArchiveTest.java
@@ -0,0 +1,118 @@
+/*
+ * 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 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;
+
+/**
+ * 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/VoicemailPlaybackTest.java b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java
index 630789cf7..abd582bec 100644
--- a/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java
+++ b/tests/src/com/android/dialer/voicemail/VoicemailPlaybackTest.java
@@ -16,54 +16,17 @@
package com.android.dialer.voicemail;
-import static com.android.dialer.voicemail.VoicemailPlaybackPresenter.Tasks.CHECK_FOR_CONTENT;
-import static com.android.dialer.voicemail.VoicemailPlaybackPresenter.Tasks.CHECK_CONTENT_AFTER_CHANGE;
-
-import android.app.Activity;
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.res.AssetManager;
-import android.net.Uri;
-import android.provider.VoicemailContract;
-import android.test.ActivityInstrumentationTestCase2;
-import android.test.suitebuilder.annotation.LargeTest;
import android.test.suitebuilder.annotation.Suppress;
-import android.view.View;
-import android.widget.TextView;
-import com.android.dialer.R;
import com.android.dialer.calllog.CallLogActivity;
-import com.android.dialer.util.AsyncTaskExecutors;
-import com.android.dialer.util.FakeAsyncTaskExecutor;
-import com.android.dialer.util.LocaleTestUtils;
-import com.android.dialer.voicemail.VoicemailPlaybackLayout;
-import com.android.dialer.voicemail.VoicemailPlaybackPresenter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.List;
-import java.util.Locale;
+import static com.android.dialer.voicemail.VoicemailPlaybackPresenter.Tasks.CHECK_FOR_CONTENT;
/**
- * Unit tests for the {@link VoicemailPlaybackPresenter} and {@link VoicemailPlaybackLayout}.
+ * Unit tests for {@link VoicemailPlaybackPresenter} and {@link VoicemailPlaybackLayout}.
*/
-@LargeTest
-public class VoicemailPlaybackTest extends ActivityInstrumentationTestCase2<CallLogActivity> {
- private static final String TEST_ASSET_NAME = "quick_test_recording.mp3";
- private static final String MIME_TYPE = "audio/mp3";
- private static final String CONTACT_NUMBER = "+1412555555";
- private static final String VOICEMAIL_FILE_LOCATION = "/sdcard/sadlfj893w4j23o9sfu.mp3";
-
- private Activity mActivity;
- private VoicemailPlaybackPresenter mPresenter;
- private VoicemailPlaybackLayout mLayout;
-
- private Uri mVoicemailUri;
- private LocaleTestUtils mLocaleTestUtils;
- private FakeAsyncTaskExecutor mFakeAsyncTaskExecutor;
+public class VoicemailPlaybackTest
+ extends VoicemailActivityInstrumentationTestCase2<CallLogActivity> {
public VoicemailPlaybackTest() {
super(CallLogActivity.class);
@@ -72,49 +35,7 @@ public class VoicemailPlaybackTest extends ActivityInstrumentationTestCase2<Call
@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();
-
- mPresenter = VoicemailPlaybackPresenter.getInstance(mActivity, null);
- }
-
- @Override
- protected void tearDown() throws Exception {
- cleanUpVoicemailUri();
-
- mLocaleTestUtils.restoreLocale();
- mLocaleTestUtils = null;
-
- mPresenter.clearInstance();
- AsyncTaskExecutors.setFactoryForTest(null);
-
- mActivity = null;
- mPresenter = null;
- mLayout = null;
-
- super.tearDown();
- }
-
- public void testFetchingVoicemail() throws Throwable {
- setUriForUnfetchedVoicemailEntry();
- setPlaybackViewForPresenter();
-
- getInstrumentation().runOnMainSync(new Runnable() {
- @Override
- public void run() {
- mPresenter.resumePlayback();
- assertStateTextContains("Loading voicemail");
- }
- });
+ mPresenter = VoicemailPlaybackPresenter.getInstance(getActivity(), null);
}
@Suppress
@@ -133,119 +54,4 @@ public class VoicemailPlaybackTest extends ActivityInstrumentationTestCase2<Call
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());
- }
-
- private void cleanUpVoicemailUri() {
- if (mVoicemailUri != null) {
- getContentResolver().delete(VoicemailContract.Voicemails.CONTENT_URI,
- "_ID = ?", new String[] { String.valueOf(ContentUris.parseId(mVoicemailUri)) });
- mVoicemailUri = null;
- }
- }
-
- private 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);
- }
- }
-
- private 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);
- }
-
- private 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);
- }
-
- private void setPlaybackViewForPresenter() {
- getInstrumentation().runOnMainSync(new Runnable() {
- @Override
- public void run() {
- mPresenter.setPlaybackView(mLayout, mVoicemailUri, false);
- }
- });
- }
-
- public 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);
- }
- }
-
- private void assertStateTextContains(String text) {
- assertNotNull(mLayout);
- assertTrue(mLayout.getStateText().contains(text));
- }
-
- private void assertStateTextNotContains(String text) {
- assertNotNull(mLayout);
- assertFalse(mLayout.getStateText().contains(text));
- }
-
- private ContentResolver getContentResolver() {
- return getInstrumentation().getTargetContext().getContentResolver();
- }
-
- private AssetManager getAssets() {
- return getInstrumentation().getContext().getAssets();
- }
-}
+} \ No newline at end of file