Search in sources :

Example 1 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class HTMLCreative method display.

@Override
public void display() {
    if (!(getCreativeView() instanceof PrebidWebViewBase)) {
        LogUtil.error(TAG, "Could not cast mCreativeView to a PrebidWebViewBase");
        return;
    }
    PrebidWebViewBase creativeWebView = (PrebidWebViewBase) getCreativeView();
    // Fire impression
    startViewabilityTracker();
}
Also used : PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase)

Example 2 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class TwoPartExpandRunnable method run.

// NOTE: handleMRAIDEventsInCreative ACTION_EXPAND is invoked from a background thread.
// This means the webview instantiation should be performed from a UI thread.
@Override
public void run() {
    HTMLCreative htmlCreative = mWeakHtmlCreative.get();
    if (htmlCreative == null) {
        LogUtil.error(TAG, "HTMLCreative object is null");
        return;
    }
    PrebidWebViewBase prebidWebViewBanner = new PrebidWebViewBanner(mOldWebViewBase.getContext(), mMraidController.mInterstitialManager);
    // inject mraid.js & load url here, for 2part expand
    prebidWebViewBanner.setOldWebView(mOldWebViewBase);
    prebidWebViewBanner.initTwoPartAndLoad(mMraidEvent.mraidActionHelper);
    prebidWebViewBanner.setWebViewDelegate(htmlCreative);
    prebidWebViewBanner.setCreative(htmlCreative);
    // Set a view before handling any action.
    htmlCreative.setCreativeView(prebidWebViewBanner);
    htmlCreative.setTwoPartNewWebViewBase(prebidWebViewBanner);
    mMraidController.expand(mOldWebViewBase, prebidWebViewBanner, mMraidEvent);
}
Also used : PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) PrebidWebViewBanner(org.prebid.mobile.rendering.views.webview.PrebidWebViewBanner) HTMLCreative(org.prebid.mobile.rendering.models.HTMLCreative)

Example 3 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class MraidControllerTest method delegateDisplayViewInInterstitialAndExpandNotNull_SetExpandDisplayViewAndInitMraidExpanded.

@Test
public void delegateDisplayViewInInterstitialAndExpandNotNull_SetExpandDisplayViewAndInitMraidExpanded() throws IllegalAccessException {
    mMraidController = new MraidController(mMockInterstitialManager);
    WebViewBase mockWebView = mock(WebViewBase.class);
    MraidEvent mockEvent = mock(MraidEvent.class);
    MraidExpand mockMraidExpand = mock(MraidExpand.class);
    PrebidWebViewBase mockWebViewBase = mock(PrebidWebViewBase.class);
    mockEvent.mraidAction = JSInterface.ACTION_EXPAND;
    mockEvent.mraidActionHelper = "test";
    when(mockMraidExpand.getInterstitialViewController()).thenReturn(mock(AdBaseDialog.class));
    when(mockWebView.getPreloadedListener()).thenReturn(mockWebViewBase);
    WhiteBox.field(MraidController.class, "mMraidExpand").set(mMraidController, mockMraidExpand);
    getMraidDelegate().displayPrebidWebViewForMraid(mockWebView, true, mockEvent);
    verify(mockMraidExpand, times(1)).setDisplayView(mockWebView);
    verify(mockWebViewBase).initMraidExpanded();
}
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) AdBaseDialog(org.prebid.mobile.rendering.interstitial.AdBaseDialog) MraidEvent(org.prebid.mobile.rendering.models.internal.MraidEvent) Test(org.junit.Test)

Example 4 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class MraidExpandTest method expandTest.

@Test
public void expandTest() {
    doAnswer(invocation -> {
        RedirectUrlListener listener = invocation.getArgument(1);
        listener.onSuccess("test", "html");
        return null;
    }).when(mSpyBaseJsInterface).followToOriginalUrl(anyString(), any(RedirectUrlListener.class));
    PrebidWebViewBase mockPreloadedListener = mock(PrebidWebViewBase.class);
    HTMLCreative mockCreative = mock(HTMLCreative.class);
    when(mockPreloadedListener.getCreative()).thenReturn(mockCreative);
    when(mMockWebViewBase.getPreloadedListener()).thenReturn(mockPreloadedListener);
    CompletedCallBack callBack = mock(CompletedCallBack.class);
    final MraidVariableContainer mraidVariableContainer = mSpyBaseJsInterface.getMraidVariableContainer();
    mraidVariableContainer.setCurrentState(JSInterface.STATE_DEFAULT);
    MraidExpand spyExpand = spy(mMraidExpand);
    doAnswer(invocation -> {
        CompletedCallBack completedCallBack = invocation.getArgument(1);
        completedCallBack.expandDialogShown();
        return null;
    }).when(spyExpand).showExpandDialog(any(), any());
    spyExpand.expand("test", callBack);
    verify(mSpyBaseJsInterface).followToOriginalUrl(anyString(), any(RedirectUrlListener.class));
    assertEquals(mraidVariableContainer.getUrlForLaunching(), "test");
    verify(callBack).expandDialogShown();
    verify(spyExpand).showExpandDialog(any(), any());
}
Also used : PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) MraidVariableContainer(org.prebid.mobile.rendering.models.internal.MraidVariableContainer) RedirectUrlListener(org.prebid.mobile.rendering.mraid.methods.network.RedirectUrlListener) HTMLCreative(org.prebid.mobile.rendering.models.HTMLCreative) Test(org.junit.Test)

