diff options
Diffstat (limited to 'src/instrumentationTest/de/test/antennapod/ui')
5 files changed, 0 insertions, 599 deletions
diff --git a/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java b/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java deleted file mode 100644 index 23fc224c8..000000000 --- a/src/instrumentationTest/de/test/antennapod/ui/MainActivityTest.java +++ /dev/null @@ -1,117 +0,0 @@ -package instrumentationTest.de.test.antennapod.ui; - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.res.Resources; -import android.test.ActivityInstrumentationTestCase2; -import android.view.View; -import com.robotium.solo.Solo; -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.activity.DefaultOnlineFeedViewActivity; -import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.activity.PreferenceActivity; -import de.danoeh.antennapod.feed.EventDistributor; -import de.danoeh.antennapod.feed.Feed; -import de.danoeh.antennapod.storage.PodDBAdapter; - -/** - * User interface tests for MainActivity - */ -public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> { - - private Solo solo; - private UITestUtils uiTestUtils; - - public MainActivityTest() { - super(MainActivity.class); - } - - @Override - protected 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(); - - // override first launch preference - SharedPreferences prefs = getInstrumentation().getTargetContext().getSharedPreferences(MainActivity.PREF_NAME, Context.MODE_PRIVATE); - prefs.edit().putBoolean(MainActivity.PREF_IS_FIRST_LAUNCH, false).commit(); - } - - @Override - protected void tearDown() throws Exception { - uiTestUtils.tearDown(); - solo.finishOpenedActivities(); - PodDBAdapter.deleteDatabase(getInstrumentation().getTargetContext()); - super.tearDown(); - } - - public void testAddFeed() throws Exception { - uiTestUtils.addHostedFeedData(); - final Feed feed = uiTestUtils.hostedFeeds.get(0); - solo.setNavigationDrawer(Solo.OPENED); - solo.clickOnText(solo.getString(R.string.add_feed_label)); - solo.enterText(0, feed.getDownload_url()); - solo.clickOnButton(0); - solo.waitForActivity(DefaultOnlineFeedViewActivity.class); - solo.waitForView(R.id.butSubscribe); - assertEquals(solo.getString(R.string.subscribe_label), solo.getButton(0).getText().toString()); - solo.clickOnButton(0); - solo.waitForText(solo.getString(R.string.subscribed_label)); - } - - public void testClickNavDrawer() throws Exception { - uiTestUtils.addLocalFeedData(false); - final View home = solo.getView(UITestUtils.HOME_VIEW); - - // all episodes - solo.waitForView(android.R.id.list); - assertEquals(solo.getString(R.string.all_episodes_label), getActionbarTitle()); - // queue - solo.clickOnView(home); - solo.clickOnText(solo.getString(R.string.queue_label)); - solo.waitForView(android.R.id.list); - assertEquals(solo.getString(R.string.queue_label), getActionbarTitle()); - - // downloads - solo.clickOnView(home); - solo.clickOnText(solo.getString(R.string.downloads_label)); - solo.waitForView(android.R.id.list); - assertEquals(solo.getString(R.string.downloads_label), getActionbarTitle()); - - // playback history - solo.clickOnView(home); - solo.clickOnText(solo.getString(R.string.playback_history_label)); - solo.waitForView(android.R.id.list); - assertEquals(solo.getString(R.string.playback_history_label), getActionbarTitle()); - - // add podcast - solo.clickOnView(home); - solo.clickOnText(solo.getString(R.string.add_feed_label)); - solo.waitForView(R.id.txtvFeedurl); - assertEquals(solo.getString(R.string.add_feed_label), getActionbarTitle()); - - // podcasts - for (int i = 0; i < uiTestUtils.hostedFeeds.size(); i++) { - Feed f = uiTestUtils.hostedFeeds.get(i); - solo.clickOnView(home); - solo.clickOnText(f.getTitle()); - solo.waitForView(android.R.id.list); - assertEquals("", getActionbarTitle()); - } - } - - private String getActionbarTitle() { - return ((MainActivity)solo.getCurrentActivity()).getMainActivtyActionBar().getTitle().toString(); - } - - public void testGoToPreferences() { - solo.setNavigationDrawer(Solo.CLOSED); - solo.clickOnMenuItem(solo.getString(R.string.settings_label)); - solo.waitForActivity(PreferenceActivity.class); - } -} diff --git a/src/instrumentationTest/de/test/antennapod/ui/PlaybackTest.java b/src/instrumentationTest/de/test/antennapod/ui/PlaybackTest.java deleted file mode 100644 index 98d93a35d..000000000 --- a/src/instrumentationTest/de/test/antennapod/ui/PlaybackTest.java +++ /dev/null @@ -1,149 +0,0 @@ -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(UITestUtils.HOME_VIEW)); - 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 deleted file mode 100644 index 8877d46d6..000000000 --- a/src/instrumentationTest/de/test/antennapod/ui/UITestUtils.java +++ /dev/null @@ -1,201 +0,0 @@ -package instrumentationTest.de.test.antennapod.ui; - -import android.annotation.TargetApi; -import android.content.Context; -import android.graphics.Bitmap; -import android.os.Build; - -import de.danoeh.antennapod.R; -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; -import instrumentationTest.de.test.antennapod.util.syndication.feedgenerator.RSS2Generator; -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; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * Utility methods for UI tests. - * Starts a web server that hosts feeds, episodes and images. - */ -@TargetApi(Build.VERSION_CODES.HONEYCOMB) -public class UITestUtils { - - private static final String DATA_FOLDER = "test/UITestUtils"; - - public static final int NUM_FEEDS = 5; - public static final int NUM_ITEMS_PER_FEED = 10; - - public static final int HOME_VIEW = (Build.VERSION.SDK_INT >= 11) ? android.R.id.home : R.id.home; - - - private Context context; - private HTTPBin server = new HTTPBin(); - private File destDir; - private File hostedFeedDir; - private File hostedMediaDir; - - public List<Feed> hostedFeeds = new ArrayList<Feed>(); - - public UITestUtils(Context context) { - this.context = context; - } - - - public void setup() throws IOException { - destDir = context.getExternalFilesDir(DATA_FOLDER); - destDir.mkdir(); - hostedFeedDir = new File(destDir, "hostedFeeds"); - hostedFeedDir.mkdir(); - hostedMediaDir = new File(destDir, "hostedMediaDir"); - hostedMediaDir.mkdir(); - Assert.assertTrue(destDir.exists()); - Assert.assertTrue(hostedFeedDir.exists()); - Assert.assertTrue(hostedMediaDir.exists()); - server.start(); - } - - public void tearDown() throws IOException { - FileUtils.deleteDirectory(destDir); - FileUtils.deleteDirectory(hostedMediaDir); - FileUtils.deleteDirectory(hostedFeedDir); - server.stop(); - - if (localFeedDataAdded) { - PodDBAdapter.deleteDatabase(context); - } - } - - private String hostFeed(Feed feed) throws IOException { - File feedFile = new File(hostedFeedDir, feed.getTitle()); - FileOutputStream out = new FileOutputStream(feedFile); - RSS2Generator generator = new RSS2Generator(); - generator.writeFeed(feed, out, "UTF-8", 0); - out.close(); - int id = server.serveFile(feedFile); - Assert.assertTrue(id != -1); - return String.format("%s/files/%d", HTTPBin.BASE_URL, id); - } - - private String hostFile(File file) { - int id = server.serveFile(file); - Assert.assertTrue(id != -1); - return String.format("%s/files/%d", HTTPBin.BASE_URL, id); - } - - private File newBitmapFile(String name) throws IOException { - File imgFile = new File(destDir, name); - Bitmap bitmap = Bitmap.createBitmap(128, 128, Bitmap.Config.ARGB_8888); - FileOutputStream out = new FileOutputStream(imgFile); - bitmap.compress(Bitmap.CompressFormat.PNG, 1, out); - out.close(); - return imgFile; - } - - private File newMediaFile(String name) throws IOException { - File mediaFile = new File(hostedMediaDir, name); - Assert.assertFalse(mediaFile.exists()); - - InputStream in = context.getAssets().open("testfile.mp3"); - Assert.assertNotNull(in); - - FileOutputStream out = new FileOutputStream(mediaFile); - IOUtils.copy(in, out); - out.close(); - - return mediaFile; - } - - private boolean feedDataHosted = false; - - /** - * Adds feeds, images and episodes to the webserver for testing purposes. - */ - public void addHostedFeedData() throws IOException { - if (feedDataHosted) throw new IllegalStateException("addHostedFeedData was called twice on the same instance"); - for (int i = 0; i < NUM_FEEDS; i++) { - File bitmapFile = newBitmapFile("image" + i); - FeedImage image = new FeedImage(0, "image " + i, null, hostFile(bitmapFile), false); - Feed feed = new Feed(0, new Date(), "Title " + i, "http://example.com/" + i, "Description of feed " + i, - "http://example.com/pay/feed" + i, "author " + i, "en", Feed.TYPE_RSS2, "feed" + i, image, null, - "http://example.com/feed/src/" + i, false); - image.setOwner(feed); - - // create items - List<FeedItem> items = new ArrayList<FeedItem>(); - for (int j = 0; j < NUM_ITEMS_PER_FEED; j++) { - FeedItem item = new FeedItem(0, "item" + j, "item" + j, "http://example.com/feed" + i + "/item/" + j, new Date(), true, feed); - items.add(item); - - File mediaFile = newMediaFile("feed-" + i + "-episode-" + j + ".mp3"); - item.setMedia(new FeedMedia(0, item, 0, 0, mediaFile.length(), "audio/mp3", null, hostFile(mediaFile), false, null, 0)); - - } - feed.setItems(items); - feed.setDownload_url(hostFeed(feed)); - hostedFeeds.add(feed); - } - feedDataHosted = true; - } - - - private boolean localFeedDataAdded = false; - - /** - * Adds feeds, images and episodes to the local database. This method will also call addHostedFeedData if it has not - * been called yet. - * - * Adds one item of each feed to the queue and to the playback history. - * - * This method should NOT be called if the testing class wants to download the hosted feed data. - * - * @param downloadEpisodes true if episodes should also be marked as downloaded. - */ - public void addLocalFeedData(boolean downloadEpisodes) throws Exception { - if (localFeedDataAdded) throw new IllegalStateException("addLocalFeedData was called twice on the same instance"); - if (!feedDataHosted) { - addHostedFeedData(); - } - - List<FeedItem> queue = new ArrayList<FeedItem>(); - - PodDBAdapter adapter = new PodDBAdapter(context); - adapter.open(); - for (Feed feed : hostedFeeds) { - feed.setDownloaded(true); - if (feed.getImage() != null) { - FeedImage image = feed.getImage(); - image.setFile_url(image.getDownload_url()); - image.setDownloaded(true); - } - if (downloadEpisodes) { - for (FeedItem item : feed.getItems()) { - if (item.hasMedia()) { - FeedMedia media = item.getMedia(); - int fileId = Integer.parseInt(StringUtils.substringAfter(media.getDownload_url(), "files/")); - media.setFile_url(server.accessFile(fileId).getAbsolutePath()); - media.setDownloaded(true); - } - } - } - - queue.add(feed.getItems().get(0)); - feed.getItems().get(1).getMedia().setPlaybackCompletionDate(new Date()); - } - 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 deleted file mode 100644 index 88180152c..000000000 --- a/src/instrumentationTest/de/test/antennapod/ui/UITestUtilsTest.java +++ /dev/null @@ -1,94 +0,0 @@ -package instrumentationTest.de.test.antennapod.ui; - -import android.test.InstrumentationTestCase; -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; - -/** - * Test for the UITestUtils. Makes sure that all URLs are reachable and that the class does not cause any crashes. - */ -public class UITestUtilsTest extends InstrumentationTestCase { - - private UITestUtils uiTestUtils; - - @Override - protected void setUp() throws Exception { - super.setUp(); - uiTestUtils = new UITestUtils(getInstrumentation().getTargetContext()); - uiTestUtils.setup(); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - uiTestUtils.tearDown(); - } - - public void testAddHostedFeeds() throws Exception { - uiTestUtils.addHostedFeedData(); - final List<Feed> feeds = uiTestUtils.hostedFeeds; - assertNotNull(feeds); - assertFalse(feeds.isEmpty()); - - for (Feed feed : feeds) { - testUrlReachable(feed.getDownload_url()); - if (feed.getImage() != null) { - testUrlReachable(feed.getImage().getDownload_url()); - } - for (FeedItem item : feed.getItems()) { - if (item.hasMedia()) { - testUrlReachable(item.getMedia().getDownload_url()); - } - } - } - } - - private void testUrlReachable(String strUtl) throws Exception { - URL url = new URL(strUtl); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("GET"); - conn.connect(); - int rc = conn.getResponseCode(); - assertEquals(HttpStatus.SC_OK, rc); - conn.disconnect(); - } - - private void addLocalFeedDataCheck(boolean downloadEpisodes) throws Exception { - uiTestUtils.addLocalFeedData(downloadEpisodes); - assertNotNull(uiTestUtils.hostedFeeds); - assertFalse(uiTestUtils.hostedFeeds.isEmpty()); - - for (Feed feed : uiTestUtils.hostedFeeds) { - assertTrue(feed.getId() != 0); - if (feed.getImage() != null) { - assertTrue(feed.getImage().getId() != 0); - } - for (FeedItem item : feed.getItems()) { - assertTrue(item.getId() != 0); - if (item.hasMedia()) { - assertTrue(item.getMedia().getId() != 0); - if (downloadEpisodes) { - assertTrue(item.getMedia().isDownloaded()); - assertNotNull(item.getMedia().getFile_url()); - File file = new File(item.getMedia().getFile_url()); - assertTrue(file.exists()); - } - } - } - } - } - - public void testAddLocalFeedDataNoDownload() throws Exception { - addLocalFeedDataCheck(false); - } - - public void testAddLocalFeedDataDownload() throws Exception { - addLocalFeedDataCheck(true); - } -} diff --git a/src/instrumentationTest/de/test/antennapod/ui/VideoplayerActivityTest.java b/src/instrumentationTest/de/test/antennapod/ui/VideoplayerActivityTest.java deleted file mode 100644 index 807552571..000000000 --- a/src/instrumentationTest/de/test/antennapod/ui/VideoplayerActivityTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package instrumentationTest.de.test.antennapod.ui; - -import android.test.ActivityInstrumentationTestCase2; - -import com.robotium.solo.Solo; - -import de.danoeh.antennapod.activity.VideoplayerActivity; - -/** - * Test class for VideoplayerActivity - */ -public class VideoplayerActivityTest extends ActivityInstrumentationTestCase2<VideoplayerActivity> { - - private Solo solo; - - public VideoplayerActivityTest() { - super(VideoplayerActivity.class); - } - - @Override - public void setUp() throws Exception { - super.setUp(); - solo = new Solo(getInstrumentation(), getActivity()); - } - - @Override - public void tearDown() throws Exception { - solo.finishOpenedActivities(); - super.tearDown(); - } - - /** - * Test if activity can be started. - */ - public void testStartActivity() throws Exception { - solo.waitForActivity(VideoplayerActivity.class); - } -} |