Search in sources :

Example 1 with ViewExposure

use of org.prebid.mobile.rendering.utils.exposure.ViewExposure in project prebid-mobile-android by prebid.

the class HTMLCreative method onVisibilityEvent.

@VisibleForTesting
void onVisibilityEvent(VisibilityTrackerResult result) {
    boolean isViewable = result.isVisible();
    boolean shouldFireImpression = result.shouldFireImpression();
    ViewExposure viewExposure = result.getViewExposure();
    if (shouldFireImpression && isViewable) {
        LogUtil.debug(TAG, "Impression fired");
        getCreativeModel().trackDisplayAdEvent(TrackingEvent.Events.IMPRESSION);
    }
    getCreativeView().onWindowFocusChanged(isViewable);
    getCreativeView().onViewExposureChange(viewExposure);
}
Also used : ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 2 with ViewExposure

use of org.prebid.mobile.rendering.utils.exposure.ViewExposure 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"));
}
Also used : Rect(android.graphics.Rect) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) View(android.view.View) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) Test(org.junit.Test)

Example 3 with ViewExposure

use of org.prebid.mobile.rendering.utils.exposure.ViewExposure 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));
}
Also used : Rect(android.graphics.Rect) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) VisibilityTrackerOption(org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with ViewExposure

use of org.prebid.mobile.rendering.utils.exposure.ViewExposure 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);
}
Also used : PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) WebViewBase(org.prebid.mobile.rendering.views.webview.WebViewBase) PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) Test(org.junit.Test)

Example 5 with ViewExposure

use of org.prebid.mobile.rendering.utils.exposure.ViewExposure 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());
}
Also used : VisibilityTrackerResult(org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult) ViewExposure(org.prebid.mobile.rendering.utils.exposure.ViewExposure) Test(org.junit.Test)

Aggregations

ViewExposure (org.prebid.mobile.rendering.utils.exposure.ViewExposure)8 Test (org.junit.Test)6 VisibilityTrackerResult (org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult)5 VisibilityTrackerOption (org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption)3 Rect (android.graphics.Rect)2 View (android.view.View)2 VisibleForTesting (androidx.annotation.VisibleForTesting)1 HashSet (java.util.HashSet)1 PrebidWebViewBase (org.prebid.mobile.rendering.views.webview.PrebidWebViewBase)1 WebViewBase (org.prebid.mobile.rendering.views.webview.WebViewBase)1