diff --git a/engine/src/flutter/shell/common/fixtures/shell_test.dart b/engine/src/flutter/shell/common/fixtures/shell_test.dart index a7727903af..9826d58b95 100644 --- a/engine/src/flutter/shell/common/fixtures/shell_test.dart +++ b/engine/src/flutter/shell/common/fixtures/shell_test.dart @@ -2,7 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async' show scheduleMicrotask; +// ignore_for_file: avoid_print + import 'dart:convert' show json, utf8; import 'dart:isolate'; import 'dart:typed_data'; @@ -78,14 +79,15 @@ void drawFrames() { @pragma('vm:entry-point') void reportTimingsMain() { PlatformDispatcher.instance.onReportTimings = (List timings) { - List timestamps = []; - for (FrameTiming t in timings) { - for (FramePhase phase in FramePhase.values) { + final timestamps = []; + for (final t in timings) { + for (final phase in FramePhase.values) { timestamps.add(t.timestampInMicroseconds(phase)); } } nativeReportTimingsCallback(timestamps); - PlatformDispatcher.instance.onReportTimings = (List timings) {}; + PlatformDispatcher.instance.onReportTimings = + (List timings) {}; }; } @@ -100,8 +102,8 @@ void onBeginFrameMain() { @pragma('vm:entry-point') void onPointerDataPacketMain() { PlatformDispatcher.instance.onPointerDataPacket = (PointerDataPacket packet) { - List sequence = []; - for (PointerData data in packet.data) { + final sequence = []; + for (final data in packet.data) { sequence.add(PointerChange.values.indexOf(data.change)); } nativeOnPointerDataPacket(sequence); @@ -123,7 +125,8 @@ void reportMetrics() { } @pragma('vm:external-name', 'ReportMetrics') -external void _reportMetrics(double devicePixelRatio, double width, double height); +external void _reportMetrics( + double devicePixelRatio, double width, double height); @pragma('vm:entry-point') void dummyReportTimingsMain() { @@ -150,7 +153,7 @@ void thousandCallsToNative() { } void secondaryIsolateMain(String message) { - print('Secondary isolate got message: ' + message); + print('Secondary isolate got message: $message'); notifyNative(); } @@ -162,21 +165,23 @@ void testCanLaunchSecondaryIsolate() { @pragma('vm:entry-point') void testSkiaResourceCacheSendsResponse() { - final PlatformMessageResponseCallback callback = (ByteData? data) { + void callback(ByteData? data) { if (data == null) { - throw 'Response must not be null.'; + throw AssertionError('Response must not be null.'); } final String response = utf8.decode(data.buffer.asUint8List()); - final List jsonResponse = json.decode(response).cast(); - if (jsonResponse[0] != true) { - throw 'Response was not true'; + final jsonResponse = (json.decode(response) as List).cast(); + if (!jsonResponse[0]) { + throw AssertionError('Response was not true'); } notifyNative(); - }; - const String jsonRequest = '''{ - "method": "Skia.setResourceCacheMaxBytes", - "args": 10000 - }'''; + } + + const String jsonRequest = ''' +{ + "method": "Skia.setResourceCacheMaxBytes", + "args": 10000 +}'''; PlatformDispatcher.instance.sendPlatformMessage( 'flutter/skia', ByteData.sublistView(utf8.encode(jsonRequest)), @@ -211,7 +216,10 @@ void canCreateImageFromDecompressedData() { void canAccessIsolateLaunchData() { notifyMessage( utf8.decode( - PlatformDispatcher.instance.getPersistentIsolateData()!.buffer.asUint8List(), + PlatformDispatcher.instance + .getPersistentIsolateData()! + .buffer + .asUint8List(), ), ); } @@ -219,9 +227,11 @@ void canAccessIsolateLaunchData() { @pragma('vm:entry-point') void performanceModeImpactsNotifyIdle() { notifyNativeBool(false); - PlatformDispatcher.instance.requestDartPerformanceMode(DartPerformanceMode.latency); + PlatformDispatcher.instance + .requestDartPerformanceMode(DartPerformanceMode.latency); notifyNativeBool(true); - PlatformDispatcher.instance.requestDartPerformanceMode(DartPerformanceMode.balanced); + PlatformDispatcher.instance + .requestDartPerformanceMode(DartPerformanceMode.balanced); } @pragma('vm:entry-point') @@ -252,12 +262,12 @@ external bool waitFixture(); // Return local date-time as a string, to an hour resolution. So, "2020-07-23 // 14:03:22" will become "2020-07-23 14". String localTimeAsString() { - final now = DateTime.now().toLocal(); - // This is: "$y-$m-$d $h:$min:$sec.$ms$us"; - final timeStr = now.toString(); - // Forward only "$y-$m-$d $h" for timestamp comparison. Not using DateTime - // formatting since package:intl is not available. - return timeStr.split(":")[0]; + final now = DateTime.now().toLocal(); + // This is: "$y-$m-$d $h:$min:$sec.$ms$us"; + final timeStr = now.toString(); + // Forward only "$y-$m-$d $h" for timestamp comparison. Not using DateTime + // formatting since package:intl is not available. + return timeStr.split(':')[0]; } @pragma('vm:entry-point') @@ -279,7 +289,7 @@ external void notifyCanAccessResource(bool success); external void notifySetAssetBundlePath(); @pragma('vm:entry-point') -void canAccessResourceFromAssetDir() async { +Future canAccessResourceFromAssetDir() async { notifySetAssetBundlePath(); window.sendPlatformMessage( 'flutter/assets', @@ -298,12 +308,14 @@ external void notifyNativeWhenEngineSpawn(bool success); @pragma('vm:entry-point') void canReceiveArgumentsWhenEngineRun(List args) { - notifyNativeWhenEngineRun(args.length == 2 && args[0] == 'foo' && args[1] == 'bar'); + notifyNativeWhenEngineRun( + args.length == 2 && args[0] == 'foo' && args[1] == 'bar'); } @pragma('vm:entry-point') void canReceiveArgumentsWhenEngineSpawn(List args) { - notifyNativeWhenEngineSpawn(args.length == 2 && args[0] == 'arg1' && args[1] == 'arg2'); + notifyNativeWhenEngineSpawn( + args.length == 2 && args[0] == 'arg1' && args[1] == 'arg2'); } @pragma('vm:entry-point') @@ -315,38 +327,16 @@ void onBeginFrameWithNotifyNativeMain() { } @pragma('vm:entry-point') -void frameCallback(Object? image, int durationMilliseconds, String decodeError) { +void frameCallback( + Object? image, int durationMilliseconds, String decodeError) { if (image == null) { throw Exception('Expeccted image in frame callback to be non-null'); } } -Picture CreateRedBox(Size size) { - Paint paint = Paint() - ..color = Color.fromARGB(255, 255, 0, 0) - ..style = PaintingStyle.fill; - PictureRecorder baseRecorder = PictureRecorder(); - Canvas canvas = Canvas(baseRecorder); - canvas.drawRect(Rect.fromLTRB(0.0, 0.0, size.width, size.height), paint); - return baseRecorder.endRecording(); -} - -@pragma('vm:entry-point') -void scene_with_red_box() { - PlatformDispatcher.instance.onBeginFrame = (Duration duration) { - SceneBuilder builder = SceneBuilder(); - builder.pushOffset(0.0, 0.0); - builder.addPicture(Offset(0.0, 0.0), CreateRedBox(Size(2.0, 2.0))); - builder.pop(); - PlatformDispatcher.instance.views.first.render(builder.build()); - }; - PlatformDispatcher.instance.scheduleFrame(); -} - @pragma('vm:external-name', 'NativeOnBeforeToImageSync') external void onBeforeToImageSync(); - @pragma('vm:entry-point') Future toImageSync() async { final PictureRecorder recorder = PictureRecorder(); @@ -386,13 +376,9 @@ Future toImageSync() async { } @pragma('vm:entry-point') -Future included() async { +Future included() async {} -} - -Future excluded() async { - -} +Future excluded() async {} class IsolateParam { const IsolateParam(this.sendPort, this.rawHandle); @@ -403,13 +389,13 @@ class IsolateParam { @pragma('vm:entry-point') Future runCallback(IsolateParam param) async { try { - final Future Function() func = PluginUtilities.getCallbackFromHandle( - CallbackHandle.fromRawHandle(param.rawHandle) - )! as Future Function(); + final Future Function() func = + PluginUtilities.getCallbackFromHandle( + CallbackHandle.fromRawHandle(param.rawHandle))! + as Future Function(); await func.call(); param.sendPort.send(true); - } - on NoSuchMethodError { + } on NoSuchMethodError { param.sendPort.send(false); } } @@ -424,13 +410,10 @@ external void notifyDestroyed(); Future testPluginUtilitiesCallbackHandle() async { ReceivePort port = ReceivePort(); await Isolate.spawn( - runCallback, - IsolateParam( - port.sendPort, - PluginUtilities.getCallbackHandle(included)!.toRawHandle() - ), - onError: port.sendPort - ); + runCallback, + IsolateParam(port.sendPort, + PluginUtilities.getCallbackHandle(included)!.toRawHandle()), + onError: port.sendPort); final dynamic result1 = await port.first; if (result1 != true) { print('Expected $result1 to == true'); @@ -441,13 +424,10 @@ Future testPluginUtilitiesCallbackHandle() async { if (const bool.fromEnvironment('dart.vm.product')) { port = ReceivePort(); await Isolate.spawn( - runCallback, - IsolateParam( - port.sendPort, - PluginUtilities.getCallbackHandle(excluded)!.toRawHandle() - ), - onError: port.sendPort - ); + runCallback, + IsolateParam(port.sendPort, + PluginUtilities.getCallbackHandle(excluded)!.toRawHandle()), + onError: port.sendPort); final dynamic result2 = await port.first; if (result2 != false) { print('Expected $result2 to == false'); @@ -463,18 +443,19 @@ Future testPluginUtilitiesCallbackHandle() async { Future testThatAssetLoadingHappensOnWorkerThread() async { try { await ImmutableBuffer.fromAsset('DoesNotExist'); - } catch (err) { /* Do nothing */ } + } catch (err) {/* Do nothing */} notifyNative(); } @pragma('vm:external-name', 'NativeReportViewIdsCallback') -external void nativeReportViewIdsCallback(bool hasImplicitView, List viewIds); +external void nativeReportViewIdsCallback( + bool hasImplicitView, List viewIds); List getCurrentViewIds() { final List result = PlatformDispatcher.instance.views .map((FlutterView view) => view.viewId) .toList() - ..sort(); + ..sort(); assert(result.toSet().length == result.length, 'Unexpected duplicate view ID found: $result'); return result; @@ -498,12 +479,14 @@ bool listEquals(List a, List b) { @pragma('vm:entry-point') void testReportViewIds() { List viewIds = getCurrentViewIds(); - nativeReportViewIdsCallback(PlatformDispatcher.instance.implicitView != null, viewIds); + nativeReportViewIdsCallback( + PlatformDispatcher.instance.implicitView != null, viewIds); PlatformDispatcher.instance.onMetricsChanged = () { final List newViewIds = getCurrentViewIds(); if (!listEquals(viewIds, newViewIds)) { viewIds = newViewIds; - nativeReportViewIdsCallback(PlatformDispatcher.instance.implicitView != null, viewIds); + nativeReportViewIdsCallback( + PlatformDispatcher.instance.implicitView != null, viewIds); } }; } @@ -550,9 +533,7 @@ void renderDummyToView(FlutterView view) { @pragma('vm:entry-point') void onDrawFrameRenderAllViews() { PlatformDispatcher.instance.onDrawFrame = () { - for (final FlutterView view in PlatformDispatcher.instance.views) { - renderDummyToView(view); - } + PlatformDispatcher.instance.views.forEach(renderDummyToView); }; notifyNative(); } @@ -567,7 +548,7 @@ void renderViewsInFrameAndOutOfFrame() { } @pragma('vm:external-name', 'CaptureRootLayer') -external _captureRootLayer(SceneBuilder sceneBuilder); +external void _captureRootLayer(SceneBuilder sceneBuilder); @pragma('vm:entry-point') void renderTwiceForOneView() { @@ -637,17 +618,14 @@ void renderWarmUpImplicitView() { void renderWarmUpView1and2() { bool beginFrameCalled = false; - PlatformDispatcher.instance.scheduleWarmUpFrame( - beginFrame: () { - expect(beginFrameCalled, false); - beginFrameCalled = true; - }, - drawFrame: () { - expect(beginFrameCalled, true); + PlatformDispatcher.instance.scheduleWarmUpFrame(beginFrame: () { + expect(beginFrameCalled, false); + beginFrameCalled = true; + }, drawFrame: () { + expect(beginFrameCalled, true); - for (final int viewId in [1, 2]) { - renderDummyToView(PlatformDispatcher.instance.view(id: viewId)!); - } + for (final int viewId in [1, 2]) { + renderDummyToView(PlatformDispatcher.instance.view(id: viewId)!); } - ); + }); }