1
+ import 'package:flutter/material.dart' ;
1
2
import 'package:flutter/services.dart' ;
2
- import 'package:flutter/widgets.dart' ;
3
3
import 'package:flutter_test/flutter_test.dart' ;
4
4
import 'package:sentry_flutter/sentry_flutter.dart' ;
5
5
import 'package:sentry_flutter/src/screenshot/widget_filter.dart' ;
@@ -14,6 +14,10 @@ void main() async {
14
14
const defaultBounds = Rect .fromLTRB (0 , 0 , 1000 , 1000 );
15
15
final rootBundle = TestAssetBundle ();
16
16
final otherBundle = TestAssetBundle ();
17
+ final colorScheme = WidgetFilterColorScheme (
18
+ defaultMask: Colors .white,
19
+ defaultTextMask: Colors .green,
20
+ background: Colors .red);
17
21
18
22
final createSut = ({bool redactImages = false , bool redactText = false }) {
19
23
final replayOptions = SentryPrivacyOptions ();
@@ -30,29 +34,45 @@ void main() async {
30
34
testWidgets ('redacts the correct number of elements' , (tester) async {
31
35
final sut = createSut (redactText: true );
32
36
final element = await pumpTestElement (tester);
33
- sut.obscure (element, 1.0 , defaultBounds);
37
+ sut.obscure (
38
+ context: element,
39
+ pixelRatio: 1.0 ,
40
+ bounds: defaultBounds,
41
+ colorScheme: colorScheme);
34
42
expect (sut.items.length, 5 );
35
43
});
36
44
37
45
testWidgets ('does not redact text when disabled' , (tester) async {
38
46
final sut = createSut (redactText: false );
39
47
final element = await pumpTestElement (tester);
40
- sut.obscure (element, 1.0 , defaultBounds);
48
+ sut.obscure (
49
+ context: element,
50
+ pixelRatio: 1.0 ,
51
+ bounds: defaultBounds,
52
+ colorScheme: colorScheme);
41
53
expect (sut.items.length, 0 );
42
54
});
43
55
44
56
testWidgets ('does not redact elements that are outside the screen' ,
45
57
(tester) async {
46
58
final sut = createSut (redactText: true );
47
59
final element = await pumpTestElement (tester);
48
- sut.obscure (element, 1.0 , Rect .fromLTRB (0 , 0 , 100 , 100 ));
60
+ sut.obscure (
61
+ context: element,
62
+ pixelRatio: 1.0 ,
63
+ bounds: Rect .fromLTRB (0 , 0 , 100 , 100 ),
64
+ colorScheme: colorScheme);
49
65
expect (sut.items.length, 1 );
50
66
});
51
67
52
68
testWidgets ('correctly determines sizes' , (tester) async {
53
69
final sut = createSut (redactText: true );
54
70
final element = await pumpTestElement (tester);
55
- sut.obscure (element, 1.0 , defaultBounds);
71
+ sut.obscure (
72
+ context: element,
73
+ pixelRatio: 1.0 ,
74
+ bounds: defaultBounds,
75
+ colorScheme: colorScheme);
56
76
expect (sut.items.length, 5 );
57
77
expect (boundsRect (sut.items[0 ]), '624x48' );
58
78
expect (boundsRect (sut.items[1 ]), '169x20' );
@@ -66,7 +86,11 @@ void main() async {
66
86
testWidgets ('redacts the correct number of elements' , (tester) async {
67
87
final sut = createSut (redactImages: true );
68
88
final element = await pumpTestElement (tester);
69
- sut.obscure (element, 1.0 , defaultBounds);
89
+ sut.obscure (
90
+ context: element,
91
+ pixelRatio: 1.0 ,
92
+ bounds: defaultBounds,
93
+ colorScheme: colorScheme);
70
94
expect (sut.items.length, 3 );
71
95
});
72
96
@@ -106,22 +130,34 @@ void main() async {
106
130
testWidgets ('does not redact text when disabled' , (tester) async {
107
131
final sut = createSut (redactImages: false );
108
132
final element = await pumpTestElement (tester);
109
- sut.obscure (element, 1.0 , defaultBounds);
133
+ sut.obscure (
134
+ context: element,
135
+ pixelRatio: 1.0 ,
136
+ bounds: defaultBounds,
137
+ colorScheme: colorScheme);
110
138
expect (sut.items.length, 0 );
111
139
});
112
140
113
141
testWidgets ('does not redact elements that are outside the screen' ,
114
142
(tester) async {
115
143
final sut = createSut (redactImages: true );
116
144
final element = await pumpTestElement (tester);
117
- sut.obscure (element, 1.0 , Rect .fromLTRB (0 , 0 , 500 , 100 ));
145
+ sut.obscure (
146
+ context: element,
147
+ pixelRatio: 1.0 ,
148
+ bounds: Rect .fromLTRB (0 , 0 , 500 , 100 ),
149
+ colorScheme: colorScheme);
118
150
expect (sut.items.length, 1 );
119
151
});
120
152
121
153
testWidgets ('correctly determines sizes' , (tester) async {
122
154
final sut = createSut (redactImages: true );
123
155
final element = await pumpTestElement (tester);
124
- sut.obscure (element, 1.0 , defaultBounds);
156
+ sut.obscure (
157
+ context: element,
158
+ pixelRatio: 1.0 ,
159
+ bounds: defaultBounds,
160
+ colorScheme: colorScheme);
125
161
expect (sut.items.length, 3 );
126
162
expect (boundsRect (sut.items[0 ]), '1x1' );
127
163
expect (boundsRect (sut.items[1 ]), '1x1' );
@@ -134,7 +170,11 @@ void main() async {
134
170
final element = await pumpTestElement (tester, children: [
135
171
SentryMask (Padding (padding: EdgeInsets .all (100 ), child: Text ('foo' ))),
136
172
]);
137
- sut.obscure (element, 1.0 , defaultBounds);
173
+ sut.obscure (
174
+ context: element,
175
+ pixelRatio: 1.0 ,
176
+ bounds: defaultBounds,
177
+ colorScheme: colorScheme);
138
178
expect (sut.items.length, 1 );
139
179
expect (boundsRect (sut.items[0 ]), '344x248' );
140
180
});
@@ -146,7 +186,11 @@ void main() async {
146
186
SentryUnmask (newImage ()),
147
187
SentryUnmask (SentryMask (Text ('foo' ))),
148
188
]);
149
- sut.obscure (element, 1.0 , defaultBounds);
189
+ sut.obscure (
190
+ context: element,
191
+ pixelRatio: 1.0 ,
192
+ bounds: defaultBounds,
193
+ colorScheme: colorScheme);
150
194
expect (sut.items, isEmpty);
151
195
});
152
196
@@ -155,11 +199,19 @@ void main() async {
155
199
final element = await pumpTestElement (tester, children: [
156
200
Padding (padding: EdgeInsets .all (100 ), child: Text ('foo' )),
157
201
]);
158
- sut.obscure (element, 1.0 , defaultBounds);
202
+ sut.obscure (
203
+ context: element,
204
+ pixelRatio: 1.0 ,
205
+ bounds: defaultBounds,
206
+ colorScheme: colorScheme);
159
207
expect (sut.items.length, 1 );
160
208
expect (boundsRect (sut.items[0 ]), '144x48' );
161
209
sut.throwInObscure = true ;
162
- sut.obscure (element, 1.0 , defaultBounds);
210
+ sut.obscure (
211
+ context: element,
212
+ pixelRatio: 1.0 ,
213
+ bounds: defaultBounds,
214
+ colorScheme: colorScheme);
163
215
expect (sut.items.length, 1 );
164
216
expect (boundsRect (sut.items[0 ]), '344x248' );
165
217
});
0 commit comments