Skip to content

Commit

Permalink
feat(web): upgrade to support v9.8.1 Firebase JS SDK (#8235)
Browse files Browse the repository at this point in the history
Co-authored-by: Elliot Hesp <elliot.hesp@gmail.com>
Co-authored-by: Benjamin Koch <koch@lotum.de>
Co-authored-by: Jorge Roncero <60613199+jorgeroncero@users.noreply.github.com>
Co-authored-by: Guillaume Bernos <guillaume@bernos.dev>
Co-authored-by: Mike Diarmid <mike.diarmid@gmail.com>
Co-authored-by: Nils Reichardt <nils@reichardt.io>
Co-authored-by: Russell Wheatley <russellwheatley85@gmail.com>
  • Loading branch information
7 people committed Jul 6, 2022
1 parent c70e66a commit 4b417af
Show file tree
Hide file tree
Showing 65 changed files with 1,584 additions and 1,107 deletions.
Expand Up @@ -20,6 +20,7 @@ import 'timestamp_e2e.dart';
import 'transaction_e2e.dart';
import 'write_batch_e2e.dart';
import 'load_bundle_e2e.dart';
import 'second_app_e2e.dart';

bool kUseFirestoreEmulator = true;

Expand All @@ -45,6 +46,7 @@ void testsMain() {
runTransactionTests();
runWriteBatchTests();
runLoadBundleTests();
runSecondAppTests();
}

void main() => drive.main(testsMain);
@@ -0,0 +1,74 @@
// File generated by FlutterFire CLI.
// ignore_for_file: lines_longer_than_80_chars, avoid_classes_with_only_static_members
import 'package:firebase_core/firebase_core.dart' show FirebaseOptions;
import 'package:flutter/foundation.dart'
show defaultTargetPlatform, kIsWeb, TargetPlatform;

/// Default [FirebaseOptions] for use with your Firebase apps.
///
/// Example:
/// ```dart
/// import 'firebase_options_secondary.dart';
/// // ...
/// await Firebase.initializeApp(
/// options: DefaultFirebaseOptions.currentPlatform,
/// );
/// ```
class DefaultFirebaseOptions {
static FirebaseOptions get currentPlatform {
if (kIsWeb) {
return web;
}
switch (defaultTargetPlatform) {
case TargetPlatform.android:
return android;
case TargetPlatform.iOS:
return ios;
case TargetPlatform.macOS:
return macos;
default:
throw UnsupportedError(
'DefaultFirebaseOptions are not supported for this platform.',
);
}
}

static const FirebaseOptions web = FirebaseOptions(
apiKey: 'AIzaSyAFh7c37C6MyAVwRJylz7EwvzZSECqmcus',
appId: '1:866672724757:web:3a0fad9cba4848ea19f71c',
messagingSenderId: '866672724757',
projectId: 'flutterfire-e2e-tests-2',
authDomain: 'flutterfire-e2e-tests-2.firebaseapp.com',
storageBucket: 'flutterfire-e2e-tests-2.appspot.com',
);

static const FirebaseOptions android = FirebaseOptions(
apiKey: 'AIzaSyAMoRmAcD_NW0DVoO40ThJO1zDF2vDB7Rs',
appId: '1:866672724757:android:d069b410181b65cf19f71c',
messagingSenderId: '866672724757',
projectId: 'flutterfire-e2e-tests-2',
storageBucket: 'flutterfire-e2e-tests-2.appspot.com',
);

static const FirebaseOptions ios = FirebaseOptions(
apiKey: 'AIzaSyDfWh055gUcnS6_Gqd_Jjwy7boVm5_E8oI',
appId: '1:866672724757:ios:142139d84dda4ed419f71c',
messagingSenderId: '866672724757',
projectId: 'flutterfire-e2e-tests-2',
storageBucket: 'flutterfire-e2e-tests-2.appspot.com',
iosClientId:
'866672724757-rncbdu3qrn0j423e1tfk2jg7jdvrhd8i.apps.googleusercontent.com',
iosBundleId: 'io.flutter.plugins.firebase.firestoreExample',
);

static const FirebaseOptions macos = FirebaseOptions(
apiKey: 'AIzaSyDfWh055gUcnS6_Gqd_Jjwy7boVm5_E8oI',
appId: '1:866672724757:ios:3e35357fc677cc5719f71c',
messagingSenderId: '866672724757',
projectId: 'flutterfire-e2e-tests-2',
storageBucket: 'flutterfire-e2e-tests-2.appspot.com',
iosClientId:
'866672724757-fup6o8riklmmc7mbo3b1jolbeadbb84m.apps.googleusercontent.com',
iosBundleId: 'io.flutter.plugins.firebase.firestore.example',
);
}
@@ -0,0 +1,49 @@
// Copyright 2020, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_test/flutter_test.dart';

import 'firebase_options_secondary.dart';

void runSecondAppTests() {
group('$FirebaseFirestore', () {
late FirebaseFirestore firestore;
late FirebaseFirestore secondFirestoreProject;

setUpAll(() async {
firestore = FirebaseFirestore.instance;
FirebaseApp secondApp = await Firebase.initializeApp(
name: 'secondApp',
options: DefaultFirebaseOptions.currentPlatform,
);
secondFirestoreProject = FirebaseFirestore.instanceFor(
app: secondApp,
);
});

group('Secondary app Firestore instance', () {
test(
'Second Firestore instance should fail due to firestore.rules forbidding data writes',
() async {
// successful write on default app instance
await firestore
.collection('flutter-tests/banned/doc')
.add({'foo': 'bar'});

// permission denied on second app with Firebase that denies database writes
await expectLater(
secondFirestoreProject
.collection('flutter-tests/banned/doc')
.add({'foo': 'bar'}),
throwsA(
isA<FirebaseException>()
.having((e) => e.code, 'code', 'permission-denied'),
),
);
});
});
});
}
Expand Up @@ -3,7 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';

/// Specifies custom configurations for your Cloud Firestore instance.
///
Expand All @@ -16,6 +16,7 @@ class Settings {
this.host,
this.sslEnabled,
this.cacheSizeBytes,
this.ignoreUndefinedProperties = false,
});

