Unverified Commit fef6f543 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Check if reg can run before calling it on Windows (#79905)

parent 0ee46566
...@@ -210,6 +210,7 @@ class GoogleChromeDevice extends ChromiumDevice { ...@@ -210,6 +210,7 @@ class GoogleChromeDevice extends ChromiumDevice {
// See https://bugs.chromium.org/p/chromium/issues/detail?id=158372 // See https://bugs.chromium.org/p/chromium/issues/detail?id=158372
String version = 'unknown'; String version = 'unknown';
if (_platform.isWindows) { if (_platform.isWindows) {
if (_processManager.canRun('reg')) {
final ProcessResult result = await _processManager.run(<String>[ final ProcessResult result = await _processManager.run(<String>[
r'reg', 'query', r'HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon', '/v', 'version', r'reg', 'query', r'HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon', '/v', 'version',
]); ]);
...@@ -219,6 +220,7 @@ class GoogleChromeDevice extends ChromiumDevice { ...@@ -219,6 +220,7 @@ class GoogleChromeDevice extends ChromiumDevice {
version = 'Google Chrome ' + parts[parts.length - 2]; version = 'Google Chrome ' + parts[parts.length - 2];
} }
} }
}
} else { } else {
final String chrome = chromeLauncher.findExecutable(); final String chrome = chromeLauncher.findExecutable();
final ProcessResult result = await _processManager.run(<String>[ final ProcessResult result = await _processManager.run(<String>[
...@@ -231,7 +233,6 @@ class GoogleChromeDevice extends ChromiumDevice { ...@@ -231,7 +233,6 @@ class GoogleChromeDevice extends ChromiumDevice {
} }
return version.trim(); return version.trim();
} }
} }
/// The Microsoft Edge browser based on Chromium. /// The Microsoft Edge browser based on Chromium.
...@@ -270,6 +271,7 @@ class MicrosoftEdgeDevice extends ChromiumDevice { ...@@ -270,6 +271,7 @@ class MicrosoftEdgeDevice extends ChromiumDevice {
Future<String> get sdkNameAndVersion async => _sdkNameAndVersion ??= await _getSdkNameAndVersion(); Future<String> get sdkNameAndVersion async => _sdkNameAndVersion ??= await _getSdkNameAndVersion();
String _sdkNameAndVersion; String _sdkNameAndVersion;
Future<String> _getSdkNameAndVersion() async { Future<String> _getSdkNameAndVersion() async {
if (_processManager.canRun('reg')) {
final ProcessResult result = await _processManager.run(<String>[ final ProcessResult result = await _processManager.run(<String>[
r'reg', 'query', r'HKEY_CURRENT_USER\Software\Microsoft\Edge\BLBeacon', '/v', 'version', r'reg', 'query', r'HKEY_CURRENT_USER\Software\Microsoft\Edge\BLBeacon', '/v', 'version',
]); ]);
...@@ -279,6 +281,7 @@ class MicrosoftEdgeDevice extends ChromiumDevice { ...@@ -279,6 +281,7 @@ class MicrosoftEdgeDevice extends ChromiumDevice {
return 'Microsoft Edge ' + parts[parts.length - 2]; return 'Microsoft Edge ' + parts[parts.length - 2];
} }
} }
}
// Return a non-null string so that the tool can validate the version // Return a non-null string so that the tool can validate the version
// does not meet the constraint above in _meetsVersionConstraint. // does not meet the constraint above in _meetsVersionConstraint.
return ''; return '';
......
...@@ -255,6 +255,42 @@ void main() { ...@@ -255,6 +255,42 @@ void main() {
expect(processManager, hasNoRemainingExpectations); expect(processManager, hasNoRemainingExpectations);
}); });
testWithoutContext('Chrome and Edge version check handles missing registry on Windows', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[]);
processManager.excludedExecutables.add('reg');
final Platform platform = FakePlatform(
operatingSystem: 'windows', environment: <String, String>{});
final ChromiumLauncher chromeLauncher = ChromiumLauncher(
fileSystem: MemoryFileSystem.test(),
platform: platform,
processManager: processManager,
operatingSystemUtils: null,
browserFinder: findChromeExecutable,
logger: BufferLogger.test(),
);
final MicrosoftEdgeDevice edgeDevice = MicrosoftEdgeDevice(
chromiumLauncher: chromeLauncher,
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: processManager,
);
expect(edgeDevice.isSupported(), true);
expect(await edgeDevice.sdkNameAndVersion, '');
final GoogleChromeDevice chromeDevice = GoogleChromeDevice(
chromiumLauncher: chromeLauncher,
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: processManager,
platform: platform,
);
expect(chromeDevice.isSupported(), true);
expect(await chromeDevice.sdkNameAndVersion, 'unknown');
});
testWithoutContext('Edge is not supported on versions less than 73', () async { testWithoutContext('Edge is not supported on versions less than 73', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[ final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand( const FakeCommand(
......
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