LoginActivity extends Activity { @NonNull public static Intent newIntent( @NonNull Context context, @NonNull SessionConfiguration sessionConfiguration, @NonNull ResponseType responseType) { return newIntent(context, sessionConfiguration, responseType, false); }  @NonNull static Intent newIntent(
            @NonNull Context context,
            @NonNull SessionConfiguration sessionConfiguration,
            @NonNull ResponseType responseType); @NonNull static Intent newIntent(
            @NonNull Context context,
            @NonNull SessionConfiguration sessionConfiguration,
            @NonNull ResponseType responseType,
            boolean forceWebview); static Intent newResponseIntent(Context context, Uri responseUri);  }
@Test public void onLoginLoad_withSsoEnabled_andSupported_shouldExecuteSsoDeeplink() { Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), productPriority, loginConfiguration, ResponseType.TOKEN, false, true, true); ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent); loginActivity = controller.get(); loginActivity.ssoDeeplinkFactory = ssoDeeplinkFactory; when(ssoDeeplink.isSupported(SsoDeeplink.FlowVersion.REDIRECT_TO_SDK)).thenReturn(true); controller.create(); verify(ssoDeeplink).execute(SsoDeeplink.FlowVersion.REDIRECT_TO_SDK); }
@Test public void onLoginLoad_withSsoEnabled_andNotSupported_shouldReturnErrorResultIntent() { Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), productPriority, loginConfiguration, ResponseType.TOKEN, false, true, true); ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent); loginActivity = controller.get(); loginActivity.ssoDeeplinkFactory = ssoDeeplinkFactory; ShadowActivity shadowActivity = shadowOf(loginActivity); when(ssoDeeplink.isSupported(SsoDeeplink.FlowVersion.REDIRECT_TO_SDK)).thenReturn(false); controller.create(); assertThat(shadowActivity.getResultCode()).isEqualTo(Activity.RESULT_CANCELED); assertThat(shadowActivity.getResultIntent()).isNotNull(); assertThat(getErrorFromIntent(shadowActivity.getResultIntent())) .isEqualTo(AuthenticationError.INVALID_REDIRECT_URI); assertThat(shadowActivity.isFinishing()).isTrue(); }
@Test public void onLoginLoad_withResponseTypeCode_andForceWebview_shouldLoadWebview() { Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration, ResponseType.CODE, true); loginActivity = Robolectric.buildActivity(LoginActivity.class).withIntent(intent).create().get(); ShadowWebView webview = Shadows.shadowOf(loginActivity.webView); String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.CODE, loginConfiguration); assertThat(webview.getLastLoadedUrl()).isEqualTo(expectedUrl); }
@Test public void onLoginLoad_withResponseTypeCode_andNotForceWebview_shouldLoadChrometab() { Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration, ResponseType.CODE, false); ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent); loginActivity = controller.get(); loginActivity.customTabsHelper = customTabsHelper; controller.create(); String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.CODE, loginConfiguration); verify(customTabsHelper).openCustomTab(any(LoginActivity.class), any(CustomTabsIntent.class), eq(Uri.parse(expectedUrl)), any(CustomTabsHelper.BrowserFallback.class)); }
@Test public void onLoginLoad_withResponseTypeToken_andForceWebview_andGeneralScopes_shouldLoadWebview() { Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration, ResponseType.TOKEN, true); loginActivity = Robolectric.buildActivity(LoginActivity.class).withIntent(intent).create().get(); ShadowWebView webview = Shadows.shadowOf(loginActivity.webView); String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.TOKEN, loginConfiguration); assertThat(webview.getLastLoadedUrl()).isEqualTo(expectedUrl); }
@Test public void onLoginLoad_withResponseTypeToken_andNotForceWebview_andGeneralScopes_shouldLoadChrometab() { Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration, ResponseType.TOKEN, false); ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent); loginActivity = controller.get(); loginActivity.customTabsHelper = customTabsHelper; controller.create(); String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.TOKEN, loginConfiguration); verify(customTabsHelper).openCustomTab(any(LoginActivity.class), any(CustomTabsIntent.class), eq(Uri.parse(expectedUrl)), any(CustomTabsHelper.BrowserFallback.class)); }
@Test public void onLoginLoad_withResponseTypeToken_andForceWebview_andPrivilegedScopes_andRedirectToPlayStoreDisabled_shouldLoadWebview() { loginConfiguration = new SessionConfiguration.Builder() .setClientId(CLIENT_ID) .setRedirectUri(REDIRECT_URI) .setScopes(MIXED_SCOPES) .build(); Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration, ResponseType.TOKEN, true); loginActivity = Robolectric.buildActivity(LoginActivity.class).withIntent(intent).create().get(); ShadowWebView webview = Shadows.shadowOf(loginActivity.webView); String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.TOKEN, loginConfiguration); assertThat(webview.getLastLoadedUrl()).isEqualTo(expectedUrl); }
@Test public void onLoginLoad_withResponseTypeToken_andNotForceWebview_andPrivilegedScopes_andRedirectToPlayStoreDisabled_shouldLoadChrometab() { loginConfiguration = new SessionConfiguration.Builder() .setClientId(CLIENT_ID) .setRedirectUri(REDIRECT_URI) .setScopes(MIXED_SCOPES) .build(); Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), loginConfiguration, ResponseType.TOKEN, false); ActivityController<LoginActivity> controller = Robolectric.buildActivity(LoginActivity.class).withIntent(intent); loginActivity = controller.get(); loginActivity.customTabsHelper = customTabsHelper; controller.create(); String expectedUrl = AuthUtils.buildUrl(REDIRECT_URI, ResponseType.TOKEN, loginConfiguration); verify(customTabsHelper).openCustomTab(any(LoginActivity.class), any(CustomTabsIntent.class), eq(Uri.parse(expectedUrl)), any(CustomTabsHelper.BrowserFallback.class)); }
@Test public void onLoginLoad_withResponseTypeToken_andPrivilegedScopes_andRedirectToPlayStoreEnabled_shouldRedirectToPlayStore() { loginConfiguration = new SessionConfiguration.Builder() .setClientId(CLIENT_ID) .setRedirectUri(REDIRECT_URI) .setScopes(MIXED_SCOPES) .build(); Intent intent = LoginActivity.newIntent(Robolectric.setupActivity(Activity.class), new ArrayList<SupportedAppType>(), loginConfiguration, ResponseType.TOKEN, true, false, true); ShadowActivity shadowActivity = shadowOf(Robolectric.buildActivity(LoginActivity.class).withIntent(intent).create().get()); final Intent signupDeeplinkIntent = shadowActivity.peekNextStartedActivity(); assertThat(signupDeeplinkIntent.getData().toString()).isEqualTo(SIGNUP_DEEPLINK_URL); }