mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

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>
89 lines
2.8 KiB
Dart
89 lines
2.8 KiB
Dart
// Copyright 2014 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:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:flutter_driver/flutter_driver.dart';
|
|
import 'package:path/path.dart' as p;
|
|
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
|
|
|
void main() {
|
|
group('semantics performance test', () {
|
|
late FlutterDriver driver;
|
|
|
|
setUpAll(() async {
|
|
// Turn off any accessibility services that may be running. The purpose of
|
|
// the test is to measure the time it takes to create the initial
|
|
// semantics tree in isolation. If accessibility services are on, the
|
|
// semantics tree gets generated during the first frame and we can't
|
|
// measure it in isolation.
|
|
final Process run = await Process.start(_adbPath(), const <String>[
|
|
'shell',
|
|
'settings',
|
|
'put',
|
|
'secure',
|
|
'enabled_accessibility_services',
|
|
'null',
|
|
]);
|
|
await run.exitCode;
|
|
|
|
driver = await FlutterDriver.connect(printCommunication: true);
|
|
});
|
|
|
|
tearDownAll(() async {
|
|
driver.close();
|
|
});
|
|
|
|
test('initial tree creation', () async {
|
|
// Let app become fully idle.
|
|
await Future<void>.delayed(const Duration(seconds: 2));
|
|
|
|
await driver.forceGC();
|
|
|
|
final Timeline timeline = await driver.traceAction(() async {
|
|
expect(
|
|
await driver.setSemantics(true),
|
|
isTrue,
|
|
reason:
|
|
'Could not toggle semantics to on because semantics were already '
|
|
'on, but the test needs to toggle semantics to measure the initial '
|
|
'semantics tree generation in isolation.',
|
|
);
|
|
});
|
|
|
|
final Iterable<TimelineEvent>? semanticsEvents = timeline.events?.where(
|
|
(TimelineEvent event) => event.name == 'SEMANTICS',
|
|
);
|
|
if (semanticsEvents?.length != 2) {
|
|
fail(
|
|
'Expected exactly two "SEMANTICS" events, got ${semanticsEvents?.length}:\n$semanticsEvents',
|
|
);
|
|
}
|
|
final Duration semanticsTreeCreation = Duration(
|
|
microseconds:
|
|
semanticsEvents!.last.timestampMicros! - semanticsEvents.first.timestampMicros!,
|
|
);
|
|
|
|
final String jsonEncoded = json.encode(<String, dynamic>{
|
|
'initialSemanticsTreeCreation': semanticsTreeCreation.inMilliseconds,
|
|
});
|
|
File(
|
|
p.join(testOutputsDirectory, 'complex_layout_semantics_perf.json'),
|
|
).writeAsStringSync(jsonEncoded);
|
|
}, timeout: Timeout.none);
|
|
});
|
|
}
|
|
|
|
String _adbPath() {
|
|
final String? androidHome =
|
|
Platform.environment['ANDROID_HOME'] ?? Platform.environment['ANDROID_SDK_ROOT'];
|
|
if (androidHome == null) {
|
|
return 'adb';
|
|
} else {
|
|
return p.join(androidHome, 'platform-tools', 'adb');
|
|
}
|
|
}
|