Search in sources :

Example 6 with MraidVariableContainer

use of org.prebid.mobile.rendering.models.internal.MraidVariableContainer in project prebid-mobile-android by prebid.

the class BaseJSInterfaceTest method setURLForLaunchingTest.

@Test
public void setURLForLaunchingTest() throws IllegalAccessException {
    final MraidVariableContainer mraidVariableContainer = mSpyBaseJSInterface.getMraidVariableContainer();
    assertEquals("", mraidVariableContainer.getUrlForLaunching());
    mraidVariableContainer.setUrlForLaunching("test");
    assertEquals("test", mraidVariableContainer.getUrlForLaunching());
}
Also used : MraidVariableContainer(org.prebid.mobile.rendering.models.internal.MraidVariableContainer) Test(org.junit.Test)

Example 7 with MraidVariableContainer

use of org.prebid.mobile.rendering.models.internal.MraidVariableContainer in project prebid-mobile-android by prebid.

the class BaseJSInterfaceTest method getURLForLaunchingTest.

@Test
public void getURLForLaunchingTest() throws IllegalAccessException {
    final MraidVariableContainer mraidVariableContainer = mSpyBaseJSInterface.getMraidVariableContainer();
    assertEquals("", mraidVariableContainer.getUrlForLaunching());
    mraidVariableContainer.setUrlForLaunching("test");
    assertEquals("test", mraidVariableContainer.getUrlForLaunching());
}
Also used : MraidVariableContainer(org.prebid.mobile.rendering.models.internal.MraidVariableContainer) Test(org.junit.Test)

Example 8 with MraidVariableContainer

use of org.prebid.mobile.rendering.models.internal.MraidVariableContainer in project prebid-mobile-android by prebid.

the class MraidExpand method performExpand.

private void performExpand(String url, CompletedCallBack completedCallBack) {
    final Context context = mContext;
    if (context == null) {
        LogUtil.error(TAG, "Context is null");
        return;
    }
    Handler uiHandler = new Handler(Looper.getMainLooper());
    uiHandler.post(() -> {
        try {
            final MraidVariableContainer mraidVariableContainer = mJsi.getMraidVariableContainer();
            String state = mraidVariableContainer.getCurrentState();
            if (isContainerStateInvalid(state)) {
                LogUtil.debug(TAG, "handleExpand: Skipping. Wrong container state: " + state);
                return;
            }
            mJsi.setDefaultLayoutParams(mWebViewBanner.getLayoutParams());
            if (url != null) {
                mraidVariableContainer.setUrlForLaunching(url);
            }
            showExpandDialog(context, completedCallBack);
        } catch (Exception e) {
            LogUtil.error(TAG, "Expand failed: " + Log.getStackTraceString(e));
        }
    });
}
Also used : Context(android.content.Context) MraidVariableContainer(org.prebid.mobile.rendering.models.internal.MraidVariableContainer) Handler(android.os.Handler)

Example 9 with MraidVariableContainer

use of org.prebid.mobile.rendering.models.internal.MraidVariableContainer in project prebid-mobile-android by prebid.

the class AdBaseDialog method initOrientationProperties.

private void initOrientationProperties() {
    final MraidVariableContainer mraidVariableContainer = mWebViewBase.getMRAIDInterface().getMraidVariableContainer();
    JSONObject orientationProperties;
    // IMP : must  be true by default cos this is used if expand(url) is called as at line#if (!webViewBase.getMRAIDInterface().isLaunchWithURL()) check
    boolean allowOrientationChange = true;
    String forceOrientation = "none";
    try {
        orientationProperties = new JSONObject(mraidVariableContainer.getOrientationProperties());
        allowOrientationChange = orientationProperties.optBoolean("allowOrientationChange", true);
        forceOrientation = orientationProperties.optString("forceOrientation", "none");
    } catch (Exception e) {
        LogUtil.error(TAG, "Failed to get the orientation details from JSON for MRAID: " + Log.getStackTraceString(e));
    }
    if (!mraidVariableContainer.isLaunchedWithUrl()) {
        mAllowOrientationChange = allowOrientationChange;
        mForceOrientation = OrientationManager.ForcedOrientation.valueOf(forceOrientation);
    }
}
Also used : JSONObject(org.json.JSONObject) MraidVariableContainer(org.prebid.mobile.rendering.models.internal.MraidVariableContainer) AdException(org.prebid.mobile.rendering.errors.AdException)

