summaryrefslogtreecommitdiff
path: root/library/test/robotest
diff options
context:
space:
mode:
authorCyril Lee <cyrillee@google.com>2018-06-20 18:52:05 +0800
committerCyril Lee <cyrillee@google.com>2018-06-25 11:08:53 +0800
commite4d2a1d06a1aac5c71729f51834f5a9952120b3f (patch)
tree514d1c54661f11d42bf6c78894cc9d1c421eb8c6 /library/test/robotest
parent7c8910c4e435fe36f70a3a610491cd7d49c9d45d (diff)
downloadsetupwizard-e4d2a1d06a1aac5c71729f51834f5a9952120b3f.tar.gz
Fix video view without updates aspect ratio
The IllustrationVideoView should update size of view when new aspectRatio is different from current. Bug: 110098506 Test: "./gradlew test" on folder of ub-setupwizard-master branch Change-Id: I5a4663fa0949a285966be923f183c9f24c4a709c
Diffstat (limited to 'library/test/robotest')
-rw-r--r--library/test/robotest/src/com/android/setupwizardlib/shadow/ShadowMediaPlayer.java31
-rw-r--r--library/test/robotest/src/com/android/setupwizardlib/view/IllustrationVideoViewTest.java29
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,