Skip to content

Commit 4f9dbf5

Browse files
authored
Cleanup the shell test, removing unused code (flutter#54238)
Guess we'll find out!
1 parent 795c0d8 commit 4f9dbf5

1 file changed

Lines changed: 78 additions & 100 deletions

File tree

shell/common/fixtures/shell_test.dart

Lines changed: 78 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import 'dart:async' show scheduleMicrotask;
5+
// ignore_for_file: avoid_print
6+
67
import 'dart:convert' show json, utf8;
78
import 'dart:isolate';
89
import 'dart:typed_data';
@@ -78,14 +79,15 @@ void drawFrames() {
7879
@pragma('vm:entry-point')
7980
void reportTimingsMain() {
8081
PlatformDispatcher.instance.onReportTimings = (List<FrameTiming> timings) {
81-
List<int> timestamps = [];
82-
for (FrameTiming t in timings) {
83-
for (FramePhase phase in FramePhase.values) {
82+
final timestamps = <int>[];
83+
for (final t in timings) {
84+
for (final phase in FramePhase.values) {
8485
timestamps.add(t.timestampInMicroseconds(phase));
8586
}
8687
}
8788
nativeReportTimingsCallback(timestamps);
88-
PlatformDispatcher.instance.onReportTimings = (List<FrameTiming> timings) {};
89+
PlatformDispatcher.instance.onReportTimings =
90+
(List<FrameTiming> timings) {};
8991
};
9092
}
9193

@@ -100,8 +102,8 @@ void onBeginFrameMain() {
100102
@pragma('vm:entry-point')
101103
void onPointerDataPacketMain() {
102104
PlatformDispatcher.instance.onPointerDataPacket = (PointerDataPacket packet) {
103-
List<int> sequence = <int>[];
104-
for (PointerData data in packet.data) {
105+
final sequence = <int>[];
106+
for (final data in packet.data) {
105107
sequence.add(PointerChange.values.indexOf(data.change));
106108
}
107109
nativeOnPointerDataPacket(sequence);
@@ -123,7 +125,8 @@ void reportMetrics() {
123125
}
124126

125127
@pragma('vm:external-name', 'ReportMetrics')
126-
external void _reportMetrics(double devicePixelRatio, double width, double height);
128+
external void _reportMetrics(
129+
double devicePixelRatio, double width, double height);
127130

128131
@pragma('vm:entry-point')
129132
void dummyReportTimingsMain() {
@@ -150,7 +153,7 @@ void thousandCallsToNative() {
150153
}
151154

152155
void secondaryIsolateMain(String message) {
153-
print('Secondary isolate got message: ' + message);
156+
print('Secondary isolate got message: $message');
154157
notifyNative();
155158
}
156159

@@ -162,21 +165,23 @@ void testCanLaunchSecondaryIsolate() {
162165

163166
@pragma('vm:entry-point')
164167
void testSkiaResourceCacheSendsResponse() {
165-
final PlatformMessageResponseCallback callback = (ByteData? data) {
168+
void callback(ByteData? data) {
166169
if (data == null) {
167-
throw 'Response must not be null.';
170+
throw AssertionError('Response must not be null.');
168171
}
169172
final String response = utf8.decode(data.buffer.asUint8List());
170-
final List<bool> jsonResponse = json.decode(response).cast<bool>();
171-
if (jsonResponse[0] != true) {
172-
throw 'Response was not true';
173+
final jsonResponse = (json.decode(response) as List).cast<bool>();
174+
if (!jsonResponse[0]) {
175+
throw AssertionError('Response was not true');
173176
}
174177
notifyNative();
175-
};
176-
const String jsonRequest = '''{
177-
"method": "Skia.setResourceCacheMaxBytes",
178-
"args": 10000
179-
}''';
178+
}
179+
180+
const String jsonRequest = '''
181+
{
182+
"method": "Skia.setResourceCacheMaxBytes",
183+
"args": 10000
184+
}''';
180185
PlatformDispatcher.instance.sendPlatformMessage(
181186
'flutter/skia',
182187
ByteData.sublistView(utf8.encode(jsonRequest)),
@@ -211,17 +216,22 @@ void canCreateImageFromDecompressedData() {
211216
void canAccessIsolateLaunchData() {
212217
notifyMessage(
213218
utf8.decode(
214-
PlatformDispatcher.instance.getPersistentIsolateData()!.buffer.asUint8List(),
219+
PlatformDispatcher.instance
220+
.getPersistentIsolateData()!
221+
.buffer
222+
.asUint8List(),
215223
),
216224
);
217225
}
218226

219227
@pragma('vm:entry-point')
220228
void performanceModeImpactsNotifyIdle() {
221229
notifyNativeBool(false);
222-
PlatformDispatcher.instance.requestDartPerformanceMode(DartPerformanceMode.latency);
230+
PlatformDispatcher.instance
231+
.requestDartPerformanceMode(DartPerformanceMode.latency);
223232
notifyNativeBool(true);
224-
PlatformDispatcher.instance.requestDartPerformanceMode(DartPerformanceMode.balanced);
233+
PlatformDispatcher.instance
234+
.requestDartPerformanceMode(DartPerformanceMode.balanced);
225235
}
226236

227237
@pragma('vm:entry-point')
@@ -252,12 +262,12 @@ external bool waitFixture();
252262
// Return local date-time as a string, to an hour resolution. So, "2020-07-23
253263
// 14:03:22" will become "2020-07-23 14".
254264
String localTimeAsString() {
255-
final now = DateTime.now().toLocal();
256-
// This is: "$y-$m-$d $h:$min:$sec.$ms$us";
257-
final timeStr = now.toString();
258-
// Forward only "$y-$m-$d $h" for timestamp comparison. Not using DateTime
259-
// formatting since package:intl is not available.
260-
return timeStr.split(":")[0];
265+
final now = DateTime.now().toLocal();
266+
// This is: "$y-$m-$d $h:$min:$sec.$ms$us";
267+
final timeStr = now.toString();
268+
// Forward only "$y-$m-$d $h" for timestamp comparison. Not using DateTime
269+
// formatting since package:intl is not available.
270+
return timeStr.split(':')[0];
261271
}
262272

263273
@pragma('vm:entry-point')
@@ -279,7 +289,7 @@ external void notifyCanAccessResource(bool success);
279289
external void notifySetAssetBundlePath();
280290

281291
@pragma('vm:entry-point')
282-
void canAccessResourceFromAssetDir() async {
292+
Future<void> canAccessResourceFromAssetDir() async {
283293
notifySetAssetBundlePath();
284294
window.sendPlatformMessage(
285295
'flutter/assets',
@@ -298,12 +308,14 @@ external void notifyNativeWhenEngineSpawn(bool success);
298308

299309
@pragma('vm:entry-point')
300310
void canReceiveArgumentsWhenEngineRun(List<String> args) {
301-
notifyNativeWhenEngineRun(args.length == 2 && args[0] == 'foo' && args[1] == 'bar');
311+
notifyNativeWhenEngineRun(
312+
args.length == 2 && args[0] == 'foo' && args[1] == 'bar');
302313
}
303314

304315
@pragma('vm:entry-point')
305316
void canReceiveArgumentsWhenEngineSpawn(List<String> args) {
306-
notifyNativeWhenEngineSpawn(args.length == 2 && args[0] == 'arg1' && args[1] == 'arg2');
317+
notifyNativeWhenEngineSpawn(
318+
args.length == 2 && args[0] == 'arg1' && args[1] == 'arg2');
307319
}
308320

309321
@pragma('vm:entry-point')
@@ -315,38 +327,16 @@ void onBeginFrameWithNotifyNativeMain() {
315327
}
316328

317329
@pragma('vm:entry-point')
318-
void frameCallback(Object? image, int durationMilliseconds, String decodeError) {
330+
void frameCallback(
331+
Object? image, int durationMilliseconds, String decodeError) {
319332
if (image == null) {
320333
throw Exception('Expeccted image in frame callback to be non-null');
321334
}
322335
}
323336

324-
Picture CreateRedBox(Size size) {
325-
Paint paint = Paint()
326-
..color = Color.fromARGB(255, 255, 0, 0)
327-
..style = PaintingStyle.fill;
328-
PictureRecorder baseRecorder = PictureRecorder();
329-
Canvas canvas = Canvas(baseRecorder);
330-
canvas.drawRect(Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint);
331-
return baseRecorder.endRecording();
332-
}
333-
334-
@pragma('vm:entry-point')
335-
void scene_with_red_box() {
336-
PlatformDispatcher.instance.onBeginFrame = (Duration duration) {
337-
SceneBuilder builder = SceneBuilder();
338-
builder.pushOffset(0.0, 0.0);
339-
builder.addPicture(Offset(0.0, 0.0), CreateRedBox(Size(2.0, 2.0)));
340-
builder.pop();
341-
PlatformDispatcher.instance.views.first.render(builder.build());
342-
};
343-
PlatformDispatcher.instance.scheduleFrame();
344-
}
345-
346337
@pragma('vm:external-name', 'NativeOnBeforeToImageSync')
347338
external void onBeforeToImageSync();
348339

349-
350340
@pragma('vm:entry-point')
351341
Future<void> toImageSync() async {
352342
final PictureRecorder recorder = PictureRecorder();
@@ -386,13 +376,9 @@ Future<void> toImageSync() async {
386376
}
387377

388378
@pragma('vm:entry-point')
389-
Future<void> included() async {
390-
391-
}
392-
393-
Future<void> excluded() async {
379+
Future<void> included() async {}
394380

395-
}
381+
Future<void> excluded() async {}
396382

397383
class IsolateParam {
398384
const IsolateParam(this.sendPort, this.rawHandle);
@@ -403,13 +389,13 @@ class IsolateParam {
403389
@pragma('vm:entry-point')
404390
Future<void> runCallback(IsolateParam param) async {
405391
try {
406-
final Future<dynamic> Function() func = PluginUtilities.getCallbackFromHandle(
407-
CallbackHandle.fromRawHandle(param.rawHandle)
408-
)! as Future<dynamic> Function();
392+
final Future<dynamic> Function() func =
393+
PluginUtilities.getCallbackFromHandle(
394+
CallbackHandle.fromRawHandle(param.rawHandle))!
395+
as Future<dynamic> Function();
409396
await func.call();
410397
param.sendPort.send(true);
411-
}
412-
on NoSuchMethodError {
398+
} on NoSuchMethodError {
413399
param.sendPort.send(false);
414400
}
415401
}
@@ -424,13 +410,10 @@ external void notifyDestroyed();
424410
Future<void> testPluginUtilitiesCallbackHandle() async {
425411
ReceivePort port = ReceivePort();
426412
await Isolate.spawn(
427-
runCallback,
428-
IsolateParam(
429-
port.sendPort,
430-
PluginUtilities.getCallbackHandle(included)!.toRawHandle()
431-
),
432-
onError: port.sendPort
433-
);
413+
runCallback,
414+
IsolateParam(port.sendPort,
415+
PluginUtilities.getCallbackHandle(included)!.toRawHandle()),
416+
onError: port.sendPort);
434417
final dynamic result1 = await port.first;
435418
if (result1 != true) {
436419
print('Expected $result1 to == true');
@@ -441,13 +424,10 @@ Future<void> testPluginUtilitiesCallbackHandle() async {
441424
if (const bool.fromEnvironment('dart.vm.product')) {
442425
port = ReceivePort();
443426
await Isolate.spawn(
444-
runCallback,
445-
IsolateParam(
446-
port.sendPort,
447-
PluginUtilities.getCallbackHandle(excluded)!.toRawHandle()
448-
),
449-
onError: port.sendPort
450-
);
427+
runCallback,
428+
IsolateParam(port.sendPort,
429+
PluginUtilities.getCallbackHandle(excluded)!.toRawHandle()),
430+
onError: port.sendPort);
451431
final dynamic result2 = await port.first;
452432
if (result2 != false) {
453433
print('Expected $result2 to == false');
@@ -463,18 +443,19 @@ Future<void> testPluginUtilitiesCallbackHandle() async {
463443
Future<void> testThatAssetLoadingHappensOnWorkerThread() async {
464444
try {
465445
await ImmutableBuffer.fromAsset('DoesNotExist');
466-
} catch (err) { /* Do nothing */ }
446+
} catch (err) {/* Do nothing */}
467447
notifyNative();
468448
}
469449

470450
@pragma('vm:external-name', 'NativeReportViewIdsCallback')
471-
external void nativeReportViewIdsCallback(bool hasImplicitView, List<int> viewIds);
451+
external void nativeReportViewIdsCallback(
452+
bool hasImplicitView, List<int> viewIds);
472453

473454
List<int> getCurrentViewIds() {
474455
final List<int> result = PlatformDispatcher.instance.views
475456
.map((FlutterView view) => view.viewId)
476457
.toList()
477-
..sort();
458+
..sort();
478459
assert(result.toSet().length == result.length,
479460
'Unexpected duplicate view ID found: $result');
480461
return result;
@@ -498,12 +479,14 @@ bool listEquals<T>(List<T> a, List<T> b) {
498479
@pragma('vm:entry-point')
499480
void testReportViewIds() {
500481
List<int> viewIds = getCurrentViewIds();
501-
nativeReportViewIdsCallback(PlatformDispatcher.instance.implicitView != null, viewIds);
482+
nativeReportViewIdsCallback(
483+
PlatformDispatcher.instance.implicitView != null, viewIds);
502484
PlatformDispatcher.instance.onMetricsChanged = () {
503485
final List<int> newViewIds = getCurrentViewIds();
504486
if (!listEquals(viewIds, newViewIds)) {
505487
viewIds = newViewIds;
506-
nativeReportViewIdsCallback(PlatformDispatcher.instance.implicitView != null, viewIds);
488+
nativeReportViewIdsCallback(
489+
PlatformDispatcher.instance.implicitView != null, viewIds);
507490
}
508491
};
509492
}
@@ -550,9 +533,7 @@ void renderDummyToView(FlutterView view) {
550533
@pragma('vm:entry-point')
551534
void onDrawFrameRenderAllViews() {
552535
PlatformDispatcher.instance.onDrawFrame = () {
553-
for (final FlutterView view in PlatformDispatcher.instance.views) {
554-
renderDummyToView(view);
555-
}
536+
PlatformDispatcher.instance.views.forEach(renderDummyToView);
556537
};
557538
notifyNative();
558539
}
@@ -567,7 +548,7 @@ void renderViewsInFrameAndOutOfFrame() {
567548
}
568549

569550
@pragma('vm:external-name', 'CaptureRootLayer')
570-
external _captureRootLayer(SceneBuilder sceneBuilder);
551+
external void _captureRootLayer(SceneBuilder sceneBuilder);
571552

572553
@pragma('vm:entry-point')
573554
void renderTwiceForOneView() {
@@ -637,17 +618,14 @@ void renderWarmUpImplicitView() {
637618
void renderWarmUpView1and2() {
638619
bool beginFrameCalled = false;
639620

640-
PlatformDispatcher.instance.scheduleWarmUpFrame(
641-
beginFrame: () {
642-
expect(beginFrameCalled, false);
643-
beginFrameCalled = true;
644-
},
645-
drawFrame: () {
646-
expect(beginFrameCalled, true);
621+
PlatformDispatcher.instance.scheduleWarmUpFrame(beginFrame: () {
622+
expect(beginFrameCalled, false);
623+
beginFrameCalled = true;
624+
}, drawFrame: () {
625+
expect(beginFrameCalled, true);
647626

648-
for (final int viewId in <int>[1, 2]) {
649-
renderDummyToView(PlatformDispatcher.instance.view(id: viewId)!);
650-
}
627+
for (final int viewId in <int>[1, 2]) {
628+
renderDummyToView(PlatformDispatcher.instance.view(id: viewId)!);
651629
}
652-
);
630+
});
653631
}

0 commit comments

Comments
 (0)