Unverified Commit d6d2e89f authored by Yegor's avatar Yegor Committed by GitHub

finer grained logging of Chromium launch sequence (#135078)

Log the details of how Chromium is about to be launched prior to running
the Chromium command, as well as the path to the Chromium executable.

This should improve our understanding of what's happening here:
https://github.com/flutter/flutter/issues/132654#issuecomment-1726630123
parent b433b175
......@@ -171,13 +171,22 @@ class ChromiumLauncher {
throwToolExit('Only one instance of chrome can be started.');
}
if (_logger.isVerbose) {
_logger.printTrace('Launching Chromium (url = $url, headless = $headless, skipCheck = $skipCheck, debugPort = $debugPort)');
}
final String chromeExecutable = _browserFinder(_platform, _fileSystem);
if (_logger.isVerbose && !_platform.isWindows) {
if (_logger.isVerbose) {
_logger.printTrace('Will use Chromium executable at $chromeExecutable');
if (!_platform.isWindows) {
// The "--version" argument is not supported on Windows.
final ProcessResult versionResult = await _processManager.run(<String>[chromeExecutable, '--version']);
_logger.printTrace('Using ${versionResult.stdout}');
}
}
final Directory userDataDir = _fileSystem.systemTempDirectory
.createTempSync('flutter_tools_chrome_device.');
......
......@@ -44,6 +44,7 @@ void main() {
late Platform platform;
late FakeProcessManager processManager;
late OperatingSystemUtils operatingSystemUtils;
late BufferLogger testLogger;
setUp(() {
exceptionHandler = FileExceptionHandler();
......@@ -59,29 +60,86 @@ void main() {
processManager: processManager,
operatingSystemUtils: operatingSystemUtils,
browserFinder: findChromeExecutable,
logger: BufferLogger.test(),
logger: testLogger = BufferLogger.test(),
);
});
Future<Chromium> testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
if (testLogger.isVerbose) {
processManager.addCommand(const FakeCommand(
command: <String>[
'example_chrome',
'--version',
],
stdout: 'Chromium 115',
));
}
processManager.addCommand(FakeCommand(
command: <String>[
'example_chrome',
'--user-data-dir=$userDataDir',
'--remote-debugging-port=12345',
...kChromeArgs,
'example_url',
],
stderr: kDevtoolsStderr,
));
return chromeLauncher.launch(
'example_url',
skipCheck: true,
);
}
testWithoutContext('can launch chrome and connect to the devtools', () async {
await expectReturnsNormallyLater(
_testLaunchChrome(
testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
processManager,
chromeLauncher,
)
);
});
testWithoutContext('can launch chrome in verbose mode', () async {
chromeLauncher = ChromiumLauncher(
fileSystem: fileSystem,
platform: platform,
processManager: processManager,
operatingSystemUtils: operatingSystemUtils,
browserFinder: findChromeExecutable,
logger: testLogger = BufferLogger.test(verbose: true),
);
await expectReturnsNormallyLater(
testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
processManager,
chromeLauncher,
)
);
expect(
testLogger.traceText.trim(),
'Launching Chromium (url = example_url, headless = false, skipCheck = true, debugPort = null)\n'
'Will use Chromium executable at example_chrome\n'
'Using Chromium 115\n'
'[CHROME]: \n'
'[CHROME]: \n'
'[CHROME]: DevTools listening',
);
});
testWithoutContext('cannot have two concurrent instances of chrome', () async {
await _testLaunchChrome(
await testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
processManager,
chromeLauncher,
);
await expectToolExitLater(
_testLaunchChrome(
testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand1',
processManager,
chromeLauncher,
......@@ -91,7 +149,7 @@ void main() {
});
testWithoutContext('can launch new chrome after stopping a previous chrome', () async {
final Chromium chrome = await _testLaunchChrome(
final Chromium chrome = await testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
processManager,
chromeLauncher,
......@@ -99,7 +157,7 @@ void main() {
await chrome.close();
await expectReturnsNormallyLater(
_testLaunchChrome(
testLaunchChrome(
'/.tmp_rand0/flutter_tools_chrome_device.rand1',
processManager,
chromeLauncher,
......@@ -630,24 +688,6 @@ void main() {
});
}
Future<Chromium> _testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
processManager.addCommand(FakeCommand(
command: <String>[
'example_chrome',
'--user-data-dir=$userDataDir',
'--remote-debugging-port=12345',
...kChromeArgs,
'example_url',
],
stderr: kDevtoolsStderr,
));
return chromeLauncher.launch(
'example_url',
skipCheck: true,
);
}
/// Fake chrome connection that fails to get tabs a few times.
class FakeChromeConnection extends Fake implements ChromeConnection {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment