@@ -34,6 +34,13 @@ public class UIHandlerAutomated : UIHandler {
3434 private string registrationToken ;
3535 private FirebaseMessage lastReceivedMessage ;
3636
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+
3744 protected override void Start ( ) {
3845#if FIREBASE_RUNNING_FROM_CI && ( UNITY_IOS || UNITY_TVOS )
3946 // Messaging on iOS requires user interaction to give permissions
@@ -177,13 +184,21 @@ IEnumerator TestSendJsonMessageToDevice(TaskCompletionSource<string> tcs) {
177184 // waits until the app receives the message and verifies the contents are the same as were sent.
178185 IEnumerator TestSendJsonMessageToSubscribedTopic ( TaskCompletionSource < string > tcs ) {
179186 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+ } ) ;
181193 // TODO(b/65218400): check message id.
182194 while ( lastReceivedMessage == null ) {
183195 yield return new WaitForSeconds ( 0.5f ) ;
184196 }
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+ } ) ;
187202 }
188203
189204 // Fake test (always passes immediately). Can be used on platforms with no other tests.
0 commit comments