diff options
author | Andrew Lee <anwlee@google.com> | 2015-05-29 10:39:14 -0700 |
---|---|---|
committer | Andrew Lee <anwlee@google.com> | 2015-06-01 11:50:09 -0700 |
commit | 42be85d8a976c049ea237a48a35beada80638b85 (patch) | |
tree | 975b86d8b44691c1bd29f0055102932ae676c17c /tests | |
parent | 6c327dcc027c6df1548873031d62a0d84a0dc50d (diff) | |
download | android_packages_apps_Dialer-42be85d8a976c049ea237a48a35beada80638b85.tar.gz android_packages_apps_Dialer-42be85d8a976c049ea237a48a35beada80638b85.tar.bz2 android_packages_apps_Dialer-42be85d8a976c049ea237a48a35beada80638b85.zip |
Fix CallDetailActivity tests.
+ Reset the AsyncTaskExecutor's instance between calls in tests.
I don't know why this is necessary, but it fixes a class of problems
which were happening.
+ Don't try to release a media player if it has not been prepared.
+ Handle possible race conditions since MediaPlayer's async prepare
may be buffering or finished when a test assert is executed.
+ Add asset file no longer provided by variablespeed library.
- Cleanup some stream copy code.
Change-Id: I0ae5fde00514c6dcdb1e9c063435a13eed6e8528
Diffstat (limited to 'tests')
-rw-r--r-- | tests/assets/README.txt | 3 | ||||
-rw-r--r-- | tests/assets/quick_test_recording.mp3 | bin | 0 -> 30591 bytes | |||
-rw-r--r-- | tests/src/com/android/dialer/CallDetailActivityTest.java | 50 |
3 files changed, 30 insertions, 23 deletions
diff --git a/tests/assets/README.txt b/tests/assets/README.txt new file mode 100644 index 000000000..6cea058cf --- /dev/null +++ b/tests/assets/README.txt @@ -0,0 +1,3 @@ +quick_test_recording.mp3 is copyright 2011 by Hugo Hudson and is licensed under a +Creative Commons Attribution 3.0 Unported License: + http://creativecommons.org/licenses/by/3.0/ diff --git a/tests/assets/quick_test_recording.mp3 b/tests/assets/quick_test_recording.mp3 Binary files differnew file mode 100644 index 000000000..ad7cb9c20 --- /dev/null +++ b/tests/assets/quick_test_recording.mp3 diff --git a/tests/src/com/android/dialer/CallDetailActivityTest.java b/tests/src/com/android/dialer/CallDetailActivityTest.java index 4dc9ebb81..97b1b0989 100644 --- a/tests/src/com/android/dialer/CallDetailActivityTest.java +++ b/tests/src/com/android/dialer/CallDetailActivityTest.java @@ -33,12 +33,12 @@ import android.test.suitebuilder.annotation.Suppress; import android.view.Menu; import android.widget.TextView; +import com.android.dialer.calllog.CallLogAsyncTaskUtil; import com.android.dialer.util.AsyncTaskExecutors; import com.android.dialer.util.FakeAsyncTaskExecutor; import com.android.contacts.common.test.IntegrationTestUtils; import com.android.dialer.util.LocaleTestUtils; import com.android.internal.view.menu.ContextMenuBuilder; -import com.google.common.io.Closeables; import java.io.IOException; import java.io.InputStream; @@ -90,27 +90,29 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal cleanUpUri(); mTestUtils = null; AsyncTaskExecutors.setFactoryForTest(null); + CallLogAsyncTaskUtil.resetForTest(); super.tearDown(); } public void testInitialActivityStartsWithFetchingVoicemail() throws Throwable { - setActivityIntentForTestVoicemailEntry(); + setActivityIntentForRealFileVoicemailEntry(); startActivityUnderTest(); - // When the activity first starts, we will show "Fetching voicemail" on the screen. + // When the activity first starts, we will show "Loading voicemail" on the screen. // The duration should not be visible. - assertHasOneTextViewContaining("Fetching voicemail"); + assertHasOneTextViewContaining("Loading voicemail"); assertZeroTextViewsContaining("00:00"); } - public void testWhenCheckForContentCompletes_UiShowsBuffering() throws Throwable { - setActivityIntentForTestVoicemailEntry(); + public void testWhenCheckForContentCompletes() throws Throwable { + setActivityIntentForRealFileVoicemailEntry(); startActivityUnderTest(); // There is a background check that is testing to see if we have the content available. - // Once that task completes, we shouldn't be showing the fetching message, we should - // be showing "Buffering". + // Once that task completes, we shouldn't be showing the fetching message. mFakeAsyncTaskExecutor.runTask(CHECK_FOR_CONTENT); - assertHasOneTextViewContaining("Buffering"); - assertZeroTextViewsContaining("Fetching voicemail"); + + // The voicemail async call may or may not return before we check the asserts. + assertHasOneTextViewContaining("Buffering", "00:00"); + assertZeroTextViewsContaining("Loading voicemail"); } public void testInvalidVoicemailShowsErrorMessage() throws Throwable { @@ -126,7 +128,7 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal public void testOnResumeDoesNotCreateManyFragments() throws Throwable { // There was a bug where every time the activity was resumed, a new fragment was created. // Before the fix, this was failing reproducibly with at least 3 "Buffering" views. - setActivityIntentForTestVoicemailEntry(); + setActivityIntentForRealFileVoicemailEntry(); startActivityUnderTest(); mFakeAsyncTaskExecutor.runTask(CHECK_FOR_CONTENT); getInstrumentation().runOnMainSync(new Runnable() { @@ -138,7 +140,7 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal getInstrumentation().callActivityOnResume(mActivityUnderTest); } }); - assertHasOneTextViewContaining("Buffering"); + assertHasOneTextViewContaining("Buffering", "00:00"); } /** @@ -215,6 +217,7 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal values.put(VoicemailContract.Voicemails.HAS_CONTENT, 1); values.put(VoicemailContract.Voicemails._DATA, VOICEMAIL_FILE_LOCATION); mVoicemailUri = contentResolver.insert(VoicemailContract.Voicemails.CONTENT_URI, values); + Uri callLogUri = ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI_WITH_VOICEMAIL, ContentUris.parseId(mVoicemailUri)); Intent intent = new Intent(Intent.ACTION_VIEW, callLogUri); @@ -233,15 +236,9 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal mVoicemailUri = getContentResolver().insert( VoicemailContract.Voicemails.buildSourceUri(packageName), values); AssetManager assets = getAssets(); - OutputStream outputStream = null; - InputStream inputStream = null; - try { - inputStream = assets.open(TEST_ASSET_NAME); - outputStream = getContentResolver().openOutputStream(mVoicemailUri); + try (InputStream inputStream = assets.open(TEST_ASSET_NAME); + OutputStream outputStream = getContentResolver().openOutputStream(mVoicemailUri)) { copyBetweenStreams(inputStream, outputStream); - } finally { - Closeables.closeQuietly(outputStream); - Closeables.closeQuietly(inputStream); } Uri callLogUri = ContentUris.withAppendedId(CallLog.Calls.CONTENT_URI_WITH_VOICEMAIL, ContentUris.parseId(mVoicemailUri)); @@ -253,9 +250,7 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal public void copyBetweenStreams(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int bytesRead; - int total = 0; - while ((bytesRead = in.read(buffer)) != -1) { - total += bytesRead; + while ((bytesRead = in.read(buffer)) > 0) { out.write(buffer, 0, bytesRead); } } @@ -285,6 +280,14 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal return views.get(0); } + private void assertHasOneTextViewContaining(String text1, String text2) throws Throwable { + assertNotNull(mActivityUnderTest); + List<TextView> view1s = mTestUtils.getTextViewsWithString(mActivityUnderTest, text1); + List<TextView> view2s = mTestUtils.getTextViewsWithString(mActivityUnderTest, text2); + assertEquals("There should have been one TextView with text '" + text1 + "' or text '" + + text2 + "' but found " + view1s + view2s, 1, view1s.size() + view2s.size()); + } + private void assertZeroTextViewsContaining(String text) throws Throwable { assertNotNull(mActivityUnderTest); List<TextView> views = mTestUtils.getTextViewsWithString(mActivityUnderTest, text); @@ -300,6 +303,7 @@ public class CallDetailActivityTest extends ActivityInstrumentationTestCase2<Cal // This is because it seems that we can have onResume, onPause, onResume during the course // of a single unit test. mFakeAsyncTaskExecutor.runAllTasks(GET_CALL_DETAILS); + CallLogAsyncTaskUtil.resetForTest(); } private AssetManager getAssets() { |