Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions lib/web_ui/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ linter:
public_member_api_docs: false
unawaited_futures: true
use_setters_to_change_properties: false
omit_local_variable_types: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to be clean and sort these!

2 changes: 1 addition & 1 deletion lib/web_ui/dev/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class AnalyzeCommand extends Command<bool> with ArgUtils<bool> {

@override
FutureOr<bool> run() async {
final Pipeline buildPipeline = Pipeline(steps: <PipelineStep>[
final buildPipeline = Pipeline(steps: <PipelineStep>[
PubGetStep(),
AnalyzeStep(),
]);
Expand Down
12 changes: 6 additions & 6 deletions lib/web_ui/dev/browser_process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class BrowserProcess {
// for the process to actually start. They should just wait for the HTTP
// request instead.
runZonedGuarded(() async {
final Process process = await startBrowser();
final process = await startBrowser();
_processCompleter.complete(process);

final Uint8Buffer output = Uint8Buffer();
final output = Uint8Buffer();
void drainOutput(Stream<List<int>> stream) {
try {
_ioSubscriptions
Expand All @@ -36,7 +36,7 @@ class BrowserProcess {
drainOutput(process.stdout);
drainOutput(process.stderr);

final int exitCode = await process.exitCode;
final exitCode = await process.exitCode;

// This hack dodges an otherwise intractable race condition. When the user
// presses Control-C, the signal is sent to the browser and the test
Expand All @@ -53,8 +53,8 @@ class BrowserProcess {
}

if (!_closed && exitCode != 0) {
final String outputString = utf8.decode(output);
String message = 'Browser process failed with exit code $exitCode.';
final outputString = utf8.decode(output);
var message = 'Browser process failed with exit code $exitCode.';
if (outputString.isNotEmpty) {
message += '\nStandard output:\n$outputString';
}
Expand Down Expand Up @@ -113,7 +113,7 @@ class BrowserProcess {
// If we don't manually close the stream the test runner can hang.
// For example this happens with Chrome Headless.
// See SDK issue: https://github.com/dart-lang/sdk/issues/31264
for (final StreamSubscription<void> stream in _ioSubscriptions) {
for (final stream in _ioSubscriptions) {
unawaited(stream.cancel());
}

Expand Down
6 changes: 3 additions & 3 deletions lib/web_ui/dev/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
if (embedDwarf && runtimeMode != RuntimeMode.debug) {
throw ToolExit('Embedding DWARF data requires debug runtime mode.');
}
final FilePath libPath = FilePath.fromWebUi('lib');
final List<PipelineStep> steps = <PipelineStep>[
final libPath = FilePath.fromWebUi('lib');
final steps = <PipelineStep>[
GnPipelineStep(
host: host,
runtimeMode: runtimeMode,
Expand All @@ -85,7 +85,7 @@ class BuildCommand extends Command<bool> with ArgUtils<bool> {
targets: targets.map((String target) => targetAliases[target] ?? target),
),
];
final Pipeline buildPipeline = Pipeline(steps: steps);
final buildPipeline = Pipeline(steps: steps);
await buildPipeline.run();

if (isWatchMode) {
Expand Down
50 changes: 25 additions & 25 deletions lib/web_ui/dev/chrome.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ChromeEnvironment implements BrowserEnvironment {

@override
Future<void> prepare() async {
final String version = packageLock.chromeLock.version;
final version = packageLock.chromeLock.version;
_installation = await getOrInstallChrome(
version,
infoLog: isCi ? stdout : DevNull(),
Expand Down Expand Up @@ -81,7 +81,7 @@ class Chrome extends Browser {
required bool debug,
required bool useDwarf,
}) {
final Completer<Uri> remoteDebuggerCompleter = Completer<Uri>.sync();
final remoteDebuggerCompleter = Completer<Uri>.sync();
return Chrome._(BrowserProcess(() async {
// A good source of various Chrome CLI options:
// https://peter.sh/experiments/chromium-command-line-switches/
Expand All @@ -93,10 +93,10 @@ class Chrome extends Browser {
// --disable-gpu
// --disallow-non-exact-resource-reuse
// --disable-font-subpixel-positioning
final bool isChromeNoSandbox =
final isChromeNoSandbox =
Platform.environment['CHROME_NO_SANDBOX'] == 'true';
final String dir = await generateUserDirectory(installation, useDwarf);
final List<String> args = <String>[
final dir = await generateUserDirectory(installation, useDwarf);
final args = <String>[
'--user-data-dir=$dir',
url.toString(),
if (!debug)
Expand Down Expand Up @@ -136,7 +136,7 @@ class Chrome extends Browser {
'--use-angle=metal',
];

final Process process =
final process =
await _spawnChromiumProcess(installation.executable, args);

remoteDebuggerCompleter.complete(
Expand All @@ -155,7 +155,7 @@ class Chrome extends Browser {
BrowserInstallation installation,
bool useDwarf
) async {
final String userDirectoryPath = environment
final userDirectoryPath = environment
.webUiDartToolDir
.createTempSync('test_chrome_user_data_')
.resolveSymbolicLinksSync();
Expand All @@ -166,11 +166,11 @@ class Chrome extends Browser {
// Using DWARF debugging info requires installation of a Chrome extension.
// We can prompt for this, but in order to avoid prompting on every single
// browser launch, we cache the user directory after it has been installed.
final Directory baselineUserDirectory = Directory(path.join(
final baselineUserDirectory = Directory(path.join(
environment.webUiDartToolDir.path,
'chrome_user_data_base',
));
final Directory dwarfExtensionInstallDirectory = Directory(path.join(
final dwarfExtensionInstallDirectory = Directory(path.join(
baselineUserDirectory.path,
'Default',
'Extensions',
Expand All @@ -183,7 +183,7 @@ class Chrome extends Browser {
if (!dwarfExtensionInstallDirectory.existsSync()) {
print('DWARF debugging requested. Launching Chrome. Please install the '
'extension and then exit Chrome when the installation is complete...');
final Process addExtension = await Process.start(
final addExtension = await Process.start(
installation.executable,
<String>[
'--user-data-dir=${baselineUserDirectory.path}',
Expand All @@ -197,9 +197,9 @@ class Chrome extends Browser {
);
await addExtension.exitCode;
}
for (final FileSystemEntity input in baselineUserDirectory.listSync(recursive: true)) {
final String relative = path.relative(input.path, from: baselineUserDirectory.path);
final String outputPath = path.join(userDirectoryPath, relative);
for (final input in baselineUserDirectory.listSync(recursive: true)) {
final relative = path.relative(input.path, from: baselineUserDirectory.path);
final outputPath = path.join(userDirectoryPath, relative);
if (input is Directory) {
await Directory(outputPath).create(recursive: true);
} else if (input is File) {
Expand Down Expand Up @@ -237,16 +237,16 @@ class Chrome extends Browser {
// TODO(yjbanov): extends tests to Window, https://github.com/flutter/flutter/issues/65673
@override
Future<Image> captureScreenshot(math.Rectangle<num>? region) async {
final wip.ChromeConnection chromeConnection =
final chromeConnection =
wip.ChromeConnection('localhost', kDevtoolsPort);
final wip.ChromeTab? chromeTab = await chromeConnection.getTab(
final chromeTab = await chromeConnection.getTab(
(wip.ChromeTab chromeTab) => chromeTab.url.contains('localhost'));
if (chromeTab == null) {
throw StateError(
'Failed locate Chrome tab with the test page',
);
}
final wip.WipConnection wipConnection = await chromeTab.connect();
final wipConnection = await chromeTab.connect();

Map<String, dynamic>? captureScreenshotParameters;
if (region != null) {
Expand All @@ -273,10 +273,10 @@ class Chrome extends Browser {
'deviceScaleFactor': 1,
'mobile': false,
});
final wip.WipResponse response = await wipConnection.sendCommand(
final response = await wipConnection.sendCommand(
'Page.captureScreenshot', captureScreenshotParameters);

final Image screenshot =
final screenshot =
decodePng(base64.decode(response.result!['data'] as String))!;

return screenshot;
Expand All @@ -301,7 +301,7 @@ Future<Process> _spawnChromiumProcess(String executable, List<String> args, { St
// - Chrome launched successfully, in which case we just return from the loop.
// - The tool detected an unretriable Chrome error, in which case we throw ToolExit.
while (true) {
final Process process = await Process.start(executable, args, workingDirectory: workingDirectory);
final process = await Process.start(executable, args, workingDirectory: workingDirectory);

process.stdout
.transform(utf8.decoder)
Expand All @@ -312,7 +312,7 @@ Future<Process> _spawnChromiumProcess(String executable, List<String> args, { St

// Wait until the DevTools are listening before trying to connect. This is
// only required for flutter_test --platform=chrome and not flutter run.
bool hitGlibcBug = false;
var hitGlibcBug = false;
await process.stderr
.transform(utf8.decoder)
.transform(const LineSplitter())
Expand All @@ -325,7 +325,7 @@ Future<Process> _spawnChromiumProcess(String executable, List<String> args, { St
})
.firstWhere((String line) => line.startsWith('DevTools listening'), orElse: () {
if (hitGlibcBug) {
const String message = 'Encountered glibc bug '
const message = 'Encountered glibc bug '
'https://sourceware.org/bugzilla/show_bug.cgi?id=19329. '
'Will try launching browser again.';
print(message);
Expand Down Expand Up @@ -366,10 +366,10 @@ Future<Process> _spawnChromiumProcess(String executable, List<String> args, { St
/// page.
Future<Uri> getRemoteDebuggerUrl(Uri base) async {
try {
final HttpClient client = HttpClient();
final HttpClientRequest request = await client.getUrl(base.resolve('/json/list'));
final HttpClientResponse response = await request.close();
final List<dynamic>? jsonObject =
final client = HttpClient();
final request = await client.getUrl(base.resolve('/json/list'));
final response = await request.close();
final jsonObject =
await json.fuse(utf8).decoder.bind(response).single as List<dynamic>?;
return base.resolve((jsonObject!.first as Map<dynamic, dynamic>)['devtoolsFrontendUrl'] as String);
} catch (_) {
Expand Down
41 changes: 20 additions & 21 deletions lib/web_ui/dev/chrome_installer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import 'dart:async';
import 'dart:io' as io;
import 'dart:typed_data';

import 'package:archive/archive.dart';
import 'package:archive/archive_io.dart';
Expand Down Expand Up @@ -66,7 +65,7 @@ Future<BrowserInstallation> getOrInstallChrome(
} else {
infoLog.writeln('Installing Chrome version: ${installer.version}');
await installer.install();
final BrowserInstallation installation = installer.getInstallation()!;
final installation = installer.getInstallation()!;
infoLog.writeln(
'Installations complete. To launch it run ${installation.executable}');
}
Expand All @@ -77,7 +76,7 @@ Future<BrowserInstallation> getOrInstallChrome(
}

Future<String> _findSystemChromeExecutable() async {
final io.ProcessResult which =
final which =
await io.Process.run('which', <String>['google-chrome']);

if (which.exitCode != 0) {
Expand All @@ -101,10 +100,10 @@ class ChromeInstaller {
throw BrowserInstallerException(
'Expected a concrete Chromer version, but got $version. Maybe use ChromeInstaller.latest()?');
}
final io.Directory chromeInstallationDir = io.Directory(
final chromeInstallationDir = io.Directory(
path.join(environment.webUiDartToolDir.path, 'chrome'),
);
final io.Directory versionDir = io.Directory(
final versionDir = io.Directory(
path.join(chromeInstallationDir.path, version),
);
return ChromeInstaller._(
Expand All @@ -121,7 +120,7 @@ class ChromeInstaller {
});

static Future<ChromeInstaller> latest() async {
final String latestVersion = await fetchLatestChromeVersion();
final latestVersion = await fetchLatestChromeVersion();
return ChromeInstaller(version: latestVersion);
}

Expand Down Expand Up @@ -165,15 +164,15 @@ class ChromeInstaller {
}
versionDir.createSync(recursive: true);

final String url = PlatformBinding.instance.getChromeDownloadUrl(version);
final url = PlatformBinding.instance.getChromeDownloadUrl(version);
print('Downloading Chrome from $url');

final StreamedResponse download = await client.send(Request(
final download = await client.send(Request(
'GET',
Uri.parse(url),
));

final io.File downloadedFile =
final downloadedFile =
io.File(path.join(versionDir.path, 'chrome.zip'));
await download.stream.pipe(downloadedFile.openWrite());

Expand All @@ -185,18 +184,18 @@ class ChromeInstaller {
/// from dart.
/// See: https://github.com/dart-lang/sdk/issues/15078.
if (io.Platform.isWindows) {
final Stopwatch stopwatch = Stopwatch()..start();
final stopwatch = Stopwatch()..start();

// Read the Zip file from disk.
final Uint8List bytes = downloadedFile.readAsBytesSync();
final bytes = downloadedFile.readAsBytesSync();

final Archive archive = ZipDecoder().decodeBytes(bytes);
final archive = ZipDecoder().decodeBytes(bytes);

// Extract the contents of the Zip archive to disk.
for (final ArchiveFile file in archive) {
final String filename = file.name;
for (final file in archive) {
final filename = file.name;
if (file.isFile) {
final List<int> data = file.content as List<int>;
final data = file.content as List<int>;
io.File(path.joinAll(<String>[
versionDir.path,
// Remove the "chrome-win/" path prefix, which is the Windows
Expand All @@ -218,9 +217,9 @@ class ChromeInstaller {
// version directory. However, the zip file contains a top-level directory
// named e.g. 'chrome-linux'. We need to copy the files out of that
// directory and into the version directory.
final io.Directory tmpDir = await io.Directory.systemTemp.createTemp();
final io.Directory unzipDir = tmpDir;
final io.ProcessResult unzipResult =
final tmpDir = await io.Directory.systemTemp.createTemp();
final unzipDir = tmpDir;
final unzipResult =
await io.Process.run('unzip', <String>[
downloadedFile.path,
'-d',
Expand All @@ -233,7 +232,7 @@ class ChromeInstaller {
'The unzip process exited with code ${unzipResult.exitCode}.');
}

final io.Directory topLevelDir =
final topLevelDir =
await tmpDir.list().single as io.Directory;
await for (final io.FileSystemEntity entity in topLevelDir.list()) {
await entity
Expand All @@ -252,9 +251,9 @@ class ChromeInstaller {

/// Fetches the latest available Chrome build version.
Future<String> fetchLatestChromeVersion() async {
final Client client = Client();
final client = Client();
try {
final Response response = await client.get(Uri.parse(
final response = await client.get(Uri.parse(
'https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2FLAST_CHANGE?alt=media'));
if (response.statusCode != 200) {
throw BrowserInstallerException(
Expand Down
12 changes: 6 additions & 6 deletions lib/web_ui/dev/cipd.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Future<bool> cipdKnowsPackageVersion({
// $package:CIPD_PACKAGE_ID
// or:
// No matching instances.
final String logLevel = isVerbose ? 'debug' : 'warning';
final String stdout = await evalProcess('cipd', <String>[
final logLevel = isVerbose ? 'debug' : 'warning';
final stdout = await evalProcess('cipd', <String>[
'search',
package,
'--tag',
Expand All @@ -43,7 +43,7 @@ Future<int> uploadDirectoryToCipd({
bool isDryRun = false,
bool isVerbose = false,
}) async {
final String cipdConfig = '''
final cipdConfig = '''
package: $packageName
description: $description
preserve_writable: true
Expand All @@ -53,12 +53,12 @@ data:
''';

// Create the config manifest to upload to CIPD
final io.File configFile = io.File(path.join(directory.path, configFileName));
final configFile = io.File(path.join(directory.path, configFileName));
await configFile.writeAsString(cipdConfig);

final String cipdCommand = isDryRun ? 'pkg-build' : 'create';
final cipdCommand = isDryRun ? 'pkg-build' : 'create';
// CIPD won't fully shut up even in 'error' mode
final String logLevel = isVerbose ? 'debug' : 'warning';
final logLevel = isVerbose ? 'debug' : 'warning';
return runProcess('cipd', <String>[
cipdCommand,
'--pkg-def',
Expand Down
Loading