forked from flutter-team-archive/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_test.dart
More file actions
1120 lines (988 loc) · 32.7 KB
/
Copy pathui_test.dart
File metadata and controls
1120 lines (988 loc) · 32.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:typed_data';
import 'dart:ui';
import 'dart:isolate';
import 'dart:ffi' hide Size;
void main() {}
/// Mutiple tests use this to signal to the C++ side that they are ready for
/// validation.
@pragma('vm:external-name', 'Finish')
external void _finish();
@pragma('vm:entry-point')
void customOnErrorTrue() {
PlatformDispatcher.instance.onError = (Object error, StackTrace? stack) {
_finish();
return true;
};
throw Exception('true');
}
@pragma('vm:entry-point')
void customOnErrorFalse() {
PlatformDispatcher.instance.onError = (Object error, StackTrace? stack) {
_finish();
return false;
};
throw Exception('false');
}
@pragma('vm:entry-point')
void customOnErrorThrow() {
PlatformDispatcher.instance.onError = (Object error, StackTrace? stack) {
_finish();
throw Exception('throw2');
};
throw Exception('throw1');
}
@pragma('vm:entry-point')
void setLatencyPerformanceMode() {
PlatformDispatcher.instance.requestDartPerformanceMode(DartPerformanceMode.latency);
_finish();
}
@pragma('vm:entry-point')
void validateSceneBuilderAndScene() {
final SceneBuilder builder = SceneBuilder();
builder.pushOffset(10, 10);
_validateBuilderHasLayers(builder);
final Scene scene = builder.build();
_validateBuilderHasNoLayers();
_captureScene(scene);
scene.dispose();
_validateSceneHasNoLayers();
}
@pragma('vm:external-name', 'ValidateBuilderHasLayers')
external _validateBuilderHasLayers(SceneBuilder builder);
@pragma('vm:external-name', 'ValidateBuilderHasNoLayers')
external _validateBuilderHasNoLayers();
@pragma('vm:external-name', 'CaptureScene')
external _captureScene(Scene scene);
@pragma('vm:external-name', 'ValidateSceneHasNoLayers')
external _validateSceneHasNoLayers();
@pragma('vm:entry-point')
void validateEngineLayerDispose() {
final SceneBuilder builder = SceneBuilder();
final EngineLayer layer = builder.pushOffset(10, 10);
_captureRootLayer(builder);
final Scene scene = builder.build();
scene.dispose();
_validateLayerTreeCounts();
layer.dispose();
_validateEngineLayerDispose();
}
@pragma('vm:external-name', 'CaptureRootLayer')
external _captureRootLayer(SceneBuilder sceneBuilder);
@pragma('vm:external-name', 'ValidateLayerTreeCounts')
external _validateLayerTreeCounts();
@pragma('vm:external-name', 'ValidateEngineLayerDispose')
external _validateEngineLayerDispose();
@pragma('vm:entry-point')
Future<void> createSingleFrameCodec() async {
final ImmutableBuffer buffer = await ImmutableBuffer.fromUint8List(Uint8List.fromList(List<int>.filled(4, 100)));
final ImageDescriptor descriptor = ImageDescriptor.raw(
buffer,
width: 1,
height: 1,
pixelFormat: PixelFormat.rgba8888,
);
final Codec codec = await descriptor.instantiateCodec();
_validateCodec(codec);
final FrameInfo info = await codec.getNextFrame();
info.image.dispose();
_validateCodec(codec);
codec.dispose();
descriptor.dispose();
buffer.dispose();
assert(buffer.debugDisposed);
_finish();
}
@pragma('vm:external-name', 'ValidateCodec')
external void _validateCodec(Codec codec);
@pragma('vm:entry-point')
void createVertices() {
const int uint16max = 65535;
final Int32List colors = Int32List(uint16max);
final Float32List coords = Float32List(uint16max * 2);
final Uint16List indices = Uint16List(uint16max);
final Float32List positions = Float32List(uint16max * 2);
colors[0] = const Color(0xFFFF0000).value;
colors[1] = const Color(0xFF00FF00).value;
colors[2] = const Color(0xFF0000FF).value;
colors[3] = const Color(0xFF00FFFF).value;
indices[1] = indices[3] = 1;
indices[2] = indices[5] = 3;
indices[4] = 2;
positions[2] = positions[4] = positions[5] = positions[7] = 250.0;
final Vertices vertices = Vertices.raw(
VertexMode.triangles,
positions,
textureCoordinates: coords,
colors: colors,
indices: indices,
);
_validateVertices(vertices);
}
@pragma('vm:external-name', 'ValidateVertices')
external void _validateVertices(Vertices vertices);
@pragma('vm:entry-point')
void sendSemanticsUpdate() {
final SemanticsUpdateBuilder builder = SemanticsUpdateBuilder();
final String label = "label";
final List<StringAttribute> labelAttributes = <StringAttribute> [
SpellOutStringAttribute(range: TextRange(start: 1, end: 2)),
];
final String value = "value";
final List<StringAttribute> valueAttributes = <StringAttribute> [
SpellOutStringAttribute(range: TextRange(start: 2, end: 3)),
];
final String increasedValue = "increasedValue";
final List<StringAttribute> increasedValueAttributes = <StringAttribute> [
SpellOutStringAttribute(range: TextRange(start: 4, end: 5)),
];
final String decreasedValue = "decreasedValue";
final List<StringAttribute> decreasedValueAttributes = <StringAttribute> [
SpellOutStringAttribute(range: TextRange(start: 5, end: 6)),
];
final String hint = "hint";
final List<StringAttribute> hintAttributes = <StringAttribute> [
LocaleStringAttribute(
locale: Locale('en', 'MX'), range: TextRange(start: 0, end: 1),
),
];
final Float64List transform = Float64List(16);
final Int32List childrenInTraversalOrder = Int32List(0);
final Int32List childrenInHitTestOrder = Int32List(0);
final Int32List additionalActions = Int32List(0);
transform[0] = 1;
transform[1] = 0;
transform[2] = 0;
transform[3] = 0;
transform[4] = 0;
transform[5] = 1;
transform[6] = 0;
transform[7] = 0;
transform[8] = 0;
transform[9] = 0;
transform[10] = 1;
transform[11] = 0;
transform[12] = 0;
transform[13] = 0;
transform[14] = 0;
transform[15] = 0;
builder.updateNode(
id: 0,
flags: 0,
actions: 0,
maxValueLength: 0,
currentValueLength: 0,
textSelectionBase: -1,
textSelectionExtent: -1,
platformViewId: -1,
scrollChildren: 0,
scrollIndex: 0,
scrollPosition: 0,
scrollExtentMax: 0,
scrollExtentMin: 0,
rect: Rect.fromLTRB(0, 0, 10, 10),
elevation: 0,
thickness: 0,
label: label,
labelAttributes: labelAttributes,
value: value,
valueAttributes: valueAttributes,
increasedValue: increasedValue,
increasedValueAttributes: increasedValueAttributes,
decreasedValue: decreasedValue,
decreasedValueAttributes: decreasedValueAttributes,
hint: hint,
hintAttributes: hintAttributes,
textDirection: TextDirection.ltr,
transform: transform,
childrenInTraversalOrder: childrenInTraversalOrder,
childrenInHitTestOrder: childrenInHitTestOrder,
additionalActions: additionalActions);
_semanticsUpdate(builder.build());
}
@pragma('vm:external-name', 'SemanticsUpdate')
external void _semanticsUpdate(SemanticsUpdate update);
@pragma('vm:entry-point')
void createPath() {
final Path path = Path()..lineTo(10, 10);
_validatePath(path);
// Arbitrarily hold a reference to the path to make sure it does not get
// garbage collected.
Future<void>.delayed(const Duration(days: 100)).then((_) {
path.lineTo(100, 100);
});
}
@pragma('vm:external-name', 'ValidatePath')
external void _validatePath(Path path);
@pragma('vm:entry-point')
void frameCallback(Object? image, int durationMilliseconds, String decodeError) {
validateFrameCallback(image, durationMilliseconds, decodeError);
}
@pragma('vm:external-name', 'ValidateFrameCallback')
external void validateFrameCallback(Object? image, int durationMilliseconds, String decodeError);
@pragma('vm:entry-point')
void platformMessagePortResponseTest() async {
ReceivePort receivePort = ReceivePort();
_callPlatformMessageResponseDartPort(receivePort.sendPort.nativePort);
List<dynamic> resultList = await receivePort.first;
int identifier = resultList[0] as int;
Uint8List? bytes = resultList[1] as Uint8List?;
ByteData result = ByteData.sublistView(bytes!);
if (result.lengthInBytes == 100) {
_finishCallResponse(true);
} else {
_finishCallResponse(false);
}
}
@pragma('vm:entry-point')
void platformMessageResponseTest() {
_callPlatformMessageResponseDart((ByteData? result) {
if (result is UnmodifiableByteDataView &&
result.lengthInBytes == 100) {
_finishCallResponse(true);
} else {
_finishCallResponse(false);
}
});
}
@pragma('vm:external-name', 'CallPlatformMessageResponseDartPort')
external void _callPlatformMessageResponseDartPort(int port);
@pragma('vm:external-name', 'CallPlatformMessageResponseDart')
external void _callPlatformMessageResponseDart(void Function(ByteData? result) callback);
@pragma('vm:external-name', 'FinishCallResponse')
external void _finishCallResponse(bool didPass);
@pragma('vm:entry-point')
void messageCallback(dynamic data) {}
@pragma('vm:entry-point')
@pragma('vm:external-name', 'ValidateConfiguration')
external void validateConfiguration();
// Draw a circle on a Canvas that has a PictureRecorder. Take the image from
// the PictureRecorder, and encode it as png. Check that the png data is
// backed by an external Uint8List.
@pragma('vm:entry-point')
Future<void> encodeImageProducesExternalUint8List() async {
final PictureRecorder pictureRecorder = PictureRecorder();
final Canvas canvas = Canvas(pictureRecorder);
final Paint paint = Paint()
..color = Color.fromRGBO(255, 255, 255, 1.0)
..style = PaintingStyle.fill;
final Offset c = Offset(50.0, 50.0);
canvas.drawCircle(c, 25.0, paint);
final Picture picture = pictureRecorder.endRecording();
final Image image = await picture.toImage(100, 100);
_encodeImage(image, ImageByteFormat.png.index, (Uint8List result) {
// The buffer should be non-null and writable.
result[0] = 0;
// The buffer should be external typed data.
_validateExternal(result);
});
}
@pragma('vm:external-name', 'EncodeImage')
external void _encodeImage(Image i, int format, void Function(Uint8List result));
@pragma('vm:external-name', 'ValidateExternal')
external void _validateExternal(Uint8List result);
@pragma('vm:entry-point')
Future<void> pumpImage() async {
const int width = 60;
const int height = 60;
final Completer<Image> completer = Completer<Image>();
decodeImageFromPixels(
Uint8List.fromList(List<int>.filled(width * height * 4, 0xFF)),
width,
height,
PixelFormat.rgba8888,
(Image image) => completer.complete(image),
);
final Image image = await completer.future;
late Picture picture;
late OffsetEngineLayer layer;
void renderBlank(Duration duration) {
image.dispose();
picture.dispose();
layer.dispose();
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.drawPaint(Paint());
picture = recorder.endRecording();
final SceneBuilder builder = SceneBuilder();
layer = builder.pushOffset(0, 0);
builder.addPicture(Offset.zero, picture);
final Scene scene = builder.build();
window.render(scene);
scene.dispose();
_finish();
}
void renderImage(Duration duration) {
final PictureRecorder recorder = PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.drawImage(image, Offset.zero, Paint());
picture = recorder.endRecording();
final SceneBuilder builder = SceneBuilder();
layer = builder.pushOffset(0, 0);
builder.addPicture(Offset.zero, picture);
_captureImageAndPicture(image, picture);
final Scene scene = builder.build();
window.render(scene);
scene.dispose();
window.onBeginFrame = renderBlank;
window.scheduleFrame();
}
window.onBeginFrame = renderImage;
window.scheduleFrame();
}
@pragma('vm:external-name', 'CaptureImageAndPicture')
external void _captureImageAndPicture(Image image, Picture picture);
@pragma('vm:entry-point')
void convertPaintToDlPaint() {
Paint paint = Paint();
paint.blendMode = BlendMode.modulate;
paint.color = Color.fromARGB(0x11, 0x22, 0x33, 0x44);
paint.colorFilter = ColorFilter.mode(Color.fromARGB(0x55, 0x66, 0x77, 0x88), BlendMode.xor);
paint.maskFilter = MaskFilter.blur(BlurStyle.inner, .75);
paint.style = PaintingStyle.stroke;
_convertPaintToDlPaint(paint);
}
@pragma('vm:external-name', 'ConvertPaintToDlPaint')
external void _convertPaintToDlPaint(Paint paint);
@pragma('vm:entry-point')
void hooksTests() async {
Future<void> test(String name, FutureOr<void> Function() testFunction) async {
try {
await testFunction();
} catch (e) {
print('Test "$name" failed!');
rethrow;
}
}
void expectEquals(Object? value, Object? expected) {
if (value != expected) {
throw 'Expected $value to be $expected.';
}
}
void expectIdentical(Object a, Object b) {
if (!identical(a, b)) {
throw 'Expected $a to be identical to $b.';
}
}
void expectNotEquals(Object? value, Object? expected) {
if (value == expected) {
throw 'Expected $value to not be $expected.';
}
}
await test('onMetricsChanged preserves callback zone', () {
late Zone originalZone;
late Zone callbackZone;
late double devicePixelRatio;
runZoned(() {
originalZone = Zone.current;
window.onMetricsChanged = () {
callbackZone = Zone.current;
devicePixelRatio = window.devicePixelRatio;
};
});
window.onMetricsChanged!();
_callHook(
'_updateWindowMetrics',
21,
0, // window Id
0.1234, // device pixel ratio
0.0, // width
0.0, // height
0.0, // padding top
0.0, // padding right
0.0, // padding bottom
0.0, // padding left
0.0, // inset top
0.0, // inset right
0.0, // inset bottom
0.0, // inset left
0.0, // system gesture inset top
0.0, // system gesture inset right
0.0, // system gesture inset bottom
0.0, // system gesture inset left
22.0, // physicalTouchSlop
<double>[], // display features bounds
<int>[], // display features types
<int>[], // display features states
0, // Display ID
);
expectIdentical(originalZone, callbackZone);
if (devicePixelRatio != 0.1234) {
throw 'Expected devicePixelRatio to be 0.1234 but got $devicePixelRatio.';
}
});
await test('onError preserves the callback zone', () {
late Zone originalZone;
late Zone callbackZone;
final Object error = Exception('foo');
StackTrace? stackTrace;
runZoned(() {
originalZone = Zone.current;
PlatformDispatcher.instance.onError = (Object exception, StackTrace? stackTrace) {
callbackZone = Zone.current;
expectIdentical(exception, error);
expectNotEquals(stackTrace, null);
return true;
};
});
_callHook('_onError', 2, error, StackTrace.current);
PlatformDispatcher.instance.onError = null;
expectIdentical(originalZone, callbackZone);
});
await test('updateUserSettings can handle an empty object', () {
_callHook('_updateUserSettingsData', 1, '{}');
});
await test('PlatformDispatcher.locale returns unknown locale when locales is set to empty list', () {
late Locale locale;
int callCount = 0;
runZoned(() {
window.onLocaleChanged = () {
locale = PlatformDispatcher.instance.locale;
callCount += 1;
};
});
const Locale fakeLocale = Locale.fromSubtags(languageCode: '1', countryCode: '2', scriptCode: '3');
_callHook('_updateLocales', 1, <String>[fakeLocale.languageCode, fakeLocale.countryCode!, fakeLocale.scriptCode!, '']);
if (callCount != 1) {
throw 'Expected 1 call, have $callCount';
}
if (locale != fakeLocale) {
throw 'Expected $locale to match $fakeLocale';
}
_callHook('_updateLocales', 1, <String>[]);
if (callCount != 2) {
throw 'Expected 2 calls, have $callCount';
}
if (locale != const Locale.fromSubtags()) {
throw '$locale did not equal ${Locale.fromSubtags()}';
}
if (locale.languageCode != 'und') {
throw '${locale.languageCode} did not equal "und"';
}
});
await test('deprecated region equals', () {
// These are equal because ZR is deprecated and was mapped to CD.
const Locale x = Locale('en', 'ZR');
const Locale y = Locale('en', 'CD');
expectEquals(x, y);
expectEquals(x.countryCode, y.countryCode);
});
await test('PlatformDispatcher.view getter returns view with provided ID', () {
const int viewId = 0;
expectEquals(PlatformDispatcher.instance.view(id: viewId)?.viewId, viewId);
});
await test('View padding/insets/viewPadding/systemGestureInsets', () {
_callHook(
'_updateWindowMetrics',
21,
0, // window Id
1.0, // devicePixelRatio
800.0, // width
600.0, // height
50.0, // paddingTop
0.0, // paddingRight
40.0, // paddingBottom
0.0, // paddingLeft
0.0, // insetTop
0.0, // insetRight
0.0, // insetBottom
0.0, // insetLeft
0.0, // systemGestureInsetTop
0.0, // systemGestureInsetRight
0.0, // systemGestureInsetBottom
0.0, // systemGestureInsetLeft
22.0, // physicalTouchSlop
<double>[], // display features bounds
<int>[], // display features types
<int>[], // display features states
0, // Display ID
);
expectEquals(window.viewInsets.bottom, 0.0);
expectEquals(window.viewPadding.bottom, 40.0);
expectEquals(window.padding.bottom, 40.0);
expectEquals(window.systemGestureInsets.bottom, 0.0);
_callHook(
'_updateWindowMetrics',
21,
0, // window Id
1.0, // devicePixelRatio
800.0, // width
600.0, // height
50.0, // paddingTop
0.0, // paddingRight
40.0, // paddingBottom
0.0, // paddingLeft
0.0, // insetTop
0.0, // insetRight
400.0, // insetBottom
0.0, // insetLeft
0.0, // systemGestureInsetTop
0.0, // systemGestureInsetRight
44.0, // systemGestureInsetBottom
0.0, // systemGestureInsetLeft
22.0, // physicalTouchSlop
<double>[], // display features bounds
<int>[], // display features types
<int>[], // display features states
0, // Display ID
);
expectEquals(window.viewInsets.bottom, 400.0);
expectEquals(window.viewPadding.bottom, 40.0);
expectEquals(window.padding.bottom, 0.0);
expectEquals(window.systemGestureInsets.bottom, 44.0);
});
await test('Window physical touch slop', () {
_callHook(
'_updateWindowMetrics',
21,
0, // window Id
1.0, // devicePixelRatio
800.0, // width
600.0, // height
50.0, // paddingTop
0.0, // paddingRight
40.0, // paddingBottom
0.0, // paddingLeft
0.0, // insetTop
0.0, // insetRight
0.0, // insetBottom
0.0, // insetLeft
0.0, // systemGestureInsetTop
0.0, // systemGestureInsetRight
0.0, // systemGestureInsetBottom
0.0, // systemGestureInsetLeft
11.0, // physicalTouchSlop
<double>[], // display features bounds
<int>[], // display features types
<int>[], // display features states
0, // Display ID
);
expectEquals(window.gestureSettings,
GestureSettings(physicalTouchSlop: 11.0));
_callHook(
'_updateWindowMetrics',
21,
0, // window Id
1.0, // devicePixelRatio
800.0, // width
600.0, // height
50.0, // paddingTop
0.0, // paddingRight
40.0, // paddingBottom
0.0, // paddingLeft
0.0, // insetTop
0.0, // insetRight
400.0, // insetBottom
0.0, // insetLeft
0.0, // systemGestureInsetTop
0.0, // systemGestureInsetRight
44.0, // systemGestureInsetBottom
0.0, // systemGestureInsetLeft
-1.0, // physicalTouchSlop
<double>[], // display features bounds
<int>[], // display features types
<int>[], // display features states
0, // Display ID
);
expectEquals(window.gestureSettings,
GestureSettings(physicalTouchSlop: null));
_callHook(
'_updateWindowMetrics',
21,
0, // window Id
1.0, // devicePixelRatio
800.0, // width
600.0, // height
50.0, // paddingTop
0.0, // paddingRight
40.0, // paddingBottom
0.0, // paddingLeft
0.0, // insetTop
0.0, // insetRight
400.0, // insetBottom
0.0, // insetLeft
0.0, // systemGestureInsetTop
0.0, // systemGestureInsetRight
44.0, // systemGestureInsetBottom
0.0, // systemGestureInsetLeft
22.0, // physicalTouchSlop
<double>[], // display features bounds
<int>[], // display features types
<int>[], // display features states
0, // Display ID
);
expectEquals(window.gestureSettings,
GestureSettings(physicalTouchSlop: 22.0));
});
await test('onLocaleChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
Locale? locale;
runZoned(() {
innerZone = Zone.current;
window.onLocaleChanged = () {
runZone = Zone.current;
locale = window.locale;
};
});
_callHook('_updateLocales', 1, <String>['en', 'US', '', '']);
expectIdentical(runZone, innerZone);
expectEquals(locale, const Locale('en', 'US'));
});
await test('onBeginFrame preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late Duration start;
runZoned(() {
innerZone = Zone.current;
window.onBeginFrame = (Duration value) {
runZone = Zone.current;
start = value;
};
});
_callHook('_beginFrame', 2, 1234, 1);
expectIdentical(runZone, innerZone);
expectEquals(start, const Duration(microseconds: 1234));
});
await test('onDrawFrame preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
runZoned(() {
innerZone = Zone.current;
window.onDrawFrame = () {
runZone = Zone.current;
};
});
_callHook('_drawFrame');
expectIdentical(runZone, innerZone);
});
await test('onReportTimings preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
runZoned(() {
innerZone = Zone.current;
window.onReportTimings = (List<FrameTiming> timings) {
runZone = Zone.current;
};
});
_callHook('_reportTimings', 1, <int>[]);
expectIdentical(runZone, innerZone);
});
await test('onPointerDataPacket preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late PointerDataPacket data;
runZoned(() {
innerZone = Zone.current;
window.onPointerDataPacket = (PointerDataPacket value) {
runZone = Zone.current;
data = value;
};
});
final ByteData testData = ByteData.view(Uint8List(0).buffer);
_callHook('_dispatchPointerDataPacket', 1, testData);
expectIdentical(runZone, innerZone);
expectEquals(data.data.length, 0);
});
await test('onSemanticsEnabledChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late bool enabled;
runZoned(() {
innerZone = Zone.current;
window.onSemanticsEnabledChanged = () {
runZone = Zone.current;
enabled = window.semanticsEnabled;
};
});
final bool newValue = !window.semanticsEnabled; // needed?
_callHook('_updateSemanticsEnabled', 1, newValue);
expectIdentical(runZone, innerZone);
expectEquals(enabled, newValue);
});
await test('onSemanticsActionEvent preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late SemanticsActionEvent action;
runZoned(() {
innerZone = Zone.current;
PlatformDispatcher.instance.onSemanticsActionEvent = (SemanticsActionEvent actionEvent) {
runZone = Zone.current;
action = actionEvent;
};
});
_callHook('_dispatchSemanticsAction', 3, 1234, 4, null);
expectIdentical(runZone, innerZone);
expectEquals(action.nodeId, 1234);
expectEquals(action.type.index, 4);
});
await test('onPlatformMessage preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late String name;
runZoned(() {
innerZone = Zone.current;
window.onPlatformMessage = (String value, _, __) {
runZone = Zone.current;
name = value;
};
});
_callHook('_dispatchPlatformMessage', 3, 'testName', null, 123456789);
expectIdentical(runZone, innerZone);
expectEquals(name, 'testName');
});
await test('onTextScaleFactorChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZoneTextScaleFactor;
late Zone runZonePlatformBrightness;
late double? textScaleFactor;
late Brightness? platformBrightness;
runZoned(() {
innerZone = Zone.current;
window.onTextScaleFactorChanged = () {
runZoneTextScaleFactor = Zone.current;
textScaleFactor = window.textScaleFactor;
};
window.onPlatformBrightnessChanged = () {
runZonePlatformBrightness = Zone.current;
platformBrightness = window.platformBrightness;
};
});
window.onTextScaleFactorChanged!();
_callHook('_updateUserSettingsData', 1, '{"textScaleFactor": 0.5, "platformBrightness": "light", "alwaysUse24HourFormat": true}');
expectIdentical(runZoneTextScaleFactor, innerZone);
expectEquals(textScaleFactor, 0.5);
textScaleFactor = null;
platformBrightness = null;
window.onPlatformBrightnessChanged!();
_callHook('_updateUserSettingsData', 1, '{"textScaleFactor": 0.5, "platformBrightness": "dark", "alwaysUse24HourFormat": true}');
expectIdentical(runZonePlatformBrightness, innerZone);
expectEquals(platformBrightness, Brightness.dark);
});
await test('onFrameDataChanged preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late int frameNumber;
runZoned(() {
innerZone = Zone.current;
window.onFrameDataChanged = () {
runZone = Zone.current;
frameNumber = window.frameData.frameNumber;
};
});
_callHook('_beginFrame', 2, 0, 2);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectEquals(frameNumber, 2);
});
await test('_updateDisplays preserves callback zone', () {
late Zone innerZone;
late Zone runZone;
late Display display;
runZoned(() {
innerZone = Zone.current;
window.onMetricsChanged = () {
runZone = Zone.current;
display = PlatformDispatcher.instance.displays.first;
};
});
_callHook('_updateDisplays', 5, <int>[0], <double>[800], <double>[600], <double>[1.5], <double>[65]);
expectNotEquals(runZone, null);
expectIdentical(runZone, innerZone);
expectEquals(display.id, 0);
expectEquals(display.size, const Size(800, 600));
expectEquals(display.devicePixelRatio, 1.5);
expectEquals(display.refreshRate, 65);
});
await test('_futureize handles callbacker sync error', () async {
String? callbacker(void Function(Object? arg) cb) {
return 'failure';
}
Object? error;
try {
await _futurize(callbacker);
} catch (err) {
error = err;
}
expectNotEquals(error, null);
});
await test('_futureize does not leak sync uncaught exceptions into the zone', () async {
String? callbacker(void Function(Object? arg) cb) {
cb(null); // indicates failure
}
Object? error;
try {
await _futurize(callbacker);
} catch (err) {
error = err;
}
expectNotEquals(error, null);
});
await test('_futureize does not leak async uncaught exceptions into the zone', () async {
String? callbacker(void Function(Object? arg) cb) {
Timer.run(() {
cb(null); // indicates failure
});
}
Object? error;
try {
await _futurize(callbacker);
} catch (err) {
error = err;
}
expectNotEquals(error, null);
});
await test('_futureize successfully returns a value sync', () async {
String? callbacker(void Function(Object? arg) cb) {
cb(true);
}
final Object? result = await _futurize(callbacker);
expectEquals(result, true);
});
await test('_futureize successfully returns a value async', () async {
String? callbacker(void Function(Object? arg) cb) {
Timer.run(() {
cb(true);
});
}
final Object? result = await _futurize(callbacker);
expectEquals(result, true);
});
await test('root isolate token', () async {
if (RootIsolateToken.instance == null) {
throw Exception('We should have a token on a root isolate.');
}
ReceivePort receivePort = ReceivePort();
Isolate.spawn(_backgroundRootIsolateTestMain, receivePort.sendPort);
bool didPass = await receivePort.first as bool;
if (!didPass) {
throw Exception('Background isolate found a root isolate id.');
}
});
await test('send port message without registering', () async {
ReceivePort receivePort = ReceivePort();
Isolate.spawn(_backgroundIsolateSendWithoutRegistering, receivePort.sendPort);
bool didError = await receivePort.first as bool;
if (!didError) {
throw Exception('Expected an error when not registering a root isolate and sending port messages.');
}
});
_finish();
}
/// Sends `true` on [port] if the isolate executing the function is not a root