@@ -34,6 +34,13 @@ public class UIHandlerAutomated : UIHandler {
34
34
private string registrationToken ;
35
35
private FirebaseMessage lastReceivedMessage ;
36
36
37
+ // Don't subscribe to a topic, since it might confuse the tests.
38
+ protected override bool SubscribeToTopicOnStart {
39
+ get {
40
+ return false ;
41
+ }
42
+ }
43
+
37
44
protected override void Start ( ) {
38
45
#if FIREBASE_RUNNING_FROM_CI && ( UNITY_IOS || UNITY_TVOS )
39
46
// Messaging on iOS requires user interaction to give permissions
@@ -177,13 +184,21 @@ IEnumerator TestSendJsonMessageToDevice(TaskCompletionSource<string> tcs) {
177
184
// waits until the app receives the message and verifies the contents are the same as were sent.
178
185
IEnumerator TestSendJsonMessageToSubscribedTopic ( TaskCompletionSource < string > tcs ) {
179
186
yield return StartCoroutine ( WaitForToken ( ) ) ;
180
- SendJsonMessageToTopicAsync ( JsonMessageB , TestTopic ) ;
187
+ // Note: Ideally this would use a more unique topic, but topic creation and subscription
188
+ // takes additional time, so instead this only subscribes during this one test, and doesn't
189
+ // fully test unsubscribing.
190
+ Firebase . Messaging . FirebaseMessaging . SubscribeAsync ( TestTopic ) . ContinueWithOnMainThread ( t => {
191
+ SendJsonMessageToTopicAsync ( JsonMessageB , TestTopic ) ;
192
+ } ) ;
181
193
// TODO(b/65218400): check message id.
182
194
while ( lastReceivedMessage == null ) {
183
195
yield return new WaitForSeconds ( 0.5f ) ;
184
196
}
185
- ValidateJsonMessageB ( tcs , lastReceivedMessage ) ;
186
- lastReceivedMessage = null ;
197
+ // Unsubscribe from the test topic, to make sure that other messages aren't received.
198
+ Firebase . Messaging . FirebaseMessaging . UnsubscribeAsync ( TestTopic ) . ContinueWithOnMainThread ( t => {
199
+ ValidateJsonMessageB ( tcs , lastReceivedMessage ) ;
200
+ lastReceivedMessage = null ;
201
+ } ) ;
187
202
}
188
203
189
204
// Fake test (always passes immediately). Can be used on platforms with no other tests.
0 commit comments