Search in sources :

Example 1 with FakeAuthResult

use of com.firebase.ui.auth.testhelpers.FakeAuthResult in project FirebaseUI-Android by firebase.

the class RegisterEmailActivityTest method testSignUpButton_successfulRegistrationShouldContinueToSaveCredentials.

@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testSignUpButton_successfulRegistrationShouldContinueToSaveCredentials() {
    // init mocks
    new BaseHelperShadow();
    reset(BaseHelperShadow.sSaveSmartLock);
    TestHelper.initializeApp(RuntimeEnvironment.application);
    RegisterEmailActivity registerEmailActivity = createActivity();
    // Trigger new user UI (bypassing check email)
    registerEmailActivity.onNewUser(new User.Builder(TestConstants.EMAIL).setName(TestConstants.NAME).setPhotoUri(TestConstants.PHOTO_URI).build());
    EditText name = (EditText) registerEmailActivity.findViewById(R.id.name);
    EditText password = (EditText) registerEmailActivity.findViewById(R.id.password);
    name.setText(TestConstants.NAME);
    password.setText(TestConstants.PASSWORD);
    FirebaseUser mockFirebaseUser = Mockito.mock(FirebaseUser.class);
    when(mockFirebaseUser.getEmail()).thenReturn(TestConstants.EMAIL);
    when(mockFirebaseUser.getDisplayName()).thenReturn(TestConstants.NAME);
    when(mockFirebaseUser.getPhotoUrl()).thenReturn(TestConstants.PHOTO_URI);
    when(mockFirebaseUser.updateProfile((UserProfileChangeRequest) Mockito.any())).thenReturn(new AutoCompleteTask<Void>(null, true, null));
    when(BaseHelperShadow.sFirebaseAuth.createUserWithEmailAndPassword(TestConstants.EMAIL, TestConstants.PASSWORD)).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button button = (Button) registerEmailActivity.findViewById(R.id.button_create);
    button.performClick();
    TestHelper.verifySmartLockSave(EmailAuthProvider.PROVIDER_ID, TestConstants.EMAIL, TestConstants.PASSWORD);
}
Also used : EditText(android.widget.EditText) Button(android.widget.Button) BaseHelperShadow(com.firebase.ui.auth.testhelpers.BaseHelperShadow) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Example 2 with FakeAuthResult

use of com.firebase.ui.auth.testhelpers.FakeAuthResult in project FirebaseUI-Android by firebase.

the class AuthMethodPickerActivityTest method testFacebookLoginFlow.

