use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.
the class CreativeVisibilityTrackerTest method visibilityRunnable_runWithViewVisibleForAtLeastMinDuration_CallOnVisibilityChanged_ImpTrackerFiredTrue_IsVisibilityScheduledFalse.
// VisibilityRunnable Tests
@Test
public void visibilityRunnable_runWithViewVisibleForAtLeastMinDuration_CallOnVisibilityChanged_ImpTrackerFiredTrue_IsVisibilityScheduledFalse() throws Exception {
ViewExposure viewExposure = new ViewExposure(100, new Rect(0, 0, 100, 100), null);
when(mSpyVisibilityChecker.isVisible(any(View.class))).thenReturn(true);
when(mSpyVisibilityChecker.checkViewExposure(any(View.class))).thenReturn(viewExposure);
when(mSpyVisibilityChecker.hasBeenVisible()).thenReturn(true);
when(mSpyVisibilityChecker.hasRequiredTimeElapsed()).thenReturn(true);
mCreativeVisibilityTracker.mVisibilityRunnable.run();
VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
verify(mMockVisibilityTrackerListener).onVisibilityChanged(result);
final VisibilityTrackerOption visibilityTrackerOption = mSpyVisibilityChecker.getVisibilityTrackerOption();
assertTrue(visibilityTrackerOption.isImpressionTracked());
assertFalse((Boolean) getFieldValue("mIsVisibilityScheduled"));
}
use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.
the class CreativeVisibilityTrackerTest method visibilityRunnable_runWithMultipleTrackingOptions_CallOnVisibilityChangedIndependently_NoTrackForVideo.
@Test
public void visibilityRunnable_runWithMultipleTrackingOptions_CallOnVisibilityChangedIndependently_NoTrackForVideo() {
mockView();
VisibilityTrackerOption trackerOptionImpression = new VisibilityTrackerOption(NativeEventTracker.EventType.IMPRESSION);
VisibilityTrackerOption trackerOptionMrc50 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC50);
VisibilityTrackerOption trackerOptionMrc100 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_MRC100);
VisibilityTrackerOption trackerOptionViewableVideo50 = new VisibilityTrackerOption(NativeEventTracker.EventType.VIEWABLE_VIDEO50);
final ViewExposure viewExposure = new ViewExposure(1.0f, new Rect(), new ArrayList<>());
Set<VisibilityTrackerOption> visibilityTrackerOptionSet = new HashSet<>();
visibilityTrackerOptionSet.add(trackerOptionImpression);
visibilityTrackerOptionSet.add(trackerOptionMrc50);
visibilityTrackerOptionSet.add(trackerOptionMrc100);
visibilityTrackerOptionSet.add(trackerOptionViewableVideo50);
CreativeVisibilityTracker creativeVisibilityTracker = new CreativeVisibilityTracker(mMockView, visibilityTrackerOptionSet);
creativeVisibilityTracker.setVisibilityTrackerListener(mMockVisibilityTrackerListener);
mockVisibilityChecker(creativeVisibilityTracker, viewExposure, visibilityTrackerOptionSet);
creativeVisibilityTracker.mVisibilityRunnable.run();
// 0 sec visibility duration
assertTrue(trackerOptionImpression.isImpressionTracked());
ShadowSystemClock.advanceBy(Duration.ofMillis(1000));
// 1 sec visibility duration
assertTrue(trackerOptionMrc50.isImpressionTracked());
assertTrue(trackerOptionMrc100.isImpressionTracked());
// 2 sec visibility duration
assertFalse(trackerOptionViewableVideo50.isImpressionTracked());
VisibilityTrackerResult impressionResult = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
VisibilityTrackerResult mrc50Result = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_MRC50, viewExposure, true, true);
VisibilityTrackerResult mrc100Result = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_MRC100, viewExposure, true, true);
VisibilityTrackerResult videoResult = new VisibilityTrackerResult(NativeEventTracker.EventType.VIEWABLE_VIDEO50, viewExposure, true, true);
verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(impressionResult));
verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(mrc50Result));
verify(mMockVisibilityTrackerListener, times(1)).onVisibilityChanged(eq(mrc100Result));
verify(mMockVisibilityTrackerListener, times(0)).onVisibilityChanged(eq(videoResult));
}
use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.
the class HTMLCreativeTest method viewabilityTrackListenerExecutionIsViewable_trackImpression.
@Test
public void viewabilityTrackListenerExecutionIsViewable_trackImpression() {
ViewExposure viewExposure = new ViewExposure();
PrebidWebViewBase mockPrebidWebViewBase = mock(PrebidWebViewBase.class);
when(mockPrebidWebViewBase.getWebView()).thenReturn(mock(WebViewBase.class));
mHtmlCreative.setCreativeView(mockPrebidWebViewBase);
VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, viewExposure, true, true);
mHtmlCreative.onVisibilityEvent(result);
verify(mMockModel, times(1)).trackDisplayAdEvent(TrackingEvent.Events.IMPRESSION);
verify(mockPrebidWebViewBase, times(1)).onWindowFocusChanged(true);
verify(mockPrebidWebViewBase, times(1)).onViewExposureChange(viewExposure);
}
use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.
the class VideoViewTest method handleVisibilityChange_visible_validPlayState_ExecutePlay.
@Test
public void handleVisibilityChange_visible_validPlayState_ExecutePlay() {
changeVideoViewState(PLAYBACK_NOT_STARTED);
VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, new ViewExposure(), true, true);
mVisibilityTrackerListener.onVisibilityChanged(result);
verify(mMockAdViewManager).show();
assertEquals(PLAYING, getVideoViewState());
}
use of org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult in project prebid-mobile-android by prebid.
the class HTMLCreativeTest method viewabilityTrackListenerExecution_TrackOnWindowFocusChangeAndOnViewExposureChange.
@Test
public void viewabilityTrackListenerExecution_TrackOnWindowFocusChangeAndOnViewExposureChange() throws Exception {
PrebidWebViewBase mockPrebidWebViewBase = mock(PrebidWebViewBase.class);
when(mockPrebidWebViewBase.getWebView()).thenReturn(mock(WebViewBase.class));
mHtmlCreative.setCreativeView(mockPrebidWebViewBase);
VisibilityTrackerResult result = new VisibilityTrackerResult(NativeEventTracker.EventType.IMPRESSION, null, false, false);
doAnswer(invocation -> {
CreativeVisibilityTracker.VisibilityTrackerListener listener = invocation.getArgument(0);
listener.onVisibilityChanged(result);
return null;
}).when(mMockCreativeVisibilityTracker).setVisibilityTrackerListener(any(CreativeVisibilityTracker.VisibilityTrackerListener.class));
mHtmlCreative.onVisibilityEvent(result);
verify(mMockModel, never()).trackDisplayAdEvent(TrackingEvent.Events.IMPRESSION);
verify(mockPrebidWebViewBase, times(1)).onWindowFocusChanged(false);
verify(mockPrebidWebViewBase, times(1)).onViewExposureChange(null);
}
Aggregations