Skip to content

Commit d6d2e89

Browse files
authored
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: flutter/flutter#132654 (comment)
1 parent b433b17 commit d6d2e89

File tree

2 files changed

+77
-28
lines changed

2 files changed

+77
-28
lines changed

packages/flutter_tools/lib/src/web/chrome.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,23 @@ class ChromiumLauncher {
171171
throwToolExit('Only one instance of chrome can be started.');
172172
}
173173

174+
if (_logger.isVerbose) {
175+
_logger.printTrace('Launching Chromium (url = $url, headless = $headless, skipCheck = $skipCheck, debugPort = $debugPort)');
176+
}
177+
174178
final String chromeExecutable = _browserFinder(_platform, _fileSystem);
175179

176-
if (_logger.isVerbose && !_platform.isWindows) {
177-
// The "--version" argument is not supported on Windows.
178-
final ProcessResult versionResult = await _processManager.run(<String>[chromeExecutable, '--version']);
179-
_logger.printTrace('Using ${versionResult.stdout}');
180+
if (_logger.isVerbose) {
181+
_logger.printTrace('Will use Chromium executable at $chromeExecutable');
182+
183+
if (!_platform.isWindows) {
184+
// The "--version" argument is not supported on Windows.
185+
final ProcessResult versionResult = await _processManager.run(<String>[chromeExecutable, '--version']);
186+
_logger.printTrace('Using ${versionResult.stdout}');
187+
}
180188
}
181189

190+
182191
final Directory userDataDir = _fileSystem.systemTempDirectory
183192
.createTempSync('flutter_tools_chrome_device.');
184193

packages/flutter_tools/test/web.shard/chrome_test.dart

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void main() {
4444
late Platform platform;
4545
late FakeProcessManager processManager;
4646
late OperatingSystemUtils operatingSystemUtils;
47+
late BufferLogger testLogger;
4748

4849
setUp(() {
4950
exceptionHandler = FileExceptionHandler();
@@ -59,29 +60,86 @@ void main() {
5960
processManager: processManager,
6061
operatingSystemUtils: operatingSystemUtils,
6162
browserFinder: findChromeExecutable,
62-
logger: BufferLogger.test(),
63+
logger: testLogger = BufferLogger.test(),
6364
);
6465
});
6566

67+
Future<Chromium> testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
68+
if (testLogger.isVerbose) {
69+
processManager.addCommand(const FakeCommand(
70+
command: <String>[
71+
'example_chrome',
72+
'--version',
73+
],
74+
stdout: 'Chromium 115',
75+
));
76+
}
77+
78+
processManager.addCommand(FakeCommand(
79+
command: <String>[
80+
'example_chrome',
81+
'--user-data-dir=$userDataDir',
82+
'--remote-debugging-port=12345',
83+
...kChromeArgs,
84+
'example_url',
85+
],
86+
stderr: kDevtoolsStderr,
87+
));
88+
89+
return chromeLauncher.launch(
90+
'example_url',
91+
skipCheck: true,
92+
);
93+
}
94+
6695
testWithoutContext('can launch chrome and connect to the devtools', () async {
6796
await expectReturnsNormallyLater(
68-
_testLaunchChrome(
97+
testLaunchChrome(
6998
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
7099
processManager,
71100
chromeLauncher,
72101
)
73102
);
74103
});
75104

105+
testWithoutContext('can launch chrome in verbose mode', () async {
106+
chromeLauncher = ChromiumLauncher(
107+
fileSystem: fileSystem,
108+
platform: platform,
109+
processManager: processManager,
110+
operatingSystemUtils: operatingSystemUtils,
111+
browserFinder: findChromeExecutable,
112+
logger: testLogger = BufferLogger.test(verbose: true),
113+
);
114+
115+
await expectReturnsNormallyLater(
116+
testLaunchChrome(
117+
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
118+
processManager,
119+
chromeLauncher,
120+
)
121+
);
122+
123+
expect(
124+
testLogger.traceText.trim(),
125+
'Launching Chromium (url = example_url, headless = false, skipCheck = true, debugPort = null)\n'
126+
'Will use Chromium executable at example_chrome\n'
127+
'Using Chromium 115\n'
128+
'[CHROME]: \n'
129+
'[CHROME]: \n'
130+
'[CHROME]: DevTools listening',
131+
);
132+
});
133+
76134
testWithoutContext('cannot have two concurrent instances of chrome', () async {
77-
await _testLaunchChrome(
135+
await testLaunchChrome(
78136
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
79137
processManager,
80138
chromeLauncher,
81139
);
82140

83141
await expectToolExitLater(
84-
_testLaunchChrome(
142+
testLaunchChrome(
85143
'/.tmp_rand0/flutter_tools_chrome_device.rand1',
86144
processManager,
87145
chromeLauncher,
@@ -91,15 +149,15 @@ void main() {
91149
});
92150

93151
testWithoutContext('can launch new chrome after stopping a previous chrome', () async {
94-
final Chromium chrome = await _testLaunchChrome(
152+
final Chromium chrome = await testLaunchChrome(
95153
'/.tmp_rand0/flutter_tools_chrome_device.rand0',
96154
processManager,
97155
chromeLauncher,
98156
);
99157
await chrome.close();
100158

101159
await expectReturnsNormallyLater(
102-
_testLaunchChrome(
160+
testLaunchChrome(
103161
'/.tmp_rand0/flutter_tools_chrome_device.rand1',
104162
processManager,
105163
chromeLauncher,
@@ -630,24 +688,6 @@ void main() {
630688
});
631689
}
632690

633-
Future<Chromium> _testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
634-
processManager.addCommand(FakeCommand(
635-
command: <String>[
636-
'example_chrome',
637-
'--user-data-dir=$userDataDir',
638-
'--remote-debugging-port=12345',
639-
...kChromeArgs,
640-
'example_url',
641-
],
642-
stderr: kDevtoolsStderr,
643-
));
644-
645-
return chromeLauncher.launch(
646-
'example_url',
647-
skipCheck: true,
648-
);
649-
}
650-
651691
/// Fake chrome connection that fails to get tabs a few times.
652692
class FakeChromeConnection extends Fake implements ChromeConnection {
653693

0 commit comments

Comments
 (0)