Unverified Commit 75486143 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Prevent windows web doctor from launching chrome (#33874)

parent b7a9a75b
......@@ -2,12 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:meta/meta.dart';
import '../application_package.dart';
import '../asset.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/logger.dart';
import '../base/platform.dart';
import '../base/process_manager.dart';
import '../build_info.dart';
import '../bundle.dart';
......@@ -82,15 +85,29 @@ class WebDevice extends Device {
@override
Future<String> get sdkNameAndVersion async {
// See https://bugs.chromium.org/p/chromium/issues/detail?id=158372
String version = 'unknown';
if (platform.isWindows) {
final ProcessResult result = await processManager.run(<String>[
r'reg', 'query', 'HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon', '/v', 'version'
]);
if (result.exitCode == 0) {
final List<String> parts = result.stdout.split(RegExp(r'\s+'));
if (parts.length > 2) {
version = 'Google Chrome ' + parts[parts.length - 2];
}
}
} else {
final String chrome = findChromeExecutable();
final ProcessResult result = await processManager.run(<String>[
chrome,
'--version',
]);
if (result.exitCode == 0) {
return result.stdout;
version = result.stdout;
}
}
return 'unknown';
return version;
}
@override
......@@ -199,3 +216,8 @@ class WebDevices extends PollingDeviceDiscovery {
@override
bool get supportsPlatform => flutterWebEnabled;
}
@visibleForTesting
String parseVersionForWindows(String input) {
return input.split(RegExp('\w')).last;
}
......@@ -3,24 +3,31 @@
// found in the LICENSE file.
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/web/chrome.dart';
import 'package:flutter_tools/src/web/compile.dart';
import 'package:flutter_tools/src/web/web_device.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../src/common.dart';
import '../src/context.dart';
void main() {
group(WebDevice, () {
final MockWebCompiler mockWebCompiler = MockWebCompiler();
final MockChromeLauncher mockChromeLauncher = MockChromeLauncher();
final MockPlatform mockPlatform = MockPlatform();
MockWebCompiler mockWebCompiler;
MockChromeLauncher mockChromeLauncher;
MockPlatform mockPlatform;
FlutterProject flutterProject;
MockProcessManager mockProcessManager;
setUp(() async {
mockProcessManager = MockProcessManager();
mockChromeLauncher = MockChromeLauncher();
mockPlatform = MockPlatform();
mockWebCompiler = MockWebCompiler();
flutterProject = FlutterProject.fromPath(fs.path.join(getFlutterRoot(), 'dev', 'integration_tests', 'web'));
when(mockWebCompiler.compileDart2js(
target: anyNamed('target'),
......@@ -40,10 +47,54 @@ void main() {
WebCompiler: () => mockWebCompiler,
Platform: () => mockPlatform,
});
testUsingContext('Invokes version command on non-Windows platforms', () async{
when(mockPlatform.isWindows).thenReturn(false);
when(mockPlatform.environment).thenReturn(<String, String>{
kChromeEnvironment: 'chrome.foo'
});
when(mockProcessManager.run(<String>['chrome.foo', '--version'])).thenAnswer((Invocation invocation) async {
return MockProcessResult(0, 'ABC');
});
final WebDevice webDevice = WebDevice();
expect(await webDevice.sdkNameAndVersion, 'ABC');
}, overrides: <Type, Generator>{
Platform: () => mockPlatform,
ProcessManager: () => mockProcessManager,
});
testUsingContext('Invokes different version command on windows.', () async {
when(mockPlatform.isWindows).thenReturn(true);
when(mockProcessManager.run(<String>[
'reg',
'query',
'HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon',
'/v',
'version',
])).thenAnswer((Invocation invocation) async {
return MockProcessResult(0, r'HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon\ version REG_SZ 74.0.0 A');
});
final WebDevice webDevice = WebDevice();
expect(await webDevice.sdkNameAndVersion, 'Google Chrome 74.0.0');
}, overrides: <Type, Generator>{
Platform: () => mockPlatform,
ProcessManager: () => mockProcessManager,
});
});
}
class MockChromeLauncher extends Mock implements ChromeLauncher {}
class MockWebCompiler extends Mock implements WebCompiler {}
class MockPlatform extends Mock implements Platform {}
class MockProcessManager extends Mock implements ProcessManager {}
class MockProcessResult extends Mock implements ProcessResult {
MockProcessResult(this.exitCode, this.stdout);
@override
final int exitCode;
@override
final String stdout;
}
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