MraidActivity extends BaseInterstitialActivity { @Override public View getAdView() { String htmlData = getIntent().getStringExtra(HTML_RESPONSE_BODY_KEY); if (htmlData == null) { MoPubLog.w("MraidActivity received a null HTML body. Finishing the activity."); finish(); return new View(this); } AdConfiguration adConfiguration = getAdConfiguration(); if (adConfiguration == null) { MoPubLog.w("MraidActivity received a null ad configuration. Finishing the activity."); finish(); return new View(this); } mMraidController = new MraidController( this, adConfiguration, PlacementType.INTERSTITIAL); mMraidController.setDebugListener(mDebugListener); mMraidController.setMraidListener(new MraidListener() { @Override public void onLoaded(View view) { mMraidController.loadJavascript(WEB_VIEW_DID_APPEAR.getJavascript()); } @Override public void onFailedToLoad() { } public void onClose() { mMraidController.loadJavascript(WEB_VIEW_DID_CLOSE.getJavascript()); finish(); } @Override public void onExpand() { } @Override public void onOpen() { broadcastAction(MraidActivity.this, getBroadcastIdentifier(), ACTION_INTERSTITIAL_CLICK); } }); mMraidController.setUseCustomCloseListener(new UseCustomCloseListener() { public void useCustomCloseChanged(boolean useCustomClose) { if (useCustomClose) { hideInterstitialCloseButton(); } else { showInterstitialCloseButton(); } } }); mMraidController.loadContent(htmlData); return mMraidController.getAdContainer(); }  static void preRenderHtml(@NonNull final Context context,
            @NonNull final CustomEventInterstitialListener customEventInterstitialListener,
            @NonNull final String htmlData); static void start(@NonNull Context context, @NonNull String htmlData,
            @NonNull AdConfiguration adConfiguration); @Override View getAdView(); @Override void onCreate(@Nullable Bundle savedInstanceState); @VisibleForTesting void setDebugListener(@Nullable MraidWebViewDebugListener debugListener);  }
@Ignore("Mraid 2.0") @Test public void getAdView_shouldSetupOnReadyListener() throws Exception { reset(mraidWebView); ArgumentCaptor<MraidListener> captor = ArgumentCaptor.forClass(MraidListener.class); View actualAdView = subject.getAdView(); assertThat(actualAdView).isSameAs(mraidWebView); verify(mraidController).setMraidListener(captor.capture()); subject.hideInterstitialCloseButton(); captor.getValue().onLoaded(null); }
@Ignore("Mraid 2.0") @Test public void baseMraidListenerOnReady_shouldFireJavascriptWebViewDidAppear() throws Exception { reset(mraidWebView); ArgumentCaptor<MraidListener> captor = ArgumentCaptor.forClass(MraidListener.class); View actualAdView = subject.getAdView(); assertThat(actualAdView).isSameAs(mraidWebView); verify(mraidController).setMraidListener(captor.capture()); MraidListener baseMraidListener = captor.getValue(); baseMraidListener.onLoaded(null); verify(mraidWebView).loadUrl(eq("javascript:webviewDidAppear();")); }
@Ignore("Mraid 2.0") @Test public void baseMraidListenerOnClose_shouldFireJavascriptWebViewDidClose() throws Exception { reset(mraidWebView); ArgumentCaptor<MraidListener> captor = ArgumentCaptor.forClass(MraidListener.class); View actualAdView = subject.getAdView(); assertThat(actualAdView).isSameAs(mraidWebView); verify(mraidController).setMraidListener(captor.capture()); MraidListener baseMraidListener = captor.getValue(); baseMraidListener.onClose(); verify(mraidWebView).loadUrl(eq("javascript:webviewDidClose();")); }
@Ignore("Mraid 2.0") @Test public void baseMraidListenerOnOpen_shouldBroadcastClickEvent() throws Exception { Intent expectedIntent = getIntentForActionAndIdentifier(ACTION_INTERSTITIAL_CLICK, testBroadcastIdentifier); ShadowLocalBroadcastManager.getInstance(subject).registerReceiver(broadcastReceiver, getHtmlInterstitialIntentFilter()); reset(mraidWebView); ArgumentCaptor<MraidListener> captor = ArgumentCaptor.forClass(MraidListener.class); View actualAdView = subject.getAdView(); assertThat(actualAdView).isSameAs(mraidWebView); verify(mraidController).setMraidListener(captor.capture()); MraidListener baseMraidListener = captor.getValue(); baseMraidListener.onOpen(); verify(broadcastReceiver).onReceive(any(Context.class), eq(expectedIntent)); }
@Ignore("Mraid 2.0") @Test public void getAdView_shouldSetupOnCloseListener() throws Exception { reset(mraidWebView); ArgumentCaptor<MraidListener> captor = ArgumentCaptor.forClass(MraidListener.class); View actualAdView = subject.getAdView(); assertThat(actualAdView).isSameAs(mraidWebView); verify(mraidController).setMraidListener(captor.capture()); captor.getValue().onClose(); ANDROID.assertThat(subject).isFinishing(); }