@@ -213,6 +213,55 @@ class TestZulipBinding extends ZulipBinding {
213
213
}
214
214
215
215
class FakeFirebaseMessaging extends Fake implements FirebaseMessaging {
216
+ ////////////////////////////////
217
+ // Permissions.
218
+
219
+ NotificationSettings requestPermissionResult = const NotificationSettings (
220
+ alert: AppleNotificationSetting .enabled,
221
+ announcement: AppleNotificationSetting .disabled,
222
+ authorizationStatus: AuthorizationStatus .authorized,
223
+ badge: AppleNotificationSetting .enabled,
224
+ carPlay: AppleNotificationSetting .disabled,
225
+ lockScreen: AppleNotificationSetting .enabled,
226
+ notificationCenter: AppleNotificationSetting .enabled,
227
+ showPreviews: AppleShowPreviewSetting .whenAuthenticated,
228
+ timeSensitive: AppleNotificationSetting .disabled,
229
+ criticalAlert: AppleNotificationSetting .disabled,
230
+ sound: AppleNotificationSetting .enabled,
231
+ );
232
+
233
+ List <FirebaseMessagingRequestPermissionCall > takeRequestPermissionCalls () {
234
+ final result = _requestPermissionCalls;
235
+ _requestPermissionCalls = [];
236
+ return result;
237
+ }
238
+ List <FirebaseMessagingRequestPermissionCall > _requestPermissionCalls = [];
239
+
240
+ @override
241
+ Future <NotificationSettings > requestPermission ({
242
+ bool alert = true ,
243
+ bool announcement = false ,
244
+ bool badge = true ,
245
+ bool carPlay = false ,
246
+ bool criticalAlert = false ,
247
+ bool provisional = false ,
248
+ bool sound = true ,
249
+ }) async {
250
+ _requestPermissionCalls.add ((
251
+ alert: alert,
252
+ announcement: announcement,
253
+ badge: badge,
254
+ carPlay: carPlay,
255
+ criticalAlert: criticalAlert,
256
+ provisional: provisional,
257
+ sound: sound,
258
+ ));
259
+ return requestPermissionResult;
260
+ }
261
+
262
+ ////////////////////////////////
263
+ // Tokens.
264
+
216
265
String ? _initialToken;
217
266
218
267
/// Set the token to a new value, as if it were newly generated.
@@ -248,6 +297,27 @@ class FakeFirebaseMessaging extends Fake implements FirebaseMessaging {
248
297
@override
249
298
Stream <String > get onTokenRefresh => _tokenController.stream;
250
299
300
+ @override
301
+ Future <String ?> getAPNSToken () async {
302
+ switch (defaultTargetPlatform) {
303
+ case TargetPlatform .iOS:
304
+ case TargetPlatform .macOS:
305
+ // In principle the APNs token is unrelated to any FCM token.
306
+ // But for tests it's convenient to have just one version of
307
+ // [TestBinding.firebaseMessagingInitialToken].
308
+ return _initialToken;
309
+
310
+ case TargetPlatform .android:
311
+ case TargetPlatform .linux:
312
+ case TargetPlatform .windows:
313
+ case TargetPlatform .fuchsia:
314
+ return null ;
315
+ }
316
+ }
317
+
318
+ ////////////////////////////////
319
+ // Messages.
320
+
251
321
StreamController <RemoteMessage > onMessage = StreamController .broadcast ();
252
322
253
323
/// Controls [TestZulipBinding.firebaseMessagingOnBackgroundMessage] .
@@ -257,6 +327,16 @@ class FakeFirebaseMessaging extends Fake implements FirebaseMessaging {
257
327
StreamController <RemoteMessage > onBackgroundMessage = StreamController .broadcast ();
258
328
}
259
329
330
+ typedef FirebaseMessagingRequestPermissionCall = ({
331
+ bool alert,
332
+ bool announcement,
333
+ bool badge,
334
+ bool carPlay,
335
+ bool criticalAlert,
336
+ bool provisional,
337
+ bool sound,
338
+ });
339
+
260
340
class FakeFlutterLocalNotificationsPlugin extends Fake implements FlutterLocalNotificationsPlugin {
261
341
InitializationSettings ? initializationSettings;
262
342
DidReceiveNotificationResponseCallback ? onDidReceiveNotificationResponse;
0 commit comments