[flutter_tools] migrate web_device.dart to null-safety (#91632)

This commit is contained in:
Christopher Fujino
2021-10-19 01:33:08 -07:00
committed by GitHub
parent ef634b39a5
commit 34ec94a16d
4 changed files with 122 additions and 84 deletions

View File

@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'dart:async';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart';
@@ -32,8 +33,10 @@ void main() {
});
testWithoutContext('GoogleChromeDevice defaults', () async {
final TestChromiumLauncher launcher = TestChromiumLauncher();
final GoogleChromeDevice chromeDevice = GoogleChromeDevice(
chromiumLauncher: null,
chromiumLauncher: launcher,
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
platform: FakePlatform(),
@@ -50,7 +53,7 @@ void main() {
expect(await chromeDevice.isLocalEmulator, false);
expect(chromeDevice.getLogReader(), isA<NoOpDeviceLogReader>());
expect(chromeDevice.getLogReader(), isA<NoOpDeviceLogReader>());
expect(await chromeDevice.portForwarder.forward(1), 1);
expect(await chromeDevice.portForwarder!.forward(1), 1);
expect(chromeDevice.supportsRuntimeMode(BuildMode.debug), true);
expect(chromeDevice.supportsRuntimeMode(BuildMode.profile), true);
@@ -59,8 +62,10 @@ void main() {
});
testWithoutContext('MicrosoftEdge defaults', () async {
final TestChromiumLauncher launcher = TestChromiumLauncher();
final MicrosoftEdgeDevice chromeDevice = MicrosoftEdgeDevice(
chromiumLauncher: null,
chromiumLauncher: launcher,
fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(),
processManager: FakeProcessManager.any(),
@@ -76,7 +81,7 @@ void main() {
expect(await chromeDevice.isLocalEmulator, false);
expect(chromeDevice.getLogReader(), isA<NoOpDeviceLogReader>());
expect(chromeDevice.getLogReader(), isA<NoOpDeviceLogReader>());
expect(await chromeDevice.portForwarder.forward(1), 1);
expect(await chromeDevice.portForwarder!.forward(1), 1);
expect(chromeDevice.supportsRuntimeMode(BuildMode.debug), true);
expect(chromeDevice.supportsRuntimeMode(BuildMode.profile), true);
@@ -99,7 +104,7 @@ void main() {
expect(await device.isLocalEmulator, false);
expect(device.getLogReader(), isA<NoOpDeviceLogReader>());
expect(device.getLogReader(), isA<NoOpDeviceLogReader>());
expect(await device.portForwarder.forward(1), 1);
expect(await device.portForwarder!.forward(1), 1);
expect(device.supportsRuntimeMode(BuildMode.debug), true);
expect(device.supportsRuntimeMode(BuildMode.profile), true);
@@ -353,3 +358,38 @@ void main() {
expect((await macosWebDevices.pollingGetDevices()).whereType<MicrosoftEdgeDevice>(), isEmpty);
});
}
/// A test implementation of the [ChromiumLauncher] that launches a fixed instance.
class TestChromiumLauncher implements ChromiumLauncher {
TestChromiumLauncher();
bool _hasInstance = false;
void setInstance(Chromium chromium) {
_hasInstance = true;
currentCompleter.complete(chromium);
}
@override
Completer<Chromium> currentCompleter = Completer<Chromium>();
@override
bool canFindExecutable() {
return true;
}
@override
Future<Chromium> get connectedInstance => currentCompleter.future;
@override
String findExecutable() {
return 'chrome';
}
@override
bool get hasChromeInstance => _hasInstance;
@override
Future<Chromium> launch(String url, {bool headless = false, int? debugPort, bool skipCheck = false, Directory? cacheDir}) async {
return currentCompleter.future;
}
}