/// Constant used to indicate the LRU garbage collection should be disabled.
Expand Down Expand Up @@ -44,13 +45,21 @@ class Settings {
/// and can be set to [Settings.CACHE_SIZE_UNLIMITED] to disable garbage collection.
final int? cacheSizeBytes;

/// Whether to skip nested properties that are set to undefined during object serialization.
///
/// If set to true, these properties are skipped and not written to Firestore. If set to false
/// or omitted, the SDK throws an exception when it encounters properties of type undefined.
/// Web only.
final bool ignoreUndefinedProperties;

/// Returns the settings as a [Map]
Map<String, dynamic> get asMap {
return {
'persistenceEnabled': persistenceEnabled,
'host': host,
'sslEnabled': sslEnabled,
'cacheSizeBytes': cacheSizeBytes
'cacheSizeBytes': cacheSizeBytes,
if (kIsWeb) 'ignoreUndefinedProperties': ignoreUndefinedProperties,
};
}

Expand All @@ -59,12 +68,15 @@ class Settings {
String? host,
bool? sslEnabled,
int? cacheSizeBytes,
bool? ignoreUndefinedProperties,
}) =>
Settings(
persistenceEnabled: persistenceEnabled ?? this.persistenceEnabled,
host: host ?? this.host,
sslEnabled: sslEnabled ?? this.sslEnabled,
cacheSizeBytes: cacheSizeBytes ?? this.cacheSizeBytes,
ignoreUndefinedProperties:
ignoreUndefinedProperties ?? this.ignoreUndefinedProperties,
);

@override
Expand All @@ -74,7 +86,8 @@ class Settings {
other.persistenceEnabled == persistenceEnabled &&
other.host == host &&
other.sslEnabled == sslEnabled &&
other.cacheSizeBytes == cacheSizeBytes;
other.cacheSizeBytes == cacheSizeBytes &&
other.ignoreUndefinedProperties == ignoreUndefinedProperties;

@override
int get hashCode => Object.hash(
Expand All @@ -83,6 +96,7 @@ class Settings {
host,
sslEnabled,
cacheSizeBytes,
ignoreUndefinedProperties,
);

@override
Expand Down
Expand Up @@ -29,10 +29,12 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
/// instance of Analytics from the web plugin
firestore_interop.Firestore? _webFirestore;

firestore_interop.Settings? _settings;

/// Lazily initialize [_webFirestore] on first method call
firestore_interop.Firestore get _delegate {
return _webFirestore ??=
firestore_interop.getFirestoreInstance(core_interop.app(app.name));
return _webFirestore ??= firestore_interop.getFirestoreInstance(
core_interop.app(app.name), _settings);
}

/// Called by PluginRegistry to register this plugin for Flutter Web
Expand Down Expand Up @@ -120,7 +122,6 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
@override
set settings(Settings settings) {
int? cacheSizeBytes;

if (settings.cacheSizeBytes == null) {
cacheSizeBytes = 40000000;
} else if (settings.cacheSizeBytes == Settings.CACHE_SIZE_UNLIMITED) {
Expand All @@ -131,13 +132,17 @@ class FirebaseFirestoreWeb extends FirebaseFirestorePlatform {
}

if (settings.host != null && settings.sslEnabled != null) {
_delegate.settings(firestore_interop.Settings(
cacheSizeBytes: cacheSizeBytes,
host: settings.host,
ssl: settings.sslEnabled));
_settings = firestore_interop.Settings(
cacheSizeBytes: cacheSizeBytes,
host: settings.host,
ssl: settings.sslEnabled,
ignoreUndefinedProperties: settings.ignoreUndefinedProperties,
);
} else {
_delegate
.settings(firestore_interop.Settings(cacheSizeBytes: cacheSizeBytes));
_settings = firestore_interop.Settings(
cacheSizeBytes: cacheSizeBytes,
ignoreUndefinedProperties: settings.ignoreUndefinedProperties,
);
}
}

Expand Down

This file was deleted.

0 comments on commit 4b417af

Please sign in to comment.