Skip to content

Commit

Permalink
feat(controls): add skip delay tests #392
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinPostindustria committed Apr 7, 2022
1 parent d12a22f commit 9c72950
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public void run() {
mCurrentTimerTaskHash = mCurrentTimerTask.hashCode();
}

private long getDuration(View view) {
protected long getDuration(View view) {
return (view instanceof BaseAdView) ? ((BaseAdView) view).getMediaDuration() : 0;
}

Expand Down Expand Up @@ -405,7 +405,7 @@ protected void setRemainingTimeInMs(int value) {
mRemainingTimeInMs = value;
}

private int getSkipDelayMs() {
protected int getSkipDelayMs() {
InterstitialDisplayPropertiesInternal properties = mInterstitialManager.getInterstitialDisplayProperties();
if (properties != null) {
long videoDuration = getDuration(mAdViewContainer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.prebid.mobile.reflection.Reflection;
import org.prebid.mobile.rendering.bidding.display.InterstitialView;
import org.prebid.mobile.rendering.models.AbstractCreative;
import org.prebid.mobile.rendering.models.InterstitialDisplayPropertiesInternal;
Expand Down Expand Up @@ -250,7 +251,7 @@ public void whenRemainingTimePresent_UseRemainingTime() throws Exception {
@Test
public void whenNoOffsetPresent_UseDefaultOffset() {
mSpyInterstitialVideo.scheduleShowCloseBtnTask(mMockAdView);
verify(mSpyInterstitialVideo).scheduleTimer(2L * 1000);
verify(mSpyInterstitialVideo).scheduleTimer(10L * 1000);
}

private void mockMediaDuration(long duration) {
Expand All @@ -260,4 +261,59 @@ private void mockMediaDuration(long duration) {
private void mockOffset(long value) {
when(mMockAdView.getMediaOffset()).thenReturn(value);
}

@Test
public void scheduleShowCloseBtnTask_TestDefaultUseSkipButton() {
mSpyInterstitialVideo.scheduleShowButtonTask();

assertFalse(getUseSkipButton());
}

@Test
public void scheduleShowCloseBtnTask_TestFalseUseSkipButton() {
mSpyInterstitialVideo.setHasEndCard(false);

mSpyInterstitialVideo.scheduleShowButtonTask();

assertFalse(getUseSkipButton());
}

@Test
public void scheduleShowCloseBtnTask_TestTrueUseSkipButton() {
mSpyInterstitialVideo.setHasEndCard(true);

mSpyInterstitialVideo.scheduleShowButtonTask();

assertTrue(getUseSkipButton());
}

private boolean getUseSkipButton() {
return (boolean) Reflection.getField(mSpyInterstitialVideo, "useSkipButton");
}


@Test
public void scheduleShowCloseBtnTask_VideoDurationLessThanSkipDelay_CallScheduleTimeWithVideoLength() {
int skipDelay = 10_000;
long videoDuration = 5_000;
when(mSpyInterstitialVideo.getDuration(any())).thenReturn(videoDuration);
when(mSpyInterstitialVideo.getSkipDelayMs()).thenReturn(skipDelay);

mSpyInterstitialVideo.scheduleShowButtonTask();

verify(mSpyInterstitialVideo).scheduleTimer(videoDuration);
}

@Test
public void scheduleShowCloseBtnTask_VideoDurationBiggerThanSkipDelay_CallScheduleTimeWithSkipDelayLength() {
int skipDelay = 5_000;
long videoDuration = 10_000;
when(mSpyInterstitialVideo.getDuration(any())).thenReturn(videoDuration);
when(mSpyInterstitialVideo.getSkipDelayMs()).thenReturn(skipDelay);

mSpyInterstitialVideo.scheduleShowButtonTask();

verify(mSpyInterstitialVideo).scheduleTimer(skipDelay);
}

}

0 comments on commit 9c72950

Please sign in to comment.