mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-02-02 11:46:55 +01:00
Added test cases for starting playback
This commit is contained in:
parent
c4e0078382
commit
c3e0ac9e74
@ -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);
|
||||
|
||||
|
149
src/instrumentationTest/de/test/antennapod/ui/PlaybackTest.java
Normal file
149
src/instrumentationTest/de/test/antennapod/ui/PlaybackTest.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user