Skip to content

Adds more unit tests for signin flow #2786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,8 @@

@RunWith(RobolectricTestRunner.class)
public class FirebaseAppDistributionTest {

private FirebaseApp firebaseApp;
private FirebaseAppDistribution firebaseAppDistribution;

@Mock private FirebaseInstallationsApi mockFirebaseInstallations;
@Mock private Bundle mockBundle;
@Mock SignInResultActivity mockSignInResultActivity;

public static final String TEST_API_KEY = "AIzaSyabcdefghijklmnopqrstuvwxyz1234567";
public static final String TEST_APP_ID_1 = "1:123456789:android:abcdef";
public static final String TEST_APP_NAME = "TestApp";
public static final String TEST_PROJECT_ID = "777777777777";
public static final String TEST_FID_1 = "cccccccccccccccccccccc";
public static final String TEST_URL =
Expand All @@ -68,11 +59,17 @@ public class FirebaseAppDistributionTest {
+ "&packageName=com.google.firebase.appdistribution.test",
TEST_APP_ID_1, TEST_FID_1);

private FirebaseApp firebaseApp;
private FirebaseAppDistribution firebaseAppDistribution;
private TestActivity activity;
private ShadowActivity shadowActivity;
private ShadowPackageManager shadowPackageManager;

public static class TestActivity extends Activity {}
@Mock private FirebaseInstallationsApi mockFirebaseInstallations;
@Mock private Bundle mockBundle;
@Mock SignInResultActivity mockSignInResultActivity;

static class TestActivity extends Activity {}

@Before
public void setup() {
Expand Down Expand Up @@ -102,7 +99,6 @@ public void setup() {

@Test
public void signInTester_whenDialogConfirmedAndChromeAvailable_opensCustomTab() {

firebaseAppDistribution.onActivityResumed(activity);
final ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.resolvePackageName = "garbage";
Expand All @@ -111,7 +107,27 @@ public void signInTester_whenDialogConfirmedAndChromeAvailable_opensCustomTab()
customTabIntent.setPackage("com.android.chrome");
shadowPackageManager.addResolveInfoForIntent(customTabIntent, resolveInfo);

Task<Void> signInTask = firebaseAppDistribution.signInTester();
firebaseAppDistribution.signInTester();

if (ShadowAlertDialog.getLatestDialog() instanceof AlertDialog) {
AlertDialog dialog = (AlertDialog) ShadowAlertDialog.getLatestDialog();
assertTrue(dialog.isShowing());
dialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick();
}

verify(mockFirebaseInstallations, times(1)).getId();
assertThat(shadowActivity.getNextStartedActivity().getData()).isEqualTo(Uri.parse(TEST_URL));
}

@Test
public void signInTester_whenDialogConfirmedAndChromeNotAvailable_opensBrowserIntent() {
firebaseAppDistribution.onActivityResumed(activity);
final ResolveInfo resolveInfo = new ResolveInfo();
resolveInfo.resolvePackageName = "garbage";
final Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(TEST_URL));
shadowPackageManager.addResolveInfoForIntent(browserIntent, resolveInfo);

firebaseAppDistribution.signInTester();

if (ShadowAlertDialog.getLatestDialog() instanceof AlertDialog) {
AlertDialog dialog = (AlertDialog) ShadowAlertDialog.getLatestDialog();
Expand Down Expand Up @@ -153,4 +169,15 @@ public void signInTester_whenReturnFromSignIn_taskSucceeds() {
firebaseAppDistribution.onActivityCreated(mockSignInResultActivity, mockBundle);
assertTrue(signInTask.isSuccessful());
}

@Test
public void signInTester_whenSignInCalledMultipleTimes_cancelsPreviousTask() {
firebaseAppDistribution.onActivityResumed(activity);

Task<Void> signInTask1 = firebaseAppDistribution.signInTester();
Task<Void> signInTask2 = firebaseAppDistribution.signInTester();

assertTrue(signInTask1.isCanceled());
assertFalse(signInTask2.isComplete());
}
}