Example 5 with PrebidWebViewBase

use of org.prebid.mobile.rendering.views.webview.PrebidWebViewBase in project prebid-mobile-android by prebid.

the class MraidResizeTest method showExpandDialogTest.

@Test
public void showExpandDialogTest() throws InvocationTargetException, IllegalAccessException {
    Method showExpandDialogMethod = WhiteBox.method(MraidResize.class, "showExpandDialog", int.class, int.class, int.class, int.class, boolean.class);
    Field secondaryAdContainerField = WhiteBox.field(MraidResize.class, "mSecondaryAdContainer");
    secondaryAdContainerField.set(mMraidResize, mock(FrameLayout.class));
    Field closeViewField = WhiteBox.field(MraidResize.class, "mCloseView");
    View mockView = mock(View.class);
    when(mockView.getLayoutParams()).thenReturn(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    closeViewField.set(mMraidResize, mockView);
    MraidScreenMetrics mockMetrics = mock(MraidScreenMetrics.class);
    when(mockMetrics.getRootViewRect()).thenReturn(new Rect(0, 0, 100, 100));
    when(mockMetrics.getDefaultAdRect()).thenReturn(new Rect(0, 0, 0, 0));
    when(mockMetrics.getRootViewRectDips()).thenReturn(new Rect(0, 0, 0, 0));
    when(mSpyBaseJsInterface.getScreenMetrics()).thenReturn(mockMetrics);
    PrebidWebViewBase mockPrebidWebViewBase = mock(PrebidWebViewBase.class);
    when(mMockWebViewBase.getParent()).thenReturn(mockPrebidWebViewBase);
    when(mSpyBaseJsInterface.getDefaultAdContainer()).thenReturn(mockPrebidWebViewBase);
    when(mSpyBaseJsInterface.getRootView()).thenReturn(mock(FrameLayout.class));
    showExpandDialogMethod.invoke(mMraidResize, 100, 100, 0, 0, true);
    verify(mSpyBaseJsInterface).onStateChange(eq(JSInterface.STATE_RESIZED));
    showExpandDialogMethod.invoke(mMraidResize, 1000, 1000, 0, 0, false);
    verify(mSpyBaseJsInterface).onError("Resize properties specified a size & offset that does not allow the ad to appear within the max allowed size", JSInterface.ACTION_RESIZE);
    showExpandDialogMethod.invoke(mMraidResize, 100, 100, 0, 0, false);
    verify(mSpyBaseJsInterface, times(2)).onStateChange(eq(JSInterface.STATE_RESIZED));
    WeakReference<Context> weakReference = new WeakReference<>(null);
    WhiteBox.field(MraidResize.class, "mContextReference").set(mMraidResize, weakReference);
    showExpandDialogMethod.invoke(mMraidResize, 100, 100, 0, 0, false);
    verify(mSpyBaseJsInterface).onError("Unable to resize when mContext is null", JSInterface.ACTION_RESIZE);
}
Also used : Context(android.content.Context) Field(java.lang.reflect.Field) Rect(android.graphics.Rect) PrebidWebViewBase(org.prebid.mobile.rendering.views.webview.PrebidWebViewBase) FrameLayout(android.widget.FrameLayout) WeakReference(java.lang.ref.WeakReference) Method(java.lang.reflect.Method) View(android.view.View) Test(org.junit.Test)

Aggregations

PrebidWebViewBase (org.prebid.mobile.rendering.views.webview.PrebidWebViewBase)19 Test (org.junit.Test)12 WebViewBase (org.prebid.mobile.rendering.views.webview.WebViewBase)8 HTMLCreative (org.prebid.mobile.rendering.models.HTMLCreative)3 View (android.view.View)2 MraidEvent (org.prebid.mobile.rendering.models.internal.MraidEvent)2 VisibilityTrackerResult (org.prebid.mobile.rendering.models.internal.VisibilityTrackerResult)2 BaseJSInterface (org.prebid.mobile.rendering.views.webview.mraid.BaseJSInterface)2 Context (android.content.Context)1 Rect (android.graphics.Rect)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Message (android.os.Message)1 FrameLayout (android.widget.FrameLayout)1 WeakReference (java.lang.ref.WeakReference)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Before (org.junit.Before)1 AdException (org.prebid.mobile.rendering.errors.AdException)1 AdBaseDialog (org.prebid.mobile.rendering.interstitial.AdBaseDialog)1