MraidController { @VisibleForTesting void handleOpen(@NonNull String url) { MoPubLog.d("Opening url: " + url); if (mMraidListener != null) { mMraidListener.onOpen(); } if (!isWebSiteUrl(url) && IntentUtils.canHandleApplicationUrl(mContext, url)) { launchApplicationUrl(url); return; } Intent i = new Intent(mContext, MoPubBrowser.class); i.putExtra(MoPubBrowser.DESTINATION_URL_KEY, url); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(i); } MraidController(@NonNull Context context, @NonNull AdConfiguration adConfiguration,
            @NonNull PlacementType placementType); @VisibleForTesting  MraidController(@NonNull Context context, @NonNull AdConfiguration adConfiguration,
            @NonNull PlacementType placementType,
            @NonNull MraidBridge bridge, @NonNull MraidBridge twoPartBridge,
            @NonNull ScreenMetricsWaiter screenMetricsWaiter); void setMraidListener(@Nullable MraidListener mraidListener); void setUseCustomCloseListener(@Nullable UseCustomCloseListener listener); void setDebugListener(@Nullable MraidWebViewDebugListener debugListener); void loadContent(@NonNull String htmlData); void pause(); void resume(); void destroy(); @NonNull FrameLayout getAdContainer(); void loadJavascript(@NonNull String javascript); @NonNull Context getContext();  }
@Test public void handleOpen_withApplicationUrl_shouldStartNewIntent() { String applicationUrl = "amzn: Robolectric.packageManager.addResolveInfoForIntent(new Intent(Intent.ACTION_VIEW, Uri .parse(applicationUrl)), new ResolveInfo()); subject.handleOpen(applicationUrl); Intent startedIntent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(startedIntent).isNotNull(); assertThat(startedIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0); assertThat(startedIntent.getComponent()).isNull(); verify(mockMraidListener).onOpen(); }
@Test public void handleOpen_withHttpApplicationUrl_shouldStartMoPubBrowser() { String applicationUrl = "http: subject.handleOpen(applicationUrl); Intent startedIntent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(startedIntent).isNotNull(); assertThat(startedIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0); assertThat(startedIntent.getComponent().getClassName()) .isEqualTo("com.mopub.common.MoPubBrowser"); verify(mockMraidListener).onOpen(); }
@Test public void handleOpen_withApplicationUrlThatCantBeHandled_shouldDefaultToMoPubBrowser() throws Exception { String applicationUrl = "canthandleme: subject.handleOpen(applicationUrl); Intent startedIntent = Robolectric.getShadowApplication().getNextStartedActivity(); assertThat(startedIntent).isNotNull(); assertThat(startedIntent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0); assertThat(startedIntent.getComponent().getClassName()) .isEqualTo("com.mopub.common.MoPubBrowser"); assertThat(startedIntent.getStringExtra(MoPubBrowser.DESTINATION_URL_KEY)) .isEqualTo(applicationUrl); verify(mockMraidListener).onOpen(); }