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();
}
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);
}
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();
}
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());
}
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);
}
Aggregations