use of com.firebase.ui.auth.ui.FlowParameters in project FirebaseUI-Android by firebase.
the class CredentialSignInHandlerTest method testSignInFailed_withFacebookAlreadyLinked.
@Test
public void testSignInFailed_withFacebookAlreadyLinked() {
AppCompatBase mockActivity = mock(AppCompatBase.class);
ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class);
IdpResponse idpResponse = new IdpResponse(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL);
CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(mockActivity, mockActivityHelper, null, RC_ACCOUNT_LINK, idpResponse);
FlowParameters mockFlowParams = mock(FlowParameters.class);
when(mockActivityHelper.getFirebaseAuth()).thenReturn(mockFirebaseAuth);
when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams);
// pretend the account has Facebook linked already
when(mockFirebaseAuth.fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn(new AutoCompleteTask<ProviderQueryResult>(new FakeProviderQueryResult(Arrays.asList(FacebookAuthProvider.PROVIDER_ID)), true, null));
// pretend there was already an account with this email
Task exceptionTask = Tasks.forException(new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
credentialSignInHandler.onComplete(exceptionTask);
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
Intent capturedIntent = intentCaptor.getValue();
User capturedUser = User.getUser(capturedIntent);
assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
assertEquals(WelcomeBackIdpPrompt.class.getName(), capturedIntent.getComponent().getClassName());
assertEquals(TestConstants.EMAIL, capturedUser.getEmail());
assertEquals(FacebookAuthProvider.PROVIDER_ID, capturedUser.getProvider());
}
use of com.firebase.ui.auth.ui.FlowParameters in project FirebaseUI-Android by firebase.
the class AuthUITest method testCreateStartIntent_deprecatedSetProvidersShouldStillWork.
@Test
public void testCreateStartIntent_deprecatedSetProvidersShouldStillWork() {
FlowParameters flowParameters = AuthUI.getInstance(mFirebaseApp).createSignInIntentBuilder().setProviders(new String[] { AuthUI.EMAIL_PROVIDER, AuthUI.TWITTER_PROVIDER }).getFlowParams();
assertEquals(2, flowParameters.providerInfo.size());
assertEquals(AuthUI.EMAIL_PROVIDER, flowParameters.providerInfo.get(0).getProviderId());
}
use of com.firebase.ui.auth.ui.FlowParameters in project FirebaseUI-Android by firebase.
the class CredentialSignInHandlerTest method testSignInFailed_withPasswordAccountAlreadyLinked.
@Test
public void testSignInFailed_withPasswordAccountAlreadyLinked() {
AppCompatBase mockActivity = mock(AppCompatBase.class);
ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
FirebaseAuth mockFirebaseAuth = mock(FirebaseAuth.class);
IdpResponse idpResponse = new IdpResponse(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL);
CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(mockActivity, mockActivityHelper, null, RC_ACCOUNT_LINK, idpResponse);
Task mockTask = mock(Task.class);
FlowParameters mockFlowParams = mock(FlowParameters.class);
// pretend there was already an account with this email
when(mockTask.getException()).thenReturn(new FirebaseAuthUserCollisionException(LINKING_ERROR, LINKING_EXPLANATION));
when(mockActivityHelper.getFirebaseAuth()).thenReturn(mockFirebaseAuth);
when(mockActivityHelper.getFlowParams()).thenReturn(mockFlowParams);
// pretend the account has a Password account linked already
when(mockFirebaseAuth.fetchProvidersForEmail(TestConstants.EMAIL)).thenReturn(new AutoCompleteTask<ProviderQueryResult>(new FakeProviderQueryResult(Arrays.asList(EmailAuthProvider.PROVIDER_ID)), true, null));
credentialSignInHandler.onComplete(mockTask);
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
ArgumentCaptor<Integer> intCaptor = ArgumentCaptor.forClass(Integer.class);
verify(mockActivity).startActivityForResult(intentCaptor.capture(), intCaptor.capture());
Intent capturedIntent = intentCaptor.getValue();
assertEquals(RC_ACCOUNT_LINK, (int) intCaptor.getValue());
assertEquals(WelcomeBackPasswordPrompt.class.getName(), capturedIntent.getComponent().getClassName());
assertEquals(TestConstants.EMAIL, IdpResponse.fromResultIntent(capturedIntent).getEmail());
}
Aggregations