@Test
@Config(shadows = { BaseHelperShadow.class, ActivityHelperShadow.class })
public void testFacebookLoginFlow() {
    // initialize mocks
    new ActivityHelperShadow();
    reset(ActivityHelperShadow.sSaveSmartLock);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(FacebookAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    List<String> providers = Arrays.asList(AuthUI.FACEBOOK_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FacebookSdk.sdkInitialize(authMethodPickerActivity);
    Button facebookButton = (Button) authMethodPickerActivity.findViewById(R.id.facebook_button);
    assertNotNull(facebookButton);
    facebookButton.performClick();
    verifySmartLockSave(AuthUI.FACEBOOK_PROVIDER, TestConstants.EMAIL, null);
}
Also used : ActivityHelperShadow(com.firebase.ui.auth.testhelpers.ActivityHelperShadow) Button(android.widget.Button) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Example 3 with FakeAuthResult

use of com.firebase.ui.auth.testhelpers.FakeAuthResult in project FirebaseUI-Android by firebase.

the class AuthMethodPickerActivityTest method testGoogleLoginFlow.

@Test
@Config(shadows = { GoogleProviderShadow.class, BaseHelperShadow.class, ActivityHelperShadow.class })
public void testGoogleLoginFlow() {
    // initialize mocks
    new ActivityHelperShadow();
    reset(ActivityHelperShadow.sSaveSmartLock);
    List<String> providers = Arrays.asList(AuthUI.GOOGLE_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(GoogleAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button googleButton = (Button) authMethodPickerActivity.findViewById(R.id.google_button);
    assertNotNull(googleButton);
    googleButton.performClick();
    verifySmartLockSave(AuthUI.GOOGLE_PROVIDER, TestConstants.EMAIL, null);
}
Also used : ActivityHelperShadow(com.firebase.ui.auth.testhelpers.ActivityHelperShadow) Button(android.widget.Button) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Example 4 with FakeAuthResult

use of com.firebase.ui.auth.testhelpers.FakeAuthResult in project FirebaseUI-Android by firebase.

the class AuthMethodPickerActivityTest method testTwitterLoginFlowStarts.

@Test
@Config(shadows = { ActivityHelperShadow.class })
public void testTwitterLoginFlowStarts() {
    List<String> providers = Arrays.asList(AuthUI.TWITTER_PROVIDER);
    AuthMethodPickerActivity authMethodPickerActivity = createActivity(providers);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    when(mockFirebaseUser.getProviders()).thenReturn(Arrays.asList(TwitterAuthProvider.PROVIDER_ID));
    when(ActivityHelperShadow.sFirebaseAuth.signInWithCredential((AuthCredential) any())).thenReturn(new AutoCompleteTask<AuthResult>(new FakeAuthResult(mockFirebaseUser), true, null));
    Button twitterButton = (Button) authMethodPickerActivity.findViewById(R.id.twitter_button);
    assertNotNull(twitterButton);
    twitterButton.performClick();
    ShadowActivity.IntentForResult nextIntent = Shadows.shadowOf(authMethodPickerActivity).getNextStartedActivityForResult();
    assertTrue(nextIntent.intent.getComponent().getClassName().contains("com.twitter.sdk"));
}
Also used : Button(android.widget.Button) ShadowActivity(org.robolectric.shadows.ShadowActivity) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) AuthResult(com.google.firebase.auth.AuthResult) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) Test(org.junit.Test) Config(org.robolectric.annotation.Config) BuildConfig(com.firebase.ui.auth.BuildConfig)

Example 5 with FakeAuthResult

use of com.firebase.ui.auth.testhelpers.FakeAuthResult in project FirebaseUI-Android by firebase.

the class CredentialSignInHandlerTest method testSignInSucceeded.

@Test
public void testSignInSucceeded() {
    AppCompatBase mockActivity = mock(AppCompatBase.class);
    ActivityHelper mockActivityHelper = mock(ActivityHelper.class);
    FirebaseUser mockFirebaseUser = TestHelper.makeMockFirebaseUser();
    IdpResponse idpResponse = new IdpResponse(GoogleAuthProvider.PROVIDER_ID, TestConstants.EMAIL);
    SaveSmartLock smartLock = mock(SaveSmartLock.class);
    CredentialSignInHandler credentialSignInHandler = new CredentialSignInHandler(mockActivity, mockActivityHelper, smartLock, RC_ACCOUNT_LINK, idpResponse);
    Task signInTask = Tasks.forResult(new FakeAuthResult(mockFirebaseUser));
    when(mockActivityHelper.getFlowParams()).thenReturn(TestHelper.getFlowParameters(Collections.<String>emptyList()));
    credentialSignInHandler.onComplete(signInTask);
    ArgumentCaptor<SaveSmartLock> smartLockCaptor = ArgumentCaptor.forClass(SaveSmartLock.class);
    ArgumentCaptor<Activity> activityCaptor = ArgumentCaptor.forClass(Activity.class);
    ArgumentCaptor<FirebaseUser> firebaseUserCaptor = ArgumentCaptor.forClass(FirebaseUser.class);
    ArgumentCaptor<IdpResponse> idpResponseCaptor = ArgumentCaptor.forClass(IdpResponse.class);
    verify(mockActivityHelper).saveCredentialsOrFinish(smartLockCaptor.capture(), activityCaptor.capture(), firebaseUserCaptor.capture(), idpResponseCaptor.capture());
    assertEquals(smartLock, smartLockCaptor.getValue());
    assertEquals(mockActivity, activityCaptor.getValue());
    assertEquals(mockFirebaseUser, firebaseUserCaptor.getValue());
    assertEquals(idpResponse.getProviderType(), idpResponseCaptor.getValue().getProviderType());
    assertEquals(idpResponse.getEmail(), idpResponseCaptor.getValue().getEmail());
    assertEquals(idpResponse.getIdpToken(), idpResponseCaptor.getValue().getIdpToken());
    assertEquals(idpResponse.getIdpSecret(), idpResponseCaptor.getValue().getIdpSecret());
}
Also used : Task(com.google.android.gms.tasks.Task) AutoCompleteTask(com.firebase.ui.auth.testhelpers.AutoCompleteTask) AppCompatBase(com.firebase.ui.auth.ui.AppCompatBase) Activity(android.app.Activity) FirebaseUser(com.google.firebase.auth.FirebaseUser) FakeAuthResult(com.firebase.ui.auth.testhelpers.FakeAuthResult) ActivityHelper(com.firebase.ui.auth.ui.ActivityHelper) SaveSmartLock(com.firebase.ui.auth.util.signincontainer.SaveSmartLock) IdpResponse(com.firebase.ui.auth.IdpResponse) Test(org.junit.Test)

Aggregations

FakeAuthResult (com.firebase.ui.auth.testhelpers.FakeAuthResult)6 FirebaseUser (com.google.firebase.auth.FirebaseUser)6 Test (org.junit.Test)6 Button (android.widget.Button)5 BuildConfig (com.firebase.ui.auth.BuildConfig)5 AuthResult (com.google.firebase.auth.AuthResult)5 Config (org.robolectric.annotation.Config)5 ActivityHelperShadow (com.firebase.ui.auth.testhelpers.ActivityHelperShadow)3 EditText (android.widget.EditText)2 Activity (android.app.Activity)1 IdpResponse (com.firebase.ui.auth.IdpResponse)1 AutoCompleteTask (com.firebase.ui.auth.testhelpers.AutoCompleteTask)1 BaseHelperShadow (com.firebase.ui.auth.testhelpers.BaseHelperShadow)1 ActivityHelper (com.firebase.ui.auth.ui.ActivityHelper)1 AppCompatBase (com.firebase.ui.auth.ui.AppCompatBase)1 WelcomeBackPasswordPrompt (com.firebase.ui.auth.ui.accountlink.WelcomeBackPasswordPrompt)1 SaveSmartLock (com.firebase.ui.auth.util.signincontainer.SaveSmartLock)1 Task (com.google.android.gms.tasks.Task)1 ShadowActivity (org.robolectric.shadows.ShadowActivity)1