Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the `engine` subdirectory and enforces that these files stay formatted with a presubmit check. **Reviewers:** Please carefully review all the commits except for the one titled "formatted". The "formatted" commit was auto-generated by running `dev/tools/format.sh -a -f`. The other commits were hand-crafted to prepare the repo for the formatting change. I recommend reviewing the commits one-by-one via the "Commits" tab and avoiding Github's "Files changed" tab as it will likely slow down your browser because of the size of this PR. --------- Co-authored-by: Kate Lovett <katelovett@google.com> Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -10,81 +10,69 @@ import 'package:integration_test/integration_test.dart';
|
||||
import 'package:macrobenchmarks/src/simple_scroll.dart';
|
||||
|
||||
void main() {
|
||||
final IntegrationTestWidgetsFlutterBinding binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
testWidgets(
|
||||
'Frame Counter and Input Delay for benchmarkLive',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: SimpleScroll())));
|
||||
await tester.pumpAndSettle();
|
||||
final Offset location = tester.getCenter(find.byType(ListView));
|
||||
int frameCount = 0;
|
||||
void frameCounter(Duration elapsed) {
|
||||
frameCount += 1;
|
||||
}
|
||||
tester.binding.addPersistentFrameCallback(frameCounter);
|
||||
final IntegrationTestWidgetsFlutterBinding binding =
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
testWidgets('Frame Counter and Input Delay for benchmarkLive', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: SimpleScroll())));
|
||||
await tester.pumpAndSettle();
|
||||
final Offset location = tester.getCenter(find.byType(ListView));
|
||||
int frameCount = 0;
|
||||
void frameCounter(Duration elapsed) {
|
||||
frameCount += 1;
|
||||
}
|
||||
|
||||
const int timeInSecond = 1;
|
||||
const Duration totalTime = Duration(seconds: timeInSecond);
|
||||
const int moveEventNumber = timeInSecond * 120; // 120Hz
|
||||
const Offset movePerRun = Offset(0.0, -200.0 / moveEventNumber);
|
||||
final List<PointerEventRecord> records = <PointerEventRecord>[
|
||||
PointerEventRecord(Duration.zero, <PointerEvent>[
|
||||
PointerAddedEvent(
|
||||
position: location,
|
||||
),
|
||||
PointerDownEvent(
|
||||
position: location,
|
||||
pointer: 1,
|
||||
),
|
||||
]),
|
||||
...<PointerEventRecord>[
|
||||
for (int t=0; t < moveEventNumber; t++)
|
||||
PointerEventRecord(totalTime * (t / moveEventNumber), <PointerEvent>[
|
||||
PointerMoveEvent(
|
||||
timeStamp: totalTime * (t / moveEventNumber),
|
||||
position: location + movePerRun * t.toDouble(),
|
||||
pointer: 1,
|
||||
delta: movePerRun,
|
||||
),
|
||||
]),
|
||||
],
|
||||
PointerEventRecord(totalTime, <PointerEvent>[
|
||||
PointerUpEvent(
|
||||
// Deviate a little from integer number of frames to reduce flakiness
|
||||
timeStamp: totalTime - const Duration(milliseconds: 1),
|
||||
position: location + movePerRun * moveEventNumber.toDouble(),
|
||||
pointer: 1,
|
||||
),
|
||||
]),
|
||||
];
|
||||
tester.binding.addPersistentFrameCallback(frameCounter);
|
||||
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive;
|
||||
List<Duration> delays = await tester.handlePointerEventRecord(records);
|
||||
await tester.pumpAndSettle();
|
||||
binding.reportData = <String, dynamic>{
|
||||
'benchmarkLive': _summarizeResult(frameCount, delays),
|
||||
};
|
||||
await tester.idle();
|
||||
await tester.binding.delayed(const Duration(milliseconds: 250));
|
||||
const int timeInSecond = 1;
|
||||
const Duration totalTime = Duration(seconds: timeInSecond);
|
||||
const int moveEventNumber = timeInSecond * 120; // 120Hz
|
||||
const Offset movePerRun = Offset(0.0, -200.0 / moveEventNumber);
|
||||
final List<PointerEventRecord> records = <PointerEventRecord>[
|
||||
PointerEventRecord(Duration.zero, <PointerEvent>[
|
||||
PointerAddedEvent(position: location),
|
||||
PointerDownEvent(position: location, pointer: 1),
|
||||
]),
|
||||
...<PointerEventRecord>[
|
||||
for (int t = 0; t < moveEventNumber; t++)
|
||||
PointerEventRecord(totalTime * (t / moveEventNumber), <PointerEvent>[
|
||||
PointerMoveEvent(
|
||||
timeStamp: totalTime * (t / moveEventNumber),
|
||||
position: location + movePerRun * t.toDouble(),
|
||||
pointer: 1,
|
||||
delta: movePerRun,
|
||||
),
|
||||
]),
|
||||
],
|
||||
PointerEventRecord(totalTime, <PointerEvent>[
|
||||
PointerUpEvent(
|
||||
// Deviate a little from integer number of frames to reduce flakiness
|
||||
timeStamp: totalTime - const Duration(milliseconds: 1),
|
||||
position: location + movePerRun * moveEventNumber.toDouble(),
|
||||
pointer: 1,
|
||||
),
|
||||
]),
|
||||
];
|
||||
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
|
||||
frameCount = 0;
|
||||
delays = await tester.handlePointerEventRecord(records);
|
||||
await tester.pumpAndSettle();
|
||||
binding.reportData!['fullyLive'] = _summarizeResult(frameCount, delays);
|
||||
await tester.idle();
|
||||
},
|
||||
);
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive;
|
||||
List<Duration> delays = await tester.handlePointerEventRecord(records);
|
||||
await tester.pumpAndSettle();
|
||||
binding.reportData = <String, dynamic>{'benchmarkLive': _summarizeResult(frameCount, delays)};
|
||||
await tester.idle();
|
||||
await tester.binding.delayed(const Duration(milliseconds: 250));
|
||||
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fullyLive;
|
||||
frameCount = 0;
|
||||
delays = await tester.handlePointerEventRecord(records);
|
||||
await tester.pumpAndSettle();
|
||||
binding.reportData!['fullyLive'] = _summarizeResult(frameCount, delays);
|
||||
await tester.idle();
|
||||
});
|
||||
}
|
||||
|
||||
Map<String, dynamic> _summarizeResult(
|
||||
final int frameCount,
|
||||
final List<Duration> delays,
|
||||
) {
|
||||
Map<String, dynamic> _summarizeResult(final int frameCount, final List<Duration> delays) {
|
||||
assert(delays.length > 1);
|
||||
final List<int> delayedInMicro = delays.map<int>(
|
||||
(Duration delay) => delay.inMicroseconds,
|
||||
).toList();
|
||||
final List<int> delayedInMicro =
|
||||
delays.map<int>((Duration delay) => delay.inMicroseconds).toList();
|
||||
final List<int> delayedInMicroSorted = List<int>.from(delayedInMicro)..sort();
|
||||
final int index90th = (delayedInMicroSorted.length * 0.90).round();
|
||||
final int percentile90th = delayedInMicroSorted[index90th];
|
||||
@@ -94,7 +82,6 @@ Map<String, dynamic> _summarizeResult(
|
||||
'frame_count': frameCount,
|
||||
'average_delay_millis': averageDelay / 1E3,
|
||||
'90th_percentile_delay_millis': percentile90th / 1E3,
|
||||
if (kDebugMode)
|
||||
'delaysInMicro': delayedInMicro,
|
||||
if (kDebugMode) 'delaysInMicro': delayedInMicro,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -11,7 +11,10 @@ void main() {
|
||||
'opacity_peephole_col_of_alpha_save_layer_rows',
|
||||
<ScrollableButtonRoute>[
|
||||
ScrollableButtonRoute(kScrollableName, kOpacityPeepholeRouteName),
|
||||
ScrollableButtonRoute(kOpacityScrollableName, kOpacityPeepholeColumnOfAlphaSaveLayerRowsOfRectsRouteName),
|
||||
ScrollableButtonRoute(
|
||||
kOpacityScrollableName,
|
||||
kOpacityPeepholeColumnOfAlphaSaveLayerRowsOfRectsRouteName,
|
||||
),
|
||||
],
|
||||
pageDelay: const Duration(seconds: 1),
|
||||
duration: const Duration(seconds: 10),
|
||||
|
||||
@@ -11,7 +11,10 @@ void main() {
|
||||
'opacity_peephole_grid_of_alpha_savelayers',
|
||||
<ScrollableButtonRoute>[
|
||||
ScrollableButtonRoute(kScrollableName, kOpacityPeepholeRouteName),
|
||||
ScrollableButtonRoute(kOpacityScrollableName, kOpacityPeepholeGridOfAlphaSaveLayerRectsRouteName),
|
||||
ScrollableButtonRoute(
|
||||
kOpacityScrollableName,
|
||||
kOpacityPeepholeGridOfAlphaSaveLayerRectsRouteName,
|
||||
),
|
||||
],
|
||||
pageDelay: const Duration(seconds: 1),
|
||||
duration: const Duration(seconds: 10),
|
||||
|
||||
@@ -24,6 +24,7 @@ void main() {
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i += 1) {
|
||||
await scrollOnce(-300.0);
|
||||
await scrollOnce(-300.0);
|
||||
|
||||
@@ -27,9 +27,7 @@ void macroPerfTestE2E(
|
||||
}) {
|
||||
macroPerfTestMultiPageE2E(
|
||||
testName,
|
||||
<ScrollableButtonRoute>[
|
||||
ScrollableButtonRoute(kScrollableName, routeName),
|
||||
],
|
||||
<ScrollableButtonRoute>[ScrollableButtonRoute(kScrollableName, routeName)],
|
||||
pageDelay: pageDelay,
|
||||
duration: duration,
|
||||
body: body,
|
||||
@@ -38,70 +36,76 @@ void macroPerfTestE2E(
|
||||
}
|
||||
|
||||
void macroPerfTestMultiPageE2E(
|
||||
String testName,
|
||||
List<ScrollableButtonRoute> routes, {
|
||||
Duration? pageDelay,
|
||||
Duration duration = const Duration(seconds: 3),
|
||||
ControlCallback? body,
|
||||
ControlCallback? setup,
|
||||
}) {
|
||||
String testName,
|
||||
List<ScrollableButtonRoute> routes, {
|
||||
Duration? pageDelay,
|
||||
Duration duration = const Duration(seconds: 3),
|
||||
ControlCallback? body,
|
||||
ControlCallback? setup,
|
||||
}) {
|
||||
final WidgetsBinding widgetsBinding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
assert(widgetsBinding is IntegrationTestWidgetsFlutterBinding);
|
||||
final IntegrationTestWidgetsFlutterBinding binding = widgetsBinding as IntegrationTestWidgetsFlutterBinding;
|
||||
final IntegrationTestWidgetsFlutterBinding binding =
|
||||
widgetsBinding as IntegrationTestWidgetsFlutterBinding;
|
||||
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive;
|
||||
|
||||
testWidgets(testName, (WidgetTester tester) async {
|
||||
assert(tester.binding == binding);
|
||||
app.main();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// The slight initial delay avoids starting the timing during a
|
||||
// period of increased load on the device. Without this delay, the
|
||||
// benchmark has greater noise.
|
||||
// See: https://github.com/flutter/flutter/issues/19434
|
||||
await tester.binding.delayed(const Duration(microseconds: 250));
|
||||
|
||||
for (final ScrollableButtonRoute route in routes) {
|
||||
expect(route.listViewKey, startsWith('/'));
|
||||
expect(route.buttonKey, startsWith('/'));
|
||||
|
||||
// Make sure each list view page is settled
|
||||
testWidgets(
|
||||
testName,
|
||||
(WidgetTester tester) async {
|
||||
assert(tester.binding == binding);
|
||||
app.main();
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final Finder listView = find.byKey(ValueKey<String>(route.listViewKey));
|
||||
// ListView is not a Scrollable, but it contains one
|
||||
final Finder scrollable = find.descendant(of: listView, matching: find.byType(Scrollable));
|
||||
// scrollable should find one widget as soon as the page is loaded
|
||||
expect(scrollable, findsOneWidget);
|
||||
// The slight initial delay avoids starting the timing during a
|
||||
// period of increased load on the device. Without this delay, the
|
||||
// benchmark has greater noise.
|
||||
// See: https://github.com/flutter/flutter/issues/19434
|
||||
await tester.binding.delayed(const Duration(microseconds: 250));
|
||||
|
||||
final Finder button = find.byKey(ValueKey<String>(route.buttonKey), skipOffstage: false);
|
||||
// button may or may not find a widget right away until we scroll to it
|
||||
await tester.scrollUntilVisible(button, 50, scrollable: scrollable);
|
||||
// After scrolling, button should find one Widget
|
||||
expect(button, findsOneWidget);
|
||||
for (final ScrollableButtonRoute route in routes) {
|
||||
expect(route.listViewKey, startsWith('/'));
|
||||
expect(route.buttonKey, startsWith('/'));
|
||||
|
||||
// Allow scrolling to settle
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(button);
|
||||
// Cannot be pumpAndSettle because some tests have infinite animation.
|
||||
await tester.pump(const Duration(milliseconds: 20));
|
||||
}
|
||||
// Make sure each list view page is settled
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
if (pageDelay != null) {
|
||||
// Wait for the page to load
|
||||
await tester.binding.delayed(pageDelay);
|
||||
}
|
||||
final Finder listView = find.byKey(ValueKey<String>(route.listViewKey));
|
||||
// ListView is not a Scrollable, but it contains one
|
||||
final Finder scrollable = find.descendant(of: listView, matching: find.byType(Scrollable));
|
||||
// scrollable should find one widget as soon as the page is loaded
|
||||
expect(scrollable, findsOneWidget);
|
||||
|
||||
if (setup != null) {
|
||||
await setup(tester);
|
||||
}
|
||||
final Finder button = find.byKey(ValueKey<String>(route.buttonKey), skipOffstage: false);
|
||||
// button may or may not find a widget right away until we scroll to it
|
||||
await tester.scrollUntilVisible(button, 50, scrollable: scrollable);
|
||||
// After scrolling, button should find one Widget
|
||||
expect(button, findsOneWidget);
|
||||
|
||||
await binding.watchPerformance(() async {
|
||||
final Future<void> durationFuture = tester.binding.delayed(duration);
|
||||
if (body != null) {
|
||||
await body(tester);
|
||||
// Allow scrolling to settle
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(button);
|
||||
// Cannot be pumpAndSettle because some tests have infinite animation.
|
||||
await tester.pump(const Duration(milliseconds: 20));
|
||||
}
|
||||
await durationFuture;
|
||||
});
|
||||
}, semanticsEnabled: false, timeout: Timeout.none);
|
||||
|
||||
if (pageDelay != null) {
|
||||
// Wait for the page to load
|
||||
await tester.binding.delayed(pageDelay);
|
||||
}
|
||||
|
||||
if (setup != null) {
|
||||
await setup(tester);
|
||||
}
|
||||
|
||||
await binding.watchPerformance(() async {
|
||||
final Future<void> durationFuture = tester.binding.delayed(duration);
|
||||
if (body != null) {
|
||||
await body(tester);
|
||||
}
|
||||
await durationFuture;
|
||||
});
|
||||
},
|
||||
semanticsEnabled: false,
|
||||
timeout: Timeout.none,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ void main() {
|
||||
);
|
||||
await Future<void>.delayed(const Duration(milliseconds: 500));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i += 1) {
|
||||
await scrollOnce(-3000.0);
|
||||
await scrollOnce(-3000.0);
|
||||
|
||||
Reference in New Issue
Block a user