From c42b57cedbafc6d88f8138e8fce7f06f846796cc Mon Sep 17 00:00:00 2001 From: Russell Wheatley Date: Thu, 15 Feb 2024 10:10:09 +0000 Subject: [PATCH] test(messaging): update tests app for messaging web (#12332) --- .../firebase_messaging_e2e_test.dart | 9 ++- tests/web/firebase-messaging-sw.js | 21 +++++ tests/web/index.html | 81 ++++++++++--------- 3 files changed, 67 insertions(+), 44 deletions(-) create mode 100644 tests/web/firebase-messaging-sw.js diff --git a/tests/integration_test/firebase_messaging/firebase_messaging_e2e_test.dart b/tests/integration_test/firebase_messaging/firebase_messaging_e2e_test.dart index 318fcdbafdfc..ab524d97f9b9 100644 --- a/tests/integration_test/firebase_messaging/firebase_messaging_e2e_test.dart +++ b/tests/integration_test/firebase_messaging/firebase_messaging_e2e_test.dart @@ -12,7 +12,7 @@ import 'package:integration_test/integration_test.dart'; import 'package:tests/firebase_options.dart'; // ignore: do_not_use_environment -const bool skipManualTests = bool.fromEnvironment('CI'); +const bool skipTestsOnCI = bool.fromEnvironment('CI'); void main() { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); @@ -110,7 +110,8 @@ void main() { AuthorizationStatus.notDetermined, ); }, - skip: !kIsWeb, + // This requires interaction with the browser's permission dialog, it no longer returns `notDetermined` on web + skip: true, ); }); @@ -146,7 +147,7 @@ void main() { expect(result, isA()); }); }, - skip: skipManualTests, + skip: skipTestsOnCI, ); // only run for manual testing group('deleteToken()', () { @@ -162,7 +163,7 @@ void main() { expect(token2, isA()); expect(token1, isNot(token2)); }, - skip: skipManualTests, + skip: skipTestsOnCI, ); // only run for manual testing }); diff --git a/tests/web/firebase-messaging-sw.js b/tests/web/firebase-messaging-sw.js new file mode 100644 index 000000000000..0c6917843fbd --- /dev/null +++ b/tests/web/firebase-messaging-sw.js @@ -0,0 +1,21 @@ +importScripts("https://www.gstatic.com/firebasejs/10.7.0/firebase-app-compat.js"); +importScripts("https://www.gstatic.com/firebasejs/10.7.0/firebase-messaging-compat.js"); + +firebase.initializeApp({ + apiKey: 'AIzaSyB7wZb2tO1-Fs6GbDADUSTs2Qs3w08Hovw', + appId: '1:406099696497:web:87e25e51afe982cd3574d0', + messagingSenderId: '406099696497', + projectId: 'flutterfire-e2e-tests', + authDomain: 'flutterfire-e2e-tests.firebaseapp.com', + databaseURL: + 'https://flutterfire-e2e-tests-default-rtdb.europe-west1.firebasedatabase.app', + storageBucket: 'flutterfire-e2e-tests.appspot.com', + measurementId: 'G-JN95N1JV2E', +}); +// Necessary to receive background messages: +const messaging = firebase.messaging(); + +// Optional: +messaging.onBackgroundMessage((m) => { + console.log("onBackgroundMessage", m); +}); diff --git a/tests/web/index.html b/tests/web/index.html index ea29a2f8f13a..0446b3238de2 100644 --- a/tests/web/index.html +++ b/tests/web/index.html @@ -33,32 +33,33 @@ - -