1
+ @TestOn ('vm' )
1
2
// ignore_for_file: invalid_use_of_internal_member
2
3
3
4
import 'package:flutter/services.dart' ;
@@ -24,15 +25,8 @@ void main() {
24
25
25
26
group (AndroidPlatformExceptionEventProcessor , () {
26
27
test ('exception is correctly parsed' , () async {
27
- final exception = fixture.options.exceptionFactory
28
- .getSentryException (testPlatformException);
29
-
30
- final event = SentryEvent (
31
- exceptions: [exception],
32
- throwable: testPlatformException,
33
- );
34
-
35
- final platformExceptionEvent = await fixture.processor.apply (event);
28
+ final platformExceptionEvent =
29
+ await fixture.processor.apply (fixture.eventWithPlatformStackTrace);
36
30
37
31
final exceptions = platformExceptionEvent! .exceptions! ;
38
32
expect (exceptions.length, 2 );
@@ -47,6 +41,49 @@ void main() {
47
41
expect (platformException.stackTrace! .frames.length, 18 );
48
42
});
49
43
44
+ test (
45
+ 'Dart thread is current and not crashed if Android exception is present' ,
46
+ () async {
47
+ final platformExceptionEvent =
48
+ await fixture.processor.apply (fixture.eventWithPlatformStackTrace);
49
+
50
+ final exceptions = platformExceptionEvent! .exceptions! ;
51
+ expect (exceptions.length, 2 );
52
+
53
+ expect (platformExceptionEvent.threads? .first.current, true );
54
+ expect (platformExceptionEvent.threads? .first.crashed, false );
55
+ });
56
+
57
+ test ('platformexception has Android thread attached' , () async {
58
+ final platformExceptionEvent =
59
+ await fixture.processor.apply (fixture.eventWithPlatformStackTrace);
60
+
61
+ final exceptions = platformExceptionEvent! .exceptions! ;
62
+ expect (exceptions.length, 2 );
63
+
64
+ final platformException = exceptions[1 ];
65
+ final platformThread = platformExceptionEvent.threads? [1 ];
66
+
67
+ expect (platformException.threadId, platformThread? .id);
68
+ expect (platformThread? .current, false );
69
+ expect (platformThread? .crashed, true );
70
+ expect (platformThread? .name, 'Android' );
71
+ });
72
+
73
+ test ('platformexception has no Android thread attached if disabled' ,
74
+ () async {
75
+ fixture.options.attachThreads = false ;
76
+ final threadCount = fixture.eventWithPlatformStackTrace.threads? .length;
77
+
78
+ final platformExceptionEvent =
79
+ await fixture.processor.apply (fixture.eventWithPlatformStackTrace);
80
+
81
+ final exceptions = platformExceptionEvent! .exceptions! ;
82
+ expect (exceptions.length, 2 );
83
+
84
+ expect (platformExceptionEvent.threads? .length, threadCount);
85
+ });
86
+
50
87
test ('does nothing if no PlatformException is there' , () async {
51
88
final exception = fixture.options.exceptionFactory
52
89
.getSentryException (testPlatformException);
@@ -62,17 +99,10 @@ void main() {
62
99
});
63
100
64
101
test ('does nothing if PlatformException has no stackTrace' , () async {
65
- final exception = fixture.options.exceptionFactory
66
- . getSentryException (emptyPlatformException );
102
+ final platformExceptionEvent =
103
+ await fixture.processor. apply (fixture.eventWithoutPlatformStackTrace );
67
104
68
- final event = SentryEvent (
69
- exceptions: [exception],
70
- throwable: emptyPlatformException,
71
- );
72
-
73
- final platformExceptionEvent = await fixture.processor.apply (event);
74
-
75
- expect (event, platformExceptionEvent);
105
+ expect (fixture.eventWithoutPlatformStackTrace, platformExceptionEvent);
76
106
});
77
107
});
78
108
}
@@ -81,7 +111,35 @@ class Fixture {
81
111
late AndroidPlatformExceptionEventProcessor processor =
82
112
AndroidPlatformExceptionEventProcessor (options);
83
113
84
- SentryFlutterOptions options = SentryFlutterOptions (dsn: fakeDsn);
114
+ late SentryException withPlatformStackTrace = options.exceptionFactory
115
+ .getSentryException (testPlatformException)
116
+ .copyWith (threadId: 1 );
117
+
118
+ late SentryException withoutPlatformStackTrace = options.exceptionFactory
119
+ .getSentryException (emptyPlatformException)
120
+ .copyWith (threadId: 1 );
121
+
122
+ late SentryEvent eventWithPlatformStackTrace = SentryEvent (
123
+ exceptions: [withPlatformStackTrace],
124
+ throwable: testPlatformException,
125
+ threads: [dartThread],
126
+ );
127
+
128
+ late SentryEvent eventWithoutPlatformStackTrace = SentryEvent (
129
+ exceptions: [withoutPlatformStackTrace],
130
+ throwable: emptyPlatformException,
131
+ threads: [dartThread],
132
+ );
133
+
134
+ late SentryThread dartThread = SentryThread (
135
+ crashed: true ,
136
+ current: true ,
137
+ id: 1 ,
138
+ name: 'main' ,
139
+ );
140
+
141
+ SentryFlutterOptions options = SentryFlutterOptions (dsn: fakeDsn)
142
+ ..attachThreads = true ;
85
143
}
86
144
87
145
final testPlatformException = PlatformException (
0 commit comments