Updated PlaybackTest to deal with some spurious bugs.
Problem was that the PlaybackController wasn't having currentMedia get updated when playback initially starts. Working around it here by getting the real playback controller that's being used in the app. Still need to update PlaybackSonicTest.
This commit is contained in:
parent
a9b04cdf41
commit
83e56a334c
BIN
app/src/androidTest/assets/3sec.mp3
Normal file
BIN
app/src/androidTest/assets/3sec.mp3
Normal file
Binary file not shown.
@ -1,6 +1,5 @@
|
||||
package de.test.antennapod.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -8,7 +7,6 @@ import android.preference.PreferenceManager;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.FlakyTest;
|
||||
import android.view.View;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.robotium.solo.Solo;
|
||||
@ -26,8 +24,8 @@ import de.danoeh.antennapod.core.service.playback.PlayerStatus;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.core.storage.PodDBAdapter;
|
||||
import de.danoeh.antennapod.core.util.playback.Playable;
|
||||
import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||
import de.danoeh.antennapod.fragment.ExternalPlayerFragment;
|
||||
|
||||
/**
|
||||
* test cases for starting and ending playback from the MainActivity and AudioPlayerActivity
|
||||
@ -43,96 +41,13 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
||||
|
||||
private Context context;
|
||||
|
||||
private PlaybackController controller;
|
||||
protected FeedMedia currentMedia;
|
||||
private PlaybackController getPlaybackController() {
|
||||
ExternalPlayerFragment fragment = (ExternalPlayerFragment)getActivity().getSupportFragmentManager().findFragmentByTag(ExternalPlayerFragment.TAG);
|
||||
return fragment.getPlaybackControllerTestingOnly();
|
||||
}
|
||||
|
||||
private PlaybackController createController(Activity activity) {
|
||||
return new PlaybackController(activity, false) {
|
||||
|
||||
@Override
|
||||
public void setupGUI() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositionObserverUpdate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBufferStart() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBufferEnd() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBufferUpdate(float progress) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleError(int code) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReloadNotification(int code) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSleepTimerUpdate() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageButton getPlayButton() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postStatusMsg(int msg) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearStatusMsg() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean loadMediaInfo() {
|
||||
Playable playable = controller.getMedia();
|
||||
if(playable == null) {
|
||||
currentMedia = null;
|
||||
return true;
|
||||
} else if(playable instanceof FeedMedia) {
|
||||
currentMedia = (FeedMedia) playable;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAwaitingVideoSurface() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServiceQueried() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShutdownNotification() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackEnd() {
|
||||
currentMedia = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackSpeedChange() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setScreenOn(boolean enable) {
|
||||
}
|
||||
};
|
||||
private FeedMedia getCurrentMedia() {
|
||||
return (FeedMedia)getPlaybackController().getMedia();
|
||||
}
|
||||
|
||||
public PlaybackTest() {
|
||||
@ -154,9 +69,6 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
||||
.putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false)
|
||||
.commit();
|
||||
|
||||
controller = createController(getActivity());
|
||||
controller.init();
|
||||
|
||||
solo = new Solo(getInstrumentation(), getActivity());
|
||||
|
||||
uiTestUtils = new UITestUtils(context);
|
||||
@ -170,7 +82,6 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
controller.release();
|
||||
solo.finishOpenedActivities();
|
||||
uiTestUtils.tearDown();
|
||||
|
||||
@ -214,18 +125,17 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
||||
solo.clickOnView(solo.getView(R.id.butSecondaryAction));
|
||||
long mediaId = episodes.get(0).getMedia().getId();
|
||||
boolean playing = solo.waitForCondition(() -> {
|
||||
if (currentMedia != null) {
|
||||
return currentMedia.getId() == mediaId;
|
||||
if (getCurrentMedia() != null) {
|
||||
return getCurrentMedia().getId() == mediaId;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, Timeout.getSmallTimeout());
|
||||
}, Timeout.getLargeTimeout());
|
||||
assertTrue(playing);
|
||||
}
|
||||
|
||||
private void startLocalPlaybackFromQueue() {
|
||||
openNavDrawer();
|
||||
|
||||
// if we try to just click on plain old text then
|
||||
// we might wind up clicking on the fragment title and not
|
||||
// the drawer element like we want.
|
||||
@ -234,19 +144,19 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
||||
View targetView = drawerView.getChildAt(QUEUE_DRAWER_LIST_INDEX);
|
||||
solo.waitForView(targetView);
|
||||
solo.clickOnView(targetView);
|
||||
|
||||
assertTrue(solo.waitForView(solo.getView(R.id.butSecondaryAction)));
|
||||
final List<FeedItem> queue = DBReader.getQueue();
|
||||
solo.clickOnImageButton(1);
|
||||
assertTrue(solo.waitForView(solo.getView(R.id.butPlay)));
|
||||
long mediaId = queue.get(0).getMedia().getId();
|
||||
boolean playing = solo.waitForCondition(() -> {
|
||||
if(currentMedia != null) {
|
||||
return currentMedia.getId() == mediaId;
|
||||
if(getCurrentMedia() != null) {
|
||||
return getCurrentMedia().getId() == mediaId;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, Timeout.getSmallTimeout());
|
||||
}, Timeout.getLargeTimeout());
|
||||
|
||||
assertTrue(playing);
|
||||
}
|
||||
|
||||
@ -269,18 +179,21 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
||||
uiTestUtils.addLocalFeedData(true);
|
||||
List<FeedItem> queue = DBReader.getQueue();
|
||||
final FeedItem first = queue.get(0);
|
||||
|
||||
startLocalPlaybackFromQueue();
|
||||
boolean stopped = solo.waitForCondition(() -> {
|
||||
if (currentMedia != null) {
|
||||
return currentMedia.getId() != first.getMedia().getId();
|
||||
// the condition is met when playback ends and we're not playing
|
||||
// anything else. When playback ends, currentMedia is set to null.
|
||||
if (getPlaybackController().getStatus() != PlayerStatus.PLAYING) {
|
||||
return true;
|
||||
} else if (getCurrentMedia() != null) {
|
||||
return getCurrentMedia().getId() != first.getMedia().getId();
|
||||
} else {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}, Timeout.getSmallTimeout());
|
||||
}, Timeout.getLargeTimeout());
|
||||
assertTrue(stopped);
|
||||
Thread.sleep(1000);
|
||||
PlayerStatus status = controller.getStatus();
|
||||
PlayerStatus status = getPlaybackController().getStatus();
|
||||
assertFalse(status.equals(PlayerStatus.PLAYING));
|
||||
}
|
||||
|
||||
@ -294,16 +207,16 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
||||
|
||||
startLocalPlaybackFromQueue();
|
||||
boolean firstPlaying = solo.waitForCondition(() -> {
|
||||
if (currentMedia != null) {
|
||||
return currentMedia.getId() == first.getMedia().getId();
|
||||
if (getCurrentMedia() != null) {
|
||||
return getCurrentMedia().getId() == first.getMedia().getId();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, Timeout.getSmallTimeout());
|
||||
}, Timeout.getLargeTimeout());
|
||||
assertTrue(firstPlaying);
|
||||
boolean secondPlaying = solo.waitForCondition(() -> {
|
||||
if (currentMedia != null) {
|
||||
return currentMedia.getId() == second.getMedia().getId();
|
||||
if (getCurrentMedia() != null) {
|
||||
return getCurrentMedia().getId() == second.getMedia().getId();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@ -323,23 +236,23 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
||||
startLocalPlayback();
|
||||
long mediaId = episodes.get(0).getMedia().getId();
|
||||
boolean startedPlaying = solo.waitForCondition(() -> {
|
||||
if (currentMedia != null) {
|
||||
return currentMedia.getId() == mediaId;
|
||||
if (getCurrentMedia() != null) {
|
||||
return getCurrentMedia().getId() == mediaId;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}, Timeout.getSmallTimeout());
|
||||
}, Timeout.getLargeTimeout());
|
||||
assertTrue(startedPlaying);
|
||||
|
||||
boolean stoppedPlaying = solo.waitForCondition(() -> {
|
||||
return currentMedia == null || currentMedia.getId() != mediaId;
|
||||
return getCurrentMedia() == null || getCurrentMedia().getId() != mediaId;
|
||||
}, Timeout.getLargeTimeout());
|
||||
assertTrue(stoppedPlaying);
|
||||
|
||||
startLocalPlayback();
|
||||
boolean startedReplay = solo.waitForCondition(() -> {
|
||||
if(currentMedia != null) {
|
||||
return currentMedia.getId() == mediaId;
|
||||
if(getCurrentMedia() != null) {
|
||||
return getCurrentMedia().getId() == mediaId;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
@ -47,6 +47,7 @@ public class UITestUtils {
|
||||
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;
|
||||
public static final String TEST_FILE_NAME = "3sec.mp3";
|
||||
|
||||
|
||||
private Context context;
|
||||
@ -119,7 +120,7 @@ public class UITestUtils {
|
||||
}
|
||||
Assert.assertFalse(mediaFile.exists());
|
||||
|
||||
InputStream in = context.getAssets().open("testfile.mp3");
|
||||
InputStream in = context.getAssets().open(TEST_FILE_NAME);
|
||||
Assert.assertNotNull(in);
|
||||
|
||||
FileOutputStream out = new FileOutputStream(mediaFile);
|
||||
|
BIN
app/src/main/assets/3sec.mp3
Normal file
BIN
app/src/main/assets/3sec.mp3
Normal file
Binary file not shown.
@ -191,7 +191,7 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity
|
||||
}
|
||||
}
|
||||
externalPlayerFragment = new ExternalPlayerFragment();
|
||||
transaction.replace(R.id.playerFragment, externalPlayerFragment);
|
||||
transaction.replace(R.id.playerFragment, externalPlayerFragment, ExternalPlayerFragment.TAG);
|
||||
transaction.commit();
|
||||
|
||||
checkFirstLaunch();
|
||||
|
@ -26,7 +26,7 @@ import de.danoeh.antennapod.core.util.playback.PlaybackController;
|
||||
* if the PlaybackService is running
|
||||
*/
|
||||
public class ExternalPlayerFragment extends Fragment {
|
||||
private static final String TAG = "ExternalPlayerFragment";
|
||||
public static final String TAG = "ExternalPlayerFragment";
|
||||
|
||||
private ViewGroup fragmentLayout;
|
||||
private ImageView imgvCover;
|
||||
@ -230,4 +230,8 @@ public class ExternalPlayerFragment extends Fragment {
|
||||
return Converter.getDurationStringLong(position) + " / "
|
||||
+ Converter.getDurationStringLong(duration);
|
||||
}
|
||||
|
||||
public PlaybackController getPlaybackControllerTestingOnly() {
|
||||
return controller;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user