Example 10 with MraidVariableContainer

use of org.prebid.mobile.rendering.models.internal.MraidVariableContainer in project prebid-mobile-android by prebid.

the class MraidCloseTest method closeThroughJSTest.

@Test
public void closeThroughJSTest() throws Exception {
    ViewGroup mockViewGroup = mock(ViewGroup.class);
    when(mSpyBaseJSInterface.getRootView()).thenReturn(mockViewGroup);
    final MraidVariableContainer mraidVariableContainer = mSpyBaseJSInterface.getMraidVariableContainer();
    mMraidClose = new MraidClose(null, mSpyBaseJSInterface, mMockWebViewBase);
    mraidVariableContainer.setCurrentState(JSInterface.STATE_DEFAULT);
    mMraidClose.closeThroughJS();
    verify(mSpyBaseJSInterface, times(0)).onStateChange(anyString());
    mMraidClose = new MraidClose(mTestActivity, mSpyBaseJSInterface, mMockWebViewBase);
    mraidVariableContainer.setCurrentState(JSInterface.STATE_LOADING);
    mMraidClose.closeThroughJS();
    verify(mSpyBaseJSInterface, times(0)).onStateChange(anyString());
    mraidVariableContainer.setCurrentState(JSInterface.STATE_DEFAULT);
    mMraidClose.closeThroughJS();
    verify(mSpyBaseJSInterface).onStateChange(eq(JSInterface.STATE_HIDDEN));
    mraidVariableContainer.setCurrentState(JSInterface.STATE_EXPANDED);
    mMraidClose.closeThroughJS();
    verify(mSpyBaseJSInterface).onStateChange(eq(JSInterface.STATE_DEFAULT));
    verify(mockViewGroup).removeView(any());
    reset(mSpyBaseJSInterface);
    AdBrowserActivity mockActivity = new AdBrowserActivity();
    mMraidClose = new MraidClose(mockActivity, mSpyBaseJSInterface, mMockWebViewBase);
    mraidVariableContainer.setCurrentState(JSInterface.STATE_EXPANDED);
    mMraidClose.closeThroughJS();
    verify(mSpyBaseJSInterface).onStateChange(eq(JSInterface.STATE_DEFAULT));
}
Also used : ViewGroup(android.view.ViewGroup) MraidVariableContainer(org.prebid.mobile.rendering.models.internal.MraidVariableContainer) AdBrowserActivity(org.prebid.mobile.rendering.views.browser.AdBrowserActivity) Test(org.junit.Test)

Aggregations

MraidVariableContainer (org.prebid.mobile.rendering.models.internal.MraidVariableContainer)12 Test (org.junit.Test)7 JSONObject (org.json.JSONObject)2 Matchers.anyString (org.mockito.Matchers.anyString)2 AdException (org.prebid.mobile.rendering.errors.AdException)2 HTMLCreative (org.prebid.mobile.rendering.models.HTMLCreative)2 PrebidWebViewBase (org.prebid.mobile.rendering.views.webview.PrebidWebViewBase)2 Context (android.content.Context)1 Handler (android.os.Handler)1 ViewGroup (android.view.ViewGroup)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 RedirectUrlListener (org.prebid.mobile.rendering.mraid.methods.network.RedirectUrlListener)1 AdBrowserActivity (org.prebid.mobile.rendering.views.browser.AdBrowserActivity)1 WebViewBase (org.prebid.mobile.rendering.views.webview.WebViewBase)1 BaseJSInterface (org.prebid.mobile.rendering.views.webview.mraid.BaseJSInterface)1