@@ -12,10 +12,7 @@ import 'package:package_info_plus/package_info_plus.dart';
1212import 'package:sentry_flutter/sentry_flutter.dart' ;
1313import 'package:sentry_flutter_example/main.dart' ;
1414import 'package:sentry_flutter/src/native/java/sentry_native_java.dart' ;
15- import 'package:sentry_flutter/src/native/cocoa/sentry_native_cocoa.dart' ;
1615import 'package:sentry_flutter/src/native/java/binding.dart' as jni;
17- import 'package:sentry_flutter/src/native/cocoa/binding.dart' as cocoa;
18- import 'package:objective_c/objective_c.dart' ;
1916
2017import 'utils.dart' ;
2118
@@ -169,13 +166,8 @@ void main() {
169166 await transaction.finish ();
170167 });
171168
172- testWidgets ('init maps Dart options into native SDK options' , (tester) async {
173- if (Platform .isIOS || Platform .isMacOS) {
174- // Since this is a static var previous test might have overridden this so
175- // we should set this back to the default (false).
176- cocoa.PrivateSentrySDKOnly .setAppStartMeasurementHybridSDKMode (false );
177- }
178-
169+ testWidgets ('init maps Dart options into native SDK options on Android' ,
170+ (tester) async {
179171 await restoreFlutterOnErrorAfter (() async {
180172 await setupSentryWithCustomInit (() async {
181173 await tester.pumpWidget (
@@ -219,140 +211,86 @@ void main() {
219211 options.replay.quality = SentryReplayQuality .high;
220212 options.replay.sessionSampleRate = 0.4 ;
221213 options.replay.onErrorSampleRate = 0.8 ;
222-
223- // Cocoa-only
224- if (Platform .isIOS || Platform .isMacOS) {
225- options.recordHttpBreadcrumbs = false ;
226- options.captureFailedRequests = false ;
227- options.enableAppHangTracking = false ;
228- options.appHangTimeoutInterval = const Duration (seconds: 1 );
229- }
230- // Android-only
231- if (Platform .isAndroid) {
232- options.enableNdkScopeSync = true ;
233- options.attachThreads = true ;
234- options.anrEnabled = false ;
235- options.anrTimeoutInterval = const Duration (seconds: 2 );
236- options.connectionTimeout = const Duration (milliseconds: 1234 );
237- options.readTimeout = const Duration (milliseconds: 2345 );
238- }
214+ options.enableNdkScopeSync = true ;
215+ options.attachThreads = true ;
216+ options.anrEnabled = false ;
217+ options.anrTimeoutInterval = const Duration (seconds: 2 );
218+ options.connectionTimeout = const Duration (milliseconds: 1234 );
219+ options.readTimeout = const Duration (milliseconds: 2345 );
239220 });
240221 });
241222
242- if (Platform .isIOS || Platform .isMacOS) {
243- final cocoaOptions = cocoa.PrivateSentrySDKOnly .getOptions ();
244- expect (cocoaOptions, isNotNull);
245- if (Platform .isIOS) {
246- final nativeReplayOptions =
247- cocoa.SentryFlutterPlugin .getReplayOptions ();
248- expect (nativeReplayOptions, isNotNull);
249- expect (nativeReplayOptions! .quality,
250- cocoa.SentryReplayQuality .SentryReplayQualityHigh );
251- // Can't use direct comparison because of floating point precision
252- expect (nativeReplayOptions.sessionSampleRate, closeTo (0.4 , 0.001 ));
253- expect (nativeReplayOptions.onErrorSampleRate, closeTo (0.8 , 0.001 ));
254- }
255- expect (cocoaOptions.dsn? .toDartString (), fakeDsn);
256- expect (cocoaOptions.debug, isTrue);
257- expect (cocoaOptions.diagnosticLevel.value, SentryLevel .error.ordinal);
258- expect (cocoaOptions.environment.toDartString (), 'init-test-env' );
259- expect (cocoaOptions.releaseName? .toDartString (), '1.2.3+9' );
260- expect (cocoaOptions.dist? .toDartString (), '42' );
261- expect (cocoaOptions.sendDefaultPii, isTrue);
262- expect (cocoaOptions.attachStacktrace, isFalse);
263- expect (cocoaOptions.maxBreadcrumbs, 7 );
264- expect (cocoaOptions.maxCacheItems, 77 );
265- expect (cocoaOptions.maxAttachmentSize, 512 );
266- expect (cocoaOptions.enableAutoSessionTracking, isFalse);
267- expect (cocoaOptions.sessionTrackingIntervalMillis, 5000 );
268- expect (cocoaOptions.enableAutoBreadcrumbTracking, isFalse);
269- expect (cocoaOptions.enableNetworkBreadcrumbs, isFalse);
270- expect (cocoaOptions.enableCaptureFailedRequests, isFalse);
271- expect (cocoaOptions.enableAppHangTracking, isFalse);
272- expect (cocoaOptions.appHangTimeoutInterval, 1 );
273- expect (cocoaOptions.enableSpotlight, isTrue);
274- expect (cocoaOptions.spotlightUrl.toDartString (),
275- Sentry .currentHub.options.spotlight.url);
276- expect (cocoaOptions.sendClientReports, isFalse);
277- expect (
278- cocoa.PrivateSentrySDKOnly .getSdkName ().toDartString (), cocoaSdkName);
279- expect (cocoa.PrivateSentrySDKOnly .getAppStartMeasurementHybridSDKMode (),
280- isFalse);
281- // currently cannot assert the sdk package and integration since it's attached only
282- // to the event and we don't have a convenient way to access beforeSend
283- } else if (Platform .isAndroid) {
284- final ref = jni.ScopesAdapter .getInstance ()? .getOptions ().reference;
285- expect (ref, isNotNull);
286- final androidOptions = jni.SentryAndroidOptions .fromReference (ref! );
287-
288- expect (androidOptions, isNotNull);
289- expect (androidOptions.getDsn ()? .toDartString (), fakeDsn);
290- expect (androidOptions.isDebug (), isTrue);
291- final diagnostic = androidOptions.getDiagnosticLevel ();
292- expect (
293- diagnostic,
294- jni.SentryLevel .ERROR ,
295- );
296- expect (androidOptions.getEnvironment ()? .toDartString (), 'init-test-env' );
297- expect (androidOptions.getRelease ()? .toDartString (), '1.2.3+9' );
298- expect (androidOptions.getDist ()? .toDartString (), '42' );
299- expect (androidOptions.isSendDefaultPii (), isTrue);
300- expect (androidOptions.isAttachStacktrace (), isFalse);
301- expect (androidOptions.isAttachThreads (), isTrue);
302- expect (androidOptions.getMaxBreadcrumbs (), 7 );
303- expect (androidOptions.getMaxCacheItems (), 77 );
304- expect (androidOptions.getMaxAttachmentSize (), 512 );
305- expect (androidOptions.isEnableScopeSync (), isTrue);
306- expect (androidOptions.isAnrEnabled (), isFalse);
307- expect (androidOptions.getAnrTimeoutIntervalMillis (), 2000 );
308- expect (androidOptions.isEnableActivityLifecycleBreadcrumbs (), isFalse);
309- expect (androidOptions.isEnableAppLifecycleBreadcrumbs (), isFalse);
310- expect (androidOptions.isEnableSystemEventBreadcrumbs (), isFalse);
311- expect (androidOptions.isEnableAppComponentBreadcrumbs (), isFalse);
312- expect (androidOptions.isEnableUserInteractionBreadcrumbs (), isFalse);
313- expect (androidOptions.getConnectionTimeoutMillis (), 1234 );
314- expect (androidOptions.getReadTimeoutMillis (), 2345 );
315- expect (androidOptions.isEnableSpotlight (), isTrue);
316- expect (androidOptions.isSendClientReports (), isFalse);
317- expect (
318- androidOptions.getSpotlightConnectionUrl ()? .toDartString (),
319- Sentry .currentHub.options.spotlight.url,
320- );
321- expect (androidOptions.getSentryClientName ()? .toDartString (),
322- '$androidSdkName /${jni .BuildConfig .VERSION_NAME ?.toDartString ()}' );
323- expect (androidOptions.getNativeSdkName ()? .toDartString (), nativeSdkName);
324- expect (androidOptions.getSdkVersion ()? .getName ().toDartString (),
325- androidSdkName);
326- expect (androidOptions.getSdkVersion ()? .getVersion ().toDartString (),
327- jni.BuildConfig .VERSION_NAME ? .toDartString ());
328- final allPackages = androidOptions
329- .getSdkVersion ()
330- ? .getPackageSet ()
331- .map ((pkg) {
332- if (pkg == null ) return null ;
333- return SentryPackage (
334- pkg.getName ().toDartString (), pkg.getVersion ().toDartString ());
335- })
336- .nonNulls
337- .toList ();
338- for (final package in Sentry .currentHub.options.sdk.packages) {
339- final findMatchingPackage = allPackages? .firstWhere (
340- (p) => p.name == package.name && p.version == package.version);
341- expect (findMatchingPackage, isNotNull);
342- }
343- final androidProxy = androidOptions.getProxy ();
344- expect (androidProxy, isNotNull);
345- expect (androidProxy! .getHost ()? .toDartString (), 'proxy.local' );
346- expect (androidProxy.getPort ()? .toDartString (), '8084' );
347- expect (androidProxy.getUser ()? .toDartString (), 'u' );
348- expect (androidProxy.getPass ()? .toDartString (), 'p' );
349- final r = androidOptions.getSessionReplay ();
350- expect (r.getQuality (), jni.SentryReplayOptions$SentryReplayQuality .HIGH );
351- expect (r.getSessionSampleRate (), isNotNull);
352- expect (r.getOnErrorSampleRate (), isNotNull);
353- expect (r.isTrackConfiguration (), isFalse);
223+ final ref = jni.ScopesAdapter .getInstance ()? .getOptions ().reference;
224+ expect (ref, isNotNull);
225+ final androidOptions = jni.SentryAndroidOptions .fromReference (ref! );
226+
227+ expect (androidOptions, isNotNull);
228+ expect (androidOptions.getDsn ()? .toDartString (), fakeDsn);
229+ expect (androidOptions.isDebug (), isTrue);
230+ final diagnostic = androidOptions.getDiagnosticLevel ();
231+ expect (
232+ diagnostic,
233+ jni.SentryLevel .ERROR ,
234+ );
235+ expect (androidOptions.getEnvironment ()? .toDartString (), 'init-test-env' );
236+ expect (androidOptions.getRelease ()? .toDartString (), '1.2.3+9' );
237+ expect (androidOptions.getDist ()? .toDartString (), '42' );
238+ expect (androidOptions.isSendDefaultPii (), isTrue);
239+ expect (androidOptions.isAttachStacktrace (), isFalse);
240+ expect (androidOptions.isAttachThreads (), isTrue);
241+ expect (androidOptions.getMaxBreadcrumbs (), 7 );
242+ expect (androidOptions.getMaxCacheItems (), 77 );
243+ expect (androidOptions.getMaxAttachmentSize (), 512 );
244+ expect (androidOptions.isEnableScopeSync (), isTrue);
245+ expect (androidOptions.isAnrEnabled (), isFalse);
246+ expect (androidOptions.getAnrTimeoutIntervalMillis (), 2000 );
247+ expect (androidOptions.isEnableActivityLifecycleBreadcrumbs (), isFalse);
248+ expect (androidOptions.isEnableAppLifecycleBreadcrumbs (), isFalse);
249+ expect (androidOptions.isEnableSystemEventBreadcrumbs (), isFalse);
250+ expect (androidOptions.isEnableAppComponentBreadcrumbs (), isFalse);
251+ expect (androidOptions.isEnableUserInteractionBreadcrumbs (), isFalse);
252+ expect (androidOptions.getConnectionTimeoutMillis (), 1234 );
253+ expect (androidOptions.getReadTimeoutMillis (), 2345 );
254+ expect (androidOptions.isEnableSpotlight (), isTrue);
255+ expect (androidOptions.isSendClientReports (), isFalse);
256+ expect (
257+ androidOptions.getSpotlightConnectionUrl ()? .toDartString (),
258+ Sentry .currentHub.options.spotlight.url,
259+ );
260+ expect (androidOptions.getSentryClientName ()? .toDartString (),
261+ '$androidSdkName /${jni .BuildConfig .VERSION_NAME ?.toDartString ()}' );
262+ expect (androidOptions.getNativeSdkName ()? .toDartString (), nativeSdkName);
263+ expect (androidOptions.getSdkVersion ()? .getName ().toDartString (),
264+ androidSdkName);
265+ expect (androidOptions.getSdkVersion ()? .getVersion ().toDartString (),
266+ jni.BuildConfig .VERSION_NAME ? .toDartString ());
267+ final allPackages = androidOptions
268+ .getSdkVersion ()
269+ ? .getPackageSet ()
270+ .map ((pkg) {
271+ if (pkg == null ) return null ;
272+ return SentryPackage (
273+ pkg.getName ().toDartString (), pkg.getVersion ().toDartString ());
274+ })
275+ .nonNulls
276+ .toList ();
277+ for (final package in Sentry .currentHub.options.sdk.packages) {
278+ final findMatchingPackage = allPackages? .firstWhere (
279+ (p) => p.name == package.name && p.version == package.version);
280+ expect (findMatchingPackage, isNotNull);
354281 }
355- });
282+ final androidProxy = androidOptions.getProxy ();
283+ expect (androidProxy, isNotNull);
284+ expect (androidProxy! .getHost ()? .toDartString (), 'proxy.local' );
285+ expect (androidProxy.getPort ()? .toDartString (), '8084' );
286+ expect (androidProxy.getUser ()? .toDartString (), 'u' );
287+ expect (androidProxy.getPass ()? .toDartString (), 'p' );
288+ final r = androidOptions.getSessionReplay ();
289+ expect (r.getQuality (), jni.SentryReplayOptions$SentryReplayQuality .HIGH );
290+ expect (r.getSessionSampleRate (), isNotNull);
291+ expect (r.getOnErrorSampleRate (), isNotNull);
292+ expect (r.isTrackConfiguration (), isFalse);
293+ }, skip: ! Platform .isAndroid);
356294
357295 testWidgets ('loads native contexts through loadContexts' , (tester) async {
358296 await restoreFlutterOnErrorAfter (() async {
@@ -422,8 +360,8 @@ void main() {
422360 expect (breadcrumbs, isA <List >());
423361 if (breadcrumbs! .isNotEmpty) {
424362 final firstCrumb = breadcrumbs.first;
425- expect (firstCrumb, isA <Map < String , dynamic > >());
426- final Map < String , dynamic > crumbMap = firstCrumb as Map < String , dynamic > ;
363+ expect (firstCrumb, isA <Map >());
364+ final crumbMap = firstCrumb as Map ;
427365 expect (crumbMap.containsKey ('timestamp' ), isTrue,
428366 reason: 'Breadcrumb timestamp missing' );
429367 expect (crumbMap['timestamp' ], isA <String >());
0 commit comments