diff options
Diffstat (limited to 'library/test')
-rw-r--r-- | library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java | 31 | ||||
-rw-r--r-- | library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java | 29 |
2 files changed, 60 insertions, 0 deletions
diff --git a/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java b/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java index 2ef2b7d..7bcefd0 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java +++ b/library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java @@ -34,6 +34,15 @@ import java.util.Map; @Implements(MediaPlayer.class) public class ShadowMediaPlayer extends org.robolectric.shadows.ShadowMediaPlayer { + private int mVideoWidth; + private int mVideoHeight; + + public ShadowMediaPlayer() { + super(); + mVideoWidth = -1; + mVideoHeight = -1; + } + @Implementation public void setDataSource( @NonNull Context context, @@ -48,4 +57,26 @@ public class ShadowMediaPlayer extends org.robolectric.shadows.ShadowMediaPlayer public void seekTo(long msec, int mode) { seekTo((int) msec); } + + public void setVideoSize(int width, int height) { + if (width < 0) { + throw new IllegalArgumentException("Unexpected negative width=" + width); + } + if (height < 0) { + throw new IllegalArgumentException("Unexpected negative height=" + height); + } + + mVideoWidth = width; + mVideoHeight = height; + } + + @Override + public int getVideoWidth() { + return mVideoWidth; + } + + @Override + public int getVideoHeight() { + return mVideoHeight; + } } diff --git a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java index c09e22f..a39ffb9 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java @@ -161,6 +161,35 @@ public class IllustrationVideoViewTest { + android.R.color.black); } + @Test + public void prepareVideo_shouldSetAspectRatio() { + createDefaultView(); + + mShadowMediaPlayer.setVideoSize(720, 1280); + + Robolectric.flushForegroundThreadScheduler(); + mView.start(); + + mView.measure(View.MeasureSpec.makeMeasureSpec(720, View.MeasureSpec.EXACTLY), + View.MeasureSpec.makeMeasureSpec(720, View.MeasureSpec.EXACTLY)); + + final float aspectRatio = (float) mView.getMeasuredHeight() / mView.getMeasuredWidth(); + assertThat(aspectRatio).isWithin(0.001f).of(1280f / 720f); + } + + @Test + public void prepareVideo_zeroHeight_shouldSetAspectRatioToZero() { + createDefaultView(); + + mShadowMediaPlayer.setVideoSize(720, 0); + + Robolectric.flushForegroundThreadScheduler(); + mView.start(); + + final float aspectRatio = (float) mView.getHeight() / mView.getWidth(); + assertThat(aspectRatio).isEqualTo(0.0f); + } + private void createDefaultView() { mView = new IllustrationVideoView( application, |