diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-06-07 16:38:29 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-06-07 16:38:29 +0200 |
commit | c3e0ac9e74ef012c08eef0348604c2fdefca8074 (patch) | |
tree | a9cd92b8901d1d9fbda4330cd30c000fae64c025 /src/instrumentationTest/de | |
parent | c4e0078382c6ea048456e127cc887476d48a6686 (diff) | |
download | AntennaPod-c3e0ac9e74ef012c08eef0348604c2fdefca8074.zip |
Added test cases for starting playback
Diffstat (limited to 'src/instrumentationTest/de')
5 files changed, 159 insertions, 8 deletions
diff --git a/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java b/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java index 26f38da98..2dfd6a544 100644 --- a/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java +++ b/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java @@ -66,8 +66,6 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv public void testClickNavDrawer() throws Exception { uiTestUtils.addLocalFeedData(false); - EventDistributor.getInstance().sendFeedUpdateBroadcast(); - EventDistributor.getInstance().sendQueueUpdateBroadcast(); final View home = solo.getView(android.R.id.home); diff --git a/src/instrumentationTest/de/test/antennapod/ui/PlaybackTest.java b/src/instrumentationTest/de/test/antennapod/ui/PlaybackTest.java new file mode 100644 index 000000000..835973560 --- /dev/null +++ b/src/instrumentationTest/de/test/antennapod/ui/PlaybackTest.java @@ -0,0 +1,149 @@ +package instrumentationTest.de.test.antennapod.ui; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.test.ActivityInstrumentationTestCase2; +import android.widget.TextView; +import com.robotium.solo.Solo; +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.AudioplayerActivity; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.feed.FeedItem; +import de.danoeh.antennapod.preferences.UserPreferences; +import de.danoeh.antennapod.service.playback.PlaybackService; +import de.danoeh.antennapod.storage.DBReader; +import de.danoeh.antennapod.storage.DBWriter; +import de.danoeh.antennapod.storage.PodDBAdapter; + +import java.util.List; + +/** + * Test cases for starting and ending playback from the MainActivity and AudioPlayerActivity + */ +public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity> { + + private Solo solo; + private UITestUtils uiTestUtils; + + public PlaybackTest() { + super(MainActivity.class); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + solo = new Solo(getInstrumentation(), getActivity()); + uiTestUtils = new UITestUtils(getInstrumentation().getTargetContext()); + uiTestUtils.setup(); + // create database + PodDBAdapter adapter = new PodDBAdapter(getInstrumentation().getTargetContext()); + adapter.open(); + adapter.close(); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext()); + prefs.edit().putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false).commit(); + } + + @Override + public void tearDown() throws Exception { + uiTestUtils.tearDown(); + solo.finishOpenedActivities(); + PodDBAdapter.deleteDatabase(getInstrumentation().getTargetContext()); + + // shut down playback service + skipEpisode(); + getInstrumentation().getTargetContext().sendBroadcast( + new Intent(PlaybackService.ACTION_SHUTDOWN_PLAYBACK_SERVICE)); + + super.tearDown(); + } + + private void setContinuousPlaybackPreference(boolean value) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext()); + prefs.edit().putBoolean(UserPreferences.PREF_FOLLOW_QUEUE, value).commit(); + } + + private void skipEpisode() { + Intent skipIntent = new Intent(PlaybackService.ACTION_SKIP_CURRENT_EPISODE); + getInstrumentation().getTargetContext().sendBroadcast(skipIntent); + } + + private void startLocalPlayback() { + assertTrue(solo.waitForActivity(MainActivity.class)); + solo.setNavigationDrawer(Solo.CLOSED); + solo.clickOnView(solo.getView(R.id.butSecondaryAction)); + assertTrue(solo.waitForActivity(AudioplayerActivity.class)); + assertTrue(solo.waitForView(solo.getView(R.id.butPlay))); + } + + private void startLocalPlaybackFromQueue() { + assertTrue(solo.waitForActivity(MainActivity.class)); + solo.clickOnView(solo.getView(android.R.id.home)); + solo.clickOnText(solo.getString(R.string.queue_label)); + assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction))); + solo.clickOnImageButton(0); + assertTrue(solo.waitForActivity(AudioplayerActivity.class)); + assertTrue(solo.waitForView(solo.getView(R.id.butPlay))); + } + + public void testStartLocal() throws Exception { + uiTestUtils.addLocalFeedData(true); + DBWriter.clearQueue(getInstrumentation().getTargetContext()).get(); + startLocalPlayback(); + + solo.clickOnView(solo.getView(R.id.butPlay)); + } + + public void testContinousPlaybackOffSingleEpisode() throws Exception { + setContinuousPlaybackPreference(false); + uiTestUtils.addLocalFeedData(true); + DBWriter.clearQueue(getInstrumentation().getTargetContext()).get(); + startLocalPlayback(); + assertTrue(solo.waitForActivity(MainActivity.class)); + } + + + public void testContinousPlaybackOffMultipleEpisodes() throws Exception { + setContinuousPlaybackPreference(false); + uiTestUtils.addLocalFeedData(true); + List<FeedItem> queue = DBReader.getQueue(getInstrumentation().getTargetContext()); + FeedItem second = queue.get(1); + + startLocalPlaybackFromQueue(); + assertTrue(solo.waitForText(second.getTitle())); + } + + public void testContinuousPlaybackOnMultipleEpisodes() throws Exception { + setContinuousPlaybackPreference(true); + uiTestUtils.addLocalFeedData(true); + List<FeedItem> queue = DBReader.getQueue(getInstrumentation().getTargetContext()); + FeedItem second = queue.get(1); + + startLocalPlaybackFromQueue(); + assertTrue(solo.waitForText(second.getTitle())); + } + + /** + * Check if an episode can be played twice without problems. + */ + private void replayEpisodeCheck(boolean followQueue) throws Exception { + setContinuousPlaybackPreference(followQueue); + uiTestUtils.addLocalFeedData(true); + DBWriter.clearQueue(getInstrumentation().getTargetContext()).get(); + String title = ((TextView) solo.getView(R.id.txtvTitle)).getText().toString(); + startLocalPlayback(); + assertTrue(solo.waitForText(title)); + assertTrue(solo.waitForActivity(MainActivity.class)); + startLocalPlayback(); + assertTrue(solo.waitForText(title)); + assertTrue(solo.waitForActivity(MainActivity.class)); + } + + public void testReplayEpisodeContinuousPlaybackOn() throws Exception { + replayEpisodeCheck(true); + } + + public void testReplayEpisodeContinuousPlaybackOff() throws Exception { + replayEpisodeCheck(false); + } +} diff --git a/src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java b/src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java index 4d1ca093a..a02d4e55c 100644 --- a/src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java +++ b/src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java @@ -2,10 +2,7 @@ package instrumentationTest.de.test.antennapod.ui; import android.content.Context; import android.graphics.Bitmap; -import de.danoeh.antennapod.feed.Feed; -import de.danoeh.antennapod.feed.FeedImage; -import de.danoeh.antennapod.feed.FeedItem; -import de.danoeh.antennapod.feed.FeedMedia; +import de.danoeh.antennapod.feed.*; import de.danoeh.antennapod.storage.DBWriter; import de.danoeh.antennapod.storage.PodDBAdapter; import instrumentationTest.de.test.antennapod.util.service.download.HTTPBin; @@ -13,6 +10,7 @@ import instrumentationTest.de.test.antennapod.util.syndication.feedgenerator.RSS import junit.framework.Assert; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import java.io.File; import java.io.FileOutputStream; @@ -177,7 +175,8 @@ public class UITestUtils { for (FeedItem item : feed.getItems()) { if (item.hasMedia()) { FeedMedia media = item.getMedia(); - media.setFile_url(media.getDownload_url()); + int fileId = Integer.parseInt(StringUtils.substringAfter(media.getDownload_url(), "files/")); + media.setFile_url(server.accessFile(fileId).getAbsolutePath()); media.setDownloaded(true); } } @@ -189,5 +188,7 @@ public class UITestUtils { adapter.setCompleteFeed(hostedFeeds.toArray(new Feed[hostedFeeds.size()])); adapter.setQueue(queue); adapter.close(); + EventDistributor.getInstance().sendFeedUpdateBroadcast(); + EventDistributor.getInstance().sendQueueUpdateBroadcast(); } } diff --git a/src/instrumentationTest/de/test/antennapod/ui/UITestUtilsTest.java b/src/instrumentationTest/de/test/antennapod/ui/UITestUtilsTest.java index 9628c5522..88180152c 100644 --- a/src/instrumentationTest/de/test/antennapod/ui/UITestUtilsTest.java +++ b/src/instrumentationTest/de/test/antennapod/ui/UITestUtilsTest.java @@ -5,6 +5,7 @@ import de.danoeh.antennapod.feed.Feed; import de.danoeh.antennapod.feed.FeedItem; import org.apache.http.HttpStatus; +import java.io.File; import java.net.HttpURLConnection; import java.net.URL; import java.util.List; @@ -75,6 +76,8 @@ public class UITestUtilsTest extends InstrumentationTestCase { if (downloadEpisodes) { assertTrue(item.getMedia().isDownloaded()); assertNotNull(item.getMedia().getFile_url()); + File file = new File(item.getMedia().getFile_url()); + assertTrue(file.exists()); } } } diff --git a/src/instrumentationTest/de/test/antennapod/util/service/download/HTTPBin.java b/src/instrumentationTest/de/test/antennapod/util/service/download/HTTPBin.java index adde08ef0..fc5025b14 100644 --- a/src/instrumentationTest/de/test/antennapod/util/service/download/HTTPBin.java +++ b/src/instrumentationTest/de/test/antennapod/util/service/download/HTTPBin.java @@ -72,7 +72,7 @@ public class HTTPBin extends NanoHTTPD { } } - private synchronized File accessFile(int id) { + public synchronized File accessFile(int id) { if (id < 0 || id >= servedFiles.size()) { return null; } else { |