Unverified Commit 34ec94a1 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

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

parent ef634b39
...@@ -541,7 +541,7 @@ class AndroidDevice extends Device { ...@@ -541,7 +541,7 @@ class AndroidDevice extends Device {
String mainPath, String mainPath,
String route, String route,
DebuggingOptions debuggingOptions, DebuggingOptions debuggingOptions,
Map<String, dynamic> platformArgs, Map<String, dynamic> platformArgs = const <String, Object>{},
bool prebuiltApplication = false, bool prebuiltApplication = false,
bool ipv6 = false, bool ipv6 = false,
String userIdentifier, String userIdentifier,
......
...@@ -468,7 +468,7 @@ abstract class Device { ...@@ -468,7 +468,7 @@ abstract class Device {
/// The ID returned matches that in the output of `flutter emulators`. Fetching /// The ID returned matches that in the output of `flutter emulators`. Fetching
/// this name may require connecting to the device and if an error occurs null /// this name may require connecting to the device and if an error occurs null
/// will be returned. /// will be returned.
Future<String> get emulatorId; Future<String?> get emulatorId;
/// Whether this device can run the provided [buildMode]. /// Whether this device can run the provided [buildMode].
/// ///
...@@ -501,7 +501,7 @@ abstract class Device { ...@@ -501,7 +501,7 @@ abstract class Device {
/// Specify [userIdentifier] to install for a particular user (Android only). /// Specify [userIdentifier] to install for a particular user (Android only).
Future<bool> installApp( Future<bool> installApp(
covariant ApplicationPackage app, { covariant ApplicationPackage app, {
String userIdentifier, String? userIdentifier,
}); });
/// Uninstall an app package from the current device. /// Uninstall an app package from the current device.
...@@ -510,7 +510,7 @@ abstract class Device { ...@@ -510,7 +510,7 @@ abstract class Device {
/// defaults to all users (Android only). /// defaults to all users (Android only).
Future<bool> uninstallApp( Future<bool> uninstallApp(
covariant ApplicationPackage app, { covariant ApplicationPackage app, {
String userIdentifier, String? userIdentifier,
}); });
/// Check if the device is supported by Flutter. /// Check if the device is supported by Flutter.
...@@ -550,12 +550,12 @@ abstract class Device { ...@@ -550,12 +550,12 @@ abstract class Device {
/// reader will also include log messages from before the invocation time. /// reader will also include log messages from before the invocation time.
/// Defaults to false. /// Defaults to false.
FutureOr<DeviceLogReader> getLogReader({ FutureOr<DeviceLogReader> getLogReader({
covariant ApplicationPackage app, covariant ApplicationPackage? app,
bool includePastLogs = false, bool includePastLogs = false,
}); });
/// Get the port forwarder for this device. /// Get the port forwarder for this device.
DevicePortForwarder get portForwarder; DevicePortForwarder? get portForwarder;
/// Get the DDS instance for this device. /// Get the DDS instance for this device.
final DartDevelopmentService dds = DartDevelopmentService(); final DartDevelopmentService dds = DartDevelopmentService();
...@@ -572,13 +572,13 @@ abstract class Device { ...@@ -572,13 +572,13 @@ abstract class Device {
/// start call. The build mode is not used by all platforms. /// start call. The build mode is not used by all platforms.
Future<LaunchResult> startApp( Future<LaunchResult> startApp(
covariant ApplicationPackage package, { covariant ApplicationPackage package, {
String mainPath, String? mainPath,
String route, String? route,
DebuggingOptions debuggingOptions, required DebuggingOptions debuggingOptions,
Map<String, Object?> platformArgs, Map<String, Object?> platformArgs,
bool prebuiltApplication = false, bool prebuiltApplication = false,
bool ipv6 = false, bool ipv6 = false,
String userIdentifier, String? userIdentifier,
}); });
/// Whether this device implements support for hot reload. /// Whether this device implements support for hot reload.
...@@ -603,7 +603,7 @@ abstract class Device { ...@@ -603,7 +603,7 @@ abstract class Device {
/// Specify [userIdentifier] to stop app installed to a profile (Android only). /// Specify [userIdentifier] to stop app installed to a profile (Android only).
Future<bool> stopApp( Future<bool> stopApp(
covariant ApplicationPackage app, { covariant ApplicationPackage app, {
String userIdentifier, String? userIdentifier,
}); });
/// Query the current application memory usage.. /// Query the current application memory usage..
...@@ -917,7 +917,7 @@ class DiscoveredApp { ...@@ -917,7 +917,7 @@ class DiscoveredApp {
// An empty device log reader // An empty device log reader
class NoOpDeviceLogReader implements DeviceLogReader { class NoOpDeviceLogReader implements DeviceLogReader {
NoOpDeviceLogReader(this.name); NoOpDeviceLogReader(String? nameOrNull) : name = nameOrNull ?? '';
@override @override
final String name; final String name;
......
...@@ -2,9 +2,10 @@ ...@@ -2,9 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8 import 'dart:async';
import 'package:file/memory.dart'; 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/logger.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
...@@ -32,8 +33,10 @@ void main() { ...@@ -32,8 +33,10 @@ void main() {
}); });
testWithoutContext('GoogleChromeDevice defaults', () async { testWithoutContext('GoogleChromeDevice defaults', () async {
final TestChromiumLauncher launcher = TestChromiumLauncher();
final GoogleChromeDevice chromeDevice = GoogleChromeDevice( final GoogleChromeDevice chromeDevice = GoogleChromeDevice(
chromiumLauncher: null, chromiumLauncher: launcher,
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(), logger: BufferLogger.test(),
platform: FakePlatform(), platform: FakePlatform(),
...@@ -50,7 +53,7 @@ void main() { ...@@ -50,7 +53,7 @@ void main() {
expect(await chromeDevice.isLocalEmulator, false); expect(await chromeDevice.isLocalEmulator, false);
expect(chromeDevice.getLogReader(), isA<NoOpDeviceLogReader>()); expect(chromeDevice.getLogReader(), isA<NoOpDeviceLogReader>());
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.debug), true);
expect(chromeDevice.supportsRuntimeMode(BuildMode.profile), true); expect(chromeDevice.supportsRuntimeMode(BuildMode.profile), true);
...@@ -59,8 +62,10 @@ void main() { ...@@ -59,8 +62,10 @@ void main() {
}); });
testWithoutContext('MicrosoftEdge defaults', () async { testWithoutContext('MicrosoftEdge defaults', () async {
final TestChromiumLauncher launcher = TestChromiumLauncher();
final MicrosoftEdgeDevice chromeDevice = MicrosoftEdgeDevice( final MicrosoftEdgeDevice chromeDevice = MicrosoftEdgeDevice(
chromiumLauncher: null, chromiumLauncher: launcher,
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(), logger: BufferLogger.test(),
processManager: FakeProcessManager.any(), processManager: FakeProcessManager.any(),
...@@ -76,7 +81,7 @@ void main() { ...@@ -76,7 +81,7 @@ void main() {
expect(await chromeDevice.isLocalEmulator, false); expect(await chromeDevice.isLocalEmulator, false);
expect(chromeDevice.getLogReader(), isA<NoOpDeviceLogReader>()); expect(chromeDevice.getLogReader(), isA<NoOpDeviceLogReader>());
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.debug), true);
expect(chromeDevice.supportsRuntimeMode(BuildMode.profile), true); expect(chromeDevice.supportsRuntimeMode(BuildMode.profile), true);
...@@ -99,7 +104,7 @@ void main() { ...@@ -99,7 +104,7 @@ void main() {
expect(await device.isLocalEmulator, false); expect(await device.isLocalEmulator, false);
expect(device.getLogReader(), isA<NoOpDeviceLogReader>()); expect(device.getLogReader(), isA<NoOpDeviceLogReader>());
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.debug), true);
expect(device.supportsRuntimeMode(BuildMode.profile), true); expect(device.supportsRuntimeMode(BuildMode.profile), true);
...@@ -353,3 +358,38 @@ void main() { ...@@ -353,3 +358,38 @@ void main() {
expect((await macosWebDevices.pollingGetDevices()).whereType<MicrosoftEdgeDevice>(), isEmpty); 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;
}
}
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