Unverified Commit 288a7733 authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Remove unnecessary null checks in flutter_driver (#118864)

parent 83720015
......@@ -28,8 +28,7 @@ class GetDiagnosticsTree extends CommandWithTarget {
this.subtreeDepth = 0,
this.includeProperties = true,
super.timeout,
}) : assert(subtreeDepth != null),
assert(includeProperties != null);
});
/// Deserializes this command from the value generated by [serialize].
GetDiagnosticsTree.deserialize(super.json, super.finderFactory)
......
......@@ -23,9 +23,7 @@ DriverError _createInvalidKeyValueTypeError(String invalidType) {
/// and add more keys to the returned map.
abstract class CommandWithTarget extends Command {
/// Constructs this command given a [finder].
CommandWithTarget(this.finder, {super.timeout}) {
assert(finder != null, '$runtimeType target cannot be null');
}
CommandWithTarget(this.finder, {super.timeout});
/// Deserializes this command from the value generated by [serialize].
CommandWithTarget.deserialize(super.json, DeserializeFinderFactory finderFactory)
......
......@@ -260,7 +260,6 @@ mixin CommandHandlerFactory {
}
Future<Result> _waitForCondition(Command command) async {
assert(command != null);
final WaitForCondition waitForConditionCommand = command as WaitForCondition;
final WaitCondition condition = deserializeCondition(waitForConditionCommand.condition);
await condition.wait();
......
......@@ -36,8 +36,7 @@ final EnumIndex<HealthStatus> _healthStatusIndex =
/// [FlutterDriver.checkHealth] test.
class Health extends Result {
/// Creates a [Health] object with the given [status].
const Health(this.status)
: assert(status != null);
const Health(this.status);
/// The status represented by this object.
///
......
......@@ -11,15 +11,13 @@ class WaitForCondition extends Command {
/// Creates a command that waits for the given [condition] is met.
///
/// The [condition] argument must not be null.
const WaitForCondition(this.condition, {super.timeout})
: assert(condition != null);
const WaitForCondition(this.condition, {super.timeout});
/// Deserializes this command from the value generated by [serialize].
///
/// The [json] argument cannot be null.
WaitForCondition.deserialize(super.json)
: assert(json != null),
condition = _deserialize(json),
: condition = _deserialize(json),
super.deserialize();
/// The condition that this command shall wait for.
......@@ -94,7 +92,6 @@ class NoTransientCallbacks extends SerializableWaitCondition {
///
/// The [json] argument must not be null.
factory NoTransientCallbacks.deserialize(Map<String, String> json) {
assert(json != null);
if (json['conditionName'] != 'NoTransientCallbacksCondition') {
throw SerializationException('Error occurred during deserializing the NoTransientCallbacksCondition JSON string: $json');
}
......@@ -115,7 +112,6 @@ class NoPendingFrame extends SerializableWaitCondition {
///
/// The [json] argument must not be null.
factory NoPendingFrame.deserialize(Map<String, String> json) {
assert(json != null);
if (json['conditionName'] != 'NoPendingFrameCondition') {
throw SerializationException('Error occurred during deserializing the NoPendingFrameCondition JSON string: $json');
}
......@@ -136,7 +132,6 @@ class FirstFrameRasterized extends SerializableWaitCondition {
///
/// The [json] argument must not be null.
factory FirstFrameRasterized.deserialize(Map<String, String> json) {
assert(json != null);
if (json['conditionName'] != 'FirstFrameRasterizedCondition') {
throw SerializationException('Error occurred during deserializing the FirstFrameRasterizedCondition JSON string: $json');
}
......@@ -160,7 +155,6 @@ class NoPendingPlatformMessages extends SerializableWaitCondition {
///
/// The [json] argument must not be null.
factory NoPendingPlatformMessages.deserialize(Map<String, String> json) {
assert(json != null);
if (json['conditionName'] != 'NoPendingPlatformMessagesCondition') {
throw SerializationException('Error occurred during deserializing the NoPendingPlatformMessagesCondition JSON string: $json');
}
......@@ -176,15 +170,13 @@ class CombinedCondition extends SerializableWaitCondition {
/// Creates a [CombinedCondition] condition.
///
/// The [conditions] argument must not be null.
const CombinedCondition(this.conditions)
: assert(conditions != null);
const CombinedCondition(this.conditions);
/// Factory constructor to parse a [CombinedCondition] instance from the
/// given JSON map.
///
/// The [jsonMap] argument must not be null.
factory CombinedCondition.deserialize(Map<String, String> jsonMap) {
assert(jsonMap != null);
if (jsonMap['conditionName'] != 'CombinedCondition') {
throw SerializationException('Error occurred during deserializing the CombinedCondition JSON string: $jsonMap');
}
......@@ -210,7 +202,6 @@ class CombinedCondition extends SerializableWaitCondition {
final Map<String, String> jsonMap = super.serialize();
final List<Map<String, String>> jsonConditions = conditions.map(
(SerializableWaitCondition condition) {
assert(condition != null);
return condition.serialize();
}).toList();
jsonMap['conditions'] = json.encode(jsonConditions);
......@@ -222,7 +213,6 @@ class CombinedCondition extends SerializableWaitCondition {
///
/// The [json] argument must not be null.
SerializableWaitCondition _deserialize(Map<String, String> json) {
assert(json != null);
final String conditionName = json['conditionName']!;
switch (conditionName) {
case 'NoTransientCallbacksCondition':
......
......@@ -432,11 +432,6 @@ abstract class FlutterDriver {
double dyScroll = 0.0,
Duration? timeout,
}) async {
assert(scrollable != null);
assert(item != null);
assert(alignment != null);
assert(dxScroll != null);
assert(dyScroll != null);
assert(dxScroll != 0.0 || dyScroll != 0.0);
// Kick off an (unawaited) waitFor that will complete when the item we're
......@@ -509,7 +504,6 @@ abstract class FlutterDriver {
/// invoked when the widget is focused, as the [SystemChannels.textInput]
/// channel will be mocked out.
Future<void> setTextEntryEmulation({ required bool enabled, Duration? timeout }) async {
assert(enabled != null);
await sendCommand(SetTextEntryEmulation(enabled, timeout: timeout));
}
......@@ -537,7 +531,6 @@ abstract class FlutterDriver {
///
Future<void> sendTextInputAction(TextInputAction action,
{Duration? timeout}) async {
assert(action != null);
await sendCommand(SendTextInputAction(action, timeout: timeout));
}
......
......@@ -144,7 +144,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
// Let subsequent isolates start automatically.
try {
final vms.Response result = await client.setFlag('pause_isolates_on_start', 'false');
if (result == null || result.type != 'Success') {
if (result.type != 'Success') {
_log('setFlag failure: $result');
}
} catch (e) {
......@@ -348,7 +348,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
_log(message);
}
if (_logCommunicationToFile) {
assert(_logFilePathName != null);
final f.File file = fs.file(_logFilePathName);
file.createSync(recursive: true); // no-op if file exists
file.writeAsStringSync('${DateTime.now()} $message\n', mode: f.FileMode.append, flush: true);
......@@ -380,8 +379,7 @@ class VMServiceFlutterDriver extends FlutterDriver {
List<TimelineStream> streams = const <TimelineStream>[TimelineStream.all],
Duration timeout = kUnusuallyLongTimeout,
}) async {
assert(streams != null && streams.isNotEmpty);
assert(timeout != null);
assert(streams.isNotEmpty);
try {
await _warnIfSlow<vms.Success>(
future: _serviceClient.setVMTimelineFlags(
......@@ -405,7 +403,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
int? startTime,
int? endTime,
}) async {
assert(timeout != null);
assert((startTime == null && endTime == null) ||
(startTime != null && endTime != null));
......@@ -497,7 +494,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
Future<void> clearTimeline({
Duration timeout = kUnusuallyLongTimeout,
}) async {
assert(timeout != null);
try {
await _warnIfSlow<vms.Success>(
future: _serviceClient.clearVMTimeline(),
......@@ -630,9 +626,6 @@ Future<T> _warnIfSlow<T>({
required Duration timeout,
required String message,
}) async {
assert(future != null);
assert(timeout != null);
assert(message != null);
final Completer<void> completer = Completer<void>();
completer.future.timeout(timeout, onTimeout: () {
_log(message);
......
......@@ -174,7 +174,6 @@ class WebFlutterDriver extends FlutterDriver {
driverLog('WebFlutterDriver', message);
}
if (_logCommunicationToFile) {
assert(_logFilePathName != null);
final File file = fs.file(_logFilePathName);
file.createSync(recursive: true); // no-op if file exists
file.writeAsStringSync('${DateTime.now()} $message\n', mode: FileMode.append, flush: true);
......
......@@ -319,7 +319,7 @@ class FlutterDriverExtension with DeserializeFinderFactory, CreateFinderFactory,
this._enableTextEntryEmulation, {
List<FinderExtension> finders = const <FinderExtension>[],
List<CommandExtension> commands = const <CommandExtension>[],
}) : assert(finders != null) {
}) {
if (_enableTextEntryEmulation) {
registerTextInput();
}
......
......@@ -42,7 +42,6 @@ class _InternalNoTransientCallbacksCondition implements WaitCondition {
///
/// The [condition] argument must not be null.
factory _InternalNoTransientCallbacksCondition.deserialize(SerializableWaitCondition condition) {
assert(condition != null);
if (condition.conditionName != 'NoTransientCallbacksCondition') {
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
}
......@@ -71,7 +70,6 @@ class _InternalNoPendingFrameCondition implements WaitCondition {
///
/// The [condition] argument must not be null.
factory _InternalNoPendingFrameCondition.deserialize(SerializableWaitCondition condition) {
assert(condition != null);
if (condition.conditionName != 'NoPendingFrameCondition') {
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
}
......@@ -100,7 +98,6 @@ class _InternalFirstFrameRasterizedCondition implements WaitCondition {
///
/// The [condition] argument must not be null.
factory _InternalFirstFrameRasterizedCondition.deserialize(SerializableWaitCondition condition) {
assert(condition != null);
if (condition.conditionName != 'FirstFrameRasterizedCondition') {
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
}
......@@ -127,7 +124,6 @@ class _InternalNoPendingPlatformMessagesCondition implements WaitCondition {
///
/// The [condition] argument must not be null.
factory _InternalNoPendingPlatformMessagesCondition.deserialize(SerializableWaitCondition condition) {
assert(condition != null);
if (condition.conditionName != 'NoPendingPlatformMessagesCondition') {
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
}
......@@ -156,15 +152,13 @@ class _InternalCombinedCondition implements WaitCondition {
/// [conditions].
///
/// The [conditions] argument must not be null.
const _InternalCombinedCondition(this.conditions)
: assert(conditions != null);
const _InternalCombinedCondition(this.conditions);
/// Factory constructor to parse an [_InternalCombinedCondition] instance from
/// the given [SerializableWaitCondition] instance.
///
/// The [condition] argument must not be null.
factory _InternalCombinedCondition.deserialize(SerializableWaitCondition condition) {
assert(condition != null);
if (condition.conditionName != 'CombinedCondition') {
throw SerializationException('Error occurred during deserializing from the given condition: ${condition.serialize()}');
}
......@@ -185,7 +179,6 @@ class _InternalCombinedCondition implements WaitCondition {
Future<void> wait() async {
while (!condition) {
for (final WaitCondition condition in conditions) {
assert (condition != null);
await condition.wait();
}
}
......@@ -197,7 +190,6 @@ class _InternalCombinedCondition implements WaitCondition {
///
/// The [waitCondition] argument must not be null.
WaitCondition deserializeCondition(SerializableWaitCondition waitCondition) {
assert(waitCondition != null);
final String conditionName = waitCondition.conditionName;
switch (conditionName) {
case 'NoTransientCallbacksCondition':
......
......@@ -1193,9 +1193,9 @@ class FakeVmService extends Fake implements vms.VmService {
commandLog.add('$method $args');
await artificialExtensionDelay;
final vms.Response response = responses[args!['command']]!;
final vms.Response? response = responses[args!['command']];
assert(response != null, 'Failed to create a response for ${args['command']}');
return response;
return response!;
}
@override
......@@ -1243,9 +1243,9 @@ class FakeVmService extends Fake implements vms.VmService {
@override
Future<vms.Timeline> getVMTimeline({int? timeOriginMicros, int? timeExtentMicros}) async {
connectionLog.add('getVMTimeline $timeOriginMicros $timeExtentMicros');
final vms.Timeline timeline = timelineResponses[timeOriginMicros ?? 1]!;
final vms.Timeline? timeline = timelineResponses[timeOriginMicros ?? 1];
assert(timeline != null, 'Missing entry in timelineResponses[$timeOriginMicros]');
return timeline;
return timeline!;
}
@override
......
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