HtmlInterstitialWebView extends BaseHtmlWebView { public void init(final CustomEventInterstitialListener customEventInterstitialListener, boolean isScrollable, String redirectUrl, String clickthroughUrl) { super.init(isScrollable); HtmlInterstitialWebViewListener htmlInterstitialWebViewListener = new HtmlInterstitialWebViewListener(customEventInterstitialListener); HtmlWebViewClient htmlWebViewClient = new HtmlWebViewClient(htmlInterstitialWebViewListener, this, clickthroughUrl, redirectUrl); setWebViewClient(htmlWebViewClient); addMoPubUriJavascriptInterface(new MoPubUriJavascriptFireFinishLoadListener() { @Override public void onInterstitialLoaded() { if (!mIsDestroyed) { customEventInterstitialListener.onInterstitialLoaded(); } } }); } HtmlInterstitialWebView(Context context, AdConfiguration adConfiguration); void init(final CustomEventInterstitialListener customEventInterstitialListener, boolean isScrollable, String redirectUrl, String clickthroughUrl); @TargetApi(11) @Override void destroy();  }
@Test public void init_shouldSetupWebViewClient() throws Exception { subject.init(customEventInterstitialListener, false, clickthroughUrl, redirectUrl); WebViewClient webViewClient = shadowOf(subject).getWebViewClient(); assertThat(webViewClient).isNotNull(); assertThat(webViewClient).isInstanceOf(HtmlWebViewClient.class); }
@Test public void init_shouldAddJavascriptInterface() throws Exception { subject.init(customEventInterstitialListener, isScrollable, clickthroughUrl, redirectUrl); Object javascriptInterface = shadowOf(subject).getJavascriptInterface(MOPUB_JS_INTERFACE_NAME); assertThat(javascriptInterface).isNotNull(); Method fireFinishLoad = javascriptInterface.getClass().getDeclaredMethod("fireFinishLoad"); Robolectric.pauseMainLooper(); boolean returnValue = (Boolean) fireFinishLoad.invoke(javascriptInterface); assertThat(returnValue).isTrue(); verify(customEventInterstitialListener, never()).onInterstitialShown(); Robolectric.unPauseMainLooper(); verify(customEventInterstitialListener).onInterstitialLoaded(); }
@Test public void destroy_shouldPreventJavascriptInterfaceFromNotifyingListener() throws Exception{ subject.init(customEventInterstitialListener, isScrollable, clickthroughUrl, redirectUrl); Object javascriptInterface = shadowOf(subject).getJavascriptInterface(MOPUB_JS_INTERFACE_NAME); assertThat(javascriptInterface).isNotNull(); subject.setIsDestroyed(true); Method fireFinishLoad = javascriptInterface.getClass().getDeclaredMethod("fireFinishLoad"); fireFinishLoad.invoke(javascriptInterface); verify(customEventInterstitialListener, never()).onInterstitialLoaded(); }