48
48
49
49
@ RunWith (RobolectricTestRunner .class )
50
50
public class FirebaseAppDistributionTest {
51
-
52
- private FirebaseApp firebaseApp ;
53
- private FirebaseAppDistribution firebaseAppDistribution ;
54
-
55
- @ Mock private FirebaseInstallationsApi mockFirebaseInstallations ;
56
- @ Mock private Bundle mockBundle ;
57
- @ Mock SignInResultActivity mockSignInResultActivity ;
58
-
59
51
public static final String TEST_API_KEY = "AIzaSyabcdefghijklmnopqrstuvwxyz1234567" ;
60
52
public static final String TEST_APP_ID_1 = "1:123456789:android:abcdef" ;
61
- public static final String TEST_APP_NAME = "TestApp" ;
62
53
public static final String TEST_PROJECT_ID = "777777777777" ;
63
54
public static final String TEST_FID_1 = "cccccccccccccccccccccc" ;
64
55
public static final String TEST_URL =
@@ -68,11 +59,17 @@ public class FirebaseAppDistributionTest {
68
59
+ "&packageName=com.google.firebase.appdistribution.test" ,
69
60
TEST_APP_ID_1 , TEST_FID_1 );
70
61
62
+ private FirebaseApp firebaseApp ;
63
+ private FirebaseAppDistribution firebaseAppDistribution ;
71
64
private TestActivity activity ;
72
65
private ShadowActivity shadowActivity ;
73
66
private ShadowPackageManager shadowPackageManager ;
74
67
75
- public static class TestActivity extends Activity {}
68
+ @ Mock private FirebaseInstallationsApi mockFirebaseInstallations ;
69
+ @ Mock private Bundle mockBundle ;
70
+ @ Mock SignInResultActivity mockSignInResultActivity ;
71
+
72
+ static class TestActivity extends Activity {}
76
73
77
74
@ Before
78
75
public void setup () {
@@ -102,7 +99,6 @@ public void setup() {
102
99
103
100
@ Test
104
101
public void signInTester_whenDialogConfirmedAndChromeAvailable_opensCustomTab () {
105
-
106
102
firebaseAppDistribution .onActivityResumed (activity );
107
103
final ResolveInfo resolveInfo = new ResolveInfo ();
108
104
resolveInfo .resolvePackageName = "garbage" ;
@@ -111,7 +107,27 @@ public void signInTester_whenDialogConfirmedAndChromeAvailable_opensCustomTab()
111
107
customTabIntent .setPackage ("com.android.chrome" );
112
108
shadowPackageManager .addResolveInfoForIntent (customTabIntent , resolveInfo );
113
109
114
- Task <Void > signInTask = firebaseAppDistribution .signInTester ();
110
+ firebaseAppDistribution .signInTester ();
111
+
112
+ if (ShadowAlertDialog .getLatestDialog () instanceof AlertDialog ) {
113
+ AlertDialog dialog = (AlertDialog ) ShadowAlertDialog .getLatestDialog ();
114
+ assertTrue (dialog .isShowing ());
115
+ dialog .getButton (AlertDialog .BUTTON_POSITIVE ).performClick ();
116
+ }
117
+
118
+ verify (mockFirebaseInstallations , times (1 )).getId ();
119
+ assertThat (shadowActivity .getNextStartedActivity ().getData ()).isEqualTo (Uri .parse (TEST_URL ));
120
+ }
121
+
122
+ @ Test
123
+ public void signInTester_whenDialogConfirmedAndChromeNotAvailable_opensBrowserIntent () {
124
+ firebaseAppDistribution .onActivityResumed (activity );
125
+ final ResolveInfo resolveInfo = new ResolveInfo ();
126
+ resolveInfo .resolvePackageName = "garbage" ;
127
+ final Intent browserIntent = new Intent (Intent .ACTION_VIEW , Uri .parse (TEST_URL ));
128
+ shadowPackageManager .addResolveInfoForIntent (browserIntent , resolveInfo );
129
+
130
+ firebaseAppDistribution .signInTester ();
115
131
116
132
if (ShadowAlertDialog .getLatestDialog () instanceof AlertDialog ) {
117
133
AlertDialog dialog = (AlertDialog ) ShadowAlertDialog .getLatestDialog ();
@@ -153,4 +169,15 @@ public void signInTester_whenReturnFromSignIn_taskSucceeds() {
153
169
firebaseAppDistribution .onActivityCreated (mockSignInResultActivity , mockBundle );
154
170
assertTrue (signInTask .isSuccessful ());
155
171
}
172
+
173
+ @ Test
174
+ public void signInTester_whenSignInCalledMultipleTimes_cancelsPreviousTask () {
175
+ firebaseAppDistribution .onActivityResumed (activity );
176
+
177
+ Task <Void > signInTask1 = firebaseAppDistribution .signInTester ();
178
+ Task <Void > signInTask2 = firebaseAppDistribution .signInTester ();
179
+
180
+ assertTrue (signInTask1 .isCanceled ());
181
+ assertFalse (signInTask2 .isComplete ());
182
+ }
156
183
}
0 commit comments